Added a new method (buildPanels) for building tabbed 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 application panels
253      */
254     void buildPanels();
255
256     /**
257      * @brief Build user info panel and connect slots
258      */
259     void buildUserInfoPanel();
260
261     /**
262      * @brief Build webview and connect slots
263      */
264     void buildWebView();
265
266     /**
267      * @brief Build zoom button panel and connect slots
268      */
269     void buildZoomButtonPanel();
270
271     /**
272      * @brief Private method to create the Menu items
273      */
274     void createMenus();
275
276     /**
277      * @brief Grab or release HW increase and decrease buttons.
278      *
279      * @param grab Use true for grabbing and false for releasing the keys
280      */
281     void grabZoomKeys(bool grab);
282
283     /**
284      * @brief Queues dialog/information box
285      *
286      * @param dialog Dialog to be added into queue
287      */
288     void queueDialog(QDialog *dialog);
289
290     /**
291      * @brief Shows queued error information box
292      *
293      */
294     void showErrorInformationBox();
295
296     /**
297      * @brief Shows queued information box
298      *
299      * @fn showInformationBox
300      */
301     void showInformationBox();
302
303 private slots:
304     /**
305      * @brief Slot for automatic update dialog finished.
306      *
307      * @result result code
308      */
309     void automaticUpdateDialogFinished(int result);
310
311     /**
312      * @brief Slot to intercept signal when dialog/information note is processed
313      *
314      * @param status Status of the dialog
315      */
316     void dialogFinished(int status);
317
318     /**
319      * @brief Slot for drawing the fullscreen toggle button
320      *
321      * @param size Size of the screen
322      */
323     void drawFullScreenButton(const QSize &size);
324
325     /**
326      * @brief Slot for drawing the map distance scale
327      *
328      * @param size Size of the screen
329      */
330     void drawMapScale(const QSize &size);
331
332     /**
333      * @brief Slot for drawing the Open Street Map license text
334      *
335      * @param size Size of the screen
336      */
337     void drawOsmLicense(const QSize &size);
338
339     /**
340      * @brief Slot for drawing the own location crosshair
341      *
342      * @param size Size of the screen
343      */
344     void drawOwnLocationCrosshair(const QSize &size);
345
346     /**
347      * @brief Slot to intercept signal when error dialog/information note is processed
348      *
349      * @param status Status of the dialog
350      */
351     void errorDialogFinished(int status);
352
353     /**
354      * @brief Slot for gps timeout.
355      *
356      * Called when request timeout occurs.
357      */
358     void gpsTimeout();
359
360     /**
361      * @brief Slot to load cookies from settings
362      */
363     void loadCookies();
364
365     /**
366      * @brief Slot to intercept signal when webview has finished loading webpage
367      *
368      * @param done Status of the loading
369      */
370     void loadDone(bool done);
371
372     /**
373      * @brief Slot to save cookies to settings
374      */
375     void saveCookies();
376
377     /**
378      * @brief Slot for settings dialog accepted.
379      */
380     void settingsDialogAccepted();
381
382     /**
383      * @brief Set correnct view port size to datamembers
384      *
385      * @param size Size of the screen
386      */
387     void setViewPortSize(const QSize &size);
388
389     /**
390      * @brief Start location search (open search dialog)
391      */
392     void startLocationSearch();
393
394     /**
395      * @brief Toggle between fullscreen and normal window mode
396      */
397     void toggleFullScreen();
398
399     /**
400      * @brief Slot to intercept signal from webview's networkaccessmanager
401      *
402      * @param reply Network reply (contains errors)
403      */
404     void webViewRequestFinished(QNetworkReply* reply);
405
406 /*******************************************************************************
407  * SIGNALS
408  ******************************************************************************/
409 signals:
410     /**
411      * @brief Automatic centering setting changed by user
412      *
413      * @param enabled True if automatic centering is enabled, otherwise false
414      */
415     void autoCenteringTriggered(bool enabled);
416
417     /**
418      * @brief Signal that indicates when user has cancelled login process
419      *
420      */
421     void cancelLoginProcess();
422
423     /**
424      * @brief View should be centered to new location
425      *
426      * @param coordinate Scene coordinates of the new center point
427      */
428     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
429
430     /**
431      * @brief Signal for enabling automatic location update.
432      *
433      * @param enabled true if enabled, false otherwise
434      * @param updateIntervalMsecs update interval in milliseconds
435      */
436     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
437
438     /**
439      * @brief Signals error
440      *
441      * @param context error context
442      * @param error error code
443      */
444     void error(const int context, const int error);
445
446     /**
447      * @brief Signal for requesting username from settings
448      *
449      */
450     void fetchUsernameFromSettings();
451
452     /**
453      * @brief Signal for finding user.
454      *
455      * @param coordinates user geo coordinates
456      */
457     void findUser(const GeoCoordinate &coordinates);
458
459     /**
460      * @brief Signals when friend's profile image is ready
461      *
462      * @param user Friend
463      */
464     void friendImageReady(User *user);
465
466     /**
467      * @brief GPS setting changed
468      *
469      * @param enabled True if GPS is enabled, otherwise false
470      */
471     void gpsTriggered(bool enabled);
472
473     /**
474      * @brief Signal for finding friend.
475      *
476      * @param coordinates friend's geo coordinates
477      */
478     void findFriend(const GeoCoordinate &coordinates);
479
480     /**
481      * @brief Signal for friend location ready.
482      *
483      * @param friendsList
484      */
485     void friendsLocationsReady(QList<User *> &friendsList);
486
487     /**
488      * @brief Signal is emitted when location item is clicked.
489      *
490      * @param userIDs list of friends user IDs in the group
491      */
492     void locationItemClicked(const QList<QString> &userIDs);
493
494     /**
495      * @brief Signals when Login/Logout action is pressed
496      *
497      */
498     void loginActionPressed();
499
500     /**
501      * @brief MapView has been resized
502      *
503      * @param size view size
504      */
505     void mapViewResized(const QSize &size);
506
507     /**
508      * @brief Forwarding signal from MapView to MapEngine
509      *
510      * @param coordinate
511      */
512     void mapViewScrolled(const SceneCoordinate &coordinate);
513
514     /**
515      * @brief Forwarding signal from MapEngine to MapView
516      */
517     void maxZoomLevelReached();
518
519     /**
520      * @brief Forwarding signal from MapEngine to MapView
521      */
522     void minZoomLevelReached();
523
524     /**
525      * @brief Forwarding signal from MapEngine to MapScale
526      */
527     void newMapResolution(qreal scale);
528
529     /**
530      * @brief Signal for refreshing user data.
531      *
532      */
533     void refreshUserData();
534
535     /**
536      * @brief Signal for requesting reverseGeo from SituareEngine
537      *
538      */
539     void requestReverseGeo();
540
541     /**
542      * @brief Signals, when address data is ready
543      *
544      * @param address Street address
545      */
546     void reverseGeoReady(const QString &address);
547
548     /**
549      * @brief Signal to save username to settings
550      *
551      * @param username Username
552      */
553     void saveUsername(const QString &username);
554
555     /**
556      * @brief Signal for location search
557      *
558      * @param location QString location
559      */
560     void searchForLocation(QString location);
561
562     /**
563      * @brief Signal for requestLocationUpdate from SituareEngine
564      *
565      * @param status Status message
566      * @param publish Publish on Facebook
567      */
568     void statusUpdate(const QString &status, const bool &publish);
569
570     /**
571      * @brief Signals when webview's urlChanged signal is emitted
572      *
573      * @param url New url
574      */
575     void updateCredentials(const QUrl &url);
576
577     /**
578      * @brief Signals when updateLocationDialog's data must be cleared
579      *
580      */
581     void clearUpdateLocationDialogData();
582
583     /**
584     * @brief Dragging mode triggered.
585     */
586     void draggingModeTriggered();
587
588     /**
589      * @brief MapView has finished zooming
590      */
591     void viewZoomFinished();
592
593     /**
594      * @brief Signal for use location ready.
595      *
596      * @param user User object
597      */
598     void userLocationReady(User *user);
599
600     /**
601      * @brief Map zoom in request
602      */
603     void zoomIn();
604
605     /**
606      * @brief Forwarding signal from MapEngine to MapView
607      */
608     void zoomLevelChanged(int zoomLevel);
609
610     /**
611      * @brief Map zoom out request
612      */
613     void zoomOut();
614
615 /*******************************************************************************
616  * DATA MEMBERS
617  ******************************************************************************/
618 private:
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_gpsToggleAct;                ///< Action to trigger gps toggle
626     QAction *m_loginAct;                    ///< Action to Login/Logout
627     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
628     QAction *m_searchLocationAct;           /// @todo this is temporary, remove when not needed!
629
630     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
631     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
632
633     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
634     QList<QDialog *> m_queue;               ///< QList type dialog queue
635
636     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
637
638     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
639
640     QSize m_viewPortSize;                 ///< Size of the viewport
641
642     QString m_email;                        ///< Placeholder for email
643     QString m_password;                     ///< Placeholder for password
644
645     QWebView *m_webView;                    ///< Shows facebook login page
646
647     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
648     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
649     IndicatorButton *m_indicatorButton;     ///< Instance of direction indicator button
650     MapScale *m_mapScale;                   ///< Instance of the map scale
651     MapView *m_mapView;                     ///< Instance of the map view
652     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
653     TabbedPanel *m_tabbedPanel;             ///< Widget for tabbed panels
654     UserInfoPanel *m_userInfoPanel;         ///< Instance of the user information panel
655     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
656 };
657
658 #endif // MAINWINDOW_H