summaryrefslogtreecommitdiffstats
path: root/gtk-gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'gtk-gui.c')
-rw-r--r--gtk-gui.c88
1 files changed, 42 insertions, 46 deletions
diff --git a/gtk-gui.c b/gtk-gui.c
index 371a0308f..7d0e95c43 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -7,6 +7,7 @@
#include <string.h>
#include <stdlib.h>
#include <time.h>
+#include <unistd.h>
#include "dive.h"
#include "divelist.h"
@@ -22,7 +23,6 @@ GtkWidget *error_label;
GtkWidget *vpane, *hpane;
int error_count;
-#define DIVELIST_DEFAULT_FONT "Sans 8"
const char *divelist_font;
struct units output_units;
@@ -107,14 +107,14 @@ static void file_open(GtkWidget *w, gpointer data)
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- GSList *filenames;
+ GSList *filenames, *fn_glist;
char *filename;
- filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
+ filenames = fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
GError *error = NULL;
while(filenames != NULL) {
filename = filenames->data;
- parse_xml_file(filename, &error);
+ parse_file(filename, &error);
if (error != NULL)
{
report_error(error);
@@ -125,7 +125,7 @@ static void file_open(GtkWidget *w, gpointer data)
g_free(filename);
filenames = g_slist_next(filenames);
}
- g_slist_free(filenames);
+ g_slist_free(fn_glist);
report_dives(FALSE);
}
gtk_widget_destroy(dialog);
@@ -245,7 +245,7 @@ GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char
return col;
}
-static void create_radio(GtkWidget *vbox, const char *name, ...)
+static void create_radio(GtkWidget *vbox, const char *w_name, ...)
{
va_list args;
GtkRadioButton *group = NULL;
@@ -254,10 +254,10 @@ static void create_radio(GtkWidget *vbox, const char *name, ...)
box = gtk_hbox_new(TRUE, 10);
gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 0);
- label = gtk_label_new(name);
+ label = gtk_label_new(w_name);
gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
- va_start(args, name);
+ va_start(args, w_name);
for (;;) {
int enabled;
const char *name;
@@ -531,11 +531,7 @@ static void about_dialog(GtkWidget *w, gpointer data)
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
+ GtkWidget *image = gtk_image_new_from_file(subsurface_icon_name());
if (image) {
logo = gtk_image_get_pixbuf(GTK_IMAGE(image));
@@ -585,19 +581,19 @@ static GtkActionEntry menu_items[] = {
{ "ViewMenuAction", GTK_STOCK_FILE, "View", 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) },
- { "Print", GTK_STOCK_PRINT, NULL, "<control>P", NULL, G_CALLBACK(do_print) },
+ { "OpenFile", GTK_STOCK_OPEN, NULL, CTRLCHAR "O", NULL, G_CALLBACK(file_open) },
+ { "SaveFile", GTK_STOCK_SAVE, NULL, CTRLCHAR "S", NULL, G_CALLBACK(file_save) },
+ { "Print", GTK_STOCK_PRINT, NULL, CTRLCHAR "P", NULL, G_CALLBACK(do_print) },
{ "Import", NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) },
- { "Preferences", NULL, "Preferences", NULL, NULL, G_CALLBACK(preferences_dialog) },
+ { "Preferences", NULL, "Preferences", PREFERENCE_ACCEL, 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) },
+ { "Quit", GTK_STOCK_QUIT, NULL, CTRLCHAR "Q", NULL, G_CALLBACK(quit) },
{ "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) },
- { "ViewList", NULL, "List", "<control>1", NULL, G_CALLBACK(view_list) },
- { "ViewProfile", NULL, "Profile", "<control>2", NULL, G_CALLBACK(view_profile) },
- { "ViewInfo", NULL, "Info", "<control>3", NULL, G_CALLBACK(view_info) },
- { "ViewThree", NULL, "Three", "<control>4", NULL, G_CALLBACK(view_three) },
+ { "ViewList", NULL, "List", CTRLCHAR "1", NULL, G_CALLBACK(view_list) },
+ { "ViewProfile", NULL, "Profile", CTRLCHAR "2", NULL, G_CALLBACK(view_profile) },
+ { "ViewInfo", NULL, "Info", CTRLCHAR "3", NULL, G_CALLBACK(view_info) },
+ { "ViewThree", NULL, "Three", CTRLCHAR "4", NULL, G_CALLBACK(view_three) },
};
static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
@@ -634,12 +630,11 @@ static const gchar* ui_string = " \
</ui> \
";
-static GtkWidget *get_menubar_menu(GtkWidget *window)
+static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager)
{
GtkActionGroup *action_group = gtk_action_group_new("Menu");
gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
- GtkUIManager *ui_manager = gtk_ui_manager_new();
gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
GError* error = 0;
gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error);
@@ -659,15 +654,14 @@ void init_ui(int *argcp, char ***argvp)
{
GtkWidget *win;
GtkWidget *notebook;
- GtkWidget *dive_info;
+ GtkWidget *nb_page;
GtkWidget *dive_list;
- GtkWidget *equipment;
- GtkWidget *stats;
GtkWidget *menubar;
GtkWidget *vbox;
GdkScreen *screen;
GtkIconTheme *icon_theme=NULL;
GtkSettings *settings;
+ GtkUIManager *ui_manager;
gtk_init(argcp, argvp);
settings = gtk_settings_get_default();
@@ -695,9 +689,6 @@ void init_ui(int *argcp, char ***argvp)
divelist_font = subsurface_get_conf("divelist_font", PREF_STRING);
- if (!divelist_font)
- divelist_font = DIVELIST_DEFAULT_FONT;
-
error_info_bar = NULL;
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_set_application_name ("subsurface");
@@ -712,12 +703,11 @@ void init_ui(int *argcp, char ***argvp)
gtk_window_set_default_icon_name ("subsurface");
}
}
- if (need_icon)
-#if defined __linux__ || defined __APPLE__
- gtk_window_set_icon_from_file(GTK_WINDOW(win), "subsurface.svg", NULL);
-#elif defined WIN32
- gtk_window_set_icon_from_file(GTK_WINDOW(win), "subsurface.ico", NULL);
-#endif
+ if (need_icon) {
+ const char *icon_name = subsurface_icon_name();
+ if (!access(icon_name, R_OK))
+ gtk_window_set_icon_from_file(GTK_WINDOW(win), icon_name, NULL);
+ }
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;
@@ -726,8 +716,10 @@ void init_ui(int *argcp, char ***argvp)
gtk_container_add(GTK_CONTAINER(win), vbox);
main_vbox = vbox;
- menubar = get_menubar_menu(win);
- gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
+ ui_manager = gtk_ui_manager_new();
+ menubar = get_menubar_menu(win, ui_manager);
+
+ subsurface_ui_setup(settings, menubar, vbox, ui_manager);
vpane = gtk_vpaned_new();
gtk_box_pack_start(GTK_BOX(vbox), vpane, TRUE, TRUE, 3);
@@ -751,16 +743,20 @@ void init_ui(int *argcp, char ***argvp)
gtk_paned_add2(GTK_PANED(hpane), dive_profile);
/* Frame for extended dive info */
- dive_info = extended_dive_info_widget();
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dive_info, gtk_label_new("Dive Notes"));
+ nb_page = extended_dive_info_widget();
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Dive Notes"));
/* Frame for dive equipment */
- equipment = equipment_widget();
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), equipment, gtk_label_new("Equipment"));
+ nb_page = equipment_widget();
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Equipment"));
+
+ /* Frame for single dive statistics */
+ nb_page = single_stats_widget();
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Dive Info"));
- /* Frame for dive statistics */
- stats = stats_widget();
- gtk_notebook_append_page(GTK_NOTEBOOK(notebook), stats, gtk_label_new("Info & Stats"));
+ /* Frame for total dive statistics */
+ nb_page = total_stats_widget();
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook), nb_page, gtk_label_new("Stats"));
gtk_widget_set_app_paintable(win, TRUE);
gtk_widget_show_all(win);
@@ -975,7 +971,7 @@ static GtkWidget *xml_file_selector(GtkWidget *vbox, GtkWidget *main_dialog)
static void do_import_file(gpointer data, gpointer user_data)
{
GError *error = NULL;
- parse_xml_file(data, &error);
+ parse_file(data, &error);
if (error != NULL)
{