Alarm dbus connection added
[toast/confclerk.git] / src / mvc / treeview.cpp
index ac1e5d7..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,21 +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())
-                {
-                    static_cast<Event*>(aIndex.internalPointer())->setFavourite(false); // list of events
-                    event.setFavourite(false); // update DB
-                }
+                    event.setFavourite(false);
                 else
-                {
-                    static_cast<Event*>(aIndex.internalPointer())->setFavourite(true); // list of events
                     event.setFavourite(true);
-                }
-                qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
                 event.update("favourite");
-                // since the Favourite icon has changed, update TreeView accordingly
-                static_cast<EventModel*>(model())->emitDataChangedSignal(aIndex,aIndex);
+
+                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(),true));
+
                 handled = true;
             }
             break;
@@ -68,10 +80,9 @@ 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())
                 {
-                    static_cast<Event*>(aIndex.internalPointer())->setHasAlarm(false); // list of events
                     event.setHasAlarm(false); // update DB
 #ifdef MAEMO
                     // remove alarm from the 'alarmd' alrms list
@@ -82,19 +93,20 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP
                 }
                 else
                 {
-                    static_cast<Event*>(aIndex.internalPointer())->setHasAlarm(true); // list of events
                     event.setHasAlarm(true);
 #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 */
                 }
-                qDebug() << " ALARM [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.hasAlarm();
                 event.update("alarm");
+                qDebug() << " ALARM [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.hasAlarm();
                 // since the Alarm icon has changed, update TreeView accordingly
-                static_cast<EventModel*>(model())->emitDataChangedSignal(aIndex,aIndex);
+                // all TreeViews have to listen on this signal
+                emit(eventHasChanged(event.id()));
                 handled = true;
             }
             break;
@@ -106,10 +118,11 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP
                 handled = true;
             }
         break;
-        case Delegate::WarningControlOn:
-        case Delegate::WarningControlOff:
+        case Delegate::WarningControl:
         {
-            // TODO: implement
+
+            qDebug() << "WARNING CLICKED: " << qVariantValue<QString>(aIndex.data());
+            emit(requestForConflicts(aIndex));
             handled = true;
         }
         break;
@@ -128,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);
+    }
+}
+