00001
00002
00003
00004
00005
00006
00007
00008
00009 void QTS_DownloadDialog::init() {
00010 urlOperator = new QUrlOperator();
00011 connect(urlOperator, SIGNAL(start(QNetworkOperation*)),
00012 this, SLOT(slotStart(QNetworkOperation*)));
00013 connect(urlOperator, SIGNAL(finished(QNetworkOperation*)),
00014 this, SLOT(slotFinished(QNetworkOperation*)));
00015 connect(urlOperator, SIGNAL(dataTransferProgress(int, int, QNetworkOperation*)),
00016 this, SLOT(slotDataTransferProgress(int, int, QNetworkOperation*)));
00017 connect(urlOperator, SIGNAL(data(const QByteArray&, QNetworkOperation*)),
00018 this, SLOT(slotData(const QByteArray&, QNetworkOperation*)));
00019 connect(bCancel, SIGNAL(clicked()),
00020 this, SLOT(cancelled()));
00021 }
00022
00023 void QTS_DownloadDialog::destroy() {
00024 delete urlOperator;
00025 delete file;
00026 }
00027
00028 void QTS_DownloadDialog::startDownload(const QString& url, const QString& fileName) {
00029 bytes = 0;
00030 file = new QFile(fileName);
00031 file->open(IO_WriteOnly);
00032 urlOperator->get(url);
00033 }
00034
00038 void QTS_DownloadDialog::slotStart(QNetworkOperation*) {
00039 RS_DEBUG->print("QTS_DownloadDialog::slotStart\n");
00040 }
00041
00042
00046 void QTS_DownloadDialog::slotFinished(QNetworkOperation*) {
00047 RS_DEBUG->print("QTS_DownloadDialog::slotFinished\n");
00048
00049 file->flush();
00050 file->close();
00051 accept();
00052 }
00053
00054
00058 void QTS_DownloadDialog::slotDataTransferProgress(int, int, QNetworkOperation*) {
00059
00060 }
00061
00062 void QTS_DownloadDialog::slotData(const QByteArray& data, QNetworkOperation*) {
00063
00064
00065 file->writeBlock(data);
00066 file->flush();
00067
00068 bytes+=data.size();
00069
00070 lBytes->setText(QString("%1").arg(bytes));
00071
00072 RS_DEBUG->print("Retrieving data: %d Bytes", bytes);
00073
00074
00075
00076
00077
00078 }
00079
00080 void QTS_DownloadDialog::cancelled() {
00081 RS_DEBUG->print("QTS_DownloadDialog::cancelled\n");
00082
00083 file->remove();
00084 reject();
00085 }
00086