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(int aEventId, QWidget *aParent)
24 : QMainWindow(aParent)
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 searchTreeView->setHeaderHidden(true);
75 searchTreeView->setRootIsDecorated(false);
76 searchTreeView->setIndentation(0);
77 searchTreeView->setAnimated(true);
78 searchTreeView->setModel(new EventModel());
79 searchTreeView->setItemDelegate(new Delegate(searchTreeView));
80 searchTreeView->setVisible(false);
81 searchDayNavigator->setVisible(false);
83 connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
84 connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
85 connect(actTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
86 connect(searchTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &)));
87 // request for map to be displayed
88 connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
89 connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
90 connect(actTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
91 connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
92 // event search button clicked
93 connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
95 // TESTING: load some 'fav' data
96 if(Conference::getAll().count()) // no conference(s) in the DB
98 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
102 if(!Conference::getAll().count()) // no conference(s) in the DB
104 dayNavigator->hide(); // hide DayNavigatorWidget
105 activityDayNavigator->hide();
109 QDate aStartDate = Conference::getById(confId).start();
110 QDate aEndDate = Conference::getById(confId).end();
111 dayNavigator->setDates(aStartDate, aEndDate);
112 activityDayNavigator->setDates(aStartDate, aEndDate);
113 favouriteDayNavigator->setDates(aStartDate, aEndDate);
116 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTab(int)));
118 // open dialog for given Event ID
119 // this is used in case Alarm Dialog request application to start
122 EventDialog dialog(aEventId,this);
127 MainWindow::~MainWindow()
141 void MainWindow::importSchedule()
143 QFile file(":/schedule.en.xml");
144 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
146 qDebug() << "can't open " << file.fileName();
150 QByteArray data = file.readAll();
151 mXmlParser->parseData(data,mSqlEngine);
153 if(Conference::getAll().count())
155 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
156 QDate aStartDate = Conference::getById(confId).start();
157 QDate aEndDate = Conference::getById(confId).end();
158 dayNavigator->setDates(aStartDate, aEndDate);
159 activityDayNavigator->setDates(aStartDate, aEndDate);
161 //update activity map
162 Activity::updateActivityMap();
165 void MainWindow::showParsingProgress(int aStatus)
167 QString msg = QString("Parsing completed: %1\%").arg(aStatus);
168 statusBar()->showMessage(msg,1000);
171 void MainWindow::aboutApp()
173 QDialog dialog(this);
179 void MainWindow::updateDayView(const QDate &aDate)
181 static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
182 dayTreeView->reset();
183 dayNavigator->show();
186 void MainWindow::updateTab(const int aIndex)
190 case 0://index 0 of tabWidget: dayViewTab
192 static_cast<EventModel*>(dayTreeView->model())->loadEvents(Conference::getById(confId).start(),confId);
193 dayTreeView->reset();
194 dayNavigator->show();
197 case 1: //index 1 of tabWidget: favouritesTab
199 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
200 favTreeView->reset();
201 favouriteDayNavigator->show();
204 case 2: //index 2 of tabWidget: activitiesTab
206 static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(Conference::getById(confId).start(), confId);
207 actTreeView->reset();
208 activityDayNavigator->show();
218 void MainWindow::updateActivitiesDayView(const QDate &aDate)
220 static_cast<EventModel*>(actTreeView->model())->loadEventsByActivities(aDate, confId);
221 actTreeView->reset();
222 activityDayNavigator->show();
225 void MainWindow::updateFavouritesDayView(const QDate &aDate)
227 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,confId);
228 favTreeView->reset();
229 favouriteDayNavigator->show();
232 void MainWindow::itemClicked(const QModelIndex &aIndex)
234 // have to handle only events, not time-groups
235 if(!aIndex.parent().isValid()) // time-group
238 EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
242 void MainWindow::displayMap(const QModelIndex &aIndex)
244 Event *event = static_cast<Event*>(aIndex.internalPointer());
246 // room names are stored in lower-case format
247 // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
248 QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
249 if(!QFile::exists(mapPath))
250 mapPath = QString(":/maps/rooms/not-available.png");
253 if(mapPath.contains("not-available", Qt::CaseInsensitive))
254 roomName = QString("Map is not available: %1").arg(event->room());
256 roomName = event->room();
258 QPixmap map(mapPath);
259 MapWindow window(map,roomName,this);
263 void MainWindow::searchClicked()
265 QList<QString> columns;
267 if( searchTitle->isChecked() )
268 columns.append( "title" );
269 if( searchAbstract->isChecked() )
270 columns.append( "abstract" );
272 if( mSqlEngine->searchEvent( confId, columns, searchEdit->text() ) > 0 ){
273 searchTreeView->setVisible(true);
274 searchDayNavigator->setVisible(true);