Merge branch 'new_panels' into locationlistview
[situare] / src / ui / mainwindow.cpp
index 021eaea..2b7acce 100644 (file)
@@ -4,9 +4,10 @@
 
       Henri Lampela - henri.lampela@ixonos.com
       Kaj Wallin - kaj.wallin@ixonos.com
-      Jussi Laitinen jussi.laitinen@ixonos.com
+      Jussi Laitinen - jussi.laitinen@ixonos.com
       Sami Rämö - sami.ramo@ixonos.com
       Ville Tiensuu - ville.tiensuu@ixonos.com
+      Katri Kaikkonen - katri.kaikkonen@ixonos.com
 
    Situare is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    USA.
 */
 
-#include <QtGui>
-#include <QtWebKit>
+#include <QAction>
+#include <QApplication>
+#include <QMenuBar>
+#include <QMessageBox>
 #include <QtAlgorithms>
+#include <QtWebKit>
 
-#include "common.h"
+///< @todo sort
 #include "facebookservice/facebookauthentication.h"
+#include "map/mapcommon.h"
+#include "map/mapview.h"
+#include "common.h"
+#include "error.h"
 #include "friendlistpanel.h"
+#include "fullscreenbutton.h"
+#include "indicatorbuttonpanel.h"
 #include "logindialog.h"
-#include "map/mapview.h"
+#include "mapscale.h"
+#include "panelcommon.h"
+#include "routingpanel.h"
+#include "tabbedpanel.h"
+#include "searchdialog.h"
 #include "settingsdialog.h"
 #include "userinfopanel.h"
 #include "zoombuttonpanel.h"
 #include <X11/Xlib.h>
 #endif // Q_WS_MAEMO_5
 
-// values for setting screen size in desktop matching N900 screen size
-const int N900_APP_WIDTH = 800;
-const int N900_APP_HEIGHT = 449;
-
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent),
-    m_drawOwnLocationCrosshair(false),
-    m_loggedIn(false),
-    m_refresh(false),
-    m_ownLocationCrosshair(0),
-    m_email(),    
-    m_password(),
-    m_fullScreenButton(0),
-    m_webView(0),
-    m_cookieJar(0)
+      m_errorShown(false),
+      m_loggedIn(false),
+      m_refresh(false),
+      m_progressIndicatorCount(0),
+      m_ownLocationCrosshair(0),
+      m_email(), ///< @todo WTF?!?!?!?
+      m_password(),
+      m_webView(0),
+      m_fullScreenButton(0),
+      m_indicatorButtonPanel(0),
+      m_mapScale(0),
+      m_cookieJar(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -70,36 +83,36 @@ MainWindow::MainWindow(QWidget *parent)
     QHBoxLayout *layout = new QHBoxLayout;
     layout->addWidget(m_mapView);
     layout->setMargin(0);
+    layout->setSpacing(0);
+
     setCentralWidget(new QWidget());
     centralWidget()->setLayout(layout);
 
-    buildFriendListPanel();
-    buildUserInfoPanel();
-
-    m_settingsDialog = new SettingsDialog(this);
-    m_settingsDialog->hide();
-    connect(m_settingsDialog, SIGNAL(enableAutomaticLocationUpdate(bool,int)),
-            this, SIGNAL(enableAutomaticLocationUpdate(bool,int)));
+    buildPanels();
 
     createMenus();
     setWindowTitle(tr("Situare"));
 
     // set stacking order of widgets
-    m_zoomButtonPanel->stackUnder(m_userPanel);
+    m_zoomButtonPanel->stackUnder(m_tabbedPanel);
     if(m_fullScreenButton) {
         m_fullScreenButton->stackUnder(m_zoomButtonPanel);
         m_osmLicense->stackUnder(m_fullScreenButton);
-    } else
+    } else {
         m_osmLicense->stackUnder(m_zoomButtonPanel);
+    }
     m_ownLocationCrosshair->stackUnder(m_osmLicense);
