0e51cd7cdcff9cc7b934d5ba8a1b2e2caf8fd4d7
[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
36 /**
37  * @brief UserInfo shows user's data in expandable item.
38  */
39 class UserInfo : public QWidget
40 {
41     Q_OBJECT
42
43 public:
44     /**
45      * @brief Constructor
46      *
47      * @param parent Parent
48      */
49     UserInfo(QWidget *parent = 0);
50
51     /**
52      * @brief Desctructor
53      * saves unsend user message to settings
54      *
55      */
56     ~UserInfo();
57
58 /*******************************************************************************
59 * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
60 *******************************************************************************/
61 protected:
62     /**
63      * @brief Set current mouse position to mouse event position.
64      *
65      * @param event QMouseEvent mouse press event
66      */
67     void mousePressEvent(QMouseEvent *event);
68
69     /**
70      * @brief Call toggleHeight if mouse position is unchanged.
71      *
72      * Check if current mouse position is same as mouse release position.
73      * @param event QMouseEvent mouse release event
74      */
75     void mouseReleaseEvent(QMouseEvent *event);
76
77     /**
78      * @brief This function is called when the widget is drawn
79      *
80      * @param aPaintEvent Pointer to paint event
81      */
82     void paintEvent(QPaintEvent *aPaintEvent);
83
84 /******************************************************************************
85 * MEMBER FUNCTIONS AND SLOTS
86 ******************************************************************************/
87 public:
88     /**
89      * @brief Sets the users current address
90      *
91      * @param address Reference to users current address
92      */
93     void setAddress(const QString &address);
94
95     /**
96      * @brief Sets the users current coordinates
97      *
98      * @param coordinates Reference to users current coordinates
99      */
100     void setCoordinates(const GeoCoordinate &coordinates);
101
102     /**
103      * @brief Sets the user picture
104      *
105      * @param image Reference to user picture
106      */
107     void setProfileImage(const QPixmap &image);
108
109     /**
110      * @brief Sets the time of updated message
111      *
112      * @param time Reference to time when message was sent.
113      */
114     void setTime(const QString &time);
115
116     /**
117      * @brief Sets the user name
118      *
119      * @param name Reference to user name
120      */
121     void setUserName(const QString &name);
122
123 public slots:
124     /**
125      * @brief Saves status message and Facebook publish setting
126      *
127      * @param status message that user sends. Message is stored to m_backupMessage data member
128      * @param publish setting that determines whether the user status message is published on
129      *        Facebook. This value is stored to m_backupFacebookPublishPolicity data member.
130      */
131     void backupUpdateLocationDialogData(const QString &status, bool publish);
132
133     /**
134      * @brief Clears backups of message and publish on Facebook setting
135      */
136     void clearUpdateLocationDialogData();
137
138     /**
139      * @brief Sets the message text
140      *
141      * @param text Reference to user message
142      */
143     void setMessageText(const QString &text);
144
145 private:
146
147     /**
148      * @brief reads Unsend message from settings at startup
149      */
150     void restoreUnsendMessage();
151
152     /**
153      * @brief Set shortened or full-length text to labels.
154      *
155      * @param expanded true if full-length text is set, false otherwise
156      */
157     void setText(bool expanded);
158
159     /**
160      * @brief Set shortened texts from User data.
161      *
162      * Text length is defined by MAXIMUM_CHARS.
163      */
164     QString shortenText(const QLabel *label, const QString &text, int textMaxWidth);
165
166     /**
167      * @brief Split too long words.
168      *
169      * Word Reference to long word
170      */
171     QString splitWord(const QString &word) const;
172
173 private slots:
174     /**
175      * @brief Slot for find button click
176      */
177     void findButtonClicked();
178
179     /**
180      * @brief Slot function to forward messageUpdate launch signal
181      */
182     void messageUpdate();
183
184     /**
185      * @brief Slot function to get indication when dialog is finished
186      */
187     void updateLocationDialogFinished(int reason);
188
189 /******************************************************************************
190 * SIGNALS
191 ******************************************************************************/
192 signals:
193     /**
194      * @brief Signal for finding user.
195      *
196      * @param coordinates user geo coordinates
197      */
198     void findUser(const GeoCoordinate &coordinates);
199
200     /**
201      * @brief Signal that used to inform user that his message/location update tp Situare server
202      *        was failed.
203      *        This signal is originally sended from UserInfo
204      * @param message message for notification
205      * @param modal true if modal notification otherwice false
206      */
207     void notificateUpdateFailing(const QString &message, bool modal);
208
209     /**
210      * @brief Signal for refreshing user data.
211      */
212     void refreshUserData();
213
214     /**
215      * @brief Signal for requesting reverseGeo from SituareEngine
216      */
217     void requestReverseGeo();
218
219     /**
220      * @brief Signals, when address data is ready
221      *
222      * @param address Street address
223      */
224     void reverseGeoReady(const QString &address);
225
226     /**
227      * @brief Signal for requestLocationUpdate from SituareEngine via MainWindow class
228      *
229      * @param status Status message
230      * @param publish Publish on Facebook
231      */
232     void statusUpdate(const QString &status, const bool &publish);
233
234 /******************************************************************************
235 * DATA MEMBERS
236 ******************************************************************************/
237 private:
238     bool m_backupFacebookPublishPolicity;   ///< Backup of publish on Facebook checkbox value
239     bool m_expanded;                        ///< Item expanded state
240
241     QLabel *m_locationLabel;                ///< Location label
242     QLabel *m_nameLabel;                    ///< Name label
243     QLabel *m_statusTextLabel;              ///< Status text label
244     QLabel *m_updatedLabel;                 ///< Updated label
245
246     QPixmap m_backgroundBottomImage;        ///< Bottom background image
247     QPixmap m_backgroundMiddleImage;        ///< Middle background image
248     QPixmap m_backgroundTopImage;           ///< Top background image
249
250     QPoint m_mousePosition;                 ///< Current mouse press position
251
252     QString m_address;                      ///< Address from where the new message was sent
253     QString m_backupMessage;                ///< Backup of users message
254     QString m_messageText;                  ///< User's message
255     QString m_time;                         ///< Time when the new message was sent
256     QString m_userName;                     ///< User's name
257
258     GeoCoordinate m_coordinates;            ///< User current coordinates
259     ImageButton *m_findButton;              ///< User find button
260     UpdateLocationDialog *m_updateLocation; ///< Update location dialog
261 };
262
263 #endif // USERINFO_H