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