Add option to allow extended ascii characters, save/restore geometry
This commit is contained in:
@@ -75,8 +75,7 @@ OrganiseDialog::OrganiseDialog(TaskManager *task_manager, QWidget *parent)
|
|||||||
: QDialog(parent),
|
: QDialog(parent),
|
||||||
ui_(new Ui_OrganiseDialog),
|
ui_(new Ui_OrganiseDialog),
|
||||||
task_manager_(task_manager),
|
task_manager_(task_manager),
|
||||||
total_size_(0),
|
total_size_(0) {
|
||||||
resized_by_user_(false) {
|
|
||||||
|
|
||||||
ui_->setupUi(this);
|
ui_->setupUi(this);
|
||||||
connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()), SLOT(Reset()));
|
connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()), SLOT(Reset()));
|
||||||
@@ -112,7 +111,9 @@ OrganiseDialog::OrganiseDialog(TaskManager *task_manager, QWidget *parent)
|
|||||||
connect(ui_->naming, SIGNAL(textChanged()), SLOT(UpdatePreviews()));
|
connect(ui_->naming, SIGNAL(textChanged()), 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_->replace_spaces, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
connect(ui_->replace_spaces, SIGNAL(toggled(bool)), SLOT(UpdatePreviews()));
|
||||||
|
connect(ui_->remove_non_ascii, SIGNAL(toggled(bool)), SLOT(AllowExtASCII(bool)));
|
||||||
|
|
||||||
// Get the titles of the tags to put in the insert menu
|
// Get the titles of the tags to put in the insert menu
|
||||||
QStringList tag_titles = tags.keys();
|
QStringList tag_titles = tags.keys();
|
||||||
@@ -127,7 +128,16 @@ OrganiseDialog::OrganiseDialog(TaskManager *task_manager, QWidget *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
connect(tag_mapper, SIGNAL(mapped(QString)), SLOT(InsertTag(QString)));
|
connect(tag_mapper, SIGNAL(mapped(QString)), SLOT(InsertTag(QString)));
|
||||||
|
|
||||||
ui_->insert->setMenu(tag_menu);
|
ui_->insert->setMenu(tag_menu);
|
||||||
|
|
||||||
|
QSettings s;
|
||||||
|
s.beginGroup(kSettingsGroup);
|
||||||
|
if (s.contains("geometry")) {
|
||||||
|
restoreGeometry(s.value("geometry").toByteArray());
|
||||||
|
}
|
||||||
|
s.endGroup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OrganiseDialog::~OrganiseDialog() {
|
OrganiseDialog::~OrganiseDialog() {
|
||||||
@@ -296,6 +306,7 @@ void OrganiseDialog::UpdatePreviews() {
|
|||||||
format_.set_format(ui_->naming->toPlainText());
|
format_.set_format(ui_->naming->toPlainText());
|
||||||
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_replace_spaces(ui_->replace_spaces->isChecked());
|
format_.set_replace_spaces(ui_->replace_spaces->isChecked());
|
||||||
|
|
||||||
const bool format_valid = !has_local_destination || format_.IsValid();
|
const bool format_valid = !has_local_destination || format_.IsValid();
|
||||||
@@ -320,10 +331,6 @@ void OrganiseDialog::UpdatePreviews() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resized_by_user_) {
|
|
||||||
adjustSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize OrganiseDialog::sizeHint() const { return QSize(650, 0); }
|
QSize OrganiseDialog::sizeHint() const { return QSize(650, 0); }
|
||||||
@@ -333,6 +340,7 @@ void OrganiseDialog::Reset() {
|
|||||||
ui_->naming->setPlainText(kDefaultFormat);
|
ui_->naming->setPlainText(kDefaultFormat);
|
||||||
ui_->remove_non_fat->setChecked(false);
|
ui_->remove_non_fat->setChecked(false);
|
||||||
ui_->remove_non_ascii->setChecked(false);
|
ui_->remove_non_ascii->setChecked(false);
|
||||||
|
ui_->allow_ascii_ext->setChecked(false);
|
||||||
ui_->replace_spaces->setChecked(true);
|
ui_->replace_spaces->setChecked(true);
|
||||||
ui_->overwrite->setChecked(false);
|
ui_->overwrite->setChecked(false);
|
||||||
ui_->mark_as_listened->setChecked(false);
|
ui_->mark_as_listened->setChecked(false);
|
||||||
@@ -343,13 +351,12 @@ void OrganiseDialog::Reset() {
|
|||||||
|
|
||||||
void OrganiseDialog::showEvent(QShowEvent*) {
|
void OrganiseDialog::showEvent(QShowEvent*) {
|
||||||
|
|
||||||
resized_by_user_ = false;
|
|
||||||
|
|
||||||
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_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_->replace_spaces->setChecked(s.value("replace_spaces", true).toBool());
|
ui_->replace_spaces->setChecked(s.value("replace_spaces", true).toBool());
|
||||||
ui_->overwrite->setChecked(s.value("overwrite", false).toBool());
|
ui_->overwrite->setChecked(s.value("overwrite", false).toBool());
|
||||||
ui_->albumcover->setChecked(s.value("albumcover", true).toBool());
|
ui_->albumcover->setChecked(s.value("albumcover", true).toBool());
|
||||||
@@ -362,6 +369,10 @@ void OrganiseDialog::showEvent(QShowEvent*) {
|
|||||||
ui_->destination->setCurrentIndex(index);
|
ui_->destination->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.endGroup();
|
||||||
|
|
||||||
|
AllowExtASCII(ui_->remove_non_ascii->isChecked());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrganiseDialog::accept() {
|
void OrganiseDialog::accept() {
|
||||||
@@ -372,12 +383,14 @@ void OrganiseDialog::accept() {
|
|||||||
s.setValue("format", ui_->naming->toPlainText());
|
s.setValue("format", ui_->naming->toPlainText());
|
||||||
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("replace_spaces", ui_->replace_spaces->isChecked());
|
s.setValue("replace_spaces", ui_->replace_spaces->isChecked());
|
||||||
s.setValue("overwrite", ui_->overwrite->isChecked());
|
s.setValue("overwrite", ui_->overwrite->isChecked());
|
||||||
s.setValue("mark_as_listened", ui_->overwrite->isChecked());
|
s.setValue("mark_as_listened", ui_->overwrite->isChecked());
|
||||||
s.setValue("albumcover", ui_->albumcover->isChecked());
|
s.setValue("albumcover", ui_->albumcover->isChecked());
|
||||||
s.setValue("destination", ui_->destination->currentText());
|
s.setValue("destination", ui_->destination->currentText());
|
||||||
s.setValue("eject_after", ui_->eject_after->isChecked());
|
s.setValue("eject_after", ui_->eject_after->isChecked());
|
||||||
|
s.endGroup();
|
||||||
|
|
||||||
const QModelIndex destination = ui_->destination->model()->index(ui_->destination->currentIndex(), 0);
|
const QModelIndex destination = ui_->destination->model()->index(ui_->destination->currentIndex(), 0);
|
||||||
std::shared_ptr<MusicStorage> storage = destination.data(MusicStorage::Role_StorageForceConnect).value<std::shared_ptr<MusicStorage>>();
|
std::shared_ptr<MusicStorage> storage = destination.data(MusicStorage::Role_StorageForceConnect).value<std::shared_ptr<MusicStorage>>();
|
||||||
@@ -391,7 +404,26 @@ void OrganiseDialog::accept() {
|
|||||||
connect(organise, SIGNAL(FileCopied(int)), this, SIGNAL(FileCopied(int)));
|
connect(organise, SIGNAL(FileCopied(int)), this, SIGNAL(FileCopied(int)));
|
||||||
organise->Start();
|
organise->Start();
|
||||||
|
|
||||||
|
SaveGeometry();
|
||||||
|
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OrganiseDialog::reject() {
|
||||||
|
|
||||||
|
SaveGeometry();
|
||||||
|
QDialog::reject();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void OrganiseDialog::SaveGeometry() {
|
||||||
|
|
||||||
|
QSettings s;
|
||||||
|
s.beginGroup(kSettingsGroup);
|
||||||
|
s.setValue("geometry", saveGeometry());
|
||||||
|
s.endGroup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrganiseDialog::OrganiseFinished(const QStringList files_with_errors, const QStringList log) {
|
void OrganiseDialog::OrganiseFinished(const QStringList files_with_errors, const QStringList log) {
|
||||||
@@ -401,11 +433,6 @@ void OrganiseDialog::OrganiseFinished(const QStringList files_with_errors, const
|
|||||||
error_dialog_->Show(OrganiseErrorDialog::Type_Copy, files_with_errors, log);
|
error_dialog_->Show(OrganiseErrorDialog::Type_Copy, files_with_errors, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrganiseDialog::resizeEvent(QResizeEvent *e) {
|
void OrganiseDialog::AllowExtASCII(bool checked) {
|
||||||
if (e->spontaneous()) {
|
ui_->allow_ascii_ext->setEnabled(checked);
|
||||||
resized_by_user_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDialog::resizeEvent(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,9 +58,6 @@ class OrganiseDialog : public QDialog {
|
|||||||
OrganiseDialog(TaskManager *task_manager, QWidget *parent = nullptr);
|
OrganiseDialog(TaskManager *task_manager, QWidget *parent = nullptr);
|
||||||
~OrganiseDialog();
|
~OrganiseDialog();
|
||||||
|
|
||||||
static const char *kDefaultFormat;
|
|
||||||
static const char *kSettingsGroup;
|
|
||||||
|
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const;
|
||||||
|
|
||||||
void SetDestinationModel(QAbstractItemModel *model, bool devices = false);
|
void SetDestinationModel(QAbstractItemModel *model, bool devices = false);
|
||||||
@@ -78,10 +75,10 @@ class OrganiseDialog : public QDialog {
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void accept();
|
void accept();
|
||||||
|
void reject();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *);
|
void showEvent(QShowEvent *);
|
||||||
void resizeEvent(QResizeEvent *);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void Reset();
|
void Reset();
|
||||||
@@ -91,12 +88,20 @@ class OrganiseDialog : public QDialog {
|
|||||||
|
|
||||||
void OrganiseFinished(const QStringList files_with_errors, const QStringList log);
|
void OrganiseFinished(const QStringList files_with_errors, const QStringList log);
|
||||||
|
|
||||||
|
void AllowExtASCII(bool checked);
|
||||||
|
|
||||||
|
void SaveGeometry();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SongList LoadSongsBlocking(const QStringList &filenames);
|
SongList LoadSongsBlocking(const QStringList &filenames);
|
||||||
void SetLoadingSongs(bool loading);
|
void SetLoadingSongs(bool loading);
|
||||||
|
|
||||||
static Organise::NewSongInfoList ComputeNewSongsFilenames(const SongList &songs, const OrganiseFormat &format);
|
static Organise::NewSongInfoList ComputeNewSongsFilenames(const SongList &songs, const OrganiseFormat &format);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const char *kDefaultFormat;
|
||||||
|
static const char *kSettingsGroup;
|
||||||
|
|
||||||
Ui_OrganiseDialog *ui_;
|
Ui_OrganiseDialog *ui_;
|
||||||
TaskManager *task_manager_;
|
TaskManager *task_manager_;
|
||||||
|
|
||||||
@@ -109,7 +114,6 @@ class OrganiseDialog : public QDialog {
|
|||||||
|
|
||||||
std::unique_ptr<OrganiseErrorDialog> error_dialog_;
|
std::unique_ptr<OrganiseErrorDialog> error_dialog_;
|
||||||
|
|
||||||
bool resized_by_user_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ORGANISEDIALOG_H
|
#endif // ORGANISEDIALOG_H
|
||||||
|
|||||||
@@ -2,14 +2,6 @@
|
|||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>OrganiseDialog</class>
|
<class>OrganiseDialog</class>
|
||||||
<widget class="QDialog" name="OrganiseDialog">
|
<widget class="QDialog" name="OrganiseDialog">
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>588</width>
|
|
||||||
<height>608</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Organise Files</string>
|
<string>Organise Files</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -17,7 +9,7 @@
|
|||||||
<iconset resource="../../data/icons.qrc">
|
<iconset resource="../../data/icons.qrc">
|
||||||
<normaloff>:/icons/64x64/strawberry.png</normaloff>:/icons/64x64/strawberry.png</iconset>
|
<normaloff>:/icons/64x64/strawberry.png</normaloff>:/icons/64x64/strawberry.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="layout_dialog">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QFormLayout" name="layout_copying">
|
<layout class="QFormLayout" name="layout_copying">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
@@ -105,6 +97,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="allow_ascii_ext">
|
||||||
|
<property name="text">
|
||||||
|
<string>Allow extended ASCII characters</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="replace_spaces">
|
<widget class="QCheckBox" name="replace_spaces">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ OrganiseFormat::OrganiseFormat(const QString &format)
|
|||||||
: format_(format),
|
: format_(format),
|
||||||
remove_non_fat_(false),
|
remove_non_fat_(false),
|
||||||
remove_non_ascii_(false),
|
remove_non_ascii_(false),
|
||||||
|
allow_ascii_ext_(false),
|
||||||
replace_spaces_(true) {}
|
replace_spaces_(true) {}
|
||||||
|
|
||||||
void OrganiseFormat::set_format(const QString &v) {
|
void OrganiseFormat::set_format(const QString &v) {
|
||||||
@@ -115,21 +116,29 @@ QString OrganiseFormat::GetFilenameForSong(const Song &song) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (remove_non_fat_) {
|
if (remove_non_fat_) {
|
||||||
|
filename.replace(230, "ae");
|
||||||
|
filename.replace(198, "AE");
|
||||||
|
filename.replace(248, 'o');
|
||||||
|
filename.replace(216, 'O');
|
||||||
|
filename.replace(229, 'a');
|
||||||
|
filename.replace(197, 'A');
|
||||||
filename.remove(kValidFatCharacters);
|
filename.remove(kValidFatCharacters);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (replace_spaces_) filename.replace(QRegExp("\\s"), "_");
|
if (replace_spaces_) filename.replace(QRegExp("\\s"), "_");
|
||||||
|
|
||||||
if (remove_non_ascii_) {
|
if (remove_non_ascii_) {
|
||||||
|
int ascii = 128;
|
||||||
|
if (allow_ascii_ext_) ascii = 255;
|
||||||
QString stripped;
|
QString stripped;
|
||||||
for (int i = 0; i < filename.length(); ++i) {
|
for (int i = 0; i < filename.length(); ++i) {
|
||||||
const QCharRef c = filename[i];
|
const QCharRef c = filename[i];
|
||||||
if (c < 128) {
|
if (c < ascii) {
|
||||||
stripped.append(c);
|
stripped.append(c);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const QString decomposition = c.decomposition();
|
const QString decomposition = c.decomposition();
|
||||||
if (!decomposition.isEmpty() && decomposition[0] < 128)
|
if (!decomposition.isEmpty() && decomposition[0] < ascii)
|
||||||
stripped.append(decomposition[0]);
|
stripped.append(decomposition[0]);
|
||||||
else
|
else
|
||||||
stripped.append("_");
|
stripped.append("_");
|
||||||
|
|||||||
@@ -53,11 +53,13 @@ class OrganiseFormat {
|
|||||||
QString format() const { return format_; }
|
QString format() const { return format_; }
|
||||||
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 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_non_fat(bool v) { remove_non_fat_ = v; }
|
||||||
void set_remove_non_ascii(bool v) { remove_non_ascii_ = v; }
|
void set_remove_non_ascii(bool v) { remove_non_ascii_ = v; }
|
||||||
|
void set_allow_ascii_ext(bool v) { allow_ascii_ext_ = v; }
|
||||||
void set_replace_spaces(bool v) { replace_spaces_ = v; }
|
void set_replace_spaces(bool v) { replace_spaces_ = v; }
|
||||||
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
@@ -91,6 +93,7 @@ class OrganiseFormat {
|
|||||||
QString format_;
|
QString format_;
|
||||||
bool remove_non_fat_;
|
bool remove_non_fat_;
|
||||||
bool remove_non_ascii_;
|
bool remove_non_ascii_;
|
||||||
|
bool allow_ascii_ext_;
|
||||||
bool replace_spaces_;
|
bool replace_spaces_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user