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 &)));
43 dayTreeView->setHeaderHidden(true);
44 dayTreeView->setRootIsDecorated(false);
45 dayTreeView->setIndentation(0);
46 dayTreeView->setAnimated(true);
47 dayTreeView->setModel(new EventModel());
48 dayTreeView->setItemDelegate(new Delegate(dayTreeView));
51 favTreeView->setHeaderHidden(true);
52 favTreeView->setRootIsDecorated(false);
53 favTreeView->setIndentation(0);
54 favTreeView->setAnimated(true);
55 favTreeView->setModel(new EventModel());
56 favTreeView->setItemDelegate(new Delegate(favTreeView));
59 actTreeView->setHeaderHidden(true);
60 actTreeView->setRootIsDecorated(false);
61 actTreeView->setIndentation(0);
62 actTreeView->setAnimated(true);
63 actTreeView->setModel(new EventModel());
64 actTreeView->setItemDelegate(new Delegate(actTreeView));
66 // event double clicked
67 connect(dayTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
68 connect(favTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
69 connect(actTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
70 // request for map to be displayed
71 connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
72 connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
73 connect(actTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
76 // TESTING: load some 'fav' data
77 if(Conference::getAll().count()) // no conference(s) in the DB
80 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
84 if(!Conference::getAll().count()) // no conference(s) in the DB
86 dayNavigator->hide(); // hide DayNavigatorWidget
87 activityDayNavigator->hide();
92 QDate aStartDate = Conference::getById(confId).start();
93 QDate aEndDate = Conference::getById(confId).end();
94 dayNavigator->setDates(aStartDate, aEndDate);
95 activityDayNavigator->setDates(aStartDate, aEndDate);
98 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
102 MainWindow::~MainWindow()
116 void MainWindow::importSchedule()
118 QFile file("../schedule.en.xml");
119 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
121 qDebug() << "can't open " << file.fileName();
125 QByteArray data = file.readAll();
126 mXmlParser->parseData(data,mSqlEngine);
128 if(Conference::getAll().count())
131 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
132 QDate aStartDate = Conference::getById(confId).start();
133 QDate aEndDate = Conference::getById(confId).end();
134 dayNavigator->setDates(aStartDate, aEndDate);
135 activityDayNavigator->setDates(aStartDate, aEndDate);
139 void MainWindow::showParsingProgress(int aStatus)
141 QString msg = QString("Parsing completed: %1\%").arg(aStatus);
142 statusBar()->showMessage(msg,1000);
145 void MainWindow::aboutApp()
147 QDialog dialog(this);
153 void MainWindow::updateDayView(const QDate aDate)
156 static_cast<EventModel*>(dayTreeView->model())->loadEvents(Conference::getById(confId).start(),confId);
157 dayTreeView->reset();
158 dayNavigator->show();
161 void MainWindow::updateTab(const int n)
164 if(n) //index 1 of tabWidget: favouriteTab
166 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
167 favTreeView->reset();
169 else //index 0 of tabWidget: dayViewTab
171 static_cast<EventModel*>(dayTreeView->model())->loadEvents(Conference::getById(confId).start(),confId);
172 dayTreeView->reset();
174 //TODO: update of activitiesTab needed?
175 dayNavigator->show();
179 void MainWindow::updateActivitiesDayView(const QDate &aDate)
182 static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate,confId);
183 actTreeView->reset();
184 activityDayNavigator->show();
187 void MainWindow::itemDoubleClicked(const QModelIndex &aIndex)
189 // have to handle only events, not time-groups
190 if(!aIndex.parent().isValid()) // time-group
193 EventDialog dialog(aIndex,this);
197 void MainWindow::displayMap(const QModelIndex &aIndex)
199 Event *event = static_cast<Event*>(aIndex.internalPointer());
201 // room names are stored in lower-case format
202 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
203 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
204 if(!QFile::exists(mapPath))
205 mapPath = QString(":/maps/rooms/not-available.png");
208 if(mapPath.contains("not-available", Qt::CaseInsensitive))
209 roomName = QString("Map is not available: %1").arg(event->room());
211 roomName = event->room();
213 QPixmap map(mapPath);
214 MapWindow window(map,roomName,this);