8e031f615afcdbcddc7a4127abb511631ddaa028
[mdictionary] / src / plugins / xdxf / XdxfDialog.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 XdxfDialog.h
24     \brief Implementation of xdxf plugin's dialogs.
25
26     \author Mateusz Półrola <mateusz.polrola@gmail.com>
27 */
28
29 #ifndef XDXFDIALOG_H
30 #define XDXFDIALOG_H
31
32 #include <QDialog>
33 #include "../../include/settings.h"
34 #include <QtGui>
35 #include "xdxfplugin.h"
36
37
38 /*!
39     This class can create dialogs for adding a new dictionary or changing settings
40      of an existing one, based on dialog type passed to contructor.
41     When adding a new dictionary dialog contains a button to browse file system and
42     select a dictionary file. When changing settings dialog displays basic
43     information about dictionary i. e. name, languages and license info.
44     In both types of dialogs there are comboboxes with "cache" and "remove accents"
45      options. On maemo right next to comboboxes are tool buttons which allow to
46      see more information about these options, on desktop the same information is
47      displayed as a tool tip.
48     All contents of a dialog are in a scroll area.
49 */
50 class XdxfDialog : public QDialog
51 {
52     Q_OBJECT
53 public:
54     /*!
55         Describes type of dialog. New means that dialog contains widgets to browse
56         file system and select dictionary file. Change means that dialog displays
57         information about dictionary.
58         In both types dialog provides widgets to create or delete cache and remove
59         or keep accents.
60     */
61     enum XdxfDialogType {New, Change};
62
63     /*!
64         Creates new xdxf dialog
65         \param plugin if created dialog is of type Change it must be set to
66         point to plugin whose settings will be changed
67         \param type describes type of created dialog
68         \param parent parent widget of created dialog
69     */
70     explicit XdxfDialog(XdxfPlugin* plugin = 0,
71                         XdxfDialogType type = New,
72                         QWidget* parent = 0);
73
74     /*!
75         After acceptance of dialog this method returns plugin's settings based on
76         user's choices in dialog.
77         \returns settings of plugin
78     */
79     Settings* getSettings();
80
81 Q_SIGNALS:
82     //! Requests to show notification
83     void notify(Notify::NotifyType, QString);
84
85 public Q_SLOTS:
86     /*!
87         Reimplemented accept method, to check if all necessary fields in
88         dialog are correct e. g. dictionary file path
89         and saves new settings
90     */
91     void accept();
92
93 private Q_SLOTS:
94     //! displays dialog to browse and select file
95     void selectFile();
96
97     //! download dictionaries list
98     void downloadFile();
99
100     //! set properti _generateCache
101     void setGenerateCache(bool);
102
103     //! set properti _accents
104     void setAccents(bool);
105
106     void fileDownloaded(QString);
107
108     #ifdef Q_WS_MAEMO_5
109         //! on maemo shows information about checkboxes
110         void showCacheInfo();
111
112         //! on maemo shows information about checkboxes
113         void showAccentsInfo();
114     #endif
115
116
117 private:
118     void initializeUI();
119
120     //! saves new settings after acceptance of dialog
121     void saveSettings();
122
123     QLabel* infoLabel;
124     QPushButton* browseButton;
125     QPushButton* downloadButton;
126     QHBoxLayout* browseLayout;
127     QHBoxLayout* infoLayout;
128
129     QCheckBox* cacheCheckBox;
130     QCheckBox* accentsCheckBox;
131     QHBoxLayout* cacheLayout;
132     QHBoxLayout* accentsLayout;
133
134     QString cacheToolTip;
135     QString accentsToolTip;
136
137     #ifdef Q_WS_MAEMO_5
138         QToolButton* cacheInfoToolButton;
139         QToolButton* accentsInfoToolButton;
140     #endif
141
142
143     QPushButton* confirmButton;
144
145     QString _dictionaryFilePath;
146
147     QScrollArea* scrollArea;
148
149     QWidget* widget;
150     QHBoxLayout* layout;
151
152     QVBoxLayout* mainVerticalLayout;
153     bool _generateCache;
154     bool _accents;
155     bool _lastAccents;
156
157     Settings* _settings;
158
159     XdxfPlugin* plugin;
160     XdxfDialogType type;
161 };
162
163 #endif // XDXFDIALOG_H