diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-10-29 09:43:25 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-10-29 09:43:25 +0000 |
| commit | 6f72ae7e3e61b330dd1874a951b258075649fe8e (patch) | |
| tree | c911ac5434ab5cb258328037590e78af3ca92361 | |
| parent | 81a8ff3c3605ddcd22f2e6400e5a7a3e2f330f43 (diff) | |
| download | qmmp-6f72ae7e3e61b330dd1874a951b258075649fe8e.tar.gz qmmp-6f72ae7e3e61b330dd1874a951b258075649fe8e.tar.bz2 qmmp-6f72ae7e3e61b330dd1874a951b258075649fe8e.zip | |
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
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/plugins/General/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | src/plugins/General/General.pro | 3 | ||||
| -rw-r--r-- | src/plugins/General/kdenotify/CMakeLists.txt | 65 | ||||
| -rw-r--r-- | src/plugins/General/kdenotify/images/app_icon.png | bin | 0 -> 1930 bytes | |||
| -rw-r--r-- | src/plugins/General/kdenotify/images/empty_cover.png | bin | 0 -> 8926 bytes | |||
| -rw-r--r-- | src/plugins/General/kdenotify/kdenotify.cpp | 99 | ||||
| -rw-r--r-- | src/plugins/General/kdenotify/kdenotify.h | 27 | ||||
| -rw-r--r-- | src/plugins/General/kdenotify/kdenotify.pro | 30 | ||||
| -rw-r--r-- | src/plugins/General/kdenotify/kdenotifyfactory.cpp | 43 | ||||
| -rw-r--r-- | src/plugins/General/kdenotify/kdenotifyfactory.h | 23 | ||||
| -rw-r--r-- | src/plugins/General/kdenotify/settingsdialog.cpp | 43 | ||||
| -rw-r--r-- | src/plugins/General/kdenotify/settingsdialog.h | 28 | ||||
| -rw-r--r-- | src/plugins/General/kdenotify/settingsdialog.ui | 81 | ||||
| -rw-r--r-- | src/plugins/General/kdenotify/translations/kdenotify_plugin_pl.ts | 39 | ||||
| -rw-r--r-- | src/plugins/General/kdenotify/translations/translations.qrc | 5 |
16 files changed, 491 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c08cf7b0c..5847f5148 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,6 +130,7 @@ PRINT_SUMMARY ("HAL support ......................." USE_HAL 1) PRINT_SUMMARY ("Global hotkey support ............." USE_HOTKEY X11_FOUND) PRINT_SUMMARY ("File operations ..................." USE_FILEOPS 1) PRINT_SUMMARY ("Cover manager ....................." USE_COVER 1) +PRINT_SUMMARY ("KDE4 notifications support ........" USE_KDENOTIFY 1) MESSAGE("") MESSAGE("File Dialogs:") 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 Binary files differnew file mode 100644 index 000000000..cace7e215 --- /dev/null +++ b/src/plugins/General/kdenotify/images/app_icon.png diff --git a/src/plugins/General/kdenotify/images/empty_cover.png b/src/plugins/General/kdenotify/images/empty_cover.png Binary files differnew file mode 100644 index 000000000..cbc0d1ddc --- /dev/null +++ b/src/plugins/General/kdenotify/images/empty_cover.png 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 <qmmp/soundcore.h> +#include <qmmp/metadatamanager.h> +#include <QDBusConnection> +#include <QDBusConnectionInterface> +#include <QDBusInterface> +#include <QList> +#include <QStringList> +#include <QVariant> +#include <QFileInfo> +#include <QDir> +#include <QSettings> + +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<QVariant> 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("<b>" + title + "</b> (" + totalTimeString() +")<br>"); + + if(!artist.isEmpty()) + { + body.append(tr("by ") + artist + "<br>"); + } + + 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("<table padding=\"3px\"><tr><td width=\"80px\" height=\"80px\" padding=\"3px\">"); + nBody.append("<img height=\"80\" width=\"80\" src=\"%1\"></td><td width=\"10\"></td><td>%2</td></tr><table>"); + 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 <QtGui> + +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 <a.guzik88@gmail.com>"); +} + +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 <QObject> +#include <QTranslator> +#include <QDialog> + +#include <qmmpui/general.h> +#include <qmmpui/generalfactory.h> + +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 <qmmp/qmmp.h> + +#include <QSettings> + +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 <QDialog> + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SettingsDialog</class> + <widget class="QDialog" name="SettingsDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>104</height> + </rect> + </property> + <property name="windowTitle"> + <string>KDE 4 Notification Plugin Settings</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Notification delay [ms]:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QSpinBox" name="kNotifyDelaySpinBox"> + <property name="maximum"> + <number>50000</number> + </property> + <property name="value"> + <number>10000</number> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>SettingsDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>SettingsDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> 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 @@ +<!DOCTYPE TS><TS> +<context> + <name>KdeNotify</name> + <message> + <location filename="../kdenotify.cpp" line="58"/> + <source>Now playing:</source> + <translation>Teraz odtwarzane:</translation> + </message> + <message> + <location filename="../kdenotify.cpp" line="68"/> + <source>by </source> + <translation>przez </translation> + </message> + <message> + <location filename="../kdenotify.cpp" line="73"/> + <source>on </source> + <translation>na </translation> + </message> +</context> +<context> + <name>KdeNotifyFactory</name> + <message> + <location filename="../kdenotifyfactory.cpp" line="10"/> + <source>KDE 4 notification plugin</source> + <translation>Wtyczka powiadamiania KDE 4</translation> + </message> +</context> +<context> + <name>SettingsDialog</name> + <message> + <source>KDE 4 Notification Plugin Settings</source> + <translation>Ustawienia wtyczki Powiadamianie KDE 4</translation> + </message> + <message> + <source>Notification delay [ms]:</source> + <translation>Czas zanikania [ms]:</translation> + </message> +</context> +</TS> 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 @@ +<RCC> + <qresource prefix="/"> + <file>kdenotify_plugin_pl.qm</file> + </qresource> +</RCC> |
