From: Bartosz Szatkowski Date: Mon, 4 Oct 2010 11:05:04 +0000 (+0200) Subject: wget download changet to internal mechanisms X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=8d314ecae873551236796975c39d7d4a7e30f69f;p=mdictionary wget download changet to internal mechanisms --- diff --git a/src/plugins/xdxf/XdxfDictDownloader.cpp b/src/plugins/xdxf/XdxfDictDownloader.cpp index 677be7f..3529873 100644 --- a/src/plugins/xdxf/XdxfDictDownloader.cpp +++ b/src/plugins/xdxf/XdxfDictDownloader.cpp @@ -50,6 +50,7 @@ XdxfDictDownloader::XdxfDictDownloader(QObject *parent) : this, SLOT(processFinished(int))); progressDialog = 0; + connect(&http, SIGNAL(finished()), this, SLOT(processFinished())); } void XdxfDictDownloader::download(QWidget *parent) { @@ -84,24 +85,16 @@ void XdxfDictDownloader::breakDownloading() { } -void XdxfDictDownloader::processFinished(int exitcode) { +void XdxfDictDownloader::processFinished() { //first check if user cancel downloading if(aborted) return; - //if error of proces, notify user about this - if(exitcode != 0) { - Q_EMIT notify(Notify::Error, tr("Error while downloading or processing dictionary")); - breakDownloading(); + if(!extract("/tmp/" + _fileName)) { + Q_EMIT notify(Notify::Error, + "Error while extracting dictionary archive"); return; } - //if there are any left commands, execute next - if(++currentCommandstart(commands[currentCommand]); - } - else { - qDebug() << "EXTRACT" << extract("/tmp/" + _fileName); - downloadComplete(); - } + downloadComplete(); } void XdxfDictDownloader::downloadComplete() { @@ -169,26 +162,13 @@ void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) { _fileName = url.split('/').last(); - // Now its the tricky part ... its temporary (probably) - // We dont have any tar-dev and bz2-dev packages on maemo so we need - // to call commands via shell, each command from list is called after - // previous call returns 0 - - currentCommand = 0; - commands.clear(); - commands.push_back("rm -rf /tmp/mdict"); - commands.push_back("mkdir /tmp/mdict"); - - // Downloading xdxf dict from sourceforge is kind of complicated, - // there is a lot of redirection and QNetwork* is kind of lost, we - // tried to follow redirection (by hand) but we end up with some - // page and js scripts and thats all - // Maybe calling wget is not pretty one but its working! - commands.push_back("wget --quiet -P /tmp/ " + url); - - //commands.push_back(QString("tar -xjvf /tmp/") + _fileName + QString(" -C /tmp/mdict")); + QProcess clean; + clean.start("rm -rf /tmp/mdict"); + clean.waitForFinished(-1); + clean.start("mkdir /tmp/mdict"); + clean.waitForFinished(-1); - process->start(commands[0]); + http.download(QUrl(url), "/tmp/" + _fileName); } } diff --git a/src/plugins/xdxf/XdxfDictDownloader.h b/src/plugins/xdxf/XdxfDictDownloader.h index 5b7aec9..b381379 100644 --- a/src/plugins/xdxf/XdxfDictDownloader.h +++ b/src/plugins/xdxf/XdxfDictDownloader.h @@ -35,6 +35,7 @@ #include #include "XdxfDictDownloadProgressDialog.h" #include "../../include/Notify.h" +#include "HttpDownloader.h" #include #include @@ -68,7 +69,7 @@ private Q_SLOTS: void dictListReceived(QNetworkReply*); //! one of system processes finished - void processFinished(int); + void processFinished(); //! user cancel downloading void breakDownloading(); @@ -88,6 +89,7 @@ private: bool aborted; QNetworkAccessManager *manager; bool extract(QString file); + HttpDownloader http; }; #endif // XDXFDICTDOWNLOADER_H diff --git a/src/plugins/xdxf/xdxf.pro b/src/plugins/xdxf/xdxf.pro index be2f482..f0e1ecc 100644 --- a/src/plugins/xdxf/xdxf.pro +++ b/src/plugins/xdxf/xdxf.pro @@ -5,9 +5,8 @@ QT = core \ xml \ sql \ network - -LIBS += -ltar -lbz2 - +LIBS += -ltar \ + -lbz2 maemo5:QT += maemo5 SOURCES += xdxfplugin.cpp \ TranslationXdxf.cpp \ @@ -17,9 +16,8 @@ SOURCES += xdxfplugin.cpp \ XdxfDictDownloader.cpp \ XdxfDictSelectDialog.cpp \ XdxfDictDownloadProgressDialog.cpp \ - DictsModel.cpp - - + DictsModel.cpp \ + HttpDownloader.cpp HEADERS += xdxfplugin.h \ TranslationXdxf.h \ ../../include/DictDialog.h \ @@ -31,14 +29,12 @@ HEADERS += xdxfplugin.h \ XdxfDialog.h \ XdxfDictDownloader.h \ XdxfDictSelectDialog.h \ - XdxfDictDownloadProgressDialog.h \ + XdxfDictDownloadProgressDialog.h \ DownloadDict.h \ DictsModel.h \ - DictsProxyModel.h - -RESOURCES += \ - xdxf.qrc - + DictsProxyModel.h \ + HttpDownloader.h +RESOURCES += xdxf.qrc TRANSLATIONS += pl_PL.ts \ en_US.ts unix {