52464b1bc661b18ee6e1dd4124085bdd0b630626
[mdictionary] / src / plugins / google / GoogleDialog.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 GoogleDialog.h
23     \brief Implementation of google plugin's dialogs.
24
25     \author Mateusz Półrola <mateusz.polrola@gmail.com>
26     \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
27 */
28
29 #ifndef GOOGLEDIALOG_H
30 #define GOOGLEDIALOG_H
31
32 #include <QDialog>
33 #include "../../include/settings.h"
34 #include <QtGui>
35 #include <QDeclarativeView>
36
37 #include "GooglePlugin.h"
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 constructor.
42      These types differ only in confirm button label.
43      Both provide comboboxes with available languages to choose.
44 */
45 class GoogleDialog : public QDialog
46 {
47     Q_OBJECT
48 public:
49     /*!
50       Describes type of dialog. New means that dialog confirm button has
51         "Add" label, Change means that dialog confirm button has "Save settings" label.
52     */
53     enum GoogleDialogType {New, Change};
54
55     //! Constructor
56     /*!
57         Creates new google dialog
58         \param plugin if created dialog is of type Change it must be set to
59             point to plugin whose settings will be changed
60         \param type describes type of created dialog
61         \param parent parent widget of created dialog
62     */
63     explicit GoogleDialog(GooglePlugin* plugin = 0,
64                           GoogleDialogType type = New,
65                           QWidget* parent = 0);
66
67     //! \returns settings of plugin
68     /*!
69         After acceptance of dialog this method returns plugin's settings based on
70          user's choices in dialog.
71     */
72     Settings* getSettings();
73
74 Q_SIGNALS:
75     //! requests to show notification
76     void notify(Notify::NotifyType, QString);
77
78 public Q_SLOTS:
79     //! reimplemented accept method, to save new settings
80     void accept();
81
82 private Q_SLOTS:
83     //! assigns the language chosen from a list(langFromComboBox) to _langFrom
84     void langFromChanged(int);
85
86     //! assigns the language chosen from a list(langToComboBox) to _langTo
87     void langToChanged(int);
88
89     //! handles the "swap languages" button
90     void changeLangButtonClicked();
91
92 private:
93     QVBoxLayout* mainLayout;
94     QDeclarativeView *view;
95
96     void initializeUI();
97
98     //! saves new settings after acceptance of dialog
99     void saveSettings();
100
101     QLabel* infoLabel;
102     QLabel* langFromLabel;
103     QLabel* langToLabel;
104     QLabel* connectInfoLabel;
105     QPushButton* confirmButton;
106     QPushButton* changeLangButton;
107     QComboBox *langFromComboBox;
108     QComboBox *langToComboBox;
109     QVBoxLayout* verticalLayout;
110     QVBoxLayout* langLayout;
111     QFormLayout* langsFormLayout;
112     QHBoxLayout* changeLangLayout;
113     QString _langFrom;
114     QString _langTo;
115
116     Settings* _settings;
117     GooglePlugin* plugin;
118     GoogleDialogType type;
119 };
120
121 #endif // GOOGLEDIALOG_H