X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=gtk-gui.c;h=c78d7e6677feeadabf850c738f2450dfc5132884;hb=abdee5b1b8a97c641bca9bc2ebac9555c3e2ea54;hp=47cab62fabc46f0d060d17e821434ce41d4bc211;hpb=8c0c6bad59b588de4fe1e8983d76ded16538fc44;p=ext%2Fsubsurface.git diff --git a/gtk-gui.c b/gtk-gui.c index 47cab62..c78d7e6 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; @@ -305,6 +311,13 @@ OPTIONCALLBACK(nitrox_toggle, visible_cols.nitrox) OPTIONCALLBACK(temperature_toggle, visible_cols.temperature) OPTIONCALLBACK(cylinder_toggle, visible_cols.cylinder) +static void event_toggle(GtkWidget *w, gpointer _data) +{ + gboolean *plot_ev = _data; + + *plot_ev = GTK_TOGGLE_BUTTON(w)->active; +} + static void preferences_dialog(GtkWidget *w, gpointer data) { int result; @@ -393,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); @@ -403,6 +417,92 @@ 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); +} + +static void create_toggle(const char* label, int *on, void *_data) +{ + GtkWidget *button, *table = _data; + int rows, cols, x, y; + static int count; + + if (table == NULL) { + /* magic way to reset the number of toggle buttons + * that we have already added - call this before you + * create the dialog */ + count = 0; + return; + } + g_object_get(G_OBJECT(table), "n-columns", &cols, "n-rows", &rows, NULL); + if (count > rows * cols) { + gtk_table_resize(GTK_TABLE(table),rows+1,cols); + rows++; + } + x = count % cols; + y = count / cols; + button = gtk_check_button_new_with_label(label); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), *on); + gtk_table_attach_defaults(GTK_TABLE(table), button, x, x+1, y, y+1); + g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(event_toggle), on); + count++; +} + +static void selectevents_dialog(GtkWidget *w, gpointer data) +{ + int result; + GtkWidget *dialog, *frame, *vbox, *table; + + dialog = gtk_dialog_new_with_buttons("SelectEvents", + GTK_WINDOW(main_window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, + NULL); + /* initialize the function that fills the table */ + create_toggle(NULL, NULL, NULL); + + frame = gtk_frame_new("Enable / Disable Events"); + vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); + + table = gtk_table_new(1, 4, TRUE); + gtk_container_add(GTK_CONTAINER(frame), table); + + evn_foreach(&create_toggle, table); + + gtk_widget_show_all(dialog); + result = gtk_dialog_run(GTK_DIALOG(dialog)); + if (result == GTK_RESPONSE_ACCEPT) { + repaint_dive(); } gtk_widget_destroy(dialog); } @@ -452,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)); @@ -475,6 +579,7 @@ static void about_dialog(GtkWidget *w, gpointer data) static GtkActionEntry menu_items[] = { { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL}, { "LogMenuAction", GTK_STOCK_FILE, "Log", NULL, NULL, NULL}, + { "FilterMenuAction", GTK_STOCK_FILE, "Filter", NULL, NULL, NULL}, { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL}, { "OpenFile", GTK_STOCK_OPEN, NULL, "O", NULL, G_CALLBACK(file_open) }, { "SaveFile", GTK_STOCK_SAVE, NULL, "S", NULL, G_CALLBACK(file_save) }, @@ -482,8 +587,9 @@ static GtkActionEntry menu_items[] = { { "Import", NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) }, { "Preferences", NULL, "Preferences", NULL, NULL, G_CALLBACK(preferences_dialog) }, { "Renumber", NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) }, + { "SelectEvents", NULL, "SelectEvents", NULL, NULL, G_CALLBACK(selectevents_dialog) }, { "Quit", GTK_STOCK_QUIT, NULL, "Q", NULL, G_CALLBACK(quit) }, - { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) }, + { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) }, }; static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); @@ -504,6 +610,9 @@ static const gchar* ui_string = " \ \ \ \ + \ + \ + \ \ \ \ @@ -585,23 +694,21 @@ static GtkNotebook *create_new_notebook_window(GtkNotebook *source, return GTK_NOTEBOOK(notebook); } -static void drag_cb(GtkWidget *widget, GdkDragContext *context, +static gboolean drag_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) { GtkWidget *source; notebook_data_t *nbdp; + gtk_drag_finish(context, TRUE, TRUE, time); source = gtk_drag_get_source_widget(context); if (nbd[0].name && ! strcmp(nbd[0].name,gtk_widget_get_name(source))) nbdp = nbd; else if (nbd[1].name && ! strcmp(nbd[1].name,gtk_widget_get_name(source))) nbdp = nbd + 1; - else - /* HU? */ - return; - - gtk_drag_finish(context, TRUE, TRUE, time); + else /* just on ourselves */ + return TRUE; /* we no longer need the widget - but getting rid of this is hard; * remove the signal handler, remove the notebook from the box @@ -613,15 +720,33 @@ static void drag_cb(GtkWidget *widget, GdkDragContext *context, nbdp->widget = NULL; free(nbdp->name); nbdp->name = NULL; + + return TRUE; } -void init_ui(int argc, char **argv) +#ifdef WIN32 +static int get_from_registry(HKEY hkey, const char *key) +{ + DWORD value; + DWORD len = 4; + LONG success; + + success = RegQueryValueEx(hkey, TEXT(key), NULL, NULL, + (LPBYTE) &value, &len ); + if (success != ERROR_SUCCESS) + return FALSE; /* that's what happens the first time we start */ + return value; +} +#endif + +void init_ui(int *argcp, char ***argvp) { GtkWidget *win; GtkWidget *notebook; GtkWidget *dive_info; GtkWidget *dive_list; GtkWidget *equipment; + GtkWidget *stats; GtkWidget *menubar; GtkWidget *vbox; GdkScreen *screen; @@ -631,11 +756,13 @@ void init_ui(int argc, char **argv) "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0 }; - gtk_init(&argc, &argv); + gtk_init(argcp, argvp); settings = gtk_settings_get_default(); 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)) @@ -654,6 +781,36 @@ 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 len = 4; + LONG success; + HKEY hkey; + + success = RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Software\\subsurface"), 0, + KEY_QUERY_VALUE, &hkey); + + output_units.length = get_from_registry(hkey, "feet"); + output_units.pressure = get_from_registry(hkey, "psi"); + output_units.volume = get_from_registry(hkey, "cuft"); + output_units.temperature = get_from_registry(hkey, "fahrenheit"); + visible_cols.temperature = get_from_registry(hkey, "temperature"); + visible_cols.cylinder = get_from_registry(hkey, "cylinder"); + visible_cols.nitrox = get_from_registry(hkey, "nitrox"); + visible_cols.sac = get_from_registry(hkey, "sac"); + visible_cols.otu = get_from_registry(hkey, "otu"); + + divelist_font = malloc(80); + len = 80; + success = RegQueryValueEx(hkey, TEXT("divelist_font"), NULL, NULL, + (LPBYTE) 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; + } + RegCloseKey(hkey); + +#endif if (!divelist_font) divelist_font = DIVELIST_DEFAULT_FONT; @@ -672,7 +829,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; @@ -715,6 +876,10 @@ void init_ui(int argc, char **argv) equipment = equipment_widget(); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), equipment, gtk_label_new("Equipment")); + /* Frame for dive statistics */ + stats = stats_widget(); + gtk_notebook_append_page(GTK_NOTEBOOK(notebook), stats, gtk_label_new("Info & Stats")); + gtk_widget_set_app_paintable(win, TRUE); gtk_widget_show_all(win);