X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=gtk-gui.c;h=b1bc82a735c81743205a7be997f8d650a0e84fb2;hb=667f07d281399414ff683536a848dda71e04d561;hp=f4b9989d3bec561f7c6c7943027acf1073738b90;hpb=036fccd34a8659208554c38aa4cf31a1fd56800d;p=ext%2Fsubsurface.git diff --git a/gtk-gui.c b/gtk-gui.c index f4b9989..b1bc82a 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -8,7 +8,11 @@ #include #include +#ifndef WIN32 #include +#else +#include +#endif #include "dive.h" #include "divelist.h" @@ -26,10 +30,12 @@ int error_count; #define DIVELIST_DEFAULT_FONT "Sans 8" const char *divelist_font; +#ifndef WIN32 GConfClient *gconf; -struct units output_units; - #define GCONF_NAME(x) "/apps/subsurface/" #x +#endif + +struct units output_units; static GtkWidget *dive_profile; @@ -400,6 +406,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data) update_dive_list_units(); repaint_dive(); update_dive_list_col_visibility(); +#ifndef WIN32 gconf_client_set_bool(gconf, GCONF_NAME(feet), output_units.length == FEET, NULL); gconf_client_set_bool(gconf, GCONF_NAME(psi), output_units.pressure == PSI, NULL); gconf_client_set_bool(gconf, GCONF_NAME(cuft), output_units.volume == CUFT, NULL); @@ -410,6 +417,34 @@ static void preferences_dialog(GtkWidget *w, gpointer data) gconf_client_set_bool(gconf, GCONF_NAME(SAC), visible_cols.sac, NULL); gconf_client_set_bool(gconf, GCONF_NAME(OTU), visible_cols.otu, NULL); gconf_client_set_string(gconf, GCONF_NAME(divelist_font), divelist_font, NULL); +#else + HKEY hkey; + LONG success = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\subsurface"), + 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, + NULL, &hkey, NULL); + if (success != ERROR_SUCCESS) + printf("CreateKey Software\\subsurface failed %ld\n", success); + DWORD value; + +#define StoreInReg(_key, _val) { \ + value = (_val) ; \ + RegSetValueEx(hkey, TEXT(_key), 0, REG_DWORD, &value, 4); \ + } + + StoreInReg("feet", output_units.length == FEET); + StoreInReg("psi", output_units.pressure == PSI); + StoreInReg("cuft", output_units.volume == CUFT); + StoreInReg("fahrenheit", output_units.temperature == FAHRENHEIT); + StoreInReg("temperature", visible_cols.temperature); + StoreInReg("cylinder", visible_cols.cylinder); + StoreInReg("nitrox", visible_cols.nitrox); + StoreInReg("sac", visible_cols.sac); + StoreInReg("otu", visible_cols.otu); + RegSetValueEx(hkey, TEXT("divelist_font"), 0, REG_SZ, divelist_font, strlen(divelist_font)); + if (RegFlushKey(hkey) != ERROR_SUCCESS) + printf("RegFlushKey failed %ld\n"); + RegCloseKey(hkey); +#endif } gtk_widget_destroy(dialog); } @@ -517,7 +552,11 @@ static void about_dialog(GtkWidget *w, gpointer data) GdkPixbuf *logo = NULL; if (need_icon) { +#ifndef WIN32 GtkWidget *image = gtk_image_new_from_file("subsurface.svg"); +#else + GtkWidget *image = gtk_image_new_from_file("subsurface.ico"); +#endif if (image) { logo = gtk_image_get_pixbuf(GTK_IMAGE(image)); @@ -685,6 +724,22 @@ static void drag_cb(GtkWidget *widget, GdkDragContext *context, nbdp->name = NULL; } +#ifdef WIN32 +static int get_from_registry(const char *key) +{ + DWORD value; + DWORD type; + DWORD len = 4; + LONG success; + + success = RegGetValue(HKEY_CURRENT_USER, TEXT("Software\\subsurface"), TEXT(key), + RRF_RT_ANY, &type, &value, &len); + if (success != ERROR_SUCCESS) + return FALSE; /* that's what happens the first time we start */ + return value; +} +#endif + void init_ui(int argc, char **argv) { GtkWidget *win; @@ -706,6 +761,8 @@ void init_ui(int argc, char **argv) gtk_settings_set_long_property(settings, "gtk_tooltip_timeout", 10, "subsurface setting"); g_type_init(); + +#ifndef WIN32 gconf = gconf_client_get_default(); if (gconf_client_get_bool(gconf, GCONF_NAME(feet), NULL)) @@ -724,6 +781,31 @@ void init_ui(int argc, char **argv) visible_cols.sac = gconf_client_get_bool(gconf, GCONF_NAME(SAC), NULL); divelist_font = gconf_client_get_string(gconf, GCONF_NAME(divelist_font), NULL); +#else + DWORD type; + DWORD len = 4; + LONG success; + + output_units.length = get_from_registry("feet"); + output_units.pressure = get_from_registry("psi"); + output_units.volume = get_from_registry("cuft"); + output_units.temperature = get_from_registry("fahrenheit"); + visible_cols.temperature = get_from_registry("temperature"); + visible_cols.cylinder = get_from_registry("cylinder"); + visible_cols.nitrox = get_from_registry("nitrox"); + visible_cols.sac = get_from_registry("sac"); + visible_cols.otu = get_from_registry("otu"); + + divelist_font = malloc(80); + len = 80; + success = RegGetValue(HKEY_CURRENT_USER, TEXT("Software\\subsurface"), + TEXT("divelist_font"), RRF_RT_ANY, &type, divelist_font, &len); + if (success != ERROR_SUCCESS) { + /* that's what happens the first time we start - just use the default */ + free(divelist_font); + divelist_font = NULL; + } +#endif if (!divelist_font) divelist_font = DIVELIST_DEFAULT_FONT; @@ -742,7 +824,11 @@ void init_ui(int argc, char **argv) } } if (need_icon) +#ifndef WIN32 gtk_window_set_icon_from_file(GTK_WINDOW(win), "subsurface.svg", NULL); +#else + gtk_window_set_icon_from_file(GTK_WINDOW(win), "subsurface.ico", NULL); +#endif g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(on_delete), NULL); g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL); main_window = win;