implemented importing the schedule from the Internet
authorpavelpa <pavelpa@localhost>
Fri, 29 Jan 2010 12:15:40 +0000 (12:15 +0000)
committerpavelpa <pavelpa@localhost>
Fri, 29 Jan 2010 12:15:40 +0000 (12:15 +0000)
 - usded url: http://fosdem.org/2010/schedule/xml
 - todo: hard-coded PROXY has to be fixed (add proxy settings dialog)

src/app/app.pro
src/gui/gui.pro
src/gui/importschedulewidget.cpp
src/gui/importschedulewidget.h
src/gui/mainwindow.cpp

index 35d9169..ab788f7 100644 (file)
@@ -2,7 +2,7 @@ include(../global.pri)
 TEMPLATE = app
 TARGET = fosdem-schedule
 DESTDIR = ../bin
-QT += sql xml
+QT += sql xml network
 
 # module dependencies
 LIBS += -L$$DESTDIR -lgui -lmvc -lsql
index ae85249..5d4cfc7 100644 (file)
@@ -4,7 +4,8 @@ TARGET = gui
 DESTDIR = ../bin
 CONFIG += static
 QT += sql \
-    xml
+    xml \
+    network
 
 # module dependencies
 LIBS += -L$$DESTDIR \
index 4ff87d8..379aa67 100644 (file)
@@ -5,8 +5,13 @@
 #include <QDir>
 #include <QFile>
 #include <QFileDialog>
+#include <QNetworkProxy>
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
 #include <QDebug>
 
+const QString SCHEDULE_URL = "http://fosdem.org/2010/schedule/xml";
+
 ImportScheduleWidget::ImportScheduleWidget(QWidget *aParent)
     : QWidget(aParent)
 {
@@ -20,8 +25,12 @@ ImportScheduleWidget::ImportScheduleWidget(QWidget *aParent)
     progressBar->hide();
 
     cancel->hide();
-    online->hide();
     importAction->hide();
+    connect(online, SIGNAL(clicked()), SLOT(downloadSchedule()));
+
+    mNetworkAccessManager = new QNetworkAccessManager(this);
+    connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkQueryFinished(QNetworkReply*)));
+    mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
 }
 
 ImportScheduleWidget::~ImportScheduleWidget()
@@ -31,6 +40,11 @@ ImportScheduleWidget::~ImportScheduleWidget()
         delete mXmlParser;
         mXmlParser = NULL;
     }
+    if(mNetworkAccessManager)
+    {
+        delete mNetworkAccessManager;
+        mNetworkAccessManager = NULL;
+    }
 }
 
 void ImportScheduleWidget::parsingSchedule(const QString &aTitle)
@@ -55,20 +69,51 @@ void ImportScheduleWidget::browseSchedule()
             return;
         }
 
-        QByteArray data = file.readAll();
-        browse->hide();
-        progressBar->show();
-        int confId = mXmlParser->parseData(data);
+        importData(file.readAll());
 
+    }
+    else
+    {
         progressBar->hide();
-        browse->show();
-        importScheduleLabel->setText("Import schedule: ");
+    }
+}
 
-        emit(scheduleImported(confId));
+void ImportScheduleWidget::networkQueryFinished(QNetworkReply *aReply)
+{
+    qDebug() << "ImportScheduleWidget::networkQueryFinished()";
+
+    if ( aReply->error() != QNetworkReply::NoError )
+    {
+        qDebug() << "Error occured during download: " << aReply->errorString();
     }
     else
     {
-        progressBar->hide();
+        importData(aReply->readAll());
     }
 }
 
+void ImportScheduleWidget::downloadSchedule()
+{
+    qDebug() << "downloading schedule";
+
+    QNetworkRequest request;
+    request.setUrl(QUrl(SCHEDULE_URL));
+    mNetworkAccessManager->get(request);
+}
+
+void ImportScheduleWidget::importData(const QByteArray &aData)
+{
+    browse->hide();
+    online->hide();
+    progressBar->show();
+
+    int confId = mXmlParser->parseData(aData);
+
+    progressBar->hide();
+    browse->show();
+    online->show();
+    importScheduleLabel->setText("Import schedule: ");
+
+    emit(scheduleImported(confId));
+}
+
index 26abd8d..302dc06 100644 (file)
@@ -5,6 +5,8 @@
 #include "ui_importschedulewidget.h"
 
 class ScheduleXmlParser;
+class QNetworkAccessManager;
+class QNetworkReply;
 
 class ImportScheduleWidget : public QWidget, Ui::ImportScheduleWidget
 {
@@ -16,10 +18,15 @@ class ImportScheduleWidget : public QWidget, Ui::ImportScheduleWidget
         void browseSchedule();
         void parsingSchedule(const QString &aTitle);
         void showParsingProgress(int progress);
+        void networkQueryFinished(QNetworkReply *aReply);
+        void downloadSchedule();
     signals:
         void scheduleImported(int confId);
+    private:
+        void importData(const QByteArray &aData);
     private:
         ScheduleXmlParser *mXmlParser;
+        QNetworkAccessManager *mNetworkAccessManager;
 };
 
 #endif /* IMPORTSCHEDULEWIDGET_H */
index 8b650cc..71440db 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <QTreeView>
 #include <QFile>
+#include <QNetworkProxy>
 
 #include <sqlengine.h>
 
 
 #include <tabcontainer.h>
 
+const QString PROXY_URL("192.168.0.252");
+const quint16 PROXY_PORT = 4040;
+const QString PROXY_USERNAME;
+const QString PROXY_PASSWD;
+const bool DIRECT_CONNECTION = false;
+
 MainWindow::MainWindow(int aEventId, QWidget *aParent)
     : QMainWindow(aParent)
 {
     setupUi(this);
 
+    qDebug() << "Setting-up proxy: " << PROXY_URL << ":" << PROXY_PORT;
+    QNetworkProxy proxy(DIRECT_CONNECTION ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
+            PROXY_URL, PROXY_PORT, PROXY_USERNAME, PROXY_PASSWD);
+    QNetworkProxy::setApplicationProxy(proxy);
+
     int confId = Conference::activeConference();
 
     connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));