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 +++++++++++------------------ 1 file changed, 22 insertions(+), 37 deletions(-) (limited to 'src/plugins/General/kdenotify/kdenotify.cpp') 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); } -- cgit v1.2.3-13-gbd6f