X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fplugins%2Fxdxf%2FXdxfDictDownloader.cpp;h=1b654080e74aa878a0b49001e4804575c3f29605;hb=00c4970f59cd301a63e58a470619b9ad5ab075f2;hp=38066f4b10ac7647dc37f6c287dd1254734e91bb;hpb=0b2d2410c37da3d2740a7c1f7dc7ed45c5e9e0f6;p=mdictionary diff --git a/src/plugins/xdxf/XdxfDictDownloader.cpp b/src/plugins/xdxf/XdxfDictDownloader.cpp index 38066f4..1b65408 100644 --- a/src/plugins/xdxf/XdxfDictDownloader.cpp +++ b/src/plugins/xdxf/XdxfDictDownloader.cpp @@ -18,40 +18,41 @@ Copyright 2010 Comarch S.A. *******************************************************************************/ - /*! - \file XdxfDictDownloader.cpp - \author Mateusz Półrola - */ + \file XdxfDictDownloader.cpp + \author Mateusz Półrola +*/ #include "XdxfDictDownloader.h" #include "XdxfDictDownloadProgressDialog.h" #include - +#include #include +#ifndef Q_WS_MAEMO_5 #include +#endif #include #include typedef void BZFILE; - - XdxfDictDownloader::XdxfDictDownloader(QObject *parent) : QObject(parent) { parentDialog = 0; + progressDialog = 0; manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(dictListReceived(QNetworkReply*))); - - - progressDialog = 0; - connect(&http, SIGNAL(finished()), this, SLOT(processFinished())); + connect(&http, SIGNAL(finished()), + this, SLOT(processFinished())); connect(&http, SIGNAL(error(QString)), this, SLOT(downloadingError(QString))); + connect(&http, SIGNAL(progress(qint64,qint64)), + this, SLOT(updateDownloadProgress(qint64,qint64))); } + void XdxfDictDownloader::download(QWidget *parent) { parentDialog = parent; aborted = false; @@ -62,20 +63,31 @@ void XdxfDictDownloader::download(QWidget *parent) { connect(progressDialog, SIGNAL(cancelDownloading()), this, SLOT(breakDownloading())); + connect(this, SIGNAL(downloadProgress(float)), + progressDialog, SLOT(updateProgress(float))); + progressDialog->setText(tr("Downloading dictionaries list")); progressDialog->show(); } + QString XdxfDictDownloader::downloadedFile() { return _downloadedFile; } +void XdxfDictDownloader::updateDownloadProgress(qint64 downloaded, + qint64 total) { + Q_EMIT downloadProgress(float(downloaded) / float(total)); +} + + void XdxfDictDownloader::downloadingError(QString error) { breakDownloading(); Q_EMIT notify(Notify::Error, error); } + void XdxfDictDownloader::breakDownloading() { //if user cancel downloading we kill all running processes, hide progress dialog and set flag that user cancel downloading. aborted = true; @@ -84,9 +96,9 @@ void XdxfDictDownloader::breakDownloading() { if(progressDialog && progressDialog->isVisible()) { progressDialog->accept(); } - } + void XdxfDictDownloader::processFinished() { //first check if user cancel downloading if(aborted) return; @@ -99,6 +111,7 @@ void XdxfDictDownloader::processFinished() { downloadComplete(); } + void XdxfDictDownloader::downloadComplete() { if(aborted) return; // Downloaded tar file name is different than extracted folder so we need @@ -121,11 +134,11 @@ void XdxfDictDownloader::downloadComplete() { emit fileDownloaded(_downloadedFile); } + void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) { progressDialog->accept(); - if(aborted) return; - - + if(aborted) + return; if(reply->error() != QNetworkReply::NoError) { Q_EMIT notify(Notify::Error, reply->errorString()); return; @@ -201,6 +214,7 @@ bool XdxfDictDownloader::extract(QString file) { fclose(archive); // Extracting tar + #ifndef Q_WS_MAEMO_5 TAR *t; char * tarfname = new char[file.replace(QRegExp(".bz2%"), "").size()+1]; strcpy(tarfname, file.replace(QRegExp(".bz2%"), "").toStdString().c_str()); @@ -214,6 +228,11 @@ bool XdxfDictDownloader::extract(QString file) { return false; } tar_close(t); + #else + QProcess tar; + tar.start("tar -xvf " + file.replace(QRegExp(".bz2%"), "") + " -C /tmp/mdict"); + tar.waitForFinished(-1); + #endif return true; }