QML-UI: replace the two ways to log progress with one

The logging to the UI didn't work anymore since the message area had been
removed in commit 8646934ba3 ("Simple DiveList as initial Page").

This way all the updates simply land on the Log page.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-12-03 15:59:40 -08:00
parent d20e25419f
commit 2fc99092fb
2 changed files with 19 additions and 18 deletions

View file

@ -9,17 +9,21 @@
#include "qthelper.h" #include "qthelper.h"
#include "qt-gui.h" #include "qt-gui.h"
void qmlUiShowMessage(const char *errorString) QMLManager *QMLManager::m_instance = NULL;
static void appendTextToLogStandalone(const char *text)
{ {
if (qqWindowObject && !qqWindowObject->setProperty("messageText", QVariant(errorString))) QMLManager *mgr = QMLManager::instance();
qDebug() << "couldn't set property messageText to" << errorString; if (mgr)
mgr->appendTextToLog(QString(text));
} }
QMLManager::QMLManager() : QMLManager::QMLManager() :
m_locationServiceEnabled(false) m_locationServiceEnabled(false)
{ {
m_instance = this;
// create location manager service // create location manager service
locationProvider = new GpsLocation(&qmlUiShowMessage, this); locationProvider = new GpsLocation(&appendTextToLogStandalone, this);
// Initialize cloud credentials. // Initialize cloud credentials.
setCloudUserName(prefs.cloud_storage_email); setCloudUserName(prefs.cloud_storage_email);
@ -37,6 +41,12 @@ QMLManager::QMLManager() :
QMLManager::~QMLManager() QMLManager::~QMLManager()
{ {
m_instance = NULL;
}
QMLManager *QMLManager::instance()
{
return m_instance;
} }
void QMLManager::savePreferences() void QMLManager::savePreferences()
@ -95,16 +105,13 @@ void QMLManager::saveCloudCredentials()
void QMLManager::loadDives() void QMLManager::loadDives()
{ {
if (same_string(prefs.cloud_storage_email, "") || same_string(prefs.cloud_storage_password, "")) { if (same_string(prefs.cloud_storage_email, "") || same_string(prefs.cloud_storage_password, "")) {
qmlUiShowMessage("Please set up cloud storage credentials");
appendTextToLog("Unable to load dives; cloud storage credentials missing"); appendTextToLog("Unable to load dives; cloud storage credentials missing");
return; return;
} }
qmlUiShowMessage("Loading dives...");
appendTextToLog("Loading dives..."); appendTextToLog("Loading dives...");
QString url; QString url;
if (getCloudURL(url)) { if (getCloudURL(url)) {
qmlUiShowMessage(get_error_string());
appendTextToLog(get_error_string()); appendTextToLog(get_error_string());
return; return;
} }
@ -115,13 +122,11 @@ void QMLManager::loadDives()
if (!error) { if (!error) {
report_error("filename is now %s", fileNamePrt.data()); report_error("filename is now %s", fileNamePrt.data());
const char *error_string = get_error_string(); const char *error_string = get_error_string();
qmlUiShowMessage(error_string);
appendTextToLog(error_string); appendTextToLog(error_string);
set_filename(fileNamePrt.data(), true); set_filename(fileNamePrt.data(), true);
} else { } else {
report_error("failed to open file %s", fileNamePrt.data()); report_error("failed to open file %s", fileNamePrt.data());
const char *error_string = get_error_string(); const char *error_string = get_error_string();
qmlUiShowMessage(error_string);
appendTextToLog(error_string); appendTextToLog(error_string);
return; return;
} }
@ -170,24 +175,21 @@ void QMLManager::commitChanges(QString diveId, QString suit, QString buddy, QStr
void QMLManager::saveChanges() void QMLManager::saveChanges()
{ {
if (!loadFromCloud()) { if (!loadFromCloud()) {
qmlUiShowMessage("Don't save dives without loading from the cloud, first."); appendTextToLog("Don't save dives without loading from the cloud, first.");
return; return;
} }
qmlUiShowMessage("Saving dives."); appendTextToLog("Saving dives.");
QString fileName; QString fileName;
if (getCloudURL(fileName)) { if (getCloudURL(fileName)) {
qmlUiShowMessage(get_error_string());
appendTextToLog(get_error_string()); appendTextToLog(get_error_string());
return; return;
} }
if (save_dives(fileName.toUtf8().data())) { if (save_dives(fileName.toUtf8().data())) {
qmlUiShowMessage(get_error_string());
appendTextToLog(get_error_string()); appendTextToLog(get_error_string());
return; return;
} }
qmlUiShowMessage("Dives saved.");
appendTextToLog("Dive saved."); appendTextToLog("Dive saved.");
set_filename(fileName.toUtf8().data(), true); set_filename(fileName.toUtf8().data(), true);
mark_divelist_changed(false); mark_divelist_changed(false);
@ -195,7 +197,6 @@ void QMLManager::saveChanges()
void QMLManager::addDive() void QMLManager::addDive()
{ {
qmlUiShowMessage("Adding new dive.");
appendTextToLog("Adding new dive."); appendTextToLog("Adding new dive.");
DiveListModel::instance()->startAddDive(); DiveListModel::instance()->startAddDive();
} }
@ -233,7 +234,6 @@ void QMLManager::appendTextToLog(const QString &newText)
emit logTextChanged(); emit logTextChanged();
} }
bool QMLManager::saveCloudPassword() const bool QMLManager::saveCloudPassword() const
{ {
return m_saveCloudPassword; return m_saveCloudPassword;

View file

@ -6,8 +6,6 @@
#include "gpslocation.h" #include "gpslocation.h"
void qmlUiShowMessage(const char *errorString);
class QMLManager : public QObject class QMLManager : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -23,6 +21,8 @@ public:
QMLManager(); QMLManager();
~QMLManager(); ~QMLManager();
static QMLManager *instance();
QString cloudUserName() const; QString cloudUserName() const;
void setCloudUserName(const QString &cloudUserName); void setCloudUserName(const QString &cloudUserName);
@ -70,6 +70,7 @@ private:
int m_timeThreshold; int m_timeThreshold;
GpsLocation *locationProvider; GpsLocation *locationProvider;
bool m_loadFromCloud; bool m_loadFromCloud;
static QMLManager *m_instance;
signals: signals:
void cloudUserNameChanged(); void cloudUserNameChanged();