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 connect(changeUrl, SIGNAL(clicked()), SLOT(on_changeUrl()));
58 connect(newConfFromUrl, SIGNAL(clicked()), SLOT(on_newFromUrl()));
59 connect(delConf, SIGNAL(clicked()), SLOT(on_delete()));
61 mNetworkAccessManager = new QNetworkAccessManager(this);
62 connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkQueryFinished(QNetworkReply*)));
63 mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
66 ImportScheduleWidget::~ImportScheduleWidget()
73 if(mNetworkAccessManager)
75 delete mNetworkAccessManager;
76 mNetworkAccessManager = NULL;
80 void ImportScheduleWidget::parsingSchedule(const QString &aTitle)
82 importScheduleLabel->setText("Importing: " + aTitle);
85 void ImportScheduleWidget::showParsingProgress(int progress)
87 progressBar->setValue(progress);
90 void ImportScheduleWidget::browseSchedule()
92 QString scheduleFileName = QFileDialog::getOpenFileName(this, tr("Select Conference Schedule"), QDir::homePath(), tr("Schedule Files (*.xml)"));
93 if(QFile::exists(scheduleFileName))
95 QFile file(scheduleFileName);
96 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
98 qDebug() << "can't open " << file.fileName();
102 importData(file.readAll(), QString());
111 void ImportScheduleWidget::networkQueryFinished(QNetworkReply *aReply)
113 if ( aReply->error() != QNetworkReply::NoError )
115 qDebug() << "Error occured during download: " << aReply->errorString();
119 importData(aReply->readAll(), aReply->url().toEncoded());
123 void ImportScheduleWidget::downloadSchedule()
126 // TODO: make a nicer GUI
127 // basically, you have to do the following things:
128 // 1. store schedule URL for each conteferce
129 // 2. allow refreshing of the current conference schedule with "1 button click"
130 // 3. allow changing of the URL for a conference;
131 // run refresh together with it is ok and even justified by usability,
132 // but it must not loose this change if refresh not available.
133 // So it cannot be done as "do like #4 and rely on REPLACE".
134 // 4. allow getting the new conference by URL
136 // FIXME: it will throw
137 // GUI should not show this button if there is no active conf
138 importFromNetwork(Conference::getById(Conference::activeConference()).getUrl());
141 void ImportScheduleWidget::on_changeUrl()
143 // FIXME: it will throw
144 // GUI should not show this button if there is no active conf
145 Conference active_conference = Conference::getById(Conference::activeConference());
148 QInputDialog::getText(this, "URL request", "Enter the new URL for conference schedule"
150 , active_conference.getUrl()
153 active_conference.setUrl(new_url);
157 void ImportScheduleWidget::on_newFromUrl()
160 QString url = QInputDialog::getText(this, "URL request", "Put the schedule URL", QLineEdit::Normal, "", &ok);
162 importFromNetwork(url);
167 void ImportScheduleWidget::on_delete()
172 void ImportScheduleWidget::importFromNetwork(const QString& url)
174 QNetworkRequest request;
175 request.setUrl(QUrl(url));
177 mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
178 mNetworkAccessManager->get(request);
181 void ImportScheduleWidget::importData(const QByteArray &aData, const QString& url)
186 // proxySettings->hide();
188 int confId = mXmlParser->parseData(aData, url);
193 // proxySettings->show();
194 importScheduleLabel->setText("Import schedule: ");
196 emit(scheduleImported(confId));