#include <stdlib.h>
#include <time.h>
+#ifndef WIN32
#include <gconf/gconf-client.h>
+#else
+#include <windows.h>
+#endif
#include "dive.h"
#include "divelist.h"
#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;
}
static char *existing_filename;
+static gboolean need_icon = TRUE;
static void on_info_bar_response(GtkWidget *widget, gint response,
gpointer data)
GError *error = NULL;
while(filenames != NULL) {
- filename = (char *)filenames->data;
+ filename = filenames->data;
parse_xml_file(filename, &error);
if (error != NULL)
{
filenames = g_slist_next(filenames);
}
g_slist_free(filenames);
- report_dives();
- dive_list_update_dives();
+ report_dives(FALSE);
}
gtk_widget_destroy(dialog);
}
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)
{
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);
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);
+#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);
}
static void renumber_dialog(GtkWidget *w, gpointer data)
{
int result;
+ struct dive *dive;
GtkWidget *dialog, *frame, *button, *vbox;
dialog = gtk_dialog_new_with_buttons("Renumber",
button = gtk_spin_button_new_with_range(1, 50000, 1);
gtk_container_add(GTK_CONTAINER(frame), button);
+ /*
+ * Do we have a number for the first dive already? Use that
+ * as the default.
+ */
+ dive = get_dive(0);
+ if (dive && dive->number)
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(button), dive->number);
+
gtk_widget_show_all(dialog);
result = gtk_dialog_run(GTK_DIALOG(dialog));
if (result == GTK_RESPONSE_ACCEPT) {
{
const char *logo_property = NULL;
GdkPixbuf *logo = NULL;
- GtkWidget *image = gtk_image_new_from_file("icon.svg");
- if (image) {
- logo = gtk_image_get_pixbuf(GTK_IMAGE(image));
- logo_property = "logo";
+ if (need_icon) {
+ GtkWidget *image = gtk_image_new_from_file("subsurface.svg");
+
+ if (image) {
+ logo = gtk_image_get_pixbuf(GTK_IMAGE(image));
+ logo_property = "logo";
+ }
}
gtk_show_about_dialog(NULL,
"license", "GPLv2",
"version", VERSION_STRING,
"copyright", "Linus Torvalds 2011",
+ "logo-icon-name", "subsurface",
/* Must be last: */
logo_property, logo,
NULL);
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) },
{ "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]);
<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> \
{
GtkWidget *win, *notebook, *vbox;
notebook_data_t *nbdp;
+ GtkAllocation allocation;
/* pick the right notebook page data and return if both are detached */
if (nbd[0].widget == NULL)
/* disallow drop events */
gtk_drag_dest_set(notebook, 0, NULL, 0, 0);
gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 6);
- gtk_widget_set_size_request(notebook, 450, 350);
+ gtk_widget_get_allocation(page, &allocation);
+ gtk_window_set_default_size(GTK_WINDOW(win), allocation.width, allocation.height);
gtk_widget_show_all(win);
return GTK_NOTEBOOK(notebook);
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;
GtkWidget *equipment;
GtkWidget *menubar;
GtkWidget *vbox;
+ GdkScreen *screen;
+ GtkIconTheme *icon_theme=NULL;
+ GtkSettings *settings;
static const GtkTargetEntry notebook_target = {
"GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0
};
gtk_init(&argc, &argv);
+ 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))
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);
+#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;
error_info_bar = NULL;
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_icon_from_file(GTK_WINDOW(win), "icon.svg", NULL);
+ g_set_application_name ("subsurface");
+ /* Let's check if the subsurface icon has been installed or if
+ * we need to try to load it from the current directory */
+ screen = gdk_screen_get_default();
+ if (screen)
+ icon_theme = gtk_icon_theme_get_for_screen(screen);
+ if (icon_theme) {
+ if (gtk_icon_theme_has_icon(icon_theme, "subsurface")) {
+ need_icon = FALSE;
+ gtk_window_set_default_icon_name ("subsurface");
+ }
+ }
+ 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.bmp", 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;
return GTK_ENTRY(entry);
}
+/* once a file is selected in the FileChooserButton we want to exit the import dialog */
+static void on_file_set(GtkFileChooserButton *widget, gpointer _data)
+{
+ GtkDialog *main_dialog = _data;
+
+ gtk_dialog_response(main_dialog, GTK_RESPONSE_ACCEPT);
+}
+
+static GtkWidget *xml_file_selector(GtkWidget *vbox, GtkWidget *main_dialog)
+{
+ GtkWidget *hbox, *frame, *chooser, *dialog;
+ GtkFileFilter *filter;
+
+ hbox = gtk_hbox_new(FALSE, 6);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
+
+ frame = gtk_frame_new("XML file name");
+ gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
+ dialog = gtk_file_chooser_dialog_new("Open XML File",
+ GTK_WINDOW(main_window),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE);
+
+ filter = gtk_file_filter_new();
+ gtk_file_filter_add_pattern(filter, "*.xml");
+ gtk_file_filter_add_pattern(filter, "*.XML");
+ gtk_file_filter_add_pattern(filter, "*.sda");
+ gtk_file_filter_add_pattern(filter, "*.SDA");
+ gtk_file_filter_add_mime_type(filter, "text/xml");
+ gtk_file_filter_set_name(filter, "XML file");
+ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
+
+ chooser = gtk_file_chooser_button_new_with_dialog(dialog);
+ g_signal_connect(G_OBJECT(chooser), "file-set", G_CALLBACK(on_file_set), main_dialog);
+
+ gtk_file_chooser_button_set_width_chars(GTK_FILE_CHOOSER_BUTTON(chooser), 30);
+ gtk_container_add(GTK_CONTAINER(frame), chooser);
+
+ return chooser;
+}
+
+static void do_import_file(gpointer data, gpointer user_data)
+{
+ GError *error = NULL;
+ parse_xml_file(data, &error);
+
+ if (error != NULL)
+ {
+ report_error(error);
+ g_error_free(error);
+ error = NULL;
+ }
+}
+
void import_dialog(GtkWidget *w, gpointer data)
{
int result;
- GtkWidget *dialog, *hbox, *vbox;
+ GtkWidget *dialog, *hbox, *vbox, *label;
GtkComboBox *computer;
GtkEntry *device;
+ GtkWidget *XMLchooser;
device_data_t devicedata = {
.devname = NULL,
};
NULL);
vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
-
+ label = gtk_label_new("Import: \nLoad XML file or import directly from dive computer");
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 3);
+ XMLchooser = xml_file_selector(vbox, dialog);
computer = dive_computer_selector(vbox);
device = dive_computer_device(vbox);
-
hbox = gtk_hbox_new(FALSE, 6);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 3);
devicedata.progress.bar = gtk_progress_bar_new();
GtkTreeIter iter;
GtkTreeModel *model;
const char *comp;
+ GSList *list;
case GTK_RESPONSE_ACCEPT:
- if (!gtk_combo_box_get_active_iter(computer, &iter))
- break;
- model = gtk_combo_box_get_model(computer);
- gtk_tree_model_get(model, &iter,
- 0, &comp,
- 1, &type,
- -1);
- devicedata.type = type;
- devicedata.name = comp;
- devicedata.devname = gtk_entry_get_text(device);
- do_import(&devicedata);
+ /* what happened - did the user pick a file? In that case
+ * we ignore whether a dive computer model was picked */
+ list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(XMLchooser));
+ if (g_slist_length(list) == 0) {
+ if (!gtk_combo_box_get_active_iter(computer, &iter))
+ break;
+ model = gtk_combo_box_get_model(computer);
+ gtk_tree_model_get(model, &iter,
+ 0, &comp,
+ 1, &type,
+ -1);
+ devicedata.type = type;
+ devicedata.name = comp;
+ devicedata.devname = gtk_entry_get_text(device);
+ do_import(&devicedata);
+ } else {
+ g_slist_foreach(list,do_import_file,NULL);
+ g_slist_free(list);
+ }
break;
default:
break;
}
gtk_widget_destroy(dialog);
- report_dives();
- dive_list_update_dives();
+ report_dives(TRUE);
}
void update_progressbar(progressbar_t *progress, double value)
void set_filename(const char *filename)
{
- if (filename)
+ if (!existing_filename && filename)
existing_filename = strdup(filename);
return;
}