Fixed search history settings read and write and added search history
[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 FriendListPanel;
44 class FullScreenButton;
45 class GeoCoordinate;
46 class IndicatorButtonPanel;
47 class Location;
48 class LocationSearchPanel;
49 class MapScale;
50 class MapScene;
51 class MapView;
52 class Route;
53 class RoutingPanel;
54 class SceneCoordinate;
55 class SettingsDialog;
56 class SituareService;
57 class TabbedPanel;
58 class User;
59 class UserInfoPanel;
60 class ZoomButtonPanel;
61
62 /**
63  * @brief Main Window Class
64  */
65 class MainWindow : public QMainWindow
66 {
67     Q_OBJECT
68
69 public:
70     /**
71      * @brief Constructor
72      *
73      * @param parent Parent
74      */
75     MainWindow(QWidget *parent = 0);
76
77     /**
78      * @brief Destructor
79      */
80     ~MainWindow();
81
82 /*******************************************************************************
83  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
84  ******************************************************************************/
85 private:
86     /**
87      * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
88      */
89     void keyPressEvent(QKeyEvent* event);
90
91 /*******************************************************************************
92  * MEMBER FUNCTIONS AND SLOTS
93  ******************************************************************************/
94 public:
95     /**
96      * @brief Clears cookie jar
97      *
98      */
99     void clearCookieJar();
100
101     /**
102      * @brief
103      *
104      * @param logged
105      */
106     void loggedIn(bool logged);
107
108     /**
109      * @brief Gets the login state (logged in/logged out)
110      *
111      * @return bool Login state
112      */
113     bool loginState();
114
115     /**
116      * @brief Reads automatic location update settings.
117      */
118     void readAutomaticLocationUpdateSettings();
119
120     /**
121      * @brief Enable / disable GPS button.
122      *
123      * Does set visibilities for manual location cursor and auto centering menu button.
124      *
125      * @param enabled true if enabled, false otherwise
126      */
127     void setGPSButtonEnabled(bool enabled);
128
129     /**
130      * @brief Enable / disable direction indicator button.
131      *
132      * @param enabled true if shoud be enabled, false otherwise
133      */
134     void setIndicatorButtonEnabled(bool enabled);
135
136     /**
137      * @brief Set scene for MapView
138      *
139      * @param scene Scene to be set
140      */
141     void setMapViewScene(QGraphicsScene *scene);
142
143     /**
144      * Shows dialog with enable automatic location update question.
145      *
146      * @param text text to show in dialog
147      */
148     void showEnableAutomaticUpdateLocationDialog(const QString &text);
149
150     /**
151      * @brief Gets the username from member variable for saving purposes
152      *
153      * @return QString Username
154      */
155     const QString username();
156
157 public slots:
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 setCrosshairVisibility(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 Public slot to intercept signal when old cerdentials are invalid or credentials
197      *        doesn't exist yet
198      */
199     void startLoginProcess();
200
201     /**
202      * @brief Toggle progress indicator.
203      *
204      * @param state true if progress indicator should be shown, false otherwise
205      */
206     void toggleProgressIndicator(bool state);
207
208     /**
209      * @brief Shows / hides Situare related UI items
210      *
211      */
212     void updateItemVisibility();
213
214 private:
215     /**
216      * @brief Build manual location setting cross hair and connect slots
217      */
218     void buildCrosshair();
219
220     /**
221      * @brief Build friend list panel and connect slots
222      */
223     void buildFriendListPanel();
224
225     /**
226      * @brief Build fullscreen toggle button and connect slots
227      */
228     void buildFullScreenButton();
229
230     /**
231      * @brief Build direction indicator button panel and connect signals
232      */
233     void buildIndicatorButtonPanel();
234
235
236     /**
237      * @brief Build location search panel and connect signals
238      */
239     void buildLocationSearchPanel();
240
241     /**
242      * @brief Build map and connect slots
243      */
244     void buildMap();
245
246     /**
247      * @brief Build map scale and connect slots
248      */
249     void buildMapScale();
250
251     /**
252      * @brief Build OSM license and connect slots
253      */
254     void buildOsmLicense();
255
256     /**
257      * @brief Build application panels
258      */
259     void buildPanels();
260
261     /**
262      * @brief Build routing panel and connect slots
263      */
264     void buildRoutingPanel();
265
266     /**
267      * @brief Build user info panel and connect slots
268      */
269     void buildUserInfoPanel();
270
271     /**
272      * @brief Build webview and connect slots
273      */
274     void buildWebView();
275
276     /**
277      * @brief Build zoom button panel and connect slots
278      */
279     void buildZoomButtonPanel();
280
281     /**
282      * @brief Private method to create the Menu items
283      */
284     void createMenus();
285
286     /**
287      * @brief Grab or release HW increase and decrease buttons.
288      *
289      * @param grab Use true for grabbing and false for releasing the keys
290      */
291     void grabZoomKeys(bool grab);
292
293     /**
294      * @brief Queues dialog/information box
295      *
296      * @param dialog Dialog to be added into queue
297      */
298     void queueDialog(QDialog *dialog);
299
300     /**
301      * @brief Shows queued error information box
302      *
303      */
304     void showErrorInformationBox();
305
306     /**
307      * @brief Shows queued information box
308      *
309      * @fn showInformationBox
310      */
311     void showInformationBox();
312
313 private slots:
314     /**
315      * @brief Slot for automatic update dialog finished.
316      *
317      * @result result code
318      */
319     void automaticUpdateDialogFinished(int result);
320
321     /**
322      * @brief Slot to intercept signal when dialog/information note is processed
323      *
324      * @param status Status of the dialog
325      */
326     void dialogFinished(int status);
327
328     /**
329      * @brief Slot for drawing the fullscreen toggle button
330      *
331      * @param size Size of the screen
332      */
333     void drawFullScreenButton(const QSize &size);
334
335     /**
336      * @brief Slot for drawing the map distance scale
337      *
338      * @param size Size of the screen
339      */
340     void drawMapScale(const QSize &size);
341
342     /**
343      * @brief Slot for drawing the Open Street Map license text
344      *
345      * @param size Size of the screen
346      */
347     void drawOsmLicense(const QSize &size);
348
349     /**
350      * @brief Slot to intercept signal when error dialog/information note is processed
351      *
352      * @param status Status of the dialog
353      */
354     void errorDialogFinished(int status);
355
356     /**
357      * @brief Slot for gps timeout.
358      *
359      * Called when request timeout occurs.
360      */
361     void gpsTimeout();
362
363     /**
364      * @brief Slot to load cookies from settings
365      */
366     void loadCookies();
367
368     /**
369      * @brief Slot to intercept signal when webview has finished loading webpage
370      *
371      * @param done Status of the loading
372      */
373     void loadDone(bool done);
374
375     /**
376     * @brief Called when map center point horizontal shifting is changed
377     *
378     * @param shifting New shifting value
379     */
380     void mapCenterHorizontalShiftingChanged(int shifting);
381
382     /**
383      * @brief Move the crosshair
384      */
385     void moveCrosshair();
386
387     /**
388      * @brief Slot to save cookies to settings
389      */
390     void saveCookies();
391
392     /**
393      * @brief Slot for settings dialog accepted.
394      */
395     void settingsDialogAccepted();
396
397     /**
398      * @brief Start location search (open search dialog)
399      */
400     void startLocationSearch();
401
402     /**
403      * @brief Toggle between fullscreen and normal window mode
404      */
405     void toggleFullScreen();
406
407     /**
408      * @brief Slot to intercept signal from webview's networkaccessmanager
409      *
410      * @param reply Network reply (contains errors)
411      */
412     void webViewRequestFinished(QNetworkReply* reply);
413
414 /*******************************************************************************
415  * SIGNALS
416  ******************************************************************************/
417 signals:
418     /**
419      * @brief Automatic centering setting changed by user
420      *
421      * @param enabled True if automatic centering is enabled, otherwise false
422      */
423     void autoCenteringTriggered(bool enabled);
424
425     /**
426      * @brief Signal that indicates when user has cancelled login process
427      *
428      */
429     void cancelLoginProcess();
430
431     /**
432      * @brief Signal for centering to coordinates.
433      *
434      * @param coordinates geo coordinates to center to.
435      */
436     void centerToCoordinates(const GeoCoordinate &coordinates);
437
438     /**
439      * @brief View should be centered to new location
440      *
441      * @param coordinate Scene coordinates of the new center point
442      */
443     void centerToSceneCoordinates(const SceneCoordinate &coordinate);
444
445     /**
446     * @brief Emitted when route is cleared
447     */
448     void clearRoute();
449
450     /**
451     * @brief Signal when direction and distance from current map center point to current GPS
452     *        location is changed
453     *
454     * @param direction Direction in degrees
455     * @param distance Distance in meters
456     * @param draw Should the indicator triangle be drawn or not
457     */
458     void directionIndicatorValuesUpdate(qreal direction, qreal distance, bool draw);
459
460     /**
461      * @brief Signal for enabling automatic location update.
462      *
463      * @param enabled true if enabled, false otherwise
464      * @param updateIntervalMsecs update interval in milliseconds
465      */
466     void enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs = 0);
467
468     /**
469      * @brief Signals error
470      *
471      * @param context error context
472      * @param error error code
473      */
474     void error(const int context, const int error);
475
476     /**
477      * @brief Signal for requesting username from settings
478      *
479      */
480     void fetchUsernameFromSettings();
481
482     /**
483      * @brief Signals when friend's profile image is ready
484      *
485      * @param user Friend
486      */
487     void friendImageReady(User *user);
488
489     /**
490      * @brief GPS setting changed
491      *
492      * @param enabled True if GPS is enabled, otherwise false
493      */
494     void gpsTriggered(bool enabled);
495
496     /**
497      * @brief Signal for friend location ready.
498      *
499      * @param friendsList
500      */
501     void friendsLocationsReady(QList<User *> &friendsList);
502
503     /**
504     * @brief Emited when location request is parsed and is ready for further processing
505     *
506     * @param result List of Location items
507     */
508     void locationDataParsed(const QList<Location> &result);
509
510     /**
511      * @brief Signal is emitted when location item is clicked on map.
512      *
513      * @param userIDs list of friends user IDs in the group
514      */
515     void locationItemClicked(const QList<QString> &userIDs);
516
517     /**
518      * @brief Signal is emitted when location item is clicked in list.
519      *
520      * @param swBound south-west bound in GeoCoorinate
521      * @param neBound north-east bound in GeoCoordinate
522      */
523     void locationItemClicked(const GeoCoordinate &swBound, const GeoCoordinate &neBound);
524
525     /**
526      * @brief Signals when Login/Logout action is pressed
527      *
528      */
529     void loginActionPressed();
530
531     /**
532      * @brief MapView has been resized
533      *
534      * @param size view size
535      */
536     void mapViewResized(const QSize &size);
537
538     /**
539      * @brief Forwarding signal from MapView to MapEngine
540      *
541      * @param coordinate New center point coordinate
542      */
543     void mapViewScrolled(const SceneCoordinate &coordinate);
544
545     /**
546      * @brief Forwarding signal from MapEngine to MapView
547      */
548     void maxZoomLevelReached();
549
550     /**
551      * @brief Forwarding signal from MapEngine to MapView
552      */
553     void minZoomLevelReached();
554
555     /**
556      * @brief Forwarding signal from MapEngine to MapScale
557      */
558     void newMapResolution(qreal scale);
559
560     /**
561      * @brief Signal for refreshing user data.
562      *
563      */
564     void refreshUserData();
565
566     /**
567      * @brief Signal for requesting reverseGeo from SituareEngine
568      *
569      */
570     void requestReverseGeo();
571
572     /**
573      * @brief Signals, when address data is ready
574      *
575      * @param address Street address
576      */
577     void reverseGeoReady(const QString &address);
578
579     /**
580     * @brief Emited when route is parsed and is ready for further processing
581     *
582     * @param route Route item containing parsed route details
583     */
584     void routeParsed(Route &route);
585
586     /**
587     * @brief Signal for routing to geo coordinates.
588     *
589     * @param coordinates destination geo coordinates
590     */
591     void routeTo(const GeoCoordinate &coordinates);
592
593     /**
594     * @brief Request routing to current cursor position
595     */
596     void routeToCursor();
597
598     /**
599      * @brief Signal to save username to settings
600      *
601      * @param username Username
602      */
603     void saveUsername(const QString &username);
604
605     /**
606      * @brief Signal for location search
607      *
608      * @param location QString location
609      */
610     void searchForLocation(QString location);
611
612     /**
613     * @brief Signal is emitted when search history item is clicked.
614     *
615     * @param searchString search string used
616     */
617     void searchHistoryItemClicked(const QString &searchString);
618
619     /**
620      * @brief Signal for requestLocationUpdate from SituareEngine
621      *
622      * @param status Status message
623      * @param publish Publish on Facebook
624      */
625     void statusUpdate(const QString &status, const bool &publish);
626
627     /**
628      * @brief Signals when webview's urlChanged signal is emitted
629      *
630      * @param url New url
631      */
632     void updateCredentials(const QUrl &url);
633
634     /**
635      * @brief Signals when updateLocationDialog's data must be cleared
636      *
637      */
638     void clearUpdateLocationDialogData();
639
640     /**
641     * @brief Dragging mode triggered.
642     */
643     void draggingModeTriggered();
644
645     /**
646      * @brief MapView has finished zooming
647      */
648     void viewZoomFinished();
649
650     /**
651      * @brief Signal for use location ready.
652      *
653      * @param user User object
654      */
655     void userLocationReady(User *user);
656
657     /**
658      * @brief Map zoom in request
659      */
660     void zoomIn();
661
662     /**
663      * @brief Forwarding signal from MapEngine to MapView
664      */
665     void zoomLevelChanged(int zoomLevel);
666
667     /**
668      * @brief Map zoom out request
669      */
670     void zoomOut();
671
672 /*******************************************************************************
673  * DATA MEMBERS
674  ******************************************************************************/
675 private:
676     bool m_errorShown;                      ///< Indicates if error dialog/note is shown
677     bool m_loggedIn;                        ///< Indicates login state
678     bool m_refresh;                         ///< Indicates when webpage is refreshed
679
680     int m_mapCenterHorizontalShifting;      ///< Amount of map center point horizontal shifting
681     int m_progressIndicatorCount;           ///< Indicates the number of progress indicator calls
682
683     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
684     QAction *m_loginAct;                    ///< Action to Login/Logout
685     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
686
687     QLabel *m_crosshair;                    ///< Label for center point crosshair
688     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
689
690     QList<int> m_situareTabsIndexes;        ///< List of Situare tab indexes
691     QList<QDialog *> m_error_queue;         ///< QList type error dialog queue
692     QList<QDialog *> m_queue;               ///< QList type dialog queue
693
694     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
695
696     QMessageBox *m_automaticUpdateLocationDialog;   ///< Automatic update location dialog
697
698     QString m_email;                        ///< Placeholder for email
699     QString m_password;                     ///< Placeholder for password
700
701     QWebView *m_webView;                    ///< Shows facebook login page
702
703     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
704     FullScreenButton *m_fullScreenButton;   ///< Instance of the fullscreen toggle button
705     IndicatorButtonPanel *m_indicatorButtonPanel;   ///< Instance of direction indicator button
706     LocationSearchPanel *m_locationSearchPanel;     ///< Location search panel
707     MapScale *m_mapScale;                   ///< Instance of the map scale
708     MapView *m_mapView;                     ///< Instance of the map view
709     NetworkCookieJar *m_cookieJar;          ///< Placeholder for QNetworkCookies
710     RoutingPanel *m_routingPanel;           ///< Instance of routing panel
711     TabbedPanel *m_tabbedPanel;             ///< Widget for tabbed panels
712     UserInfoPanel *m_userInfoPanel;         ///< Instance of the user information panel
713     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
714 };
715
716 #endif // MAINWINDOW_H