Initial commit
[tietoopcom] / include / TocUi / tocaccountsettingswidget.h
1 /** \file TocAccountSettingsWidget.h
2  * \brief Declaration of TocAccountSettingsWidget class
3  * 
4  * Tieto Open Communicator - Client for the Telepathy communications framework.
5  * Copyright (c) 2010, Tieto Corporation
6  *
7  * All rights reserved.
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  *      Redistributions of source code must retain the above copyright notice,
12  *      this list of conditions and the following disclaimer.
13  *      Redistributions in binary form must reproduce the above copyright notice,
14  *      this list of conditions and the following disclaimer in the documentation
15  *      and/or other materials provided with the distribution.
16  *      Neither the name of the Tieto Corporation nor the names of its contributors 
17  *      may be used to endorse or promote products derived from this software without
18  *      specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  * 
30  */
31
32 #ifndef TOCACCOUNTSETTINGSWIDGET_H
33 #define TOCACCOUNTSETTINGSWIDGET_H
34
35 #include <QWidget>
36 #include "defs.h"
37
38 class Ui_TocAccountSettingsWidgetClass;
39
40 QT_BEGIN_NAMESPACE
41
42 /** \brief TocAccountSettingsWidget class
43  * 
44  * Configuration window for account settings. 
45  */
46 class TocAccountSettingsWidget : public QWidget
47 {
48         Q_OBJECT
49
50 public:
51
52         /**
53          * Public Constructor
54          */
55         TocAccountSettingsWidget( QWidget * parent = 0, Qt::WindowFlags flags = 0 );
56
57         /**
58          * Destructor
59          */
60         ~TocAccountSettingsWidget();
61
62         /** \brief Virtual method called when widget is about to be shown
63          * 
64          * Overloaded method used to reload account list, when widget is shown
65          * 
66          * @param type of show event
67          */
68         void showEvent(QShowEvent *event);      
69         
70         /** \brief Checks wheter or not widget is in Ftu mode
71          * 
72          * Returns true if `Create mode` is enabled, otherwise false
73          * 
74          */
75         inline bool createMode() const;
76
77         /** \brief Allows enabling/disabling Create mode during runtime
78          * 
79          * Method for switching `Create mode` on and off
80          * 
81          * @param bool create Indicates if widget should enter Create mode
82          */
83         void setCreateMode( bool create );
84
85         /** \brief Connects server and protocol hints
86          * 
87          * Used to enable server and protocol hints
88          */
89         void connectHints();
90
91
92 signals:
93
94         /** \brief Emited when user clicks 'Ok' button
95          * 
96          * This signal is emited when user changes settings by pressing 'Ok' button
97          * and new settings differs from previous.
98          * Settings of account are already changed, when signal is emitted.
99          * 
100          */
101         void accountSettingsChanged();
102
103         /** \brief Emited when user clicks 'Create' button during `Create mode`
104          * 
105          * This signal is emited when user creates settings by pressing 'Create' button.
106          * Settings of account are already saved, when signal is emitted.
107          * 
108          */
109         void newAccountSettingsCreated();
110
111         /** \brief Emited when user clicks 'Ok' or 'Create' button
112          * 
113          * This signal is emited when user chooses to close widget by pressing 'Ok' or 'Create' button
114          * regardless if current account was changed.
115          *
116          */
117         void finished();
118
119         /** \brief Emited when user wants to go to the previous screen
120          * 
121          */
122         void backClicked();
123
124 public slots:
125
126         /** \brief Reloads accounts list
127          * 
128          * This method is used to reload account data when it has changed.
129          * 
130          */
131         void reload();
132
133 private slots:
134
135         /** \brief Commits new data 
136          * 
137          * Verifies data and either triggers creation of new account or stores altered data. 
138         */
139         void onOkButton();
140
141         /** \brief Allows to change password 
142          * 
143          * Shows layout for password change.
144         */
145         void onChangePasswordButton();
146         
147         /** \brief Connected to textEdited signal from loginLineEdit 
148          * 
149          * Sets text for serverLineEdit and portLineEdit according to new login 
150          * 
151          * @param newLogin new login received from signal
152         */      
153         void loginEdited(const QString& newLogin);
154
155         /** \brief Connected to currentIndexChanged signal from protocolComboBox 
156          * 
157          * Sets text for serverLineEdit and portLineEdit according to new protocol 
158          * 
159          * @param newProtocol new protocol name received from signal
160         */      
161         void protocolEdited(const QString& newProtocol);
162         
163         /** \brief Disconnects server and protocol hints
164          * 
165          * Used to disable server and protocol hints when user already changed the server
166          * (It would be annoying if hints reset his personaly chosen server and port) 
167          */
168         void disconnectHints();
169
170 private: // Methods
171
172         /** \brief Displays error message 
173          * 
174          * @param errorText text of error to be displayed
175          */
176         void handleError(QString errorText);
177         
178         /** \brief Validates corectness of entered data
179          * 
180          * @return True if data is corect
181          */     
182         bool dataVerified();
183
184         /** \brief Saves edited data
185          * 
186          * If no property was changed it does nothing
187          */
188         void saveAccountData();
189
190         /** \brief Creates new account from the data
191          * 
192          */
193         void createNewAccount();
194
195 private: // Members
196
197         Ui_TocAccountSettingsWidgetClass* ui;           /// Ui definition header
198         bool _bCreateMode;                                                      /// Tells if widget is in `Create mode`
199         
200 };
201
202 QT_END_NAMESPACE
203
204 #endif // TOCACCOUNTSETTINGSWIDGET_H