mobile UI: setup callback for the new notification mechanism

This simply passes the text to the existing notification text mechanism.

The call to processEvents() ensures that Qt processes the UI events
after we updated the notification and that the user gets timely updates;
otherwise the UI might look like the app is hanging.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-04-01 06:59:11 -07:00
parent f58bc91d8b
commit d317eefb67

View file

@ -76,6 +76,7 @@ extern "C" void showErrorFromC(char *buf)
QMetaObject::invokeMethod(QMLManager::instance(), "registerError", Qt::AutoConnection, Q_ARG(QString, error));
}
// this gets called from libdivecomputer
static void progressCallback(const char *text)
{
QMLManager *self = QMLManager::instance();
@ -92,18 +93,24 @@ static void appendTextToLogStandalone(const char *text)
self->appendTextToLog(QString(text));
}
// this callback is used from the uiNotification() function
// the detour via callback allows us to keep the core code independent from QMLManager
// I'm not sure it makes sense to have three different progress callbacks,
// but the usage models (and the situations in the program flow where they are used)
// are really vastly different...
// this is mainly intended for the early stages of the app so the user sees that
// things are progressing
static void showProgress(QString msg)
{
QMLManager *self = QMLManager::instance();
if (self)
self->setNotificationText(msg);
}
// show the git progress in the passive notification area
extern "C" int gitProgressCB(const char *text)
{
static QMLManager *self;
if (!self)
self = QMLManager::instance();
if (self) {
self->appendTextToLog(text);
self->setNotificationText(text);
}
showProgress(QString(text));
// return 0 so that we don't end the download
return 0;
}
@ -162,6 +169,8 @@ void QMLManager::usbRescan()
#endif
}
extern void (*uiNotificationCallback)(QString);
QMLManager::QMLManager() : m_locationServiceEnabled(false),
m_verboseEnabled(false),
m_diveListProcessing(false),
@ -233,6 +242,7 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
}
#endif
set_error_cb(&showErrorFromC);
uiNotificationCallback = showProgress;
appendTextToLog("Starting " + getUserAgent());
appendTextToLog(QStringLiteral("built with libdivecomputer v%1").arg(dc_version(NULL)));
appendTextToLog(QStringLiteral("built with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion()));
@ -244,7 +254,6 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
extern QString getAndroidHWInfo();
appendTextToLog(getAndroidHWInfo());
#endif
setStartPageText(tr("Starting..."));
if (ignore_bt) {
m_btEnabled = false;
} else {
@ -1705,8 +1714,10 @@ QString QMLManager::getGpsFromSiteName(const QString &siteName)
void QMLManager::setNotificationText(QString text)
{
appendTextToLog(QStringLiteral("showProgress: ") + text);
m_notificationText = text;
emit notificationTextChanged();
qApp->processEvents();
}
qreal QMLManager::lastDevicePixelRatio()