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

View file

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