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