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