cloudstorage: some cleanup of cloud url handling

We know the preference is never empty, so stop testing for this. But
don't maintain two different preferences with basically the same
content. Instead add the '/git' suffix where needed and keep this all in
one place.

Simplify the extraction of the branch name from the cloud URL.

Also a typo fix and a new comment.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2021-04-10 17:40:30 -07:00
parent da6395a4a8
commit c5eb806adb
12 changed files with 14 additions and 41 deletions

View file

@ -628,8 +628,8 @@ void MainWindow::closeCurrentFile()
void MainWindow::updateCloudOnlineStatus()
{
bool is_cloud = existing_filename && prefs.cloud_git_url && prefs.cloud_verification_status == qPrefCloudStorage::CS_VERIFIED &&
strstr(existing_filename, prefs.cloud_git_url);
bool is_cloud = existing_filename && prefs.cloud_verification_status == qPrefCloudStorage::CS_VERIFIED &&
strstr(existing_filename, prefs.cloud_base_url);
ui.actionCloudOnline->setEnabled(is_cloud);
ui.actionCloudOnline->setChecked(is_cloud && !git_local_only);
}
@ -1174,7 +1174,7 @@ void MainWindow::loadRecentFiles()
QString file = s.value(key).toString();
// never add our cloud URL to the recent files
if (!same_string(prefs.cloud_git_url, "") && file.startsWith(prefs.cloud_git_url))
if (file.startsWith(prefs.cloud_base_url))
continue;
// but allow local git repos
QRegularExpression gitrepo("(.*)\\[[^]]+]");
@ -1212,7 +1212,7 @@ void MainWindow::updateRecentFilesMenu()
void MainWindow::addRecentFile(const QString &file, bool update)
{
// never add Subsurface cloud file to the recent files - it has its own menu entry
if (!same_string(prefs.cloud_git_url, "") && file.startsWith(prefs.cloud_git_url))
if (file.startsWith(prefs.cloud_base_url))
return;
QString localFile = QDir::toNativeSeparators(file);
int index = recentFiles.indexOf(localFile);
@ -1262,9 +1262,8 @@ int MainWindow::file_save_as(void)
// if the default is to save to cloud storage, pick something that will work as local file:
// simply extract the branch name which should be the users email address
if (default_filename && strstr(default_filename, prefs.cloud_git_url)) {
if (default_filename && strstr(default_filename, prefs.cloud_base_url)) {
QString filename(default_filename);
filename.remove(prefs.cloud_git_url);
filename.remove(0, filename.indexOf("[") + 1);
filename.replace("]", ".ssrf");
default_filename = copy_qstring(filename);
@ -1355,7 +1354,7 @@ QString MainWindow::displayedFilename(QString fullFilename)
QFileInfo fileInfo(f);
QString fileName(fileInfo.fileName());
if (fullFilename.contains(prefs.cloud_git_url)) {
if (fullFilename.contains(prefs.cloud_base_url)) {
QString email = fileName.left(fileName.indexOf('['));
return git_local_only ?
tr("[local cache for] %1").arg(email) :