Some minor cosmetic changes
[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         Jussi Laitinen - jussi.laitinen@ixonos.com
8         Sami Rämö - sami.ramo@ixonos.com
9         Ville Tiensuu - ville.tiensuu@ixonos.com
10         Katri Kaikkonen - katri.kaikkonen@ixonos.com
11
12     Situare is free software; you can redistribute it and/or
13     modify it under the terms of the GNU General Public License
14     version 2 as published by the Free Software Foundation.
15
16     Situare is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19     GNU General Public License for more details.
20
21     You should have received a copy of the GNU General Public License
22     along with Situare; if not, write to the Free Software
23     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
24     USA.
25 */
26
27 #ifndef MAINWINDOW_H
28 #define MAINWINDOW_H
29
30 #include <QtGui/QMainWindow>
31 #include <QUrl>
32
33 #include "network/networkcookiejar.h"
34
35 class QGraphicsScene;
36 class QLabel;
37 class QMessageBox;
38 class QNetworkReply;
39 class QToolButton;
40 class QWebView;
41
42 class FacebookAuthentication;
43 class FullScreenButton;
44 class FriendListPanel;
45 class IndicatorButtonPanel;
46 class GeoCoordinate;
47 class MapScale;
48 class MapScene;
49 class MapView;
50 class TabbedPanel;
51 class SettingsDialog;
52 class SceneCoordinate;
53 class SituareService;
54 class User;
55 class UserInfoPanel;
56 class ZoomButtonPanel;
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     ~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 panel and connect signals
156      */
157     void buildIndicatorButtonPanel();
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 when direction and distance from current map center point to current GPS
433     *        location is changed
434     *
435     * @param direction Direction in degrees
436     * @param distance Distance in meters
437     * @param draw Should the indicator triangle be drawn or not
438     */
439     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
440
441     /**
442      * @brief Signal for enabling automatic location update.
443      *
444      * @param enabled true if enabled, false otherwise
445      * @param updateIntervalMsecs update interval in milliseconds
446      */
447     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
448
449     /**
450      * @brief Signals error
451      *
452      * @param context error context
453      * @param error error code
454      */
455     void error(const int context, const int error);
456
457     /**
458      * @brief Signal for requesting username from settings
459      *
460      */
461     void fetchUsernameFromSettings();
462
463     /**
464      * @brief Signal for finding user.
465      *
466      * @param coordinates user geo coordinates
467      */
468     void findUser(const GeoCoordinate &coordinates);
469
470     /**
471      * @brief Signals when friend's profile image is ready
472      *
473      * @param user Friend
474      */
475     void friendImageReady(User *user);
476
477     /**
478      * @brief GPS setting changed
479      *
480      * @param enabled True if GPS is enabled, otherwise false
481      */
482     void gpsTriggered(bool enabled);
483
484     /**
485      * @brief Signal for finding friend.
486      *
487      * @param coordinates friend's geo coordinates
488      */
489     void findFriend(const GeoCoordinate &coordinates);
490
491     /**
492      * @brief Signal for friend location ready.
493      *
494      * @param friendsList
495      */
496     void friendsLocationsReady(QList<User *> &friendsList);
497
498     /**
499      * @brief Signal is emitted when location item is clicked.
500      *
501      * @param userIDs list of friends user IDs in the group
502      */
503     void locationItemClicked(const QList<QString> &userIDs);
504
505     /**
506      * @brief Signals when Login/Logout action is pressed
507      *
508      */
509     void loginActionPressed();
510
511     /**
512      * @brief MapView has been resized
513      *
514      * @param size view size
515      */
516     void mapViewResized(const QSize &size);
517
518     /**
519      * @brief Forwarding signal from MapView to MapEngine
520      *
521      * @param coordinate
522      */
523     void mapViewScrolled(const SceneCoordinate &coordinate);
524
525     /**
526      * @brief Forwarding signal from MapEngine to MapView
527      */
528     void maxZoomLevelReached();
529
530     /**
531      * @brief Forwarding signal from MapEngine to MapView
532      */
533     void minZoomLevelReached();
534
535     /**
536      * @brief Forwarding signal from MapEngine to MapScale
537      */
538     void newMapResolution(qreal scale);
539
540     /**
541      * @brief Signal for refreshing user data.
542      *
543      */
544     void refreshUserData();
545
546     /**
547      * @brief Signal for requesting reverseGeo from SituareEngine
548      *
549      */
550     void requestReverseGeo();
551
552     /**
553      * @brief Signals, when address data is ready
554      *
555      * @param address Street address
556      */
557     void reverseGeoReady(const QString &address);
558
559     /**
560      * @brief Signal to save username to settings
561      *
562      * @param username Username
563      */
564     void saveUsername(const QString &username);
565
566     /**
567      * @brief Signal for location search
568      *
569      * @param location QString location
570      */
571     void searchForLocation(QString location);
572
573     /**
574      * @brief Signal for requestLocationUpdate from SituareEngine
575      *
576      * @param status Status message
577      * @param publish Publish on Facebook
578      */
579     void statusUpdate(const QString &status, const bool &publish);
580
581     /**
582      * @brief Signals when webview's urlChanged signal is emitted
583      *
584      * @param url New url
585      */
586     void updateCredentials(const QUrl &url);
587
588     /**
589      * @brief Signals when updateLocationDialog's data must be cleared
590      *
591      */
592     void clearUpdateLocationDialogData();
593
594     /**
595     * @brief Dragging mode triggered.
596     */
597     void draggingModeTriggered();
598
599     /**
600      * @brief MapView has finished zooming
601      */
602     void viewZoomFinished();
603
604     /**
605      * @brief Signal for use location ready.
606      *
607      * @param user User object
608      */
609     void userLocationReady(User *user);
610
611     /**
612      * @brief Map zoom in request
613      */
614     void zoomIn();
615
616     /**
617      * @brief Forwarding signal from MapEngine to MapView
618      */
619     void zoomLevelChanged(int zoomLevel);
620
621     /**
622      * @brief Map zoom out request
623      */
624     void zoomOut();
625
626 /*******************************************************************************
627  * DATA MEMBERS
628  ******************************************************************************/
629 private:
630     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
631     bool m_loggedIn;                        ///< Indicates login state
632     bool m_refresh;                         ///< Indicates when webpage is refreshed
633
634     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
635
636     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
637     QAction *m_loginAct;                    ///< Action to Login/Logout
638     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
639     QAction *m_searchLocationAct;           /// @todo this is temporary, remove when not needed!
640
641     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
642     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
643
644     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
645     QList<QDialog *> m_queue;               ///< QList type dialog queue
646
647     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
648
649     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
650
651     QSize m_viewPortSize;                 ///< Size of the viewport
652
653     QString m_email;                        ///< Placeholder for email
654     QString m_password;                     ///< Placeholder for password
655
656     QWebView *m_webView;                    ///< Shows facebook login page
657
658     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
659     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
660     IndicatorButtonPanel *m_indicatorButtonPanel;     ///< Instance of direction indicator button
661     MapScale *m_mapScale;                   ///< Instance of the map scale
662     MapView *m_mapView;                     ///< Instance of the map view
663     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
664     TabbedPanel *m_tabbedPanel;             ///< Widget for tabbed panels
665     UserInfoPanel *m_userInfoPanel;         ///< Instance of the user information panel
666     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
667 };
668
669 #endif // MAINWINDOW_H