#include <stdlib.h>
#include <time.h>
-#ifndef WIN32
-#include <gconf/gconf-client.h>
-#else
-#include <windows.h>
-#endif
-
#include "dive.h"
#include "divelist.h"
#include "display.h"
#define DIVELIST_DEFAULT_FONT "Sans 8"
const char *divelist_font;
-#ifndef WIN32
-GConfClient *gconf;
-#define GCONF_NAME(x) "/apps/subsurface/" #x
-#endif
-
struct units output_units;
static GtkWidget *dive_profile;
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(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
+ subsurface_set_conf("feet", PREF_BOOL, BOOL_TO_PTR(output_units.length == FEET));
+ subsurface_set_conf("psi", PREF_BOOL, BOOL_TO_PTR(output_units.pressure == PSI));
+ subsurface_set_conf("cuft", PREF_BOOL, BOOL_TO_PTR(output_units.volume == CUFT));
+ subsurface_set_conf("fahrenheit", PREF_BOOL, BOOL_TO_PTR(output_units.temperature == FAHRENHEIT));
+ subsurface_set_conf("TEMPERATURE", PREF_BOOL, BOOL_TO_PTR(visible_cols.temperature));
+ subsurface_set_conf("CYLINDER", PREF_BOOL, BOOL_TO_PTR(visible_cols.cylinder));
+ subsurface_set_conf("NITROX", PREF_BOOL, BOOL_TO_PTR(visible_cols.nitrox));
+ 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();
}
gtk_widget_destroy(dialog);
}
GdkPixbuf *logo = NULL;
if (need_icon) {
+#if defined __linux__ || defined __APPLE__
GtkWidget *image = gtk_image_new_from_file("subsurface.svg");
+#elif defined WIN32
+ GtkWidget *image = gtk_image_new_from_file("subsurface.ico");
+#endif
if (image) {
logo = gtk_image_get_pixbuf(GTK_IMAGE(image));
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
nbdp->widget = NULL;
free(nbdp->name);
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;
+ return TRUE;
}
-#endif
-void init_ui(int argc, char **argv)
+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;
+ GtkWidget *hpane, *vpane;
GdkScreen *screen;
GtkIconTheme *icon_theme=NULL;
GtkSettings *settings;
"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))
+ subsurface_open_conf();
+ if (subsurface_get_conf("feet", PREF_BOOL))
output_units.length = FEET;
- if (gconf_client_get_bool(gconf, GCONF_NAME(psi), NULL))
+ if (subsurface_get_conf("psi", PREF_BOOL))
output_units.pressure = PSI;
- if (gconf_client_get_bool(gconf, GCONF_NAME(cuft), NULL))
+ if (subsurface_get_conf("cuft", PREF_BOOL))
output_units.volume = CUFT;
- if (gconf_client_get_bool(gconf, GCONF_NAME(fahrenheit), NULL))
+ if (subsurface_get_conf("fahrenheit", PREF_BOOL))
output_units.temperature = FAHRENHEIT;
/* 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);
-
- 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
+ visible_cols.cylinder = PTR_TO_BOOL(subsurface_get_conf("CYLINDER", PREF_BOOL));
+ visible_cols.temperature = PTR_TO_BOOL(subsurface_get_conf("TEMPERATURE", PREF_BOOL));
+ visible_cols.nitrox = PTR_TO_BOOL(subsurface_get_conf("NITROX", PREF_BOOL));
+ visible_cols.otu = PTR_TO_BOOL(subsurface_get_conf("OTU", PREF_BOOL));
+ visible_cols.sac = PTR_TO_BOOL(subsurface_get_conf("SAC", PREF_BOOL));
+
+ divelist_font = subsurface_get_conf("divelist_font", PREF_STRING);
+
if (!divelist_font)
divelist_font = DIVELIST_DEFAULT_FONT;
}
}
if (need_icon)
-#ifndef WIN32
+#if defined __linux__ || defined __APPLE__
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);
+#elif defined WIN32
+ 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);
menubar = get_menubar_menu(win);
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
+ vpane = gtk_vpaned_new();
+ gtk_box_pack_start(GTK_BOX(vbox), vpane, TRUE, TRUE, 3);
+
+ hpane = gtk_hpaned_new();
+ gtk_paned_add1(GTK_PANED(vpane), hpane);
+
/* Notebook for dive info vs profile vs .. */
notebook = gtk_notebook_new();
- gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 6);
+ gtk_paned_add1(GTK_PANED(hpane), notebook);
gtk_notebook_set_group(GTK_NOTEBOOK(notebook), GRP_ID);
g_signal_connect(notebook, "create-window", G_CALLBACK(create_new_notebook_window), NULL);
gtk_drag_dest_set(notebook, GTK_DEST_DEFAULT_ALL, ¬ebook_target, 1, GDK_ACTION_MOVE);
/* Create the actual divelist */
dive_list = dive_list_create();
gtk_widget_set_name(dive_list, "Dive List");
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dive_list, gtk_label_new("Dive List"));
- gtk_notebook_set_tab_detachable(GTK_NOTEBOOK(notebook), dive_list, 1);
- gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(notebook), dive_list, 1);
+ gtk_paned_add2(GTK_PANED(vpane), dive_list);
/* Frame for dive profile */
dive_profile = dive_profile_widget();
gtk_widget_set_name(dive_profile, "Dive Profile");
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dive_profile, gtk_label_new("Dive Profile"));
- gtk_notebook_set_tab_detachable(GTK_NOTEBOOK(notebook), dive_profile, 1);
- gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(notebook), dive_profile, 1);
+ gtk_paned_add2(GTK_PANED(hpane), dive_profile);
/* Frame for extended dive info */
dive_info = extended_dive_info_widget();
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);