1 #include "mainwindow.h"
2 #include <appsettings.h>
10 #include <eventmodel.h>
13 #include <conference.h>
16 #include <QMessageBox>
19 #include "eventdialog.h"
20 #include "daynavigatorwidget.h"
21 #include "importscheduledialog.h"
22 #include "mapwindow.h"
24 MainWindow::MainWindow(int aEventId, QWidget *aParent)
25 : QMainWindow(aParent)
29 // create "SQLITE" DB instance/connection
30 // opens DB connection (needed for EventModel)
31 mSqlEngine = new SqlEngine(this);
32 mSqlEngine->initialize();
34 // Sanity check for existence of any Conference in the DB
35 // it AppSettings::confId() is 0, but there are any Conference(s) in the DB
36 // set the confId in the AppSettings for the ID of the first conference in the DB
37 QList<Conference> confs = Conference::getAll();
38 if(!confs.count()) // no conference(s) in the DB
40 AppSettings::setConfId(0); // no conference in the DB
44 if(AppSettings::confId() == 0)
45 AppSettings::setConfId(confs[0].id());
48 // connect Menu actions
49 connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
50 connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
51 connect(actionAboutApplication, SIGNAL(triggered()), SLOT(aboutApp()));
53 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
54 connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &)));
55 connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &)));
56 connect(searchDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateSearchView(const QDate &)));
57 connect(roomDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateRoomView(const QDate &)));
60 dayTreeView->setHeaderHidden(true);
61 dayTreeView->setRootIsDecorated(false);
62 dayTreeView->setIndentation(0);
63 dayTreeView->setAnimated(true);
64 dayTreeView->setModel(new EventModel());
65 dayTreeView->setItemDelegate(new Delegate(dayTreeView));
68 favTreeView->setHeaderHidden(true);
69 favTreeView->setRootIsDecorated(false);
70 favTreeView->setIndentation(0);
71 favTreeView->setAnimated(true);
72 favTreeView->setModel(new EventModel());
73 favTreeView->setItemDelegate(new Delegate(favTreeView));
76 trackTreeView->setHeaderHidden(true);
77 trackTreeView->setRootIsDecorated(false);
78 trackTreeView->setIndentation(0);
79 trackTreeView->setAnimated(true);
80 trackTreeView->setModel(new EventModel());
81 trackTreeView->setItemDelegate(new Delegate(trackTreeView));
84 searchTreeView->setHeaderHidden(true);
85 searchTreeView->setRootIsDecorated(false);
86 searchTreeView->setIndentation(0);
87 searchTreeView->setAnimated(true);
88 searchTreeView->setModel(new EventModel());
89 searchTreeView->setItemDelegate(new Delegate(searchTreeView));
92 nowTreeView->setHeaderHidden(true);
93 nowTreeView->setRootIsDecorated(false);
94 nowTreeView->setIndentation(0);
95 nowTreeView->setAnimated(true);
96 nowTreeView->setModel(new EventModel());
97 nowTreeView->setItemDelegate(new Delegate(nowTreeView));
99 // NOW View refresh timer
100 QTimer *timer = new QTimer( this );
101 connect( timer, SIGNAL(timeout()), SLOT(timerUpdateNowView()) );
102 timer->start( 30000); // 30 seconds timer
105 roomTreeView->setHeaderHidden(true);
106 roomTreeView->setRootIsDecorated(false);
107 roomTreeView->setIndentation(0);
108 roomTreeView->setAnimated(true);
109 roomTreeView->setModel(new EventModel());
110 roomTreeView->setItemDelegate(new Delegate(roomTreeView));
112 // event details have changed
113 connect(dayTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
114 connect(favTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
115 connect(trackTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
116 connect(searchTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
117 connect(nowTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
118 connect(roomTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
121 connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
122 connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
123 connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
124 connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
125 connect(nowTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
126 connect(roomTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
127 // request for map to be displayed
128 connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
129 connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
130 connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
131 connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
132 connect(nowTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
133 connect(roomTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
134 // request for warning to be displayed
135 connect(dayTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
136 connect(favTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
137 connect(trackTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
138 connect(searchTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
139 connect(nowTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
140 connect(roomTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
141 // event search button clicked
142 connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
143 connect(searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
144 // event conference map button clicked
145 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
147 connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHasChanged(int)));
148 connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
150 if(!Conference::getAll().count()) // no conference(s) in the DB
152 dayNavigator->hide(); // hide DayNavigatorWidget
153 trackDayNavigator->hide();
154 roomDayNavigator->hide();
158 QDate aStartDate = Conference::getById(AppSettings::confId()).start();
159 QDate aEndDate = Conference::getById(AppSettings::confId()).end();
160 dayNavigator->setDates(aStartDate, aEndDate);
161 trackDayNavigator->setDates(aStartDate, aEndDate);
162 favouriteDayNavigator->setDates(aStartDate, aEndDate);
163 searchDayNavigator->setDates(aStartDate, aEndDate);
164 roomDayNavigator->setDates(aStartDate, aEndDate);
166 conferenceTitle->setText(Conference::getById(AppSettings::confId()).title());
167 conferenceSubtitle->setText(Conference::getById(AppSettings::confId()).subtitle());
168 conferenceWhere->setText(Conference::getById(AppSettings::confId()).city() + ", " + Conference::getById(AppSettings::confId()).venue());
169 conferenceWhen->setText(
170 Conference::getById(AppSettings::confId()).start().toString("dd-MM-yyyy")
172 Conference::getById(AppSettings::confId()).end().toString("dd-MM-yyyy"));
175 searchTreeView->hide();
176 searchVerticalWidget->hide();
179 // open dialog for given Event ID
180 // this is used in case Alarm Dialog request application to start
185 EventDialog dialog(aEventId,this);
188 catch(OrmNoObjectException&) {} // just start application
189 catch(...) {} // just start application
193 MainWindow::~MainWindow()
202 void MainWindow::importSchedule()
204 ImportScheduleDialog dialog(mSqlEngine,this);
207 QList<Conference> confs = Conference::getAll();
208 if(!confs.count()) // no conference(s) in the DB
210 AppSettings::setConfId(0); // no conference in the DB
214 if(AppSettings::confId() == 0)
215 AppSettings::setConfId(confs[0].id());
217 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
218 QDate aStartDate = Conference::getById(AppSettings::confId()).start();
219 QDate aEndDate = Conference::getById(AppSettings::confId()).end();
220 dayNavigator->setDates(aStartDate, aEndDate);
221 trackDayNavigator->setDates(aStartDate, aEndDate);
222 roomDayNavigator->setDates(aStartDate, aEndDate);
226 void MainWindow::aboutApp()
228 QDialog dialog(this);
234 void MainWindow::updateDayView(const QDate &aDate)
236 static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,AppSettings::confId());
237 dayTreeView->reset();
238 dayNavigator->show();
241 void MainWindow::updateTracksView(const QDate &aDate)
243 static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, AppSettings::confId());
244 trackTreeView->reset();
245 trackDayNavigator->show();
248 void MainWindow::updateFavouritesView(const QDate &aDate)
250 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,AppSettings::confId());
251 favTreeView->reset();
252 favouriteDayNavigator->show();
255 void MainWindow::updateSearchView(const QDate &aDate)
257 qDebug() << "MainWindow::updateSearchView(), aDate: " << aDate.toString() ;
258 searchTreeView->reset();
259 int eventsCount = static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(aDate,AppSettings::confId());
261 searchDayNavigator->getCurrentDate() != Conference::getById(AppSettings::confId()).start() ){
262 searchVerticalWidget->show();
263 searchAgainButton->show();
264 searchTreeView->show();
268 searchTreeView->hide();
269 searchVerticalWidget->hide();
274 void MainWindow::updateNowView()
276 EventModel *model = static_cast<EventModel*>(nowTreeView->model());
277 model->loadNowEvents(AppSettings::confId());
278 nowTreeView->reset();
279 nowTreeView->setAllExpanded(true);
282 void MainWindow::updateRoomView(const QDate &aDate)
284 static_cast<EventModel*>(roomTreeView->model())->loadEventsByRoom(aDate, AppSettings::confId());
285 roomTreeView->reset();
286 roomDayNavigator->show();
289 void MainWindow::itemClicked(const QModelIndex &aIndex)
291 // have to handle only events, not time-groups
292 if(!aIndex.parent().isValid()) // time-group
295 EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
299 void MainWindow::displayMap(const QModelIndex &aIndex)
301 Event *event = static_cast<Event*>(aIndex.internalPointer());
303 // room names are stored in lower-case format
304 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
305 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
306 if(!QFile::exists(mapPath))
307 mapPath = QString(":/maps/rooms/not-available.png");
310 if(mapPath.contains("not-available", Qt::CaseInsensitive))
311 roomName = QString("Map is not available: %1").arg(event->room());
313 roomName = event->room();
315 QPixmap map(mapPath);
316 MapWindow window(map,roomName,this);
320 void MainWindow::searchClicked()
322 QHash<QString,QString> columns;
324 if( searchTitle->isChecked() )
325 columns.insertMulti("EVENT", "title");
326 if( searchAbstract->isChecked() )
327 columns.insertMulti("EVENT", "abstract");
328 if( searchTag->isChecked() )
329 columns.insertMulti("EVENT", "tag");
330 if( searchSpeaker->isChecked() )
331 columns["PERSON"] = "name";
332 if( searchRoom->isChecked() )
333 columns["ROOM"] = "name";
335 QString keyword = searchEdit->text().replace( QString("%"), QString("\\%") );
336 qDebug() << "\nKeyword to search: " << keyword;
337 mSqlEngine->searchEvent( AppSettings::confId(), columns, keyword );
339 updateSearchView( Conference::getById(AppSettings::confId()).start() );
342 void MainWindow::searchAgainClicked()
345 searchAgainButton->hide();
348 void MainWindow::conferenceMapClicked()
351 QString mapPath = QString(":/maps/campus.png");
352 if(!QFile::exists(mapPath))
353 mapPath = QString(":/maps/rooms/not-available.png");
357 QPixmap map(mapPath);
358 MapWindow window(map,roomName,this);
362 void MainWindow::displayWarning(const QModelIndex &aIndex)
366 QMessageBox::warning(
368 tr("Time Conflict Warning"),
369 tr("This event happens at the same time than another one of your favourites.") );
372 void MainWindow::eventHasChanged(int aEventId)
374 static_cast<EventModel*>(dayTreeView->model())->updateModel(aEventId);
375 static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
376 static_cast<EventModel*>(trackTreeView->model())->updateModel(aEventId);
377 static_cast<EventModel*>(searchTreeView->model())->updateModel(aEventId);
378 static_cast<EventModel*>(nowTreeView->model())->updateModel(aEventId);
379 static_cast<EventModel*>(roomTreeView->model())->updateModel(aEventId);
382 void MainWindow::tabHasChanged(int aIndex)
386 // TODO: only if it changed to favourities tab
387 updateFavouritesView(favouriteDayNavigator->getCurrentDate());
388 // TODO: only if it changed to now tab
392 void MainWindow::timerUpdateNowView()
394 QWidget * pCurrentWidget = tabWidget->widget(tabWidget->currentIndex());
396 if( pCurrentWidget != NULL )
398 if( pCurrentWidget == tab )