From 6623dcc7cd9f07571a0666d977955872ca159413 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Tue, 19 Jan 2010 13:54:50 +0000 Subject: improved kde notification plugin (Artur Guzik) git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1510 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/kdenotify/kdenotify.cpp | 68 +++++++++++++++------- src/plugins/General/kdenotify/kdenotify.h | 6 ++ src/plugins/General/kdenotify/kdenotify.pro | 11 ++++ src/plugins/General/kdenotify/settingsdialog.cpp | 2 + src/plugins/General/kdenotify/settingsdialog.ui | 9 ++- .../kdenotify/translations/kdenotify_plugin_cs.ts | 17 ++++-- .../kdenotify/translations/kdenotify_plugin_de.ts | 17 ++++-- .../kdenotify/translations/kdenotify_plugin_it.ts | 17 ++++-- .../kdenotify/translations/kdenotify_plugin_lt.ts | 17 ++++-- .../kdenotify/translations/kdenotify_plugin_pl.ts | 21 +++---- .../kdenotify/translations/kdenotify_plugin_ru.ts | 21 ++++--- .../kdenotify/translations/kdenotify_plugin_tr.ts | 17 ++++-- .../translations/kdenotify_plugin_uk_UA.ts | 25 ++++---- .../translations/kdenotify_plugin_zh_CN.ts | 17 ++++-- .../translations/kdenotify_plugin_zh_TW.ts | 17 ++++-- 15 files changed, 187 insertions(+), 95 deletions(-) (limited to 'src') diff --git a/src/plugins/General/kdenotify/kdenotify.cpp b/src/plugins/General/kdenotify/kdenotify.cpp index 5c67107e1..908e21432 100644 --- a/src/plugins/General/kdenotify/kdenotify.cpp +++ b/src/plugins/General/kdenotify/kdenotify.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 * @@ -21,13 +21,13 @@ #include #include #include -#include -#include -#include #include #include #include #include +#include +#include + #include #include #include "kdenotify.h" @@ -43,36 +43,47 @@ KdeNotify::KdeNotify(QObject *parent) : General(parent) return; } + m_ConfigDir = QFileInfo(Qmmp::configFile()).absoluteDir().path(); + QSettings settings(Qmmp::configFile(),QSettings::IniFormat); settings.beginGroup("Kde_Notifier"); m_NotifyDelay = settings.value("notify_delay",10000).toInt(); + m_ShowCovers = settings.value("show_covers",true).toBool(); settings.endGroup(); - connect(SoundCore::instance(),SIGNAL(metaDataChanged()), SLOT(showMetaData())); + + QTimer *timer = new QTimer(this); + timer->setSingleShot(true); + timer->setInterval(3000); //after that notification will be showed. + connect(timer,SIGNAL(timeout()),SLOT(showMetaData())); + connect(SoundCore::instance(),SIGNAL(metaDataChanged()),timer, SLOT(start())); } KdeNotify::~KdeNotify() { + QDir dir(QDir::home()); + dir.remove(m_ConfigDir + "/cover.jpg"); delete notifier; } QString KdeNotify::totalTimeString() { - SoundCore * core = SoundCore::instance(); - int second = core->totalTime() / 1000; - int minute = second / 60; - int hour = minute / 60; + int time = SoundCore::instance()->totalTime()/1000; - if(core->totalTime() >= 3600000) + if(time >= 3600) { - return QString("%1:%2:%3").arg(hour,2,10,QChar('0')).arg(minute%60,2,10,QChar('0')) - .arg(second%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(minute%60,2,10,QChar('0')).arg(second%60,2,10,QChar('0')); + return QString("%1:%2").arg(time/60,2,10,QChar('0')).arg(time%60,2,10,QChar('0')); } -void KdeNotify::showMetaData() +QList KdeNotify::prepareNotification() { SoundCore *core = SoundCore::instance(); + if(core->metaData(Qmmp::URL).isEmpty()) //prevent show empty notification + { + return QList(); + } QList args; QString body(""); //metadata set QString title(core->metaData(Qmmp::TITLE)); @@ -82,8 +93,8 @@ void KdeNotify::showMetaData() args.append("Qmmp"); //app-name args.append(0U); //replaces-id args.append(""); //event-id - args.append(QFileInfo(Qmmp::configFile()).absoluteDir().path() + "/app_icon.png"); //app-icon(path to icon on disk) - args.append(tr("Qmmp now playing:")); //summary (notification title) + 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()) { @@ -93,20 +104,26 @@ void KdeNotify::showMetaData() if(!artist.isEmpty()) { - body.append(tr("by ") + artist + "
"); + body.append(tr("by ") + artist + "
"); } if(!album.isEmpty()) { - body.append(tr("on ") + album); + body.append(tr("on ") + album); } QString nBody; - QString coverPath = MetaDataManager::instance()->getCoverPath(core->metaData(Qmmp::URL)); - if(coverPath.isEmpty()) + 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 = QFileInfo(Qmmp::configFile()).absoluteDir().path() + "/empty_cover.png"; + coverPath = m_ConfigDir + "/empty_cover.png"; } nBody.append("
"); @@ -118,5 +135,12 @@ void KdeNotify::showMetaData() args.append(QVariantMap()); //hints args.append(m_NotifyDelay); //timeout - notifier->callWithArgumentList(QDBus::AutoDetect,"Notify",args); + return args; +} + +void KdeNotify::showMetaData() +{ + QList n = prepareNotification(); + if(!n.isEmpty()) + notifier->callWithArgumentList(QDBus::NoBlock,"Notify",n); } diff --git a/src/plugins/General/kdenotify/kdenotify.h b/src/plugins/General/kdenotify/kdenotify.h index 1d2466d9f..652e111eb 100644 --- a/src/plugins/General/kdenotify/kdenotify.h +++ b/src/plugins/General/kdenotify/kdenotify.h @@ -21,6 +21,9 @@ #ifndef KDENOTIFY_H #define KDENOTIFY_H +#include +#include + #include "qmmpui/general.h" #include "qmmp/qmmp.h" @@ -34,8 +37,11 @@ public: ~KdeNotify(); private: + QList prepareNotification(); QDBusInterface *notifier; + QString m_ConfigDir; int m_NotifyDelay; + bool m_ShowCovers; private slots: void showMetaData(); diff --git a/src/plugins/General/kdenotify/kdenotify.pro b/src/plugins/General/kdenotify/kdenotify.pro index d9f8838fc..d350b513e 100644 --- a/src/plugins/General/kdenotify/kdenotify.pro +++ b/src/plugins/General/kdenotify/kdenotify.pro @@ -28,3 +28,14 @@ HEADERS += kdenotifyfactory.h \ settingsdialog.h RESOURCES += translations/translations.qrc FORMS += settingsdialog.ui + +TRANSLATIONS = translations/kdenotify_plugin_cs.ts \ + translations/kdenotify_plugin_de.ts \ + translations/kdenotify_plugin_zh_CN.ts \ + translations/kdenotify_plugin_zh_TW.ts \ + translations/kdenotify_plugin_ru.ts \ + translations/kdenotify_plugin_pl.ts \ + translations/kdenotify_plugin_uk_UA.ts \ + translations/kdenotify_plugin_it.ts \ + translations/kdenotify_plugin_tr.ts \ + translations/kdenotify_plugin_lt.ts diff --git a/src/plugins/General/kdenotify/settingsdialog.cpp b/src/plugins/General/kdenotify/settingsdialog.cpp index 00f029871..f1acc18e7 100644 --- a/src/plugins/General/kdenotify/settingsdialog.cpp +++ b/src/plugins/General/kdenotify/settingsdialog.cpp @@ -33,6 +33,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QSettings settings(Qmmp::configFile(),QSettings::IniFormat); settings.beginGroup("Kde_Notifier"); ui->kNotifyDelaySpinBox->setValue(settings.value("notify_delay",10000).toInt()); + ui->showCoversCheckBox->setChecked(settings.value("show_covers",true).toBool()); settings.endGroup(); } @@ -46,6 +47,7 @@ void SettingsDialog::accept() QSettings settings(Qmmp::configFile(),QSettings::IniFormat); settings.beginGroup("Kde_Notifier"); settings.setValue("notify_delay",ui->kNotifyDelaySpinBox->value()); + settings.setValue("show_covers",ui->showCoversCheckBox->isChecked()); settings.endGroup(); QDialog::accept(); } diff --git a/src/plugins/General/kdenotify/settingsdialog.ui b/src/plugins/General/kdenotify/settingsdialog.ui index d2ef67a20..0f7ec7f4f 100644 --- a/src/plugins/General/kdenotify/settingsdialog.ui +++ b/src/plugins/General/kdenotify/settingsdialog.ui @@ -31,7 +31,7 @@ - + Qt::Horizontal @@ -41,6 +41,13 @@ + + + + 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 7b4723f86..6981288e8 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_cs.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_cs.ts @@ -4,17 +4,17 @@ KdeNotify - + Qmmp now playing: Qmmp nyní přehrává: - + by - - + on - @@ -22,17 +22,17 @@ KdeNotifyFactory - + KDE 4 notification plugin Notifikační modul pro KDE4 - + About KDE Notification Plugin O notifikačním modulu pro KDE - + KDE 4 notification plugin for Qmmp Notifikační modul Qmmp pro KDE4 @@ -50,5 +50,10 @@ Notification delay [ms]: Prodleva notifikace [ms]: + + + Show covers + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_de.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_de.ts index 7c7c5e01d..ce391aaa9 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_de.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_de.ts @@ -4,17 +4,17 @@ KdeNotify - + Qmmp now playing: Qmmp spielt zurzeit: - + by von - + on auf @@ -22,17 +22,17 @@ KdeNotifyFactory - + KDE 4 notification plugin KDE-4-Benachrichtigungsmodul - + About KDE Notification Plugin Über KDE-4-Benachrichtigungsmodul - + KDE 4 notification plugin for Qmmp KDE-4-Benachrichtigungsmodul für Qmmp @@ -50,5 +50,10 @@ Notification delay [ms]: Benachrichtigungsdauer (ms): + + + Show covers + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_it.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_it.ts index 8d027fd2e..c84ad5af7 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_it.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_it.ts @@ -4,17 +4,17 @@ KdeNotify - + Qmmp now playing: Qmmp ora in esecuzione: - + by di - + on su @@ -22,17 +22,17 @@ KdeNotifyFactory - + KDE 4 notification plugin Plugin notificazione epr KIDE 4 - + About KDE Notification Plugin Info sul Plugin di notificazione per KDE - + KDE 4 notification plugin for Qmmp Plugin di notificazione epr KDE 4 @@ -50,5 +50,10 @@ Notification delay [ms]: Ritardo notificazione [ms]: + + + Show covers + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_lt.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_lt.ts index bddaba2f5..3bacbeba8 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_lt.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_lt.ts @@ -4,17 +4,17 @@ KdeNotify - + Qmmp now playing: Qmmp dabar groja: - + by - + on @@ -22,17 +22,17 @@ KdeNotifyFactory - + KDE 4 notification plugin KDE 4 pranešimų įskiepis - + About KDE Notification Plugin Apie qmmp KDE 4 pranešimų įskiepį - + KDE 4 notification plugin for Qmmp Qmmp KDE 4 pranešimų įskiepis @@ -51,5 +51,10 @@ Notification delay [ms]: Pranešimo užlaikymas [ms]: + + + Show covers + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts index ae78dc51e..08ff804ee 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts @@ -4,21 +4,17 @@ KdeNotify - Now playing: - Teraz odtwarzane: - - - + Qmmp now playing: Qmmp teraz odtwarza: - + by przez - + on na @@ -26,17 +22,17 @@ KdeNotifyFactory - + KDE 4 notification plugin Wtyczka powiadamiania KDE 4 - + About KDE Notification Plugin O wtyczce Powiadomienia KDE - + KDE 4 notification plugin for Qmmp Wtyczka Powiadomienia KDE 4 dla Qmmp @@ -55,5 +51,10 @@ Notification delay [ms]: Czas zanikania [ms]: + + + Show covers + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_ru.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_ru.ts index 2eedcbf10..b1fc4be10 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_ru.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_ru.ts @@ -1,20 +1,20 @@ - - + + KdeNotify - + Qmmp now playing: Играет: - + by исполнитель - + on на @@ -22,17 +22,17 @@ KdeNotifyFactory - + KDE 4 notification plugin Модуль уведомлений KDE4 - + About KDE Notification Plugin О модуле уведомлений KDE4 - + KDE 4 notification plugin for Qmmp Модуль уведомлений KDE4 для Qmmp @@ -51,5 +51,10 @@ Notification delay [ms]: Задержка уведомления [мс]: + + + Show covers + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_tr.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_tr.ts index f27b8c4e4..f06ed9846 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_tr.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_tr.ts @@ -4,17 +4,17 @@ KdeNotify - + Qmmp now playing: - + by - + on @@ -22,17 +22,17 @@ KdeNotifyFactory - + KDE 4 notification plugin - + About KDE Notification Plugin - + KDE 4 notification plugin for Qmmp @@ -50,5 +50,10 @@ Notification delay [ms]: + + + Show covers + + 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 f18ed40db..586556c03 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_uk_UA.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_uk_UA.ts @@ -1,24 +1,20 @@ - - + + KdeNotify - Now playing: - Відтворюється: - - - + Qmmp now playing: Відтворюється: - + by виконавець - + on на @@ -26,17 +22,17 @@ KdeNotifyFactory - + KDE 4 notification plugin Модуль повідомлень KDE4 - + About KDE Notification Plugin Про модуль повідомлень KDE4 - + KDE 4 notification plugin for Qmmp Модуль повідомлень KDE4 для Qmmp @@ -55,5 +51,10 @@ Notification delay [ms]: Час показу [мс]: + + + Show covers + + 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 f27b8c4e4..f06ed9846 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_CN.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_CN.ts @@ -4,17 +4,17 @@ KdeNotify - + Qmmp now playing: - + by - + on @@ -22,17 +22,17 @@ KdeNotifyFactory - + KDE 4 notification plugin - + About KDE Notification Plugin - + KDE 4 notification plugin for Qmmp @@ -50,5 +50,10 @@ Notification delay [ms]: + + + Show covers + + 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 f27b8c4e4..f06ed9846 100644 --- a/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_TW.ts +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_zh_TW.ts @@ -4,17 +4,17 @@ KdeNotify - + Qmmp now playing: - + by - + on @@ -22,17 +22,17 @@ KdeNotifyFactory - + KDE 4 notification plugin - + About KDE Notification Plugin - + KDE 4 notification plugin for Qmmp @@ -50,5 +50,10 @@ Notification delay [ms]: + + + Show covers + + -- cgit v1.2.3-13-gbd6f