fix small bug(wildcard), and change some comments
[mdictionary] / src / plugins / xdxf / XdxfDictDownloader.h
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     mDictionary is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21 /*!
22     \file XdxfDictDownloader.h
23     \author Mateusz Półrola <mateusz.polrola@comarch.pl>
24 */
25
26 #ifndef XDXFDICTDOWNLOADER_H
27 #define XDXFDICTDOWNLOADER_H
28
29 #include <QObject>
30 #include "XdxfDictSelectDialog.h"
31 #include <QTimer>
32 #include <QNetworkAccessManager>
33 #include <QNetworkReply>
34 #include <DownloadDict.h>
35 #include "XdxfDictDownloadProgressDialog.h"
36 #include "../../include/Notify.h"
37 #include "HttpDownloader.h"
38 #include <string.h>
39 #include <errno.h>
40
41 /*!
42     XdxfDictDownloader is responsible for getting dict list from XDXF website
43     and other actions necessary to download and add dictionary
44
45     When user want to add dictionary he may choose "browse" or "download",
46     after selecting "download"  XDXFDictDownloader would present him list of
47     dictionaries and when he select one downloading would be started. Next
48     step is to extract archive and move file to ~/.mdictionary
49 */
50 class XdxfDictDownloader : public QObject {
51     Q_OBJECT
52 public:
53     XdxfDictDownloader(QObject *parent = 0);
54
55     //! \return name of downloaded file
56     QString downloadedFile();
57
58 public Q_SLOTS:
59     //! downloads dictionaries list from xdxf website
60     void download(QWidget* parent);
61
62 Q_SIGNALS:
63     //! emmited when file download precess is complete
64     void fileDownloaded(QString);
65
66     //! emitted to inform user about errors and warnings
67     void notify(Notify::NotifyType, QString);
68
69     //! emmited what is update Download Progress
70     void downloadProgress(float);
71
72 private Q_SLOTS:
73     //! obtained list of dictionaries from website
74     void dictListReceived(QNetworkReply*);
75
76     //! one of system processes finished
77     void processFinished();
78
79     //! user cancel downloading
80     void breakDownloading();
81
82     //! handling a download error
83     void downloadingError(QString);
84
85     /*!
86         function divide two qint64 and result emmit in
87         signals downloadProgress(float)
88     */
89     void updateDownloadProgress(qint64, qint64);
90
91 private:
92     //! dict is downloaded and unpacked
93     void downloadComplete();
94
95     QList<DownloadDict> dicts;
96     QWidget* parentDialog;
97     QString _downloadedFile;
98     XdxfDictDownloadProgressDialog* progressDialog;
99     QStringList commands;
100     int currentCommand;
101     QProcess* process;
102     QString _fileName;
103     bool downloadError;
104     bool aborted;
105     QNetworkAccessManager *manager;
106     bool extract(QString file);
107     HttpDownloader http;
108 };
109
110 #endif // XDXFDICTDOWNLOADER_H