1 #include "mainwindow.h"
7 #include <schedulexmlparser.h>
10 #include <eventmodel.h>
13 #include <conference.h>
17 #include "eventdialog.h"
18 #include "daynavigatorwidget.h"
19 #include "mapwindow.h"
23 MainWindow::MainWindow(QWidget *parent)
28 // connect Menu actions
29 connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
30 connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
31 connect(actionAboutApplication, SIGNAL(triggered()), SLOT(aboutApp()));
33 // create "SQLITE" DB instance/connection
34 // opens DB connection (needed for EventModel)
35 mSqlEngine = new SqlEngine(this);
36 mSqlEngine->initialize();
38 mXmlParser = new ScheduleXmlParser(this);
39 connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
40 statusBar()->showMessage(tr("Ready"));
43 Activity::updateActivityMap();
45 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
46 connect(activityDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateActivitiesDayView(const QDate &)));
47 connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesDayView(const QDate &)));
50 dayTreeView->setHeaderHidden(true);
51 dayTreeView->setRootIsDecorated(false);
52 dayTreeView->setIndentation(0);
53 dayTreeView->setAnimated(true);
54 dayTreeView->setModel(new EventModel());
55 dayTreeView->setItemDelegate(new Delegate(dayTreeView));
58 favTreeView->setHeaderHidden(true);
59 favTreeView->setRootIsDecorated(false);
60 favTreeView->setIndentation(0);
61 favTreeView->setAnimated(true);
62 favTreeView->setModel(new EventModel());
63 favTreeView->setItemDelegate(new Delegate(favTreeView));
66 actTreeView->setHeaderHidden(true);
67 actTreeView->setRootIsDecorated(false);
68 actTreeView->setIndentation(0);
69 actTreeView->setAnimated(true);
70 actTreeView->setModel(new EventModel());
71 actTreeView->setItemDelegate(new Delegate(actTreeView));
74 connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
75 connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
76 connect(actTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
77 // request for map to be displayed
78 connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
79 connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
80 connect(actTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
83 // TESTING: load some 'fav' data
84 if(Conference::getAll().count()) // no conference(s) in the DB
86 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
90 if(!Conference::getAll().count()) // no conference(s) in the DB
92 dayNavigator->hide(); // hide DayNavigatorWidget
93 activityDayNavigator->hide();
97 QDate aStartDate = Conference::getById(confId).start();
98 QDate aEndDate = Conference::getById(confId).end();
99 dayNavigator->setDates(aStartDate, aEndDate);
100 activityDayNavigator->setDates(aStartDate, aEndDate);
101 favouriteDayNavigator->setDates(aStartDate, aEndDate);
104 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
108 MainWindow::~MainWindow()
122 void MainWindow::importSchedule()
124 QFile file(":/schedule.en.xml");
125 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
127 qDebug() << "can't open " << file.fileName();
131 QByteArray data = file.readAll();
132 mXmlParser->parseData(data,mSqlEngine);
134 if(Conference::getAll().count())
136 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
137 QDate aStartDate = Conference::getById(confId).start();
138 QDate aEndDate = Conference::getById(confId).end();
139 dayNavigator->setDates(aStartDate, aEndDate);
140 activityDayNavigator->setDates(aStartDate, aEndDate);
142 //update activity map
143 Activity::updateActivityMap();
146 void MainWindow::showParsingProgress(int aStatus)
148 QString msg = QString("Parsing completed: %1\%").arg(aStatus);
149 statusBar()->showMessage(msg,1000);
152 void MainWindow::aboutApp()
154 QDialog dialog(this);
160 void MainWindow::updateDayView(const QDate &aDate)
162 static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
163 dayTreeView->reset();
164 dayNavigator->show();
167 void MainWindow::updateTab(const int aIndex)
171 case 0://index 0 of tabWidget: dayViewTab
173 static_cast<EventModel*>(dayTreeView->model())->loadEvents(Conference::getById(confId).start(),confId);
174 dayTreeView->reset();
175 dayNavigator->show();
178 case 1: //index 1 of tabWidget: favouritesTab
180 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
181 favTreeView->reset();
182 favouriteDayNavigator->show();
185 case 2: //index 2 of tabWidget: activitiesTab
187 static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(Conference::getById(confId).start(), confId);
188 actTreeView->reset();
189 activityDayNavigator->show();
199 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)
208 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,confId);
209 favTreeView->reset();
210 favouriteDayNavigator->show();
213 void MainWindow::itemClicked(const QModelIndex &aIndex)
215 // have to handle only events, not time-groups
216 if(!aIndex.parent().isValid()) // time-group
219 EventDialog dialog(aIndex,this);
223 void MainWindow::displayMap(const QModelIndex &aIndex)
225 Event *event = static_cast<Event*>(aIndex.internalPointer());
227 // room names are stored in lower-case format
228 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
229 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
230 if(!QFile::exists(mapPath))
231 mapPath = QString(":/maps/rooms/not-available.png");
234 if(mapPath.contains("not-available", Qt::CaseInsensitive))
235 roomName = QString("Map is not available: %1").arg(event->room());
237 roomName = event->room();
239 QPixmap map(mapPath);
240 MapWindow window(map,roomName,this);