Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
[mdictionary] / src / mdictionary / gui / DictManagerWidget.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 DictManagerWidget.h
23 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
24
25 #ifndef DICTMANAGERWIDGET_H
26 #define DICTMANAGERWIDGET_H
27
28 #include <QWidget>
29 #include <QtGui>
30 #include "../../common/GUIInterface.h"
31
32
33 //! Implements dictionaries management widget
34 /*!
35   Shows list of loaded dictionaries and their states (active/inactive).
36   It allows to change dicts states, add new dict, remove selected one or
37   change settings of selected dict. All changes are saved automatically after
38   hiding of this widget.
39 */
40 class DictManagerWidget : public QDialog {
41     Q_OBJECT
42 public:
43     //! Constructor
44     /*!
45       \param parent parent of this widget, which must be subclass of
46       GUIInterface, because it will use it to get info about loaded plugins
47       and dicts.
48     */
49     explicit DictManagerWidget(GUIInterface *parent = 0);
50
51 protected:
52     void showEvent(QShowEvent *e);
53     void hideEvent(QHideEvent *e);
54
55 Q_SIGNALS:
56     //! Emitted when hiding widget, it will save states of dictionaries
57     /*!
58         \param list of only active dictionaries
59     */
60     void selectedDictionaries(QList<CommonDictInterface*>);
61
62     //! Emitted when user wants to add new dictionary
63     /*!
64         \param new dictionary returned by specific plugin dialog
65     */
66     void addDictionary(CommonDictInterface*);
67
68     //! Emitted when user wants to remove dictionary
69     /*!
70         \param dictionary which will be removed
71     */
72     void removeDictionary(CommonDictInterface*);
73
74
75 public Q_SLOTS:
76     #ifndef Q_WS_MAEMO_5
77         void save();
78     #endif
79
80 private Q_SLOTS:
81     /*! Shows "plugin select" dialog and then plugin specific "add new dictionary
82         dialog", which will return new CommonDictInterface* object, which is
83         later passed as parameter of addDictionary signal*/
84     void addNewDictButtonClicked();
85
86     /*! Passes dictionary selected from list as parameter of removeDictionary
87         signal */
88     void removeButtonClicked();
89
90     //! user select one of items
91     void itemSelected(QListWidgetItem*);
92
93     //! Shows plugin's settings dialog
94     void settingsButtonClicked();
95
96     //! Each change of state (that needs to be saved) should call this to
97     //! indicate state change
98     void changed();
99
100     //! saves changes
101     void saveChanges();
102
103 private:
104     void initalizeUI();
105     QPushButton* addNewDictButton;
106     QPushButton* removeDictButton;
107     QPushButton* settingsButton;
108
109     QVBoxLayout* verticalLayout;
110     QHBoxLayout* buttonGroup;
111     QListWidget* dictListWidget;
112
113     //holds association between items on list and CommonDictInterface objects
114     QHash<QListWidgetItem*, CommonDictInterface*> dictsHash;
115     GUIInterface* guiInterface;
116
117     bool _changed;
118
119     void refreshDictsList();
120
121     #ifndef Q_WS_MAEMO_5
122         QPushButton* closeButton;
123         bool _save;
124     #endif
125 };
126
127 #endif // DICTMANAGERWIDGET_H