-    m_mapView->stackUnder(m_ownLocationCrosshair);
-
-    this->toggleProgressIndicator(true);
+    m_indicatorButtonPanel->stackUnder(m_ownLocationCrosshair);
+    m_mapScale->stackUnder(m_indicatorButtonPanel);
+    m_mapView->stackUnder(m_mapScale);
 
     grabZoomKeys(true);
 
-    // set screen size in desktop matching N900 screen size
-    resize(N900_APP_WIDTH, N900_APP_HEIGHT);
+    // Set default screen size
+    resize(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
+#ifdef Q_WS_MAEMO_5
+    setAttribute(Qt::WA_Maemo5StackedWindow);
+#endif
 }
 
 MainWindow::~MainWindow()
@@ -113,19 +126,41 @@ MainWindow::~MainWindow()
 
     qDeleteAll(m_queue.begin(), m_queue.end());
     m_queue.clear();
+
+    qDeleteAll(m_error_queue.begin(), m_error_queue.end());
+    m_error_queue.clear();
+}
+
+void MainWindow::automaticUpdateDialogFinished(int result)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (result == QMessageBox::Yes) {
+        readAutomaticLocationUpdateSettings();
+    } else {
+        QSettings settings(DIRECTORY_NAME, FILE_NAME);
+        settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
+        readAutomaticLocationUpdateSettings();
+    }
+
+    m_automaticUpdateLocationDialog->deleteLater();
 }
 
 void MainWindow::buildFullScreenButton()
 {
     qDebug() << __PRETTY_FUNCTION__;
+
 #ifdef Q_WS_MAEMO_5
-    m_fullScreenButton = new QToolButton(this);
-    m_fullScreenButton->setIcon(QIcon::fromTheme(QLatin1String("general_fullsize")));
-    m_fullScreenButton->setFixedSize(m_fullScreenButton->sizeHint());
-    connect(m_fullScreenButton, SIGNAL(clicked()),
-            this, SLOT(toggleFullScreen()));
-#endif // Q_WS_MAEMO_5
+    m_fullScreenButton = new FullScreenButton(this);
 
+    if (m_fullScreenButton) {
+        connect(m_fullScreenButton, SIGNAL(clicked()),
+                this, SLOT(toggleFullScreen()));
+
+        connect(qApp, SIGNAL(showFullScreenButton()),
+                m_fullScreenButton, SLOT(invoke()));
+    }
+#endif // Q_WS_MAEMO_5
 }
 
 void MainWindow::buildFriendListPanel()
@@ -133,46 +168,68 @@ void MainWindow::buildFriendListPanel()
     qDebug() << __PRETTY_FUNCTION__;
 
     m_friendsListPanel = new FriendListPanel(this);
-    m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
-
-    m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
 
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
 
-    connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
-            this, SIGNAL(findFriend(QPointF)));
+    connect(this, SIGNAL(locationItemClicked(QList<QString>)),
+            m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
+
+    connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
+            this, SIGNAL(centerToCoordinates(GeoCoordinate)));
+
+    connect(this, SIGNAL(friendImageReady(User*)),
+            m_friendsListPanel, SLOT(friendImageReady(User*)));
+
+    connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
+            this, SIGNAL(routeTo(const GeoCoordinate&)));
+}
+
+void MainWindow::buildIndicatorButtonPanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_indicatorButtonPanel = new IndicatorButtonPanel(this);
+
+    connect(m_indicatorButtonPanel, SIGNAL(autoCenteringTriggered(bool)),
+        this, SIGNAL(autoCenteringTriggered(bool)));
 
     connect(m_mapView, SIGNAL(viewResized(QSize)),
-            m_friendsListPanel, SLOT(screenResized(QSize)));
+            m_indicatorButtonPanel, SLOT(screenResized(QSize)));
 
-    connect(this, SIGNAL(locationItemClicked(QList<QString>)),
-            m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
+    connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
+            m_indicatorButtonPanel, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
 
-    connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
-            m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
+    connect(m_indicatorButtonPanel, SIGNAL(draggingModeTriggered()),
+            this, SIGNAL(draggingModeTriggered()));
 }
 
 void MainWindow::buildInformationBox(const QString &message, bool modal)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    QString errorMessage = message;
