[e5bc908] | 1 | #include "mainwindow.h" |
---|
| 2 | |
---|
[d0d0a66] | 3 | #include <QTreeView> |
---|
[9bbb44e] | 4 | #include <QDirModel> |
---|
[d0d0a66] | 5 | |
---|
[72f6fe4] | 6 | #include <sqlengine.h> |
---|
| 7 | |
---|
[4693fa6] | 8 | #include <track.h> |
---|
[d0d0a66] | 9 | #include <eventmodel.h> |
---|
[66327a0] | 10 | #include <delegate.h> |
---|
[d0d0a66] | 11 | |
---|
[969a840] | 12 | #include <conference.h> |
---|
| 13 | |
---|
[c2d66b2] | 14 | #include <QDialog> |
---|
[3f3e22d] | 15 | #include <QMessageBox> |
---|
[c2d66b2] | 16 | #include "ui_about.h" |
---|
[707cd31] | 17 | #include "eventdialog.h" |
---|
[969a840] | 18 | #include "daynavigatorwidget.h" |
---|
[e493054] | 19 | #include "importscheduledialog.h" |
---|
[59c6cfe] | 20 | #include "mapwindow.h" |
---|
[72f6fe4] | 21 | |
---|
[3f3e22d] | 22 | |
---|
[c53a3f4] | 23 | const int confId = 1; |
---|
| 24 | |
---|
[d4a8bbf] | 25 | MainWindow::MainWindow(int aEventId, QWidget *aParent) |
---|
| 26 | : QMainWindow(aParent) |
---|
[e5bc908] | 27 | { |
---|
[9bbb44e] | 28 | setupUi(this); |
---|
[72f6fe4] | 29 | |
---|
[c2d66b2] | 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())); |
---|
| 34 | |
---|
[72f6fe4] | 35 | // create "SQLITE" DB instance/connection |
---|
| 36 | // opens DB connection (needed for EventModel) |
---|
| 37 | mSqlEngine = new SqlEngine(this); |
---|
| 38 | mSqlEngine->initialize(); |
---|
| 39 | |
---|
[4693fa6] | 40 | //update track map |
---|
| 41 | Track::updateTrackMap(); |
---|
[9208bdb] | 42 | |
---|
[969a840] | 43 | connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &))); |
---|
[4693fa6] | 44 | connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &))); |
---|
| 45 | connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &))); |
---|
[9d8946b] | 46 | connect(searchDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateSearchView(const QDate &))); |
---|
[5842349] | 47 | |
---|
[6f39595] | 48 | // DAY EVENTS View |
---|
| 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)); |
---|
| 55 | |
---|
| 56 | // FAVOURITIES View |
---|
| 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)); |
---|
[fbc1646] | 63 | |
---|
| 64 | //ACTIVITIES View |
---|
[4693fa6] | 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)); |
---|
[707cd31] | 71 | |
---|
[e662750] | 72 | // SEARCH EVENTS View |
---|
[990afd5] | 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)); |
---|
[9d8946b] | 79 | |
---|
[c53a3f4] | 80 | // event clicked |
---|
| 81 | connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); |
---|
| 82 | connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); |
---|
[4693fa6] | 83 | connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); |
---|
[30cd9b6] | 84 | connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); |
---|
[59c6cfe] | 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 &))); |
---|
[4693fa6] | 88 | connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); |
---|
[990afd5] | 89 | connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); |
---|
[3f3e22d] | 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 &))); |
---|
[990afd5] | 95 | // event search button clicked |
---|
| 96 | connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked())); |
---|
[fbc1646] | 97 | |
---|
[6f39595] | 98 | // TESTING: load some 'fav' data |
---|
| 99 | if(Conference::getAll().count()) // no conference(s) in the DB |
---|
| 100 | { |
---|
| 101 | static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId); |
---|
| 102 | favTreeView->reset(); |
---|
| 103 | } |
---|
[969a840] | 104 | |
---|
| 105 | if(!Conference::getAll().count()) // no conference(s) in the DB |
---|
[fbc1646] | 106 | { |
---|
[969a840] | 107 | dayNavigator->hide(); // hide DayNavigatorWidget |
---|
[4693fa6] | 108 | trackDayNavigator->hide(); |
---|
[fbc1646] | 109 | } |
---|
[969a840] | 110 | else |
---|
| 111 | { |
---|
[fbc1646] | 112 | QDate aStartDate = Conference::getById(confId).start(); |
---|
| 113 | QDate aEndDate = Conference::getById(confId).end(); |
---|
| 114 | dayNavigator->setDates(aStartDate, aEndDate); |
---|
[4693fa6] | 115 | trackDayNavigator->setDates(aStartDate, aEndDate); |
---|
[7f84a70] | 116 | favouriteDayNavigator->setDates(aStartDate, aEndDate); |
---|
[e662750] | 117 | searchDayNavigator->setDates(aStartDate, aEndDate); |
---|
[969a840] | 118 | } |
---|
[c5324ca] | 119 | |
---|
| 120 | connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int))); |
---|
| 121 | |
---|
[9d8946b] | 122 | searchTreeView->hide(); |
---|
| 123 | searchDayNavigator->hide(); |
---|
| 124 | |
---|
[d4a8bbf] | 125 | // open dialog for given Event ID |
---|
| 126 | // this is used in case Alarm Dialog request application to start |
---|
| 127 | if(aEventId) |
---|
| 128 | { |
---|
[95596f6] | 129 | try |
---|
| 130 | { |
---|
| 131 | EventDialog dialog(aEventId,this); |
---|
| 132 | dialog.exec(); |
---|
| 133 | } |
---|
[06570e9] | 134 | catch(OrmNoObjectException) {} // just start application |
---|
[95596f6] | 135 | catch(...) {} // just start application |
---|
[d4a8bbf] | 136 | } |
---|
[e5bc908] | 137 | } |
---|
[66327a0] | 138 | |
---|
[72f6fe4] | 139 | MainWindow::~MainWindow() |
---|
| 140 | { |
---|
| 141 | if(mSqlEngine) |
---|
| 142 | { |
---|
| 143 | delete mSqlEngine; |
---|
| 144 | mSqlEngine = NULL; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | void MainWindow::importSchedule() |
---|
| 149 | { |
---|
[e493054] | 150 | ImportScheduleDialog dialog(mSqlEngine,this); |
---|
| 151 | dialog.exec(); |
---|
| 152 | |
---|
[969a840] | 153 | if(Conference::getAll().count()) |
---|
| 154 | { |
---|
| 155 | // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates |
---|
[a35aa83] | 156 | QDate aStartDate = Conference::getById(confId).start(); |
---|
| 157 | QDate aEndDate = Conference::getById(confId).end(); |
---|
| 158 | dayNavigator->setDates(aStartDate, aEndDate); |
---|
[72cd3af] | 159 | //update activity map |
---|
| 160 | Track::updateTrackMap(); |
---|
[4693fa6] | 161 | trackDayNavigator->setDates(aStartDate, aEndDate); |
---|
[969a840] | 162 | } |
---|
[72f6fe4] | 163 | } |
---|
| 164 | |
---|
[c2d66b2] | 165 | void MainWindow::aboutApp() |
---|
| 166 | { |
---|
| 167 | QDialog dialog(this); |
---|
| 168 | Ui::AboutDialog ui; |
---|
| 169 | ui.setupUi(&dialog); |
---|
| 170 | dialog.exec(); |
---|
| 171 | } |
---|
| 172 | |
---|
[ec67a0b] | 173 | void MainWindow::updateDayView(const QDate &aDate) |
---|
[969a840] | 174 | { |
---|
[ec67a0b] | 175 | static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId); |
---|
[6f39595] | 176 | dayTreeView->reset(); |
---|
[969a840] | 177 | dayNavigator->show(); |
---|
| 178 | } |
---|
| 179 | |
---|
[ec67a0b] | 180 | void MainWindow::updateTab(const int aIndex) |
---|
[5842349] | 181 | { |
---|
[ec67a0b] | 182 | switch(aIndex) |
---|
[c5324ca] | 183 | { |
---|
[ec67a0b] | 184 | case 0://index 0 of tabWidget: dayViewTab |
---|
| 185 | { |
---|
[d8d5bd2] | 186 | updateDayView(dayNavigator->getCurrentDate()); |
---|
[ec67a0b] | 187 | } |
---|
| 188 | break; |
---|
| 189 | case 1: //index 1 of tabWidget: favouritesTab |
---|
| 190 | { |
---|
[d8d5bd2] | 191 | updateFavouritesView(favouriteDayNavigator->getCurrentDate()); |
---|
[7f84a70] | 192 | } |
---|
| 193 | break; |
---|
[72cd3af] | 194 | case 2: //index 2 of tabWidget: activitiesTab |
---|
[7f84a70] | 195 | { |
---|
[d8d5bd2] | 196 | updateTracksView(trackDayNavigator->getCurrentDate()); |
---|
[ec67a0b] | 197 | } |
---|
| 198 | break; |
---|
[9d8946b] | 199 | case 3: //index 3 of tabWidget: searchTab |
---|
| 200 | { |
---|
| 201 | updateSearchView( searchDayNavigator->getCurrentDate() ); |
---|
| 202 | } |
---|
| 203 | break; |
---|
[ec67a0b] | 204 | default: |
---|
| 205 | { |
---|
[7f84a70] | 206 | |
---|
[ec67a0b] | 207 | } |
---|
| 208 | }; |
---|
[7f84a70] | 209 | } |
---|
[f6300c7] | 210 | |
---|
[4693fa6] | 211 | void MainWindow::updateTracksView(const QDate &aDate) |
---|
[f6300c7] | 212 | { |
---|
[4693fa6] | 213 | static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, confId); |
---|
| 214 | trackTreeView->reset(); |
---|
| 215 | trackDayNavigator->show(); |
---|
[f6300c7] | 216 | } |
---|
[707cd31] | 217 | |
---|
[4693fa6] | 218 | void MainWindow::updateFavouritesView(const QDate &aDate) |
---|
[7f84a70] | 219 | { |
---|
| 220 | static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,confId); |
---|
| 221 | favTreeView->reset(); |
---|
| 222 | favouriteDayNavigator->show(); |
---|
| 223 | } |
---|
| 224 | |
---|
[9d8946b] | 225 | void MainWindow::updateSearchView(const QDate &aDate) |
---|
| 226 | { |
---|
| 227 | searchTreeView->reset(); |
---|
| 228 | int eventsCount = static_cast<EventModel*>(searchTreeView->model())->loadSearchResultEvents(aDate,confId); |
---|
| 229 | if( eventsCount ){ |
---|
| 230 | searchDayNavigator->show(); |
---|
| 231 | searchTreeView->show(); |
---|
| 232 | } |
---|
| 233 | else{ |
---|
| 234 | searchTreeView->hide(); |
---|
| 235 | searchDayNavigator->hide(); |
---|
| 236 | } |
---|
| 237 | } |
---|
| 238 | |
---|
[c53a3f4] | 239 | void MainWindow::itemClicked(const QModelIndex &aIndex) |
---|
[707cd31] | 240 | { |
---|
| 241 | // have to handle only events, not time-groups |
---|
| 242 | if(!aIndex.parent().isValid()) // time-group |
---|
| 243 | return; |
---|
| 244 | |
---|
[d4a8bbf] | 245 | EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this); |
---|
[707cd31] | 246 | dialog.exec(); |
---|
| 247 | } |
---|
| 248 | |
---|
[59c6cfe] | 249 | void MainWindow::displayMap(const QModelIndex &aIndex) |
---|
| 250 | { |
---|
[f9db452] | 251 | Event *event = static_cast<Event*>(aIndex.internalPointer()); |
---|
[9afc0ee] | 252 | |
---|
| 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(".")); |
---|
[b1fc17a] | 256 | if(!QFile::exists(mapPath)) |
---|
| 257 | mapPath = QString(":/maps/rooms/not-available.png"); |
---|
[9afc0ee] | 258 | |
---|
| 259 | QString roomName; |
---|
| 260 | if(mapPath.contains("not-available", Qt::CaseInsensitive)) |
---|
| 261 | roomName = QString("Map is not available: %1").arg(event->room()); |
---|
| 262 | else |
---|
| 263 | roomName = event->room(); |
---|
| 264 | |
---|
[f9db452] | 265 | QPixmap map(mapPath); |
---|
[9afc0ee] | 266 | MapWindow window(map,roomName,this); |
---|
[59c6cfe] | 267 | window.exec(); |
---|
| 268 | } |
---|
[990afd5] | 269 | |
---|
| 270 | void MainWindow::searchClicked() |
---|
| 271 | { |
---|
| 272 | QList<QString> columns; |
---|
| 273 | |
---|
| 274 | if( searchTitle->isChecked() ) |
---|
| 275 | columns.append( "title" ); |
---|
| 276 | if( searchAbstract->isChecked() ) |
---|
| 277 | columns.append( "abstract" ); |
---|
| 278 | |
---|
[9d8946b] | 279 | mSqlEngine->searchEvent( confId, columns, searchEdit->text() ); |
---|
| 280 | updateSearchView( Conference::getById(confId).start() ); |
---|
[990afd5] | 281 | } |
---|
| 282 | |
---|
[3f3e22d] | 283 | void MainWindow::displayWarning(const QModelIndex &aIndex) |
---|
| 284 | { |
---|
| 285 | QMessageBox::warning( |
---|
| 286 | this, |
---|
| 287 | tr("Time Conflict Warning"), |
---|
| 288 | tr("This event happens at the same time than another one of your favourites.") ); |
---|
| 289 | } |
---|