1 #include "mainwindow.h"
7 #include <schedulexmlparser.h>
9 #include <eventmodel.h>
12 #include <conference.h>
16 #include "eventdialog.h"
17 #include "daynavigatorwidget.h"
18 #include "mapwindow.h"
20 MainWindow::MainWindow(QWidget *parent)
25 // connect Menu actions
26 connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
27 connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
28 connect(actionAboutApplication, SIGNAL(triggered()), SLOT(aboutApp()));
30 // create "SQLITE" DB instance/connection
31 // opens DB connection (needed for EventModel)
32 mSqlEngine = new SqlEngine(this);
33 mSqlEngine->initialize();
35 mXmlParser = new ScheduleXmlParser(this);
36 connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
37 statusBar()->showMessage(tr("Ready"));
39 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
40 connect(activityDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateActivitiesDayView(const QDate &)));
41 connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesDayView(const QDate &)));
44 dayTreeView->setHeaderHidden(true);
45 dayTreeView->setRootIsDecorated(false);
46 dayTreeView->setIndentation(0);
47 dayTreeView->setAnimated(true);
48 dayTreeView->setModel(new EventModel());
49 dayTreeView->setItemDelegate(new Delegate(dayTreeView));
52 favTreeView->setHeaderHidden(true);
53 favTreeView->setRootIsDecorated(false);
54 favTreeView->setIndentation(0);
55 favTreeView->setAnimated(true);
56 favTreeView->setModel(new EventModel());
57 favTreeView->setItemDelegate(new Delegate(favTreeView));
60 actTreeView->setHeaderHidden(true);
61 actTreeView->setRootIsDecorated(false);
62 actTreeView->setIndentation(0);
63 actTreeView->setAnimated(true);
64 actTreeView->setModel(new EventModel());
65 actTreeView->setItemDelegate(new Delegate(actTreeView));
67 // event double clicked
68 connect(dayTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
69 connect(favTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
70 connect(actTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
71 // request for map to be displayed
72 connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
73 connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
74 connect(actTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
77 // TESTING: load some 'fav' data
78 if(Conference::getAll().count()) // no conference(s) in the DB
81 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
85 if(!Conference::getAll().count()) // no conference(s) in the DB
87 dayNavigator->hide(); // hide DayNavigatorWidget
88 activityDayNavigator->hide();
93 QDate aStartDate = Conference::getById(confId).start();
94 QDate aEndDate = Conference::getById(confId).end();
95 dayNavigator->setDates(aStartDate, aEndDate);
96 activityDayNavigator->setDates(aStartDate, aEndDate);
97 favouriteDayNavigator->setDates(aStartDate, aEndDate);
100 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
104 MainWindow::~MainWindow()
118 void MainWindow::importSchedule()
120 QFile file(":/schedule.en.xml");
121 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
123 qDebug() << "can't open " << file.fileName();
127 QByteArray data = file.readAll();
128 mXmlParser->parseData(data,mSqlEngine);
130 if(Conference::getAll().count())
133 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
134 QDate aStartDate = Conference::getById(confId).start();
135 QDate aEndDate = Conference::getById(confId).end();
136 dayNavigator->setDates(aStartDate, aEndDate);
137 activityDayNavigator->setDates(aStartDate, aEndDate);
141 void MainWindow::showParsingProgress(int aStatus)
143 QString msg = QString("Parsing completed: %1\%").arg(aStatus);
144 statusBar()->showMessage(msg,1000);
147 void MainWindow::aboutApp()
149 QDialog dialog(this);
155 void MainWindow::updateDayView(const QDate &aDate)
158 static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
159 dayTreeView->reset();
160 dayNavigator->show();
163 void MainWindow::updateTab(const int aIndex)
168 case 0://index 0 of tabWidget: dayViewTab
170 static_cast<EventModel*>(dayTreeView->model())->loadEvents(Conference::getById(confId).start(),confId);
171 dayTreeView->reset();
172 dayNavigator->show();
175 case 1: //index 1 of tabWidget: favouritesTab
177 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
178 favTreeView->reset();
179 favouriteDayNavigator->show();
182 case 2: //index 2 of tabWidget: activitiesTab
184 static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(Conference::getById(confId).start(),confId);
185 actTreeView->reset();
186 activityDayNavigator->show();
198 void MainWindow::updateActivitiesDayView(const QDate &aDate)
201 static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate,confId);
202 actTreeView->reset();
203 activityDayNavigator->show();
206 void MainWindow::updateFavouritesDayView(const QDate &aDate)
209 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,confId);
210 favTreeView->reset();
211 favouriteDayNavigator->show();
214 void MainWindow::itemDoubleClicked(const QModelIndex &aIndex)
216 // have to handle only events, not time-groups
217 if(!aIndex.parent().isValid()) // time-group
220 EventDialog dialog(aIndex,this);
224 void MainWindow::displayMap(const QModelIndex &aIndex)
226 Event *event = static_cast<Event*>(aIndex.internalPointer());
228 // room names are stored in lower-case format
229 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
230 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
231 if(!QFile::exists(mapPath))
232 mapPath = QString(":/maps/rooms/not-available.png");
235 if(mapPath.contains("not-available", Qt::CaseInsensitive))
236 roomName = QString("Map is not available: %1").arg(event->room());
238 roomName = event->room();
240 QPixmap map(mapPath);
241 MapWindow window(map,roomName,this);