+
 #ifdef Q_WS_MAEMO_5
+
     QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
-    QLabel *label = new QLabel(msgBox);
-    label->setAlignment(Qt::AlignCenter);
-    label->setText(message);
-    msgBox->setWidget(label);
 
     if(modal) {
         msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
+        // extra line changes are needed to make error notes broader
+        errorMessage.prepend("\n");
+        errorMessage.append("\n");
     } else {
         msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
     }
+    QLabel *label = new QLabel(msgBox);
+    label->setAlignment(Qt::AlignCenter);
+    label->setText(errorMessage);
+    msgBox->setWidget(label);
 #else
     QMessageBox *msgBox = new QMessageBox(this);
     msgBox->button(QMessageBox::Ok);
-    msgBox->setText(message);
+    msgBox->setText(errorMessage);
     msgBox->setModal(modal);
 #endif
 
@@ -190,8 +247,8 @@ void MainWindow::buildManualLocationCrosshair()
     m_ownLocationCrosshair->hide();
     m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
 
-    connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
-            this, SLOT(drawOwnLocationCrosshair(int, int)));
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            this, SLOT(drawOwnLocationCrosshair(QSize)));
 }
 
 void MainWindow::buildMap()
@@ -204,12 +261,14 @@ void MainWindow::buildMap()
     buildOsmLicense();
     buildManualLocationCrosshair();
     buildFullScreenButton();
+    buildIndicatorButtonPanel();
+    buildMapScale();
 
-    connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
-            this, SIGNAL(mapViewScrolled(QPoint)));
+    connect(m_mapView, SIGNAL(viewScrolled(SceneCoordinate)),
+            this, SIGNAL(mapViewScrolled(SceneCoordinate)));
 
-    connect(this, SIGNAL(centerToSceneCoordinates(QPoint)),
-            m_mapView, SLOT(centerToSceneCoordinates(QPoint)));
+    connect(this, SIGNAL(centerToSceneCoordinates(SceneCoordinate)),
+            m_mapView, SLOT(centerToSceneCoordinates(SceneCoordinate)));
 
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             this, SIGNAL(mapViewResized(QSize)));
@@ -217,14 +276,27 @@ void MainWindow::buildMap()
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             this, SLOT(drawFullScreenButton(QSize)));
 
-    connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
-             this, SLOT(setViewPortSize(int, int)));
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            this, SLOT(drawMapScale(QSize)));
+
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+             this, SLOT(setViewPortSize(QSize)));
 
     connect(this, SIGNAL(zoomLevelChanged(int)),
             m_mapView, SLOT(setZoomLevel(int)));
 
     connect(m_mapView, SIGNAL(viewZoomFinished()),
             this, SIGNAL(viewZoomFinished()));
+
+    connect(m_mapView, SIGNAL(zoomIn()),
+            this, SIGNAL(zoomIn()));
+}
+
+void MainWindow::buildMapScale()
+{
+    m_mapScale = new MapScale(this);
+    connect(this, SIGNAL(newMapResolution(qreal)),
+            m_mapScale, SLOT(updateMapResolution(qreal)));
 }
 
 void MainWindow::buildOsmLicense()
@@ -243,36 +315,82 @@ void MainWindow::buildOsmLicense()
             this, SLOT(drawOsmLicense(QSize)));
 }
 
-void MainWindow::buildUserInfoPanel()
+void MainWindow::buildPanels()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_userPanel = new UserInfoPanel(this);
-    m_userPanelSidebar = new PanelSideBar(this, LEFT);
+    buildUserInfoPanel();
+    buildFriendListPanel();
+    buildRoutingPanel();
 
-    m_userPanelSidebar->stackUnder(m_friendsListPanel);
-    m_userPanel->stackUnder(m_userPanelSidebar);
+    m_tabbedPanel = new TabbedPanel(this);
+    m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
+    m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
+    m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
 
