this, SLOT(processFinished(int)));
progressDialog = 0;
+ connect(&http, SIGNAL(finished()), this, SLOT(processFinished()));
}
void XdxfDictDownloader::download(QWidget *parent) {
}
-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(++currentCommand<commands.size()) {
- process->start(commands[currentCommand]);
- }
- else {
- qDebug() << "EXTRACT" << extract("/tmp/" + _fileName);
- downloadComplete();
- }
+ downloadComplete();
}
void XdxfDictDownloader::downloadComplete() {
_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);
}
}
#include <DownloadDict.h>
#include "XdxfDictDownloadProgressDialog.h"
#include "../../include/Notify.h"
+#include "HttpDownloader.h"
#include <string.h>
#include <errno.h>
void dictListReceived(QNetworkReply*);
//! one of system processes finished
- void processFinished(int);
+ void processFinished();
//! user cancel downloading
void breakDownloading();
bool aborted;
QNetworkAccessManager *manager;
bool extract(QString file);
+ HttpDownloader http;
};
#endif // XDXFDICTDOWNLOADER_H
xml \
sql \
network
-
-LIBS += -ltar -lbz2
-
+LIBS += -ltar \
+ -lbz2
maemo5:QT += maemo5
SOURCES += xdxfplugin.cpp \
TranslationXdxf.cpp \
XdxfDictDownloader.cpp \
XdxfDictSelectDialog.cpp \
XdxfDictDownloadProgressDialog.cpp \
- DictsModel.cpp
-
-
+ DictsModel.cpp \
+ HttpDownloader.cpp
HEADERS += xdxfplugin.h \
TranslationXdxf.h \
../../include/DictDialog.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 {