]> ToastFreeware Gitweb - toast/confclerk.git/blobdiff - src/mvc/treeview.cpp
Bump copyright years.
[toast/confclerk.git] / src / mvc / treeview.cpp
index ccc27034e9aed6d257ec2ce2bbb5dd4d61b36bde..dfce255bd924b85018bf6cad944d17b8c0bf1c3a 100644 (file)
@@ -1,12 +1,33 @@
+/*
+ * Copyright (C) 2010 Ixonos Plc.
+ * Copyright (C) 2011-2024 Philipp Spitzer, gregor herrmann, Stefan Stahl
+ *
+ * This file is part of ConfClerk.
+ *
+ * ConfClerk is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * ConfClerk is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
+ */
 #include <QMouseEvent>
 
 #include "treeview.h"
 #include "delegate.h"
 #include "event.h"
+#include "conference.h"
 #include "eventmodel.h"
 
 #ifdef MAEMO
-#include <alarm.h>
+#include "alarm.h"
+#include "appsettings.h"
 #endif
 
 #include <QDebug>
@@ -23,7 +44,7 @@ void TreeView::mouseReleaseEvent(QMouseEvent *aEvent)
     QPoint point = aEvent->pos();
 
     // test whether we have handled the mouse event
-    if(!testForControlClicked(index,point))
+    if(!testForControlClicked(index, point, aEvent->button()))
     {
         // pass the event to the Base class, so item clicks/events are handled correctly
         QTreeView::mouseReleaseEvent(aEvent);
@@ -31,33 +52,40 @@ 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, Qt::MouseButton button)
 {
     bool handled = false;
 
     if(!aIndex.isValid())
         return handled;
 
-    QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list
+    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))
     {
-        case Delegate::FavouriteControlOn:
-        case Delegate::FavouriteControlOff:
+        case Delegate::FavouriteControlStrong:
+        case Delegate::FavouriteControlWeak:
+        case Delegate::FavouriteControlNo:
             {
                 // handle Favourite Control clicked
-                Event event = Event::getById(aIndex.data().toInt(),1);
-                if(event.isFavourite())
-                    event.setFavourite(false);
-                else
-                    event.setFavourite(true);
+                Event event = Event::getById(aIndex.data().toInt(),confId);
+
+                QList<Event> conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
+                event.cycleFavourite(button == Qt::RightButton);
                 event.update("favourite");
-                qDebug() << " FAVOURITE [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.isFavourite();
-                // update EVENT_CONFLICT table
-                event.updateConflicts();
+
+                // event has became 'favourite' and so 'conflicts' list may have changed
+                conflicts = Event::conflictEvents(event.id(),Conference::activeConference());
+
+                // have to emit 'eventChanged' signal on all events in conflict
+                for(int i=0; i<conflicts.count(); i++)
+                    emit eventChanged(conflicts[i].id(), false);
+
                 // since the Favourite icon has changed, update TreeViews accordingly
                 // all TreeViews have to listen on this signal
-                emit(eventHasChanged(event.id()));
+                emit eventChanged(event.id(), true);
+
                 handled = true;
             }
             break;
@@ -65,15 +93,14 @@ 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
 #ifdef MAEMO
-                    // remove alarm from the 'alarmd' alrms list
+                    // remove alarm from the 'alarmd' alarms list
                     Alarm alarm;
-                    alarm.deleteAlarm(event.id());
-                    // TODO: test if removing was successfull
+                    alarm.deleteAlarm(event.conferenceId(), event.id());
 #endif /* MAEMO */
                 }
                 else
@@ -82,30 +109,19 @@ 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));
-                    qDebug() << "cookie: " << cookie;
+                    alarm.addAlarm(event.conferenceId(), event.id(), event.title(),event.start().addSecs(-AppSettings::preEventAlarmSec()));
 #endif /* MAEMO */
                 }
                 event.update("alarm");
-                qDebug() << " ALARM [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.hasAlarm();
                 // since the Alarm icon has changed, update TreeView accordingly
                 // all TreeViews have to listen on this signal
-                emit(eventHasChanged(event.id()));
+                emit eventChanged(event.id(), false);
                 handled = true;
             }
             break;
-        case Delegate::MapControl:
-            {
-                // handle Alarm Control clicked
-                qDebug() << "MAP CLICKED: " << qVariantValue<QString>(aIndex.data());
-                emit(requestForMap(aIndex));
-                handled = true;
-            }
-        break;
         case Delegate::WarningControl:
         {
 
-            qDebug() << "WARNING CLICKED: " << qVariantValue<QString>(aIndex.data());
             emit(requestForConflicts(aIndex));
             handled = true;
         }
@@ -125,7 +141,7 @@ 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);