-    connect(m_userPanel, SIGNAL(findUser(QPointF)),
-            this, SIGNAL(findUser(QPointF)));
+    connect(m_tabbedPanel, SIGNAL(panelClosed()),
+            m_friendsListPanel, SLOT(clearFriendListFilter()));
 
-    connect(this, SIGNAL(userLocationReady(User*)),
-            m_userPanel, SLOT(userDataReceived(User*)));
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            m_tabbedPanel, SLOT(resizePanel(QSize)));
+}
 
-    connect(m_userPanel, SIGNAL(requestReverseGeo()),
-            this, SIGNAL(requestReverseGeo()));
+void MainWindow::buildRoutingPanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_routingPanel = new RoutingPanel(this);
+
+    connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
+            m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
+
+    connect(m_routingPanel,
+            SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
+            this,
+            SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
+
+    connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
+            this, SIGNAL(routeTo(const GeoCoordinate&)));
+
+    connect(this, SIGNAL(routeParsed(Route&)),
+            m_routingPanel, SLOT(setRoute(Route&)));
+
+    connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
+            this, SIGNAL(centerToCoordinates(GeoCoordinate)));
+
+    connect(m_routingPanel, SIGNAL(requestSearchLocation()),
+            this, SLOT(startLocationSearch()));
+}
+
+void MainWindow::buildUserInfoPanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_userInfoPanel = new UserInfoPanel(this);
+
+    connect(this, SIGNAL(userLocationReady(User*)),
+            m_userInfoPanel, SLOT(userDataReceived(User*)));
 
     connect(this, SIGNAL(reverseGeoReady(QString)),
-            m_userPanel, SIGNAL(reverseGeoReady(QString)));
+            m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
 
-    connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
+    connect(this, SIGNAL(clearUpdateLocationDialogData()),
+            m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
+
+    connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
+            this, SIGNAL(centerToCoordinates(GeoCoordinate)));
+
+    connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
+            this, SIGNAL(requestReverseGeo()));
+
+    connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
             this, SIGNAL(statusUpdate(QString,bool)));
 
-    connect(m_userPanel, SIGNAL(refreshUserData()),
+    connect(m_userInfoPanel, SIGNAL(refreshUserData()),
             this, SIGNAL(refreshUserData()));
 
-    connect(m_mapView, SIGNAL(viewResized(QSize)),
-            m_userPanel, SLOT(screenResized(QSize)));
+    connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
+            this, SLOT(buildInformationBox(QString, bool)));
 }
 
 void MainWindow::buildWebView()
@@ -321,6 +439,9 @@ void MainWindow::buildZoomButtonPanel()
 
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             m_zoomButtonPanel, SLOT(screenResized(QSize)));
+
+    connect(m_zoomButtonPanel, SIGNAL(draggingModeTriggered()),
+            this, SIGNAL(draggingModeTriggered()));
 }
 
 void MainWindow::clearCookieJar()
@@ -329,6 +450,8 @@ void MainWindow::clearCookieJar()
 
     buildWebView();
 
+    m_webView->stop();
+
     if(!m_cookieJar) {
         m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
     }
@@ -360,30 +483,25 @@ void MainWindow::createMenus()
     connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
             this, SIGNAL(gpsTriggered(bool)));
 
-    // automatic centering
-    m_autoCenteringAct = new QAction(tr("Auto centering"), this);
-    m_autoCenteringAct->setCheckable(true);
-    connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
-        this, SIGNAL(autoCenteringTriggered(bool)));
-
     // build the actual menu
     m_viewMenu = menuBar()->addMenu(tr("Main"));
     m_viewMenu->addAction(m_loginAct);
     m_viewMenu->addAction(m_toSettingsAct);
     m_viewMenu->addAction(m_gpsToggleAct);
-    m_viewMenu->addAction(m_autoCenteringAct);
     m_viewMenu->setObjectName(tr("Menu"));
 }
 
 void MainWindow::dialogFinished(int status)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    qDebug() << status;
+
     QDialog *dialog = m_queue.takeFirst();
