Event 'details' dialog now contains also 'favourite' and 'alarm'
[toast/confclerk.git] / src / gui / eventdialog.cpp
index 8d11d15..5202663 100644 (file)
@@ -3,6 +3,10 @@
 
 #include <QScrollBar>
 
+#ifdef MAEMO
+#include <alarm.h>
+#endif
+
 DetailsContainer::DetailsContainer(QWidget *aParent)
     : QWidget(aParent)
 {
@@ -55,12 +59,81 @@ EventDialog::EventDialog(const int &aEventId, QWidget *aParent)
     showFullScreen();
 #endif
 
-    Event event = Event::getById(aEventId,AppSettings::confId());
+    Event event = Event::getById(mEventId,AppSettings::confId());
 
     title->setText(event.title());
     mDetails.setPersons(event.persons());
     mDetails.setAbstract(event.abstract());
     mDetails.setDescription(event.description());
     scrollArea->setWidget(&mDetails);
+
+    connect(favouriteButton, SIGNAL(clicked()), SLOT(favouriteClicked()));
+    connect(alarmButton, SIGNAL(clicked()), SLOT(alarmClicked()));
+
+    if(event.isFavourite())
+    {
+        favouriteButton->setIcon(QIcon(":/icons/favourite-onBig.png"));
+    }
+
+    if(event.hasAlarm())
+    {
+        alarmButton->setIcon(QIcon(":/icons/alarm-onBig.png"));
+    }
+}
+
+void EventDialog::favouriteClicked()
+{
+    Event event = Event::getById(mEventId,AppSettings::confId());
+
+    if(event.isFavourite())
+    {
+        event.setFavourite(false);
+        favouriteButton->setIcon(QIcon(":/icons/favourite-offBig.png"));
+    }
+    else
+    {
+        event.setFavourite(true);
+        favouriteButton->setIcon(QIcon(":/icons/favourite-onBig.png"));
+    }
+    event.update("favourite");
+    qDebug() << " FAVOURITE [" << event.id() << "] -> " << event.isFavourite();
+    // update EVENT_CONFLICT table
+    event.updateConflicts();
+    // since the Favourite icon has changed, update TreeViews accordingly
+    // all TreeViews have to listen on this signal
+    emit(eventHasChanged(event.id()));
+}
+
+void EventDialog::alarmClicked()
+{
+    Event event = Event::getById(mEventId,AppSettings::confId());
+
+    if(event.hasAlarm())
+    {
+        event.setHasAlarm(false); // update DB
+        alarmButton->setIcon(QIcon(":/icons/alarm-offBig.png"));
+#ifdef MAEMO
+        // remove alarm from the 'alarmd' alrms list
+        Alarm alarm;
+        alarm.deleteAlarm(event.id());
+        // TODO: test if removing was successfull
+#endif /* MAEMO */
+    }
+    else
+    {
+        event.setHasAlarm(true);
+        alarmButton->setIcon(QIcon(":/icons/alarm-onBig.png"));
+#ifdef MAEMO
+        // add alarm to the 'alarmd'
+        Alarm alarm;
+        int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10));
+        qDebug() << "cookie: " << cookie;
+#endif /* MAEMO */
+    }
+    event.update("alarm");
+    qDebug() << " ALARM [" << event.id() << "] -> " << event.hasAlarm();
+    // since the Alarm icon has changed, update TreeView accordingly
+    // all TreeViews have to listen on this signal
+    emit(eventHasChanged(event.id()));
 }