Added location class for location search results and added location search dialog
[situare] / src / ui / mainwindow.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Henri Lampela - henri.lampela@ixonos.com
6       Kaj Wallin - kaj.wallin@ixonos.com
7       Sami Rämö - sami.ramo@ixonos.com
8
9    Situare is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License
11    version 2 as published by the Free Software Foundation.
12
13    Situare is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with Situare; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
21    USA.
22 */
23
24 #ifndef MAINWINDOW_H
25 #define MAINWINDOW_H
26
27 #include <QtGui/QMainWindow>
28 #include <QUrl>
29
30 #include "network/networkcookiejar.h"
31 #include "panelsidebar.h"
32
33 class QGraphicsScene;
34 class QLabel;
35 class QMessageBox;
36 class QNetworkReply;
37 class QToolButton;
38 class QWebView;
39
40 class FacebookAuthentication;
41 class FullScreenButton;
42 class FriendListPanel;
43 class GeoCoordinate;
44 class MapScale;
45 class MapScene;
46 class MapView;
47 class SettingsDialog;
48 class SceneCoordinate;
49 class SituareService;
50 class User;
51 class UserInfoPanel;
52 class ZoomButtonPanel;
53
54
55 /**
56 * @brief Main Window Class
57 */
58 class MainWindow : public QMainWindow
59 {
60     Q_OBJECT
61
62 public:
63     /**
64     * @brief Constructor
65     *
66     * @param parent Parent
67     */
68     MainWindow(QWidget *parent = 0);
69
70     /**
71     * @brief Destructor
72     *
73     */
74     ~MainWindow();
75
76 /*******************************************************************************
77  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
78  ******************************************************************************/
79 private:
80     /**
81       * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
82       */
83     void keyPressEvent(QKeyEvent* event);
84
85 /*******************************************************************************
86  * MEMBER FUNCTIONS AND SLOTS
87  ******************************************************************************/
88 public:
89     /**
90     * @brief Clears cookie jar
91     *
92     */
93     void clearCookieJar();
94
95     /**
96     * @brief
97     *
98     * @param logged
99     */
100     void loggedIn(bool logged);
101
102     /**
103     * @brief Gets the login state (logged in/logged out)
104     *
105     * @return bool Login state
106     */
107     bool loginState();
108
109     /**
110     * @brief Reads automatic location update settings.
111     */
112     void readAutomaticLocationUpdateSettings();
113
114     /**
115     * @brief Enable / disable auto centering button.
116     *
117     * @param enabled true if shoud be enabled, false otherwise
118     */
119     void setAutoCenteringButtonEnabled(bool enabled);
120
121     /**
122     * @brief Enable / disable GPS button.
123     *
124     * Does set visibilities for manual location cursor and auto centering menu button.
125     *
126     * @param enabled true if enabled, false otherwise
127     */
128     void setGPSButtonEnabled(bool enabled);
129
130     /**
131       * @brief Set scene for MapView
132       *
133       * @param scene Scene to be set
134       */
135     void setMapViewScene(QGraphicsScene *scene);
136
137     /**
138     * Shows dialog with enable automatic location update question.
139     *
140     * @param text text to show in dialog
141     */
142     void showEnableAutomaticUpdateLocationDialog(const QString &text);
143
144     /**
145     * @brief Gets the username from member variable for saving purposes
146     *
147     * @return QString Username
148     */
149     const QString username();
150
151 public slots:
152     /**
153     * @brief Builds information box with message.
154     *
155     * @param message Information message
156     * @param modal Modal = true, non-modal false
157     */
158     void buildInformationBox(const QString &message, bool modal=false);
159
160     /**
161     * @brief Slot for failed login
162     *
163     */
164     void loginFailed();
165
166     /**
167     * @brief Slot to intercept signal when login with cookies is requested
168     *
169     */
170     void loginUsingCookies();
171
172     /**
173     * @brief Public slot, which open settings dialog
174     */
175     void openSettingsDialog();
176
177     /**
178       * @brief Set own location crosshair visibility
179       *
180       * @param visible
181       */
182     void setOwnLocationCrosshairVisibility(bool visible);
183
184     /**
185     * @brief Sets username to member variable for login dialog
186     *
187     * @param username Username to be set
188     */
189     void setUsername(const QString &username);
190
191     /**
192     * @brief Method to show panels
193     *
194     */
195     void showPanels();
196
197     /**
198     * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
199     *        doesn't exist yet
200     *
201     */
202     void startLoginProcess();
203
204     /**
205     * @brief Toggle progress indicator.
206     *
207     * @param state true if progress indicator should be shown, false otherwise
208     */
209     void toggleProgressIndicator(bool state);
210
211     /**
212     * @brief Shows / hides Situare related UI items
213     *
214     */
215     void updateItemVisibility();
216
217 private:
218     /**
219       * @brief Build fullscreen toggle button and connect slots
220       */
221     void buildFullScreenButton();
222
223     /**
224       * @brief Build friend list panel and connect slots
225       */
226     void buildFriendListPanel();
227
228     /**
229       * @brief Build manual location setting cross hair and connect slots
230       */
231     void buildManualLocationCrosshair();
232
233     /**
234       * @brief Build map and connect slots
235       */
236     void buildMap();
237
238     /**
239      * @brief Build map scale and connect slots
240      */
241     void buildMapScale();
242
243     /**
244       * @brief Build OSM license and connect slots
245       */
246     void buildOsmLicense();
247
248     /**
249       * @brief Build user info panel and connect slots
250       */
251     void buildUserInfoPanel();
252
253     /**
254     * @brief Build webview and connect slots
255     *
256     */
257     void buildWebView();
258
259     /**
260       * @brief Build zoom button panel and connect slots
261       */
262     void buildZoomButtonPanel();
263
264     /**
265     * @brief Private method to create the Menu items
266     */
267     void createMenus();
268
269     /**
270       * @brief Grab or release HW increase and decrease buttons.
271       *
272       * @param grab Use true for grabbing and false for releasing the keys
273       */
274     void grabZoomKeys(bool grab);
275
276     /**
277     * @brief Queues dialog/information box
278     *
279     * @param dialog Dialog to be added into queue
280     */
281     void queueDialog(QDialog *dialog);
282
283     /**
284     * @brief Shows queued error information box
285     *
286     */
287     void showErrorInformationBox();
288
289     /**
290     * @brief Shows queued information box
291     *
292     * @fn showInformationBox
293     */
294     void showInformationBox();
295
296 private slots:
297     /**
298     * @brief Slot for automatic update dialog finished.
299     *
300     * @result result code
301     */
302     void automaticUpdateDialogFinished(int result);
303
304     /**
305     * @brief Slot to intercept signal when dialog/information note is processed
306     *
307     * @param status Status of the dialog
308     */
309     void dialogFinished(int status);
310
311     /**
312     * @brief Slot for drawing the fullscreen toggle button
313     *
314     * @param size Size of the screen
315     */
316     void drawFullScreenButton(const QSize &size);
317
318     /**
319     * @brief Slot for drawing the map distance scale
320     *
321     * @param size Size of the screen
322     */
323     void drawMapScale(const QSize &size);
324
325     /**
326     * @brief Slot for drawing the Open Street Map license text
327     *
328     * @param size Size of the screen
329     */
330     void drawOsmLicense(const QSize &size);
331
332     /**
333     * @brief Slot for drawing the own location crosshair
334     *
335     * @param size Size of the screen
336     */
337     void drawOwnLocationCrosshair(const QSize &size);
338
339     /**
340     * @brief Slot to intercept signal when error dialog/information note is processed
341     *
342     * @param status Status of the dialog
343     */
344     void errorDialogFinished(int status);
345
346     /**
347     * @brief Slot for gps timeout.
348     *
349     * Called when request timeout occurs.
350     */
351     void gpsTimeout();
352
353     /**
354     * @brief Slot to load cookies from settings
355     *
356     */
357     void loadCookies();
358
359     /**
360     * @brief Slot to intercept signal when webview has finished loading webpage
361     *
362     * @param done Status of the loading
363     */
364     void loadDone(bool done);
365
366     /**
367     * @brief Slot to save cookies to settings
368     *
369     */
370     void saveCookies();
371
372     /**
373     * @brief Slot for settings dialog accepted.
374     */
375     void settingsDialogAccepted();
376
377     /**
378     * @brief Set correnct view port size to datamembers
379     *
380     * @param size Size of the screen
381     */
382     void setViewPortSize(const QSize &size);
383
384     /**
385     * @brief Start location search (open search dialog)
386     */
387     void startLocationSearch();
388
389     /**
390     * @brief Toggle between fullscreen and normal window mode
391     */
392     void toggleFullScreen();
393
394     /**
395     * @brief Slot to intercept signal from webview's networkaccessmanager
396     *
397     * @param reply Network reply (contains errors)
398     */
399     void webViewRequestFinished(QNetworkReply* reply);
400
401
402 /*******************************************************************************
403  * SIGNALS
404  ******************************************************************************/
405 signals:
406     /**
407     * @brief Automatic centering setting changed by user
408     *
409     * @param enabled True if automatic centering is enabled, otherwise false
410     */
411     void autoCenteringTriggered(bool enabled);
412
413     /**
414     * @brief Signal that indicates when user has cancelled login process
415     *
416     */
417     void cancelLoginProcess();
418
419     /**
420     * @brief View should be centered to new location
421     *
422     * @param coordinate Scene coordinates of the new center point
423     */
424     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
425
426     /**
427     * @brief Signal for enabling automatic location update.
428     *
429     * @param enabled true if enabled, false otherwise
430     * @param updateIntervalMsecs update interval in milliseconds
431     */
432     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
433
434     /**
435     * @brief Signals error
436     *
437     * @param context error context
438     * @param error error code
439     */
440     void error(const int context, const int error);
441
442     /**
443     * @brief Signal for requesting username from settings
444     *
445     */
446     void fetchUsernameFromSettings();
447
448     /**
449     * @brief Signal for finding user.
450     *
451     * @param coordinates user geo coordinates
452     */
453     void findUser(const GeoCoordinate &coordinates);
454
455     /**
456     * @brief Signals when friend's profile image is ready
457     *
458     * @param user Friend
459     */
460     void friendImageReady(User *user);
461
462     /**
463     * @brief GPS setting changed
464     *
465     * @param enabled True if GPS is enabled, otherwise false
466     */
467     void gpsTriggered(bool enabled);
468
469     /**
470     * @brief Signal for finding friend.
471     *
472     * @param coordinates friend's geo coordinates
473     */
474     void findFriend(const GeoCoordinate &coordinates);
475
476     /**
477     * @brief Signal for friend location ready.
478     *
479     * @param friendsList
480     */
481     void friendsLocationsReady(QList<User *> &friendsList);
482
483     /**
484     * @brief Signal is emitted when location item is clicked.
485     *
486     * @param userIDs list of friends user IDs in the group
487     */
488     void locationItemClicked(const QList<QString> &userIDs);
489
490     /**
491     * @brief Signals when Login/Logout action is pressed
492     *
493     */
494     void loginActionPressed();
495
496     /**
497     * @brief MapView has been resized
498     *
499     * @param size view size
500     */
501     void mapViewResized(const QSize &size);
502
503     /**
504       * @brief Forwarding signal from MapView to MapEngine
505       *
506       * @param coordinate
507       */
508     void mapViewScrolled(const SceneCoordinate &coordinate);
509
510     /**
511       * @brief Forwarding signal from MapEngine to MapView
512       */
513     void maxZoomLevelReached();
514
515     /**
516       * @brief Forwarding signal from MapEngine to MapView
517       */
518     void minZoomLevelReached();
519
520     /**
521      * @brief Forwarding signal from MapEngine to MapScale
522      */
523     void newMapResolution(qreal scale);
524
525     /**
526     * @brief Signal for refreshing user data.
527     *
528     */
529     void refreshUserData();
530
531     /**
532     * @brief Signal for requesting reverseGeo from SituareEngine
533     *
534     */
535     void requestReverseGeo();
536
537     /**
538     * @brief Signals, when address data is ready
539     *
540     * @param address Street address
541     */
542     void reverseGeoReady(const QString &address);
543
544     /**
545     * @brief Signal to save username to settings
546     *
547     * @param username Username
548     */
549     void saveUsername(const QString &username);
550
551     /**
552     * @brief Signal for location search
553     *
554     * @param location QString location
555     */
556     void searchForLocation(QString location);
557
558     /**
559     * @brief Signal for requestLocationUpdate from SituareEngine
560     *
561     * @param status Status message
562     * @param publish Publish on Facebook
563     */
564     void statusUpdate(const QString &status, const bool &publish);
565
566     /**
567     * @brief Signals when webview's urlChanged signal is emitted
568     *
569     * @param url New url
570     */
571     void updateCredentials(const QUrl &url);
572
573     /**
574     * @brief Signals when updateLocationDialog's data must be cleared
575     *
576     */
577     void clearUpdateLocationDialogData();
578
579     /**
580     * @brief MapView has finished zooming
581     */
582     void viewZoomFinished();
583
584     /**
585     * @brief Signal for use location ready.
586     *
587     * @param user User object
588     */
589     void userLocationReady(User *user);
590
591     /**
592     * @brief Map zoom in request
593     */
594     void zoomIn();
595
596     /**
597       * @brief Forwarding signal from MapEngine to MapView
598       */
599     void zoomLevelChanged(int zoomLevel);
600
601     /**
602     * @brief Map zoom out request
603     */
604     void zoomOut();
605
606 /*******************************************************************************
607  * DATA MEMBERS
608  ******************************************************************************/
609 private:
610     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
611     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
612     bool m_loggedIn;                        ///< Indicates login state
613     bool m_refresh;                         ///< Indicates when webpage is refreshed
614
615     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
616
617     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
618     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
619     QAction *m_loginAct;                    ///< Action to Login/Logout
620     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
621     QAction *m_searchLocationAct;           /// @todo this is temporary, remove when not needed!
622
623     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
624     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
625
626     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
627     QList<QDialog *> m_queue;               ///< QList type dialog queue
628
629     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
630
631     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
632
633     QSize m_viewPortSize;                 ///< Size of the viewport
634
635     QString m_email;                        ///< Placeholder for email
636     QString m_password;                     ///< Placeholder for password
637
638     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
639
640     QWebView *m_webView;                    ///< Shows facebook login page
641
642     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
643     MapScale *m_mapScale;                   ///< Instance of the map scale
644     MapView *m_mapView;                     ///< Instance of the map view
645     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
646     PanelSideBar *m_userPanelSidebar;       ///< User panel side bar
647     PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
648     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
649     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
650 };
651
652 #endif // MAINWINDOW_H