]> ToastFreeware Gitweb - toast/confclerk.git/blobdiff - src/gui/mainwindow.cpp
conference tab header is hidden if there isn't active conference
[toast/confclerk.git] / src / gui / mainwindow.cpp
index 660de2b405ee0dd4e26d4cb7b6d68ad60a5b282f..b5882d64abe389d468d998a6be4227f5034c8a24 100644 (file)
@@ -1,5 +1,4 @@
 #include "mainwindow.h"
-#include <appsettings.h>
 
 #include <QTreeView>
 #include <QFile>
@@ -27,63 +26,32 @@ MainWindow::MainWindow(int aEventId, QWidget *aParent)
 {
     setupUi(this);
 
-    // Sanity check for existence of any Conference in the DB
-    // it AppSettings::confId() is 0, but there are any Conference(s) in the DB
-    // set the confId in the AppSettings for the ID of the first conference in the DB
-    QList<Conference> confs = Conference::getAll();
-    if(!confs.count()) // no conference(s) in the DB
-    {
-        AppSettings::setConfId(0); // no conference in the DB
-    }
-    else
-    {
-        if(AppSettings::confId() == 0)
-            AppSettings::setConfId(confs[0].id());
-
-        setWindowTitle(confs[0].title());
-    }
-
-    dayTabContainer->setType(TabContainer::EContainerTypeDay);
-    favsTabContainer->setType(TabContainer::EContainerTypeFavs);
-    tracksTabContainer->setType(TabContainer::EContainerTypeTracks);
-    nowTabContainer->setType(TabContainer::EContainerTypeNow);
-    roomsTabContainer->setType(TabContainer::EContainerTypeRooms);
-    searchTabContainer->setType(TabContainer::EContainerTypeSearch);
+    int confId = Conference::activeConference();
 
     connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
 
     // event details have changed
     connect(dayTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     connect(favsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
-    connect(favsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
+    connect(tracksTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     connect(roomsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     connect(nowTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     connect(searchTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
 
-
     // event conference map button clicked
     connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
 
     connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
 
-    if(Conference::getAll().count()) // no conference(s) in the DB
+    if(Conference::getAll().count())
+    {
+        initTabs();
+        fillAndShowConferenceHeader();
+        setWindowTitle(Conference::getById(confId).title());
+    }
+    else
     {
-        QDate startDate = Conference::getById(AppSettings::confId()).start();
-        QDate endDate = Conference::getById(AppSettings::confId()).end();
-        //
-        dayTabContainer->setDates(startDate, endDate);
-        tracksTabContainer->setDates(startDate, endDate);
-        roomsTabContainer->setDates(startDate, endDate);
-        favsTabContainer->setDates(startDate, endDate);
-        searchTabContainer->setDates(startDate, endDate);
-        //
-        conferenceTitle->setText(Conference::getById(AppSettings::confId()).title());
-        conferenceSubtitle->setText(Conference::getById(AppSettings::confId()).subtitle());
-        conferenceWhere->setText(Conference::getById(AppSettings::confId()).city() + ", " + Conference::getById(AppSettings::confId()).venue());
-        conferenceWhen->setText(
-                Conference::getById(AppSettings::confId()).start().toString("dd-MM-yyyy")
-                + ", " +
-                Conference::getById(AppSettings::confId()).end().toString("dd-MM-yyyy"));
+        conferenceHeader->hide();
     }
 
     // open dialog for given Event ID
@@ -105,22 +73,11 @@ void MainWindow::scheduleImported(int aConfId)
     Q_UNUSED(aConfId);
 
     QList<Conference> confs = Conference::getAll();
-    if(!confs.count()) // no conference(s) in the DB
-    {
-        AppSettings::setConfId(0); // no conference in the DB
-    }
-    else
+    if(confs.count())
     {
-        if(AppSettings::confId() == 0)
-            AppSettings::setConfId(confs[0].id());
-
-        // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
-        QDate startDate = Conference::getById(AppSettings::confId()).start();
-        QDate endDate = Conference::getById(AppSettings::confId()).end();
-        dayTabContainer->setDates(startDate, endDate);
-        tracksTabContainer->setDates(startDate, endDate);
-        roomsTabContainer->setDates(startDate, endDate);
-        favsTabContainer->setDates(startDate, endDate);
+        initTabs();
+        fillAndShowConferenceHeader();
+        setWindowTitle(Conference::getById(Conference::activeConference()).title());
     }
 }
 
@@ -155,3 +112,31 @@ void MainWindow::eventHasChanged(int aEventId)
     searchTabContainer->updateTreeViewModel(aEventId);
 }
 
+void MainWindow::fillAndShowConferenceHeader()
+{
+    int confId = Conference::activeConference();
+    conferenceTitle->setText(Conference::getById(confId).title());
+    conferenceSubtitle->setText(Conference::getById(confId).subtitle());
+    conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
+    conferenceWhen->setText(
+            Conference::getById(confId).start().toString("dd-MM-yyyy")
+            + ", " +
+            Conference::getById(confId).end().toString("dd-MM-yyyy"));
+    conferenceHeader->show();
+}
+
+void MainWindow::initTabs()
+{
+    int confId = Conference::activeConference();
+    QDate startDate = Conference::getById(confId).start();
+    QDate endDate = Conference::getById(confId).end();
+
+    // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
+    dayTabContainer->setDates(startDate, endDate);
+    tracksTabContainer->setDates(startDate, endDate);
+    roomsTabContainer->setDates(startDate, endDate);
+    favsTabContainer->setDates(startDate, endDate);
+    searchTabContainer->setDates(startDate, endDate);
+    nowTabContainer->updateTreeView(QDate::currentDate());
+}
+