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