Modified update location dialog
[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, 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     * @brief Slot function to get indication when dialog is finished
190     *
191     */
192     void updateLocationDialogFinished(int reason);
193
194 /******************************************************************************
195 * SIGNALS
196 ******************************************************************************/
197 signals:
198     /**
199     * @brief Signal for finding user.
200     *
201     * @param coordinates user geo coordinates
202     */
203     void findUser(const QPointF &coordinates);
204
205     /**
206     * @brief Signal that informs that user's message/location failed to update on Situare server
207     *        This signal is originally sended from SituareService with name error
208     *        Signal is renamed on MainWindow
209     */
210     void messageSendingFailed(const QString &error);
211
212     /**
213     * @brief Signal that used to inform user that his message/location update tp Situare server
214     *        was failed.
215     *        This signal is originally sended from UserInfo
216     */
217     void notificateUpdateFailing(const QString &message);
218
219     /**
220     * @brief Signal for refreshing user data.
221     *
222     */
223     void refreshUserData();
224
225     /**
226     * @brief Signal for requesting reverseGeo from SituareEngine
227     *
228     */
229     void requestReverseGeo();
230
231     /**
232     * @brief Signals, when address data is ready
233     *
234     * @param address Street address
235     */
236     void reverseGeoReady(const QString &address);
237
238     /**
239     * @brief Signal for requestLocationUpdate from SituareEngine via MainWindow class
240     *
241     * @param status Status message
242     * @param publish Publish on Facebook
243     */
244     void statusUpdate(const QString &status, const bool &publish);
245 /******************************************************************************
246 * DATA MEMBERS
247 ******************************************************************************/
248 private:
249     bool m_backupFacebookPublishPolicity; ///< Backup of publish on Facebook checkbox value
250     bool m_expanded;                    ///< Item expanded state   
251     bool m_messageUpdateVerified;       ///< Place for message/location update check
252     QLabel *m_locationLabel;            ///< Location label
253     QLabel *m_nameLabel;                ///< Name label
254     QLabel *m_statusTextLabel;          ///< Status text label
255     QLabel *m_updatedLabel;             ///< Updated label
256     QPixmap m_backgroundBottomImage;    ///< Bottom background image
257     QPixmap m_backgroundMiddleImage;    ///< Middle background image
258     QPixmap m_backgroundTopImage;       ///< Top background image
259     QPoint m_mousePosition;             ///< Current mouse press position
260     QPointF m_coordinates;              ///< User current coordinates
261     QString m_address;                  ///< Address from where the new message was sent
262     QString m_backupMessage;            ///< Backup of users message
263     QString m_messageText;              ///< User's message
264     QString m_time;                     ///< Time when the new message was sent
265     QString m_userName;                 ///< User's name
266     ImageButton *m_findButton;          ///< User find button   
267     UpdateLocationDialog *m_updateLocation; ///< Update location dialog
268 };
269
270 #endif // USERINFO_H