Ignore:
Timestamp:
01/29/10 13:15:40 (13 years ago)
Author:
pavelpa <pavelpa@…>
Branches:
master, qt5
Children:
a023fd2
Parents:
1fb7a33
Message:

implemented importing the schedule from the Internet

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gui/importschedulewidget.cpp

    r1fb7a33 r5007fde  
    66#include <QFile>
    77#include <QFileDialog>
     8#include <QNetworkProxy>
     9#include <QNetworkAccessManager>
     10#include <QNetworkReply>
    811#include <QDebug>
     12
     13const QString SCHEDULE_URL = "http://fosdem.org/2010/schedule/xml";
    914
    1015ImportScheduleWidget::ImportScheduleWidget(QWidget *aParent)
     
    2126
    2227    cancel->hide();
    23     online->hide();
    2428    importAction->hide();
     29    connect(online, SIGNAL(clicked()), SLOT(downloadSchedule()));
     30
     31    mNetworkAccessManager = new QNetworkAccessManager(this);
     32    connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkQueryFinished(QNetworkReply*)));
     33    mNetworkAccessManager->setProxy(QNetworkProxy::applicationProxy());
    2534}
    2635
     
    3140        delete mXmlParser;
    3241        mXmlParser = NULL;
     42    }
     43    if(mNetworkAccessManager)
     44    {
     45        delete mNetworkAccessManager;
     46        mNetworkAccessManager = NULL;
    3347    }
    3448}
     
    5670        }
    5771
    58         QByteArray data = file.readAll();
    59         browse->hide();
    60         progressBar->show();
    61         int confId = mXmlParser->parseData(data);
     72        importData(file.readAll());
    6273
    63         progressBar->hide();
    64         browse->show();
    65         importScheduleLabel->setText("Import schedule: ");
    66 
    67         emit(scheduleImported(confId));
    6874    }
    6975    else
     
    7379}
    7480
     81void ImportScheduleWidget::networkQueryFinished(QNetworkReply *aReply)
     82{
     83    qDebug() << "ImportScheduleWidget::networkQueryFinished()";
     84
     85    if ( aReply->error() != QNetworkReply::NoError )
     86    {
     87        qDebug() << "Error occured during download: " << aReply->errorString();
     88    }
     89    else
     90    {
     91        importData(aReply->readAll());
     92    }
     93}
     94
     95void ImportScheduleWidget::downloadSchedule()
     96{
     97    qDebug() << "downloading schedule";
     98
     99    QNetworkRequest request;
     100    request.setUrl(QUrl(SCHEDULE_URL));
     101    mNetworkAccessManager->get(request);
     102}
     103
     104void ImportScheduleWidget::importData(const QByteArray &aData)
     105{
     106    browse->hide();
     107    online->hide();
     108    progressBar->show();
     109
     110    int confId = mXmlParser->parseData(aData);
     111
     112    progressBar->hide();
     113    browse->show();
     114    online->show();
     115    importScheduleLabel->setText("Import schedule: ");
     116
     117    emit(scheduleImported(confId));
     118}
     119
Note: See TracChangeset for help on using the changeset viewer.