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