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"
22 MainWindow::MainWindow(QWidget *parent)
27 // connect Menu actions
28 connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
29 connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
30 connect(actionAboutApplication, SIGNAL(triggered()), SLOT(aboutApp()));
32 // create "SQLITE" DB instance/connection
33 // opens DB connection (needed for EventModel)
34 mSqlEngine = new SqlEngine(this);
35 mSqlEngine->initialize();
37 mXmlParser = new ScheduleXmlParser(this);
38 connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
39 statusBar()->showMessage(tr("Ready"));
41 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
42 connect(activityDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateActivitiesDayView(const QDate &)));
43 connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesDayView(const QDate &)));
46 dayTreeView->setHeaderHidden(true);
47 dayTreeView->setRootIsDecorated(false);
48 dayTreeView->setIndentation(0);
49 dayTreeView->setAnimated(true);
50 dayTreeView->setModel(new EventModel());
51 dayTreeView->setItemDelegate(new Delegate(dayTreeView));
54 favTreeView->setHeaderHidden(true);
55 favTreeView->setRootIsDecorated(false);
56 favTreeView->setIndentation(0);
57 favTreeView->setAnimated(true);
58 favTreeView->setModel(new EventModel());
59 favTreeView->setItemDelegate(new Delegate(favTreeView));
62 actTreeView->setHeaderHidden(true);
63 actTreeView->setRootIsDecorated(false);
64 actTreeView->setIndentation(0);
65 actTreeView->setAnimated(true);
66 actTreeView->setModel(new EventModel());
67 actTreeView->setItemDelegate(new Delegate(actTreeView));
70 connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
71 connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
72 connect(actTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
73 // request for map to be displayed
74 connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
75 connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
76 connect(actTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
79 // TESTING: load some 'fav' data
80 if(Conference::getAll().count()) // no conference(s) in the DB
82 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
86 if(!Conference::getAll().count()) // no conference(s) in the DB
88 dayNavigator->hide(); // hide DayNavigatorWidget
89 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())
132 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
133 QDate aStartDate = Conference::getById(confId).start();
134 QDate aEndDate = Conference::getById(confId).end();
135 dayNavigator->setDates(aStartDate, aEndDate);
136 activityDayNavigator->setDates(aStartDate, aEndDate);
140 void MainWindow::showParsingProgress(int aStatus)
142 QString msg = QString("Parsing completed: %1\%").arg(aStatus);
143 statusBar()->showMessage(msg,1000);
146 void MainWindow::aboutApp()
148 QDialog dialog(this);
154 void MainWindow::updateDayView(const QDate &aDate)
156 static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
157 dayTreeView->reset();
158 dayNavigator->show();
161 void MainWindow::updateTab(const int aIndex)
165 case 0://index 0 of tabWidget: dayViewTab
167 static_cast<EventModel*>(dayTreeView->model())->loadEvents(Conference::getById(confId).start(),confId);
168 dayTreeView->reset();
169 dayNavigator->show();
172 case 1: //index 1 of tabWidget: favouritesTab
174 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
175 favTreeView->reset();
176 favouriteDayNavigator->show();
179 case 2: //index 2 of tabWidget: activitiesTab
181 static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(Conference::getById(confId).start(),confId);
182 actTreeView->reset();
183 activityDayNavigator->show();
193 void MainWindow::updateActivitiesDayView(const QDate &aDate)
195 static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate,confId);
196 actTreeView->reset();
197 activityDayNavigator->show();
200 void MainWindow::updateFavouritesDayView(const QDate &aDate)
202 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,confId);
203 favTreeView->reset();
204 favouriteDayNavigator->show();
207 void MainWindow::itemClicked(const QModelIndex &aIndex)
209 // have to handle only events, not time-groups
210 if(!aIndex.parent().isValid()) // time-group
213 EventDialog dialog(aIndex,this);
217 void MainWindow::displayMap(const QModelIndex &aIndex)
219 Event *event = static_cast<Event*>(aIndex.internalPointer());
221 // room names are stored in lower-case format
222 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
223 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
224 if(!QFile::exists(mapPath))
225 mapPath = QString(":/maps/rooms/not-available.png");
228 if(mapPath.contains("not-available", Qt::CaseInsensitive))
229 roomName = QString("Map is not available: %1").arg(event->room());
231 roomName = event->room();
233 QPixmap map(mapPath);
234 MapWindow window(map,roomName,this);