Initial commit
[tietoopcom] / include / TocUi / tocmaintoolbar.h
1 /** \file TocMainToolbar.h
2  * \brief Declaration of TocMainToolbar 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 TOCMAINTOOLBAR_H
33 #define TOCMAINTOOLBAR_H
34
35 #include <QWidget>
36 #include <QWidgetAction>
37 #include <QHBoxLayout>
38
39 #include "defs.h"
40 #include "uidefs.h"
41
42 class QPushButton;
43 class QMenu;
44 class QAction;
45 class QLabel;
46 class ActiveSessions;
47 class ScrollWidget;
48
49 QT_BEGIN_NAMESPACE
50
51 /** \brief TocMainToolbar class
52  * 
53  * Applications  main toolbar used to control window switching, presence changes
54  * and management of active chat windows.
55  * It also shows current activity name, notifies about incoming messages
56  * and allows to quickly switch between converstion and contact list and back.
57  * The main toolbar is allways visible in applications window.
58  */
59 class TocMainToolbar : public QWidget
60 {
61         Q_OBJECT
62
63 public:
64
65         /**
66          * Public Constructor
67          */
68         TocMainToolbar( QWidget * parent = 0, Qt::WindowFlags flags = 0 );
69
70         /**
71          * Destructor
72          */
73         ~TocMainToolbar();
74         
75         /** \brief This method is used when new message arives
76          * 
77          * When the message arives, `Active Sessions` button should notify this
78          * by changing color of the button and the corresponding menu action.
79          * If action doesn't exist, it must create it.
80          * 
81          * @param uid Contact's uid
82          * @param name Contact's name
83          * @param presence Contact's current presence
84          */
85         void onNewMessage(const QString& uid, const QString& name = "", Presence presence = Unspecified);
86         
87         /** \brief This method is used when current window changes
88          * 
89          * It is used only if window changes without the knowledge of TocMainToolbar
90          * (i.e. when not triggered by toolbar but by settings window or contact list).
91          * 
92          * @param viewType Type of the window
93          * @param text Text to be displayed in notification area
94          */
95         void onCurrentView(ViewType viewType, const QString& text = QString() );
96         
97         /** \brief This method is used to handle contacts dislayed name changes
98          * 
99          * It changes the name of the corresponding action.
100          * 
101          * @param uid Contact's uid
102          * @param name New contact's name
103          */
104         void onDisplayedNameChange(const QString& uid, const QString& name);
105         
106         /** \brief This method is used to handle contacts presence changes
107          * 
108          * It changes the presence icon of the corresponding action.
109          * 
110          * @param uid Contact's uid
111          * @param name New contact's name
112          */
113         void onContactPresenceUpdate(const QString& uid, Presence presence);
114         
115         /** \brief This method is used to handle account presence changes
116          * 
117          * It should follow the `presenceUpdated` signal if presence change
118          * was succesfull.
119          * 
120          * @param presence Own presence
121          * @param desc Own presence description
122          */
123          void onPresenceUpdate(Presence presence, const QString& desc);
124
125          
126          /** \brief Used to close all sessions at once
127           * 
128           * Closes all sessions at once on request from outside of the toolbar.
129           * Typicaly useful when user changes account data
130           * and the previous sessions needs to be cleared.
131           */
132          void clearAllSessions();
133
134 signals:
135
136         /** \brief Emited when user chooses a conversation window from active sessions menu
137          * 
138          * This signal is emited when user triggers an action in `Active Sessions` menu.
139          * 
140          * @param uid Contact's ID
141          * @param name Contact's name
142          */
143         void activeSessionTriggered(const QString& uid, const QString& name);
144
145         /** \brief Emited when user closes the chat window
146          * 
147          * This signal is emited when user chooses to close current chat window.
148          * 
149          * @param uid Contact's ID for which the window was created
150          */
151         void finishedSession(const QString& uid);
152
153         /** \brief Emited when user closes all chat windows
154          * 
155          * This signal is emited when user chooses to close all chat windows
156          * using `Close All Sessions` button in `Active Sessions` menu.
157          */
158         void finishedAllSessions();
159
160         /** \brief Emited when user chooses contact list
161          * 
162          * This signal is emited when user clicks contacts button.
163          */
164         void contactsClicked();
165
166         /** \brief Emited when user chooses settings window
167          * 
168          * This signal is emited when user clicks settings button.
169          */
170         void settingsClicked();
171
172         /** \brief Emited when user changes presence 
173          * 
174          * This signal is emited when user requests presence change using
175          * presence button's menu.
176          * 
177          * @param presence Requested presence
178          * @param desc Requested presence description
179          */
180         void presenceUpdate(Presence presence, const QString& desc);
181
182 public slots:
183
184         /** \brief This slot is used when user requests a new session
185          * 
186          * When new session is started at user request, main toolbar should react for this
187          * by displaying the name of a contact and disabling the corresponding menu action.
188          * If action doesn't exist, main toolbar must create it.
189          * 
190          * @param uid Contact's uid
191          * @param name Contact's name
192          * @param presence Contact's current presence
193          */
194         void onNewSession(const QString& uid, const QString& name, Presence presence);
195
196 private slots:
197
198         /** \brief Used to close current session
199          * 
200          * Connected to the notification area button when in "Close role".
201          */
202         void closeCurrentSession();
203
204         /** \brief Used to close all sessions at once
205          * 
206          * Connected to the close all sessions action, and closes all sessions in one run.
207          */
208         void closeAllSessions();
209
210         /** \brief Used to return to the last chat window
211          * 
212          * Connected to the notification area button when in "Return role".
213          */
214         void restoreCurrentSession();
215
216         /** \brief Used when user clicks on a name in active sessions menu
217          * 
218          * Handles user clicks in action's from active sessions menu,
219          * it does nothing when action is Close All Sessions action.
220          * 
221          * @param action The action triggered
222          */ 
223         void onActiveSessionTriggered(QAction* pAction);
224
225         /** \brief Used when user clicks on a presence in presence button's menu
226          * 
227          * Handles user clicks in action's from presence button's menu.
228          * 
229          * @param action The action triggered
230          */ 
231         void onTriggeredPresence(QAction* action);
232         
233         /** \brief Used to handle `Contacts Button` click action
234          * 
235          * If user clicks `Contacts Button` the toolbar should change
236          * the `Label Button` text to "" and disable it, but if there is chat window active
237          * the `Label Button` should display Name of the Contact the chat is active for,
238          * and change it's mode to "Restore Chat".
239          */
240         void onContactsClicked();
241         
242         /** \brief Used to handle `Settings Button` click action
243          * 
244          * If user clicks `Contacts Button` the toolbar should change
245          * the `Label Button` text to "Settings" and disable it.
246          * It should also disconnect all the connections made for `Label Button`.
247          */
248         void onSettingsClicked();
249
250         
251 private: // Methods
252         
253         /** \brief Sets style sheets for each widget
254          * 
255          * Used to overload style sheet properties that could come from main style sheet,
256          * to forbid corruption of the application layout from the external style sheets. 
257          */
258         void setupStyles();
259         
260         /** \brief Returns an action with the given Uid
261          * 
262          * If the action is not on the list it retruns 0.
263          * 
264          * @param uid Contact's ID
265          */
266         QAction* action( const QString& uid );
267         
268         /** \bried Highlights the selected button
269          * 
270          * @param button Button to be highlighted
271          */
272         void highlightButton(const QPushButton* button);
273
274 private: // Members
275
276         QPushButton*    statusButton;                   /// Button for the presence menu
277         QPushButton*    statusAreaButton;               /// Notification area button ("Eduardo button")
278         QLabel*                 statusAreaLabel;                /// Notification area label ("Eduardo label")
279         QPushButton*    activeSessionsButton;   /// Button for the active sessions menu
280         QPushButton*    settingsButton;                 /// Settings button
281         QPushButton*    contactsButton;                 /// Contact list button
282         QMenu*                  statusMenu;                             /// Status selection menu
283         QAction*                onlineAction;                   /// Action for online presence
284         QAction*                awayAction;                             /// Action for away presence
285         QAction*                busyAction;                             /// Action for busy presence
286         QAction*                hiddenAction;                   /// Action for hidden presence
287         QAction*                offlineAction;                  /// Action for offline presence
288         
289         ActiveSessions* _pActiveSessions;               /// Pointer to an object that manages active sesssions
290         
291 };
292
293
294 /** \brief ActiveSessions class
295  * 
296  * Class that encapsulates active sessions menu. The main role of this class it to ensure that 
297  * there aren't to many actions displayed on the screen at the same time and allows to scroll
298  * them. 
299  */
300
301 class ActiveSessions: public QWidget
302 {
303         Q_OBJECT
304         
305 public:
306
307         /**
308          * Public Constructor
309          */
310         ActiveSessions(QWidget * parent = 0);
311         
312         /** \brief It adds an action to _pActiveSessionsMenu
313          * 
314          * When adding new action this function takes into account how many actions can be shown 
315          * at the same time (_visibleActionsAllowed) and also when to show additional itmes like
316          * _pCloseAllSessionsAction or _pScrollAction.
317          * 
318          * @param pAction action to be added
319          */
320         void addAction(QAction *pAction);
321         
322         /** \brief It removes an action from _pActiveSessionsMenu
323          * 
324          * When removing an action this function takes into account how many actions can be shown 
325          * at the same time (_visibleActionsAllowed) and also when to show additional itmes like
326          * _pCloseAllSessionsAction or _pScrollAction.
327          * 
328          * @param pAction action to be added
329          */
330         void removeAction(QAction *pAction);
331         
332         /** \brief Removes currently selected action from the menu selects a new one and returns a pointer to it
333          * 
334          */
335         QAction* closeCurrentSession();
336
337         /** \brief Returns a disabled action
338          * 
339          * If there is no disabled action it retruns 0.
340          */
341         QAction* disabledAction() const;
342         
343         /** \brief Returns an action with the given Uid
344          * 
345          * If the action is not on the list it retruns 0.
346          * 
347          * @param uid Contact's ID
348          */
349         QAction* action(const QString& uid) const;
350         
351         /** \brief Returns a list of an actions from _pActiveSessionsMenu
352          * 
353          */
354         QList<QAction*> actions() const;
355         
356         /** \brief Clears all actions from _pActiveSessionsMenu
357          * 
358          */
359         void clear();
360         
361         /** \brief Returns a pointer to _pActiveSessionsMenu
362          * 
363          */
364         QMenu* menu() const {return _pActiveSessionsMenu;} 
365         
366         /** \brief Handles change of a presence
367          * 
368          * It resets an icon according to new presence
369          * 
370          * @param uid Contact's uid
371          * @param presence New presence 
372          */
373         void onContactPresenceUpdate(const QString& uid, Presence presence);
374         
375         /** \brief Handles new message event
376          * 
377          * It checks for an action for given uid and eventually creats a new one
378          * 
379          * @param uid Uid of a contact for which new message come
380          * @param name Contact's name 
381          * @param presence Contact's presence 
382          */
383         void onNewMessage(const QString& uid, const QString& name, Presence presence);
384         
385         /** \brief This slot is used when user requests a new session
386          * 
387          * This function selects an action with given uid or if it doesn't exist adds it to menu.
388          * 
389          * @param uid Contact's uid
390          * @param name Contact's name
391          * @param presence Contact's current presence
392          */
393         void onNewSession(const QString& uid, const QString& name, Presence presence);  
394         
395 private:
396
397         /** \brief Enables or disables scroll up and down buttons according to currently visible actions
398          * 
399          */
400         void checkScrollButtonsState(); 
401
402 private slots:
403
404         /** \brief Scrolls up actions from _actionsList that are visible in _pActiveSessionsMenu
405          * 
406          */
407         void scrollUp();
408         
409         /** \brief Scrolls down actions from _actionsList that are visible in _pActiveSessionsMenu
410          * 
411          */     
412         void scrollDown();
413         
414 private:
415         
416         QMenu*                                          _pActiveSessionsMenu;           /// Menu for chat window selection
417         QAction*                                        _pCloseAllSessionsAction;       /// Action to close all active sessions
418         QAction*                                        _pSeparatorAction;                      /// Action for separator
419         QWidgetAction*                          _pScrollAction;                         /// Action from _pActiveSessionsMenu that is associated with _pScrollWidget
420         ScrollWidget*                           _pScrollWidget;                         /// Widget with two buttons that enables scrolling
421         QList<QAction*>                         _actionsList;                           ///     List of actions that not includes 'Close all', separator and scroll
422         const int                                       _visibleActionsAllowed;         /// Variable that limits amount of active session actions present on _pActiveSessionsMenu
423         QList<QAction*>::iterator       _firstVisibleAction;            /// Iterator that is fixed on first active session action from _pActiveSessionsMenu
424         QList<QAction*>::iterator       _lastVisibleAction;                     /// Iterator that is fixed on last active session action from _pActiveSessionsMenu
425         
426 };
427
428
429 /** \brief ScrollWidget class
430  * 
431  * This small widget was meant as a part of active sessions menu to provide a way to scroll it. 
432  */
433
434 class ScrollWidget: public QWidget
435 {
436         Q_OBJECT
437         
438 public:
439         /**
440          * Public Constructor
441          */
442         ScrollWidget(QWidget *parent = 0);
443         
444         QPushButton*    scrollUpButton() const { return _pScrollUpButton; }
445         QPushButton*    scrollDownButton() const { return _pScrollDownButton; } 
446         
447 private:
448         QPushButton*    _pScrollUpButton;
449         QPushButton*    _pScrollDownButton;
450         QHBoxLayout*    _pLayout;
451 };
452
453
454 QT_END_NAMESPACE
455
456 #endif // TOCMAINTOOLBAR_H