Prepared to show an alarm message via tray icon on non-MAEMO systems.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 2 Apr 2013 21:28:06 +0000 (21:28 +0000)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 2 Apr 2013 21:28:06 +0000 (21:28 +0000)
src/gui/eventdialog.cpp
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/mvc/delegate.cpp

index 486d2d9..baaa1b5 100644 (file)
@@ -31,8 +31,6 @@ EventDialog::EventDialog(int conferenceId, int eventId, QWidget *parent): QDialo
 
 #ifdef MAEMO
     showFullScreen();
-#else
-    alarmButton->hide();
 #endif
 
     Event event = Event::getById(mEventId, mConferenceId);
index e055b6a..ce54361 100644 (file)
@@ -63,7 +63,11 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow(parent) {
     conferenceModel = new ConferenceModel(this);
     mXmlParser = new ScheduleXmlParser(sqlEngine, this);
     mNetworkAccessManager = new QNetworkAccessManager(this);
+    systemTrayIcon = new QSystemTrayIcon(qApp->windowIcon(), this);
+    alarmTimer = new QTimer(this);
 
+    alarmTimer->setInterval(60000);
+    alarmTimer->start();
     saved_title = windowTitle();
 
 #ifdef N810
@@ -100,6 +104,11 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow(parent) {
     // search result has changed
     connect(searchTabContainer, SIGNAL(searchResultChanged()), SLOT(onSearchResultChanged()));
 
+    // systm tray icon
+    connect(systemTrayIcon, SIGNAL(messageClicked()), SLOT(onSystemTrayMessageClicked()));
+
+    // timer
+    connect(alarmTimer, SIGNAL(timeout()), SLOT(onAlarmTimerTimeout()));
 
     useConference(Conference::activeConference());
     // optimization, see useConference() code
@@ -115,6 +124,7 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow(parent) {
     connect(mXmlParser, SIGNAL(parsingScheduleEnd(int)), conferenceModel, SLOT(newConferenceEnd(int)));
 }
 
+
 void MainWindow::on_aboutAction_triggered()
 {
     QDialog dialog(this);
@@ -206,6 +216,22 @@ void MainWindow::onSearchResultChanged() {
 }
 
 
+void MainWindow::onSystemTrayMessageClicked() {
+    // TODO: Hide icon
+}
+
+
+void MainWindow::onAlarmTimerTimeout() {
+    // TODO: Show Message if an alarm is set on an event that's starting soon and delete the corresponding alarm.
+    /* Example:
+    systemTrayIcon->show();
+    systemTrayIcon->showMessage("title", "message", QSystemTrayIcon::Information, 1000);
+    QApplication::alert(this);
+    QApplication::beep();
+    */
+}
+
+
 void MainWindow::useConference(int conferenceId)
 {
     if (conferenceId == -1)  // in case no conference is active
index 336b9fe..613116c 100644 (file)
@@ -49,12 +49,15 @@ private slots:
 
     void onEventChanged(int aEventId, bool favouriteChanged);
     void onSearchResultChanged();
+
     // TODO: remove
     void networkQueryFinished(QNetworkReply*);
     void importFromNetwork(const QString&, int conferenceId);
     void importFromFile(const QString&, int conferenceId);
     void removeConference(int);
     void changeConferenceUrl(int, const QString&);
+    void onSystemTrayMessageClicked();
+    void onAlarmTimerTimeout();
 
     void useConference(int conferenceId);
     void unsetConference();
@@ -71,6 +74,8 @@ private:
     ConferenceModel* conferenceModel;
     ScheduleXmlParser *mXmlParser;
     QNetworkAccessManager *mNetworkAccessManager;
+    QSystemTrayIcon* systemTrayIcon; ///< to be able to show notifications
+    QTimer* alarmTimer; ///< timer that triggers every minute to be able to show alarms
 };
 
 #endif /* MAINWINDOW_H */
index 54da554..93df5b4 100644 (file)
@@ -109,12 +109,12 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
             mControls[FavouriteControlOn]->paint(painter, option.rect);
         else
             mControls[FavouriteControlOff]->paint(painter, option.rect);
-#ifdef MAEMO
+
         if(event->hasAlarm())
             mControls[AlarmControlOn]->paint(painter, option.rect);
         else
             mControls[AlarmControlOff]->paint(painter, option.rect);
-#endif
+
         if(event->hasTimeConflict())
             mControls[WarningControl]->paint(painter, option.rect);
 
@@ -163,9 +163,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
     else // doesn't have parent - time-groups' elements (top items)
     {
         int numFav = numberOfFavourities(index);
-#ifdef MAEMO
         int numAlarm = numberOfAlarms(index);
-#endif
 
         QStyleOptionButton styleOptionButton;
         styleOptionButton.rect = option.rect;
@@ -199,13 +197,13 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         painter->drawImage(drawPoint,*image);
         painter->drawText(drawPoint+QPoint(image->width()+2, image->height() - 2),
                 QString::number(numFav));
-#ifdef MAEMO
+
         drawPoint.setX(drawPoint.x() - spacer - image->width());
         image = mControls[numAlarm ? AlarmControlOn : AlarmControlOff]->image();
         painter->drawImage(drawPoint,*image);
         painter->drawText(drawPoint+QPoint(image->width()+2, image->height() - 2),
                 QString::number(numAlarm));
-#endif
+
         // draw texts
         QString numEvents = QString::number(index.model()->rowCount(index)).append("/");
         drawPoint.setX(drawPoint.x() - spacer - fmSmall.boundingRect(numEvents).width());
@@ -313,7 +311,6 @@ void Delegate::defineControls()
     // off
     mControls.insert(FavouriteControlOff, new Control(FavouriteControlOff, QString(":icons/favourite-off.png"), NULL));
 
-#ifdef MAEMO
     // ALARM ICONs
     // on
     mControls.insert(AlarmControlOn,
@@ -324,13 +321,7 @@ void Delegate::defineControls()
     // WARNING ICON
     mControls.insert(WarningControl,
                     new Control(WarningControl, QString(":icons/dialog-warning.png"), mControls[AlarmControlOff]));
-#else
-    // WARNING ICON
-    mControls.insert(WarningControl,
-                    new Control(WarningControl, QString(":icons/dialog-warning.png"), mControls[FavouriteControlOn]));
-#endif
-
-}
+        }
 
 bool Delegate::isPointFromRect(const QPoint &aPoint, const QRect &aRect) const
 {