conflicts updated correctly
[toast/confclerk.git] / src / mvc / treeview.cpp
index ac1e5d789d07f2a39da96edda32f8c12f70af151..0b3b632c6c3cd5aa8951f98c9052a0bc585baaba 100644 (file)
@@ -3,6 +3,7 @@
 #include "treeview.h"
 #include "delegate.h"
 #include "event.h"
+#include "conference.h"
 #include "eventmodel.h"
 
 #ifdef MAEMO
@@ -47,20 +48,31 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP
             {
                 // handle Favourite Control clicked
                 Event event = Event::getById(aIndex.data().toInt(),1);
+
+                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();
+                // update EVENT_CONFLICT table
+                event.updateConflicts();
+                if(event.isFavourite())
+                {
+                    // event has became 'favourite' and so 'conflicts' list may have changed
+                    conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
+                }
+
+                // since the Favourite icon has changed, update TreeViews accordingly
+                // all TreeViews have to listen on this signal
+                emit(eventHasChanged(event.id()));
+
+                // have to emit 'eventHasChanged' signal on all events in conflict
+                for(int i=0; i<conflicts.count(); i++)
+                    emit(eventHasChanged(conflicts[i].id()));
+
                 handled = true;
             }
             break;
@@ -71,7 +83,6 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP
                 Event event = Event::getById(aIndex.data().toInt(),1);
                 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,7 +93,6 @@ 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'
@@ -91,10 +101,11 @@ bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP
                     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 +117,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;
@@ -135,3 +147,11 @@ void TreeView::handleItemClicked(const QModelIndex &index)
     }
 }
 
+void TreeView::setAllExpanded(bool aExpanded)
+{
+    for(int i=0; i<model()->rowCount(QModelIndex()); i++)
+    {
+        setExpanded(model()->index(i,0,QModelIndex()),aExpanded);
+    }
+}
+