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