]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Don't close config file when changing preferences
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 2 May 2012 17:03:48 +0000 (10:03 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 2 May 2012 17:03:48 +0000 (10:03 -0700)
On Linux and MacOS the subsurface_close_conf() doesn't really close the
config file (it flushes writes on MacOS), but on Windows it does
actually close the registry hkey.

Which is bad, if you change the settings multiple times - we assume that
the config file is open the whole time.

So add a "subsurface_flush_conf()" function, and call *that* when
changing configuration parameters.  And call the close function only at
the very end.

Alternatively, maybe we should just open the config file separately
every time. I don't much care, maybe somebody else does.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
display-gtk.h
dive.h
gtk-gui.c
linux.c
macos.c
main.c
windows.c

index f12e4299661d2d7795db8e6a477f2310f960d8fa..5a76edce205e68315ed99ffb7d26dbd0fd989306 100644 (file)
@@ -38,6 +38,7 @@ typedef enum {
 extern void subsurface_open_conf(void);
 extern void subsurface_set_conf(char *name, pref_type_t type, const void *value);
 extern const void *subsurface_get_conf(char *name, pref_type_t type);
+extern void subsurface_flush_conf(void);
 extern void subsurface_close_conf(void);
 
 extern const char *subsurface_USB_name(void);
diff --git a/dive.h b/dive.h
index 89f790122fa4d4312a2aca694ab1c75ef2b5b5e7..4d60a77a2c173e64f22f10374cb6f48d2121ab17 100644 (file)
--- a/dive.h
+++ b/dive.h
@@ -317,6 +317,7 @@ extern void add_event(struct dive *dive, int time, int type, int flags, int valu
 extern void init_ui(int *argcp, char ***argvp);
 
 extern void run_ui(void);
+extern void exit_ui(void);
 
 extern void report_error(GError* error);
 
index 7d0e95c43ecdf5b8885ff44dd4a1693b75b744c6..6f48c734f06d990e0f70e005a6af37068ce519fd 100644 (file)
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -423,7 +423,9 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
                subsurface_set_conf("SAC", PREF_BOOL, BOOL_TO_PTR(visible_cols.sac));
                subsurface_set_conf("OTU", PREF_BOOL, BOOL_TO_PTR(visible_cols.otu));
                subsurface_set_conf("divelist_font", PREF_STRING, divelist_font);
-               subsurface_close_conf();
+
+               /* Flush the changes out to the system */
+               subsurface_flush_conf();
        }
        gtk_widget_destroy(dialog);
 }
@@ -769,6 +771,11 @@ void run_ui(void)
        gtk_main();
 }
 
+void exit_ui(void)
+{
+       subsurface_close_conf();
+}
+
 typedef struct {
        cairo_rectangle_int_t rect;
        const char *text;
diff --git a/linux.c b/linux.c
index f0ab2841caa48ed6dc4a5377a5c6fd5536d3e97d..42a3c9f5f396ee2737ffedab868e27908646ee49 100644 (file)
--- a/linux.c
+++ b/linux.c
@@ -43,6 +43,11 @@ const void *subsurface_get_conf(char *name, pref_type_t type)
        return NULL;
 }
 
+void subsurface_flush_conf(void)
+{
+       /* this is a no-op */
+}
+
 void subsurface_close_conf(void)
 {
        /* this is a no-op */
diff --git a/macos.c b/macos.c
index f6c4bd6c097c8ce14cd5ed73539cf99f42e9429e..931d4fa1e8a7c74faba0c5ff94b39f09470f5fdc 100644 (file)
--- a/macos.c
+++ b/macos.c
@@ -59,13 +59,18 @@ const void *subsurface_get_conf(char *name, pref_type_t type)
        return NULL;
 }
 
-void subsurface_close_conf(void)
+void subsurface_flush_conf(void)
 {
        int ok = CFPreferencesAppSynchronize(SUBSURFACE_PREFERENCES);
        if (!ok)
                fprintf(stderr,"Could not save preferences\n");
 }
 
+void subsurface_close_conf(void)
+{
+       /* Nothing */
+}
+
 const char *subsurface_USB_name()
 {
        return "/dev/tty.SLAB_USBtoUART";
diff --git a/main.c b/main.c
index eae4ee2399412a1b329f1e765f77cba519735c04..60f2902e60f685d86b7c6d601f847b963b66a465 100644 (file)
--- a/main.c
+++ b/main.c
@@ -239,5 +239,6 @@ int main(int argc, char **argv)
        report_dives(imported);
 
        run_ui();
+       exit_ui();
        return 0;
 }
index 46b6951bd87bd8c7a9d6ad43020b994d557d263d..0353adef3692625cdb077b8fe8e25de126afcd59 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -73,10 +73,15 @@ const void *subsurface_get_conf(char *name, pref_type_t type)
        return NULL;
 }
 
-void subsurface_close_conf(void)
+void subsurface_flush_conf(void)
 {
+       /* I wonder if we should even do this - it's apparently very expensive */
        if (RegFlushKey(hkey) != ERROR_SUCCESS)
                printf("RegFlushKey failed \n");
+}
+
+void subsurface_close_conf(void)
+{
        RegCloseKey(hkey);
 }