2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of fosdem-schedule.
6 * fosdem-schedule is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
11 * fosdem-schedule is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>.
19 #include "importschedulewidget.h"
21 #include <schedulexmlparser.h>
22 #include "proxysettingsdialog.h"
26 #include <QFileDialog>
27 #include <QNetworkProxy>
28 #include <QNetworkAccessManager>
29 #include <QNetworkReply>
31 #include <appsettings.h>
33 const QString SCHEDULE_URL = "http://fosdem.org/2010/schedule/xml";
35 const QString PROXY_USERNAME;
36 const QString PROXY_PASSWD;
38 ImportScheduleWidget::ImportScheduleWidget(QWidget *aParent)
43 mXmlParser = new ScheduleXmlParser(this);
44 connect(mXmlParser, SIGNAL(progressStatus(int)), SLOT(showParsingProgress(int)));
45 connect(mXmlParser, SIGNAL(parsingSchedule(const QString &)), SLOT(parsingSchedule(const QString &)));
47 connect(browse, SIGNAL(clicked()), SLOT(browseSchedule()));
52 connect(online, SIGNAL(clicked()), SLOT(downloadSchedule()));
54 connect(proxySettings, SIGNAL(clicked()), SLOT(setupProxy()));
55 mNetworkAccessManager = new QNetworkAccessManager(this);
56 connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkQueryFinished(QNetworkReply*)));
57 mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
60 ImportScheduleWidget::~ImportScheduleWidget()
67 if(mNetworkAccessManager)
69 delete mNetworkAccessManager;
70 mNetworkAccessManager = NULL;
74 void ImportScheduleWidget::parsingSchedule(const QString &aTitle)
76 importScheduleLabel->setText("Importing: " + aTitle);
79 void ImportScheduleWidget::showParsingProgress(int progress)
81 progressBar->setValue(progress);
84 void ImportScheduleWidget::browseSchedule()
86 QString scheduleFileName = QFileDialog::getOpenFileName(this, tr("Select Conference Schedule"), QDir::homePath(), tr("Schedule Files (*.xml)"));
87 if(QFile::exists(scheduleFileName))
89 QFile file(scheduleFileName);
90 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
92 qDebug() << "can't open " << file.fileName();
96 importData(file.readAll());
105 void ImportScheduleWidget::networkQueryFinished(QNetworkReply *aReply)
107 if ( aReply->error() != QNetworkReply::NoError )
109 qDebug() << "Error occured during download: " << aReply->errorString();
113 importData(aReply->readAll());
117 void ImportScheduleWidget::downloadSchedule()
119 QNetworkRequest request;
120 request.setUrl(QUrl(SCHEDULE_URL));
121 mNetworkAccessManager->get(request);
124 void ImportScheduleWidget::importData(const QByteArray &aData)
129 proxySettings->hide();
131 int confId = mXmlParser->parseData(aData);
136 proxySettings->show();
137 importScheduleLabel->setText("Import schedule: ");
139 emit(scheduleImported(confId));
142 void ImportScheduleWidget::setupProxy()
144 ProxySettingsDialog dialog;
147 qDebug() << "Setting-up proxy: " << AppSettings::proxyAddress() << ":" << AppSettings::proxyPort();
149 AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : QNetworkProxy::HttpProxy,
150 AppSettings::proxyAddress(),
151 AppSettings::proxyPort(),
154 QNetworkProxy::setApplicationProxy(proxy);
156 mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());