1 #include "mainwindow.h"
7 #include <schedulexmlparser.h>
9 #include <eventmodel.h>
12 #include <conference.h>
16 #include "daynavigatorwidget.h"
18 MainWindow::MainWindow(QWidget *parent)
23 // connect Menu actions
24 connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
25 connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
26 connect(actionAboutApplication, SIGNAL(triggered()), SLOT(aboutApp()));
28 // create "SQLITE" DB instance/connection
29 // opens DB connection (needed for EventModel)
30 mSqlEngine = new SqlEngine(this);
31 mSqlEngine->initialize();
33 mXmlParser = new ScheduleXmlParser(this);
34 connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
35 statusBar()->showMessage(tr("Ready"));
37 connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
40 dayTreeView->setHeaderHidden(true);
41 dayTreeView->setRootIsDecorated(false);
42 dayTreeView->setIndentation(0);
43 dayTreeView->setAnimated(true);
44 dayTreeView->setModel(new EventModel());
45 dayTreeView->setItemDelegate(new Delegate(dayTreeView));
48 favTreeView->setHeaderHidden(true);
49 favTreeView->setRootIsDecorated(false);
50 favTreeView->setIndentation(0);
51 favTreeView->setAnimated(true);
52 favTreeView->setModel(new EventModel());
53 favTreeView->setItemDelegate(new Delegate(favTreeView));
54 // TESTING: load some 'fav' data
55 if(Conference::getAll().count()) // no conference(s) in the DB
58 static_cast<EventModel*>(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId);
62 if(!Conference::getAll().count()) // no conference(s) in the DB
63 dayNavigator->hide(); // hide DayNavigatorWidget
67 dayNavigator->setDates(Conference::getById(confId).start(),Conference::getById(confId).end());
71 MainWindow::~MainWindow()
85 void MainWindow::importSchedule()
87 QFile file("../schedule.en.xml");
88 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
90 QString currPath = QDir::currentPath();
91 qDebug() << "current path: " << currPath;
92 qDebug() << "can't open " << file.fileName();
96 QByteArray data = file.readAll();
97 mXmlParser->parseData(data,mSqlEngine);
99 if(Conference::getAll().count())
102 // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
103 dayNavigator->setDates(Conference::getById(confId).start(),Conference::getById(confId).end());
107 void MainWindow::showParsingProgress(int aStatus)
109 QString msg = QString("Parsing completed: %1\%").arg(aStatus);
110 statusBar()->showMessage(msg,1000);
113 void MainWindow::aboutApp()
115 QDialog dialog(this);
121 void MainWindow::updateDayView(const QDate &aDate)
124 static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,confId);
125 dayTreeView->reset();
126 dayNavigator->show();