1 /** \file TocContactListWidget.h
2 * \brief Declaration of TocContactListWidget 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 TOCCONTACTLISTWIDGET_H
33 #define TOCCONTACTLISTWIDGET_H
35 #include <QtGui/QListWidget>
40 #include "TocSettings"
44 /** \brief TocContactListWidget class
46 * Widget representing the list of current account contact's.
47 * QListWidget is used in `IconMode`, and allows user to show a unique
48 * avatar for each contact. It allows user to delete add and change contact's data,
49 * and to start conversation with the contact.
51 class TocContactListWidget : public QListWidget
54 // Property holding color of the logo.
55 // It's a Q_PROPERTY to enable easy setting of the color with style sheet's.
56 Q_PROPERTY(QColor logoColor READ logoColor WRITE setLogoColor NOTIFY logoColorChanged)
63 TocContactListWidget( QWidget * parent = 0 );
68 ~TocContactListWidget();
70 /** \brief Method used when contact's presence has changed
72 * This method handles presence change of a contact.
74 * @param uid Contact's ID
75 * @param presence Contact's new presence
76 * @param description Contact's new presence description
78 void onContactPresenceUpdate(const QString& uid, Presence presence, const QString& description);
80 /** \brief This method translates Contact's ID to its Name
82 * This method is used when TocMainWindow needs the Name for
83 * the given Uid, in order to create a new TocChatWidget.
85 * @param uid Contact's ID
86 * @return Displayed Name of the contact
88 QString getDisplayedName(const QString& uid);
90 /** \brief This method is used to find specific contact on the list by contact's uid
92 * It searches for the user in contact list and returns it's item,
93 * if there is no such contact it returns 0. It's possible to exlude particular
94 * item from search. It's used when editing an exisiting contact because contact data
95 * are associated with the same QListWidgetItem pointer.
97 * @param item Item to be excluded from searching
98 * @param uid Contact's ID
99 * @param pExcludedItem Item from the list
100 * @return Pointer to found item
102 QListWidgetItem* findItem(const QString& uid, const QListWidgetItem* pExcludedItem = 0);
104 /** \brief Clears statuses of contacts
106 * Typicaly used to clear statuses after setting the self-status to Offline
108 void clearStatuses();
110 /** \brief Getter for logoColor property
113 QColor logoColor() const;
115 /** \brief Setter for logoColor property
118 void setLogoColor(QColor rgb);
122 /** \brief Implementation of the interface that allows to handle mouse double click event
124 void mouseDoubleClickEvent(QMouseEvent *event);
126 /** \brief Implementation of the interface that allows to handle context menu event
128 * It creates context menu for managing contact items on the list.
130 void contextMenuEvent(QContextMenuEvent *event);
132 /** \brief Implementation of the interface that allows to handle custom paint events
134 * It allows to paint Tieto logo in contact list view.
136 void paintEvent(QPaintEvent * event);
141 /** \brief Emited when user chooses a contact to chat with
143 * This signal is emited when user selects and then clicks an item on the list.
145 * @param uid Contact's ID
146 * @param name Contact's name
147 * @param presence Contact's presence
150 void triggered(const QString& uid, const QString& name, Presence presence);
152 /** \brief Emited when user requests to see a contact info
154 * This signal is emited when user selects to edit contact's data
155 * or if the user wants to add new contact to the list ( then *item == QListWidgetItem() ).
157 * @param pItem Contact item to be edited or added
159 void contactInfoRequest(QListWidgetItem* pItem);
161 /** \brief Emited when contact is removed
163 * This signal is emited when user wants to delete the contact with given Uid.
164 * Note that the contact should be already deleted from the TocListWidget
165 * before it's emision.
167 * @param uid Contact's ID
169 void removedContact(const QString& uid);
171 /** \brief Emited when user commits the changes
173 * This signal is emited when user finished adding contact.
175 * @param pContact Pointer to a contact to be added.
177 void addContact(TocContact* pContact);
179 /** \brief Emited when user commits the changes
181 * This signal is emited when user finished editing contact data.
183 * @param pContact Pointer to a contact to be altered.
184 * @param oldUid Previous ID of a contact (omited if widget is in "Add Mode")
186 void editContact(TocContact* pContact, QString oldUid);
188 /** \brief Emited when name of the contact has been changed
190 * This signal is emited to notify that user chas changed the displayed name
191 * of the contact so it can be used to change the name at runtime
192 * in TocChatWindow and in active sessions menu of TocMainToolbar.
194 * @param uid Contact's ID
195 * @param name New displayed name of the contact
197 void displayedNameChanged( const QString& uid, const QString& name);
199 /** \brief Emited when name of the logoCount property has been changed
201 * When logoCount property is changed, this signal is emited, with new value as a parameter.
203 * @param rgb new value of logoColor property
205 void logoColorChanged(QColor rgb);
209 /** \brief Used to set a contact list to the widget
211 * This slot is used when a new TocContactList has arived from TocEngine.
212 * Data from the list should be copied to QListWidgetItem's.
214 * @param contactList New contact list to be handled
216 void onNewContactList(const TocContactList& contactList);
218 /** \brief Used when user finishes editing new contact data
220 * This slot is used when user actualy commits new contact's addition
221 * from the TocUserInfoWidget. It adds created item to the contact list.
223 * @param pNewItem Item to be added
225 void commitAdd(QListWidgetItem* pNewItem);
227 /** \brief Used when user finishes edition of contact data
229 * This slot is used when user actualy commits changes to the contact
230 * from the TocUserInfoWidget.
232 * @param pEditedItem Item with changed data
234 void commitEdit(QListWidgetItem* pEditedItem);
238 /** \brief Slot that reacts on Edit action from context menu
240 * It extracts QListWidgetItem from sender and posts it to UserInfoWidget
243 void onEditRequested();
245 /** \brief Slot that reacts on Remove action from context menu
247 * It extracts QListWidgetItem from sender, removes it from the contacts list
248 * and notifies engine about it.
250 void onRemoveRequested();
252 /** \brief Slot that sets the color of the logo
254 * This method paints the logo with the color provided.
256 * @param rgb Color to be set for the logo
258 void changeLogoColor(QColor rgb);
262 /** \brief Sorts all the items in the list widget
264 * This method sorts all the items in the list widget according to
265 * the specified order.
266 * TODO: only Literal sorting is now implemented, implement other methods as well
268 * @param order Order to sort by
270 void sortItems(SortOrder order = Alphabetical);
274 TocContact _currentEditedContact; /// Temporary TocContact used in the process of editing an item
275 QListWidgetItem* _pCurrentEditedItem; /// Temporary item used in the process of editing an item
276 QAction _editAction; /// An action from context menu that triggers edition of selected item. It's connected to onEditRequested() slot
277 QAction _removeAction; /// An action from context menu that triggers deletion of selected item. It's connected to onRemoveRequested() slot
278 QImage* _logo; /// Logo image mask. Created inside constructor.
279 QColor _logoColor; /// Color in RGB of the logo. (Q_PROPERTY logoColor)
284 #endif // TOCCONTACTLISTWIDGET_H