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