-    if(!dialog->objectName().isEmpty()) {
+    LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
+    SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
+    if(loginDialog) {
         if(status != 0) {
             buildWebView();
-            static_cast<LoginDialog *>(dialog)->userInput(m_email, m_password);
+            loginDialog->userInput(m_email, m_password);
 
             QStringList urlParts;
             urlParts.append(FACEBOOK_LOGINBASE);
@@ -401,44 +519,79 @@ void MainWindow::dialogFinished(int status)
         } else {
             emit cancelLoginProcess();
         }
+    } else if(searchDialog) {
+        if(status != 0) {
+            emit searchForLocation(searchDialog->input());
+        }
     }
 
     dialog->deleteLater();
 
-    if(!m_queue.isEmpty())
-        showInformationBox();
+    if(!m_error_queue.isEmpty() && m_errorShown == false) {
+        showErrorInformationBox();
+    } else {
+        if(!m_queue.isEmpty()) {
+            showInformationBox();
+        }
+    }
 }
 
 void MainWindow::drawFullScreenButton(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
 
-    if(m_fullScreenButton) {
-        m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width()
-                                 - PANEL_PEEK_AMOUNT,
+    if (m_fullScreenButton) {
+        m_fullScreenButton->move(size.width() - m_fullScreenButton->size().width(),
                                  size.height() - m_fullScreenButton->size().height());
     }
 }
 
+void MainWindow::drawMapScale(const QSize &size)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    const int LEFT_SCALE_MARGIN = 10;
+    const int BOTTOM_SCALE_MARGIN = 2;
+
+    m_mapScale->move(LEFT_SCALE_MARGIN,
+                     size.height() - m_mapScale->size().height() - BOTTOM_SCALE_MARGIN);
+}
+
 void MainWindow::drawOsmLicense(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
 
     m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
-                       - PANEL_PEEK_AMOUNT,
+                       - PANEL_BAR_WIDTH,
                        size.height() - m_osmLicense->fontMetrics().height());
 }
 
-void MainWindow::drawOwnLocationCrosshair(int width, int height)
+void MainWindow::drawOwnLocationCrosshair(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
-        m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
-                            height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
+    if (m_ownLocationCrosshair != 0) {
+        m_ownLocationCrosshair->move(size.width()/2 - m_ownLocationCrosshair->pixmap()->width()/2,
+                            size.height()/2 - m_ownLocationCrosshair->pixmap()->height()/2);
     }
 }
 
+void MainWindow::errorDialogFinished(int status)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    qDebug() << status;
+    QDialog *dialog = m_error_queue.takeFirst();
+
+    dialog->deleteLater();
+    m_errorShown = false;
+
+    if(!m_error_queue.isEmpty())
+        showErrorInformationBox();
+    else if(!m_queue.isEmpty())
+        showInformationBox();
+}
+
 void MainWindow::gpsTimeout()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -510,7 +663,6 @@ void MainWindow::loadCookies()
 
         m_cookieJar->setAllCookies(cookieList);
         m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
-
     }
 }
 
@@ -573,7 +725,7 @@ void MainWindow::loggedIn(bool logged)
 
         m_loginAct->setText(tr("Login"));
     }
-    updateItemVisibility(m_loggedIn);
+    updateItemVisibility();
 }
 
 void MainWindow::loginFailed()
@@ -581,19 +733,25 @@ void MainWindow::loginFailed()
     qDebug() << __PRETTY_FUNCTION__;
 
     clearCookieJar();
+    startLoginProcess();
+}
 
-    toggleProgressIndicator(false);
+bool MainWindow::loginState()
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    startLoginProcess();
+    return m_loggedIn;
 }
 
 void MainWindow::loginUsingCookies()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    toggleProgressIndicator(true);
+
     buildWebView();
     loadCookies();
-    
+
     QStringList urlParts;
     urlParts.append(FACEBOOK_LOGINBASE);
     urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
