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