Merge branch 'offlineDefault'

This commit is contained in:
Dirk Hohndel 2016-04-30 12:40:52 -07:00
commit 241dd7cb81
18 changed files with 327 additions and 77 deletions

View file

@ -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 */

View file

@ -450,6 +450,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
@ -940,3 +945,17 @@ 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;
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;
}

View file

@ -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;

View file

@ -4,6 +4,8 @@
#include <QTextCodec>
#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;

View file

@ -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);

View file

@ -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,
@ -197,6 +200,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 +262,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");

View file

@ -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