code clean
[mdictionary] / src / plugins / xdxf / XdxfDictDownloader.cpp
index 6ae05a6..57227b1 100644 (file)
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
-
 /*!
-  \file XdxfDictDownloader.cpp
-  \author Mateusz Półrola <mateusz.polrola@comarch.com>
-  */
+    \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 <mateusz.polrola@comarch.com>
+*/
 
 #include "XdxfDictDownloader.h"
 #include "XdxfDictDownloadProgressDialog.h"
 #include <QDebug>
 #include <QProcess>
-
-
 #include <bzlib.h>
-#include <libtar.h>
 #include <stdio.h>
 #include <fcntl.h>
 
-typedef void BZFILE;
+#ifndef Q_WS_MAEMO_5
+    #include <libtar.h>
+#endif
+
 
+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;
@@ -69,36 +71,38 @@ void XdxfDictDownloader::download(QWidget *parent) {
             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;
     http.kill();
-
     if(progressDialog && progressDialog->isVisible()) {
         progressDialog->accept();
     }
-
 }
 
+
 void XdxfDictDownloader::processFinished() {
     //first check if user cancel downloading
     if(aborted) return;
@@ -111,6 +115,7 @@ void XdxfDictDownloader::processFinished() {
     downloadComplete();
 }
 
+
 void XdxfDictDownloader::downloadComplete() {
     if(aborted) return;
     // Downloaded tar file name is different than extracted folder so we need
@@ -133,11 +138,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;
@@ -157,7 +162,7 @@ void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) {
     QRegExp regInner("<tr>.*</tr>");
     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())
@@ -168,12 +173,10 @@ void XdxfDictDownloader::dictListReceived(QNetworkReply *reply) {
     XdxfDictSelectDialog selectDialog(dicts, parentDialog);
 
     if(selectDialog.exec()==QDialog::Accepted) {
-
         progressDialog->setText(tr("Downloading dictionary"));
         progressDialog->show();
 
         QString url = selectDialog.link();
-
         _fileName = url.split('/').last();
 
         QProcess clean;
@@ -204,7 +207,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;
     }
@@ -222,7 +225,8 @@ 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;
     }
@@ -237,3 +241,4 @@ bool XdxfDictDownloader::extract(QString file) {
 }
 
 
+