search tab - header is hidden in case no conf exists in the DB
[toast/confclerk.git] / src / gui / mainwindow.cpp
1 #include "mainwindow.h"
2
3 #include <QTreeView>
4 #include <QFile>
5
6 #include <sqlengine.h>
7
8 #include <track.h>
9 #include <eventmodel.h>
10 #include <delegate.h>
11
12 #include <conference.h>
13
14 #include <QDialog>
15 #include <QMessageBox>
16 #include "ui_about.h"
17 #include <eventdialog.h>
18 #include "daynavigatorwidget.h"
19 #include "importschedulewidget.h"
20 #include "mapwindow.h"
21
22 #include <tabcontainer.h>
23
24 MainWindow::MainWindow(int aEventId, QWidget *aParent)
25     : QMainWindow(aParent)
26 {
27     setupUi(this);
28
29     int confId = Conference::activeConference();
30
31     connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
32
33     // event details have changed
34     connect(dayTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
35     connect(favsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
36     connect(tracksTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
37     connect(roomsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
38     connect(nowTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
39     connect(searchTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
40
41     // event conference map button clicked
42     connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
43
44     connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
45
46     if(Conference::getAll().count())
47     {
48         initTabs();
49         fillAndShowConferenceHeader();
50         setWindowTitle(Conference::getById(confId).title());
51     }
52     else
53     {
54         conferenceHeader->hide();
55     }
56
57     // open dialog for given Event ID
58     // this is used in case Alarm Dialog request application to start
59     if(aEventId)
60     {
61         try
62         {
63             EventDialog dialog(aEventId,this);
64             dialog.exec();
65         }
66         catch(OrmNoObjectException&) {} // just start application
67         catch(...) {} // just start application
68     }
69 }
70
71 void MainWindow::scheduleImported(int aConfId)
72 {
73     Q_UNUSED(aConfId);
74
75     QList<Conference> confs = Conference::getAll();
76     if(confs.count())
77     {
78         initTabs();
79         fillAndShowConferenceHeader();
80         setWindowTitle(Conference::getById(Conference::activeConference()).title());
81     }
82 }
83
84 void MainWindow::aboutApp()
85 {
86     QDialog dialog(this);
87     Ui::AboutDialog ui;
88     ui.setupUi(&dialog);
89     dialog.exec();
90 }
91
92 void MainWindow::conferenceMapClicked()
93 {
94     QString mapPath = QString(":/maps/campus.png");
95     if(!QFile::exists(mapPath))
96         mapPath = QString(":/maps/rooms/not-available.png");
97
98     QString roomName;
99
100     QPixmap map(mapPath);
101     MapWindow window(map,roomName,this);
102     window.exec();
103 }
104
105 void MainWindow::eventHasChanged(int aEventId)
106 {
107     dayTabContainer->updateTreeViewModel(aEventId);
108     favsTabContainer->updateTreeViewModel(aEventId);
109     tracksTabContainer->updateTreeViewModel(aEventId);
110     nowTabContainer->updateTreeViewModel(aEventId);
111     roomsTabContainer->updateTreeViewModel(aEventId);
112     searchTabContainer->updateTreeViewModel(aEventId);
113 }
114
115 void MainWindow::fillAndShowConferenceHeader()
116 {
117     int confId = Conference::activeConference();
118     conferenceTitle->setText(Conference::getById(confId).title());
119     conferenceSubtitle->setText(Conference::getById(confId).subtitle());
120     conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
121     conferenceWhen->setText(
122             Conference::getById(confId).start().toString("dd-MM-yyyy")
123             + ", " +
124             Conference::getById(confId).end().toString("dd-MM-yyyy"));
125     conferenceHeader->show();
126 }
127
128 void MainWindow::initTabs()
129 {
130     int confId = Conference::activeConference();
131     QDate startDate = Conference::getById(confId).start();
132     QDate endDate = Conference::getById(confId).end();
133
134     // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
135     dayTabContainer->setDates(startDate, endDate);
136     tracksTabContainer->setDates(startDate, endDate);
137     roomsTabContainer->setDates(startDate, endDate);
138     //favsTabContainer->setDates(startDate, endDate);
139     //searchTabContainer->setDates(startDate, endDate);
140     searchTabContainer->searchAgainClicked();
141     nowTabContainer->updateTreeView(QDate::currentDate());
142 }
143