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>
25 #include <QFileDialog>
26 #include <QNetworkProxy>
27 #include <QNetworkAccessManager>
28 #include <QNetworkReply>
30 #include <appsettings.h>
32 // TODO: this is temporary
33 #include <QInputDialog>
35 #include "conference.h"
37 // const QString SCHEDULE_URL = "http://fosdem.org/2010/schedule/xml";
39 const QString PROXY_USERNAME;
40 const QString PROXY_PASSWD;
42 ImportScheduleWidget::ImportScheduleWidget(QWidget *aParent)
47 mXmlParser = new ScheduleXmlParser(this);
48 connect(mXmlParser, SIGNAL(progressStatus(int)), SLOT(showParsingProgress(int)));
49 connect(mXmlParser, SIGNAL(parsingSchedule(const QString &)), SLOT(parsingSchedule(const QString &)));
51 connect(browse, SIGNAL(clicked()), SLOT(browseSchedule()));
55 connect(online, SIGNAL(clicked()), SLOT(downloadSchedule()));
57 mNetworkAccessManager = new QNetworkAccessManager(this);
58 connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkQueryFinished(QNetworkReply*)));
59 mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
62 ImportScheduleWidget::~ImportScheduleWidget()
69 if(mNetworkAccessManager)
71 delete mNetworkAccessManager;
72 mNetworkAccessManager = NULL;
76 void ImportScheduleWidget::parsingSchedule(const QString &aTitle)
78 importScheduleLabel->setText("Importing: " + aTitle);
81 void ImportScheduleWidget::showParsingProgress(int progress)
83 progressBar->setValue(progress);
86 void ImportScheduleWidget::browseSchedule()
88 QString scheduleFileName = QFileDialog::getOpenFileName(this, tr("Select Conference Schedule"), QDir::homePath(), tr("Schedule Files (*.xml)"));
89 if(QFile::exists(scheduleFileName))
91 QFile file(scheduleFileName);
92 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
94 qDebug() << "can't open " << file.fileName();
98 importData(file.readAll(), QString());
107 void ImportScheduleWidget::networkQueryFinished(QNetworkReply *aReply)
109 if ( aReply->error() != QNetworkReply::NoError )
111 qDebug() << "Error occured during download: " << aReply->errorString();
115 importData(aReply->readAll(), aReply->url().toEncoded());
119 void ImportScheduleWidget::downloadSchedule()
121 QNetworkRequest request;
123 // TODO: make a nicer GUI
124 // basically, you have to do the following things:
125 // 1. store schedule URL for each conteferce
126 // 2. allow refreshing of the current conference schedule with "1 button click"
127 // 3. allow changing of the URL for a conference;
128 // run refresh together with it is ok and even justified by usability,
129 // but it must not loose this change if refresh not available.
130 // So it cannot be done as "do like #4 and rely on REPLACE".
131 // 4. allow getting the new conference by URL
135 url_default = Conference::getById(Conference::activeConference()).getUrl();
136 } catch (OrmException& e) {
137 qWarning() << "failed to get default URL:" << e.text();
141 QString url = QInputDialog::getText(this, "URL request", "Put proper schedule URL or let it try with it", QLineEdit::Normal, url_default, &ok);
142 if (!ok) { // cancel pressed
145 request.setUrl(QUrl(url));
147 mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
148 mNetworkAccessManager->get(request);
151 void ImportScheduleWidget::importData(const QByteArray &aData, const QString& url)
156 // proxySettings->hide();
158 int confId = mXmlParser->parseData(aData, url);
163 // proxySettings->show();
164 importScheduleLabel->setText("Import schedule: ");
166 emit(scheduleImported(confId));