Merge branch 'master' into situare_interact
[situare] / src / ui / friendlistpanel.h
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Kaj Wallin - kaj.wallin@ixonos.com
6         Henri Lampela - henri.lampela@ixonos.com
7         Pekka Nissinen - pekka.nissinen@ixonos.com
8         Jussi Laitinen - jussi.laitinen@ixonos.com
9         Sami Rämö - sami.ramo@ixonos.com
10
11     Situare is free software; you can redistribute it and/or
12     modify it under the terms of the GNU General Public License
13     version 2 as published by the Free Software Foundation.
14
15     Situare is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19
20     You should have received a copy of the GNU General Public License
21     along with Situare; if not, write to the Free Software
22     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
23     USA.
24 */
25
26 #ifndef FRIENDLISTPANEL_H
27 #define FRIENDLISTPANEL_H
28
29 #include "panelbase.h"
30
31 class QLabel;
32 class QLineEdit;
33 class QPushButton;
34
35 class FriendListItemDelegate;
36 class FriendListView;
37 class GeoCoordinate;
38 class ImageButton;
39 class User;
40
41 /**
42  * @brief Class for sliding friends list panel
43  *
44  * @author Kaj Wallin - kaj.wallin (at) ixonos.com
45  * @author Henri Lampela - henri.lampela (at) ixonos.com
46  * @author Pekka Nissinen - pekka.nissinen (at) ixonos.com
47  * @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
48  * @author Sami Rämö - sami.ramo (at) ixonos.com
49  */
50 class FriendListPanel : public PanelBase
51 {
52     Q_OBJECT
53
54 public:
55     /**
56      * @brief Default constructor
57      *
58      * @param parent
59      */
60     FriendListPanel(QWidget *parent = 0);
61
62 /*******************************************************************************
63  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
64  ******************************************************************************/
65 protected:
66     /**
67     * @brief Re-implemented from QWidget::hideEvent()
68     *
69     * Calls updateKeyboardGrabbing() and clearFriendGroupFiltering().
70     *
71     * @param event
72     */
73     void hideEvent(QHideEvent *event);
74
75     /**
76     * @brief Re-implemented from QWidget::showEvent()
77     *
78     * Calls updateKeyboardGrabbing().
79     *
80     * @param event
81     */
82     void showEvent(QShowEvent *event);
83
84 /*******************************************************************************
85  * MEMBER FUNCTIONS AND SLOTS
86  ******************************************************************************/
87 public slots:
88     /**
89      * @brief Slot to update friend item's image
90      *
91      * @param id friend ID
92      * @param image friend image
93      */
94     void friendImageReady(const QString &id, const QPixmap &image);
95
96     /**
97      * @brief Slot to refresh friends list
98      *
99      * @param friendList
100      */
101     void friendInfoReceived(QList<User *> &friendList);
102
103 private:
104     /**
105     * @brief Set visibility for filtering text field and clearing button
106     *
107     * @param visible True if items should be visible, false if not
108     */
109     void setFilteringLayoutVisibility(bool visible);
110
111     /**
112     * @brief Takes care of grabbing and releasing the keyboard when required
113     *
114     * Keyboard is grabbed when MainWindow it the topmost window, panel tab is open and
115     * FriendListPanel is visible. Releasing is done if the MainWindow is not the topmost window
116     * or panel tab is not open or FriendListPanel is invisible.
117     */
118     void updateKeyboardGrabbing();
119
120 private slots:
121     /**
122     * @brief Called when any of the panel tabs is closed
123     *
124     * Does call clearFriendGroupFiltering().
125     *
126     * Calls updateKeyboardGrabbing() for releasing the grabbing when FriendListPanel is closed, not
127     * changed to other panel. In this case the hideEvent() is not triggered.
128     */
129     void anyPanelClosed();
130
131     /**
132     * @brief Called when any of the panel tabs is opened
133     *
134     * Calls updateKeyboardGrabbing() for grabbing the keyboard when FriendListPanel is closed and
135     * is the last selected tab. In this case the showEvent() is not triggered.
136     */
137     void anyPanelOpened();
138
139     /**
140     * @brief Slot for clearing the filtering
141     *
142     * Clears friend group (or single friend) filtering and calls clearTextFiltering().
143     */
144     void clearFiltering();
145
146     /**
147     * @brief Slot for clearing the text based filtering.
148     *
149     * Does clear only the text based filtering. Friend group based filtering is not affected.
150     */
151     void clearTextFiltering();
152
153     /**
154     * @brief Updates the filtering when filtering text value is changed
155     *
156     * Filtering UI elements are invoked when the text becomes not empty and hidden when text
157     * becomes empty.
158     *
159     * Sets the new filtering text.
160     *
161     * @param text New text value
162     */
163     void filterTextChanged(const QString &text);
164
165     /**
166     * @brief Requests selected friend's contact dialog.
167     */
168     void requestSelectedFriendContactDialog();
169
170     /**
171     * @brief Routes to selected friend.
172     *
173     * Emits routeToFriend if friend is selected from list.
174     */
175     void routeToSelectedFriend();
176
177     /**
178      * @brief show / hide empty panel label
179      *
180      * @param show true if empty panel should be shown
181      */
182     void showEmptyPanel(bool show);
183
184     /**
185      * @brief Slot to show friends in list.
186      *
187      * Shows only friends that are on userIDs list
188      * @param userIDs list of user ID's
189      */
190     void showFriendsInList(const QList<QString> &userIDs);
191
192     /**
193     * @brief Called when topmost window is changed
194     *
195     * Does set m_mainWindowIsTopmost and calls updateKeyboardGrabbing()
196     *
197     * @param mainWindowIsTopmost True if MainWindow is the topmost one
198     */
199     void topmostWindowChanged(bool mainWindowIsTopmost);
200
201 /*******************************************************************************
202  * SIGNALS
203  ******************************************************************************/
204 signals:
205     /**
206      * @brief Signal for friend finding
207      *
208      * @param coordinates Target coordinate
209      */
210     void findFriend(const GeoCoordinate &coordinates);
211
212     /**
213     * @brief Requests contact dialog.
214     *
215     * @param facebookId contact's facebookId
216     */
217     void requestContactDialog(const QString &facebookId);
218
219     /**
220     * @brief Signal for routing to friend.
221     *
222     * @param coordinates friend's geo coordinates
223     */
224     void routeToFriend(const GeoCoordinate &coordinates);
225
226 /*******************************************************************************
227  * DATA MEMBERS
228  ******************************************************************************/
229 private:
230     bool m_mainWindowIsTopmost;                 ///< Is the MainWindow the topmost one
231     bool m_somePanelIsOpen;                     ///< Is any panel tab open
232
233     QLabel *m_headerLabel;                      ///< Show how many friends are selected
234     QLabel *m_noFriendsLabel;                   ///< Text label for empty panel
235
236     QLineEdit *m_filterField;                   ///< Text field for the filter text
237
238     QPushButton *m_clearTextFilteringButton;    ///< Button for clearing the text filtering
239
240     QWidget *m_headerWidget;                    ///< Friend list header widget
241
242     FriendListView *m_friendListView;           ///< Friend list view
243     ImageButton *m_clearGroupFilteringButton;   ///< Button for clearing friend group filtering
244     ImageButton *m_showContactButton;           ///< Button for showing contact dialog    
245     ImageButton *m_routeButton;                 ///< Button for routing to selected friend
246 };
247
248 #endif // FRIENDLISTPANEL_H