@@ -611,17 +769,45 @@ void MainWindow::openSettingsDialog()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_settingsDialog->enableSituareSettings(m_gpsToggleAct->isChecked() && m_loggedIn);
-    m_settingsDialog->show();
+    SettingsDialog *settingsDialog = new SettingsDialog(this);
+    settingsDialog->enableSituareSettings((m_loggedIn && m_gpsToggleAct->isChecked()));
+    connect(settingsDialog, SIGNAL(accepted()), this, SLOT(settingsDialogAccepted()));
+
+    settingsDialog->show();
+}
+
+void MainWindow::readAutomaticLocationUpdateSettings()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
+    QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
+                                      .toTime();
+
+    if (automaticUpdateEnabled && automaticUpdateInterval.isValid()) {
+        QTime time;
+        emit enableAutomaticLocationUpdate(true, time.msecsTo(automaticUpdateInterval));
+    } else {
+        emit enableAutomaticLocationUpdate(false);
+    }
 }
 
 void MainWindow::queueDialog(QDialog *dialog)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_queue.append(dialog);
+    // check is dialog is modal, for now all modal dialogs have hihger priority i.e. errors
+    if(dialog->isModal()) {
+        m_error_queue.append(dialog);
+    } else {
+        m_queue.append(dialog);
+    }
 
-    if(m_queue.count() == 1)
+    // show error dialog if there is only one error dialog in the queue and no error dialog is shown
+    if(m_error_queue.count() == 1 && m_errorShown == false)
+        showErrorInformationBox();
+    else if(m_queue.count() == 1 && m_errorShown == false)
         showInformationBox();
 }
 
@@ -646,23 +832,18 @@ void MainWindow::saveCookies()
     settings.setValue(COOKIES, list);
 }
 
-void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
+void MainWindow::setGPSButtonEnabled(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_autoCenteringAct->setChecked(enabled);
+    m_gpsToggleAct->setChecked(enabled);
 }
 
-void MainWindow::setGPSButtonEnabled(bool enabled)
+void MainWindow::setIndicatorButtonEnabled(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_gpsToggleAct->setChecked(enabled);
-
-    if(m_loggedIn)
-        setOwnLocationCrosshairVisibility(!enabled);
-
-    m_autoCenteringAct->setVisible(enabled);
+    m_indicatorButtonPanel->setIndicatorButtonEnabled(enabled);
 }
 
 void MainWindow::setMapViewScene(QGraphicsScene *scene)
@@ -678,14 +859,19 @@ void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
 
     if (visibility) {
         m_ownLocationCrosshair->show();
-        m_drawOwnLocationCrosshair = true;
-        drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
+        drawOwnLocationCrosshair(m_viewPortSize);
     } else {
         m_ownLocationCrosshair->hide();
-        m_drawOwnLocationCrosshair = false;
     }
 }
 
+void MainWindow::settingsDialogAccepted()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    readAutomaticLocationUpdateSettings();
+}
+
 void MainWindow::setUsername(const QString &username)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -693,12 +879,25 @@ void MainWindow::setUsername(const QString &username)
     m_email = username;
 }
 
-void MainWindow::setViewPortSize(int width, int height)
+void MainWindow::setViewPortSize(const QSize &size)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_viewPortSize = size;
+}
+
+void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_viewPortWidth = width;
-    m_viewPortHeight = height;
+    m_automaticUpdateLocationDialog = new QMessageBox(QMessageBox::Question,
+                                                      tr("Automatic location update"), text,
+                                                      QMessageBox::Yes | QMessageBox::No |
+                                                      QMessageBox::Cancel, this);
+    connect(m_automaticUpdateLocationDialog, SIGNAL(finished(int)),
+            this, SLOT(automaticUpdateDialogFinished(int)));
+
+    m_automaticUpdateLocationDialog->show();
 }
 
 void MainWindow::toggleFullScreen()
@@ -711,15 +910,58 @@ void MainWindow::toggleFullScreen()
         showNormal();
 }
 
