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);
215 roomDayNavigator->setDates(aStartDate, aEndDate);
219 void MainWindow::aboutApp()
221 QDialog dialog(this);
227 void MainWindow::updateDayView(const QDate &aDate)
229 static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,AppSettings::confId());
230 dayTreeView->reset();
231 dayNavigator->show();
234 void MainWindow::updateTracksView(const QDate &aDate)
236 static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, AppSettings::confId());
237 trackTreeView->reset();
238 trackDayNavigator->show();
241 void MainWindow::updateFavouritesView(const QDate &aDate)
243 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,AppSettings::confId());
244 favTreeView->reset();
245 favouriteDayNavigator->show();
248 void MainWindow::updateSearchView(const QDate &aDate)
250 qDebug() << "MainWindow::updateSearchView(), aDate: " << aDate.toString() ;
251 searchTreeView->reset();
252 int eventsCount = static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(aDate,AppSettings::confId());
254 searchDayNavigator->getCurrentDate() != Conference::getById(AppSettings::confId()).start() ){
255 searchVerticalWidget->show();
256 searchAgainButton->show();
257 searchTreeView->show();
261 searchTreeView->hide();
262 searchVerticalWidget->hide();
267 void MainWindow::updateNowView()
269 EventModel *model = static_cast<EventModel*>(nowTreeView->model());
270 model->loadNowEvents(AppSettings::confId());
271 nowTreeView->reset();
272 nowTreeView->setAllExpanded(true);
275 void MainWindow::updateRoomView(const QDate &aDate)
277 static_cast<EventModel*>(roomTreeView->model())->loadEventsByRoom(aDate, AppSettings::confId());
278 roomTreeView->reset();
279 roomDayNavigator->show();
282 void MainWindow::itemClicked(const QModelIndex &aIndex)
284 // have to handle only events, not time-groups
285 if(!aIndex.parent().isValid()) // time-group
288 EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
292 void MainWindow::displayMap(const QModelIndex &aIndex)
294 Event *event = static_cast<Event*>(aIndex.internalPointer());
296 // room names are stored in lower-case format
297 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
298 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
299 if(!QFile::exists(mapPath))
300 mapPath = QString(":/maps/rooms/not-available.png");
303 if(mapPath.contains("not-available", Qt::CaseInsensitive))
304 roomName = QString("Map is not available: %1").arg(event->room());
306 roomName = event->room();
308 QPixmap map(mapPath);
309 MapWindow window(map,roomName,this);
313 void MainWindow::searchClicked()
315 QHash<QString,QString> columns;
317 if( searchTitle->isChecked() )
318 columns.insertMulti("EVENT", "title");
319 if( searchAbstract->isChecked() )
320 columns.insertMulti("EVENT", "abstract");
321 if( searchTag->isChecked() )
322 columns.insertMulti("EVENT", "tag");
323 if( searchSpeaker->isChecked() )
324 columns["PERSON"] = "name";
325 if( searchRoom->isChecked() )
326 columns["ROOM"] = "name";
328 QString keyword = searchEdit->text().replace( QString("%"), QString("\\%") );
329 qDebug() << "\nKeyword to search: " << keyword;
330 mSqlEngine->searchEvent( AppSettings::confId(), columns, keyword );
332 updateSearchView( Conference::getById(AppSettings::confId()).start() );
335 void MainWindow::searchAgainClicked()
338 searchAgainButton->hide();
341 void MainWindow::conferenceMapClicked()
344 QString mapPath = QString(":/maps/campus.png");
345 if(!QFile::exists(mapPath))
346 mapPath = QString(":/maps/rooms/not-available.png");
350 QPixmap map(mapPath);
351 MapWindow window(map,roomName,this);
355 void MainWindow::displayWarning(const QModelIndex &aIndex)
359 QMessageBox::warning(
361 tr("Time Conflict Warning"),
362 tr("This event happens at the same time than another one of your favourites.") );
365 void MainWindow::eventHasChanged(int aEventId)
367 static_cast<EventModel*>(dayTreeView->model())->updateModel(aEventId);
368 static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
369 static_cast<EventModel*>(trackTreeView->model())->updateModel(aEventId);
370 static_cast<EventModel*>(searchTreeView->model())->updateModel(aEventId);
371 static_cast<EventModel*>(nowTreeView->model())->updateModel(aEventId);
372 static_cast<EventModel*>(roomTreeView->model())->updateModel(aEventId);
375 void MainWindow::tabHasChanged(int aIndex)
379 // TODO: only if it changed to favourities tab
380 updateFavouritesView(favouriteDayNavigator->getCurrentDate());
381 // TODO: only if it changed to now tab