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