1 #include "mainwindow.h"
9 #include <eventmodel.h>
12 #include <conference.h>
15 #include <QMessageBox>
17 #include "eventdialog.h"
18 #include "daynavigatorwidget.h"
19 #include "importscheduledialog.h"
20 #include "mapwindow.h"
25 MainWindow::MainWindow(int aEventId, QWidget *aParent)
26 : QMainWindow(aParent)
30 // connect Menu actions
31 connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
32 connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
33 connect(actionAboutApplication, SIGNAL(triggered()), SLOT(aboutApp()));
35 // create "SQLITE" DB instance/connection
36 // opens DB connection (needed for EventModel)
37 mSqlEngine = new SqlEngine(this);
38 mSqlEngine->initialize();
41 Track::updateTrackMap();
43 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
44 connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &)));
45 connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &)));
46 connect(searchDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateSearchView(const QDate &)));
49 dayTreeView->setHeaderHidden(true);
50 dayTreeView->setRootIsDecorated(false);
51 dayTreeView->setIndentation(0);
52 dayTreeView->setAnimated(true);
53 dayTreeView->setModel(new EventModel());
54 dayTreeView->setItemDelegate(new Delegate(dayTreeView));
57 favTreeView->setHeaderHidden(true);
58 favTreeView->setRootIsDecorated(false);
59 favTreeView->setIndentation(0);
60 favTreeView->setAnimated(true);
61 favTreeView->setModel(new EventModel());
62 favTreeView->setItemDelegate(new Delegate(favTreeView));
65 trackTreeView->setHeaderHidden(true);
66 trackTreeView->setRootIsDecorated(false);
67 trackTreeView->setIndentation(0);
68 trackTreeView->setAnimated(true);
69 trackTreeView->setModel(new EventModel());
70 trackTreeView->setItemDelegate(new Delegate(trackTreeView));
73 searchTreeView->setHeaderHidden(true);
74 searchTreeView->setRootIsDecorated(false);
75 searchTreeView->setIndentation(0);
76 searchTreeView->setAnimated(true);
77 searchTreeView->setModel(new EventModel());
78 searchTreeView->setItemDelegate(new Delegate(searchTreeView));
81 connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
82 connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
83 connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
84 connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
85 // request for map to be displayed
86 connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
87 connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
88 connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
89 connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
90 // request for warning to be displayed
91 connect(dayTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
92 connect(favTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
93 connect(trackTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
94 connect(searchTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
95 // event search button clicked
96 connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
98 // TESTING: load some 'fav' data
99 if(Conference::getAll().count()) // no conference(s) in the DB
101 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
102 favTreeView->reset();
105 if(!Conference::getAll().count()) // no conference(s) in the DB
107 dayNavigator->hide(); // hide DayNavigatorWidget
108 trackDayNavigator->hide();
112 QDate aStartDate = Conference::getById(confId).start();
113 QDate aEndDate = Conference::getById(confId).end();
114 dayNavigator->setDates(aStartDate, aEndDate);
115 trackDayNavigator->setDates(aStartDate, aEndDate);
116 favouriteDayNavigator->setDates(aStartDate, aEndDate);
117 searchDayNavigator->setDates(aStartDate, aEndDate);
120 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
122 searchTreeView->hide();
123 searchDayNavigator->hide();
125 // open dialog for given Event ID
126 // this is used in case Alarm Dialog request application to start
131 EventDialog dialog(aEventId,this);
134 catch(OrmNoObjectException) {} // just start application
135 catch(...) {} // just start application
139 MainWindow::~MainWindow()
148 void MainWindow::importSchedule()
150 ImportScheduleDialog dialog(mSqlEngine,this);
153 if(Conference::getAll().count())
155 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
156 QDate aStartDate = Conference::getById(confId).start();
157 QDate aEndDate = Conference::getById(confId).end();
158 dayNavigator->setDates(aStartDate, aEndDate);
159 //update activity map
160 Track::updateTrackMap();
161 trackDayNavigator->setDates(aStartDate, aEndDate);
165 void MainWindow::aboutApp()
167 QDialog dialog(this);
173 void MainWindow::updateDayView(const QDate &aDate)
175 static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
176 dayTreeView->reset();
177 dayNavigator->show();
180 void MainWindow::updateTab(const int aIndex)
184 case 0://index 0 of tabWidget: dayViewTab
186 updateDayView(dayNavigator->getCurrentDate());
189 case 1: //index 1 of tabWidget: favouritesTab
191 updateFavouritesView(favouriteDayNavigator->getCurrentDate());
194 case 2: //index 2 of tabWidget: activitiesTab
196 updateTracksView(trackDayNavigator->getCurrentDate());
199 case 3: //index 3 of tabWidget: searchTab
201 updateSearchView( searchDayNavigator->getCurrentDate() );
211 void MainWindow::updateTracksView(const QDate &aDate)
213 static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, confId);
214 trackTreeView->reset();
215 trackDayNavigator->show();
218 void MainWindow::updateFavouritesView(const QDate &aDate)
220 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,confId);
221 favTreeView->reset();
222 favouriteDayNavigator->show();
225 void MainWindow::updateSearchView(const QDate &aDate)
227 searchTreeView->reset();
228 int eventsCount = static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(aDate,confId);
230 searchDayNavigator->show();
231 searchTreeView->show();
234 searchTreeView->hide();
235 searchDayNavigator->hide();
239 void MainWindow::itemClicked(const QModelIndex &aIndex)
241 // have to handle only events, not time-groups
242 if(!aIndex.parent().isValid()) // time-group
245 EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
249 void MainWindow::displayMap(const QModelIndex &aIndex)
251 Event *event = static_cast<Event*>(aIndex.internalPointer());
253 // room names are stored in lower-case format
254 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
255 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
256 if(!QFile::exists(mapPath))
257 mapPath = QString(":/maps/rooms/not-available.png");
260 if(mapPath.contains("not-available", Qt::CaseInsensitive))
261 roomName = QString("Map is not available: %1").arg(event->room());
263 roomName = event->room();
265 QPixmap map(mapPath);
266 MapWindow window(map,roomName,this);
270 void MainWindow::searchClicked()
272 QList<QString> columns;
274 if( searchTitle->isChecked() )
275 columns.append( "title" );
276 if( searchAbstract->isChecked() )
277 columns.append( "abstract" );
279 mSqlEngine->searchEvent( confId, columns, searchEdit->text() );
280 updateSearchView( Conference::getById(confId).start() );
283 void MainWindow::displayWarning(const QModelIndex &aIndex)
285 QMessageBox::warning(
287 tr("Time Conflict Warning"),
288 tr("This event happens at the same time than another one of your favourites.") );