if no conference is in the DB, the user is automatically
[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         // go to the 'conferenceTab', so the user can import the schedule
56         tabWidget->setCurrentIndex(6); // 6 - conference tab
57     }
58
59     // open dialog for given Event ID
60     // this is used in case Alarm Dialog request application to start
61     if(aEventId)
62     {
63         try
64         {
65             EventDialog dialog(aEventId,this);
66             dialog.exec();
67         }
68         catch(OrmNoObjectException&) {} // just start application
69         catch(...) {} // just start application
70     }
71 }
72
73 void MainWindow::scheduleImported(int aConfId)
74 {
75     Q_UNUSED(aConfId);
76
77     QList<Conference> confs = Conference::getAll();
78     if(confs.count())
79     {
80         initTabs();
81         fillAndShowConferenceHeader();
82         setWindowTitle(Conference::getById(Conference::activeConference()).title());
83     }
84 }
85
86 void MainWindow::aboutApp()
87 {
88     QDialog dialog(this);
89     Ui::AboutDialog ui;
90     ui.setupUi(&dialog);
91     dialog.exec();
92 }
93
94 void MainWindow::conferenceMapClicked()
95 {
96     QString mapPath = QString(":/maps/campus.png");
97     if(!QFile::exists(mapPath))
98         mapPath = QString(":/maps/rooms/not-available.png");
99
100     QString roomName;
101
102     QPixmap map(mapPath);
103     MapWindow window(map,roomName,this);
104     window.exec();
105 }
106
107 void MainWindow::eventHasChanged(int aEventId)
108 {
109     dayTabContainer->updateTreeViewModel(aEventId);
110     favsTabContainer->updateTreeViewModel(aEventId);
111     tracksTabContainer->updateTreeViewModel(aEventId);
112     nowTabContainer->updateTreeViewModel(aEventId);
113     roomsTabContainer->updateTreeViewModel(aEventId);
114     searchTabContainer->updateTreeViewModel(aEventId);
115 }
116
117 void MainWindow::fillAndShowConferenceHeader()
118 {
119     int confId = Conference::activeConference();
120     conferenceTitle->setText(Conference::getById(confId).title());
121     conferenceSubtitle->setText(Conference::getById(confId).subtitle());
122     conferenceWhere->setText(Conference::getById(confId).city() + ", " + Conference::getById(confId).venue());
123     conferenceWhen->setText(
124             Conference::getById(confId).start().toString("dd-MM-yyyy")
125             + ", " +
126             Conference::getById(confId).end().toString("dd-MM-yyyy"));
127     conferenceHeader->show();
128 }
129
130 void MainWindow::initTabs()
131 {
132     int confId = Conference::activeConference();
133     QDate startDate = Conference::getById(confId).start();
134     QDate endDate = Conference::getById(confId).end();
135
136     // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
137     dayTabContainer->setDates(startDate, endDate);
138     tracksTabContainer->setDates(startDate, endDate);
139     roomsTabContainer->setDates(startDate, endDate);
140     //favsTabContainer->setDates(startDate, endDate);
141     //searchTabContainer->setDates(startDate, endDate);
142     searchTabContainer->searchAgainClicked();
143     nowTabContainer->updateTreeView(QDate::currentDate());
144 }
145