]> ToastFreeware Gitweb - toast/confclerk.git/blobdiff - src/gui/tabcontainer.cpp
fine tune geometry to look nicer
[toast/confclerk.git] / src / gui / tabcontainer.cpp
index f2e3fff0c5e3b824c0e27def2da3763a48c4c783..01900d884e84849c9ad449fe472f8fddf873bf1e 100644 (file)
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2010 Ixonos Plc.
+ *
+ * This file is part of fosdem-schedule.
+ *
+ * fosdem-schedule 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.
+ *
+ * fosdem-schedule 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
+ * fosdem-schedule.  If not, see <http://www.gnu.org/licenses/>.
+ */
 #include "tabcontainer.h"
 
 #include <QFile>
@@ -10,6 +28,8 @@
 #include "eventdialog.h"
 #include "mapwindow.h"
 
+#include "conflictsdialog.h"
+
 TabContainer::TabContainer(QWidget *aParent)
     : QWidget(aParent)
 {
@@ -24,28 +44,24 @@ TabContainer::TabContainer(QWidget *aParent)
 
     connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &)));
 
-    connect(treeView, SIGNAL(eventHasChanged(int)), SIGNAL(eventHasChanged(int)));
+    connect(treeView, SIGNAL(eventHasChanged(int,bool)), SIGNAL(eventHasChanged(int,bool)));
     connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
     connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
-    connect(treeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
+    connect(treeView, SIGNAL(requestForConflicts(const QModelIndex &)), SLOT(displayConflicts(const QModelIndex &)));
 
-    if(!Conference::getAll().count()) // no conference(s) in the DB
-    {
-        dayNavigator->hide(); // hide DayNavigatorWidget
-    }
-    else
-    {
-        QDate aStartDate = Conference::getById(AppSettings::confId()).start();
-        QDate aEndDate = Conference::getById(AppSettings::confId()).end();
-        dayNavigator->setDates(aStartDate, aEndDate);
-    }
+    // day navigator is hidden by default
+    dayNavigator->hide();
 }
 
 void TabContainer::updateTreeView(const QDate &aDate)
 {
+    int active_id = Conference::activeConference();
     dayNavigator->show();
-    loadEvents( aDate, AppSettings::confId() );
-    treeView->reset();
+    if (active_id > 0) {
+        loadEvents(aDate, active_id);
+    } else {
+        static_cast<EventModel*>(treeView->model())->clearModel();
+    }
 }
 
 void TabContainer::itemClicked(const QModelIndex &aIndex)
@@ -55,9 +71,12 @@ void TabContainer::itemClicked(const QModelIndex &aIndex)
         return;
 
     EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
-    connect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int)));
+#ifdef N810
+    dialog.setFixedWidth(static_cast<QWidget*>(parent())->width());
+#endif
+    connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
     dialog.exec();
-    disconnect(&dialog, SIGNAL(eventHasChanged(int)), this, SIGNAL(eventHasChanged(int)));
+    disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
 }
 
 void TabContainer::displayMap(const QModelIndex &aIndex)
@@ -81,19 +100,35 @@ void TabContainer::displayMap(const QModelIndex &aIndex)
     window.exec();
 }
 
-void TabContainer::displayWarning(const QModelIndex &aIndex)
+void TabContainer::displayConflicts(const QModelIndex &aIndex)
 {
-    Q_UNUSED(aIndex);
-
-    QMessageBox::warning(
-        this,
-        tr("Time Conflict Warning"),
-        tr("This event happens at the same time than another one of your favourites.") );
+    ConflictsDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
+#ifdef N810
+    dialog.setFixedWidth(static_cast<QWidget*>(parent())->width());
+#endif
+    connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
+    dialog.exec();
+    disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
 }
 
-void TabContainer::updateTreeViewModel(int aEventId)
+void TabContainer::updateTreeViewModel(int aEventId, bool aReloadModel)
 {
-    static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
+    if(aReloadModel)
+    {
+        // requires special handling
+        // eg. in case of favourities - some favourities may have changed
+        // and so we need to reload them
+        int confId = Conference::activeConference();
+        QDate startDate = Conference::getById(confId).start();
+        QDate endDate = Conference::getById(confId).end();
+        dayNavigator->setDates(startDate, endDate);
+        updateTreeView( Conference::getById(confId).start() );
+    }
+    else
+    {
+        // just update event in the question
+        static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
+    }
 }
 
 void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
@@ -101,5 +136,8 @@ void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
     dayNavigator->setDates(aStart, aEnd);
 }
 
-
+void TabContainer::clearModel()
+{
+    static_cast<EventModel*>(treeView->model())->clearModel();
+}