Repair problem with build app on scratchbox. Add rules to build deb package with...
[mdictionary] / src / plugins / xdxf / XdxfDictDownloader.cpp
index 38066f4..887fdf5 100644 (file)
 #include "XdxfDictDownloader.h"
 #include "XdxfDictDownloadProgressDialog.h"
 #include <QDebug>
+#include <QProcess>
+
 
 #include <bzlib.h>
+#ifndef Q_WS_MAEMO_5
 #include <libtar.h>
+#endif
 #include <stdio.h>
 #include <fcntl.h>
 
@@ -50,6 +54,9 @@ XdxfDictDownloader::XdxfDictDownloader(QObject *parent) :
     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) {
@@ -62,6 +69,9 @@ 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();
 }
@@ -70,6 +80,10 @@ 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();
@@ -201,6 +215,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 +229,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;
 }