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 "importschedulewidget.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();
33 importScheduleWidget->setSqlEngine(mSqlEngine);
35 // Sanity check for existence of any Conference in the DB
36 // it AppSettings::confId() is 0, but there are any Conference(s) in the DB
37 // set the confId in the AppSettings for the ID of the first conference in the DB
38 QList<Conference> confs = Conference::getAll();
39 if(!confs.count()) // no conference(s) in the DB
41 AppSettings::setConfId(0); // no conference in the DB
45 if(AppSettings::confId() == 0)
46 AppSettings::setConfId(confs[0].id());
49 connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
51 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
52 connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &)));
53 connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &)));
54 connect(searchDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateSearchView(const QDate &)));
55 connect(roomDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateRoomView(const QDate &)));
58 dayTreeView->setHeaderHidden(true);
59 dayTreeView->setRootIsDecorated(false);
60 dayTreeView->setIndentation(0);
61 dayTreeView->setAnimated(true);
62 dayTreeView->setModel(new EventModel());
63 dayTreeView->setItemDelegate(new Delegate(dayTreeView));
66 favTreeView->setHeaderHidden(true);
67 favTreeView->setRootIsDecorated(false);
68 favTreeView->setIndentation(0);
69 favTreeView->setAnimated(true);
70 favTreeView->setModel(new EventModel());
71 favTreeView->setItemDelegate(new Delegate(favTreeView));
74 trackTreeView->setHeaderHidden(true);
75 trackTreeView->setRootIsDecorated(false);
76 trackTreeView->setIndentation(0);
77 trackTreeView->setAnimated(true);
78 trackTreeView->setModel(new EventModel());
79 trackTreeView->setItemDelegate(new Delegate(trackTreeView));
82 searchTreeView->setHeaderHidden(true);
83 searchTreeView->setRootIsDecorated(false);
84 searchTreeView->setIndentation(0);
85 searchTreeView->setAnimated(true);
86 searchTreeView->setModel(new EventModel());
87 searchTreeView->setItemDelegate(new Delegate(searchTreeView));
90 nowTreeView->setHeaderHidden(true);
91 nowTreeView->setRootIsDecorated(false);
92 nowTreeView->setIndentation(0);
93 nowTreeView->setAnimated(true);
94 nowTreeView->setModel(new EventModel());
95 nowTreeView->setItemDelegate(new Delegate(nowTreeView));
97 // NOW View refresh timer
98 QTimer *timer = new QTimer( this );
99 connect( timer, SIGNAL(timeout()), SLOT(timerUpdateNowView()) );
100 timer->start( 30000); // 30 seconds timer
103 roomTreeView->setHeaderHidden(true);
104 roomTreeView->setRootIsDecorated(false);
105 roomTreeView->setIndentation(0);
106 roomTreeView->setAnimated(true);
107 roomTreeView->setModel(new EventModel());
108 roomTreeView->setItemDelegate(new Delegate(roomTreeView));
110 // event details have changed
111 connect(dayTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
112 connect(favTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
113 connect(trackTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
114 connect(searchTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
115 connect(nowTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
116 connect(roomTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
119 connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
120 connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
121 connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
122 connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
123 connect(nowTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
124 connect(roomTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
125 // request for map to be displayed
126 connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
127 connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
128 connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
129 connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
130 connect(nowTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
131 connect(roomTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
132 // request for warning to be displayed
133 connect(dayTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
134 connect(favTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
135 connect(trackTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
136 connect(searchTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
137 connect(nowTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
138 connect(roomTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
139 // event search button clicked
140 connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
141 connect(searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
142 // event conference map button clicked
143 connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
145 connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHasChanged(int)));
146 connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
148 if(!Conference::getAll().count()) // no conference(s) in the DB
150 dayNavigator->hide(); // hide DayNavigatorWidget
151 trackDayNavigator->hide();
152 roomDayNavigator->hide();
156 QDate aStartDate = Conference::getById(AppSettings::confId()).start();
157 QDate aEndDate = Conference::getById(AppSettings::confId()).end();
158 dayNavigator->setDates(aStartDate, aEndDate);
159 trackDayNavigator->setDates(aStartDate, aEndDate);
160 favouriteDayNavigator->setDates(aStartDate, aEndDate);
161 searchDayNavigator->setDates(aStartDate, aEndDate);
162 roomDayNavigator->setDates(aStartDate, aEndDate);
164 conferenceTitle->setText(Conference::getById(AppSettings::confId()).title());
165 conferenceSubtitle->setText(Conference::getById(AppSettings::confId()).subtitle());
166 conferenceWhere->setText(Conference::getById(AppSettings::confId()).city() + ", " + Conference::getById(AppSettings::confId()).venue());
167 conferenceWhen->setText(
168 Conference::getById(AppSettings::confId()).start().toString("dd-MM-yyyy")
170 Conference::getById(AppSettings::confId()).end().toString("dd-MM-yyyy"));
173 searchTreeView->hide();
174 searchVerticalWidget->hide();
177 // open dialog for given Event ID
178 // this is used in case Alarm Dialog request application to start
183 EventDialog dialog(aEventId,this);
186 catch(OrmNoObjectException&) {} // just start application
187 catch(...) {} // just start application
191 MainWindow::~MainWindow()
200 void MainWindow::scheduleImported(int aConfId)
204 QList<Conference> confs = Conference::getAll();
205 if(!confs.count()) // no conference(s) in the DB
207 AppSettings::setConfId(0); // no conference in the DB
211 if(AppSettings::confId() == 0)
212 AppSettings::setConfId(confs[0].id());
214 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
215 QDate aStartDate = Conference::getById(AppSettings::confId()).start();
216 QDate aEndDate = Conference::getById(AppSettings::confId()).end();
217 dayNavigator->setDates(aStartDate, aEndDate);
218 trackDayNavigator->setDates(aStartDate, aEndDate);
219 roomDayNavigator->setDates(aStartDate, aEndDate);
223 void MainWindow::aboutApp()
225 QDialog dialog(this);
231 void MainWindow::updateDayView(const QDate &aDate)
233 static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,AppSettings::confId());
234 dayTreeView->reset();
235 dayNavigator->show();
238 void MainWindow::updateTracksView(const QDate &aDate)
240 static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, AppSettings::confId());
241 trackTreeView->reset();
242 trackDayNavigator->show();
245 void MainWindow::updateFavouritesView(const QDate &aDate)
247 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,AppSettings::confId());
248 favTreeView->reset();
249 favouriteDayNavigator->show();
252 void MainWindow::updateSearchView(const QDate &aDate)
254 qDebug() << "MainWindow::updateSearchView(), aDate: " << aDate.toString() ;
255 searchTreeView->reset();
256 int eventsCount = static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(aDate,AppSettings::confId());
258 searchDayNavigator->getCurrentDate() != Conference::getById(AppSettings::confId()).start() ){
259 searchVerticalWidget->show();
260 //searchAgainButton->show();
261 searchTreeView->show();
265 searchTreeView->hide();
266 searchVerticalWidget->hide();
271 void MainWindow::updateNowView()
273 EventModel *model = static_cast<EventModel*>(nowTreeView->model());
274 model->loadNowEvents(AppSettings::confId());
275 nowTreeView->reset();
276 nowTreeView->setAllExpanded(true);
279 void MainWindow::updateRoomView(const QDate &aDate)
281 static_cast<EventModel*>(roomTreeView->model())->loadEventsByRoom(aDate, AppSettings::confId());
282 roomTreeView->reset();
283 roomDayNavigator->show();
286 void MainWindow::itemClicked(const QModelIndex &aIndex)
288 // have to handle only events, not time-groups
289 if(!aIndex.parent().isValid()) // time-group
292 EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
296 void MainWindow::displayMap(const QModelIndex &aIndex)
298 Event *event = static_cast<Event*>(aIndex.internalPointer());
300 // room names are stored in lower-case format
301 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
302 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
303 if(!QFile::exists(mapPath))
304 mapPath = QString(":/maps/rooms/not-available.png");
307 if(mapPath.contains("not-available", Qt::CaseInsensitive))
308 roomName = QString("Map is not available: %1").arg(event->room());
310 roomName = event->room();
312 QPixmap map(mapPath);
313 MapWindow window(map,roomName,this);
317 void MainWindow::searchClicked()
319 QHash<QString,QString> columns;
321 if( searchTitle->isChecked() )
322 columns.insertMulti("EVENT", "title");
323 if( searchAbstract->isChecked() )
324 columns.insertMulti("EVENT", "abstract");
325 if( searchTag->isChecked() )
326 columns.insertMulti("EVENT", "tag");
327 if( searchSpeaker->isChecked() )
328 columns["PERSON"] = "name";
329 if( searchRoom->isChecked() )
330 columns["ROOM"] = "name";
332 QString keyword = searchEdit->text().replace( QString("%"), QString("\\%") );
333 qDebug() << "\nKeyword to search: " << keyword;
334 mSqlEngine->searchEvent( AppSettings::confId(), columns, keyword );
336 QDate aStartDate = Conference::getById(AppSettings::confId()).start();
337 QDate aEndDate = Conference::getById(AppSettings::confId()).end();
338 searchDayNavigator->setDates(aStartDate, aEndDate);
339 updateSearchView( Conference::getById(AppSettings::confId()).start() );
342 void MainWindow::searchAgainClicked()
345 //searchAgainButton->hide();
346 searchVerticalWidget->hide();
347 searchTreeView->hide();
351 void MainWindow::conferenceMapClicked()
354 QString mapPath = QString(":/maps/campus.png");
355 if(!QFile::exists(mapPath))
356 mapPath = QString(":/maps/rooms/not-available.png");
360 QPixmap map(mapPath);
361 MapWindow window(map,roomName,this);
365 void MainWindow::displayWarning(const QModelIndex &aIndex)
369 QMessageBox::warning(
371 tr("Time Conflict Warning"),
372 tr("This event happens at the same time than another one of your favourites.") );
375 void MainWindow::eventHasChanged(int aEventId)
377 static_cast<EventModel*>(dayTreeView->model())->updateModel(aEventId);
378 static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
379 static_cast<EventModel*>(trackTreeView->model())->updateModel(aEventId);
380 static_cast<EventModel*>(searchTreeView->model())->updateModel(aEventId);
381 static_cast<EventModel*>(nowTreeView->model())->updateModel(aEventId);
382 static_cast<EventModel*>(roomTreeView->model())->updateModel(aEventId);
385 void MainWindow::tabHasChanged(int aIndex)
389 // TODO: only if it changed to favourities tab
390 updateFavouritesView(favouriteDayNavigator->getCurrentDate());
391 // TODO: only if it changed to now tab
395 void MainWindow::timerUpdateNowView()
397 QWidget * pCurrentWidget = tabWidget->widget(tabWidget->currentIndex());
399 if( pCurrentWidget != NULL )
401 if( pCurrentWidget == tab )