Initial commit
[tietoopcom] / include / TocUi / tocmainwindow.h
1 /** \file TocMainWindow.h
2  * \brief Declaration of TocMainWindow 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 TOCMAINWINDOW_H
33 #define TOCMAINWINDOW_H
34
35 #include <QMainWindow>
36 #include <QListWidgetItem>
37 #include "TocBaseMainWindow"
38 #include "defs.h"
39
40 class TocBaseEngine;
41 class QStackedLayout;
42 class TocChatWidget;
43 class TocMainToolbar;
44 class TocContactListWidget;
45 class TocUserInfoWidget;
46 class TocSettingsWidget;
47 class TocGeneralSettingsWidget;
48 class TocAccountSettingsWidget;
49 class TocAccountIntermediateWidget;
50 class TocNetworkSettingsWidget;
51 class TocThemesSettingsWidget;
52 class QCloseEvent;
53
54 QT_BEGIN_NAMESPACE
55
56 /** \brief TocMainWindow class
57  * 
58  * Class responsible for user GUI management
59  * and for communication with TocEngine.
60  */
61 class TocMainWindow : public TocBaseMainWindow
62 {
63         Q_OBJECT
64         Q_CLASSINFO("D-Bus Interface", "org.indt.tietoopcom")
65
66 public:
67
68         /**
69          * Public Constructor
70          */
71         TocMainWindow( TocBaseEngine* engine, QWidget * parent = 0, Qt::WindowFlags flags = 0 );
72
73         /**
74          * Destructor
75          */
76         ~TocMainWindow();
77
78 protected:
79         
80         /** \brief Reimplemented from QWidget
81          * 
82          */
83         virtual void closeEvent(QCloseEvent* event);
84         
85 public slots:
86         Q_SCRIPTABLE int top_application();
87         
88 protected slots:
89
90         /** \brief Reimplemented from TocBaseMainWindow
91          * 
92          */
93         void onAuthorizationRequest(QString uid);
94         
95         /** \brief Reimplemented from TocBaseMainWindow
96          * 
97          */
98         void onSubscriptionAccepted(QString uid);
99         
100         /** \brief Reimplemented from TocBaseMainWindow
101          * 
102          */
103         void onStatusChange(Status status, Reason reason);
104
105         /** \brief Reimplemented from TocBaseMainWindow
106          * 
107          */
108         void onPresenceUpdate(Presence presence, QString desc);
109
110         /** \brief Reimplemented from TocBaseMainWindow
111          * 
112          */
113         void onContactPresenceUpdate(QString uid, Presence presence, QString desc);
114
115         /** \brief Reimplemented from TocBaseMainWindow
116          * 
117          */
118         void onIncomingMessage(QString uid, Message message);
119         
120         /** \brief Reimplemented from TocBaseMainWindow
121          * 
122          */
123         void onContactListReceived(const TocContactList& cList);        
124
125 private slots:
126
127         /** \brief Shows chat window for the given Uid
128          * 
129          * If the chat with Uid is already created, just show it,
130          * if not, create a chat with the given Uid and Name
131          * and emit newSessionStarted(Uid) signal.
132          * Note that this is overloaded SLOT, take caution with that.
133          * 
134          * @param uid Contact's ID
135          * @param name Contact's name
136          * @param presence Contact's current presence
137          */
138         void showChat(const QString& uid, const QString& name, Presence presence = Offline);
139
140
141         /** \brief Closes a chat for the given Uid
142          * 
143          * This slot closes a chat for the given Uid
144          * and emits sessionClosed(Uid) signal to the engine.
145          * 
146          * @param uid Contact's ID
147          */
148         void closeChat(const QString& uid);
149
150         /** \brief Closes all active chat windows
151          * 
152          * This slot closes all open chat windows
153          * and emits sessionClosed(Uid) signal for each chat.
154          */
155         void closeAllOpenChats();
156
157         /** \brief Closes all active chat windows
158          * 
159          * This slot closes and deletes all created chat windows
160          * and emits sessionClosed(Uid) signal for each chat.
161          * This is typicaly useful when user changes account data.
162          */
163         void clearAllChats();
164
165         /** \brief Shows window of a given type
166          * 
167          * Shows a TocWidget of the type == ViewType (except for TocChatWidget)
168          * `ViewType` is static-casted to `int` in a signal emission in the TocSettingsWidget
169          * si it could use a QSignalMapper class.
170          * 
171          * @param type Type of the view to be shown 
172          */
173         void showView(/*ViewType*/int type);
174
175         /** \brief Shows TocUserInfoWidget
176          * 
177          * Creates and displays TocUserInfoWidget with the data provided by the signal.
178          * 
179          * @param item Item with contact's data (*item==QListWidgetItem() if You want TocUserInfoWidget to be run in "Add mode")
180          */
181         void showUserInfo(QListWidgetItem* item);
182         
183         /** \brief Shows TocContactListWidget
184          * 
185          * Displays TocContactListWidget.
186          */
187         void showContacts();
188         
189         /** \brief Shows TocContactListWidget
190          * 
191          * Displays TocContactListWidget.
192          * Also informs TocMainToolbar about the change.
193          */
194         void returnToContacts();
195         
196         /** \brief Shows TocSettingsWidget
197          * 
198          * Creates if necessary and displays TocSettingsWidget.
199          */
200         void showSettings();
201         
202         /** \brief Shows TocSettingsWidget
203          * 
204          * Displays TocSettingsWidget .
205          * Also informs TocMainToolbar about the change.
206          */
207         void returnToSettings();
208         
209         /** \brief Shows TocAccountSettingsWidget
210          * 
211          * Creates if necessary and displays TocAccountSettingsWidget.
212          */
213         void showAccount();
214         
215         /** \brief Shows TocAccountIntermediateWidget
216          * 
217          * Creates if necessary and displays TocAccountIntermediateWidget .
218          */
219         void returnToIntermediate();
220
221         /** \brief Shows TocAccountSettingsWidget in `Create mode`
222          * 
223          * Creates if necessary and displays TocAccountSettingsWidget.
224          * When user clicks `Create` button the account settings are
225          * saved in TocSettings and the `_register` flag of TocSettings is set to "true".
226          */
227         void showAccountCreate();
228         
229         /** \brief Changes the displayed name in the application on user request
230          * 
231          * If a user changes the displayed name using TocUserInfoView in editing mode
232          * the slot changes the name in the TocContactListWidget and, if needed,
233          * in TocMainToolbar and TocChatWidget.
234          * 
235          * @param uid Contact's ID
236          * @param name Contact's new name
237          */
238         void onDisplayedNameChange(const QString& uid, const QString& name);    
239
240         /** \brief Reloads the displayed application theme
241          * 
242          * Reads file URL from settings and sets the stylesheet as the current one.
243          */     
244         void reloadTheme();
245
246         /** \brief This slot prepares Toc for the account details change
247          * 
248          * It disconnects, clears the contact list and active sessions list.
249          */
250         void onAccountSettingsChanged();
251
252         /** \brief This slot prepares Toc for the new account creation
253          * 
254          * It disconnects, clears the contact list and active sessions list.
255          * Then it connects with the `_register` parameter set to true,
256          * when the connection is successfull the account has been created.
257          */
258         void onAccountSettingsCreated();
259
260         /** \brief Shows About info widget
261          * 
262          */
263         void showAbout();
264         
265 private: // Methods
266
267         /** \brief Returns cached TocChatWidget for the given Uid
268          * 
269          * If there is a chached chat with the given uid then
270          * it returns pointer to this chat, if not it returns 0.
271          * 
272          * @param uid Contact's ID
273          * @return Pointer to the chached TocChatWidget or 0 if there is no active chat.
274          */
275         TocChatWidget* chatForUid(const QString& uid);
276
277         /** \brief Returns active/open TocChatWidget for the given Uid
278          * 
279          * If there is a active/open chat with the given uid then
280          * it returns pointer to this chat, if not it returns 0.
281          * 
282          * @param uid Contact's ID
283          * @return Pointer to the active/open TocChatWidget or 0 if there is no active chat.
284          */
285         TocChatWidget* openChatForUid(const QString& uid);
286
287         /** \brief Checks if this is FTU
288          * 
289          * returns true if settings on which FirstTimeUse case is based, are empty
290          * 
291          * @return bool value indicating FTU use case
292          */
293         bool isFtu();
294
295         /** \brief Returns an error string for the given error
296          * 
297          * @param reason Reason of the error
298          * @return Human readable error string
299          */
300         QString errorString(Reason reason);
301
302 private: // Members
303         QString                         _defaultStyle;          /// Default application style sheet
304
305         QList<TocChatWidget*>*          _pChatList;             /// List of cached chat widgets
306         QList<TocChatWidget*>*          _pOpenChatList;         /// List of active/open chat widgets
307         TocMainToolbar*                 _pMainToolbar;          /// Pointer to a toolbar that allows user to control the UI
308         QStackedLayout*                 _pMainLayout;           ///     Layout displaying all the "following" widgets
309         QWidget*                        _pCentralWidget;        /// Main Window's Central Widget 
310         TocContactListWidget*           _pContactList;          /// Widget displaying list of contacts 
311         TocUserInfoWidget*              _pUserInfoWidget;       /// Widget displaying contact info
312         TocSettingsWidget*              _pSettingsWidget;       /// Widget displaying settings window
313         TocGeneralSettingsWidget*       _pGeneralWidget;        /// Widget displaying general settings
314         TocAccountSettingsWidget*       _pAccountWidget;        /// Widget displaying account settings
315         TocAccountIntermediateWidget*   _pIntermediateWidget;   /// Widget that lets user to choose account settings mode 
316         TocThemesSettingsWidget*        _pThemesWidget;         /// Widget displaying themes setting
317         bool                            _register;              /// Flag indicating if TietoOpCom is in "Create Account Mode"
318 };
319
320 QT_END_NAMESPACE
321
322 #endif // TOCMAINWINDOW_H