From 6f72ae7e3e61b330dd1874a951b258075649fe8e Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Thu, 29 Oct 2009 09:43:25 +0000 Subject: added kde notifications plugin (author: Artur Guzik) (Closes issue 164) git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1337 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/CMakeLists.txt | 5 ++ src/plugins/General/General.pro | 3 +- src/plugins/General/kdenotify/CMakeLists.txt | 65 ++++++++++++++ src/plugins/General/kdenotify/images/app_icon.png | Bin 0 -> 1930 bytes .../General/kdenotify/images/empty_cover.png | Bin 0 -> 8926 bytes src/plugins/General/kdenotify/kdenotify.cpp | 99 +++++++++++++++++++++ src/plugins/General/kdenotify/kdenotify.h | 27 ++++++ src/plugins/General/kdenotify/kdenotify.pro | 30 +++++++ src/plugins/General/kdenotify/kdenotifyfactory.cpp | 43 +++++++++ src/plugins/General/kdenotify/kdenotifyfactory.h | 23 +++++ src/plugins/General/kdenotify/settingsdialog.cpp | 43 +++++++++ src/plugins/General/kdenotify/settingsdialog.h | 28 ++++++ src/plugins/General/kdenotify/settingsdialog.ui | 81 +++++++++++++++++ .../kdenotify/translations/kdenotify_plugin_pl.ts | 39 ++++++++ .../kdenotify/translations/translations.qrc | 5 ++ 15 files changed, 490 insertions(+), 1 deletion(-) create mode 100644 src/plugins/General/kdenotify/CMakeLists.txt create mode 100644 src/plugins/General/kdenotify/images/app_icon.png create mode 100644 src/plugins/General/kdenotify/images/empty_cover.png create mode 100644 src/plugins/General/kdenotify/kdenotify.cpp create mode 100644 src/plugins/General/kdenotify/kdenotify.h create mode 100644 src/plugins/General/kdenotify/kdenotify.pro create mode 100644 src/plugins/General/kdenotify/kdenotifyfactory.cpp create mode 100644 src/plugins/General/kdenotify/kdenotifyfactory.h create mode 100644 src/plugins/General/kdenotify/settingsdialog.cpp create mode 100644 src/plugins/General/kdenotify/settingsdialog.h create mode 100644 src/plugins/General/kdenotify/settingsdialog.ui create mode 100644 src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts create mode 100644 src/plugins/General/kdenotify/translations/translations.qrc (limited to 'src/plugins/General') diff --git a/src/plugins/General/CMakeLists.txt b/src/plugins/General/CMakeLists.txt index cdd47cbd3..629c741a8 100644 --- a/src/plugins/General/CMakeLists.txt +++ b/src/plugins/General/CMakeLists.txt @@ -7,6 +7,7 @@ SET(USE_HAL TRUE CACHE BOOL "enable/disable hal plugin") SET(USE_HOTKEY TRUE CACHE BOOL "enable/disable global hotkey plugin") SET(USE_FILEOPS TRUE CACHE BOOL "enable/disable fileops plugin") SET(USE_COVER TRUE CACHE BOOL "enable/disable cover manager plugin") +SET(USE_KDENOTIFY TRUE CACHE BOOL "enable/disable kde notification plugin") IF(USE_MPRIS) add_subdirectory(mpris) @@ -43,3 +44,7 @@ ENDIF(USE_FILEOPS) IF(USE_COVER) add_subdirectory(covermanager) ENDIF(USE_COVER) + +IF(USE_KDENOTIFY) +add_subdirectory(kdenotify) +ENDIF(USE_KDENOTIFY) diff --git a/src/plugins/General/General.pro b/src/plugins/General/General.pro index b1316d360..4c935d9a2 100644 --- a/src/plugins/General/General.pro +++ b/src/plugins/General/General.pro @@ -6,5 +6,6 @@ SUBDIRS += statusicon \ unix:SUBDIRS += mpris \ hal \ hotkey \ - covermanager + covermanager \ + kdenotify TEMPLATE = subdirs diff --git a/src/plugins/General/kdenotify/CMakeLists.txt b/src/plugins/General/kdenotify/CMakeLists.txt new file mode 100644 index 000000000..e27d26e0e --- /dev/null +++ b/src/plugins/General/kdenotify/CMakeLists.txt @@ -0,0 +1,65 @@ +project(libkdenotify) + +cmake_minimum_required(VERSION 2.4.8 FATAL_ERROR) + +SET (QT_USE_QTDBUS TRUE) + +INCLUDE(FindQt4) + +include(${QT_USE_FILE}) + +if(COMMAND cmake_policy) +cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +# qt plugin +ADD_DEFINITIONS( -Wall ) +ADD_DEFINITIONS(${QT_DEFINITIONS}) +ADD_DEFINITIONS(-DQT_PLUGIN) +ADD_DEFINITIONS(-DQT_NO_DEBUG) +ADD_DEFINITIONS(-DQT_SHARED) +ADD_DEFINITIONS(-DQT_THREAD) + + + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +# libqmmpui & libqmmp +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmpui) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmp) + +SET(libkdenotify_SRCS + kdenotify.cpp + kdenotifyfactory.cpp + settingsdialog.cpp +) + +SET(libkdenotify_MOC_HDRS + kdenotifyfactory.h + kdenotify.h + settingsdialog.h +) + +SET(libkdenotify_RCCS translations/translations.qrc) + +QT4_ADD_RESOURCES(libkdenotify_RCC_SRCS ${libkdenotify_RCCS}) + +QT4_WRAP_CPP(libkdenotify_MOC_SRCS ${libkdenotify_MOC_HDRS}) + +# user interface +SET(libkdenotify_UIS + settingsdialog.ui +) + +QT4_WRAP_UI(libkdenotify_UIS_H ${libkdenotify_UIS}) + +# QT4_WRAP_UI(libkdenotify_UIS_H ${libkdenotify_UIS}) +# Don't forget to include output directory, otherwise +# the UI file won't be wrapped! +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +ADD_LIBRARY(kdenotify MODULE ${libkdenotify_SRCS} ${libkdenotify_MOC_SRCS} ${libkdenotify_RCC_SRCS} ${libkdenotify_UIS_H}) +add_dependencies(kdenotify qmmpui) +target_link_libraries(kdenotify ${QT_LIBRARIES} -lqmmpui -lqmmp) +install(TARGETS kdenotify DESTINATION ${LIB_DIR}/qmmp/General) diff --git a/src/plugins/General/kdenotify/images/app_icon.png b/src/plugins/General/kdenotify/images/app_icon.png new file mode 100644 index 000000000..cace7e215 Binary files /dev/null and b/src/plugins/General/kdenotify/images/app_icon.png differ diff --git a/src/plugins/General/kdenotify/images/empty_cover.png b/src/plugins/General/kdenotify/images/empty_cover.png new file mode 100644 index 000000000..cbc0d1ddc Binary files /dev/null and b/src/plugins/General/kdenotify/images/empty_cover.png differ diff --git a/src/plugins/General/kdenotify/kdenotify.cpp b/src/plugins/General/kdenotify/kdenotify.cpp new file mode 100644 index 000000000..0b77c11f1 --- /dev/null +++ b/src/plugins/General/kdenotify/kdenotify.cpp @@ -0,0 +1,99 @@ +#include "kdenotify.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +KdeNotify::KdeNotify(QObject *parent) : General(parent) +{ + if (!QDBusConnection::sessionBus ().interface ()->isServiceRegistered ("org.kde.VisualNotifications")) + { + qWarning("KdeNotify: org.kde.VisualNotifications is not registered"); + return; + } + notifier = new QDBusInterface("org.kde.VisualNotifications", + "/VisualNotifications", "org.kde.VisualNotifications"); + QSettings settings(Qmmp::configFile(),QSettings::IniFormat); + settings.beginGroup("Kde_Notifier"); + m_NotifyDelay = settings.value("notify_delay",10000).toInt(); + settings.endGroup(); + connect(SoundCore::instance(),SIGNAL(metaDataChanged()),this,SLOT(showMetaData())); +} + +KdeNotify::~KdeNotify() +{ + delete notifier; +} + +QString KdeNotify::totalTimeString() +{ + SoundCore * core = SoundCore::instance(); + int second = core->totalTime() / 1000; + int minute = second / 60; + int hour = minute / 60; + + if(core->totalTime() >= 3600000) + { + 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").arg(minute%60,2,10,QChar('0')).arg(second%60,2,10,QChar('0')); +} + +void KdeNotify::showMetaData() +{ + SoundCore *core = SoundCore::instance(); + 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 + 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) + + if(title.isEmpty()) + { + title = QFileInfo(core->metaData(Qmmp::URL)).completeBaseName(); + } + body.append("" + title + " (" + totalTimeString() +")
"); + + if(!artist.isEmpty()) + { + body.append(tr("by ") + artist + "
"); + } + + if(!album.isEmpty()) + { + body.append(tr("on ") + album); + } + + QString nBody; + QString coverPath = MetaDataManager::instance()->getCoverPath(core->metaData(Qmmp::URL)); + + if(coverPath.isEmpty()) + { + coverPath = QFileInfo(Qmmp::configFile()).absoluteDir().path() + "/empty_cover.png"; + } + + nBody.append("
"); + nBody.append("%2
"); + nBody = nBody.arg(coverPath,body); + + args.append(nBody); //body + args.append(QStringList()); //actions + args.append(QVariantMap()); //hints + args.append(m_NotifyDelay); //timeout + + notifier->callWithArgumentList(QDBus::AutoDetect,"Notify",args); +} diff --git a/src/plugins/General/kdenotify/kdenotify.h b/src/plugins/General/kdenotify/kdenotify.h new file mode 100644 index 000000000..61309614c --- /dev/null +++ b/src/plugins/General/kdenotify/kdenotify.h @@ -0,0 +1,27 @@ +#ifndef KDENOTIFY_H +#define KDENOTIFY_H + +#include "qmmpui/general.h" +#include "qmmp/qmmp.h" + +class QDBusInterface; + +class KdeNotify : public General +{ + Q_OBJECT; +public: + KdeNotify(QObject *parent = 0); + ~KdeNotify(); + +private: + QDBusInterface *notifier; + int m_NotifyDelay; + +private slots: + void showMetaData(); + QString totalTimeString(); + + +}; + +#endif // KDENOTIFY_H diff --git a/src/plugins/General/kdenotify/kdenotify.pro b/src/plugins/General/kdenotify/kdenotify.pro new file mode 100644 index 000000000..d9f8838fc --- /dev/null +++ b/src/plugins/General/kdenotify/kdenotify.pro @@ -0,0 +1,30 @@ +# ------------------------------------------------- +# Project created by QtCreator 2009-10-14T17:55:38 +# ------------------------------------------------- +include(../../plugins.pri) +INCLUDEPATH += ../../../../src +QT += dbus +CONFIG += release \ + warn_on \ + plugin +unix:TARGET = $$PLUGINS_PREFIX/General/kdenotify +unix:QMAKE_CLEAN = $$PLUGINS_PREFIX/General/libkdenotify.so +TEMPLATE = lib +unix { + QMAKE_LIBDIR += ../../../../lib + LIBS += -lqmmpui \ + -lqmmp +} +unix { + isEmpty(LIB_DIR):LIB_DIR = /lib + target.path = $$LIB_DIR/qmmp/General + INSTALLS += target +} +SOURCES += kdenotifyfactory.cpp \ + kdenotify.cpp \ + settingsdialog.cpp +HEADERS += kdenotifyfactory.h \ + kdenotify.h \ + settingsdialog.h +RESOURCES += translations/translations.qrc +FORMS += settingsdialog.ui diff --git a/src/plugins/General/kdenotify/kdenotifyfactory.cpp b/src/plugins/General/kdenotify/kdenotifyfactory.cpp new file mode 100644 index 000000000..2fdd9f75b --- /dev/null +++ b/src/plugins/General/kdenotify/kdenotifyfactory.cpp @@ -0,0 +1,43 @@ +#include "kdenotifyfactory.h" +#include "kdenotify.h" +#include "settingsdialog.h" + +#include + +const GeneralProperties KdeNotifyFactory::properties() const +{ + GeneralProperties properties; + properties.name = tr("KDE 4 notification plugin"); + properties.shortName = "kdenotify_icon"; + properties.hasAbout = TRUE; + properties.hasSettings = TRUE; + properties.visibilityControl = FALSE; + return properties; +} + +General *KdeNotifyFactory::create(QObject *parent) +{ + return new KdeNotify(parent); +} + +QDialog *KdeNotifyFactory::createConfigDialog(QWidget *parent) +{ + return new SettingsDialog(parent); +} + +void KdeNotifyFactory::showAbout(QWidget *parent) +{ + QMessageBox::about (parent, tr("About KDE Notification Plugin"), + tr("KDE 4 notification plugin for Qmmp \n") + + "Artur Guzik "); +} + +QTranslator *KdeNotifyFactory::createTranslator(QObject *parent) +{ + QTranslator *translator = new QTranslator(parent); + QString locale = Qmmp::systemLanguageID(); + translator->load(QString(":/kdenotify_plugin_") + locale); + return translator; +} + +Q_EXPORT_PLUGIN(KdeNotifyFactory) diff --git a/src/plugins/General/kdenotify/kdenotifyfactory.h b/src/plugins/General/kdenotify/kdenotifyfactory.h new file mode 100644 index 000000000..075f9b5f4 --- /dev/null +++ b/src/plugins/General/kdenotify/kdenotifyfactory.h @@ -0,0 +1,23 @@ +#ifndef KDENOTIFYFACTORY_H +#define KDENOTIFYFACTORY_H + +#include +#include +#include + +#include +#include + +class KdeNotifyFactory : public QObject, public GeneralFactory +{ + Q_OBJECT; + Q_INTERFACES(GeneralFactory) +public: + const GeneralProperties properties() const; + General *create(QObject *parent); + QDialog *createConfigDialog(QWidget *parent); + void showAbout(QWidget *parent); + QTranslator *createTranslator(QObject *parent); +}; + +#endif // KDENOTIFYFACTORY_H diff --git a/src/plugins/General/kdenotify/settingsdialog.cpp b/src/plugins/General/kdenotify/settingsdialog.cpp new file mode 100644 index 000000000..b4aeae018 --- /dev/null +++ b/src/plugins/General/kdenotify/settingsdialog.cpp @@ -0,0 +1,43 @@ +#include "settingsdialog.h" +#include "ui_settingsdialog.h" +#include + +#include + +SettingsDialog::SettingsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SettingsDialog) +{ + ui->setupUi(this); + + QSettings settings(Qmmp::configFile(),QSettings::IniFormat); + settings.beginGroup("Kde_Notifier"); + ui->kNotifyDelaySpinBox->setValue(settings.value("notify_delay",10000).toInt()); + settings.endGroup(); +} + +SettingsDialog::~SettingsDialog() +{ + delete ui; +} + +void SettingsDialog::accept() +{ + QSettings settings(Qmmp::configFile(),QSettings::IniFormat); + settings.beginGroup("Kde_Notifier"); + settings.setValue("notify_delay",ui->kNotifyDelaySpinBox->value()); + settings.endGroup(); + QDialog::accept(); +} + +void SettingsDialog::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} diff --git a/src/plugins/General/kdenotify/settingsdialog.h b/src/plugins/General/kdenotify/settingsdialog.h new file mode 100644 index 000000000..500167612 --- /dev/null +++ b/src/plugins/General/kdenotify/settingsdialog.h @@ -0,0 +1,28 @@ +#ifndef SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include + +namespace Ui { + class SettingsDialog; +} + +class SettingsDialog : public QDialog +{ +Q_OBJECT + +public: + SettingsDialog(QWidget *parent = 0); + ~SettingsDialog(); + +public slots: + virtual void accept(); + +protected: + void changeEvent(QEvent *e); + +private: + Ui::SettingsDialog *ui; +}; + +#endif // SETTINGSDIALOG_H diff --git a/src/plugins/General/kdenotify/settingsdialog.ui b/src/plugins/General/kdenotify/settingsdialog.ui new file mode 100644 index 000000000..d2ef67a20 --- /dev/null +++ b/src/plugins/General/kdenotify/settingsdialog.ui @@ -0,0 +1,81 @@ + + + SettingsDialog + + + + 0 + 0 + 400 + 104 + + + + KDE 4 Notification Plugin Settings + + + + + + Notification delay [ms]: + + + + + + + 50000 + + + 10000 + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts b/src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts new file mode 100644 index 000000000..104b3c401 --- /dev/null +++ b/src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts @@ -0,0 +1,39 @@ + + + KdeNotify + + + Now playing: + Teraz odtwarzane: + + + + by + przez + + + + on + na + + + + KdeNotifyFactory + + + KDE 4 notification plugin + Wtyczka powiadamiania KDE 4 + + + + SettingsDialog + + KDE 4 Notification Plugin Settings + Ustawienia wtyczki Powiadamianie KDE 4 + + + Notification delay [ms]: + Czas zanikania [ms]: + + + diff --git a/src/plugins/General/kdenotify/translations/translations.qrc b/src/plugins/General/kdenotify/translations/translations.qrc new file mode 100644 index 000000000..a1560ef64 --- /dev/null +++ b/src/plugins/General/kdenotify/translations/translations.qrc @@ -0,0 +1,5 @@ + + + kdenotify_plugin_pl.qm + + -- cgit v1.2.3-13-gbd6f