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