Moved location update logic to new class called UpdateLocation.
[situare] / src / engine / updatelocation.cpp
diff --git a/src/engine/updatelocation.cpp b/src/engine/updatelocation.cpp
new file mode 100644 (file)
index 0000000..4997316
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+*/
+
+#include <QDebug>
+#include <QSettings>
+
+#include "common.h"
+
+#include "updatelocation.h"
+
+const QString UNSENT_MESSAGE_SETTING = "UNSENT_MESSAGE";
+const QString UNSENT_MESSAGE_PUBLISH_SETTING = "UNSENT_MESSAGE_PUBLISH";
+
+UpdateLocation::UpdateLocation(QObject *parent) :
+    QObject(parent),
+    m_publish(false)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
+    m_message = settings.value(UNSENT_MESSAGE_SETTING).toString();
+    m_publish = settings.value(UNSENT_MESSAGE_PUBLISH_SETTING, false).toBool();
+}
+
+UpdateLocation::~UpdateLocation()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
+
+    if (!m_message.isEmpty()) {
+        settings.setValue(UNSENT_MESSAGE_SETTING, m_message);
+        settings.setValue(UNSENT_MESSAGE_PUBLISH_SETTING, m_publish);
+    } else {
+        settings.remove(UNSENT_MESSAGE_SETTING);
+        settings.remove(UNSENT_MESSAGE_PUBLISH_SETTING);
+    }
+}
+
+void UpdateLocation::clear()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    m_message.clear();
+    m_publish = false;
+}
+
+QString UpdateLocation::message() const
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    return m_message;
+}
+
+void UpdateLocation::send()
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    emit locationUpdate(m_message, m_publish);
+}
+
+void UpdateLocation::setMessage(const QString &message)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    if (message != m_message) {
+        m_message = message;
+        emit messageChanged();
+    }
+}
+
+bool UpdateLocation::publish() const
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    return m_publish;
+}
+
+void UpdateLocation::setPublish(bool publish)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    if (publish != m_publish) {
+        m_publish = publish;
+        emit publishChanged();
+    }
+}