X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fplugins%2Fxdxf%2FXdxfDictDownloader.cpp;h=96415d91b16f89bc9216982df002b2e1d3475a77;hb=68811e830ed9d474a0c2d723605065c03344df33;hp=35298737202052bc49c8759e59bce2ba265e7b4c;hpb=8d314ecae873551236796975c39d7d4a7e30f69f;p=mdictionary diff --git a/src/plugins/xdxf/XdxfDictDownloader.cpp b/src/plugins/xdxf/XdxfDictDownloader.cpp index 3529873..96415d9 100644 --- a/src/plugins/xdxf/XdxfDictDownloader.cpp +++ b/src/plugins/xdxf/XdxfDictDownloader.cpp @@ -18,41 +18,47 @@ Copyright 2010 Comarch S.A. *******************************************************************************/ - /*! - \file XdxfDictDownloader.cpp - \author Mateusz Półrola - */ + \file XdxfDictDownloader.cpp + \brief XdxfDictDownloader is responsible for getting dict list from XDXF website + and other actions necessary to download and add dictionary + + \author Mateusz Półrola +*/ #include "XdxfDictDownloader.h" #include "XdxfDictDownloadProgressDialog.h" #include - +#include #include -#include #include #include -typedef void BZFILE; +#ifndef Q_WS_MAEMO_5 + #include +#endif +typedef void BZFILE; + XdxfDictDownloader::XdxfDictDownloader(QObject *parent) : QObject(parent) { parentDialog = 0; - process = new QProcess(this); + progressDialog = 0; manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(dictListReceived(QNetworkReply*))); - - connect(process, SIGNAL(finished(int)), - this, SLOT(processFinished(int))); - - 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; @@ -63,28 +69,43 @@ void XdxfDictDownloader::download(QWidget *parent) { connect(progressDialog, SIGNAL(cancelDownloading()), this, SLOT(breakDownloading())); + connect(this, SIGNAL(downloadProgress(float)), + progressDialog, SLOT(updateProgress(float))); + + qDebug()<<"etam 3.1"; 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; - if(process->state() != QProcess::NotRunning) { - process->kill(); - } - + http.kill(); + qDebug()<<"end download"; if(progressDialog && progressDialog->isVisible()) { progressDialog->accept(); } - } + void XdxfDictDownloader::processFinished() { //first check if user cancel downloading if(aborted) return; @@ -97,6 +118,7 @@ void XdxfDictDownloader::processFinished() { downloadComplete(); } + void XdxfDictDownloader::downloadComplete() { if(aborted) return; // Downloaded tar file name is different than extracted folder so we need @@ -119,11 +141,11 @@ void XdxfDictDownloader::downloadComplete() { emit fileDownloaded(_downloadedFile); } -void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) { - if(aborted) return; +void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) { progressDialog->accept(); - + if(aborted) + return; if(reply->error() != QNetworkReply::NoError) { Q_EMIT notify(Notify::Error, reply->errorString()); return; @@ -143,7 +165,7 @@ void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) { QRegExp regInner(".*"); regInner.setMinimal(true); int pos = 0; - + dicts.clear(); while ((pos = regInner.indexIn(page, pos)) != -1) { DownloadDict temp = DownloadDict(regInner.cap(0)); if(!temp.fromLang().isEmpty()) @@ -154,12 +176,11 @@ void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) { XdxfDictSelectDialog selectDialog(dicts, parentDialog); if(selectDialog.exec()==QDialog::Accepted) { - + qDebug()<<"etap 3.2"; progressDialog->setText(tr("Downloading dictionary")); progressDialog->show(); QString url = selectDialog.link(); - _fileName = url.split('/').last(); QProcess clean; @@ -190,7 +211,7 @@ bool XdxfDictDownloader::extract(QString file) { int bufflen = 100; char buff[bufflen]; while(err == BZ_OK) { - int len = BZ2_bzRead(&err, afterbzFile, buff, bufflen); + unsigned int len = BZ2_bzRead(&err, afterbzFile, buff, bufflen); if(fwrite(buff, 1, len, tarfile) != len) return false; } @@ -199,6 +220,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()); @@ -207,13 +229,20 @@ bool XdxfDictDownloader::extract(QString file) { if(err == -1) return false; - err = tar_extract_all(t, "/tmp/mdict/"); + char text[]={"/tmp/mdict/"}; + err = tar_extract_all(t,text); if(err == -1) { 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; } +