3a74b204c75b3226d0984862ee3465d40e6ac002
[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 /*!
23   \file XdxfDictDownloader.h
24   \author Mateusz Półrola <mateusz.polrola@comarch.pl>
25  */
26
27 #ifndef XDXFDICTDOWNLOADER_H
28 #define XDXFDICTDOWNLOADER_H
29
30 #include <QObject>
31 #include "XdxfDictSelectDialog.h"
32 #include <QTimer>
33 #include <QNetworkAccessManager>
34 #include <QNetworkReply>
35 #include <DownloadDict.h>
36 #include "XdxfDictDownloadProgressDialog.h"
37 #include "../../include/Notify.h"
38
39 /** XdxfDictDownloader is responsible for getting dict list from XDXF website
40     and other actions necessary to download and add dictionary
41
42     When user want to add dictionary he may choose "browse" or "download",
43     after selecting "download"  XDXFDictDownloader would present him list of
44     dictionaries and when he select one downloading would be started. Next
45     step is to extract archive and move file to ~/.mdictionary
46 */
47 class XdxfDictDownloader : public QObject {
48     Q_OBJECT
49 public:
50     XdxfDictDownloader(QObject *parent = 0);
51     //! \return name of downloaded file
52     QString downloadedFile();
53
54 public Q_SLOTS:
55     //! downloads dictionaries list from xdxf website
56     void download(QWidget* parent);
57
58 Q_SIGNALS:
59     //! emmited when file download precess is complete
60     void fileDownloaded(QString);
61     //! emitted to inform user about errors and warnings
62     void notify(Notify::NotifyType, QString);
63
64 private Q_SLOTS:
65     //! obtained list of dictionaries from website
66     void dictListReceived(QNetworkReply*);
67
68     //! one of system processes finished
69     void processFinished(int);
70
71     //! user cancel downloading
72     void breakDownloading();
73
74 private:
75     //! dict is downloaded and unpacked
76     void downloadComplete();
77     QList<DownloadDict> dicts;
78     QWidget* parentDialog;
79     QString _downloadedFile;
80     XdxfDictDownloadProgressDialog* progressDialog;
81     QStringList commands;
82     int currentCommand;
83     QProcess* process;
84     QString _fileName;
85     bool downloadError;
86     bool aborted;
87     QNetworkAccessManager *manager;
88 };
89
90 #endif // XDXFDICTDOWNLOADER_H