implemented xml parser
[toast/confclerk.git] / src / gui / mainwindow.cpp
index b2f091c277b5ad7cf03cc9b2b870568a03002c8a..c8ce6f59833b48f1bbfdaab3e7d205f9325ed979 100644 (file)
@@ -3,19 +3,29 @@
 #include <QTreeView>
 #include <QDirModel>
 
+#include <sqlengine.h>
+#include <schedulexmlparser.h>
+
 #include <eventmodel.h>
 #include <delegate.h>
 
+
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
 {
-    // open database connection
-    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
-    db.setDatabaseName("fosdem-test.sqlite");
-    db.open();
-
     setupUi(this);
-    //TODO Palo: continue
+
+    // create "SQLITE" DB instance/connection
+    // opens DB connection (needed for EventModel)
+    mSqlEngine = new SqlEngine(this);
+    mSqlEngine->initialize();
+
+    mXmlParser = new ScheduleXmlParser(this);
+    connect(mXmlParser, SIGNAL(progressStatus(int)), this, SLOT(showParsingProgress(int)));
+    statusBar()->showMessage(tr("Ready"));
+
+    connect(actionImportSchedule, SIGNAL(triggered()), SLOT(importSchedule()));
+
     treeView->setHeaderHidden(true);
     treeView->setRootIsDecorated(false);
     treeView->setIndentation(0);
@@ -24,3 +34,38 @@ MainWindow::MainWindow(QWidget *parent)
     treeView->setItemDelegate(new Delegate(treeView));
 }
 
+MainWindow::~MainWindow()
+{
+    if(mSqlEngine)
+    {
+        delete mSqlEngine;
+        mSqlEngine = NULL;
+    }
+    if(mXmlParser)
+    {
+        delete mXmlParser;
+        mXmlParser = NULL;
+    }
+}
+
+void MainWindow::importSchedule()
+{
+    QFile file("../schedule.en.xml");
+    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+    {
+        qDebug() << "can't open " << file.fileName();
+        return;
+    }
+
+    QByteArray data = file.readAll();
+    mXmlParser->parseData(data,mSqlEngine);
+    static_cast<EventModel*>(treeView->model())->reload();
+    treeView->reset();
+}
+
+void MainWindow::showParsingProgress(int aStatus)
+{
+    QString msg = QString("Parsing completed: %1\%").arg(aStatus);
+    statusBar()->showMessage(msg,1000);
+}
+