1 /** \file TocMainToolbar.h
2 * \brief Declaration of TocMainToolbar class
4 * Tieto Open Communicator - Client for the Telepathy communications framework.
5 * Copyright (c) 2010, Tieto Corporation
8 * Redistribution and use in source and binary forms, with or without modification,
9 * are permitted provided that the following conditions are met:
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.
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.
32 #ifndef TOCMAINTOOLBAR_H
33 #define TOCMAINTOOLBAR_H
36 #include <QWidgetAction>
37 #include <QHBoxLayout>
51 /** \brief TocMainToolbar class
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.
59 class TocMainToolbar : public QWidget
68 TocMainToolbar( QWidget * parent = 0, Qt::WindowFlags flags = 0 );
75 /** \brief This method is used when new message arives
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.
81 * @param uid Contact's uid
82 * @param name Contact's name
83 * @param presence Contact's current presence
85 void onNewMessage(const QString& uid, const QString& name = "", Presence presence = Unspecified);
87 /** \brief This method is used when current window changes
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).
92 * @param viewType Type of the window
93 * @param text Text to be displayed in notification area
95 void onCurrentView(ViewType viewType, const QString& text = QString() );
97 /** \brief This method is used to handle contacts dislayed name changes
99 * It changes the name of the corresponding action.
101 * @param uid Contact's uid
102 * @param name New contact's name
104 void onDisplayedNameChange(const QString& uid, const QString& name);
106 /** \brief This method is used to handle contacts presence changes
108 * It changes the presence icon of the corresponding action.
110 * @param uid Contact's uid
111 * @param name New contact's name
113 void onContactPresenceUpdate(const QString& uid, Presence presence);
115 /** \brief This method is used to handle account presence changes
117 * It should follow the `presenceUpdated` signal if presence change
120 * @param presence Own presence
121 * @param desc Own presence description
123 void onPresenceUpdate(Presence presence, const QString& desc);
126 /** \brief Used to close all sessions at once
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.
132 void clearAllSessions();
136 /** \brief Emited when user chooses a conversation window from active sessions menu
138 * This signal is emited when user triggers an action in `Active Sessions` menu.
140 * @param uid Contact's ID
141 * @param name Contact's name
143 void activeSessionTriggered(const QString& uid, const QString& name);
145 /** \brief Emited when user closes the chat window
147 * This signal is emited when user chooses to close current chat window.
149 * @param uid Contact's ID for which the window was created
151 void finishedSession(const QString& uid);
153 /** \brief Emited when user closes all chat windows
155 * This signal is emited when user chooses to close all chat windows
156 * using `Close All Sessions` button in `Active Sessions` menu.
158 void finishedAllSessions();
160 /** \brief Emited when user chooses contact list
162 * This signal is emited when user clicks contacts button.
164 void contactsClicked();
166 /** \brief Emited when user chooses settings window
168 * This signal is emited when user clicks settings button.
170 void settingsClicked();
172 /** \brief Emited when user changes presence
174 * This signal is emited when user requests presence change using
175 * presence button's menu.
177 * @param presence Requested presence
178 * @param desc Requested presence description
180 void presenceUpdate(Presence presence, const QString& desc);
184 /** \brief This slot is used when user requests a new session
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.
190 * @param uid Contact's uid
191 * @param name Contact's name
192 * @param presence Contact's current presence
194 void onNewSession(const QString& uid, const QString& name, Presence presence);
198 /** \brief Used to close current session
200 * Connected to the notification area button when in "Close role".
202 void closeCurrentSession();
204 /** \brief Used to close all sessions at once
206 * Connected to the close all sessions action, and closes all sessions in one run.
208 void closeAllSessions();
210 /** \brief Used to return to the last chat window
212 * Connected to the notification area button when in "Return role".
214 void restoreCurrentSession();
216 /** \brief Used when user clicks on a name in active sessions menu
218 * Handles user clicks in action's from active sessions menu,
219 * it does nothing when action is Close All Sessions action.
221 * @param action The action triggered
223 void onActiveSessionTriggered(QAction* pAction);
225 /** \brief Used when user clicks on a presence in presence button's menu
227 * Handles user clicks in action's from presence button's menu.
229 * @param action The action triggered
231 void onTriggeredPresence(QAction* action);
233 /** \brief Used to handle `Contacts Button` click action
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".
240 void onContactsClicked();
242 /** \brief Used to handle `Settings Button` click action
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`.
248 void onSettingsClicked();
253 /** \brief Sets style sheets for each widget
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.
260 /** \brief Returns an action with the given Uid
262 * If the action is not on the list it retruns 0.
264 * @param uid Contact's ID
266 QAction* action( const QString& uid );
268 /** \bried Highlights the selected button
270 * @param button Button to be highlighted
272 void highlightButton(const QPushButton* button);
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
289 ActiveSessions* _pActiveSessions; /// Pointer to an object that manages active sesssions
294 /** \brief ActiveSessions class
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
301 class ActiveSessions: public QWidget
310 ActiveSessions(QWidget * parent = 0);
312 /** \brief It adds an action to _pActiveSessionsMenu
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.
318 * @param pAction action to be added
320 void addAction(QAction *pAction);
322 /** \brief It removes an action from _pActiveSessionsMenu
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.
328 * @param pAction action to be added
330 void removeAction(QAction *pAction);
332 /** \brief Removes currently selected action from the menu selects a new one and returns a pointer to it
335 QAction* closeCurrentSession();
337 /** \brief Returns a disabled action
339 * If there is no disabled action it retruns 0.
341 QAction* disabledAction() const;
343 /** \brief Returns an action with the given Uid
345 * If the action is not on the list it retruns 0.
347 * @param uid Contact's ID
349 QAction* action(const QString& uid) const;
351 /** \brief Returns a list of an actions from _pActiveSessionsMenu
354 QList<QAction*> actions() const;
356 /** \brief Clears all actions from _pActiveSessionsMenu
361 /** \brief Returns a pointer to _pActiveSessionsMenu
364 QMenu* menu() const {return _pActiveSessionsMenu;}
366 /** \brief Handles change of a presence
368 * It resets an icon according to new presence
370 * @param uid Contact's uid
371 * @param presence New presence
373 void onContactPresenceUpdate(const QString& uid, Presence presence);
375 /** \brief Handles new message event
377 * It checks for an action for given uid and eventually creats a new one
379 * @param uid Uid of a contact for which new message come
380 * @param name Contact's name
381 * @param presence Contact's presence
383 void onNewMessage(const QString& uid, const QString& name, Presence presence);
385 /** \brief This slot is used when user requests a new session
387 * This function selects an action with given uid or if it doesn't exist adds it to menu.
389 * @param uid Contact's uid
390 * @param name Contact's name
391 * @param presence Contact's current presence
393 void onNewSession(const QString& uid, const QString& name, Presence presence);
397 /** \brief Enables or disables scroll up and down buttons according to currently visible actions
400 void checkScrollButtonsState();
404 /** \brief Scrolls up actions from _actionsList that are visible in _pActiveSessionsMenu
409 /** \brief Scrolls down actions from _actionsList that are visible in _pActiveSessionsMenu
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
429 /** \brief ScrollWidget class
431 * This small widget was meant as a part of active sessions menu to provide a way to scroll it.
434 class ScrollWidget: public QWidget
442 ScrollWidget(QWidget *parent = 0);
444 QPushButton* scrollUpButton() const { return _pScrollUpButton; }
445 QPushButton* scrollDownButton() const { return _pScrollDownButton; }
448 QPushButton* _pScrollUpButton;
449 QPushButton* _pScrollDownButton;
450 QHBoxLayout* _pLayout;
456 #endif // TOCMAINTOOLBAR_H