Add option to remove problematic filename characters
This commit is contained in:
@@ -84,7 +84,11 @@ OrganiseDialog::OrganiseDialog(TaskManager *task_manager, CollectionBackend *bac
|
|||||||
|
|
||||||
setWindowFlags(windowFlags()|Qt::WindowMaximizeButtonHint);
|
setWindowFlags(windowFlags()|Qt::WindowMaximizeButtonHint);
|
||||||
|
|
||||||
connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()), SLOT(Reset()));
|
QPushButton *button_save = ui_->button_box->addButton("Save settings", QDialogButtonBox::ApplyRole);
|
||||||
|
connect(button_save, SIGNAL(clicked()), SLOT(SaveSettings()));
|
||||||
|
button_save->setIcon(IconLoader::Load("document-save"));
|
||||||
|
ui_->button_box->button(QDialogButtonBox::RestoreDefaults)->setIcon(IconLoader::Load("edit-undo"));
|
||||||
|
connect(ui_->button_box->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), SLOT(RestoreDefaults()));
|
||||||
|
|
||||||
ui_->aftercopying->setItemIcon(1, IconLoader::Load("edit-delete"));
|
ui_->aftercopying->setItemIcon(1, IconLoader::Load("edit-delete"));
|
||||||
|
|
||||||
@@ -115,6 +119,7 @@ OrganiseDialog::OrganiseDialog(TaskManager *task_manager, CollectionBackend *bac
|
|||||||
|
|
||||||
connect(ui_->destination, SIGNAL(currentIndexChanged(int)), SLOT(UpdatePreviews()));
|
connect(ui_->destination, SIGNAL(currentIndexChanged(int)), SLOT(UpdatePreviews()));
|
||||||
connect(ui_->naming, SIGNAL(textChanged()), SLOT(UpdatePreviews()));
|
connect(ui_->naming, SIGNAL(textChanged()), SLOT(UpdatePreviews()));
|
||||||
|
connect(ui_->remove_problematic, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
||||||
connect(ui_->remove_non_fat, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
connect(ui_->remove_non_fat, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
||||||
connect(ui_->remove_non_ascii, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
connect(ui_->remove_non_ascii, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
||||||
connect(ui_->allow_ascii_ext, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
connect(ui_->allow_ascii_ext, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
||||||
@@ -164,6 +169,7 @@ void OrganiseDialog::closeEvent(QCloseEvent*) {
|
|||||||
|
|
||||||
void OrganiseDialog::accept() {
|
void OrganiseDialog::accept() {
|
||||||
|
|
||||||
|
SaveGeometry();
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
|
|
||||||
const QModelIndex destination = ui_->destination->model()->index(ui_->destination->currentIndex(), 0);
|
const QModelIndex destination = ui_->destination->model()->index(ui_->destination->currentIndex(), 0);
|
||||||
@@ -181,8 +187,6 @@ void OrganiseDialog::accept() {
|
|||||||
|
|
||||||
organise->Start();
|
organise->Start();
|
||||||
|
|
||||||
SaveGeometry();
|
|
||||||
|
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -232,11 +236,29 @@ void OrganiseDialog::SaveGeometry() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OrganiseDialog::RestoreDefaults() {
|
||||||
|
|
||||||
|
ui_->naming->setPlainText(kDefaultFormat);
|
||||||
|
ui_->remove_problematic->setChecked(true);
|
||||||
|
ui_->remove_non_fat->setChecked(false);
|
||||||
|
ui_->remove_non_ascii->setChecked(false);
|
||||||
|
ui_->allow_ascii_ext->setChecked(false);
|
||||||
|
ui_->replace_spaces->setChecked(true);
|
||||||
|
ui_->overwrite->setChecked(false);
|
||||||
|
ui_->mark_as_listened->setChecked(false);
|
||||||
|
ui_->albumcover->setChecked(true);
|
||||||
|
ui_->eject_after->setChecked(false);
|
||||||
|
|
||||||
|
SaveSettings();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void OrganiseDialog::LoadSettings() {
|
void OrganiseDialog::LoadSettings() {
|
||||||
|
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(kSettingsGroup);
|
s.beginGroup(kSettingsGroup);
|
||||||
ui_->naming->setPlainText(s.value("format", kDefaultFormat).toString());
|
ui_->naming->setPlainText(s.value("format", kDefaultFormat).toString());
|
||||||
|
ui_->remove_problematic->setChecked(s.value("remove_problematic", true).toBool());
|
||||||
ui_->remove_non_fat->setChecked(s.value("remove_non_fat", false).toBool());
|
ui_->remove_non_fat->setChecked(s.value("remove_non_fat", false).toBool());
|
||||||
ui_->remove_non_ascii->setChecked(s.value("remove_non_ascii", false).toBool());
|
ui_->remove_non_ascii->setChecked(s.value("remove_non_ascii", false).toBool());
|
||||||
ui_->allow_ascii_ext->setChecked(s.value("allow_ascii_ext", false).toBool());
|
ui_->allow_ascii_ext->setChecked(s.value("allow_ascii_ext", false).toBool());
|
||||||
@@ -263,6 +285,7 @@ void OrganiseDialog::SaveSettings() {
|
|||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(kSettingsGroup);
|
s.beginGroup(kSettingsGroup);
|
||||||
s.setValue("format", ui_->naming->toPlainText());
|
s.setValue("format", ui_->naming->toPlainText());
|
||||||
|
s.setValue("remove_problematic", ui_->remove_problematic->isChecked());
|
||||||
s.setValue("remove_non_fat", ui_->remove_non_fat->isChecked());
|
s.setValue("remove_non_fat", ui_->remove_non_fat->isChecked());
|
||||||
s.setValue("remove_non_ascii", ui_->remove_non_ascii->isChecked());
|
s.setValue("remove_non_ascii", ui_->remove_non_ascii->isChecked());
|
||||||
s.setValue("allow_ascii_ext", ui_->allow_ascii_ext->isChecked());
|
s.setValue("allow_ascii_ext", ui_->allow_ascii_ext->isChecked());
|
||||||
@@ -434,6 +457,7 @@ void OrganiseDialog::UpdatePreviews() {
|
|||||||
|
|
||||||
// Update the format object
|
// Update the format object
|
||||||
format_.set_format(ui_->naming->toPlainText());
|
format_.set_format(ui_->naming->toPlainText());
|
||||||
|
format_.set_remove_problematic(ui_->remove_problematic->isChecked());
|
||||||
format_.set_remove_non_fat(ui_->remove_non_fat->isChecked());
|
format_.set_remove_non_fat(ui_->remove_non_fat->isChecked());
|
||||||
format_.set_remove_non_ascii(ui_->remove_non_ascii->isChecked());
|
format_.set_remove_non_ascii(ui_->remove_non_ascii->isChecked());
|
||||||
format_.set_allow_ascii_ext(ui_->allow_ascii_ext->isChecked());
|
format_.set_allow_ascii_ext(ui_->allow_ascii_ext->isChecked());
|
||||||
@@ -465,20 +489,6 @@ void OrganiseDialog::UpdatePreviews() {
|
|||||||
|
|
||||||
QSize OrganiseDialog::sizeHint() const { return QSize(650, 0); }
|
QSize OrganiseDialog::sizeHint() const { return QSize(650, 0); }
|
||||||
|
|
||||||
void OrganiseDialog::Reset() {
|
|
||||||
|
|
||||||
ui_->naming->setPlainText(kDefaultFormat);
|
|
||||||
ui_->remove_non_fat->setChecked(false);
|
|
||||||
ui_->remove_non_ascii->setChecked(false);
|
|
||||||
ui_->allow_ascii_ext->setChecked(false);
|
|
||||||
ui_->replace_spaces->setChecked(true);
|
|
||||||
ui_->overwrite->setChecked(false);
|
|
||||||
ui_->mark_as_listened->setChecked(false);
|
|
||||||
ui_->albumcover->setChecked(true);
|
|
||||||
ui_->eject_after->setChecked(false);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void OrganiseDialog::OrganiseFinished(const QStringList files_with_errors, const QStringList log) {
|
void OrganiseDialog::OrganiseFinished(const QStringList files_with_errors, const QStringList log) {
|
||||||
if (files_with_errors.isEmpty()) return;
|
if (files_with_errors.isEmpty()) return;
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ class OrganiseDialog : public QDialog {
|
|||||||
void LoadGeometry();
|
void LoadGeometry();
|
||||||
void SaveGeometry();
|
void SaveGeometry();
|
||||||
void LoadSettings();
|
void LoadSettings();
|
||||||
void SaveSettings();
|
|
||||||
|
|
||||||
SongList LoadSongsBlocking(const QStringList &filenames);
|
SongList LoadSongsBlocking(const QStringList &filenames);
|
||||||
void SetLoadingSongs(bool loading);
|
void SetLoadingSongs(bool loading);
|
||||||
@@ -98,7 +97,8 @@ class OrganiseDialog : public QDialog {
|
|||||||
void reject();
|
void reject();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void Reset();
|
void SaveSettings();
|
||||||
|
void RestoreDefaults();
|
||||||
|
|
||||||
void InsertTag(const QString &tag);
|
void InsertTag(const QString &tag);
|
||||||
void UpdatePreviews();
|
void UpdatePreviews();
|
||||||
|
|||||||
@@ -91,6 +91,13 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="remove_problematic">
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove problematic characters from filenames</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="remove_non_fat">
|
<widget class="QCheckBox" name="remove_non_fat">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -242,11 +249,8 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="button_box">
|
<widget class="QDialogButtonBox" name="button_box">
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="standardButtons">
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ const QStringList OrganiseFormat::kKnownTags = QStringList() << "title"
|
|||||||
<< "lyrics";
|
<< "lyrics";
|
||||||
|
|
||||||
const QRegExp OrganiseFormat::kInvalidDirCharacters("[/\\\\]");
|
const QRegExp OrganiseFormat::kInvalidDirCharacters("[/\\\\]");
|
||||||
|
const QRegExp OrganiseFormat::kProblematicCharacters("[:?*\"<>|]");
|
||||||
// From http://en.wikipedia.org/wiki/8.3_filename#Directory_table
|
// From http://en.wikipedia.org/wiki/8.3_filename#Directory_table
|
||||||
const QRegExp OrganiseFormat::kInvalidFatCharacters("[^a-zA-Z0-9!#\\$%&'()\\-@\\^_`{}~/. ]");
|
const QRegExp OrganiseFormat::kInvalidFatCharacters("[^a-zA-Z0-9!#\\$%&'()\\-@\\^_`{}~/. ]");
|
||||||
|
|
||||||
@@ -86,6 +87,7 @@ const QRgb OrganiseFormat::SyntaxHighlighter::kBlockColorDark = qRgb(64, 64, 64)
|
|||||||
|
|
||||||
OrganiseFormat::OrganiseFormat(const QString &format)
|
OrganiseFormat::OrganiseFormat(const QString &format)
|
||||||
: format_(format),
|
: format_(format),
|
||||||
|
remove_problematic_(false),
|
||||||
remove_non_fat_(false),
|
remove_non_fat_(false),
|
||||||
remove_non_ascii_(false),
|
remove_non_ascii_(false),
|
||||||
allow_ascii_ext_(false),
|
allow_ascii_ext_(false),
|
||||||
@@ -116,8 +118,9 @@ QString OrganiseFormat::GetFilenameForSong(const Song &song) const {
|
|||||||
filename = Utilities::PathWithoutFilenameExtension(filename) + song.basefilename();
|
filename = Utilities::PathWithoutFilenameExtension(filename) + song.basefilename();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (remove_problematic_) filename = filename.remove(kProblematicCharacters);
|
||||||
if (remove_non_fat_ || (remove_non_ascii_ && !allow_ascii_ext_)) filename = Utilities::UnicodeToAscii(filename);
|
if (remove_non_fat_ || (remove_non_ascii_ && !allow_ascii_ext_)) filename = Utilities::UnicodeToAscii(filename);
|
||||||
if (remove_non_fat_) filename.remove(kInvalidFatCharacters);
|
if (remove_non_fat_) filename = filename.remove(kInvalidFatCharacters);
|
||||||
|
|
||||||
if (remove_non_ascii_) {
|
if (remove_non_ascii_) {
|
||||||
int ascii = 128;
|
int ascii = 128;
|
||||||
@@ -151,7 +154,7 @@ QString OrganiseFormat::GetFilenameForSong(const Song &song) const {
|
|||||||
QString part = parts_old[i];
|
QString part = parts_old[i];
|
||||||
for (int j = 0 ; j < kInvalidPrefixCharactersCount ; ++j) {
|
for (int j = 0 ; j < kInvalidPrefixCharactersCount ; ++j) {
|
||||||
if (part.startsWith(kInvalidPrefixCharacters[j])) {
|
if (part.startsWith(kInvalidPrefixCharacters[j])) {
|
||||||
part.remove(0, 1);
|
part = part.remove(0, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,6 +265,7 @@ QString OrganiseFormat::TagValue(const QString &tag, const Song &song) const {
|
|||||||
|
|
||||||
// Replace characters that really shouldn't be in paths
|
// Replace characters that really shouldn't be in paths
|
||||||
value = value.remove(kInvalidDirCharacters);
|
value = value.remove(kInvalidDirCharacters);
|
||||||
|
if (remove_problematic_) value = value.remove('.');
|
||||||
value = value.trimmed();
|
value = value.trimmed();
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
|||||||
@@ -44,22 +44,25 @@ class OrganiseFormat {
|
|||||||
static const char *kBlockPattern;
|
static const char *kBlockPattern;
|
||||||
static const QStringList kKnownTags;
|
static const QStringList kKnownTags;
|
||||||
static const QRegExp kInvalidDirCharacters;
|
static const QRegExp kInvalidDirCharacters;
|
||||||
|
static const QRegExp kProblematicCharacters;
|
||||||
static const QRegExp kInvalidFatCharacters;
|
static const QRegExp kInvalidFatCharacters;
|
||||||
|
|
||||||
static const char kInvalidPrefixCharacters[];
|
static const char kInvalidPrefixCharacters[];
|
||||||
static const int kInvalidPrefixCharactersCount;
|
static const int kInvalidPrefixCharactersCount;
|
||||||
|
|
||||||
QString format() const { return format_; }
|
QString format() const { return format_; }
|
||||||
|
bool remove_problematic() const { return remove_problematic_; }
|
||||||
bool remove_non_fat() const { return remove_non_fat_; }
|
bool remove_non_fat() const { return remove_non_fat_; }
|
||||||
bool remove_non_ascii() const { return remove_non_ascii_; }
|
bool remove_non_ascii() const { return remove_non_ascii_; }
|
||||||
bool allow_ascii_ext() const { return allow_ascii_ext_; }
|
bool allow_ascii_ext() const { return allow_ascii_ext_; }
|
||||||
bool replace_spaces() const { return replace_spaces_; }
|
bool replace_spaces() const { return replace_spaces_; }
|
||||||
|
|
||||||
void set_format(const QString &v);
|
void set_format(const QString &v);
|
||||||
void set_remove_non_fat(bool v) { remove_non_fat_ = v; }
|
void set_remove_problematic(const bool v) { remove_problematic_ = v; }
|
||||||
void set_remove_non_ascii(bool v) { remove_non_ascii_ = v; }
|
void set_remove_non_fat(const bool v) { remove_non_fat_ = v; }
|
||||||
void set_allow_ascii_ext(bool v) { allow_ascii_ext_ = v; }
|
void set_remove_non_ascii(const bool v) { remove_non_ascii_ = v; }
|
||||||
void set_replace_spaces(bool v) { replace_spaces_ = v; }
|
void set_allow_ascii_ext(const bool v) { allow_ascii_ext_ = v; }
|
||||||
|
void set_replace_spaces(const bool v) { replace_spaces_ = v; }
|
||||||
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
QString GetFilenameForSong(const Song &song) const;
|
QString GetFilenameForSong(const Song &song) const;
|
||||||
@@ -90,6 +93,7 @@ class OrganiseFormat {
|
|||||||
QString TagValue(const QString &tag, const Song &song) const;
|
QString TagValue(const QString &tag, const Song &song) const;
|
||||||
|
|
||||||
QString format_;
|
QString format_;
|
||||||
|
bool remove_problematic_;
|
||||||
bool remove_non_fat_;
|
bool remove_non_fat_;
|
||||||
bool remove_non_ascii_;
|
bool remove_non_ascii_;
|
||||||
bool allow_ascii_ext_;
|
bool allow_ascii_ext_;
|
||||||
|
|||||||
Reference in New Issue
Block a user