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