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