Moved UpdateLocationDialog to be managed by MainWindow.
[situare] / src / ui / mainwindow.cpp
index 7bdb807..aeaedac 100644 (file)
@@ -47,6 +47,7 @@
 #include "settingsdialog.h"
 #include "situareservice/situarecommon.h"
 #include "tabbedpanel.h"
+#include "updatelocation/updatelocationdialog.h"
 #include "userinfopanel.h"
 #include "zoombuttonpanel.h"
 
@@ -75,7 +76,8 @@ MainWindow::MainWindow(QWidget *parent)
       m_crosshair(0),
       m_fullScreenButton(0),
       m_indicatorButtonPanel(0),
-      m_mapScale(0)
+      m_mapScale(0),
+      m_updateLocation(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -124,6 +126,16 @@ 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)
@@ -141,6 +153,14 @@ 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__;
@@ -449,26 +469,14 @@ void MainWindow::buildUserInfoPanel()
     connect(this, SIGNAL(userLocationReady(User*)),
             m_userInfoPanel, SLOT(userDataReceived(User*)));
 
-    connect(this, SIGNAL(reverseGeoReady(QString)),
-            m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
-
-    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_userInfoPanel, SIGNAL(refreshUserData()),
             this, SIGNAL(refreshUserData()));
 
-    connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
-            this, SLOT(buildInformationBox(QString, bool)));
+    connect(m_userInfoPanel, SIGNAL(updateLocationMessageButtonClicked()),
+            this, SLOT(showUpdateLocationDialog()));
 }
 
 void MainWindow::buildZoomButtonPanel()
@@ -499,6 +507,14 @@ void MainWindow::buildZoomButtonPanel()
             this, SIGNAL(draggingModeTriggered()));
 }
 
+void MainWindow::clearUpdateLocationDialogData()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_backupMessage.clear();
+    m_backupFacebookPublishPolicity = false;
+}
+
 void MainWindow::createMenus()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -737,6 +753,15 @@ 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__;
@@ -828,6 +853,31 @@ void MainWindow::showInformationBox()
     }
 }
 
+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)));
+
+    connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
+            this, SLOT(backupUpdateLocationDialogData(QString, bool)));
+
+    connect(m_updateLocation, SIGNAL(finished(int)),
+            this, SLOT(updateLocationDialogFinished(int)));
+
+    m_updateLocation->show();
+
+    emit requestReverseGeo();
+}
+
 void MainWindow::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
 {
     qWarning() << __PRETTY_FUNCTION__;
@@ -879,3 +929,27 @@ 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;
+    }
+}