Alarm dbus connection added
[toast/confclerk.git] / src / mvc / treeview.cpp
index 8b3b647..5fd63ee 100644 (file)
@@ -3,6 +3,7 @@
 #include "treeview.h"
 #include "delegate.h"
 #include "event.h"
+#include "conference.h"
 #include "eventmodel.h"
 
 #ifdef MAEMO
@@ -31,13 +32,14 @@ void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
 }
 
 // returns bool if some Control was clicked
-bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint) 
+bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint)
 {
     bool handled = false;
 
     if(!aIndex.isValid())
         return handled;
 
+    int confId = Conference::activeConference();
     QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
     Delegate *delegate = static_cast<Delegate*>(itemDelegate(aIndex));
     switch(delegate->whichControlClicked(aIndex,aPoint))
@@ -46,16 +48,31 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP
         case Delegate::FavouriteControlOff:
             {
                 // handle Favourite Control clicked
-                Event event = Event::getById(aIndex.data().toInt(),1);
+                Event event = Event::getById(aIndex.data().toInt(),confId);
+
+                QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
                 if(event.isFavourite())
                     event.setFavourite(false);
                 else
                     event.setFavourite(true);
                 event.update("favourite");
+
                 qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
+
+                if(event.isFavourite())
+                {
+                    // event has became 'favourite' and so 'conflicts' list may have changed
+                    conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
+                }
+
+                // have to emit 'eventHasChanged' signal on all events in conflict
+                for(int i=0; i<conflicts.count(); i++)
+                    emit(eventHasChanged(conflicts[i].id()));
+
                 // since the Favourite icon has changed, update TreeViews accordingly
                 // all TreeViews have to listen on this signal
-                emit(eventHasChanged(event.id()));
+                emit(eventHasChanged(event.id(),true));
+
                 handled = true;
             }
             break;
@@ -63,7 +80,7 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP
         case Delegate::AlarmControlOff:
             {
                 // handle Alarm Control clicked
-                Event event = Event::getById(aIndex.data().toInt(),1);
+                Event event = Event::getById(aIndex.data().toInt(),confId);
                 if(event.hasAlarm())
                 {
                     event.setHasAlarm(false); // update DB
@@ -80,7 +97,8 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP
 #ifdef MAEMO
                     // add alarm to the 'alarmd'
                     Alarm alarm;
-                    int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10));
+                    //int cookie = alarm.addAlarm(event.id(),QDateTime::currentDateTime().addSecs(10)); // testing
+                    int cookie = alarm.addAlarm(event.id(),event.start().addSecs(-15*60)); // 15 minutes before real start
                     qDebug() << "cookie: " << cookie;
 #endif /* MAEMO */
                 }
@@ -100,13 +118,11 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP
                 handled = true;
             }
         break;
-        case Delegate::WarningControlOff:
-        case Delegate::WarningControlOn:
+        case Delegate::WarningControl:
         {
 
             qDebug() << "WARNING CLICKED: " << qVariantValue<QString>(aIndex.data());
-            // TODO: implement
-            emit(requestForWarning(aIndex));
+            emit(requestForConflicts(aIndex));
             handled = true;
         }
         break;
@@ -125,10 +141,18 @@ void TreeView::handleItemClicked(const QModelIndex &index)
 {
     if(!index.parent().isValid()) // time-group
     {
-        if(isExpanded(index)) 
+        if(isExpanded(index))
             setExpanded(index, false);
         else
             setExpanded(index, true);
     }
 }
 
+void TreeView::setAllExpanded(bool aExpanded)
+{
+    for(int i=0; i<model()->rowCount(QModelIndex()); i++)
+    {
+        setExpanded(model()->index(i,0,QModelIndex()),aExpanded);
+    }
+}
+