8d48f7ba5b9fbab455f868e4c75ba2c79a25cfee
[situare] / src / ui / userinfo.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jukka Saastamoinen - jukka.saastamoinen@ixonos.com
6        Jussi Laitinen - jussi.laitinen@ixonos.com
7        Katri Kaikkonen - katri.kaikkonen@ixonos.com
8        Henri Lampela - henri.lampela@ixonos.com
9        Ville Tiensuu - ville.tiensuu@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 USERINFO_H
27 #define USERINFO_H
28
29 #include <QWidget>
30
31 #include "coordinates/geocoordinate.h"
32 #include "updatelocation/updatelocationdialog.h"
33
34 class ImageButton;
35 class TagsDialog;
36
37 /**
38  * @brief UserInfo shows user's data in expandable item.
39  */
40 class UserInfo : public QWidget
41 {
42     Q_OBJECT
43
44 public:
45     /**
46      * @brief Constructor
47      *
48      * @param parent Parent
49      */
50     UserInfo(QWidget *parent = 0);
51
52     /**
53      * @brief Desctructor
54      * saves unsend user message to settings
55      *
56      */
57     ~UserInfo();
58
59 /*******************************************************************************
60 * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
61 *******************************************************************************/
62 protected:
63     /**
64      * @brief Set current mouse position to mouse event position.
65      *
66      * @param event QMouseEvent mouse press event
67      */
68     void mousePressEvent(QMouseEvent *event);
69
70     /**
71      * @brief Call toggleHeight if mouse position is unchanged.
72      *
73      * Check if current mouse position is same as mouse release position.
74      * @param event QMouseEvent mouse release event
75      */
76     void mouseReleaseEvent(QMouseEvent *event);
77
78     /**
79      * @brief This function is called when the widget is drawn
80      *
81      * @param event Pointer to paint event
82      */
83     void paintEvent(QPaintEvent *event);
84
85 /******************************************************************************
86 * MEMBER FUNCTIONS AND SLOTS
87 ******************************************************************************/
88 public:
89     /**
90      * @brief Sets the users current address
91      *
92      * @param address Reference to users current address
93      */
94     void setAddress(const QString &address);
95
96     /**
97      * @brief Sets the users current coordinates
98      *
99      * @param coordinates Reference to users current coordinates
100      */
101     void setCoordinates(const GeoCoordinate &coordinates);
102
103     /**
104      * @brief Sets the user picture
105      *
106      * @param image Reference to user picture
107      */
108     void setProfileImage(const QPixmap &image);
109
110     /**
111      * @brief Sets the user tags
112      *
113      * @param tags list of tags
114      */
115     void setProfileImage(const QStringList &tags);
116
117     /**
118     * @brief Sets the user tags
119     *
120     * @param tags list of tags
121     */
122     void setTags(const QHash<QString, QString> &tags);
123
124     /**
125      * @brief Sets the time of updated message
126      *
127      * @param time Reference to time when message was sent.
128      */
129     void setTime(const QString &time);
130
131     /**
132      * @brief Sets the user name
133      *
134      * @param name Reference to user name
135      */
136     void setUserName(const QString &name);
137
138     /**
139     * @brief Shows users tags dialog.
140     */
141     void showTagsDialog();
142
143 public slots:
144     /**
145      * @brief Saves status message and Facebook publish setting
146      *
147      * @param status message that user sends. Message is stored to m_backupMessage data member
148      * @param publish setting that determines whether the user status message is published on
149      *        Facebook. This value is stored to m_backupFacebookPublishPolicity data member.
150      */
151     void backupUpdateLocationDialogData(const QString &status, bool publish);
152
153     /**
154      * @brief Clears backups of message and publish on Facebook setting
155      */
156     void clearUpdateLocationDialogData();
157
158     /**
159      * @brief Sets the message text
160      *
161      * @param text Reference to user message
162      */
163     void setMessageText(const QString &text);
164
165 private:
166     /**
167      * @brief reads Unsend message from settings at startup
168      */
169     void restoreUnsendMessage();
170
171     /**
172      * @brief Set shortened or full-length text to labels.
173      *
174      * @param expanded true if full-length text is set, false otherwise
175      */
176     void setExpanded(bool expanded);
177
178 private slots:
179     /**
180      * @brief Slot for collapse user info
181      */
182     void collapse();
183
184     /**
185      * @brief Slot for find button click
186      */
187     void findButtonClicked();
188
189     /**
190      * @brief Slot function to forward messageUpdate launch signal
191      */
192     void messageUpdate();
193
194     /**
195     * @brief Slot to handle changes in tags dialog.
196     */
197     void tagsDialogFinished(int reason);
198
199     /**
200      * @brief Slot function to get indication when dialog is finished
201      */
202     void updateLocationDialogFinished(int reason);
203
204 /******************************************************************************
205 * SIGNALS
206 ******************************************************************************/
207 signals:
208     /**
209     * @brief Signal for adding tags.
210     *
211     * @param tags tags to add
212     */
213     void addTags(const QStringList &tags);
214
215     /**
216      * @brief Signal for finding user.
217      *
218      * @param coordinates user geo coordinates
219      */
220     void findUser(const GeoCoordinate &coordinates);
221
222     /**
223      * @brief Signal that used to inform user that his message/location update tp Situare server
224      *        was failed.
225      *        This signal is originally sended from UserInfo
226      * @param message message for notification
227      * @param modal true if modal notification otherwice false
228      */
229     void notificateUpdateFailing(const QString &message, bool modal);
230
231     /**
232      * @brief Signal for requesting reverseGeo from SituareEngine
233      */
234     void requestReverseGeo();
235
236     /**
237     * @brief Signal for removing tags.
238     *
239     * @param tags tags to add
240     */
241     void removeTags(const QStringList &tags);
242
243     /**
244      * @brief Signals, when address data is ready
245      *
246      * @param address Street address
247      */
248     void reverseGeoReady(const QString &address);
249
250     /**
251     * @brief Signals, when item selection changed
252     *
253     * @param address Street address
254     */
255     void itemSelectionChanged(bool selected);
256
257     /**
258      * @brief Signal for requestLocationUpdate from SituareEngine via MainWindow class
259      *
260      * @param status Status message
261      * @param publish Publish on Facebook
262      */
263     void statusUpdate(const QString &status, const bool &publish);
264
265 /******************************************************************************
266 * DATA MEMBERS
267 ******************************************************************************/
268 private:
269     bool m_backupFacebookPublishPolicity;   ///< Backup of publish on Facebook checkbox value
270     bool m_expanded;                        ///< Item expanded state
271
272     QLabel *m_locationLabel;                ///< Location label
273     QLabel *m_nameLabel;                    ///< Name label
274     QLabel *m_statusTextLabel;              ///< Status text label
275     QLabel *m_tagsTextLabel;                ///< Tags text label
276     QLabel *m_updatedLabel;                 ///< Updated label
277
278     QPixmap m_backgroundBottomImage;        ///< Bottom background image
279     QPixmap m_backgroundMiddleImage;        ///< Middle background image
280     QPixmap m_backgroundTopImage;           ///< Top background image
281     QPixmap m_backgroundBottomSelectedImage;   ///< Selected bottom background image
282     QPixmap m_backgroundMiddleSelectedImage;   ///< Selected middle background image
283     QPixmap m_backgroundTopSelectedImage;      ///< Selected top background image
284
285     QPoint m_mousePosition;                 ///< Current mouse press position
286
287     QString m_backupMessage;                ///< Backup of users message
288     QString m_expandedMessageText;          ///< Expanded message text
289     QString m_messageText;                  ///< User's message
290     QString m_userName;                     ///< User's name
291
292     QHash<QString, QString> m_userTags;                 ///< User's tags
293
294     GeoCoordinate m_coordinates;            ///< User current coordinates
295     ImageButton *m_avatar;                  ///< User find button
296     TagsDialog *m_tagsDialog;               ///< Tags dialog
297     UpdateLocationDialog *m_updateLocation; ///< Update location dialog    
298 };
299
300 #endif // USERINFO_H