From 90b71df1362b7e128ca99ee09cc8402b8421f76d Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sat, 21 Nov 2009 17:13:34 +0000 Subject: added metadata formatter git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1389 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/notifier/popupwidget.cpp | 27 ++-- src/plugins/General/notifier/popupwidget.h | 3 +- src/plugins/General/notifier/settingsdialog.cpp | 45 ++++++- src/plugins/General/notifier/settingsdialog.h | 7 +- src/plugins/General/notifier/settingsdialog.ui | 142 +++++++++++++++------ .../notifier/translations/notifier_plugin_cs.ts | 113 ++++++++++++++-- .../notifier/translations/notifier_plugin_de.ts | 113 ++++++++++++++-- .../notifier/translations/notifier_plugin_it.ts | 113 ++++++++++++++-- .../notifier/translations/notifier_plugin_lt.ts | 113 ++++++++++++++-- .../notifier/translations/notifier_plugin_pl.ts | 113 ++++++++++++++-- .../notifier/translations/notifier_plugin_ru.ts | 113 ++++++++++++++-- .../notifier/translations/notifier_plugin_tr.ts | 113 ++++++++++++++-- .../notifier/translations/notifier_plugin_uk_UA.ts | 113 ++++++++++++++-- .../notifier/translations/notifier_plugin_zh_CN.ts | 113 ++++++++++++++-- .../notifier/translations/notifier_plugin_zh_TW.ts | 113 ++++++++++++++-- src/qmmpui/CMakeLists.txt | 3 + src/qmmpui/metadataformatter.cpp | 98 ++++++++++++++ src/qmmpui/metadataformatter.h | 43 +++++++ src/qmmpui/playlistitem.cpp | 42 +----- src/qmmpui/playlistitem.h | 1 - src/ui/configdialog.cpp | 6 +- src/ui/translations/qmmp_cs.ts | 24 +++- src/ui/translations/qmmp_de.ts | 24 +++- src/ui/translations/qmmp_it.ts | 24 +++- src/ui/translations/qmmp_lt.ts | 24 +++- src/ui/translations/qmmp_pl_PL.ts | 24 +++- src/ui/translations/qmmp_pt_BR.ts | 24 +++- src/ui/translations/qmmp_ru.ts | 24 +++- src/ui/translations/qmmp_tr.ts | 24 +++- src/ui/translations/qmmp_uk_UA.ts | 24 +++- src/ui/translations/qmmp_zh_CN.ts | 24 +++- src/ui/translations/qmmp_zh_TW.ts | 24 +++- 32 files changed, 1486 insertions(+), 325 deletions(-) create mode 100644 src/qmmpui/metadataformatter.cpp create mode 100644 src/qmmpui/metadataformatter.h (limited to 'src') diff --git a/src/plugins/General/notifier/popupwidget.cpp b/src/plugins/General/notifier/popupwidget.cpp index 6ce89da44..e7b34b99e 100644 --- a/src/plugins/General/notifier/popupwidget.cpp +++ b/src/plugins/General/notifier/popupwidget.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "popupwidget.h" @@ -57,6 +58,7 @@ PopupWidget::PopupWidget(QWidget *parent) setWindowOpacity(settings.value("opacity", 1.0).toDouble()); QString fontname = settings.value("font").toString(); m_coverSize = settings.value("cover_size", 64).toInt(); + m_template = settings.value("template","").toString(); settings.endGroup(); //font QFont font; @@ -81,30 +83,19 @@ void PopupWidget::mousePressEvent (QMouseEvent *) void PopupWidget::showMetaData() { m_timer->stop(); + QString title = m_template; + SoundCore *core = SoundCore::instance(); - QString title = ""; - if (core->metaData(Qmmp::TITLE).isEmpty()) - title.append(core->metaData(Qmmp::URL).section('/',-1)); - else - title.append(core->metaData(Qmmp::TITLE)); - title.append(""); if (core->totalTime() > 0) { - title.append(" "); int l = core->totalTime()/1000; - title.append(QString("(%1:%2)").arg(l/60).arg(l%60, 2, 10, QChar('0'))); - } - if(!core->metaData(Qmmp::ARTIST).isEmpty()) - { - title.append("
"); - title.append(core->metaData(Qmmp::ARTIST)); + title.replace("%l",QString("%1:%2").arg(l/60).arg(l%60, 2, 10, QChar('0'))); } + else + title.replace("%l",""); + MetaDataFormatter f(title); + title = f.parse(core->metaData()); - if(!core->metaData(Qmmp::ALBUM).isEmpty()) - { - title.append("
"); - title.append(core->metaData(Qmmp::ALBUM)); - } m_label1->setText(title); QPixmap pix = MetaDataManager::instance()->getCover(core->metaData(Qmmp::URL)); diff --git a/src/plugins/General/notifier/popupwidget.h b/src/plugins/General/notifier/popupwidget.h index a845ea24c..7efcad04f 100644 --- a/src/plugins/General/notifier/popupwidget.h +++ b/src/plugins/General/notifier/popupwidget.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Ilya Kotov * + * Copyright (C) 2008-2009 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -61,6 +61,7 @@ private: QTimer *m_timer; QLabel *m_label1; QLabel *m_pixlabel; + QString m_template; uint m_pos; int m_coverSize; diff --git a/src/plugins/General/notifier/settingsdialog.cpp b/src/plugins/General/notifier/settingsdialog.cpp index 9b2a18f30..3822e64aa 100644 --- a/src/plugins/General/notifier/settingsdialog.cpp +++ b/src/plugins/General/notifier/settingsdialog.cpp @@ -20,12 +20,13 @@ #include #include - +#include #include - #include "popupwidget.h" #include "settingsdialog.h" +#define DEFAULT_TEMPLATE "%if(%t,%t,%f) \\(%l\\)\n%if(%p,
%p,)\n%if(%a,
%a,)" + SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent) { @@ -52,6 +53,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) ui.transparencySlider->setValue(100 - settings.value("opacity", 1.0).toDouble()*100); QString fontname = settings.value ("font").toString(); ui.coverSizeSlider->setValue(settings.value ("cover_size", 64).toInt()); + ui.textEdit->setPlainText(settings.value ("template", DEFAULT_TEMPLATE).toString()); settings.endGroup(); QFont font; if(!fontname.isEmpty()) @@ -59,6 +61,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) ui.fontLabel->setText (font.family () + " " + QString::number(font.pointSize ())); ui.fontLabel->setFont(font); connect (ui.fontButton, SIGNAL (clicked()), SLOT (setFont())); + createMenu(); } @@ -80,9 +83,10 @@ void SettingsDialog::accept() settings.setValue("psi_notification", ui.psiCheckBox->isChecked()); settings.setValue("song_notification", ui.songCheckBox->isChecked()); settings.setValue("volume_notification", ui.volumeCheckBox->isChecked()); - settings.setValue ("opacity", 1.0 - (double)ui.transparencySlider->value()/100); - settings.setValue ("font", ui.fontLabel->font().toString()); - settings.setValue ("cover_size", ui.coverSizeSlider->value()); + settings.setValue("opacity", 1.0 - (double)ui.transparencySlider->value()/100); + settings.setValue("font", ui.fontLabel->font().toString()); + settings.setValue("cover_size", ui.coverSizeSlider->value()); + settings.setValue("template", ui.textEdit->toPlainText()); settings.endGroup(); QDialog::accept(); } @@ -98,3 +102,34 @@ void SettingsDialog::setFont() ui.fontLabel->setFont(font); } } + +void SettingsDialog::createMenu() +{ + QMenu *menu = new QMenu(this); + menu->addAction(tr("Artist"))->setData("%p"); + menu->addAction(tr("Album"))->setData("%a"); + menu->addAction(tr("Title"))->setData("%t"); + menu->addAction(tr("Track number"))->setData("%n"); + menu->addAction(tr("Two-digit track number"))->setData("%NN"); + menu->addAction(tr("Genre"))->setData("%g"); + menu->addAction(tr("Comment"))->setData("%c"); + menu->addAction(tr("Composer"))->setData("%C"); + menu->addAction(tr("Duration"))->setData("%l"); + menu->addAction(tr("Disc number"))->setData("%D"); + menu->addAction(tr("File name"))->setData("%f"); + menu->addAction(tr("File path"))->setData("%F"); + menu->addAction(tr("Year"))->setData("%y"); + menu->addAction(tr("Condition"))->setData("%if(%p&%t,%p - %t,%f)"); + ui.insertButton->setMenu(menu); + connect(menu, SIGNAL(triggered (QAction *)), SLOT(insertExpression(QAction *))); +} + +void SettingsDialog::insertExpression(QAction *a) +{ + ui.textEdit->insertPlainText(a->data().toString()); +} + +void SettingsDialog::on_resetButton_clicked() +{ + ui.textEdit->setPlainText(DEFAULT_TEMPLATE); +} diff --git a/src/plugins/General/notifier/settingsdialog.h b/src/plugins/General/notifier/settingsdialog.h index e6b94c321..245ca6f99 100644 --- a/src/plugins/General/notifier/settingsdialog.h +++ b/src/plugins/General/notifier/settingsdialog.h @@ -21,10 +21,10 @@ #define SETTINGSDIALOG_H #include - - #include "ui_settingsdialog.h" +class Action; + /** @author Ilya Kotov */ @@ -42,8 +42,11 @@ public slots: private slots: void setFont(); + void insertExpression(QAction *); + void on_resetButton_clicked(); private: + void createMenu(); Ui::SettingsDialog ui; QMap m_buttons; diff --git a/src/plugins/General/notifier/settingsdialog.ui b/src/plugins/General/notifier/settingsdialog.ui index d2e557a27..b38a112d0 100644 --- a/src/plugins/General/notifier/settingsdialog.ui +++ b/src/plugins/General/notifier/settingsdialog.ui @@ -6,8 +6,8 @@ 0 0 - 298 - 403 + 529 + 325 @@ -23,24 +23,14 @@ 6 - - - - Psi Notification - - - - - - Enable Psi notification - - - - - - - + + + + 0 + 0 + + Desktop Notification @@ -348,32 +338,104 @@ - - - - Qt::Horizontal - - - - 131 - 31 - + + + + Notification Template - + + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + + 138 + 20 + + + + + + + + Reset + + + + + + + Insert + + + + + - - - - - 0 - 0 - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + Psi Notification + + + + + + 0 + 0 + + + + Enable Psi notification + + + + + + + + + + Qt::Horizontal + + + + 131 + 31 + + + + + + + + + 0 + 0 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_cs.ts b/src/plugins/General/notifier/translations/notifier_plugin_cs.ts index d298d28ee..f938174f9 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_cs.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_cs.ts @@ -27,7 +27,7 @@ PopupWidget - + Volume: Hlasitost: @@ -40,65 +40,150 @@ Nastavení notifikačního modulu - + + Notification Template + + + + + Reset + + + + + Insert + + + + Psi Notification Notifikace v Psi - + Enable Psi notification Povolit notifikaci v Psi - + Desktop Notification Notifikace na pracovní ploše - + Font: Písmo: - + Cover size: Velikost obalu: - + Delay (ms): Prodleva (ms): - + Position Umístění - + ... - + Song change notification Upozornění na změnu skladby - + Volume change notification Upozornění na změnu hlasitosti - + Transparency Průhlednost - - + + 0 0 + + + Artist + + + + + Album + + + + + Title + + + + + Track number + + + + + Two-digit track number + + + + + Genre + + + + + Comment + + + + + Composer + + + + + Duration + + + + + Disc number + + + + + File name + + + + + File path + + + + + Year + + + + + Condition + + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_de.ts b/src/plugins/General/notifier/translations/notifier_plugin_de.ts index 2eb38c8ce..7e55f1ed2 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_de.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_de.ts @@ -27,7 +27,7 @@ PopupWidget - + Volume: Lautstärke: @@ -35,27 +35,27 @@ SettingsDialog - + Psi Notification Psi-Benachrichtigungen - + Enable Psi notification Psi-Benachrichtigungen aktivieren - + Desktop Notification Desktop-Benachrichtigungen - + Delay (ms): Anzeigedauer (ms): - + Position Position @@ -65,40 +65,125 @@ Einstellungen Benachrichtigungsmodul - + Song change notification Benachrichtigung bei Titelwechsel - + Volume change notification Benachrichtigung bei Lautstärkeänderung - + Transparency Transparenz - - + + 0 0 - + + Notification Template + + + + + Reset + + + + + Insert + + + + Font: Schriftart: - + Cover size: Cover-Größe: - + ... ... + + + Artist + + + + + Album + + + + + Title + + + + + Track number + + + + + Two-digit track number + + + + + Genre + + + + + Comment + + + + + Composer + + + + + Duration + + + + + Disc number + + + + + File name + + + + + File path + + + + + Year + + + + + Condition + + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_it.ts b/src/plugins/General/notifier/translations/notifier_plugin_it.ts index 584ba5e33..98a789ae9 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_it.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_it.ts @@ -27,7 +27,7 @@ PopupWidget - + Volume: Volume: @@ -35,27 +35,27 @@ SettingsDialog - + Psi Notification Notifica Psi - + Enable Psi notification Abilita notifica Psi - + Desktop Notification Notifica sul desktop - + Delay (ms): - + Position Posizione @@ -65,40 +65,125 @@ Impostazioni modulo notifica - + Song change notification Notifica cambio brano - + Volume change notification Notifica modifica volume - + Transparency Trasparenza - - + + 0 0 - + + Notification Template + + + + + Reset + + + + + Insert + + + + Font: - + Cover size: - + ... + + + Artist + + + + + Album + + + + + Title + + + + + Track number + + + + + Two-digit track number + + + + + Genre + + + + + Comment + + + + + Composer + + + + + Duration + + + + + Disc number + + + + + File name + + + + + File path + + + + + Year + + + + + Condition + + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_lt.ts b/src/plugins/General/notifier/translations/notifier_plugin_lt.ts index 059e4758b..fd9644f9b 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_lt.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_lt.ts @@ -27,7 +27,7 @@ PopupWidget - + Volume: Garsumas: @@ -40,65 +40,150 @@ Notifier įskiepio nustatymai - + + Notification Template + + + + + Reset + + + + + Insert + + + + Psi Notification Psi pranešimas - + Enable Psi notification Įjungti Psi pranešimą - + Desktop Notification Pranešimas darbalaukyje - + Delay (ms): - + Position Padėtis - + Song change notification Pranešti pasikeitus dainai - + Volume change notification Pranešti pasikeitus garsumui - + Transparency Permatomumas - - + + 0 - + Font: - + Cover size: - + ... + + + Artist + + + + + Album + + + + + Title + + + + + Track number + + + + + Two-digit track number + + + + + Genre + + + + + Comment + + + + + Composer + + + + + Duration + + + + + Disc number + + + + + File name + + + + + File path + + + + + Year + + + + + Condition + + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_pl.ts b/src/plugins/General/notifier/translations/notifier_plugin_pl.ts index 6a3d7354b..1a379b2da 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_pl.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_pl.ts @@ -27,7 +27,7 @@ PopupWidget - + Volume: Głośność: @@ -40,65 +40,150 @@ Ustawienia wtyczki Notifier - + + Notification Template + + + + + Reset + + + + + Insert + + + + Psi Notification Powiadomienia Psi - + Enable Psi notification Włącz powiadomienia Psi - + Desktop Notification Powiadomienie na pulpicie - + Song change notification Pozycja - + Volume change notification Powiadamianie o zmianie głośności - + Transparency Przezroczystość - - + + 0 0 - + Position Pozycja - + Font: Czcionka: - + Cover size: Wielkość okładki: - + Delay (ms): Opóźnienie (ms): - + ... + + + Artist + + + + + Album + + + + + Title + + + + + Track number + + + + + Two-digit track number + + + + + Genre + + + + + Comment + + + + + Composer + + + + + Duration + + + + + Disc number + + + + + File name + + + + + File path + + + + + Year + + + + + Condition + + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_ru.ts b/src/plugins/General/notifier/translations/notifier_plugin_ru.ts index 3956be1be..4f86dcba6 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_ru.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_ru.ts @@ -27,7 +27,7 @@ PopupWidget - + Volume: Громкость: @@ -40,65 +40,150 @@ Настройки модуля уведомлений - + + Notification Template + + + + + Reset + + + + + Insert + + + + Psi Notification Уведомление Psi - + Enable Psi notification Включить уведомление Psi - + Desktop Notification Сообщение на рабочем столе - + Delay (ms): Задежка (мс): - + Position Положение - + Song change notification Уведомление о смене песни - + Volume change notification Уведомление о смене громкости - + Transparency Прозрачность - - + + 0 - + Font: Шрифт: - + Cover size: Размер обложки: - + ... + + + Artist + + + + + Album + + + + + Title + + + + + Track number + + + + + Two-digit track number + + + + + Genre + + + + + Comment + + + + + Composer + + + + + Duration + + + + + Disc number + + + + + File name + + + + + File path + + + + + Year + + + + + Condition + + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_tr.ts b/src/plugins/General/notifier/translations/notifier_plugin_tr.ts index c6f3f6655..9e41e4317 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_tr.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_tr.ts @@ -27,7 +27,7 @@ PopupWidget - + Volume: Ses: @@ -40,65 +40,150 @@ Bildirim Eklentisi Ayarları - + + Notification Template + + + + + Reset + + + + + Insert + + + + Psi Notification Psi Bildirimi - + Enable Psi notification Psi bildirimi etkinleştir - + Desktop Notification Masaüstü Bildirimi - + Song change notification Şarkı değişimi bildirimi - + Volume change notification Ses değişimi bildirimi - + Transparency Şeffaflık - - + + 0 0 - + Position Konum - + Font: Шрифт: - + Cover size: Размер обложки: - + Delay (ms): Задержка (мс): - + ... + + + Artist + + + + + Album + + + + + Title + + + + + Track number + + + + + Two-digit track number + + + + + Genre + + + + + Comment + + + + + Composer + + + + + Duration + + + + + Disc number + + + + + File name + + + + + File path + + + + + Year + + + + + Condition + + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_uk_UA.ts b/src/plugins/General/notifier/translations/notifier_plugin_uk_UA.ts index 2155188b6..6c40a12a9 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_uk_UA.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_uk_UA.ts @@ -27,7 +27,7 @@ PopupWidget - + Volume: Гучність: @@ -40,65 +40,150 @@ Налаштування модуля повідомлень - + + Notification Template + + + + + Reset + + + + + Insert + + + + Psi Notification Повідомлення Psi - + Enable Psi notification Увімкнути повідомлення Psi - + Desktop Notification Повідомлення на робочому столі - + Delay (ms): Затримка (мс): - + Position Позиція - + Song change notification Повідомлення зміни треку - + Volume change notification Повідомлення зміни гучності - + Transparency Прозорість - - + + 0 - + Font: Шрифт: - + Cover size: Розмір обкладинки: - + ... ... + + + Artist + + + + + Album + + + + + Title + + + + + Track number + + + + + Two-digit track number + + + + + Genre + + + + + Comment + + + + + Composer + + + + + Duration + + + + + Disc number + + + + + File name + + + + + File path + + + + + Year + + + + + Condition + + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_zh_CN.ts b/src/plugins/General/notifier/translations/notifier_plugin_zh_CN.ts index 7a89f8691..2db3cd6ab 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_zh_CN.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_zh_CN.ts @@ -27,7 +27,7 @@ PopupWidget - + Volume: 音量: @@ -35,27 +35,27 @@ SettingsDialog - + Psi Notification PSI 通知 - + Enable Psi notification 启用 PSI 通知 - + Desktop Notification 桌面通知 - + Delay (ms): - + Position 位置 @@ -65,40 +65,125 @@ 通知插件设置 - + Song change notification 歌曲更改通知 - + Volume change notification 音量更改通知 - + Transparency 透明度 - - + + 0 0 - + + Notification Template + + + + + Reset + + + + + Insert + + + + Font: - + Cover size: - + ... + + + Artist + + + + + Album + + + + + Title + + + + + Track number + + + + + Two-digit track number + + + + + Genre + + + + + Comment + + + + + Composer + + + + + Duration + + + + + Disc number + + + + + File name + + + + + File path + + + + + Year + + + + + Condition + + diff --git a/src/plugins/General/notifier/translations/notifier_plugin_zh_TW.ts b/src/plugins/General/notifier/translations/notifier_plugin_zh_TW.ts index 60ed5b227..0ffda28b4 100644 --- a/src/plugins/General/notifier/translations/notifier_plugin_zh_TW.ts +++ b/src/plugins/General/notifier/translations/notifier_plugin_zh_TW.ts @@ -27,7 +27,7 @@ PopupWidget - + Volume: 音量: @@ -35,27 +35,27 @@ SettingsDialog - + Psi Notification PSI 通知 - + Enable Psi notification 啟用 PSI 通知 - + Desktop Notification 桌面通知 - + Delay (ms): - + Position 位置 @@ -65,40 +65,125 @@ 通知插件設定 - + Song change notification 曲目改變通知 - + Volume change notification 音量改變通知 - + Transparency 透明度 - - + + 0 0 - + + Notification Template + + + + + Reset + + + + + Insert + + + + Font: - + Cover size: - + ... + + + Artist + + + + + Album + + + + + Title + + + + + Track number + + + + + Two-digit track number + + + + + Genre + + + + + Comment + + + + + Composer + + + + + Duration + + + + + Disc number + + + + + File name + + + + + File path + + + + + Year + + + + + Condition + + diff --git a/src/qmmpui/CMakeLists.txt b/src/qmmpui/CMakeLists.txt index 84b640b7a..595cf4f0c 100644 --- a/src/qmmpui/CMakeLists.txt +++ b/src/qmmpui/CMakeLists.txt @@ -39,6 +39,7 @@ SET(libqmmpui_SRCS detailsdialog.cpp tageditor.cpp playlistmanager.cpp + metadataformatter.cpp ) SET(libqmmpui_MOC_HDRS @@ -62,6 +63,7 @@ SET(libqmmpui_MOC_HDRS detailsdialog.h tageditor.h playlistmanager.h + metadataformatter.h ) SET(libqmmpui_DEVEL_HDRS @@ -81,6 +83,7 @@ SET(libqmmpui_DEVEL_HDRS detailsdialog.h tageditor.h playlistmanager.h + metadataformatter.h ) diff --git a/src/qmmpui/metadataformatter.cpp b/src/qmmpui/metadataformatter.cpp new file mode 100644 index 000000000..9a055f4e9 --- /dev/null +++ b/src/qmmpui/metadataformatter.cpp @@ -0,0 +1,98 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + + +/* +Syntax: +%p - artist +%a - album +%t - title +%n - track, +%NN - 2-digit track +%g - genre +%c - comment +%C - composer +%D - disc number +%f - file name +%F - full path +%y - year +%if(A,B,C) +%if(A&B&C,D,E) +*/ + +#include +#include +#include "metadataformatter.h" + +MetaDataFormatter::MetaDataFormatter(const QString &format) +{ + m_format = format; +} + +QString MetaDataFormatter::parse(const QMap metaData) +{ + QString title = m_format; + title.replace("\\(", "%28"); + title.replace("\\)", "%29"); + title.replace(")", "%)"); + title.replace("&", "%&"); + title.replace("%p", metaData[Qmmp::ARTIST]); + title.replace("%a", metaData[Qmmp::ALBUM]); + title.replace("%t", metaData[Qmmp::TITLE]); + title.replace("%n", metaData[Qmmp::TRACK]); + title.replace("%NN", QString("%1").arg(metaData[Qmmp::TRACK],2,'0')); + title.replace("%g", metaData[Qmmp::GENRE]); + title.replace("%c", metaData[Qmmp::COMMENT]); + title.replace("%C", metaData[Qmmp::COMPOSER]); + title.replace("%D", metaData[Qmmp::DISCNUMBER]); + title.replace("%f", metaData[Qmmp::URL].section('/',-1)); + title.replace("%F", metaData[Qmmp::URL]); + title.replace("%y", metaData[Qmmp::YEAR]); + + if(title.contains("%if")) + title = processIfKeyWord(title); + title.replace("%28", "("); + title.replace("%29", ")"); + return title; +} + +QString MetaDataFormatter::processIfKeyWord(QString title) +{ + int pos = title.indexOf("%if("); + int size = title.indexOf("%)",pos) - pos; + + QStringList args = title.mid (pos + 4, size - 4).split(","); + if(args.count() < 3) + { + qWarning("TitleFormatter: invalid title format"); + return title; + } + //process condition + bool cond = TRUE; + foreach(QString arg, args.at(0).split("%&")) + { + cond &= !arg.isEmpty(); + } + QString r_str = cond ? args.at(1) : args.at(2); + title.replace (pos, size + 2, r_str); + if(title.contains("%if")) + return processIfKeyWord(title); + return title; +} diff --git a/src/qmmpui/metadataformatter.h b/src/qmmpui/metadataformatter.h new file mode 100644 index 000000000..c826cb499 --- /dev/null +++ b/src/qmmpui/metadataformatter.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef METADATAFORMATTER_H +#define METADATAFORMATTER_H + +#include +#include +#include + +/*! + * @author Ilya Kotov + */ +class MetaDataFormatter +{ +public: + MetaDataFormatter(const QString &format); + QString parse(const QMap metaData); + +private: + QString m_format; + QString processIfKeyWord(QString title); + +}; + +#endif // METADATAFORMATTER_H diff --git a/src/qmmpui/playlistitem.cpp b/src/qmmpui/playlistitem.cpp index 60422aee1..3bb57963a 100644 --- a/src/qmmpui/playlistitem.cpp +++ b/src/qmmpui/playlistitem.cpp @@ -21,6 +21,7 @@ #include #include +#include "metadataformatter.h" #include "playlistsettings.h" #include "playlistitem.h" @@ -117,18 +118,8 @@ void PlayListItem::setText(const QString &title) void PlayListItem::readMetadata() { - m_title = PlaylistSettings::instance()->format(); - m_title = printTag(m_title, "%p", artist()); - m_title = printTag(m_title, "%a", album()); - m_title = printTag(m_title, "%t", title()); - m_title = printTag(m_title, "%n", track()); - m_title = printTag(m_title, "%c", comment()); - m_title = printTag(m_title, "%C", composer()); - m_title = printTag(m_title, "%g", genre()); - m_title = printTag(m_title, "%D", discNumber()); - m_title = printTag(m_title, "%f", url().section('/',-1)); - m_title = printTag(m_title, "%F", url()); - m_title = printTag(m_title, "%y", year ()); + MetaDataFormatter f(PlaylistSettings::instance()->format()); + m_title = f.parse(metaData()); //TODO rewrite this if (m_title.isEmpty()) { @@ -143,30 +134,3 @@ void PlayListItem::readMetadata() if (PlaylistSettings::instance()->convertTwenty()) m_title.replace("%20", " "); } - -QString PlayListItem::printTag(QString str, QString regExp, QString tagStr) -{ - QString format = PlaylistSettings::instance()->format(); - if (!tagStr.isEmpty()) - str.replace(regExp, tagStr); - else - { - //remove unused separators - int regExpPos = str.indexOf(regExp); - if (regExpPos < 0) - return str; - int nextPos = str.indexOf("%", regExpPos + 1); - if (nextPos < 0) - { - //last separator - regExpPos = format.lastIndexOf(regExp); - nextPos = format.lastIndexOf("%", regExpPos - 1); - QString lastSep = format.right (format.size() - nextPos - 2); - str.remove(lastSep); - str.remove(regExp); - } - else - str.remove ( regExpPos, nextPos - regExpPos); - } - return str; -} diff --git a/src/qmmpui/playlistitem.h b/src/qmmpui/playlistitem.h index 86d89d50d..c1bec3e38 100644 --- a/src/qmmpui/playlistitem.h +++ b/src/qmmpui/playlistitem.h @@ -104,7 +104,6 @@ public: private: void readMetadata(); - QString printTag(QString str, QString regExp, QString tagStr); QString m_title; FileInfo *m_info; bool m_selected; diff --git a/src/ui/configdialog.cpp b/src/ui/configdialog.cpp index 0b41c80f5..eeae7cb3b 100644 --- a/src/ui/configdialog.cpp +++ b/src/ui/configdialog.cpp @@ -582,13 +582,15 @@ void ConfigDialog::createMenus() menu->addAction(tr("Album"))->setData("%a"); menu->addAction(tr("Title"))->setData("%t"); menu->addAction(tr("Track number"))->setData("%n"); - menu->addAction(tr("Disc number"))->setData("%D"); + menu->addAction(tr("Two-digit track number"))->setData("%NN"); menu->addAction(tr("Genre"))->setData("%g"); + menu->addAction(tr("Comment"))->setData("%c"); menu->addAction(tr("Composer"))->setData("%C"); + menu->addAction(tr("Disc number"))->setData("%D"); menu->addAction(tr("File name"))->setData("%f"); menu->addAction(tr("File path"))->setData("%F"); menu->addAction(tr("Year"))->setData("%y"); - menu->addAction(tr("Comment"))->setData("%c"); + menu->addAction(tr("Condition"))->setData("%if(%p&%t,%p - %t,%f)"); ui.titleButton->setMenu(menu); ui.titleButton->setPopupMode(QToolButton::InstantPopup); diff --git a/src/ui/translations/qmmp_cs.ts b/src/ui/translations/qmmp_cs.ts index b6382bfaa..c0fe62a91 100644 --- a/src/ui/translations/qmmp_cs.ts +++ b/src/ui/translations/qmmp_cs.ts @@ -221,21 +221,31 @@ + Two-digit track number + + + + Disc number Číslo disku - + + Condition + + + + Composer Skladatel - + File name Název souboru - + File path Cesta k souboru @@ -245,12 +255,12 @@ Žánr - + Year Rok - + Comment Komentář @@ -515,12 +525,12 @@ Převést %20 na mezery - + Select Skin Files Vybrat soubory s tématy - + Skin files Soubory s tématy diff --git a/src/ui/translations/qmmp_de.ts b/src/ui/translations/qmmp_de.ts index be1713b81..1ebcf77e1 100644 --- a/src/ui/translations/qmmp_de.ts +++ b/src/ui/translations/qmmp_de.ts @@ -221,36 +221,46 @@ + Two-digit track number + + + + Disc number CD-Nummer + + + Condition + + Genre Genre - + Composer Komponist - + File name Dateiname - + File path Dateipfad - + Year Jahr - + Comment Kommentar @@ -515,12 +525,12 @@ %20 in Leerzeichen umwandeln - + Select Skin Files Design-Dateien auswählen - + Skin files Design-Dateien diff --git a/src/ui/translations/qmmp_it.ts b/src/ui/translations/qmmp_it.ts index 3d3c143f1..096627d24 100644 --- a/src/ui/translations/qmmp_it.ts +++ b/src/ui/translations/qmmp_it.ts @@ -221,36 +221,46 @@ + Two-digit track number + + + + Disc number + + + Condition + + Genre Genere - + Composer - + File name - + File path - + Year Anno - + Comment Commento @@ -515,12 +525,12 @@ Converti il carattere « %20 » in spazi - + Select Skin Files Seleziona aspetto - + Skin files Aspetto diff --git a/src/ui/translations/qmmp_lt.ts b/src/ui/translations/qmmp_lt.ts index 24d57bdf5..fc9c649da 100644 --- a/src/ui/translations/qmmp_lt.ts +++ b/src/ui/translations/qmmp_lt.ts @@ -221,21 +221,31 @@ + Two-digit track number + + + + Disc number - - Composer + + Condition + Composer + + + + File name - + File path @@ -245,12 +255,12 @@ Žanras - + Year Metai - + Comment Komentaras @@ -515,12 +525,12 @@ Konvertuoti %20 į tarpus - + Select Skin Files Pasirinkti temų bylas - + Skin files Temų bylos diff --git a/src/ui/translations/qmmp_pl_PL.ts b/src/ui/translations/qmmp_pl_PL.ts index 4f08a57a3..9ff9b6c33 100644 --- a/src/ui/translations/qmmp_pl_PL.ts +++ b/src/ui/translations/qmmp_pl_PL.ts @@ -221,36 +221,46 @@ + Two-digit track number + + + + Disc number Numer albumu + + + Condition + + Genre Gatunek - + Composer Kompozytor - + File name Nazwa pliku - + File path Lokalizacja - + Year Rok - + Comment Komentarz @@ -515,12 +525,12 @@ Konwertuj sekwencje %20 na spacje - + Select Skin Files Wybierz skórę - + Skin files Pliki skór diff --git a/src/ui/translations/qmmp_pt_BR.ts b/src/ui/translations/qmmp_pt_BR.ts index 82796c0ac..2a5404bcc 100644 --- a/src/ui/translations/qmmp_pt_BR.ts +++ b/src/ui/translations/qmmp_pt_BR.ts @@ -221,36 +221,46 @@ + Two-digit track number + + + + Disc number + + + Condition + + Genre Gênero - + Composer - + File name - + File path - + Year Ano - + Comment Comentário @@ -515,12 +525,12 @@ - + Select Skin Files - + Skin files diff --git a/src/ui/translations/qmmp_ru.ts b/src/ui/translations/qmmp_ru.ts index 9c41298b2..e0f5a4844 100644 --- a/src/ui/translations/qmmp_ru.ts +++ b/src/ui/translations/qmmp_ru.ts @@ -221,36 +221,46 @@ + Two-digit track number + + + + Disc number Номер диска + + + Condition + + Genre Жанр - + Composer Композитор - + File name Имя файла - + File path Путь к файлу - + Year Год - + Comment Комментарий @@ -515,12 +525,12 @@ Преобразовывать %20 в пробел - + Select Skin Files Выберите файлы обложек - + Skin files Файлы обложек diff --git a/src/ui/translations/qmmp_tr.ts b/src/ui/translations/qmmp_tr.ts index b1bb9cfb4..945e96f82 100644 --- a/src/ui/translations/qmmp_tr.ts +++ b/src/ui/translations/qmmp_tr.ts @@ -221,36 +221,46 @@ + Two-digit track number + + + + Disc number + + + Condition + + Genre Tarz - + Composer - + File name - + File path - + Year Yıl - + Comment Yorum @@ -515,12 +525,12 @@ %20 yi boşluğa çevir - + Select Skin Files Kabuk Dosyası Seç - + Skin files Kabuk dosyaları diff --git a/src/ui/translations/qmmp_uk_UA.ts b/src/ui/translations/qmmp_uk_UA.ts index 85463afb6..33ce0b2a9 100644 --- a/src/ui/translations/qmmp_uk_UA.ts +++ b/src/ui/translations/qmmp_uk_UA.ts @@ -221,36 +221,46 @@ + Two-digit track number + + + + Disc number Номер диску + + + Condition + + Genre Жанр - + Composer Композитор - + File name Ім'я файлу - + File path Шлях файлу - + Year Рік - + Comment Коментар @@ -515,12 +525,12 @@ Конвертувати %20 в пробіл - + Select Skin Files Вибрати файли скінів - + Skin files Файли скінів diff --git a/src/ui/translations/qmmp_zh_CN.ts b/src/ui/translations/qmmp_zh_CN.ts index d3d966487..03b612fe9 100644 --- a/src/ui/translations/qmmp_zh_CN.ts +++ b/src/ui/translations/qmmp_zh_CN.ts @@ -221,36 +221,46 @@ + Two-digit track number + + + + Disc number + + + Condition + + Genre 流派 - + Composer - + File name - + File path - + Year 年代 - + Comment 备注 @@ -515,12 +525,12 @@ 转换 %20 为空格 - + Select Skin Files 选择皮肤文件 - + Skin files 皮肤文件 diff --git a/src/ui/translations/qmmp_zh_TW.ts b/src/ui/translations/qmmp_zh_TW.ts index 97c1414db..46d974fd2 100644 --- a/src/ui/translations/qmmp_zh_TW.ts +++ b/src/ui/translations/qmmp_zh_TW.ts @@ -221,36 +221,46 @@ + Two-digit track number + + + + Disc number + + + Condition + + Genre 流派 - + Composer - + File name - + File path - + Year 年代 - + Comment 備註 @@ -515,12 +525,12 @@ 轉換 %20 為空格 - + Select Skin Files 選取皮膚檔案 - + Skin files 皮膚檔案 -- cgit v1.2.3-13-gbd6f