From 2eff41971d3776c7c4ac1ea9fa9a6f5a4f1513ab Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sat, 20 Mar 2010 07:22:50 +0000 Subject: improved kde4 notification (added embedded covers support and templates) git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1634 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/kdenotify/kdenotify.cpp | 59 ++++++++-------------- src/plugins/General/kdenotify/kdenotify.h | 6 ++- src/plugins/General/kdenotify/settingsdialog.cpp | 14 ++++- src/plugins/General/kdenotify/settingsdialog.h | 6 ++- src/plugins/General/kdenotify/settingsdialog.ui | 53 +++++++++++++++---- .../kdenotify/translations/kdenotify_plugin_cs.ts | 26 +++++----- .../kdenotify/translations/kdenotify_plugin_de.ts | 26 +++++----- .../kdenotify/translations/kdenotify_plugin_it.ts | 26 +++++----- .../kdenotify/translations/kdenotify_plugin_lt.ts | 26 +++++----- .../kdenotify/translations/kdenotify_plugin_pl.ts | 26 +++++----- .../kdenotify/translations/kdenotify_plugin_ru.ts | 28 +++++----- .../kdenotify/translations/kdenotify_plugin_tr.ts | 26 +++++----- .../translations/kdenotify_plugin_uk_UA.ts | 26 +++++----- .../translations/kdenotify_plugin_zh_CN.ts | 26 +++++----- .../translations/kdenotify_plugin_zh_TW.ts | 26 +++++----- 15 files changed, 218 insertions(+), 182 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/General/kdenotify/kdenotify.cpp b/src/plugins/General/kdenotify/kdenotify.cpp index 419189f3a..af8e87db6 100644 --- a/src/plugins/General/kdenotify/kdenotify.cpp +++ b/src/plugins/General/kdenotify/kdenotify.cpp @@ -27,7 +27,7 @@ #include #include #include - +#include #include #include #include "kdenotify.h" @@ -35,12 +35,13 @@ KdeNotify::KdeNotify(QObject *parent) : General(parent),m_UseFreedesktopSpec(false) { notifier = new QDBusInterface("org.kde.VisualNotifications", - "/VisualNotifications", "org.kde.VisualNotifications"); + "/VisualNotifications", "org.kde.VisualNotifications", + QDBusConnection::sessionBus(), this); if(notifier->lastError().type() != QDBusError::NoError) { delete(notifier); qWarning() << "KdeNotify: unable to create dbus interface." - << "Have you got KDE SC 4.4 or newer? Lets try..."; + << "Have you got KDE SC 4.4 or newer? Lets try..."; notifier = new QDBusInterface("org.freedesktop.Notifications", "/org/freedesktop/Notifications","org.freedesktop.Notifications"); @@ -58,6 +59,8 @@ KdeNotify::KdeNotify(QObject *parent) : General(parent),m_UseFreedesktopSpec(fal settings.beginGroup("Kde_Notifier"); m_NotifyDelay = settings.value("notify_delay",10000).toInt(); m_ShowCovers = settings.value("show_covers",true).toBool(); + m_template = settings.value("template", DEFAULT_TEMPLATE).toString(); + m_template.remove("\n"); settings.endGroup(); QTimer *timer = new QTimer(this); @@ -71,7 +74,6 @@ KdeNotify::~KdeNotify() { QDir dir(QDir::home()); dir.remove(m_ConfigDir + "/cover.jpg"); - delete notifier; } QString KdeNotify::totalTimeString() @@ -80,8 +82,8 @@ QString KdeNotify::totalTimeString() if(time >= 3600) { - return QString("%1:%2:%3").arg(time/3600,2,10,QChar('0')).arg(time%3600/60,2,10,QChar('0')) - .arg(time%60,2,10,QChar('0')); + return QString("%1:%2:%3").arg(time/3600,2,10,QChar('0')).arg(time%3600/60,2,10,QChar('0')) + .arg(time%60,2,10,QChar('0')); } return QString("%1:%2").arg(time/60,2,10,QChar('0')).arg(time%60,2,10,QChar('0')); } @@ -91,14 +93,9 @@ QList KdeNotify::prepareNotification() SoundCore *core = SoundCore::instance(); if(core->metaData(Qmmp::URL).isEmpty()) //prevent show empty notification { - return QList(); + return QList(); } QList args; - QString body(""); //metadata set - QString title(core->metaData(Qmmp::TITLE)); - QString artist(core->metaData(Qmmp::ARTIST)); - QString album(core->metaData(Qmmp::ALBUM)); - args.append("Qmmp"); //app-name args.append(0U); //replaces-id if(!m_UseFreedesktopSpec) @@ -106,36 +103,24 @@ QList KdeNotify::prepareNotification() args.append(m_ConfigDir + "/app_icon.png"); //app-icon(path to icon on disk) args.append(tr("Qmmp now playing:")); //summary (notification title) - if(title.isEmpty()) - { - title = QFileInfo(core->metaData(Qmmp::URL)).completeBaseName(); - } - body.append("" + title + " (" + totalTimeString() +")
"); + MetaDataFormatter f(m_template); + QString body = f.parse(core->metaData(), core->totalTime()/1000); - if(!artist.isEmpty()) + QString coverPath; + if(m_ShowCovers) { - body.append(tr("by ") + artist + "
"); + QPixmap cover = MetaDataManager::instance()->instance()->getCover(core->metaData(Qmmp::URL)); + if(!cover.isNull()) + { + coverPath = m_ConfigDir + "/cover.jpg"; + cover.scaled(100,100,Qt::IgnoreAspectRatio,Qt::SmoothTransformation).save(coverPath); + } } + if(coverPath.isEmpty()) + coverPath = m_ConfigDir + "/empty_cover.png"; - if(!album.isEmpty()) - { - body.append(tr("on ") + album); - } QString nBody; - - QString coverPath = MetaDataManager::instance()->getCoverPath(core->metaData(Qmmp::URL)); - if(!coverPath.isEmpty() && m_ShowCovers) - { - QImage image(coverPath); - image.scaled(100,100,Qt::IgnoreAspectRatio,Qt::SmoothTransformation).save(m_ConfigDir + "/cover.jpg","JPG"); - coverPath = m_ConfigDir + "/cover.jpg"; - } - else if(coverPath.isEmpty() || !m_ShowCovers) - { - coverPath = m_ConfigDir + "/empty_cover.png"; - } - nBody.append("
"); nBody.append("%2
"); nBody = nBody.arg(coverPath,body); @@ -152,5 +137,5 @@ void KdeNotify::showMetaData() { QList n = prepareNotification(); if(!n.isEmpty()) - notifier->callWithArgumentList(QDBus::NoBlock,"Notify",n); + notifier->callWithArgumentList(QDBus::NoBlock,"Notify",n); } diff --git a/src/plugins/General/kdenotify/kdenotify.h b/src/plugins/General/kdenotify/kdenotify.h index 58317d61d..e928c27ab 100644 --- a/src/plugins/General/kdenotify/kdenotify.h +++ b/src/plugins/General/kdenotify/kdenotify.h @@ -27,6 +27,8 @@ #include "qmmpui/general.h" #include "qmmp/qmmp.h" +#define DEFAULT_TEMPLATE "%if(%t,%t,%f)\n%if(%p,
%p,)\n%if(%a,
%a,)\n%if(%l,
%l,)" + class QDBusInterface; class KdeNotify : public General @@ -43,11 +45,11 @@ private: int m_NotifyDelay; bool m_ShowCovers; bool m_UseFreedesktopSpec; + QString m_template; + private slots: void showMetaData(); QString totalTimeString(); - - }; #endif // KDENOTIFY_H diff --git a/src/plugins/General/kdenotify/settingsdialog.cpp b/src/plugins/General/kdenotify/settingsdialog.cpp index f1acc18e7..7bc7399bf 100644 --- a/src/plugins/General/kdenotify/settingsdialog.cpp +++ b/src/plugins/General/kdenotify/settingsdialog.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Artur Guzik * + * Copyright (C) 2009-2010 by Artur Guzik * * a.guzik88@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -20,7 +20,9 @@ #include "settingsdialog.h" #include "ui_settingsdialog.h" +#include "kdenotify.h" #include +#include #include @@ -34,6 +36,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : settings.beginGroup("Kde_Notifier"); ui->kNotifyDelaySpinBox->setValue(settings.value("notify_delay",10000).toInt()); ui->showCoversCheckBox->setChecked(settings.value("show_covers",true).toBool()); + m_template = settings.value("template", DEFAULT_TEMPLATE).toString(); settings.endGroup(); } @@ -48,6 +51,7 @@ void SettingsDialog::accept() settings.beginGroup("Kde_Notifier"); settings.setValue("notify_delay",ui->kNotifyDelaySpinBox->value()); settings.setValue("show_covers",ui->showCoversCheckBox->isChecked()); + settings.setValue("template",m_template); settings.endGroup(); QDialog::accept(); } @@ -63,3 +67,11 @@ void SettingsDialog::changeEvent(QEvent *e) break; } } + +void SettingsDialog::on_templateButton_clicked() +{ + QString t = TemplateEditor::getTemplate(this, tr("Notification Template"), m_template, + DEFAULT_TEMPLATE); + if(!t.isEmpty()) + m_template = t; +} diff --git a/src/plugins/General/kdenotify/settingsdialog.h b/src/plugins/General/kdenotify/settingsdialog.h index 07e7669cd..7e0f8d4a6 100644 --- a/src/plugins/General/kdenotify/settingsdialog.h +++ b/src/plugins/General/kdenotify/settingsdialog.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Artur Guzik * + * Copyright (C) 2009-2010 by Artur Guzik * * a.guzik88@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -38,11 +38,15 @@ public: public slots: virtual void accept(); +private slots: + virtual void on_templateButton_clicked(); + protected: void changeEvent(QEvent *e); private: Ui::SettingsDialog *ui; + QString m_template; }; #endif // SETTINGSDIALOG_H diff --git a/src/plugins/General/kdenotify/settingsdialog.ui b/src/plugins/General/kdenotify/settingsdialog.ui index 0f7ec7f4f..67785333d 100644 --- a/src/plugins/General/kdenotify/settingsdialog.ui +++ b/src/plugins/General/kdenotify/settingsdialog.ui @@ -6,14 +6,23 @@ 0 0 - 400 - 104 + 296 + 125 KDE 4 Notification Plugin Settings + + 6 + + + 6 + + + 6 + @@ -31,7 +40,38 @@ - + + + + Show covers + + + + + + + + + Change template + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + Qt::Horizontal @@ -41,13 +81,6 @@ - - - - Show covers - - - diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_cs.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_cs.ts index c3205d308..bd8fbd8c8 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_cs.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_cs.ts @@ -4,20 +4,10 @@ KdeNotify - + Qmmp now playing: Qmmp nyní přehrává: - - - by - - - - - - on - - - KdeNotifyFactory @@ -46,14 +36,24 @@ Nastavení notifikačního modulu pro KDE4 - + Notification delay [ms]: Prodleva notifikace [ms]: - + Show covers + + + Change template + + + + + Notification Template + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_de.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_de.ts index a35e8c10a..f9ce9c765 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_de.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_de.ts @@ -4,20 +4,10 @@ KdeNotify - + Qmmp now playing: Qmmp spielt zurzeit: - - - by - von - - - - on - auf - KdeNotifyFactory @@ -46,14 +36,24 @@ Einstellungen KDE-4-Benachrichtigungsmodul - + Notification delay [ms]: Benachrichtigungsdauer (ms): - + Show covers Cover anzeigen + + + Change template + + + + + Notification Template + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_it.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_it.ts index 2b2fe5a2a..dba21edac 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_it.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_it.ts @@ -4,20 +4,10 @@ KdeNotify - + Qmmp now playing: Qmmp ora in esecuzione: - - - by - di - - - - on - su - KdeNotifyFactory @@ -46,14 +36,24 @@ Impostazioni del plugin di notificazione per KDE 4 - + Notification delay [ms]: Ritardo notificazione [ms]: - + Show covers Mostra copertine + + + Change template + + + + + Notification Template + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_lt.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_lt.ts index d6ea24065..32df41ab7 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_lt.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_lt.ts @@ -4,20 +4,10 @@ KdeNotify - + Qmmp now playing: Qmmp dabar groja: - - - by - - - - - on - - KdeNotifyFactory @@ -47,14 +37,24 @@ KDE 4 pranešimų įskiepio nustatymai - + Notification delay [ms]: Pranešimo užlaikymas [ms]: - + Show covers + + + Change template + + + + + Notification Template + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts index d464615aa..a975d06d8 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts @@ -4,20 +4,10 @@ KdeNotify - + Qmmp now playing: Qmmp teraz odtwarza: - - - by - przez - - - - on - na - KdeNotifyFactory @@ -47,14 +37,24 @@ Ustawienia wtyczki Powiadamianie KDE 4 - + Notification delay [ms]: Czas zanikania [ms]: - + Show covers + + + Change template + + + + + Notification Template + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_ru.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_ru.ts index 6aa6fe232..3bc81f68d 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_ru.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_ru.ts @@ -4,20 +4,10 @@ KdeNotify - + Qmmp now playing: Играет: - - - by - исполнитель - - - - on - на - KdeNotifyFactory @@ -47,14 +37,24 @@ Настройки модуля уведомлений KDE4 - + Notification delay [ms]: Задержка уведомления [мс]: - + Show covers - + Показывать обложки + + + + Change template + Изменить шаблон + + + + Notification Template + Шаблон уведомления diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_tr.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_tr.ts index 6d4e10a3f..15e7d6c89 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_tr.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_tr.ts @@ -4,20 +4,10 @@ KdeNotify - + Qmmp now playing: - - - by - - - - - on - - KdeNotifyFactory @@ -46,14 +36,24 @@ - + Notification delay [ms]: - + Show covers + + + Change template + + + + + Notification Template + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_uk_UA.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_uk_UA.ts index ea4ded89d..71e4c772b 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_uk_UA.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_uk_UA.ts @@ -4,20 +4,10 @@ KdeNotify - + Qmmp now playing: Відтворюється: - - - by - виконавець - - - - on - на - KdeNotifyFactory @@ -47,14 +37,24 @@ Налаштування модуля повідомлень KDE4 - + Notification delay [ms]: Час показу [мс]: - + Show covers Показати обкладинки + + + Change template + + + + + Notification Template + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_CN.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_CN.ts index 6d4e10a3f..15e7d6c89 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_CN.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_CN.ts @@ -4,20 +4,10 @@ KdeNotify - + Qmmp now playing: - - - by - - - - - on - - KdeNotifyFactory @@ -46,14 +36,24 @@ - + Notification delay [ms]: - + Show covers + + + Change template + + + + + Notification Template + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_TW.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_TW.ts index 6d4e10a3f..15e7d6c89 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_TW.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_TW.ts @@ -4,20 +4,10 @@ KdeNotify - + Qmmp now playing: - - - by - - - - - on - - KdeNotifyFactory @@ -46,14 +36,24 @@ - + Notification delay [ms]: - + Show covers + + + Change template + + + + + Notification Template + + -- cgit v1.2.3-13-gbd6f