From db5b68f071652db2be954408c920dd0b0ba183dc Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Fri, 7 Oct 2011 17:43:49 +0000 Subject: converter: added presets support, fixed flac preset, enabled 'cancel' button git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@2381 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/converter/converter.cpp | 74 ++++++++++++++++++---- src/plugins/General/converter/converter.h | 13 +++- src/plugins/General/converter/converterdialog.cpp | 29 ++++----- src/plugins/General/converter/converterdialog.h | 1 + src/plugins/General/converter/converterhelper.cpp | 9 ++- src/plugins/General/converter/presets.conf | 2 +- .../converter/translations/converter_plugin_cs.ts | 49 ++++++++------ .../converter/translations/converter_plugin_de.ts | 49 ++++++++------ .../converter/translations/converter_plugin_es.ts | 49 ++++++++------ .../converter/translations/converter_plugin_it.ts | 49 ++++++++------ .../converter/translations/converter_plugin_ja.ts | 49 ++++++++------ .../converter/translations/converter_plugin_lt.ts | 49 ++++++++------ .../converter/translations/converter_plugin_nl.ts | 49 ++++++++------ .../converter/translations/converter_plugin_pl.ts | 49 ++++++++------ .../converter/translations/converter_plugin_ru.ts | 49 ++++++++------ .../converter/translations/converter_plugin_tr.ts | 49 ++++++++------ .../translations/converter_plugin_uk_UA.ts | 55 ++++++++++------ .../translations/converter_plugin_zh_CN.ts | 49 ++++++++------ .../translations/converter_plugin_zh_TW.ts | 49 ++++++++------ 19 files changed, 502 insertions(+), 269 deletions(-) (limited to 'src') diff --git a/src/plugins/General/converter/converter.cpp b/src/plugins/General/converter/converter.cpp index 68746ff2f..441b97e09 100644 --- a/src/plugins/General/converter/converter.cpp +++ b/src/plugins/General/converter/converter.cpp @@ -32,13 +32,18 @@ Converter::Converter(QObject *parent) : QThread(parent) {} -void Converter::add(const QStringList &urls) +Converter::~Converter() +{ + stop(); +} + +void Converter::add(const QStringList &urls, const QVariantMap &preset) { foreach(QString url, urls) - add(url); + add(url, preset); } -void Converter::add(const QString &url) +void Converter::add(const QString &url, const QVariantMap &preset) { InputSource *source = InputSource::create(url, this); if(!source->initialize()) @@ -88,41 +93,64 @@ void Converter::add(const QString &url) } m_decoders.enqueue(decoder); m_inputs.insert(decoder, source); + m_presets.insert(decoder, preset); if(!decoder->totalTime()) source->setOffset(-1); source->setParent(this); } +void Converter::stop() +{ + m_mutex.lock(); + m_user_stop = true; + m_mutex.unlock(); + wait(); + m_presets.clear(); + qDeleteAll(m_inputs.values()); + m_inputs.clear(); + qDeleteAll(m_decoders); + m_decoders.clear(); +} + void Converter::run() { - QSettings settings(Qmmp::configFile(), QSettings::IniFormat); - QString music_path = QDesktopServices::storageLocation(QDesktopServices::MusicLocation); - QString path = settings.value("Converter/out_dir", music_path).toString(); - QString pattern = settings.value("Converter/file_name","%p - %t").toString(); - MetaDataFormatter formatter(pattern); + qDebug("Converter: staring thread"); + m_user_stop = false; MetaDataFormatter desc_formatter("%p%if(%p&%t, - ,)%t [%l]"); while(!m_decoders.isEmpty()) { Decoder *decoder = m_decoders.dequeue(); + QVariantMap preset = m_presets.take(decoder); AudioParameters ap = decoder->audioParameters(); QString url = m_inputs[decoder]->url(); + QString out_path = preset["out_dir"].toString(); + QString pattern = preset["file_name"].toString(); QList list = MetaDataManager::instance()->createPlayList(url); - if(list.isEmpty()) + if(list.isEmpty() || out_path.isEmpty() || pattern.isEmpty()) { - //ignore + qWarning("Converter: invalid parameters"); + m_inputs.take(decoder)->deleteLater(); + delete decoder; + continue; } - QString desc = desc_formatter.parse(list[0]->metaData(), list[0]->length()); + MetaDataFormatter formatter(pattern); + + QString desc = tr("Track: %1").arg(desc_formatter.parse(list[0]->metaData(), list[0]->length())); + desc += "\n"; + desc += tr("Preset: %1").arg(preset["name"].toString()); emit desriptionChanged(desc); QString name = formatter.parse(list[0]->metaData(), list[0]->length()); - QString full_path = path + "/" + name + ".ogg"; - QString command = "oggenc -q 1 -o %o -"; + QString full_path = out_path + "/" + name + "." + preset["ext"].toString(); + QString command = preset["command"].toString(); command.replace("%o", "\"" + full_path + "\""); + qDebug("Converter: starting task '%s'", qPrintable(preset["name"].toString())); + qDeleteAll(list); list.clear(); @@ -164,6 +192,7 @@ void Converter::run() size_t to_write = sizeof(wave_header); if(to_write != fwrite(&wave_header, 1, to_write, enc_pipe)) { + qWarning("Converter: output file write erro"); m_inputs.take(decoder)->deleteLater(); delete decoder; pclose(enc_pipe); @@ -175,7 +204,18 @@ void Converter::run() //fclose(enc_pipe); m_inputs.take(decoder)->deleteLater(); delete decoder; + m_mutex.lock(); + if(m_user_stop) + { + qDebug("Converter: task '%s' aborted", qPrintable(preset["name"].toString())); + m_mutex.unlock(); + return; + } + else + qDebug("Converter: task '%s' finished with success", qPrintable(preset["name"].toString())); + m_mutex.unlock(); } + qDebug("Converter: thread finished"); } bool Converter::convert(Decoder *decoder, FILE *file) @@ -222,6 +262,14 @@ bool Converter::convert(Decoder *decoder, FILE *file) qDebug("finished!"); return true; } + + m_mutex.lock(); + if(m_user_stop) + { + m_mutex.unlock(); + return false; + } + m_mutex.unlock(); } return false; } diff --git a/src/plugins/General/converter/converter.h b/src/plugins/General/converter/converter.h index 080d3688d..0e69a4fdc 100644 --- a/src/plugins/General/converter/converter.h +++ b/src/plugins/General/converter/converter.h @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -36,9 +38,13 @@ class Converter : public QThread Q_OBJECT public: explicit Converter(QObject *parent = 0); + virtual ~Converter(); - void add(const QStringList &urls); - void add(const QString &url); + void add(const QStringList &urls, const QVariantMap &preset); + void add(const QString &url, const QVariantMap &preset); + +public slots: + void stop(); signals: void progress(int percent); @@ -50,6 +56,9 @@ private: bool convert(Decoder *decoder, FILE *file); QQueue m_decoders; QHash m_inputs; + QHash m_presets; + QMutex m_mutex; + bool m_user_stop; }; diff --git a/src/plugins/General/converter/converterdialog.cpp b/src/plugins/General/converter/converterdialog.cpp index 8a54a1885..e4938afe6 100644 --- a/src/plugins/General/converter/converterdialog.cpp +++ b/src/plugins/General/converter/converterdialog.cpp @@ -71,6 +71,18 @@ QStringList ConverterDialog::selectedUrls() const return out; } +QVariantMap ConverterDialog::preset() const +{ + if(ui.presetComboBox->currentIndex() == -1) + return QVariantMap(); + int index = ui.presetComboBox->currentIndex(); + //aditional parameters + QVariantMap preset = ui.presetComboBox->itemData(index).toMap(); + preset["out_dir"] = ui.outDirEdit->text(); + preset["file_name"] = ui.outFileEdit->text(); + return preset; +} + void ConverterDialog::on_dirButton_clicked() { QString dir = FileDialog::getExistingDirectory(this, tr("Choose a directory"), @@ -86,22 +98,6 @@ void ConverterDialog::accept() settings.setValue("out_dir", ui.outDirEdit->text()); settings.value("file_name", ui.outFileEdit->text()); settings.endGroup(); - - /*QSettings preset_settings(QDir::homePath() + "/.qmmp/converterrc", QSettings::IniFormat); - preset_settings.clear(); - for(int i = 0; i < ui.presetComboBox->count(); ++i) - { - QString name = ui.presetComboBox->itemText(i); - QVariantMap data = ui.presetComboBox->itemData(i).toMap(); - if(data["read_only"].toBool()) - continue; - preset_settings.beginGroup(name); - preset_settings.setValue("ext", data["ext"].toString()); - preset_settings.setValue("command", data["command"].toString()); - preset_settings.setValue("use_16bit", data["use_16bit"].toBool()); - preset_settings.setValue("tags", data["tags"].toBool()); - preset_settings.endGroup(); - }*/ QDialog::accept(); } @@ -184,6 +180,7 @@ void ConverterDialog::copyPreset() int index = ui.presetComboBox->currentIndex(); QVariantMap data = ui.presetComboBox->itemData(index).toMap(); data["name"] = uniqueName(data["name"].toString()); + data["read_only"] = false; ui.presetComboBox->addItem (data["name"].toString(), data); } diff --git a/src/plugins/General/converter/converterdialog.h b/src/plugins/General/converter/converterdialog.h index acb223b11..452d6d9af 100644 --- a/src/plugins/General/converter/converterdialog.h +++ b/src/plugins/General/converter/converterdialog.h @@ -40,6 +40,7 @@ public: virtual ~ConverterDialog(); QStringList selectedUrls() const; + QVariantMap preset() const; public slots: virtual void accept(); diff --git a/src/plugins/General/converter/converterhelper.cpp b/src/plugins/General/converter/converterhelper.cpp index 2bde69119..44f7337f9 100644 --- a/src/plugins/General/converter/converterhelper.cpp +++ b/src/plugins/General/converter/converterhelper.cpp @@ -44,6 +44,7 @@ ConverterHelper::ConverterHelper(QObject *parent) : QObject(parent) connect(m_converter,SIGNAL(progress(int)),m_progress,SLOT(setValue(int))); connect(m_converter, SIGNAL(finished()), m_progress, SLOT(reset())); connect(m_converter, SIGNAL(desriptionChanged(QString)), m_progress, SLOT(setLabelText(QString))); + connect(m_progress, SIGNAL(canceled()), m_converter, SLOT(stop())); } ConverterHelper::~ConverterHelper() @@ -62,7 +63,13 @@ void ConverterHelper::openConverter() if(d->exec() == QDialog::Accepted) { QStringList urls = d->selectedUrls(); - m_converter->add(urls); + QVariantMap preset = d->preset(); + if(preset.isEmpty()) + { + d->deleteLater(); + return; + } + m_converter->add(urls, preset); if(!m_converter->isRunning()) m_converter->start(); diff --git a/src/plugins/General/converter/presets.conf b/src/plugins/General/converter/presets.conf index 5b2ebb03e..78afcb8ea 100644 --- a/src/plugins/General/converter/presets.conf +++ b/src/plugins/General/converter/presets.conf @@ -30,7 +30,7 @@ tags=true name=FLAC ext=flac -command=flac -o %o -5 - +command=flac -o %o -5 --ignore-chunk-sizes -f - use_16bit=false tags=true diff --git a/src/plugins/General/converter/translations/converter_plugin_cs.ts b/src/plugins/General/converter/translations/converter_plugin_cs.ts index 4faa2ef56..6fa8de85b 100644 --- a/src/plugins/General/converter/translations/converter_plugin_cs.ts +++ b/src/plugins/General/converter/translations/converter_plugin_cs.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ - + Choose a directory Vyberte adresář - + Artist Umělec - + Album Album - + Title Název - + Track number Číslo stopy - + Two-digit track number Dvoumístné číslo stopy - + Genre Žánr - + Comment Poznámka - + Composer Skladatel - + Duration Délka - + Disc number Číslo disku - + File name Název souboru - + Create a copy - + Year Rok - + Condition Stav - + Create - + Edit - + Delete diff --git a/src/plugins/General/converter/translations/converter_plugin_de.ts b/src/plugins/General/converter/translations/converter_plugin_de.ts index 75137bfab..d36a82f0a 100644 --- a/src/plugins/General/converter/translations/converter_plugin_de.ts +++ b/src/plugins/General/converter/translations/converter_plugin_de.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ - + Choose a directory Ein Verzeichnis wählen - + Artist Interpret - + Album Album - + Title Titel - + Track number Stücknummer - + Two-digit track number Zweistellige Stücknummer - + Genre Genre - + Comment Kommentar - + Composer Komponist - + Duration Abspieldauer - + Disc number CD-Nummer - + File name Dateiname - + Create a copy - + Year Jahr - + Condition Zustand - + Create - + Edit - + Delete diff --git a/src/plugins/General/converter/translations/converter_plugin_es.ts b/src/plugins/General/converter/translations/converter_plugin_es.ts index 8ba2870c6..f8a6dc0be 100644 --- a/src/plugins/General/converter/translations/converter_plugin_es.ts +++ b/src/plugins/General/converter/translations/converter_plugin_es.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ ... - + Choose a directory Elija un directorio - + Artist Intérprete - + Album Album - + Title Título - + Track number Número de pista - + Two-digit track number Número de pista con dos cifras - + Genre Género - + Comment Comentario - + Composer Compositor - + Duration Duración - + Disc number Número de disco - + File name Nombre del archivo - + Create a copy - + Year Año - + Condition Condición - + Create - + Edit - + Delete diff --git a/src/plugins/General/converter/translations/converter_plugin_it.ts b/src/plugins/General/converter/translations/converter_plugin_it.ts index 1d1657b90..9abca0615 100644 --- a/src/plugins/General/converter/translations/converter_plugin_it.ts +++ b/src/plugins/General/converter/translations/converter_plugin_it.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ ... - + Choose a directory Scegli una cartella - + Artist Interprete - + Album Album - + Title Titolo - + Track number Numero traccia - + Two-digit track number Numero traccia su due cifre - + Genre Genere - + Comment Commento - + Composer Compositore - + Duration Durata - + Disc number Disco num. - + File name Nome documento - + Create a copy - + Year Anno - + Condition PErcorso documento - + Create - + Edit - + Delete diff --git a/src/plugins/General/converter/translations/converter_plugin_ja.ts b/src/plugins/General/converter/translations/converter_plugin_ja.ts index a5175541f..795d5feee 100644 --- a/src/plugins/General/converter/translations/converter_plugin_ja.ts +++ b/src/plugins/General/converter/translations/converter_plugin_ja.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ ... - + Choose a directory ディレクトリを選択 - + Artist アーティスト - + Album アルバム - + Title タイトル - + Track number トラック番号 - + Two-digit track number トラック番号 数字2桁 - + Genre ジャンル - + Comment コメント - + Composer 作曲者 - + Duration 演奏時間 - + Disc number ディスク番号 - + File name ファイル名 - + Create a copy - + Year - + Condition 定番 - + Create - + Edit - + Delete diff --git a/src/plugins/General/converter/translations/converter_plugin_lt.ts b/src/plugins/General/converter/translations/converter_plugin_lt.ts index bc19ff4af..31ecff01e 100644 --- a/src/plugins/General/converter/translations/converter_plugin_lt.ts +++ b/src/plugins/General/converter/translations/converter_plugin_lt.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ ... - + Choose a directory Pasirinkite aplanką - + Artist Atlikėjas - + Album Albumas - + Title Pavadinimas - + Track number Takelio numeris - + Two-digit track number Dviejų skaitmenų takelio numeris - + Genre Žanras - + Comment Komentaras - + Composer Autorius - + Duration Trukmė - + Disc number Disko numeris - + File name Bylos pavadinimas - + Create a copy - + Year Metai - + Condition Būklė - + Create - + Edit - + Delete diff --git a/src/plugins/General/converter/translations/converter_plugin_nl.ts b/src/plugins/General/converter/translations/converter_plugin_nl.ts index 38619ca4f..d058d4da2 100644 --- a/src/plugins/General/converter/translations/converter_plugin_nl.ts +++ b/src/plugins/General/converter/translations/converter_plugin_nl.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ - + Choose a directory Kies een map - + Artist Artiest - + Album Album - + Title Naam - + Track number Liednummer - + Two-digit track number Twee-getal liednummer - + Genre Genre - + Comment Commentaar - + Composer Componist - + Duration Duur - + Disc number CD nummer - + File name Bestandsnaam - + Create a copy - + Year Jaar - + Condition Staat - + Create - + Edit - + Delete diff --git a/src/plugins/General/converter/translations/converter_plugin_pl.ts b/src/plugins/General/converter/translations/converter_plugin_pl.ts index f655a5589..b510d8cee 100644 --- a/src/plugins/General/converter/translations/converter_plugin_pl.ts +++ b/src/plugins/General/converter/translations/converter_plugin_pl.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ - + Choose a directory Wybierz katalog - + Artist Artysta - + Album Album - + Title Tytuł - + Track number Numer utworu - + Two-digit track number Dwucyfrowy numer utworu - + Genre Gatunek - + Comment Komentarz - + Composer Kompozytor - + Duration Długość - + Disc number Numer płyty - + File name Nazwa pliku - + Create a copy - + Year Rok - + Condition Warunek - + Create - + Edit - + Delete diff --git a/src/plugins/General/converter/translations/converter_plugin_ru.ts b/src/plugins/General/converter/translations/converter_plugin_ru.ts index 4b0c9212e..cfaccbbef 100644 --- a/src/plugins/General/converter/translations/converter_plugin_ru.ts +++ b/src/plugins/General/converter/translations/converter_plugin_ru.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ ... - + Choose a directory Выберите директорию - + Artist Исполнитель - + Album Альбом - + Title Название - + Track number Номер трека - + Two-digit track number 2-х разрядный номер трека - + Genre Жанр - + Comment Комментарий - + Composer Композитор - + Duration Длительность - + Disc number Номер диска - + File name Имя файла - + Create a copy - + Year Год - + Condition Условие - + Create - + Edit - + Delete diff --git a/src/plugins/General/converter/translations/converter_plugin_tr.ts b/src/plugins/General/converter/translations/converter_plugin_tr.ts index f54926c27..40c122244 100644 --- a/src/plugins/General/converter/translations/converter_plugin_tr.ts +++ b/src/plugins/General/converter/translations/converter_plugin_tr.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ ... - + Choose a directory Dizin seç - + Artist - + Album - + Title - + Track number - + Two-digit track number - + Genre - + Comment Yorum - + Composer - + Duration - + Disc number - + File name - + Create a copy - + Year Yıl - + Condition - + Create - + Edit - + Delete diff --git a/src/plugins/General/converter/translations/converter_plugin_uk_UA.ts b/src/plugins/General/converter/translations/converter_plugin_uk_UA.ts index 5a568ad57..ecba260a5 100644 --- a/src/plugins/General/converter/translations/converter_plugin_uk_UA.ts +++ b/src/plugins/General/converter/translations/converter_plugin_uk_UA.ts @@ -1,6 +1,19 @@ - - + + + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -34,97 +47,99 @@ Переписати існуючі файли + + ... ... - + Choose a directory Виберіть теку - + Artist Виконавець - + Album Альбом - + Title Назва - + Track number Номер трека - + Two-digit track number 2-розрядний номер трека - + Genre Жанр - + Comment Коментар - + Composer Композитор - + Duration Тривалість - + Disc number Номер диска - + File name Ім'я файла - + Create a copy Створити копію - + Year Рік - + Condition Умова - + Create Створити - + Edit Редагувати - + Delete Видалити diff --git a/src/plugins/General/converter/translations/converter_plugin_zh_CN.ts b/src/plugins/General/converter/translations/converter_plugin_zh_CN.ts index c7e6269e8..13a9a316f 100644 --- a/src/plugins/General/converter/translations/converter_plugin_zh_CN.ts +++ b/src/plugins/General/converter/translations/converter_plugin_zh_CN.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ ... - + Choose a directory 选择一个目录 - + Artist 艺术家 - + Album 专辑 - + Title 标题 - + Track number 音轨编号 - + Two-digit track number 两位数音轨编号 - + Genre 流派 - + Comment 备注 - + Composer 作曲 - + Duration 持续时间 - + Disc number 光盘编号 - + File name 文件名 - + Create a copy - + Year 年代 - + Condition 条件 - + Create - + Edit - + Delete diff --git a/src/plugins/General/converter/translations/converter_plugin_zh_TW.ts b/src/plugins/General/converter/translations/converter_plugin_zh_TW.ts index 8c52466bf..763f58e25 100644 --- a/src/plugins/General/converter/translations/converter_plugin_zh_TW.ts +++ b/src/plugins/General/converter/translations/converter_plugin_zh_TW.ts @@ -1,6 +1,19 @@ + + Converter + + + Track: %1 + + + + + Preset: %1 + + + ConverterDialog @@ -41,92 +54,92 @@ ... - + Choose a directory 選取一個目錄 - + Artist 藝術家 - + Album 專輯 - + Title 標題 - + Track number 音軌編號 - + Two-digit track number 兩位數音軌編號 - + Genre 流派 - + Comment 備註 - + Composer 作曲 - + Duration 持續時間 - + Disc number 光槃編號 - + File name 文件名 - + Create a copy - + Year 年代 - + Condition 條件 - + Create - + Edit - + Delete -- cgit v1.2.3-13-gbd6f