Moved location update logic to new class called UpdateLocation.
[situare] / src / ui / mainwindow.cpp
index aeaedac..e149901 100644 (file)
@@ -33,6 +33,7 @@
 #include <QMessageBox>
 
 #include "common.h"
+#include "engine/updatelocation.h"
 #include "error.h"
 #include "friendlistpanel.h"
 #include "fullscreenbutton.h"
@@ -77,7 +78,7 @@ MainWindow::MainWindow(QWidget *parent)
       m_fullScreenButton(0),
       m_indicatorButtonPanel(0),
       m_mapScale(0),
-      m_updateLocation(0)
+      m_updateLocationController(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -126,16 +127,6 @@ MainWindow::~MainWindow()
 
     qDeleteAll(m_error_queue.begin(), m_error_queue.end());
     m_error_queue.clear();
-
-    QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
-
-    if (!m_backupMessage.isEmpty()) {
-        settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
-        settings.setValue(USER_UNSEND_MESSAGE_PUBLISH, m_backupFacebookPublishPolicity);
-    } else {
-        settings.remove(USER_UNSEND_MESSAGE);
-        settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
-    }
 }
 
 void MainWindow::automaticUpdateDialogFinished(int result)
@@ -153,14 +144,6 @@ void MainWindow::automaticUpdateDialogFinished(int result)
     m_automaticUpdateLocationDialog->deleteLater();
 }
 
-void MainWindow::backupUpdateLocationDialogData(const QString &status, bool publish)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_backupMessage = status;
-    m_backupFacebookPublishPolicity = publish;
-}
-
 void MainWindow::buildCrosshair()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -507,14 +490,6 @@ void MainWindow::buildZoomButtonPanel()
             this, SIGNAL(draggingModeTriggered()));
 }
 
-void MainWindow::clearUpdateLocationDialogData()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_backupMessage.clear();
-    m_backupFacebookPublishPolicity = false;
-}
-
 void MainWindow::createMenus()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -684,6 +659,7 @@ void MainWindow::loggedIn(bool logged)
     } else {
         m_loginAct->setText(tr("Login"));
         m_userInfoPanel->showUserInfo(false);
+        m_updateLocationController->clear();
     }
     updateItemVisibility(logged);
 }
@@ -753,15 +729,6 @@ void MainWindow::readAutomaticLocationUpdateSettings()
     }
 }
 
-void MainWindow::restoreUnsendMessage()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
-    m_backupMessage = settings.value(USER_UNSEND_MESSAGE).toString();
-    m_backupFacebookPublishPolicity = settings.value(USER_UNSEND_MESSAGE_PUBLISH, false).toBool();
-}
-
 void MainWindow::setCrosshairVisibility(bool visibility)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -857,23 +824,23 @@ void MainWindow::showUpdateLocationDialog()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    delete m_updateLocation;
-    m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
-                                                this);
-
-    connect(this, SIGNAL(reverseGeoReady(QString)),
-            m_updateLocation, SLOT(setAddress(QString)));
-
-    connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
-            this, SIGNAL(statusUpdate(QString, bool)));
+    if (!m_updateLocationController) {
+        m_updateLocationController = new UpdateLocation(this);
+        if (!m_updateLocationController)
+            return;
+        else
+            connect(this, SIGNAL(updateWasSuccessful()), m_updateLocationController, SLOT(clear()));
+            connect(m_updateLocationController, SIGNAL(locationUpdate(QString,bool)),
+                    this, SIGNAL(locationUpdate(QString,bool)));
+    }
 
-    connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
-            this, SLOT(backupUpdateLocationDialogData(QString, bool)));
+    UpdateLocationDialog *updateLocationDialog
+            = new UpdateLocationDialog(m_updateLocationController, this);
 
-    connect(m_updateLocation, SIGNAL(finished(int)),
-            this, SLOT(updateLocationDialogFinished(int)));
+    connect(this, SIGNAL(reverseGeoReady(QString)),
+            updateLocationDialog, SLOT(setAddress(QString)));
 
-    m_updateLocation->show();
+    updateLocationDialog->show();
 
     emit requestReverseGeo();
 }
@@ -929,27 +896,3 @@ void MainWindow::updateItemVisibility(bool loggedIn)
 
     m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, loggedIn);
 }
-
-void MainWindow::updateLocationDialogFinished(int reason)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    Q_UNUSED(reason);
-
-    if (m_updateLocation) {
-        disconnect(this, SIGNAL(reverseGeoReady(QString)),
-                m_updateLocation, SLOT(setAddress(QString)));
-
-        disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
-                this, SIGNAL(statusUpdate(QString,bool)));
-
-        disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
-                this, SLOT(backupUpdateLocationDialogData(QString,bool)));
-
-        disconnect(m_updateLocation, SIGNAL(finished(int)),
-                this, SLOT(updateLocationDialogFinished(int)));
-
-        m_updateLocation->deleteLater();
-        m_updateLocation = 0;
-    }
-}