source: src/gui/importschedulewidget.cpp @ ad5c62f

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

move Settings and About to Window Menu

  • remove Setting and About controls from widgets
  • make instead a window menus with the corresponding actions
  • rename "Proxy settings" to "Settings", placing the proxy button in a control group
  • Property mode set to 100644
File size: 3.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
32const QString SCHEDULE_URL = "http://fosdem.org/2010/schedule/xml";
33
34const QString PROXY_USERNAME;
35const QString PROXY_PASSWD;
36
37ImportScheduleWidget::ImportScheduleWidget(QWidget *aParent)
38    : QWidget(aParent)
39{
40    setupUi(this);
41
42    mXmlParser = new ScheduleXmlParser(this);
43    connect(mXmlParser, SIGNAL(progressStatus(int)), SLOT(showParsingProgress(int)));
44    connect(mXmlParser, SIGNAL(parsingSchedule(const QString &)), SLOT(parsingSchedule(const QString &)));
45
46    connect(browse, SIGNAL(clicked()), SLOT(browseSchedule()));
47    progressBar->hide();
48
49    cancel->hide();
50    importAction->hide();
51    connect(online, SIGNAL(clicked()), SLOT(downloadSchedule()));
52
53    mNetworkAccessManager = new QNetworkAccessManager(this);
54    connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkQueryFinished(QNetworkReply*)));
55    mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
56}
57
58ImportScheduleWidget::~ImportScheduleWidget()
59{
60    if(mXmlParser)
61    {
62        delete mXmlParser;
63        mXmlParser = NULL;
64    }
65    if(mNetworkAccessManager)
66    {
67        delete mNetworkAccessManager;
68        mNetworkAccessManager = NULL;
69    }
70}
71
72void ImportScheduleWidget::parsingSchedule(const QString &aTitle)
73{
74    importScheduleLabel->setText("Importing: " + aTitle);
75}
76
77void ImportScheduleWidget::showParsingProgress(int progress)
78{
79    progressBar->setValue(progress);
80}
81
82void ImportScheduleWidget::browseSchedule()
83{
84    QString scheduleFileName = QFileDialog::getOpenFileName(this, tr("Select Conference Schedule"), QDir::homePath(), tr("Schedule Files (*.xml)"));
85    if(QFile::exists(scheduleFileName))
86    {
87        QFile file(scheduleFileName);
88        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
89        {
90            qDebug() << "can't open " << file.fileName();
91            return;
92        }
93
94        importData(file.readAll());
95
96    }
97    else
98    {
99        progressBar->hide();
100    }
101}
102
103void ImportScheduleWidget::networkQueryFinished(QNetworkReply *aReply)
104{
105    if ( aReply->error() != QNetworkReply::NoError )
106    {
107        qDebug() << "Error occured during download: " << aReply->errorString();
108    }
109    else
110    {
111        importData(aReply->readAll());
112    }
113}
114
115void ImportScheduleWidget::downloadSchedule()
116{
117    QNetworkRequest request;
118    request.setUrl(QUrl(SCHEDULE_URL));
119
120    mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
121    mNetworkAccessManager->get(request);
122}
123
124void ImportScheduleWidget::importData(const QByteArray &aData)
125{
126    browse->hide();
127    online->hide();
128    progressBar->show();
129    // proxySettings->hide();
130
131    int confId = mXmlParser->parseData(aData);
132
133    progressBar->hide();
134    browse->show();
135    online->show();
136    // proxySettings->show();
137    importScheduleLabel->setText("Import schedule: ");
138
139    emit(scheduleImported(confId));
140}
141
Note: See TracBrowser for help on using the repository browser.