Enable cloud-online menu entry only if connected to cloud

Enable the menu item cloud-online only if the current file is the
cloud storage. Since this has to be checked every time the current
file is set, factor this out into the new MainWindow::setCurrentFile()
function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-01-03 17:11:52 +01:00 committed by Dirk Hohndel
parent bb64c6bda8
commit b3901aa8f9
2 changed files with 23 additions and 14 deletions

View file

@ -441,8 +441,6 @@ 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.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 {
@ -611,10 +609,8 @@ void MainWindow::on_actionCloudstorageopen_triggered()
showProgressBar(); showProgressBar();
QByteArray fileNamePtr = QFile::encodeName(filename); QByteArray fileNamePtr = QFile::encodeName(filename);
if (!parse_file(fileNamePtr.data())) { if (!parse_file(fileNamePtr.data()))
set_filename(fileNamePtr.data()); setCurrentFile(fileNamePtr.data());
setTitle();
}
process_dives(false, false); process_dives(false, false);
hideProgressBar(); hideProgressBar();
refreshDisplay(); refreshDisplay();
@ -641,8 +637,7 @@ void MainWindow::on_actionCloudstoragesave_triggered()
if (error) if (error)
return; return;
set_filename(filename.toUtf8().data()); setCurrentFile(filename.toUtf8().data());
setTitle();
mark_divelist_changed(false); mark_divelist_changed(false);
} }
@ -684,7 +679,7 @@ void MainWindow::on_actionCloudOnline_triggered()
} }
setTitle(); setTitle();
ui.actionCloudOnline->setChecked(!prefs.git_local_only); updateCloudOnlineStatus();
} }
void learnImageDirs(QStringList dirnames) void learnImageDirs(QStringList dirnames)
@ -759,6 +754,21 @@ void MainWindow::closeCurrentFile()
dcList.dcMap.clear(); dcList.dcMap.clear();
} }
void MainWindow::updateCloudOnlineStatus()
{
bool is_cloud = existing_filename && prefs.cloud_git_url && prefs.cloud_verification_status == CS_VERIFIED &&
strstr(existing_filename, prefs.cloud_git_url);
ui.actionCloudOnline->setEnabled(is_cloud);
ui.actionCloudOnline->setChecked(is_cloud && !prefs.git_local_only);
}
void MainWindow::setCurrentFile(const char *f)
{
set_filename(f);
setTitle();
updateCloudOnlineStatus();
}
void MainWindow::on_actionClose_triggered() void MainWindow::on_actionClose_triggered()
{ {
if (okToClose(tr("Please save or cancel the current dive edit before closing the file."))) { if (okToClose(tr("Please save or cancel the current dive edit before closing the file."))) {
@ -1685,8 +1695,7 @@ int MainWindow::file_save_as(void)
if (save_dives(filename.toUtf8().data())) if (save_dives(filename.toUtf8().data()))
return -1; return -1;
set_filename(filename.toUtf8().data()); setCurrentFile(filename.toUtf8().data());
setTitle();
mark_divelist_changed(false); mark_divelist_changed(false);
addRecentFile(filename, true); addRecentFile(filename, true);
return 0; return 0;
@ -1740,7 +1749,6 @@ 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('['));
ui.actionCloudOnline->setChecked(!prefs.git_local_only);
if (prefs.git_local_only) if (prefs.git_local_only)
return tr("[local cache for] %1").arg(email); return tr("[local cache for] %1").arg(email);
else else
@ -1824,9 +1832,8 @@ void MainWindow::loadFiles(const QStringList fileNames)
for (int i = 0; i < fileNames.size(); ++i) { for (int i = 0; i < fileNames.size(); ++i) {
fileNamePtr = QFile::encodeName(fileNames.at(i)); fileNamePtr = QFile::encodeName(fileNames.at(i));
if (!parse_file(fileNamePtr.data())) { if (!parse_file(fileNamePtr.data())) {
set_filename(fileNamePtr.data()); setCurrentFile(fileNamePtr.data());
addRecentFile(fileNamePtr, false); addRecentFile(fileNamePtr, false);
setTitle();
} }
} }
hideProgressBar(); hideProgressBar();

View file

@ -198,6 +198,8 @@ private:
bool askSaveChanges(); bool askSaveChanges();
bool okToClose(QString message); bool okToClose(QString message);
void closeCurrentFile(); void closeCurrentFile();
void setCurrentFile(const char *f);
void updateCloudOnlineStatus();
void showProgressBar(); void showProgressBar();
void hideProgressBar(); void hideProgressBar();
void writeSettings(); void writeSettings();