Turn take-cloud-online menu action into checkbox

Replace the "Take cloud storage online" menu entry by a "Cloud online"
checkbox. After this change, the user can also force going offline.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-01-03 11:46:21 +01:00 committed by Dirk Hohndel
parent dbef391786
commit bb64c6bda8
3 changed files with 44 additions and 29 deletions

View file

@ -441,7 +441,8 @@ void MainWindow::enableDisableCloudActions()
{ {
ui.actionCloudstorageopen->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); ui.actionCloudstorageopen->setEnabled(prefs.cloud_verification_status == CS_VERIFIED);
ui.actionCloudstoragesave->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); ui.actionCloudstoragesave->setEnabled(prefs.cloud_verification_status == CS_VERIFIED);
ui.actionTake_cloud_storage_online->setEnabled(prefs.cloud_verification_status == CS_VERIFIED && prefs.git_local_only); ui.actionCloudOnline->setEnabled(prefs.cloud_verification_status == CS_VERIFIED);
ui.actionCloudOnline->setChecked(prefs.cloud_verification_status == CS_VERIFIED && !prefs.git_local_only);
} }
PlannerDetails *MainWindow::plannerDetails() const { PlannerDetails *MainWindow::plannerDetails() const {
@ -645,15 +646,25 @@ void MainWindow::on_actionCloudstoragesave_triggered()
mark_divelist_changed(false); mark_divelist_changed(false);
} }
void MainWindow::on_actionTake_cloud_storage_online_triggered() void MainWindow::on_actionCloudOnline_triggered()
{ {
bool isOffline = !ui.actionCloudOnline->isChecked();
if (isOffline == prefs.git_local_only)
return;
// Refuse to go online if there is an edit in progress // Refuse to go online if there is an edit in progress
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || if (!isOffline &&
information()->isEditing() ) { (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
information()->isEditing())) {
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before going online")); QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before going online"));
// We didn't switch to online, therefore uncheck the checkbox
ui.actionCloudOnline->setChecked(false);
return; return;
} }
prefs.git_local_only = isOffline;
if (!isOffline) {
// User requests to go online. Try to sync cloud storage
prefs.git_local_only = false; prefs.git_local_only = false;
if (unsaved_changes()) { if (unsaved_changes()) {
// If there are unsaved changes, ask the user if they want to save them. // If there are unsaved changes, ask the user if they want to save them.
@ -664,14 +675,16 @@ void MainWindow::on_actionTake_cloud_storage_online_triggered()
"\"Open cloud storage\" or \"Save to cloud storage\"."), "\"Open cloud storage\" or \"Save to cloud storage\"."),
QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes)
on_actionCloudstoragesave_triggered(); on_actionCloudstoragesave_triggered();
else
setTitle();
} else { } else {
// If there are no unsaved changes, let's just try to load the remote cloud // If there are no unsaved changes, let's just try to load the remote cloud
on_actionCloudstorageopen_triggered(); on_actionCloudstorageopen_triggered();
} }
if (prefs.git_local_only) if (prefs.git_local_only)
report_error(qPrintable(tr("Failure taking cloud storage online"))); report_error(qPrintable(tr("Failure taking cloud storage online")));
}
setTitle();
ui.actionCloudOnline->setChecked(!prefs.git_local_only);
} }
void learnImageDirs(QStringList dirnames) void learnImageDirs(QStringList dirnames)
@ -1727,12 +1740,11 @@ QString MainWindow::displayedFilename(QString fullFilename)
if (fullFilename.contains(prefs.cloud_git_url)) { if (fullFilename.contains(prefs.cloud_git_url)) {
QString email = fileName.left(fileName.indexOf('[')); QString email = fileName.left(fileName.indexOf('['));
if (prefs.git_local_only) { ui.actionCloudOnline->setChecked(!prefs.git_local_only);
ui.actionTake_cloud_storage_online->setEnabled(true); if (prefs.git_local_only)
return tr("[local cache for] %1").arg(email); return tr("[local cache for] %1").arg(email);
} else { else
return tr("[cloud storage for] %1").arg(email); return tr("[cloud storage for] %1").arg(email);
}
} else { } else {
return fileName; return fileName;
} }

View file

@ -103,7 +103,7 @@ slots:
void on_actionClose_triggered(); void on_actionClose_triggered();
void on_actionCloudstorageopen_triggered(); void on_actionCloudstorageopen_triggered();
void on_actionCloudstoragesave_triggered(); void on_actionCloudstoragesave_triggered();
void on_actionTake_cloud_storage_online_triggered(); void on_actionCloudOnline_triggered();
void on_actionPrint_triggered(); void on_actionPrint_triggered();
void on_actionPreferences_triggered(); void on_actionPreferences_triggered();
void on_actionQuit_triggered(); void on_actionQuit_triggered();

View file

@ -66,7 +66,7 @@
<addaction name="actionSaveAs"/> <addaction name="actionSaveAs"/>
<addaction name="actionCloudstorageopen"/> <addaction name="actionCloudstorageopen"/>
<addaction name="actionCloudstoragesave"/> <addaction name="actionCloudstoragesave"/>
<addaction name="actionTake_cloud_storage_online"/> <addaction name="actionCloudOnline"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionClose"/> <addaction name="actionClose"/>
<addaction name="actionExport"/> <addaction name="actionExport"/>
@ -714,9 +714,12 @@
<string>Facebook</string> <string>Facebook</string>
</property> </property>
</action> </action>
<action name="actionTake_cloud_storage_online"> <action name="actionCloudOnline">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text"> <property name="text">
<string>Take cloud storage online</string> <string>Cloud storage online</string>
</property> </property>
</action> </action>
</widget> </widget>