]> git.tdb.fi Git - ext/subsurface.git/blobdiff - gtk-gui.c
Update the known locations / buddies / divemasters as user enters them
[ext/subsurface.git] / gtk-gui.c
index 39703ff60eaad94102aad648fe41b2da687ac92c..04fdbece3d0c22a55208c3f6d4aaa5a71a984106 100644 (file)
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -8,7 +8,9 @@
 #include <stdlib.h>
 #include <time.h>
 
+#ifndef WIN32
 #include <gconf/gconf-client.h>
+#endif
 
 #include "dive.h"
 #include "divelist.h"
@@ -26,10 +28,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;
 
@@ -301,6 +305,16 @@ static void name(GtkWidget *w, gpointer data) \
 
 OPTIONCALLBACK(otu_toggle, visible_cols.otu)
 OPTIONCALLBACK(sac_toggle, visible_cols.sac)
+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)
 {
@@ -349,6 +363,21 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
        box = gtk_hbox_new(FALSE, 6);
        gtk_container_add(GTK_CONTAINER(frame), box);
 
+       button = gtk_check_button_new_with_label("Show Temp");
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.temperature);
+       gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
+       g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(temperature_toggle), NULL);
+
+       button = gtk_check_button_new_with_label("Show Cyl");
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.cylinder);
+       gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
+       g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(cylinder_toggle), NULL);
+
+       button = gtk_check_button_new_with_label("Show O" UTF8_SUBSCRIPT_2 "%");
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.nitrox);
+       gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
+       g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(nitrox_toggle), NULL);
+
        button = gtk_check_button_new_with_label("Show SAC");
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.sac);
        gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
@@ -375,13 +404,76 @@ 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);
                gconf_client_set_bool(gconf, GCONF_NAME(fahrenheit), output_units.temperature == FAHRENHEIT, NULL);
-               gconf_client_set_bool(gconf, GCONF_NAME(SAC), ! visible_cols.sac, NULL); /* inverted to get the correct default */
+               gconf_client_set_bool(gconf, GCONF_NAME(TEMPERATURE), visible_cols.temperature, NULL);
+               gconf_client_set_bool(gconf, GCONF_NAME(CYLINDER), visible_cols.cylinder, NULL);
+               gconf_client_set_bool(gconf, GCONF_NAME(NITROX), visible_cols.nitrox, NULL);
+               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);
+#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);
 }
@@ -454,6 +546,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,   "<control>O", NULL, G_CALLBACK(file_open) },
        { "SaveFile",       GTK_STOCK_SAVE, NULL,   "<control>S", NULL, G_CALLBACK(file_save) },
@@ -461,8 +554,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,   "<control>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]);
 
@@ -483,6 +577,9 @@ static const gchar* ui_string = " \
                        <menu name=\"LogMenu\" action=\"LogMenuAction\"> \
                                <menuitem name=\"Renumber\" action=\"Renumber\" /> \
                        </menu> \
+                       <menu name=\"FilterMenu\" action=\"FilterMenuAction\"> \
+                               <menuitem name=\"SelectEvents\" action=\"SelectEvents\" /> \
+                       </menu> \
                        <menu name=\"Help\" action=\"HelpMenuAction\"> \
                                <menuitem name=\"About\" action=\"About\" /> \
                        </menu> \
@@ -615,6 +712,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))
@@ -625,12 +724,15 @@ void init_ui(int argc, char **argv)
                output_units.volume = CUFT;
        if (gconf_client_get_bool(gconf, GCONF_NAME(fahrenheit), NULL))
                output_units.temperature = FAHRENHEIT;
-       /* an unset key is FALSE - so in order to get the default behavior right we 
-          invert the meaning of the SAC key */
+       /* an unset key is FALSE - all these are hidden by default */
+       visible_cols.cylinder = gconf_client_get_bool(gconf, GCONF_NAME(CYLINDER), NULL);
+       visible_cols.temperature = gconf_client_get_bool(gconf, GCONF_NAME(TEMPERATURE), NULL);
+       visible_cols.nitrox = gconf_client_get_bool(gconf, GCONF_NAME(NITROX), NULL);
        visible_cols.otu = gconf_client_get_bool(gconf, GCONF_NAME(OTU), NULL);
-       visible_cols.sac = gconf_client_get_bool(gconf, GCONF_NAME(SAC), NULL);
+       visible_cols.sac = gconf_client_get_bool(gconf, GCONF_NAME(SAC), NULL);
                
        divelist_font = gconf_client_get_string(gconf, GCONF_NAME(divelist_font), NULL);
+#endif
        if (!divelist_font)
                divelist_font = DIVELIST_DEFAULT_FONT;