+void MainWindow::showErrorInformationBox()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if(m_error_queue.count()) {
+        m_errorShown = true;
+        QDialog *dialog = m_error_queue.first();
+        connect(dialog, SIGNAL(finished(int)),
+                this, SLOT(errorDialogFinished(int)));
+        dialog->show();
+    }
+}
+
 void MainWindow::showInformationBox()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QDialog *dialog = m_queue.takeFirst();
-    connect(dialog, SIGNAL(finished(int)),
-            this, SLOT(dialogFinished(int)));
-    dialog->show();
-    m_queue.insert(0, dialog);
+    if(m_queue.count()) {
+        QDialog *dialog = m_queue.first();
+        connect(dialog, SIGNAL(finished(int)),
+                this, SLOT(dialogFinished(int)));
+        dialog->show();
+    }
+}
+
+void MainWindow::showPanels()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+///< @todo check how this is called and can this method be removed
+
+    drawFullScreenButton(m_viewPortSize);
+
+//    if(m_loggedIn) {
+//        if(!m_friendsListPanel->isVisible()) {
+//            m_friendsListPanel->show();
+//            m_friendsListPanelSidebar->show();
+//        }
+
+//        if(!m_userPanel->isVisible()) {
+//            m_userPanel->show();
+//            m_userPanelSidebar->show();
+//        }
+//    }
+}
+
+void MainWindow::startLocationSearch()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    SearchDialog *searchDialog = new SearchDialog();
+    queueDialog(searchDialog);
 }
 
 void MainWindow::startLoginProcess()
@@ -727,7 +969,6 @@ void MainWindow::startLoginProcess()
     qDebug() << __PRETTY_FUNCTION__;
 
     LoginDialog *loginDialog = new LoginDialog();
-    loginDialog->setObjectName(QString("loginDialog"));
 
     emit fetchUsernameFromSettings();
 
@@ -744,42 +985,42 @@ void MainWindow::toggleProgressIndicator(bool value)
     qDebug() << __PRETTY_FUNCTION__;
 
 #ifdef Q_WS_MAEMO_5
-    setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
+    if(value) {
+        m_progressIndicatorCount++;
+        setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+    } else {
+        if(m_progressIndicatorCount > 0)
+            m_progressIndicatorCount--;
+
+        if(m_progressIndicatorCount == 0)
+            setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+    }
 #else
     Q_UNUSED(value);
 #endif // Q_WS_MAEMO_5
 }
 
-void MainWindow::updateItemVisibility(bool show)
+void MainWindow::updateItemVisibility()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    
-    if(show) {
-        m_friendsListPanel->show();
-        m_friendsListPanelSidebar->show();
-        m_userPanel->show();
-        m_userPanelSidebar->show();
 
-        if(m_drawOwnLocationCrosshair) {
-            m_ownLocationCrosshair->show();
-            setGPSButtonEnabled(false);
-            emit gpsTriggered(false);
-        }
-    } else {
-        m_friendsListPanel->closePanel();
-        m_friendsListPanel->hide();
-        m_friendsListPanelSidebar->hide();
-        m_userPanel->closePanel();
-        m_userPanel->hide();
-        m_userPanelSidebar->hide();
-        m_ownLocationCrosshair->hide();       
-    }
+///< @todo can this be removed?
+
+//    if(!m_loggedIn) {
+//        m_friendsListPanel->closePanel();
+//        m_friendsListPanel->hide();
+//        m_friendsListPanelSidebar->hide();
+
+//        m_userPanel->closePanel();
+//        m_userPanel->hide();
+//        m_userPanelSidebar->hide();
+//    }
 }
 
 const QString MainWindow::username()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    
+
     return m_email;
 }
 
@@ -787,9 +1028,10 @@ void MainWindow::webViewRequestFinished(QNetworkReply *reply)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if(reply->error()) {
-        qDebug() << reply->error() << reply->errorString();
-        toggleProgressIndicator(false);
+    // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
+    // qwebview starts to load a new page while the current page loading is not finished
+    if(reply->error() != QNetworkReply::OperationCanceledError &&
+       reply->error() != QNetworkReply::NoError) {
+        emit error(ErrorContext::NETWORK, reply->error());
     }
 }
-