1 #include "mainwindow.h"
2 #include <appsettings.h>
10 #include <eventmodel.h>
13 #include <conference.h>
16 #include <QMessageBox>
18 #include "eventdialog.h"
19 #include "daynavigatorwidget.h"
20 #include "importscheduledialog.h"
21 #include "mapwindow.h"
23 MainWindow::MainWindow(int aEventId, QWidget *aParent)
24 : QMainWindow(aParent)
28 // create "SQLITE" DB instance/connection
29 // opens DB connection (needed for EventModel)
30 mSqlEngine = new SqlEngine(this);
31 mSqlEngine->initialize();
33 // Sanity check for existence of any Conference in the DB
34 // it AppSettings::confId() is 0, but there are any Conference(s) in the DB
35 // set the confId in the AppSettings for the ID of the first conference in the DB
36 QList<Conference> confs = Conference::getAll();
37 if(!confs.count()) // no conference(s) in the DB
39 AppSettings::setConfId(0); // no conference in the DB
43 if(AppSettings::confId() == 0)
44 AppSettings::setConfId(confs[0].id());
47 // connect Menu actions
48 connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
49 connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
50 connect(actionAboutApplication, SIGNAL(triggered()), SLOT(aboutApp()));
52 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
53 connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &)));
54 connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &)));
55 connect(searchDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateSearchView(const QDate &)));
56 connect(roomDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateRoomView(const QDate &)));
59 dayTreeView->setHeaderHidden(true);
60 dayTreeView->setRootIsDecorated(false);
61 dayTreeView->setIndentation(0);
62 dayTreeView->setAnimated(true);
63 dayTreeView->setModel(new EventModel());
64 dayTreeView->setItemDelegate(new Delegate(dayTreeView));
67 favTreeView->setHeaderHidden(true);
68 favTreeView->setRootIsDecorated(false);
69 favTreeView->setIndentation(0);
70 favTreeView->setAnimated(true);
71 favTreeView->setModel(new EventModel());
72 favTreeView->setItemDelegate(new Delegate(favTreeView));
75 trackTreeView->setHeaderHidden(true);
76 trackTreeView->setRootIsDecorated(false);
77 trackTreeView->setIndentation(0);
78 trackTreeView->setAnimated(true);
79 trackTreeView->setModel(new EventModel());
80 trackTreeView->setItemDelegate(new Delegate(trackTreeView));
83 searchTreeView->setHeaderHidden(true);
84 searchTreeView->setRootIsDecorated(false);
85 searchTreeView->setIndentation(0);
86 searchTreeView->setAnimated(true);
87 searchTreeView->setModel(new EventModel());
88 searchTreeView->setItemDelegate(new Delegate(searchTreeView));
91 nowTreeView->setHeaderHidden(true);
92 nowTreeView->setRootIsDecorated(false);
93 nowTreeView->setIndentation(0);
94 nowTreeView->setAnimated(true);
95 nowTreeView->setModel(new EventModel());
96 nowTreeView->setItemDelegate(new Delegate(nowTreeView));
99 roomTreeView->setHeaderHidden(true);
100 roomTreeView->setRootIsDecorated(false);
101 roomTreeView->setIndentation(0);
102 roomTreeView->setAnimated(true);
103 roomTreeView->setModel(new EventModel());
104 roomTreeView->setItemDelegate(new Delegate(roomTreeView));
106 // event details have changed
107 connect(dayTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
108 connect(favTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
109 connect(trackTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
110 connect(searchTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
111 connect(nowTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
112 connect(roomTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
115 connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
116 connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
117 connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
118 connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
119 connect(nowTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
120 connect(roomTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
121 // request for map to be displayed
122 connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
123 connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
124 connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
125 connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
126 connect(nowTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
127 connect(roomTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
128 // request for warning to be displayed
129 connect(dayTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
130 connect(favTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
131 connect(trackTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
132 connect(searchTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
133 connect(nowTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
134 connect(roomTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
135 // event search button clicked
136 connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
137 connect(searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
138 // event conference map button clicked
139 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
141 connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHasChanged(int)));
143 if(!Conference::getAll().count()) // no conference(s) in the DB
145 dayNavigator->hide(); // hide DayNavigatorWidget
146 trackDayNavigator->hide();
147 roomDayNavigator->hide();
151 QDate aStartDate = Conference::getById(AppSettings::confId()).start();
152 QDate aEndDate = Conference::getById(AppSettings::confId()).end();
153 dayNavigator->setDates(aStartDate, aEndDate);
154 trackDayNavigator->setDates(aStartDate, aEndDate);
155 favouriteDayNavigator->setDates(aStartDate, aEndDate);
156 searchDayNavigator->setDates(aStartDate, aEndDate);
157 roomDayNavigator->setDates(aStartDate, aEndDate);
159 conferenceTitle->setText(Conference::getById(AppSettings::confId()).title());
160 conferenceSubtitle->setText(Conference::getById(AppSettings::confId()).subtitle());
161 conferenceWhere->setText(Conference::getById(AppSettings::confId()).city() + ", " + Conference::getById(AppSettings::confId()).venue());
162 conferenceWhen->setText(
163 Conference::getById(AppSettings::confId()).start().toString("dd-MM-yyyy")
165 Conference::getById(AppSettings::confId()).end().toString("dd-MM-yyyy"));
168 searchTreeView->hide();
169 searchVerticalWidget->hide();
172 // open dialog for given Event ID
173 // this is used in case Alarm Dialog request application to start
178 EventDialog dialog(aEventId,this);
181 catch(OrmNoObjectException&) {} // just start application
182 catch(...) {} // just start application
186 MainWindow::~MainWindow()
195 void MainWindow::importSchedule()
197 ImportScheduleDialog dialog(mSqlEngine,this);
200 QList<Conference> confs = Conference::getAll();
201 if(!confs.count()) // no conference(s) in the DB
203 AppSettings::setConfId(0); // no conference in the DB
207 if(AppSettings::confId() == 0)
208 AppSettings::setConfId(confs[0].id());
210 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
211 QDate aStartDate = Conference::getById(AppSettings::confId()).start();
212 QDate aEndDate = Conference::getById(AppSettings::confId()).end();
213 dayNavigator->setDates(aStartDate, aEndDate);
214 trackDayNavigator->setDates(aStartDate, aEndDate);
218 void MainWindow::aboutApp()
220 QDialog dialog(this);
226 void MainWindow::updateDayView(const QDate &aDate)
228 static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,AppSettings::confId());
229 dayTreeView->reset();
230 dayNavigator->show();
233 void MainWindow::updateTracksView(const QDate &aDate)
235 static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, AppSettings::confId());
236 trackTreeView->reset();
237 trackDayNavigator->show();
240 void MainWindow::updateFavouritesView(const QDate &aDate)
242 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,AppSettings::confId());
243 favTreeView->reset();
244 favouriteDayNavigator->show();
247 void MainWindow::updateSearchView(const QDate &aDate)
249 qDebug() << "MainWindow::updateSearchView(), aDate: " << aDate.toString() ;
250 searchTreeView->reset();
251 int eventsCount = static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(aDate,AppSettings::confId());
253 searchDayNavigator->getCurrentDate() != Conference::getById(AppSettings::confId()).start() ){
254 searchVerticalWidget->show();
255 searchAgainButton->show();
256 searchTreeView->show();
260 searchTreeView->hide();
261 searchVerticalWidget->hide();
266 void MainWindow::updateNowView()
268 EventModel *model = static_cast<EventModel*>(nowTreeView->model());
269 model->loadNowEvents(AppSettings::confId());
270 nowTreeView->reset();
271 nowTreeView->setAllExpanded(true);
274 void MainWindow::updateRoomView(const QDate &aDate)
276 static_cast<EventModel*>(roomTreeView->model())->loadEventsByRoom(aDate, AppSettings::confId());
277 roomTreeView->reset();
278 roomDayNavigator->show();
281 void MainWindow::itemClicked(const QModelIndex &aIndex)
283 // have to handle only events, not time-groups
284 if(!aIndex.parent().isValid()) // time-group
287 EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
291 void MainWindow::displayMap(const QModelIndex &aIndex)
293 Event *event = static_cast<Event*>(aIndex.internalPointer());
295 // room names are stored in lower-case format
296 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
297 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
298 if(!QFile::exists(mapPath))
299 mapPath = QString(":/maps/rooms/not-available.png");
302 if(mapPath.contains("not-available", Qt::CaseInsensitive))
303 roomName = QString("Map is not available: %1").arg(event->room());
305 roomName = event->room();
307 QPixmap map(mapPath);
308 MapWindow window(map,roomName,this);
312 void MainWindow::searchClicked()
314 QHash<QString,QString> columns;
316 if( searchTitle->isChecked() )
317 columns.insertMulti("EVENT", "title");
318 if( searchAbstract->isChecked() )
319 columns.insertMulti("EVENT", "abstract");
320 if( searchTag->isChecked() )
321 columns.insertMulti("EVENT", "tag");
322 if( searchSpeaker->isChecked() )
323 columns["PERSON"] = "name";
324 if( searchRoom->isChecked() )
325 columns["ROOM"] = "name";
327 QString keyword = searchEdit->text().replace( QString("%"), QString("\\%") );
328 qDebug() << "\nKeyword to search: " << keyword;
329 mSqlEngine->searchEvent( AppSettings::confId(), columns, keyword );
331 updateSearchView( Conference::getById(AppSettings::confId()).start() );
334 void MainWindow::searchAgainClicked()
337 searchAgainButton->hide();
340 void MainWindow::conferenceMapClicked()
343 QString mapPath = QString(":/maps/campus.png");
344 if(!QFile::exists(mapPath))
345 mapPath = QString(":/maps/rooms/not-available.png");
349 QPixmap map(mapPath);
350 MapWindow window(map,roomName,this);
354 void MainWindow::displayWarning(const QModelIndex &aIndex)
358 QMessageBox::warning(
360 tr("Time Conflict Warning"),
361 tr("This event happens at the same time than another one of your favourites.") );
364 void MainWindow::eventHasChanged(int aEventId)
366 static_cast<EventModel*>(dayTreeView->model())->updateModel(aEventId);
367 static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
368 static_cast<EventModel*>(trackTreeView->model())->updateModel(aEventId);
369 static_cast<EventModel*>(searchTreeView->model())->updateModel(aEventId);
370 static_cast<EventModel*>(nowTreeView->model())->updateModel(aEventId);
373 void MainWindow::tabHasChanged(int aIndex)
377 // TODO: only if it changed to favourities tab
378 updateFavouritesView(favouriteDayNavigator->getCurrentDate());
379 // TODO: only if it changed to now tab