source: src/gui/importschedulewidget.cpp @ d06ae27

qt5
Last change on this file since d06ae27 was d06ae27, checked in by kirilma <kirilma@…>, 12 years ago

store URL's for conferences

  • use it at update
  • let user update the url before request
  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
4 * This file is part of fosdem-schedule.
5 *
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)
9 * any later version.
10 *
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
14 * more details.
15 *
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/>.
18 */
19#include "importschedulewidget.h"
20
21#include <schedulexmlparser.h>
22
23#include <QDir>
24#include <QFile>
25#include <QFileDialog>
26#include <QNetworkProxy>
27#include <QNetworkAccessManager>
28#include <QNetworkReply>
29#include <QDebug>
30#include <appsettings.h>
31
32// TODO: this is temporary
33#include <QInputDialog>
34
35#include "conference.h"
36
37// const QString SCHEDULE_URL = "http://fosdem.org/2010/schedule/xml";
38
39const QString PROXY_USERNAME;
40const QString PROXY_PASSWD;
41
42ImportScheduleWidget::ImportScheduleWidget(QWidget *aParent)
43    : QWidget(aParent)
44{
45    setupUi(this);
46
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 &)));
50
51    connect(browse, SIGNAL(clicked()), SLOT(browseSchedule()));
52    progressBar->hide();
53
54    cancel->hide();
55    connect(online, SIGNAL(clicked()), SLOT(downloadSchedule()));
56
57    mNetworkAccessManager = new QNetworkAccessManager(this);
58    connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkQueryFinished(QNetworkReply*)));
59    mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
60}
61
62ImportScheduleWidget::~ImportScheduleWidget()
63{
64    if(mXmlParser)
65    {
66        delete mXmlParser;
67        mXmlParser = NULL;
68    }
69    if(mNetworkAccessManager)
70    {
71        delete mNetworkAccessManager;
72        mNetworkAccessManager = NULL;
73    }
74}
75
76void ImportScheduleWidget::parsingSchedule(const QString &aTitle)
77{
78    importScheduleLabel->setText("Importing: " + aTitle);
79}
80
81void ImportScheduleWidget::showParsingProgress(int progress)
82{
83    progressBar->setValue(progress);
84}
85
86void ImportScheduleWidget::browseSchedule()
87{
88    QString scheduleFileName = QFileDialog::getOpenFileName(this, tr("Select Conference Schedule"), QDir::homePath(), tr("Schedule Files (*.xml)"));
89    if(QFile::exists(scheduleFileName))
90    {
91        QFile file(scheduleFileName);
92        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
93        {
94            qDebug() << "can't open " << file.fileName();
95            return;
96        }
97
98        importData(file.readAll(), QString());
99
100    }
101    else
102    {
103        progressBar->hide();
104    }
105}
106
107void ImportScheduleWidget::networkQueryFinished(QNetworkReply *aReply)
108{
109    if ( aReply->error() != QNetworkReply::NoError )
110    {
111        qDebug() << "Error occured during download: " << aReply->errorString();
112    }
113    else
114    {
115        importData(aReply->readAll(), aReply->url().toEncoded());
116    }
117}
118
119void ImportScheduleWidget::downloadSchedule()
120{
121    QNetworkRequest request;
122
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
132
133    QString url_default;
134    try {
135        url_default = Conference::getById(Conference::activeConference()).getUrl();
136    } catch (OrmException& e) {
137        qWarning() << "failed to get default URL:" << e.text();
138    }
139
140    bool ok = false;
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
143        return;
144    }
145    request.setUrl(QUrl(url));
146
147    mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
148    mNetworkAccessManager->get(request);
149}
150
151void ImportScheduleWidget::importData(const QByteArray &aData, const QString& url)
152{
153    browse->hide();
154    online->hide();
155    progressBar->show();
156    // proxySettings->hide();
157
158    int confId = mXmlParser->parseData(aData, url);
159
160    progressBar->hide();
161    browse->show();
162    online->show();
163    // proxySettings->show();
164    importScheduleLabel->setText("Import schedule: ");
165
166    emit(scheduleImported(confId));
167}
168
Note: See TracBrowser for help on using the repository browser.