mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
QML UI: redesign the user notification
The old system of cloud access updates with fake percentages just wasn't helpful. Even worse, it hid a lot important information from the user. This should be more useful (but it will require that we localize the messages sent from the git progress notifications and make them more 'user ready'). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
2d5f023b58
commit
b2b51c833a
9 changed files with 106 additions and 130 deletions
|
@ -52,18 +52,18 @@ bool CheckCloudConnection::checkServer()
|
|||
mgr->deleteLater();
|
||||
if (verbose > 1)
|
||||
qWarning() << "Cloud storage: successfully checked connection to cloud server";
|
||||
git_storage_update_progress(false, "successfully checked cloud connection");
|
||||
git_storage_update_progress("successfully checked cloud connection");
|
||||
return true;
|
||||
}
|
||||
} else if (seconds < prefs.cloud_timeout) {
|
||||
QString text = QString("waited %1 sec for cloud connetion").arg(seconds);
|
||||
git_storage_update_progress(false, qPrintable(text));
|
||||
git_storage_update_progress(qPrintable(text));
|
||||
} else {
|
||||
disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
reply->abort();
|
||||
}
|
||||
}
|
||||
git_storage_update_progress(false, "cloud connection failed");
|
||||
git_storage_update_progress("cloud connection failed");
|
||||
prefs.git_local_only = true;
|
||||
if (verbose)
|
||||
qDebug() << "connection test to cloud server failed" <<
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
|
||||
bool is_subsurface_cloud = false;
|
||||
|
||||
int (*update_progress_cb)(bool, const char *) = NULL;
|
||||
int (*update_progress_cb)(const char *) = NULL;
|
||||
|
||||
void set_git_update_cb(int(*cb)(bool, const char *))
|
||||
void set_git_update_cb(int(*cb)(const char *))
|
||||
{
|
||||
update_progress_cb = cb;
|
||||
}
|
||||
|
@ -38,11 +38,11 @@ void set_git_update_cb(int(*cb)(bool, const char *))
|
|||
// proportional - some parts are based on compute performance, some on network speed)
|
||||
// they also provide information where in the process we are so we can analyze the log
|
||||
// to understand which parts of the process take how much time.
|
||||
int git_storage_update_progress(bool reset, const char *text)
|
||||
int git_storage_update_progress(const char *text)
|
||||
{
|
||||
int ret = 0;
|
||||
if (update_progress_cb)
|
||||
ret = (*update_progress_cb)(reset, text);
|
||||
ret = (*update_progress_cb)(text);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -52,12 +52,9 @@ static void progress_cb(const char *path, size_t completed_steps, size_t total_s
|
|||
{
|
||||
(void) path;
|
||||
(void) payload;
|
||||
static size_t last_percent = -1;
|
||||
|
||||
if (total_steps && 20 * completed_steps / total_steps > last_percent) {
|
||||
(void)git_storage_update_progress(false, "checkout_progress_cb");
|
||||
last_percent = 20 * completed_steps / total_steps;
|
||||
}
|
||||
char buf[80];
|
||||
snprintf(buf, sizeof(buf), translate("gettextFromC", "Checkout from storage (%lu/%lu)"), completed_steps, total_steps);
|
||||
(void)git_storage_update_progress(buf);
|
||||
}
|
||||
|
||||
// this randomly assumes that 80% of the time is spent on the objects and 20% on the deltas
|
||||
|
@ -66,21 +63,29 @@ static void progress_cb(const char *path, size_t completed_steps, size_t total_s
|
|||
static int transfer_progress_cb(const git_transfer_progress *stats, void *payload)
|
||||
{
|
||||
(void) payload;
|
||||
static int last_percent = -1;
|
||||
|
||||
int percent = 0;
|
||||
if (stats->total_objects)
|
||||
percent = 16 * stats->received_objects / stats->total_objects;
|
||||
if (stats->total_deltas)
|
||||
percent += 4 * stats->indexed_deltas / stats->total_deltas;
|
||||
static int last_done = -1;
|
||||
char buf[80];
|
||||
int done = 0;
|
||||
int total = 0;
|
||||
|
||||
if (stats->total_objects) {
|
||||
total = 60;
|
||||
done = 60 * stats->received_objects / stats->total_objects;
|
||||
}
|
||||
if (stats->total_deltas) {
|
||||
total += 20;
|
||||
done += 20 * stats->indexed_deltas / stats->total_deltas;
|
||||
}
|
||||
/* for debugging this is useful
|
||||
char buf[100];
|
||||
snprintf(buf, 100, "transfer cb rec_obj %d tot_obj %d idx_delta %d total_delta %d local obj %d", stats->received_objects, stats->total_objects, stats->indexed_deltas, stats->total_deltas, stats->local_objects);
|
||||
return git_storage_update_progress(false, buf);
|
||||
return git_storage_update_progress(buf);
|
||||
*/
|
||||
if (percent > last_percent) {
|
||||
last_percent = percent;
|
||||
return git_storage_update_progress(false, "transfer cb");
|
||||
if (done > last_done) {
|
||||
last_done = done;
|
||||
snprintf(buf, sizeof(buf), translate("gettextFromC", "Transfer from storage (%d/%d)"), done, total);
|
||||
return git_storage_update_progress(buf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -90,16 +95,9 @@ static int push_transfer_progress_cb(unsigned int current, unsigned int total, s
|
|||
{
|
||||
(void) bytes;
|
||||
(void) payload;
|
||||
static int last_percent = -1;
|
||||
int percent = 0;
|
||||
|
||||
if (total != 0)
|
||||
percent = 5 * current / total;
|
||||
if (percent > last_percent) {
|
||||
last_percent = percent;
|
||||
return git_storage_update_progress(false, "push trasfer cb");
|
||||
}
|
||||
return 0;
|
||||
char buf[80];
|
||||
snprintf(buf, sizeof(buf), translate("gettextFromC", "Transfer to storage (%d/%d)"), current, total);
|
||||
return git_storage_update_progress("push trasfer cb");
|
||||
}
|
||||
|
||||
char *get_local_dir(const char *remote, const char *branch)
|
||||
|
@ -434,7 +432,7 @@ static int try_to_update(git_repository *repo, git_remote *origin, git_reference
|
|||
|
||||
if (verbose)
|
||||
fprintf(stderr, "git storage: try to update\n");
|
||||
git_storage_update_progress(false, "try to update");
|
||||
git_storage_update_progress("try to update");
|
||||
if (!git_reference_cmp(local, remote))
|
||||
return 0;
|
||||
|
||||
|
@ -468,7 +466,7 @@ static int try_to_update(git_repository *repo, git_remote *origin, git_reference
|
|||
}
|
||||
/* Is the remote strictly newer? Use it */
|
||||
if (git_oid_equal(&base, local_id)) {
|
||||
git_storage_update_progress(false, "fast forward to remote");
|
||||
git_storage_update_progress("fast forward to remote");
|
||||
return reset_to_remote(repo, local, remote_id);
|
||||
}
|
||||
|
||||
|
@ -476,7 +474,7 @@ static int try_to_update(git_repository *repo, git_remote *origin, git_reference
|
|||
if (git_oid_equal(&base, remote_id)) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "local is newer than remote, update remote\n");
|
||||
git_storage_update_progress(false, "git_update_remote, local was newer");
|
||||
git_storage_update_progress("git_update_remote, local was newer");
|
||||
return update_remote(repo, origin, local, remote, rt);
|
||||
}
|
||||
/* Merging a bare repository always needs user action */
|
||||
|
@ -494,7 +492,7 @@ static int try_to_update(git_repository *repo, git_remote *origin, git_reference
|
|||
return report_error("Local and remote do not match, local branch not HEAD - cannot update");
|
||||
}
|
||||
/* Ok, let's try to merge these */
|
||||
git_storage_update_progress(false, "try to merge");
|
||||
git_storage_update_progress("try to merge");
|
||||
ret = try_to_git_merge(repo, &local, remote, &base, local_id, remote_id);
|
||||
if (ret == 0)
|
||||
return update_remote(repo, origin, local, remote, rt);
|
||||
|
@ -516,7 +514,7 @@ static int check_remote_status(git_repository *repo, git_remote *origin, const c
|
|||
|
||||
if (verbose)
|
||||
fprintf(stderr, "git storage: check remote status\n");
|
||||
git_storage_update_progress(false, "git check remote status");
|
||||
git_storage_update_progress("git check remote status");
|
||||
|
||||
if (git_branch_lookup(&local_ref, repo, branch, GIT_BRANCH_LOCAL)) {
|
||||
if (is_subsurface_cloud)
|
||||
|
@ -537,7 +535,7 @@ static int check_remote_status(git_repository *repo, git_remote *origin, const c
|
|||
else if (rt == RT_HTTPS)
|
||||
opts.callbacks.credentials = credential_https_cb;
|
||||
opts.callbacks.certificate_check = certificate_check_cb;
|
||||
git_storage_update_progress(false, "git remote push (no remote existed)");
|
||||
git_storage_update_progress("git remote push (no remote existed)");
|
||||
error = git_remote_push(origin, &refspec, &opts);
|
||||
} else {
|
||||
error = try_to_update(repo, origin, local_ref, remote_ref, remote, branch, rt);
|
||||
|
@ -561,7 +559,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc
|
|||
}
|
||||
if (verbose)
|
||||
fprintf(stderr, "sync with remote %s[%s]\n", remote, branch);
|
||||
git_storage_update_progress(false, "sync with remote");
|
||||
git_storage_update_progress("sync with remote");
|
||||
git_repository_config(&conf, repo);
|
||||
if (rt == RT_HTTPS && getProxyString(&proxy_string)) {
|
||||
if (verbose)
|
||||
|
@ -588,7 +586,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc
|
|||
if (rt == RT_HTTPS && !canReachCloudServer()) {
|
||||
// this is not an error, just a warning message, so return 0
|
||||
report_error("Cannot connect to cloud server, working with local copy");
|
||||
git_storage_update_progress(false, "can't reach cloud server, working with local copy");
|
||||
git_storage_update_progress("can't reach cloud server, working with local copy");
|
||||
return 0;
|
||||
}
|
||||
if (verbose)
|
||||
|
@ -601,7 +599,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc
|
|||
else if (rt == RT_HTTPS)
|
||||
opts.callbacks.credentials = credential_https_cb;
|
||||
opts.callbacks.certificate_check = certificate_check_cb;
|
||||
git_storage_update_progress(false, "git fetch remote");
|
||||
git_storage_update_progress("git fetch remote");
|
||||
error = git_remote_fetch(origin, NULL, &opts, NULL);
|
||||
// NOTE! A fetch error is not fatal, we just report it
|
||||
if (error) {
|
||||
|
@ -616,7 +614,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc
|
|||
error = check_remote_status(repo, origin, remote, branch, rt);
|
||||
}
|
||||
git_remote_free(origin);
|
||||
git_storage_update_progress(false, "done with sync with remote");
|
||||
git_storage_update_progress("done with sync with remote");
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -636,9 +634,10 @@ static git_repository *update_local_repo(const char *localdir, const char *remot
|
|||
report_error("Unable to open git cache repository at %s: %s", localdir, giterr_last()->message);
|
||||
return NULL;
|
||||
}
|
||||
if (!prefs.git_local_only)
|
||||
if (!prefs.git_local_only) {
|
||||
git_storage_update_progress("update remote repo");
|
||||
sync_with_remote(repo, remote, branch, rt);
|
||||
|
||||
}
|
||||
return repo;
|
||||
}
|
||||
|
||||
|
@ -774,7 +773,7 @@ static struct git_repository *get_remote_repo(const char *localdir, const char *
|
|||
if (verbose > 1) {
|
||||
fprintf(stderr, "git_remote_repo: accessing %s\n", remote);
|
||||
}
|
||||
git_storage_update_progress(false, "start git interaction");
|
||||
git_storage_update_progress("start git interaction");
|
||||
/* Do we already have a local cache? */
|
||||
if (!subsurface_stat(localdir, &st)) {
|
||||
if (!S_ISDIR(st.st_mode)) {
|
||||
|
|
|
@ -25,8 +25,8 @@ extern int do_git_save(git_repository *repo, const char *branch, const char *rem
|
|||
extern const char *saved_git_id;
|
||||
extern void clear_git_id(void);
|
||||
extern void set_git_id(const struct git_oid *);
|
||||
void set_git_update_cb(int(*)(bool, const char *));
|
||||
int git_storage_update_progress(bool reset, const char *text);
|
||||
void set_git_update_cb(int(*)(const char *));
|
||||
int git_storage_update_progress(const char *text);
|
||||
char *get_local_dir(const char *remote, const char *branch);
|
||||
int git_create_local_repo(const char *filename);
|
||||
|
||||
|
|
|
@ -1675,19 +1675,19 @@ static int do_git_load(git_repository *repo, const char *branch)
|
|||
git_commit *commit;
|
||||
git_tree *tree;
|
||||
|
||||
git_storage_update_progress(false, "do_git_load, find the commit");
|
||||
git_storage_update_progress("do_git_load, find the commit");
|
||||
ret = find_commit(repo, branch, &commit);
|
||||
if (ret)
|
||||
return ret;
|
||||
git_storage_update_progress(false, "git commit tree");
|
||||
git_storage_update_progress("git commit tree");
|
||||
if (git_commit_tree(&tree, commit))
|
||||
return report_error("Could not look up tree of commit in branch '%s'", branch);
|
||||
git_storage_update_progress(false, "load dives from tree");
|
||||
git_storage_update_progress("load dives from tree");
|
||||
ret = load_dives_from_tree(repo, tree);
|
||||
if (!ret)
|
||||
set_git_id(git_commit_id(commit));
|
||||
git_object_free((git_object *)tree);
|
||||
git_storage_update_progress(false, "done do_git_load");
|
||||
git_storage_update_progress("done do_git_load");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -936,7 +936,7 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o
|
|||
struct dive *dive;
|
||||
dive_trip_t *trip;
|
||||
|
||||
git_storage_update_progress(false, "start create git tree");
|
||||
git_storage_update_progress("start create git tree");
|
||||
save_settings(repo, root);
|
||||
|
||||
save_divesites(repo, root);
|
||||
|
@ -945,7 +945,7 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o
|
|||
trip->index = 0;
|
||||
|
||||
/* save the dives */
|
||||
git_storage_update_progress(false, "start saving dives");
|
||||
git_storage_update_progress("start saving dives");
|
||||
for_each_dive(i, dive) {
|
||||
struct tm tm;
|
||||
struct dir *tree;
|
||||
|
@ -978,7 +978,7 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o
|
|||
|
||||
save_one_dive(repo, tree, dive, &tm, cached_ok);
|
||||
}
|
||||
git_storage_update_progress(false, "done creating git tree");
|
||||
git_storage_update_progress("done creating git tree");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1209,7 +1209,7 @@ int do_git_save(git_repository *repo, const char *branch, const char *remote, bo
|
|||
fprintf(stderr, "git storage: do git save\n");
|
||||
|
||||
if (!create_empty) // so we are actually saving the dives
|
||||
git_storage_update_progress(false, "start git save");
|
||||
git_storage_update_progress("start git save");
|
||||
|
||||
/*
|
||||
* Check if we can do the cached writes - we need to
|
||||
|
|
|
@ -66,16 +66,17 @@
|
|||
QProgressDialog *progressDialog = NULL;
|
||||
bool progressDialogCanceled = false;
|
||||
|
||||
extern "C" int updateProgress(bool reset, const char *text)
|
||||
extern "C" int updateProgress(const char *text)
|
||||
{
|
||||
static int percent;
|
||||
|
||||
if (reset)
|
||||
percent = 0;
|
||||
static int progress = 0;
|
||||
if (verbose)
|
||||
qDebug() << "git storage:" << +percent << "% (" << text << ")";
|
||||
if (progressDialog)
|
||||
progressDialog->setValue(percent);
|
||||
qDebug() << "git storage:" << text;
|
||||
if (progressDialog) {
|
||||
progressDialog->setLabelText(text);
|
||||
progressDialog->setValue(++progress);
|
||||
if (progress == 100)
|
||||
progress = 0; // yes this is silly, but we really don't know how long it will take
|
||||
}
|
||||
qApp->processEvents();
|
||||
return progressDialogCanceled;
|
||||
}
|
||||
|
@ -2015,7 +2016,7 @@ void MainWindow::showProgressBar()
|
|||
|
||||
progressDialog = new QProgressDialog(tr("Contacting cloud service..."), tr("Cancel"), 0, 100, this);
|
||||
progressDialog->setWindowModality(Qt::WindowModal);
|
||||
progressDialog->setMinimumDuration(200);
|
||||
progressDialog->setMinimumDuration(0);
|
||||
progressDialogCanceled = false;
|
||||
connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelCloudStorageOperation()));
|
||||
}
|
||||
|
|
|
@ -19,23 +19,19 @@ Kirigami.ApplicationWindow {
|
|||
}
|
||||
property bool fullscreen: true
|
||||
property alias oldStatus: manager.oldStatus
|
||||
property alias accessingCloud: manager.accessingCloud
|
||||
property alias notificationText: manager.notificationText
|
||||
property QtObject notification: null
|
||||
property bool showingDiveList: false
|
||||
property alias syncToCloud: manager.syncToCloud
|
||||
property alias showPin: manager.showPin
|
||||
|
||||
onAccessingCloudChanged: {
|
||||
// >= 0 for updating cloud, -1 for hide, < -1 for local storage
|
||||
if (accessingCloud >= 0) {
|
||||
// we now keep updating this to show progress, so timing out after 30 seconds is more useful
|
||||
// but should still be very conservative
|
||||
showPassiveNotification("Accessing Subsurface cloud storage " + accessingCloud +"%", 30000);
|
||||
} else if (accessingCloud < -1) {
|
||||
// local storage should be much faster, so timeout of 5 seconds
|
||||
// the offset of 2 is so that things start 0 again
|
||||
showPassiveNotification("Accessing local storage " + -(accessingCloud + 2) +"%", 5000);
|
||||
onNotificationTextChanged: {
|
||||
if (notificationText != "") {
|
||||
// there's a risk that we have a >5 second gap in update events;
|
||||
// still, keep the timeout at 5s to avoid odd unchanging notifications
|
||||
showPassiveNotification(notificationText, 5000)
|
||||
} else {
|
||||
// hiding the notification right away may be a mistake as it hides the last warning / error
|
||||
hidePassiveNotification();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,37 +40,24 @@ static void appendTextToLogStandalone(const char *text)
|
|||
self->appendTextToLog(QString(text));
|
||||
}
|
||||
|
||||
extern "C" int gitProgressCB(bool reset, const char *text)
|
||||
// show the git progress in the passive notification area
|
||||
extern "C" int gitProgressCB(const char *text)
|
||||
{
|
||||
static QElapsedTimer timer;
|
||||
static qint64 lastTime;
|
||||
static QString lastText;
|
||||
static QMLManager *self;
|
||||
static int lastPercent;
|
||||
|
||||
if (!self)
|
||||
self = QMLManager::instance();
|
||||
|
||||
if (!timer.isValid() || reset) {
|
||||
if (!timer.isValid()) {
|
||||
timer.restart();
|
||||
lastTime = 0;
|
||||
lastPercent = prefs.git_local_only ? -2 : 0;
|
||||
lastText.clear();
|
||||
}
|
||||
if (self) {
|
||||
qint64 elapsed = timer.elapsed();
|
||||
// don't show the same status twice in 200ms
|
||||
if (lastText == text && elapsed - lastTime < 200)
|
||||
return 0;
|
||||
if (lastPercent < 0)
|
||||
lastPercent--;
|
||||
else
|
||||
lastPercent++;
|
||||
self->loadDiveProgress(lastPercent);
|
||||
QString logText = QString::number(elapsed / 1000.0, 'f', 1) + " / " + QString::number((elapsed - lastTime) / 1000.0, 'f', 3) +
|
||||
QString(" : git %1 (%2)").arg(lastPercent).arg(text);
|
||||
self->appendTextToLog(logText);
|
||||
qDebug() << logText;
|
||||
self->appendTextToLog(text);
|
||||
self->setNotificationText(text);
|
||||
if (elapsed - lastTime > 500)
|
||||
qApp->processEvents();
|
||||
lastTime = elapsed;
|
||||
|
@ -101,7 +88,6 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
|
|||
qDebug() << "Starting" << getUserAgent();
|
||||
qDebug() << QStringLiteral("build with Qt Version %1, runtime from Qt Version %2").arg(QT_VERSION_STR).arg(qVersion());
|
||||
setStartPageText(tr("Starting..."));
|
||||
setAccessingCloud(-1);
|
||||
setShowPin(false);
|
||||
// create location manager service
|
||||
locationProvider = new GpsLocation(&appendTextToLogStandalone, this);
|
||||
|
@ -145,14 +131,15 @@ void QMLManager::applicationStateChanged(Qt::ApplicationState state)
|
|||
void QMLManager::openLocalThenRemote(QString url)
|
||||
{
|
||||
clear_dive_file_data();
|
||||
setNotificationText(tr("Open local dive data file"));
|
||||
QByteArray fileNamePrt = QFile::encodeName(url);
|
||||
bool glo = prefs.git_local_only;
|
||||
prefs.git_local_only = true;
|
||||
int error = parse_file(fileNamePrt.data());
|
||||
setAccessingCloud(-1);
|
||||
prefs.git_local_only = glo;
|
||||
if (error) {
|
||||
appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error));
|
||||
setNotificationText(tr("Opening local data file failed"));
|
||||
} else {
|
||||
// if we can load from the cache, we know that we have at least a valid email
|
||||
if (credentialStatus() == UNKNOWN)
|
||||
|
@ -172,6 +159,7 @@ void QMLManager::openLocalThenRemote(QString url)
|
|||
DiveListModel::instance()->clear();
|
||||
DiveListModel::instance()->addAllDives();
|
||||
appendTextToLog(QStringLiteral("%1 dives loaded from cache").arg(dive_table.nr));
|
||||
setNotificationText(tr("%1 dives loaded from local dive data file").arg(dive_table.nr));
|
||||
}
|
||||
if (oldStatus() == NOCLOUD) {
|
||||
// if we switch to credentials from NOCLOUD, we take things online temporarily
|
||||
|
@ -217,11 +205,11 @@ void QMLManager::finishSetup()
|
|||
if (error) {
|
||||
// we got an error loading the local file
|
||||
appendTextToLog(QString("got error %2 when parsing file %1").arg(existing_filename, get_error_string()));
|
||||
setNotificationText(tr("Error parsing local storage, giving up"));
|
||||
set_filename(NULL, "");
|
||||
} else {
|
||||
// successfully opened the local file, now add thigs to the dive list
|
||||
consumeFinishedLoad(0);
|
||||
setAccessingCloud(-1);
|
||||
appendTextToLog(QString("working in no-cloud mode, finished loading %1 dives from %2").arg(dive_table.nr).arg(existing_filename));
|
||||
}
|
||||
} else {
|
||||
|
@ -315,7 +303,6 @@ void QMLManager::checkCredentialsAndExecute(execute_function_type execute)
|
|||
// and (if we haven't done so) load the dive list
|
||||
if (!same_string(prefs.cloud_storage_email, "") &&
|
||||
!same_string(prefs.cloud_storage_password, "")) {
|
||||
setAccessingCloud(0);
|
||||
setStartPageText(tr("Testing cloud credentials"));
|
||||
appendTextToLog("Have credentials, let's see if they are valid");
|
||||
CloudStorageAuthenticate *csa = new CloudStorageAuthenticate(this);
|
||||
|
@ -390,7 +377,7 @@ void QMLManager::handleSslErrors(const QList<QSslError> &errors)
|
|||
}
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
setAccessingCloud(-1);
|
||||
setNotificationText(QStringLiteral(""));
|
||||
}
|
||||
|
||||
void QMLManager::handleError(QNetworkReply::NetworkError nError)
|
||||
|
@ -400,7 +387,7 @@ void QMLManager::handleError(QNetworkReply::NetworkError nError)
|
|||
setStartPageText(RED_FONT + tr("Cannot open cloud storage: %1").arg(errorString) + END_FONT);
|
||||
reply->abort();
|
||||
reply->deleteLater();
|
||||
setAccessingCloud(-1);
|
||||
setNotificationText(QStringLiteral(""));
|
||||
}
|
||||
|
||||
void QMLManager::retrieveUserid()
|
||||
|
@ -434,16 +421,11 @@ void QMLManager::retrieveUserid()
|
|||
}
|
||||
setCredentialStatus(VALID);
|
||||
setStartPageText("Cloud credentials valid, loading dives...");
|
||||
git_storage_update_progress(true, "load dives with valid credentials");
|
||||
git_storage_update_progress("load dives with valid credentials");
|
||||
// this only gets called with "alreadySaving" already locked
|
||||
loadDivesWithValidCredentials();
|
||||
}
|
||||
|
||||
void QMLManager::loadDiveProgress(int percent)
|
||||
{
|
||||
setAccessingCloud(percent);
|
||||
}
|
||||
|
||||
void QMLManager::loadDivesWithValidCredentials()
|
||||
{
|
||||
QString url;
|
||||
|
@ -474,16 +456,16 @@ void QMLManager::loadDivesWithValidCredentials()
|
|||
appendTextToLog(QString("didn't receive valid git repo, try again"));
|
||||
error = parse_file(fileNamePrt.data());
|
||||
}
|
||||
setAccessingCloud(-1);
|
||||
if (!error) {
|
||||
report_error("filename is now %s", fileNamePrt.data());
|
||||
const char *error_string = get_error_string();
|
||||
appendTextToLog(error_string);
|
||||
QString errorString(get_error_string());
|
||||
appendTextToLog(errorString);
|
||||
set_filename(fileNamePrt.data(), true);
|
||||
} else {
|
||||
report_error("failed to open file %s", fileNamePrt.data());
|
||||
QString errorString(get_error_string());
|
||||
appendTextToLog(errorString);
|
||||
setNotificationText(errorString);
|
||||
revertToNoCloudIfNeeded();
|
||||
return;
|
||||
}
|
||||
|
@ -495,7 +477,7 @@ successful_exit:
|
|||
// if we came from local storage mode, let's merge the local data into the local cache
|
||||
// for the remote data - which then later gets merged with the remote data if necessary
|
||||
if (oldStatus() == NOCLOUD) {
|
||||
git_storage_update_progress(false, "import dives from nocloud local storage");
|
||||
git_storage_update_progress("import dives from nocloud local storage");
|
||||
dive_table.preexisting = dive_table.nr;
|
||||
mergeLocalRepo();
|
||||
DiveListModel::instance()->clear();
|
||||
|
@ -507,7 +489,6 @@ successful_exit:
|
|||
prefs.git_local_only = syncToCloud();
|
||||
}
|
||||
}
|
||||
setAccessingCloud(-1);
|
||||
// if we got here just for an initial connection to the cloud, reset to offline
|
||||
if (currentGitLocalOnly) {
|
||||
currentGitLocalOnly = false;
|
||||
|
@ -543,7 +524,6 @@ void QMLManager::revertToNoCloudIfNeeded()
|
|||
set_filename(NOCLOUD_LOCALSTORAGE, true);
|
||||
setStartPageText(RED_FONT + tr("Failed to connect to cloud server, reverting to no cloud status") + END_FONT);
|
||||
}
|
||||
setAccessingCloud(-1);
|
||||
alreadySaving = false;
|
||||
}
|
||||
|
||||
|
@ -964,7 +944,7 @@ void QMLManager::changesNeedSaving()
|
|||
void QMLManager::saveChangesLocal()
|
||||
{
|
||||
if (unsaved_changes()) {
|
||||
git_storage_update_progress(true, "saving dives locally"); // reset the timers
|
||||
git_storage_update_progress("saving dives locally");
|
||||
if (credentialStatus() == NOCLOUD) {
|
||||
if (same_string(existing_filename, "")) {
|
||||
char *filename = NOCLOUD_LOCALSTORAGE;
|
||||
|
@ -990,16 +970,17 @@ void QMLManager::saveChangesLocal()
|
|||
bool glo = prefs.git_local_only;
|
||||
prefs.git_local_only = true;
|
||||
if (save_dives(existing_filename)) {
|
||||
appendTextToLog(get_error_string());
|
||||
QString errorString(get_error_string());
|
||||
appendTextToLog(errorString);
|
||||
setNotificationText(errorString);
|
||||
set_filename(NULL, true);
|
||||
setAccessingCloud(-1);
|
||||
prefs.git_local_only = glo;
|
||||
alreadySaving = false;
|
||||
return;
|
||||
}
|
||||
prefs.git_local_only = glo;
|
||||
mark_divelist_changed(false);
|
||||
git_storage_update_progress(false, "done with local save");
|
||||
git_storage_update_progress("done with local save");
|
||||
alreadySaving = false;
|
||||
} else {
|
||||
appendTextToLog("local save requested with no unsaved changes");
|
||||
|
@ -1017,6 +998,7 @@ void QMLManager::saveChangesCloud(bool forceRemoteSync)
|
|||
return;
|
||||
}
|
||||
// first we need to store any unsaved changes to the local repo
|
||||
gitProgressCB("Save changes to local cache");
|
||||
saveChangesLocal();
|
||||
|
||||
// if the user asked not to push to the cloud we are done
|
||||
|
@ -1029,13 +1011,12 @@ void QMLManager::saveChangesCloud(bool forceRemoteSync)
|
|||
}
|
||||
|
||||
bool glo = prefs.git_local_only;
|
||||
git_storage_update_progress(false, "start save change to cloud");
|
||||
git_storage_update_progress("start save change to cloud");
|
||||
prefs.git_local_only = false;
|
||||
alreadySaving = true;
|
||||
loadDivesWithValidCredentials();
|
||||
alreadySaving = false;
|
||||
git_storage_update_progress(false, "finished syncing dive list to cloud server");
|
||||
setAccessingCloud(-1);
|
||||
git_storage_update_progress("finished syncing dive list to cloud server");
|
||||
prefs.git_local_only = glo;
|
||||
}
|
||||
|
||||
|
@ -1366,15 +1347,15 @@ QString QMLManager::getVersion() const
|
|||
return versionRe.cap(1);
|
||||
}
|
||||
|
||||
int QMLManager::accessingCloud() const
|
||||
QString QMLManager::notificationText() const
|
||||
{
|
||||
return m_accessingCloud;
|
||||
return m_notificationText;
|
||||
}
|
||||
|
||||
void QMLManager::setAccessingCloud(int status)
|
||||
void QMLManager::setNotificationText(QString text)
|
||||
{
|
||||
m_accessingCloud = status;
|
||||
emit accessingCloudChanged();
|
||||
m_notificationText = text;
|
||||
emit notificationTextChanged();
|
||||
}
|
||||
|
||||
bool QMLManager::syncToCloud() const
|
||||
|
|
|
@ -29,7 +29,7 @@ class QMLManager : public QObject {
|
|||
Q_PROPERTY(bool verboseEnabled READ verboseEnabled WRITE setVerboseEnabled NOTIFY verboseEnabledChanged)
|
||||
Q_PROPERTY(credentialStatus_t credentialStatus READ credentialStatus WRITE setCredentialStatus NOTIFY credentialStatusChanged)
|
||||
Q_PROPERTY(credentialStatus_t oldStatus READ oldStatus WRITE setOldStatus NOTIFY oldStatusChanged)
|
||||
Q_PROPERTY(int accessingCloud READ accessingCloud WRITE setAccessingCloud NOTIFY accessingCloudChanged)
|
||||
Q_PROPERTY(QString notificationText READ notificationText WRITE setNotificationText NOTIFY notificationTextChanged)
|
||||
Q_PROPERTY(bool syncToCloud READ syncToCloud WRITE setSyncToCloud NOTIFY syncToCloudChanged)
|
||||
Q_PROPERTY(int updateSelectedDive READ updateSelectedDive WRITE setUpdateSelectedDive NOTIFY updateSelectedDiveChanged)
|
||||
Q_PROPERTY(int selectedDiveTimestamp READ selectedDiveTimestamp WRITE setSelectedDiveTimestamp NOTIFY selectedDiveTimestampChanged)
|
||||
|
@ -94,8 +94,8 @@ public:
|
|||
QString logText() const;
|
||||
void setLogText(const QString &logText);
|
||||
|
||||
int accessingCloud() const;
|
||||
void setAccessingCloud(int status);
|
||||
QString notificationText() const;
|
||||
void setNotificationText(QString text);
|
||||
|
||||
bool syncToCloud() const;
|
||||
void setSyncToCloud(bool status);
|
||||
|
@ -126,7 +126,6 @@ public slots:
|
|||
void handleSslErrors(const QList<QSslError> &errors);
|
||||
void retrieveUserid();
|
||||
void loadDivesWithValidCredentials();
|
||||
void loadDiveProgress(int percent);
|
||||
void provideAuth(QNetworkReply *reply, QAuthenticator *auth);
|
||||
void commitChanges(QString diveId, QString date, QString location, QString gps,
|
||||
QString duration, QString depth, QString airtemp,
|
||||
|
@ -182,7 +181,7 @@ private:
|
|||
QNetworkRequest request;
|
||||
struct dive *deletedDive;
|
||||
struct dive_trip *deletedTrip;
|
||||
int m_accessingCloud;
|
||||
QString m_notificationText;
|
||||
bool m_syncToCloud;
|
||||
int m_updateSelectedDive;
|
||||
int m_selectedDiveTimestamp;
|
||||
|
@ -213,7 +212,7 @@ signals:
|
|||
void startPageTextChanged();
|
||||
void credentialStatusChanged();
|
||||
void oldStatusChanged();
|
||||
void accessingCloudChanged();
|
||||
void notificationTextChanged();
|
||||
void syncToCloudChanged();
|
||||
void updateSelectedDiveChanged();
|
||||
void selectedDiveTimestampChanged();
|
||||
|
|
Loading…
Reference in a new issue