From 49b79615ece101063ed2a578b259ca08cba7e369 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Thu, 13 Feb 2014 18:54:45 +0100 Subject: [PATCH] added a new backend, to internaly display notifications --- src/core/plugins/snorebackend.cpp | 4 + src/plugins/backends/CMakeLists.txt | 1 + src/plugins/backends/snore/CMakeLists.txt | 16 ++ src/plugins/backends/snore/DpiScaler.cpp | 200 +++++++++++++++++ src/plugins/backends/snore/DpiScaler.h | 75 +++++++ src/plugins/backends/snore/notifywidget.cpp | 140 ++++++++++++ src/plugins/backends/snore/notifywidget.h | 72 ++++++ src/plugins/backends/snore/notifywidget.ui | 223 +++++++++++++++++++ src/plugins/backends/snore/snorenotifier.cpp | 118 ++++++++++ src/plugins/backends/snore/snorenotifier.h | 53 +++++ src/trayicon.cpp | 20 +- src/trayicon.h | 3 +- 12 files changed, 917 insertions(+), 8 deletions(-) create mode 100644 src/plugins/backends/snore/CMakeLists.txt create mode 100644 src/plugins/backends/snore/DpiScaler.cpp create mode 100644 src/plugins/backends/snore/DpiScaler.h create mode 100644 src/plugins/backends/snore/notifywidget.cpp create mode 100644 src/plugins/backends/snore/notifywidget.h create mode 100644 src/plugins/backends/snore/notifywidget.ui create mode 100644 src/plugins/backends/snore/snorenotifier.cpp create mode 100644 src/plugins/backends/snore/snorenotifier.h diff --git a/src/core/plugins/snorebackend.cpp b/src/core/plugins/snorebackend.cpp index 7088235..496e835 100644 --- a/src/core/plugins/snorebackend.cpp +++ b/src/core/plugins/snorebackend.cpp @@ -87,6 +87,10 @@ void SnoreBackend::closeNotification(Notification n, Notification::CloseReasons { m_activeNotifications.remove(n.id()); } + if(n.isUpdate() && m_activeNotifications.contains(n.old().id())) + { + m_activeNotifications.remove(n.old().id()); + } n.data()->setCloseReason(reason); snoreDebug( SNORE_DEBUG ) << n; emit notificationClosed(n); diff --git a/src/plugins/backends/CMakeLists.txt b/src/plugins/backends/CMakeLists.txt index 046e5f6..3972b05 100644 --- a/src/plugins/backends/CMakeLists.txt +++ b/src/plugins/backends/CMakeLists.txt @@ -3,3 +3,4 @@ add_subdirectory(snarl) add_subdirectory(growl) add_subdirectory(trayicon) add_subdirectory(snoretoast) +add_subdirectory(snore) diff --git a/src/plugins/backends/snore/CMakeLists.txt b/src/plugins/backends/snore/CMakeLists.txt new file mode 100644 index 0000000..2911ea5 --- /dev/null +++ b/src/plugins/backends/snore/CMakeLists.txt @@ -0,0 +1,16 @@ +set( SNORE_SRC + snorenotifier.cpp + notifywidget.cpp + DPIScaler.cpp + ) + +set( SNORE_FORMS + notifywidget.ui) + +qt4_wrap_ui(SNORE_UI ${SNORE_FORMS}) + +add_library(libsnore_backend_snore MODULE ${SNORE_SRC} ${SNORE_UI} ) +target_link_libraries(libsnore_backend_snore snorecore ${QT_QTCORE_LIBRARY} ) + +install(TARGETS libsnore_backend_snore ${SNORE_PLUGIN_INSTALL_PATH}) + diff --git a/src/plugins/backends/snore/DpiScaler.cpp b/src/plugins/backends/snore/DpiScaler.cpp new file mode 100644 index 0000000..8b52865 --- /dev/null +++ b/src/plugins/backends/snore/DpiScaler.cpp @@ -0,0 +1,200 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "DpiScaler.h" +#include +#include + + +namespace TomahawkUtils +{ +int DpiScaler::s_fontSize = 0; +#ifdef Q_OS_MAC + const qreal DpiScaler::s_baseDpi = 72.; +#else + const qreal DpiScaler::s_baseDpi = 96.; +#endif + +DpiScaler::DpiScaler( const QPaintDevice* that ) + : that( that ) +{ + m_ratioX = ratioX( that ); + m_ratioY = ratioY( that ); +} + + +QSize +DpiScaler::scaled( int w, int h ) const +{ + return QSize( scaledX( w ), scaledY( h ) ); +} + + +QSize +DpiScaler::scaled( const QSize& size ) const +{ + return scaled( size.width(), size.height() ); +} + + +QMargins +DpiScaler::scaled( int left, int top, int right, int bottom ) const +{ + return QMargins( scaledX( left ), + scaledY( top ), + scaledX( right ), + scaledY( bottom ) ); +} + + +QMargins +DpiScaler::scaled( const QMargins& margins ) const +{ + return scaled( margins.left(), + margins.top(), + margins.right(), + margins.bottom() ); +} + + +int +DpiScaler::scaledX( int x ) const +{ + return qRound( x * m_ratioX ); +} + + +int +DpiScaler::scaledY( int y ) const +{ + return qRound( y * m_ratioY ); +} + +// static methods start here + +QSize +DpiScaler::scaled( const QPaintDevice* pd, int w, int h ) +{ + return QSize( scaledX( pd, w ), scaledY( pd, h ) ); +} + + +QSize +DpiScaler::scaled( const QPaintDevice* pd, const QSize& size ) +{ + return scaled( pd, size.width(), size.height() ); +} + + +QMargins +DpiScaler::scaled( const QPaintDevice* pd, int left, int top, int right, int bottom ) +{ + return QMargins( scaledX( pd, left ), + scaledY( pd, top ), + scaledX( pd, right ), + scaledY( pd, bottom ) ); +} + + +QMargins +DpiScaler::scaled( const QPaintDevice* pd, const QMargins& margins ) +{ + return scaled( pd, + margins.left(), + margins.top(), + margins.right(), + margins.bottom() ); +} + + +int +DpiScaler::scaledX( const QPaintDevice* pd, int x ) +{ + return qRound( x * ratioX( pd ) ); +} + + +int +DpiScaler::scaledY( const QPaintDevice* pd, int y ) +{ + return qRound( y * ratioY( pd ) ); +} +int DpiScaler::getFontSize() +{ + return s_fontSize; +} + +void DpiScaler::setFontSize(int value) +{ + s_fontSize = value; +} + + + +qreal +DpiScaler::ratioX( const QPaintDevice* pd ) +{ + qreal ratioFromFH = ratioFromFontHeight(); + qreal ratioYFromDpi = pd->logicalDpiY() / s_baseDpi; //using Y because we compare with height + + //if the error is less than 1%, we trust that the logical DPI setting has the best value + if ( qAbs( ratioFromFH / ratioYFromDpi - 1 ) < 0.01 ) + return pd->logicalDpiX() / s_baseDpi; + else + return ratioFromFH; +} + + +qreal +DpiScaler::ratioY( const QPaintDevice* pd ) +{ + qreal ratioFromFH = ratioFromFontHeight(); + qreal ratioYFromDpi = pd->logicalDpiY() / s_baseDpi; //using Y because we compare with height + + //if the error is less than 1%, we trust that the logical DPI setting has the best value + if ( qAbs( ratioFromFH / ratioYFromDpi - 1 ) < 0.01 ) + return ratioYFromDpi; + else + return ratioFromFH; +} + + +qreal +DpiScaler::ratioFromFontHeight() +{ + int fS = s_fontSize; + QFont f; + f.setPointSize( fS ); + int fH = QFontMetrics( f ).ascent() + 1; //a font's em-height should be ascent + 1px (baseline) + + qreal basePpp = s_baseDpi / 72.; //72*(1.333)=96 dpi + +#ifdef Q_OS_MAC + const int baseFontSize = 13; +#else + const int baseFontSize = 8; +#endif + + qreal baseFontHeight = baseFontSize * basePpp; //we assume a minimum font size of 7pt + + qreal ratioFromFontHeights = qMax( fH / baseFontHeight, 1. ); + return ratioFromFontHeights; +} + + +} diff --git a/src/plugins/backends/snore/DpiScaler.h b/src/plugins/backends/snore/DpiScaler.h new file mode 100644 index 0000000..bb50706 --- /dev/null +++ b/src/plugins/backends/snore/DpiScaler.h @@ -0,0 +1,75 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef DPISCALER_H +#define DPISCALER_H + + +#include +#include +#include + +namespace TomahawkUtils +{ + +/** + * @brief The DpiScaler class provides some convenience methods to recompute fixed pixel sizes + * into values suitable for different environment DPI settings. + * Usage: + * class Foo : public QWidget, private TomahawkUtils::DpiScaler {...}; + */ +class DpiScaler +{ +public: + DpiScaler( const QPaintDevice* that ); + + QSize scaled( int w, int h ) const; + QSize scaled( const QSize& size ) const; + QMargins scaled( int left, int top, int right, int bottom ) const; + QMargins scaled( const QMargins& margins ) const; + int scaledX( int x ) const; + int scaledY( int y ) const; + + // convenience one-shot methods, usable without composing or private-inheriting DpiScaler + static QSize scaled( const QPaintDevice* pd, int w, int h ); + static QSize scaled( const QPaintDevice* pd, const QSize& size ); + static QMargins scaled( const QPaintDevice* pd, int left, int top, int right, int bottom ); + static QMargins scaled( const QPaintDevice* pd, const QMargins& margins ); + static int scaledX( const QPaintDevice* pd, int x ); + static int scaledY( const QPaintDevice* pd, int y ); + + static int getFontSize(); + static void setFontSize(int value); + +private: + static int s_fontSize; + inline static qreal ratioX( const QPaintDevice* pd ); + inline static qreal ratioY( const QPaintDevice* pd ); + inline static qreal ratioFromFontHeight(); + + qreal m_ratioX; + qreal m_ratioY; + + const QPaintDevice* that; + + static const qreal s_baseDpi; +}; + +} + +#endif // DPISCALER_H diff --git a/src/plugins/backends/snore/notifywidget.cpp b/src/plugins/backends/snore/notifywidget.cpp new file mode 100644 index 0000000..d6520fb --- /dev/null +++ b/src/plugins/backends/snore/notifywidget.cpp @@ -0,0 +1,140 @@ +/* + SnoreNotify is a Notification Framework based on Qt + Copyright (C) 2014 Patrick von Reth + + + SnoreNotify is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SnoreNotify is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with SnoreNotify. If not, see . +*/ + +#include "notifywidget.h" +#include "ui_notifywidget.h" +#include "core/log.h" + +#include +#include + +using namespace Snore; + +NotifyWidget::NotifyWidget(int pos,QWidget *parent) : + QWidget(parent, Qt::SplashScreen | Qt::WindowStaysOnTopHint), + ui(new Ui::NotifyWidget), + m_desktop(QDesktopWidget().availableGeometry()), + m_id(pos) +{ + ui->setupUi(this); + + TomahawkUtils::DpiScaler::setFontSize(this->ui->titel->fontInfo().pointSize()); + m_scaler = new TomahawkUtils::DpiScaler(this); + ui->closeButton->setMaximumWidth(ui->closeButton->height()); + QSize size = m_scaler->scaled(350, 90); + setMaximumSize(size); + setMinimumSize(size); + resize(size); + m_dest = QPoint(m_desktop.topRight().x() - width(), m_desktop.topRight().y() + (m_scaler->scaledY(10) + height()) * pos); +} + +NotifyWidget::~NotifyWidget() +{ + delete m_scaler; + delete ui; +} + +void NotifyWidget::display(const Notification ¬ification) +{ + update(notification); + move(m_desktop.topRight().x(), m_desktop.topRight().y() + (m_scaler->scaledY(10) + height()) * m_id); + show(); + m_moveTimer = new QTimer(this); + m_moveTimer->setInterval(3); + connect( m_moveTimer, SIGNAL(timeout()), this, SLOT(slotMove())); + m_moveTimer->start(); +} + +void NotifyWidget::update(const Notification ¬ification) +{ + m_notification = notification; + ui->titel->setText(notification.title()); + ui->body->setText(notification.text()); + + QSize iconSize = m_scaler->scaled(65,65); + ui->icon->setPixmap(QPixmap::fromImage(notification.icon().image().scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation))); + ui->icon->setMaximumSize(iconSize); + + iconSize = m_scaler->scaled(20,20); + QImage img = notification.application().icon().image().scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); + ui->appIcon->setPixmap(QPixmap::fromImage(img)); + ui->appIcon->setMaximumSize(iconSize); + + qulonglong r = 0; + qulonglong g = 0; + qulonglong b = 0; + for(int x=0;xcloseButton->setPalette(p); + ui->body->setPalette(p); + ui->titel->setPalette(p); + +} + +Notification &NotifyWidget::notification() +{ + return m_notification; +} + +int NotifyWidget::id() +{ + return m_id; +} + +void NotifyWidget::slotMove() +{ + move(pos().x()-1, pos().y()); + if(m_dest == pos()) + { + m_moveTimer->deleteLater(); + } +} + +void NotifyWidget::on_closeButton_clicked() +{ + emit dismissed(); + hide(); +} + +void NotifyWidget::mousePressEvent(QMouseEvent *e) +{ + emit invoked(); + hide(); + QWidget::mousePressEvent(e); +} diff --git a/src/plugins/backends/snore/notifywidget.h b/src/plugins/backends/snore/notifywidget.h new file mode 100644 index 0000000..35fa9be --- /dev/null +++ b/src/plugins/backends/snore/notifywidget.h @@ -0,0 +1,72 @@ +/* + SnoreNotify is a Notification Framework based on Qt + Copyright (C) 2014 Patrick von Reth + + + SnoreNotify is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SnoreNotify is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with SnoreNotify. If not, see . +*/ + +#ifndef NOTIFYWIDGET_H +#define NOTIFYWIDGET_H + +#include +#include +#include "core/notification/notification.h" +#include "DpiScaler.h" + +namespace Ui { +class NotifyWidget; +} + +class NotifyWidget : public QWidget +{ + Q_OBJECT + +public: + explicit NotifyWidget(int pos, QWidget *parent = 0); + ~NotifyWidget(); + + void display(const Snore::Notification ¬ification); + void update(const Snore::Notification ¬ification); + + Snore::Notification ¬ification(); + + int id(); + + +signals: + void invoked(); + void dismissed(); + +private slots: + void slotMove(); + + void on_closeButton_clicked(); + +protected: + void mousePressEvent(QMouseEvent *e); + + +private: + Ui::NotifyWidget *ui; + QTimer *m_moveTimer; + QPoint m_dest; + QRect m_desktop; + TomahawkUtils::DpiScaler *m_scaler; + Snore::Notification m_notification; + + int m_id; +}; + +#endif // NOTIFYWIDGET_H diff --git a/src/plugins/backends/snore/notifywidget.ui b/src/plugins/backends/snore/notifywidget.ui new file mode 100644 index 0000000..fa23415 --- /dev/null +++ b/src/plugins/backends/snore/notifywidget.ui @@ -0,0 +1,223 @@ + + + NotifyWidget + + + + 0 + 0 + 303 + 122 + + + + true + + + Form + + + + + + + + + + + 0 + 0 + + + + appIcon + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Icon + + + + + + + + + + + + 10 + 75 + true + + + + TextLabel + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Qt::NoFocus + + + X + + + + + + true + + + + + + + + + false + + + + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + + + 10 + + + + QFrame::NoFrame + + + QFrame::Plain + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + false + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Body</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"><br /></p></body></html> + + + Qt::NoTextInteraction + + + + + + + + + + + + diff --git a/src/plugins/backends/snore/snorenotifier.cpp b/src/plugins/backends/snore/snorenotifier.cpp new file mode 100644 index 0000000..f2ef706 --- /dev/null +++ b/src/plugins/backends/snore/snorenotifier.cpp @@ -0,0 +1,118 @@ +/* + SnoreNotify is a Notification Framework based on Qt + Copyright (C) 2014 Patrick von Reth + + + SnoreNotify is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SnoreNotify is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with SnoreNotify. If not, see . +*/ + + +#include "snorenotifier.h" +#include "notifywidget.h" +#include "core/notification/notification_p.h" +#include "core/snore_p.h" +#include + +Q_EXPORT_PLUGIN2(libsnore_backend_snore,SnoreNotifier) + +using namespace Snore; + +SnoreNotifier::SnoreNotifier(): + SnoreBackend("Snore", true, true, true), + m_widgets(2) +{ + moveToThread(qApp->thread());//TODO cleanup + QTimer::singleShot(0, this, SLOT(setup())); + +} + +SnoreNotifier::~SnoreNotifier() +{ + foreach (NotifyWidget *w, m_widgets) + { + w->deleteLater(); + } +} + +void SnoreNotifier::slotNotify(Snore::Notification notification) +{ + + if(notification.isUpdate()) + { + NotifyWidget *w = m_widgets[notification.old().hints().privateValue(this, "id").toInt()]; + w->update(notification); + notification.hints().setPrivateValue(this, "id", w->id()); + startTimeout(notification); + return; + } + else if(m_queue.isEmpty()) + { + foreach (NotifyWidget *w, m_widgets) + { + if(w->isHidden()) + { + w->display(notification); + notification.hints().setPrivateValue(this, "id", w->id()); + startTimeout(notification); + return; + } + } + } + m_queue.append(notification); +} + +void SnoreNotifier::slotCloseNotification(Snore::Notification notification) +{ + + NotifyWidget *w = m_widgets[notification.hints().privateValue(this, "id").toInt()]; + if(!m_queue.isEmpty()) + { + w->display(m_queue.takeLast()); + notification.hints().setPrivateValue(this, "id", w->id()); + startTimeout(notification); + } + else + { + w->hide(); + } +} + + +void SnoreNotifier::slotDismissed() +{ + NotifyWidget *widget = qobject_cast(sender()); + Notification notification = widget->notification(); + closeNotification(notification, Notification::DISMISSED); + slotCloseNotification(notification); +} + +void SnoreNotifier::slotInvoked() +{ + NotifyWidget *widget = qobject_cast(sender()); + Notification notification = widget->notification(); + snore()->d()->notificationActionInvoked(notification); + closeNotification(notification,Notification::CLOSED); + slotCloseNotification(notification); +} + +void SnoreNotifier::setup() +{ + for(int i=0;i + + + SnoreNotify is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + SnoreNotify is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with SnoreNotify. If not, see . +*/ + +#ifndef SNORENOTIFIER_H +#define SNORENOTIFIER_H + +#include "core/plugins/snorebackend.h" + +#include "notifywidget.h" + +class SnoreNotifier : public Snore::SnoreBackend +{ + Q_OBJECT + Q_INTERFACES(Snore::SnoreBackend) + Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0") +public: + SnoreNotifier(); + ~SnoreNotifier(); + + // SnoreBackend interface +public slots: + virtual void slotNotify(Snore::Notification notification); + virtual void slotCloseNotification(Snore::Notification notification); + +private slots: + void slotDismissed(); + void slotInvoked(); + + void setup(); + +private: + + QList m_queue; + QVector m_widgets; +}; + +#endif // SNORENOTIFIER_H diff --git a/src/trayicon.cpp b/src/trayicon.cpp index 8f74417..bf11c44 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -97,20 +97,26 @@ void TrayIcon::slotTestNotification() { m_snore->registerApplication(m_app); } - m_noti = Notification(m_app, m_alert, "Hello World", "This is Snore", Icon(":/root/snore.png")); - m_noti.addAction(Action(1,"Test Action")); - m_snore->broadcastNotification(m_noti); - - QTimer::singleShot(m_noti.timeout()/2*1000,this,SLOT(sloutUpdateTestNotification())); + Notification noti(m_app, m_alert, "Hello World", "This is Snore", Icon(":/root/snore.png")); + noti.addAction(Action(1,"Test Action")); + m_snore->broadcastNotification(noti); + QTimer *timer = new QTimer(this); + m_notifications[timer] = noti; + timer->setSingleShot(true); + timer->setInterval(noti.timeout()/2*1000); + connect(timer, SIGNAL(timeout()), this, SLOT(sloutUpdateTestNotification())); + timer->start(); // m_snore->deregisterApplication(app); } void TrayIcon::sloutUpdateTestNotification() { - Notification update(m_noti, "Hello World", "This is Snore, color test", Icon("http://jweatherwatch.googlecode.com/svn/trunk/iconset/04.png")); + QTimer *timer = qobject_cast(sender()); + Notification noti = m_notifications.take(timer); + Notification update(noti, "Hello World", "This is Snore, color test", Icon("http://jweatherwatch.googlecode.com/svn/trunk/iconset/04.png")); m_snore->broadcastNotification(update); - m_noti = Notification(); + timer->deleteLater(); } diff --git a/src/trayicon.h b/src/trayicon.h index 044bbdb..3dfb6d8 100644 --- a/src/trayicon.h +++ b/src/trayicon.h @@ -41,7 +41,8 @@ private: Snore::SnoreCore *m_snore; Snore::Application m_app; Snore::Alert m_alert; - Snore::Notification m_noti; + + QHash m_notifications; public slots: