From d6b36c47cb2810921ae638a9237310052d9920ef Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 22 Apr 2016 06:51:47 -0700 Subject: Fix SettingsObjectWrapper to actually use the group set At least for the GeneralSettings group. Signed-off-by: Dirk Hohndel --- core/subsurface-qt/SettingsObjectWrapper.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'core') diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index e43be1a9b..ed305ef28 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -1315,6 +1315,7 @@ int GeneralSettingsObjectWrapper::pscrRatio() const void GeneralSettingsObjectWrapper::setDefaultFilename(const QString& value) { QSettings s; + s.beginGroup(group); s.setValue("default_filename", value); prefs.default_filename = copy_string(qPrintable(value)); emit defaultFilenameChanged(value); @@ -1323,6 +1324,7 @@ void GeneralSettingsObjectWrapper::setDefaultFilename(const QString& value) void GeneralSettingsObjectWrapper::setDefaultCylinder(const QString& value) { QSettings s; + s.beginGroup(group); s.setValue("default_cylinder", value); prefs.default_cylinder = copy_string(qPrintable(value)); emit defaultCylinderChanged(value); @@ -1331,6 +1333,7 @@ void GeneralSettingsObjectWrapper::setDefaultCylinder(const QString& value) void GeneralSettingsObjectWrapper::setDefaultFileBehavior(short value) { QSettings s; + s.beginGroup(group); s.setValue("default_file_behavior", value); prefs.default_file_behavior = value; if (prefs.default_file_behavior == UNDEFINED_DEFAULT_FILE) { @@ -1347,6 +1350,7 @@ void GeneralSettingsObjectWrapper::setDefaultFileBehavior(short value) void GeneralSettingsObjectWrapper::setUseDefaultFile(bool value) { QSettings s; + s.beginGroup(group); s.setValue("use_default_file", value); prefs.use_default_file = value; emit useDefaultFileChanged(value); @@ -1355,6 +1359,7 @@ void GeneralSettingsObjectWrapper::setUseDefaultFile(bool value) void GeneralSettingsObjectWrapper::setDefaultSetPoint(int value) { QSettings s; + s.beginGroup(group); s.setValue("defaultsetpoint", value); prefs.defaultsetpoint = value; emit defaultSetPointChanged(value); @@ -1363,6 +1368,7 @@ void GeneralSettingsObjectWrapper::setDefaultSetPoint(int value) void GeneralSettingsObjectWrapper::setO2Consumption(int value) { QSettings s; + s.beginGroup(group); s.setValue("o2consumption", value); prefs.o2consumption = value; emit o2ConsumptionChanged(value); @@ -1371,6 +1377,7 @@ void GeneralSettingsObjectWrapper::setO2Consumption(int value) void GeneralSettingsObjectWrapper::setPscrRatio(int value) { QSettings s; + s.beginGroup(group); s.setValue("pscr_ratio", value); prefs.pscr_ratio = value; emit pscrRatioChanged(value); -- cgit v1.2.3-70-g09d2 From 9ba090c31fd87bdec71c4e14cae3d71c4bb07eac Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 22 Apr 2016 07:00:29 -0700 Subject: git storage: init local repository So far we didn't do that at all, we either relied on the user manually creating a local repo, or we cloned a remote repo. Signed-off-by: Dirk Hohndel --- core/git-access.c | 14 ++++++++++++++ core/git-access.h | 1 + 2 files changed, 15 insertions(+) (limited to 'core') diff --git a/core/git-access.c b/core/git-access.c index 2b7fa0ca2..0e012b082 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -429,6 +429,11 @@ static int try_to_update(git_repository *repo, git_remote *origin, git_reference return report_error("Unable to get local or remote SHA1"); } if (git_merge_base(&base, repo, local_id, remote_id)) { + // TODO: + // if they have no merge base, they actually are different repos + // so instead merge this as merging a commit into a repo - git_merge() appears to do that + // but needs testing and cleanup afterwards + // if (is_subsurface_cloud) goto cloud_data_error; else @@ -919,3 +924,12 @@ struct git_repository *is_git_repository(const char *filename, const char **bran *branchp = branch; return repo; } + +int git_create_local_repo(const char *filename) +{ + git_repository *repo; + int ret = git_repository_init(&repo, filename, false); + if (ret != 0) + (void)report_error("Create local repo failed with error code %d", ret); + return ret; +} diff --git a/core/git-access.h b/core/git-access.h index f098f1e8d..b8b8181fe 100644 --- a/core/git-access.h +++ b/core/git-access.h @@ -27,6 +27,7 @@ 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); char *get_local_dir(const char *remote, const char *branch); +int git_create_local_repo(const char *filename); extern int last_git_storage_update_val; -- cgit v1.2.3-70-g09d2 From 3f6366026798ebd31cd08af0619049aacfd96e2b Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 29 Apr 2016 06:17:02 -0700 Subject: Allow switching the user from the command line This is a feature that many people have asked for. This implementation is somewhat simplistic because we simply use a different name for the program settings - but interestingly enough this appears to be enough to capture a lot of the core functionality that people are looking for in multi-user support. Signed-off-by: Dirk Hohndel --- core/qt-init.cpp | 11 ++++++++++- core/subsurfacestartup.c | 9 ++++++++- core/subsurfacestartup.h | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/qt-init.cpp b/core/qt-init.cpp index b52dfd970..5dc25f9fc 100644 --- a/core/qt-init.cpp +++ b/core/qt-init.cpp @@ -4,6 +4,8 @@ #include #include "helpers.h" +char *settings_suffix = NULL; + void init_qt_late() { QApplication *application = qApp; @@ -19,7 +21,14 @@ void init_qt_late() QCoreApplication::setOrganizationName("Subsurface"); QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); - QCoreApplication::setApplicationName("Subsurface"); + // enable user specific settings (based on command line argument) + if (settings_suffix) { + if (verbose) + qDebug() << "using custom config for" << QString("Subsurface-%1").arg(settings_suffix); + QCoreApplication::setApplicationName(QString("Subsurface-%1").arg(settings_suffix)); + } else { + QCoreApplication::setApplicationName("Subsurface"); + } // find plugins installed in the application directory (without this SVGs don't work on Windows) QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath()); QLocale loc; diff --git a/core/subsurfacestartup.c b/core/subsurfacestartup.c index 6e0dede1c..bb257960a 100644 --- a/core/subsurfacestartup.c +++ b/core/subsurfacestartup.c @@ -197,6 +197,11 @@ void parse_argument(const char *arg) continue; case '-': /* long options with -- */ + /* first test for --user=bla which allows the use of user specific settings */ + if (strncmp(arg, "--user=", sizeof("--user=") - 1) == 0) { + settings_suffix = strdup(arg + sizeof("--user=") - 1); + return; + } if (strcmp(arg, "--help") == 0) { print_help(); exit(0); @@ -254,8 +259,10 @@ void setup_system_prefs(void) subsurface_OS_pref_setup(); default_prefs.divelist_font = strdup(system_divelist_default_font); default_prefs.font_size = system_divelist_default_font_size; - default_prefs.default_filename = system_default_filename(); +#if !defined(SUBSURFACE_MOBILE) + default_prefs.default_filename = system_default_filename(); +#endif env = getenv("LC_MEASUREMENT"); if (!env) env = getenv("LC_ALL"); diff --git a/core/subsurfacestartup.h b/core/subsurfacestartup.h index 3ccc24aa4..53d44f28d 100644 --- a/core/subsurfacestartup.h +++ b/core/subsurfacestartup.h @@ -19,6 +19,8 @@ void free_prefs(void); void copy_prefs(struct preferences *src, struct preferences *dest); void print_files(void); +extern char *settings_suffix; + #ifdef __cplusplus } #endif -- cgit v1.2.3-70-g09d2 From 05a51f7984e62a8eaf02a8b8dc7269325fb26d9b Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 30 Apr 2016 06:51:26 -0700 Subject: Only create the path to no cloud local storage once This required a small change to the helper function, but this seemed totally worth it. Signed-off-by: Dirk Hohndel --- core/git-access.c | 7 ++++++- mobile-widgets/qmlmanager.cpp | 13 +++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/git-access.c b/core/git-access.c index 0e012b082..fe9a27452 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -928,7 +928,12 @@ struct git_repository *is_git_repository(const char *filename, const char **bran int git_create_local_repo(const char *filename) { git_repository *repo; - int ret = git_repository_init(&repo, filename, false); + char *path = strdup(filename); + char *branch = strchr(path, '['); + if (branch) + *branch = '\0'; + int ret = git_repository_init(&repo, path, false); + free(path); if (ret != 0) (void)report_error("Create local repo failed with error code %d", ret); return ret; diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 8a09dc212..9b3471a7a 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -27,6 +27,8 @@ QMLManager *QMLManager::m_instance = NULL; #define RED_FONT QLatin1Literal("") #define END_FONT QLatin1Literal("") +#define NOCLOUD_LOCALSTORAGE format_string("%s/cloudstorage/localrepo[master]", system_default_directory()) + static void appendTextToLogStandalone(const char *text) { QMLManager *self = QMLManager::instance(); @@ -172,7 +174,7 @@ void QMLManager::openLocalThenRemote(QString url) void QMLManager::mergeLocalRepo() { - char *filename = format_string("%s/cloudstorage/localrepo[master]", system_default_directory()); + char *filename = NOCLOUD_LOCALSTORAGE; parse_file(filename); process_dives(true, false); } @@ -479,6 +481,7 @@ void QMLManager::revertToNoCloudIfNeeded() setCloudUserName(""); setCloudPassword(""); setCredentialStatus(INCOMPLETE); + set_filename(NOCLOUD_LOCALSTORAGE, true); setStartPageText(RED_FONT + tr("Failed to connect to cloud server, reverting to no cloud status") + END_FONT); } setAccessingCloud(-1); @@ -868,12 +871,10 @@ void QMLManager::saveChangesLocal() git_storage_update_progress(true, "saving dives locally"); // reset the timers if (credentialStatus() == NOCLOUD) { if (same_string(existing_filename, "")) { - QString filename(system_default_directory()); - filename += "/cloudstorage/localrepo"; - if (git_create_local_repo(qPrintable(filename))) + char *filename = NOCLOUD_LOCALSTORAGE; + if (git_create_local_repo(filename)) appendTextToLog(get_error_string()); - filename += "[master]"; - set_filename(qPrintable(filename), true); + set_filename(filename, true); GeneralSettingsObjectWrapper s(this); s.setDefaultFilename(filename); s.setDefaultFileBehavior(LOCAL_DEFAULT_FILE); -- cgit v1.2.3-70-g09d2 From 9bec79a71b54d39f8934254c5f6cd5abc11cd32f Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 30 Apr 2016 10:34:11 -0700 Subject: Don't pretend that opening git repo succeeded Not sure why we claimed that this was successful when clearly it wasn't. There's a risk that this could break something on the desktop, but it makes no sense to me why that would be the right thing to do. Signed-off-by: Dirk Hohndel --- core/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/file.c b/core/file.c index 52c93a719..3ce084e03 100644 --- a/core/file.c +++ b/core/file.c @@ -485,7 +485,7 @@ int parse_file(const char *filename) /* opening the cloud storage repository failed for some reason * give up here and don't send errors about git repositories */ free(current_sha); - return 0; + return -1; } /* if this is a git repository, do we already have this exact state loaded ? * get the SHA and compare with what we currently have */ -- cgit v1.2.3-70-g09d2 From d943050a93ba59d500fa3196d00529e7b2e6b925 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 30 Apr 2016 10:36:01 -0700 Subject: QML UI: make offline the default Signed-off-by: Dirk Hohndel --- core/subsurfacestartup.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core') diff --git a/core/subsurfacestartup.c b/core/subsurfacestartup.c index bb257960a..c2881a17f 100644 --- a/core/subsurfacestartup.c +++ b/core/subsurfacestartup.c @@ -10,6 +10,9 @@ struct preferences prefs, informational_prefs; struct preferences default_prefs = { .cloud_base_url = "https://cloud.subsurface-divelog.org/", +#if defined(SUBSURFACE_MOBILE) + .git_local_only = true, +#endif .units = SI_UNITS, .unit_system = METRIC, .coordinates_traditional = true, -- cgit v1.2.3-70-g09d2