Format all GUI-only files
This commit is contained in:
parent
4f53029a6e
commit
3ac822c5fe
|
@ -4,39 +4,37 @@
|
||||||
|
|
||||||
#include "resources/config.h"
|
#include "resources/config.h"
|
||||||
|
|
||||||
|
#include <tagparser/backuphelper.h>
|
||||||
#include <tagparser/mediafileinfo.h>
|
#include <tagparser/mediafileinfo.h>
|
||||||
#include <tagparser/tag.h>
|
#include <tagparser/tag.h>
|
||||||
#include <tagparser/backuphelper.h>
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QSettings>
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
using namespace TagParser;
|
using namespace TagParser;
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
AutoCompletition::AutoCompletition() :
|
AutoCompletition::AutoCompletition()
|
||||||
fields(nullptr, KnownFieldModel::DefaultSelection::None)
|
: fields(nullptr, KnownFieldModel::DefaultSelection::None)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Editor::Editor() :
|
Editor::Editor()
|
||||||
fields(nullptr, KnownFieldModel::DefaultSelection::CommonFields),
|
: fields(nullptr, KnownFieldModel::DefaultSelection::CommonFields)
|
||||||
defaultTargets(nullptr, TargetLevelModel::DefaultSelection::MostUsefulTargets)
|
, defaultTargets(nullptr, TargetLevelModel::DefaultSelection::MostUsefulTargets)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
DbQuery::DbQuery() :
|
DbQuery::DbQuery()
|
||||||
fields(QList<Models::ChecklistItem>()
|
: fields(QList<Models::ChecklistItem>() << KnownFieldModel::mkItem(KnownField::Title) << KnownFieldModel::mkItem(KnownField::TrackPosition)
|
||||||
<< KnownFieldModel::mkItem(KnownField::Title)
|
<< KnownFieldModel::mkItem(KnownField::DiskPosition) << KnownFieldModel::mkItem(KnownField::Album)
|
||||||
<< KnownFieldModel::mkItem(KnownField::TrackPosition)
|
<< KnownFieldModel::mkItem(KnownField::Album) << KnownFieldModel::mkItem(KnownField::Year)
|
||||||
<< KnownFieldModel::mkItem(KnownField::DiskPosition)
|
<< KnownFieldModel::mkItem(KnownField::Genre) << KnownFieldModel::mkItem(KnownField::Cover, Qt::Unchecked)
|
||||||
<< KnownFieldModel::mkItem(KnownField::Album)
|
<< KnownFieldModel::mkItem(KnownField::Lyrics, Qt::Unchecked))
|
||||||
<< KnownFieldModel::mkItem(KnownField::Album)
|
{
|
||||||
<< KnownFieldModel::mkItem(KnownField::Year)
|
}
|
||||||
<< KnownFieldModel::mkItem(KnownField::Genre)
|
|
||||||
<< KnownFieldModel::mkItem(KnownField::Cover, Qt::Unchecked)
|
|
||||||
<< KnownFieldModel::mkItem(KnownField::Lyrics, Qt::Unchecked))
|
|
||||||
{}
|
|
||||||
|
|
||||||
Settings &values()
|
Settings &values()
|
||||||
{
|
{
|
||||||
|
@ -48,13 +46,14 @@ void restore()
|
||||||
{
|
{
|
||||||
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral(PROJECT_NAME));
|
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral(PROJECT_NAME));
|
||||||
// move old config to new location
|
// move old config to new location
|
||||||
const QString oldConfig = QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName()).fileName();
|
const QString oldConfig
|
||||||
|
= QSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), QApplication::applicationName()).fileName();
|
||||||
QFile::rename(oldConfig, settings.fileName()) || QFile::remove(oldConfig);
|
QFile::rename(oldConfig, settings.fileName()) || QFile::remove(oldConfig);
|
||||||
settings.sync();
|
settings.sync();
|
||||||
Settings &v = values();
|
Settings &v = values();
|
||||||
|
|
||||||
settings.beginGroup(QStringLiteral("editor"));
|
settings.beginGroup(QStringLiteral("editor"));
|
||||||
switch(settings.value(QStringLiteral("adoptfields"), 0).toInt()) {
|
switch (settings.value(QStringLiteral("adoptfields"), 0).toInt()) {
|
||||||
case 1:
|
case 1:
|
||||||
v.editor.adoptFields = AdoptFields::WithinDirectory;
|
v.editor.adoptFields = AdoptFields::WithinDirectory;
|
||||||
break;
|
break;
|
||||||
|
@ -67,7 +66,7 @@ void restore()
|
||||||
};
|
};
|
||||||
v.editor.saveAndShowNextOnEnter = settings.value(QStringLiteral("saveandshownextonenter"), false).toBool();
|
v.editor.saveAndShowNextOnEnter = settings.value(QStringLiteral("saveandshownextonenter"), false).toBool();
|
||||||
v.editor.askBeforeDeleting = settings.value(QStringLiteral("askbeforedeleting"), true).toBool();
|
v.editor.askBeforeDeleting = settings.value(QStringLiteral("askbeforedeleting"), true).toBool();
|
||||||
switch(settings.value(QStringLiteral("multipletaghandling"), 0).toInt()) {
|
switch (settings.value(QStringLiteral("multipletaghandling"), 0).toInt()) {
|
||||||
case 0:
|
case 0:
|
||||||
v.editor.multipleTagHandling = MultipleTagHandling::SingleEditorPerTarget;
|
v.editor.multipleTagHandling = MultipleTagHandling::SingleEditorPerTarget;
|
||||||
break;
|
break;
|
||||||
|
@ -102,7 +101,7 @@ void restore()
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
settings.beginGroup(QStringLiteral("tagprocessing"));
|
settings.beginGroup(QStringLiteral("tagprocessing"));
|
||||||
switch(settings.value(QStringLiteral("preferredencoding"), 1).toInt()) {
|
switch (settings.value(QStringLiteral("preferredencoding"), 1).toInt()) {
|
||||||
case 0:
|
case 0:
|
||||||
v.tagPocessing.preferredEncoding = TagParser::TagTextEncoding::Latin1;
|
v.tagPocessing.preferredEncoding = TagParser::TagTextEncoding::Latin1;
|
||||||
break;
|
break;
|
||||||
|
@ -115,7 +114,7 @@ void restore()
|
||||||
default:
|
default:
|
||||||
v.tagPocessing.preferredEncoding = TagParser::TagTextEncoding::Utf8;
|
v.tagPocessing.preferredEncoding = TagParser::TagTextEncoding::Utf8;
|
||||||
};
|
};
|
||||||
switch(settings.value(QStringLiteral("unsupportedfieldhandling"), 0).toInt()) {
|
switch (settings.value(QStringLiteral("unsupportedfieldhandling"), 0).toInt()) {
|
||||||
case 1:
|
case 1:
|
||||||
v.tagPocessing.unsupportedFieldHandling = UnsupportedFieldHandling::Discard;
|
v.tagPocessing.unsupportedFieldHandling = UnsupportedFieldHandling::Discard;
|
||||||
break;
|
break;
|
||||||
|
@ -124,37 +123,42 @@ void restore()
|
||||||
};
|
};
|
||||||
v.tagPocessing.autoTagManagement = settings.value(QStringLiteral("autotagmanagement"), true).toBool();
|
v.tagPocessing.autoTagManagement = settings.value(QStringLiteral("autotagmanagement"), true).toBool();
|
||||||
settings.beginGroup(QStringLiteral("id3v1"));
|
settings.beginGroup(QStringLiteral("id3v1"));
|
||||||
switch(settings.value(QStringLiteral("usage"), 0).toInt()) {
|
switch (settings.value(QStringLiteral("usage"), 0).toInt()) {
|
||||||
case 1:
|
case 1:
|
||||||
v.tagPocessing.id3.v1Usage = TagUsage::KeepExisting;
|
v.tagPocessing.creationSettings.id3v1usage = TagUsage::KeepExisting;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
v.tagPocessing.id3.v1Usage = TagUsage::Never;
|
v.tagPocessing.creationSettings.id3v1usage = TagUsage::Never;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
v.tagPocessing.id3.v1Usage = TagUsage::Always;
|
v.tagPocessing.creationSettings.id3v1usage = TagUsage::Always;
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
settings.beginGroup(QStringLiteral("id3v2"));
|
settings.beginGroup(QStringLiteral("id3v2"));
|
||||||
switch(settings.value(QStringLiteral("usage"), 0).toInt()) {
|
switch (settings.value(QStringLiteral("usage"), 0).toInt()) {
|
||||||
case 1:
|
case 1:
|
||||||
v.tagPocessing.id3.v2Usage = TagUsage::KeepExisting;
|
v.tagPocessing.creationSettings.id3v2usage = TagUsage::KeepExisting;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
v.tagPocessing.id3.v2Usage = TagUsage::Never;
|
v.tagPocessing.creationSettings.id3v2usage = TagUsage::Never;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
v.tagPocessing.id3.v2Usage = TagUsage::Always;
|
v.tagPocessing.creationSettings.id3v2usage = TagUsage::Always;
|
||||||
};
|
};
|
||||||
v.tagPocessing.id3.v2Version = settings.value(QStringLiteral("versiontobeused"), 3).toUInt();
|
v.tagPocessing.creationSettings.id3v2MajorVersion = static_cast<byte>(settings.value(QStringLiteral("versiontobeused")).toUInt());
|
||||||
v.tagPocessing.id3.keepVersionOfExistingId3v2Tag = settings.value(QStringLiteral("keepversionofexistingtag"), true).toBool();
|
if (v.tagPocessing.creationSettings.id3v2MajorVersion < 1 || v.tagPocessing.creationSettings.id3v2MajorVersion > 4) {
|
||||||
v.tagPocessing.id3.mergeMultipleSuccessiveId3v2Tags = settings.value(QStringLiteral("mergemultiplesuccessivetags"), true).toBool();
|
v.tagPocessing.creationSettings.id3v2MajorVersion = 3;
|
||||||
|
}
|
||||||
|
v.tagPocessing.creationSettings.setFlag(
|
||||||
|
TagCreationFlags::KeepExistingId3v2Version, settings.value(QStringLiteral("keepversionofexistingtag"), true).toBool());
|
||||||
|
v.tagPocessing.creationSettings.setFlag(
|
||||||
|
TagCreationFlags::MergeMultipleSuccessiveId3v2Tags, settings.value(QStringLiteral("mergemultiplesuccessivetags"), true).toBool());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
v.editor.defaultTargets.restore(settings, QStringLiteral("targets"));
|
v.editor.defaultTargets.restore(settings, QStringLiteral("targets"));
|
||||||
settings.beginGroup(QStringLiteral("filelayout"));
|
settings.beginGroup(QStringLiteral("filelayout"));
|
||||||
v.tagPocessing.fileLayout.forceRewrite = settings.value(QStringLiteral("forcerewrite"), true).toBool();
|
v.tagPocessing.fileLayout.forceRewrite = settings.value(QStringLiteral("forcerewrite"), true).toBool();
|
||||||
switch(settings.value(QStringLiteral("tagpos")).toInt()) {
|
switch (settings.value(QStringLiteral("tagpos")).toInt()) {
|
||||||
case 0:
|
case 0:
|
||||||
v.tagPocessing.fileLayout.preferredTagPosition = ElementPosition::BeforeData;
|
v.tagPocessing.fileLayout.preferredTagPosition = ElementPosition::BeforeData;
|
||||||
break;
|
break;
|
||||||
|
@ -163,7 +167,7 @@ void restore()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
v.tagPocessing.fileLayout.forceTagPosition = settings.value(QStringLiteral("forcetagpos"), true).toBool();
|
v.tagPocessing.fileLayout.forceTagPosition = settings.value(QStringLiteral("forcetagpos"), true).toBool();
|
||||||
switch(settings.value(QStringLiteral("indexpos")).toInt()) {
|
switch (settings.value(QStringLiteral("indexpos")).toInt()) {
|
||||||
case 0:
|
case 0:
|
||||||
v.tagPocessing.fileLayout.preferredIndexPosition = ElementPosition::BeforeData;
|
v.tagPocessing.fileLayout.preferredIndexPosition = ElementPosition::BeforeData;
|
||||||
break;
|
break;
|
||||||
|
@ -243,13 +247,14 @@ void save()
|
||||||
settings.setValue(QStringLiteral("unsupportedfieldhandling"), static_cast<int>(v.tagPocessing.unsupportedFieldHandling));
|
settings.setValue(QStringLiteral("unsupportedfieldhandling"), static_cast<int>(v.tagPocessing.unsupportedFieldHandling));
|
||||||
settings.setValue(QStringLiteral("autotagmanagement"), v.tagPocessing.autoTagManagement);
|
settings.setValue(QStringLiteral("autotagmanagement"), v.tagPocessing.autoTagManagement);
|
||||||
settings.beginGroup(QStringLiteral("id3v1"));
|
settings.beginGroup(QStringLiteral("id3v1"));
|
||||||
settings.setValue(QStringLiteral("usage"), static_cast<int>(v.tagPocessing.id3.v1Usage));
|
settings.setValue(QStringLiteral("usage"), static_cast<int>(v.tagPocessing.creationSettings.id3v1usage));
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
settings.beginGroup(QStringLiteral("id3v2"));
|
settings.beginGroup(QStringLiteral("id3v2"));
|
||||||
settings.setValue(QStringLiteral("usage"), static_cast<int>(v.tagPocessing.id3.v2Usage));
|
settings.setValue(QStringLiteral("usage"), static_cast<int>(v.tagPocessing.creationSettings.id3v2usage));
|
||||||
settings.setValue(QStringLiteral("versiontobeused"), v.tagPocessing.id3.v2Version);
|
settings.setValue(QStringLiteral("versiontobeused"), v.tagPocessing.creationSettings.id3v2MajorVersion);
|
||||||
settings.setValue(QStringLiteral("keepversionofexistingtag"), v.tagPocessing.id3.keepVersionOfExistingId3v2Tag);
|
settings.setValue(QStringLiteral("keepversionofexistingtag"), v.tagPocessing.creationSettings.flags & TagCreationFlags::KeepExistingId3v2Version);
|
||||||
settings.setValue(QStringLiteral("mergemultiplesuccessivetags"), v.tagPocessing.id3.mergeMultipleSuccessiveId3v2Tags);
|
settings.setValue(
|
||||||
|
QStringLiteral("mergemultiplesuccessivetags"), v.tagPocessing.creationSettings.flags & TagCreationFlags::MergeMultipleSuccessiveId3v2Tags);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
v.editor.defaultTargets.save(settings, QStringLiteral("targets"));
|
v.editor.defaultTargets.save(settings, QStringLiteral("targets"));
|
||||||
settings.beginGroup(QStringLiteral("filelayout"));
|
settings.beginGroup(QStringLiteral("filelayout"));
|
||||||
|
@ -288,4 +293,4 @@ void save()
|
||||||
v.qt.save(settings);
|
v.qt.save(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace Settings
|
||||||
|
|
|
@ -1,45 +1,30 @@
|
||||||
#ifndef SETTINGS_H
|
#ifndef SETTINGS_H
|
||||||
#define SETTINGS_H
|
#define SETTINGS_H
|
||||||
|
|
||||||
#include "./targetlevelmodel.h"
|
|
||||||
#include "./knownfieldmodel.h"
|
#include "./knownfieldmodel.h"
|
||||||
|
#include "./targetlevelmodel.h"
|
||||||
|
|
||||||
#include <c++utilities/conversion/types.h>
|
#include <c++utilities/conversion/types.h>
|
||||||
|
|
||||||
#include <tagparser/abstractcontainer.h>
|
#include <tagparser/abstractcontainer.h>
|
||||||
#include <tagparser/tagvalue.h>
|
|
||||||
#include <tagparser/settings.h>
|
#include <tagparser/settings.h>
|
||||||
#include <tagparser/tag.h>
|
#include <tagparser/tag.h>
|
||||||
|
#include <tagparser/tagvalue.h>
|
||||||
|
|
||||||
#include <qtutilities/settingsdialog/qtsettings.h>
|
#include <qtutilities/settingsdialog/qtsettings.h>
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
enum class ActionEnabled
|
enum class ActionEnabled { Ask, Yes, No };
|
||||||
{
|
|
||||||
Ask,
|
|
||||||
Yes,
|
|
||||||
No
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class AdoptFields
|
enum class AdoptFields { Never, WithinDirectory, Always };
|
||||||
{
|
|
||||||
Never,
|
|
||||||
WithinDirectory,
|
|
||||||
Always
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class MultipleTagHandling
|
enum class MultipleTagHandling { SingleEditorPerTarget, SeparateEditors };
|
||||||
{
|
|
||||||
SingleEditorPerTarget,
|
|
||||||
SeparateEditors
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AutoCompletition
|
struct AutoCompletition {
|
||||||
{
|
|
||||||
AutoCompletition();
|
AutoCompletition();
|
||||||
bool insertTitleFromFilename = false;
|
bool insertTitleFromFilename = false;
|
||||||
bool trimWhitespaces = true;
|
bool trimWhitespaces = true;
|
||||||
|
@ -48,8 +33,7 @@ struct AutoCompletition
|
||||||
KnownFieldModel fields;
|
KnownFieldModel fields;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Editor
|
struct Editor {
|
||||||
{
|
|
||||||
Editor();
|
Editor();
|
||||||
AdoptFields adoptFields = AdoptFields::Never;
|
AdoptFields adoptFields = AdoptFields::Never;
|
||||||
bool saveAndShowNextOnEnter = false;
|
bool saveAndShowNextOnEnter = false;
|
||||||
|
@ -66,20 +50,14 @@ struct Editor
|
||||||
TargetLevelModel defaultTargets;
|
TargetLevelModel defaultTargets;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class UnsupportedFieldHandling
|
enum class UnsupportedFieldHandling { Ignore, Discard };
|
||||||
{
|
|
||||||
Ignore,
|
|
||||||
Discard
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FileBrowser
|
struct FileBrowser {
|
||||||
{
|
|
||||||
bool hideBackupFiles = true;
|
bool hideBackupFiles = true;
|
||||||
bool readOnly = true;
|
bool readOnly = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FileLayout
|
struct FileLayout {
|
||||||
{
|
|
||||||
bool forceRewrite = true;
|
bool forceRewrite = true;
|
||||||
TagParser::ElementPosition preferredTagPosition = TagParser::ElementPosition::BeforeData;
|
TagParser::ElementPosition preferredTagPosition = TagParser::ElementPosition::BeforeData;
|
||||||
bool forceTagPosition = true;
|
bool forceTagPosition = true;
|
||||||
|
@ -90,8 +68,7 @@ struct FileLayout
|
||||||
std::size_t preferredPadding = 0;
|
std::size_t preferredPadding = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TagProcessing
|
struct TagProcessing {
|
||||||
{
|
|
||||||
TagParser::TagTextEncoding preferredEncoding = TagParser::TagTextEncoding::Utf8;
|
TagParser::TagTextEncoding preferredEncoding = TagParser::TagTextEncoding::Utf8;
|
||||||
UnsupportedFieldHandling unsupportedFieldHandling = UnsupportedFieldHandling::Ignore;
|
UnsupportedFieldHandling unsupportedFieldHandling = UnsupportedFieldHandling::Ignore;
|
||||||
bool autoTagManagement = true;
|
bool autoTagManagement = true;
|
||||||
|
@ -99,16 +76,14 @@ struct TagProcessing
|
||||||
FileLayout fileLayout;
|
FileLayout fileLayout;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MainWindow
|
struct MainWindow {
|
||||||
{
|
|
||||||
QByteArray geometry;
|
QByteArray geometry;
|
||||||
QByteArray state;
|
QByteArray state;
|
||||||
QString currentFileBrowserDirectory;
|
QString currentFileBrowserDirectory;
|
||||||
bool layoutLocked = false;
|
bool layoutLocked = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DbQuery
|
struct DbQuery {
|
||||||
{
|
|
||||||
DbQuery();
|
DbQuery();
|
||||||
bool widgetShown = false;
|
bool widgetShown = false;
|
||||||
bool override = false;
|
bool override = false;
|
||||||
|
@ -118,15 +93,13 @@ struct DbQuery
|
||||||
QString lyricsWikiaUrl;
|
QString lyricsWikiaUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RenamingUtility
|
struct RenamingUtility {
|
||||||
{
|
|
||||||
int scriptSource = 0;
|
int scriptSource = 0;
|
||||||
QString externalScript;
|
QString externalScript;
|
||||||
QString editorScript;
|
QString editorScript;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Settings
|
struct Settings {
|
||||||
{
|
|
||||||
Editor editor;
|
Editor editor;
|
||||||
FileBrowser fileBrowser;
|
FileBrowser fileBrowser;
|
||||||
TagProcessing tagPocessing;
|
TagProcessing tagPocessing;
|
||||||
|
@ -140,6 +113,6 @@ Settings &values();
|
||||||
void restore();
|
void restore();
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
}
|
} // namespace Settings
|
||||||
|
|
||||||
#endif // SETTINGS_H
|
#endif // SETTINGS_H
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Settings {
|
||||||
|
|
||||||
const char *TargetLevelModel::fieldName(TagTargetLevel targetLevel)
|
const char *TargetLevelModel::fieldName(TagTargetLevel targetLevel)
|
||||||
{
|
{
|
||||||
switch(targetLevel) {
|
switch (targetLevel) {
|
||||||
case TagTargetLevel::Unspecified:
|
case TagTargetLevel::Unspecified:
|
||||||
return QT_TR_NOOP("unspecified, everything");
|
return QT_TR_NOOP("unspecified, everything");
|
||||||
case TagTargetLevel::Shot:
|
case TagTargetLevel::Shot:
|
||||||
|
@ -46,8 +46,8 @@ QString TargetLevelModel::labelForId(const QVariant &id) const
|
||||||
return translatedFieldName(static_cast<TagTargetLevel>(id.toInt()));
|
return translatedFieldName(static_cast<TagTargetLevel>(id.toInt()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetLevelModel::TargetLevelModel(QObject *parent, DefaultSelection defaultSelection) :
|
TargetLevelModel::TargetLevelModel(QObject *parent, DefaultSelection defaultSelection)
|
||||||
ChecklistModel(parent)
|
: ChecklistModel(parent)
|
||||||
{
|
{
|
||||||
QList<ChecklistItem> items;
|
QList<ChecklistItem> items;
|
||||||
items.reserve(8);
|
items.reserve(8);
|
||||||
|
@ -63,30 +63,28 @@ TargetLevelModel::TargetLevelModel(QObject *parent, DefaultSelection defaultSele
|
||||||
setItems(items);
|
setItems(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetLevelModel::TargetLevelModel(const QList<Models::ChecklistItem> &items, QObject *parent) :
|
TargetLevelModel::TargetLevelModel(const QList<Models::ChecklistItem> &items, QObject *parent)
|
||||||
ChecklistModel(parent)
|
: ChecklistModel(parent)
|
||||||
{
|
{
|
||||||
setItems(items);
|
setItems(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant TargetLevelModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant TargetLevelModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
switch(orientation) {
|
switch (orientation) {
|
||||||
case Qt::Horizontal:
|
case Qt::Horizontal:
|
||||||
switch(role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
switch(section) {
|
switch (section) {
|
||||||
case 0:
|
case 0:
|
||||||
return tr("Target level");
|
return tr("Target level");
|
||||||
default:
|
default:;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace Settings
|
||||||
|
|
|
@ -12,15 +12,10 @@ DECLARE_ENUM_CLASS(TagTargetLevel, unsigned char);
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
|
|
||||||
class TargetLevelModel : public Models::ChecklistModel
|
class TargetLevelModel : public Models::ChecklistModel {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum class DefaultSelection
|
enum class DefaultSelection { None, MostUsefulTargets };
|
||||||
{
|
|
||||||
None,
|
|
||||||
MostUsefulTargets
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char *fieldName(TagParser::TagTargetLevel targetLevel);
|
static const char *fieldName(TagParser::TagTargetLevel targetLevel);
|
||||||
static QString translatedFieldName(TagParser::TagTargetLevel targetLevel);
|
static QString translatedFieldName(TagParser::TagTargetLevel targetLevel);
|
||||||
|
@ -38,6 +33,6 @@ inline Models::ChecklistItem TargetLevelModel::mkItem(TagParser::TagTargetLevel
|
||||||
return Models::ChecklistItem(static_cast<int>(field), translatedFieldName(field), checkState);
|
return Models::ChecklistItem(static_cast<int>(field), translatedFieldName(field), checkState);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace Settings
|
||||||
|
|
||||||
#endif // TARGETLEVELMODEL_H
|
#endif // TARGETLEVELMODEL_H
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,12 +8,11 @@
|
||||||
namespace TagParser {
|
namespace TagParser {
|
||||||
class MediaFileInfo;
|
class MediaFileInfo;
|
||||||
class Diagnostics;
|
class Diagnostics;
|
||||||
}
|
} // namespace TagParser
|
||||||
|
|
||||||
namespace HtmlInfo {
|
namespace HtmlInfo {
|
||||||
|
|
||||||
QByteArray generateInfo(const TagParser::MediaFileInfo &file, TagParser::Diagnostics &diag, TagParser::Diagnostics &diagReparsing);
|
QByteArray generateInfo(const TagParser::MediaFileInfo &file, TagParser::Diagnostics &diag, TagParser::Diagnostics &diagReparsing);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HTMLINFO_H
|
#endif // HTMLINFO_H
|
||||||
|
|
114
misc/utility.cpp
114
misc/utility.cpp
|
@ -3,34 +3,33 @@
|
||||||
#include "../application/settings.h"
|
#include "../application/settings.h"
|
||||||
|
|
||||||
#include <tagparser/exceptions.h>
|
#include <tagparser/exceptions.h>
|
||||||
#include <tagparser/signature.h>
|
|
||||||
#include <tagparser/mediafileinfo.h>
|
|
||||||
#include <tagparser/tag.h>
|
|
||||||
#include <tagparser/id3/id3v1tag.h>
|
#include <tagparser/id3/id3v1tag.h>
|
||||||
#include <tagparser/id3/id3v2tag.h>
|
#include <tagparser/id3/id3v2tag.h>
|
||||||
|
#include <tagparser/mediafileinfo.h>
|
||||||
|
#include <tagparser/signature.h>
|
||||||
|
#include <tagparser/tag.h>
|
||||||
|
|
||||||
#include <c++utilities/io/path.h>
|
#include <c++utilities/io/path.h>
|
||||||
|
|
||||||
|
#include <QAbstractItemModel>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QAbstractItemModel>
|
|
||||||
|
|
||||||
#include <ios>
|
#include <ios>
|
||||||
#include <stdexcept>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace TagParser;
|
using namespace TagParser;
|
||||||
|
|
||||||
namespace Utility
|
namespace Utility {
|
||||||
{
|
|
||||||
|
|
||||||
const char *textEncodingToCodecName(TagTextEncoding textEncoding)
|
const char *textEncodingToCodecName(TagTextEncoding textEncoding)
|
||||||
{
|
{
|
||||||
switch(textEncoding) {
|
switch (textEncoding) {
|
||||||
case TagTextEncoding::Latin1:
|
case TagTextEncoding::Latin1:
|
||||||
return "ISO 8859-1";
|
return "ISO 8859-1";
|
||||||
case TagTextEncoding::Utf8:
|
case TagTextEncoding::Utf8:
|
||||||
|
@ -47,8 +46,8 @@ const char *textEncodingToCodecName(TagTextEncoding textEncoding)
|
||||||
|
|
||||||
QString tagValueToQString(const TagValue &value)
|
QString tagValueToQString(const TagValue &value)
|
||||||
{
|
{
|
||||||
if(!value.isEmpty()) {
|
if (!value.isEmpty()) {
|
||||||
switch(value.type()) {
|
switch (value.type()) {
|
||||||
case TagDataType::Text:
|
case TagDataType::Text:
|
||||||
return dataToQString(value.dataPointer(), value.dataSize(), value.dataEncoding());
|
return dataToQString(value.dataPointer(), value.dataSize(), value.dataEncoding());
|
||||||
case TagDataType::Integer:
|
case TagDataType::Integer:
|
||||||
|
@ -57,8 +56,7 @@ QString tagValueToQString(const TagValue &value)
|
||||||
case TagDataType::TimeSpan:
|
case TagDataType::TimeSpan:
|
||||||
case TagDataType::PositionInSet:
|
case TagDataType::PositionInSet:
|
||||||
return QString::fromUtf8(value.toString().c_str());
|
return QString::fromUtf8(value.toString().c_str());
|
||||||
default:
|
default:;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
|
@ -66,10 +64,10 @@ QString tagValueToQString(const TagValue &value)
|
||||||
|
|
||||||
QString dataToQString(const char *data, size_t dataSize, TagTextEncoding encoding)
|
QString dataToQString(const char *data, size_t dataSize, TagTextEncoding encoding)
|
||||||
{
|
{
|
||||||
if(data && dataSize) {
|
if (data && dataSize) {
|
||||||
const char *codecName = textEncodingToCodecName(encoding);
|
const char *codecName = textEncodingToCodecName(encoding);
|
||||||
auto *codec = QTextCodec::codecForName(codecName);
|
auto *codec = QTextCodec::codecForName(codecName);
|
||||||
if(!codec) {
|
if (!codec) {
|
||||||
codec = QTextCodec::codecForLocale();
|
codec = QTextCodec::codecForLocale();
|
||||||
}
|
}
|
||||||
return codec->toUnicode(data, static_cast<int>(dataSize));
|
return codec->toUnicode(data, static_cast<int>(dataSize));
|
||||||
|
@ -79,10 +77,10 @@ QString dataToQString(const char *data, size_t dataSize, TagTextEncoding encodin
|
||||||
|
|
||||||
QString stringToQString(const string &value, TagTextEncoding textEncoding)
|
QString stringToQString(const string &value, TagTextEncoding textEncoding)
|
||||||
{
|
{
|
||||||
if(!value.empty()) {
|
if (!value.empty()) {
|
||||||
const char *codecName = textEncodingToCodecName(textEncoding);
|
const char *codecName = textEncodingToCodecName(textEncoding);
|
||||||
auto *codec = QTextCodec::codecForName(codecName);
|
auto *codec = QTextCodec::codecForName(codecName);
|
||||||
if(!codec) {
|
if (!codec) {
|
||||||
codec = QTextCodec::codecForLocale();
|
codec = QTextCodec::codecForLocale();
|
||||||
}
|
}
|
||||||
return codec->toUnicode(value.c_str());
|
return codec->toUnicode(value.c_str());
|
||||||
|
@ -92,10 +90,10 @@ QString stringToQString(const string &value, TagTextEncoding textEncoding)
|
||||||
|
|
||||||
string qstringToString(const QString &value, TagTextEncoding textEncoding)
|
string qstringToString(const QString &value, TagTextEncoding textEncoding)
|
||||||
{
|
{
|
||||||
if(!value.isEmpty()) {
|
if (!value.isEmpty()) {
|
||||||
const char *codecName = textEncodingToCodecName(textEncoding);
|
const char *codecName = textEncodingToCodecName(textEncoding);
|
||||||
auto *codec = QTextCodec::codecForName(codecName);
|
auto *codec = QTextCodec::codecForName(codecName);
|
||||||
if(!codec) {
|
if (!codec) {
|
||||||
codec = QTextCodec::codecForLocale();
|
codec = QTextCodec::codecForLocale();
|
||||||
}
|
}
|
||||||
const auto encodedString = codec->fromUnicode(value);
|
const auto encodedString = codec->fromUnicode(value);
|
||||||
|
@ -111,13 +109,12 @@ TagValue qstringToTagValue(const QString &value, TagTextEncoding textEncoding)
|
||||||
|
|
||||||
QString elementPositionToQString(ElementPosition elementPosition)
|
QString elementPositionToQString(ElementPosition elementPosition)
|
||||||
{
|
{
|
||||||
switch(elementPosition) {
|
switch (elementPosition) {
|
||||||
case ElementPosition::BeforeData:
|
case ElementPosition::BeforeData:
|
||||||
return QCoreApplication::translate("Utility", "before data");
|
return QCoreApplication::translate("Utility", "before data");
|
||||||
case ElementPosition::AfterData:
|
case ElementPosition::AfterData:
|
||||||
return QCoreApplication::translate("Utility", "after data");
|
return QCoreApplication::translate("Utility", "after data");
|
||||||
case ElementPosition::Keep:
|
case ElementPosition::Keep:;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
@ -126,27 +123,27 @@ QString formatName(const QString &str, bool underscoreToWhitespace)
|
||||||
{
|
{
|
||||||
QString res;
|
QString res;
|
||||||
bool whitespace = true;
|
bool whitespace = true;
|
||||||
for(int i = 0, size = str.size(); i != size; ++i) {
|
for (int i = 0, size = str.size(); i != size; ++i) {
|
||||||
const QChar current = str.at(i);
|
const QChar current = str.at(i);
|
||||||
if(current.isSpace() || current == QChar('(') || current == QChar('[')) {
|
if (current.isSpace() || current == QChar('(') || current == QChar('[')) {
|
||||||
whitespace = true;
|
whitespace = true;
|
||||||
res += current;
|
res += current;
|
||||||
} else if(underscoreToWhitespace && current == QChar('_')) {
|
} else if (underscoreToWhitespace && current == QChar('_')) {
|
||||||
whitespace = true;
|
whitespace = true;
|
||||||
res += ' ';
|
res += ' ';
|
||||||
} else if(whitespace) {
|
} else if (whitespace) {
|
||||||
if(i) {
|
if (i) {
|
||||||
auto rest = str.midRef(i);
|
auto rest = str.midRef(i);
|
||||||
static const char *const connectingWords[] = {"the ", "a ", "an ", "of ", "or ", "and ", "in ", "to ", "at ", "on ", "as "};
|
static const char *const connectingWords[] = { "the ", "a ", "an ", "of ", "or ", "and ", "in ", "to ", "at ", "on ", "as " };
|
||||||
for(const char *word : connectingWords) {
|
for (const char *word : connectingWords) {
|
||||||
if(rest.startsWith(QLatin1String(word), Qt::CaseInsensitive)) {
|
if (rest.startsWith(QLatin1String(word), Qt::CaseInsensitive)) {
|
||||||
res += current.toLower();
|
res += current.toLower();
|
||||||
whitespace = false;
|
whitespace = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(whitespace) {
|
if (whitespace) {
|
||||||
res += current.toUpper();
|
res += current.toUpper();
|
||||||
whitespace = false;
|
whitespace = false;
|
||||||
}
|
}
|
||||||
|
@ -160,26 +157,23 @@ QString formatName(const QString &str, bool underscoreToWhitespace)
|
||||||
QString fixUmlauts(const QString &str)
|
QString fixUmlauts(const QString &str)
|
||||||
{
|
{
|
||||||
auto words = str.split(QChar(' '));
|
auto words = str.split(QChar(' '));
|
||||||
static const QLatin1String exceptions[] = {
|
static const QLatin1String exceptions[] = { QLatin1String("reggae"), QLatin1String("blues"), QLatin1String("auer"), QLatin1String("aues"),
|
||||||
QLatin1String("reggae"), QLatin1String("blues"), QLatin1String("auer"), QLatin1String("aues"), QLatin1String("manuel"),
|
QLatin1String("manuel"), QLatin1String("duet"), QLatin1String("neue"), QLatin1String("prologue") };
|
||||||
QLatin1String("duet"), QLatin1String("neue"), QLatin1String("prologue")
|
static const QLatin1String pairs[6][2] = { { QLatin1String("ae"), QLatin1String("\xe4") }, { QLatin1String("ue"), QLatin1String("\xfc") },
|
||||||
};
|
{ QLatin1String("oe"), QLatin1String("\xf6") }, { QLatin1String("Ae"), QLatin1String("\xc4") },
|
||||||
static const QLatin1String pairs[6][2] = {
|
{ QLatin1String("Ue"), QLatin1String("\xdc") }, { QLatin1String("Oe"), QLatin1String("\xd6") } };
|
||||||
{QLatin1String("ae"), QLatin1String("\xe4")}, {QLatin1String("ue"), QLatin1String("\xfc")}, {QLatin1String("oe"), QLatin1String("\xf6")},
|
for (auto &word : words) {
|
||||||
{QLatin1String("Ae"), QLatin1String("\xc4")}, {QLatin1String("Ue"), QLatin1String("\xdc")}, {QLatin1String("Oe"), QLatin1String("\xd6")}
|
|
||||||
};
|
|
||||||
for(auto &word : words) {
|
|
||||||
// preserve words containing any of the exceptions
|
// preserve words containing any of the exceptions
|
||||||
for(const auto &exception : exceptions) {
|
for (const auto &exception : exceptions) {
|
||||||
if(word.contains(exception, Qt::CaseInsensitive)) {
|
if (word.contains(exception, Qt::CaseInsensitive)) {
|
||||||
goto continueOuterLoop;
|
goto continueOuterLoop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fix all umlauts
|
// fix all umlauts
|
||||||
for(const auto *pair : pairs) {
|
for (const auto *pair : pairs) {
|
||||||
word = word.replace(pair[0], pair[1], Qt::CaseSensitive);
|
word = word.replace(pair[0], pair[1], Qt::CaseSensitive);
|
||||||
}
|
}
|
||||||
continueOuterLoop:;
|
continueOuterLoop:;
|
||||||
}
|
}
|
||||||
return words.join(' ');
|
return words.join(' ');
|
||||||
}
|
}
|
||||||
|
@ -189,24 +183,22 @@ void parseFileName(const QString &fileName, QString &title, int &trackNumber)
|
||||||
title = fileName.trimmed();
|
title = fileName.trimmed();
|
||||||
trackNumber = 0;
|
trackNumber = 0;
|
||||||
int lastPoint = title.lastIndexOf(QChar('.'));
|
int lastPoint = title.lastIndexOf(QChar('.'));
|
||||||
if(lastPoint > 0) {
|
if (lastPoint > 0) {
|
||||||
title.truncate(lastPoint);
|
title.truncate(lastPoint);
|
||||||
} else if(lastPoint == 0) {
|
} else if (lastPoint == 0) {
|
||||||
title.remove(0, 1);
|
title.remove(0, 1);
|
||||||
}
|
}
|
||||||
static const QLatin1String delims[] = {
|
static const QLatin1String delims[] = { QLatin1String(" - "), QLatin1String(", "), QLatin1String("-"), QLatin1String(" ") };
|
||||||
QLatin1String(" - "), QLatin1String(", "), QLatin1String("-"), QLatin1String(" ")
|
for (const auto &delim : delims) {
|
||||||
};
|
|
||||||
for(const auto &delim : delims) {
|
|
||||||
int lastDelimIndex = 0;
|
int lastDelimIndex = 0;
|
||||||
int delimIndex = title.indexOf(delim);
|
int delimIndex = title.indexOf(delim);
|
||||||
while(delimIndex > lastDelimIndex) {
|
while (delimIndex > lastDelimIndex) {
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
trackNumber = title.midRef(lastDelimIndex, delimIndex - lastDelimIndex).toInt(&ok);
|
trackNumber = title.midRef(lastDelimIndex, delimIndex - lastDelimIndex).toInt(&ok);
|
||||||
if(ok) {
|
if (ok) {
|
||||||
int titleStart = delimIndex + delim.size();
|
int titleStart = delimIndex + delim.size();
|
||||||
for(const auto &delim : delims) {
|
for (const auto &delim : delims) {
|
||||||
if(title.midRef(titleStart).startsWith(delim)) {
|
if (title.midRef(titleStart).startsWith(delim)) {
|
||||||
titleStart += delim.size();
|
titleStart += delim.size();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -229,12 +221,12 @@ QString printModel(QAbstractItemModel *model)
|
||||||
|
|
||||||
void printModelIndex(const QModelIndex &index, QString &res, int level)
|
void printModelIndex(const QModelIndex &index, QString &res, int level)
|
||||||
{
|
{
|
||||||
if(index.isValid()) {
|
if (index.isValid()) {
|
||||||
const auto data = index.data().toString();
|
const auto data = index.data().toString();
|
||||||
if(!data.isEmpty()) {
|
if (!data.isEmpty()) {
|
||||||
switch(index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
for(int i = 0; i < level; ++i) {
|
for (int i = 0; i < level; ++i) {
|
||||||
res += "\t";
|
res += "\t";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -247,16 +239,16 @@ void printModelIndex(const QModelIndex &index, QString &res, int level)
|
||||||
const auto nextInCol = index.sibling(index.row(), index.column() + 1);
|
const auto nextInCol = index.sibling(index.row(), index.column() + 1);
|
||||||
const auto child = index.child(0, 0);
|
const auto child = index.child(0, 0);
|
||||||
const auto next = index.sibling(index.row() + 1, 0);
|
const auto next = index.sibling(index.row() + 1, 0);
|
||||||
if(nextInCol.isValid()) {
|
if (nextInCol.isValid()) {
|
||||||
printModelIndex(nextInCol, res, level);
|
printModelIndex(nextInCol, res, level);
|
||||||
} else {
|
} else {
|
||||||
res += "\n";
|
res += "\n";
|
||||||
}
|
}
|
||||||
if(index.column() == 0) {
|
if (index.column() == 0) {
|
||||||
printModelIndex(child, res, level + 1);
|
printModelIndex(child, res, level + 1);
|
||||||
printModelIndex(next, res, level);
|
printModelIndex(next, res, level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace Utility
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace TagParser {
|
||||||
class MediaFileInfo;
|
class MediaFileInfo;
|
||||||
class Tag;
|
class Tag;
|
||||||
enum class ElementPosition;
|
enum class ElementPosition;
|
||||||
}
|
} // namespace TagParser
|
||||||
|
|
||||||
namespace Utility {
|
namespace Utility {
|
||||||
|
|
||||||
|
@ -40,6 +40,6 @@ constexpr int trQuandity(quint64 quandity)
|
||||||
return quandity > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : static_cast<int>(quandity);
|
return quandity > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : static_cast<int>(quandity);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace Utility
|
||||||
|
|
||||||
#endif // UTILITYFEATURES_H
|
#endif // UTILITYFEATURES_H
|
||||||
|
|
Loading…
Reference in New Issue