From: Linus Torvalds Date: Tue, 20 Sep 2011 18:24:15 +0000 (-0700) Subject: Make the divelist font configurable X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6ea513246363ba2df29b0dfa9bc752c7d40c0c38;p=ext%2Fsubsurface.git Make the divelist font configurable Instead of the hardcoding to "Sans 8", allow people to set it in the preferences. Also, make the unit choice be a frame in the preferences dialog instead. Signed-off-by: Linus Torvalds --- diff --git a/display.h b/display.h index bc97119..b5b0f91 100644 --- a/display.h +++ b/display.h @@ -7,6 +7,9 @@ extern GtkWidget *main_window; +extern const char *divelist_font; +extern void set_divelist_font(const char *); + extern void import_dialog(GtkWidget *, gpointer); extern void report_error(GError* error); diff --git a/divelist.c b/divelist.c index 0a601c5..01ab1b1 100644 --- a/divelist.c +++ b/divelist.c @@ -344,6 +344,13 @@ void flush_divelist(struct dive *dive) gtk_tree_model_foreach(model, set_one_dive, dive); } +void set_divelist_font(const char *font) +{ + PangoFontDescription *font_desc = pango_font_description_from_string(font); + gtk_widget_modify_font(dive_list.tree_view, font_desc); + pango_font_description_free(font_desc); +} + void update_dive_list_units(void) { const char *unit; @@ -446,7 +453,6 @@ static GtkTreeViewColumn *divelist_column(struct DiveList *dl, int index, const GtkWidget *dive_list_create(void) { GtkTreeSelection *selection; - PangoFontDescription *font_desc = pango_font_description_from_string("sans 8"); dive_list.model = gtk_list_store_new(DIVELIST_COLUMNS, G_TYPE_INT, /* index */ @@ -460,8 +466,7 @@ GtkWidget *dive_list_create(void) G_TYPE_INT /* SAC */ ); dive_list.tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(dive_list.model)); - gtk_widget_modify_font(dive_list.tree_view, font_desc); - pango_font_description_free(font_desc); + set_divelist_font(divelist_font); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dive_list.tree_view)); diff --git a/main.c b/main.c index dfd1b14..7d65c87 100644 --- a/main.c +++ b/main.c @@ -15,6 +15,9 @@ GtkWidget *error_info_bar; GtkWidget *error_label; int error_count; +#define DIVELIST_DEFAULT_FONT "Sans 8" +const char *divelist_font; + GConfClient *gconf; struct units output_units; @@ -223,14 +226,14 @@ static void quit(GtkWidget *w, gpointer data) gtk_main_quit(); } -static void create_radio(GtkWidget *dialog, const char *name, ...) +static void create_radio(GtkWidget *vbox, const char *name, ...) { va_list args; GtkRadioButton *group = NULL; GtkWidget *box, *label; box = gtk_hbox_new(TRUE, 10); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), box); + gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 0); label = gtk_label_new(name); gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0); @@ -275,45 +278,58 @@ UNITCALLBACK(set_cuft, volume, CUFT) UNITCALLBACK(set_celsius, temperature, CELSIUS) UNITCALLBACK(set_fahrenheit, temperature, FAHRENHEIT) -static void unit_dialog(GtkWidget *w, gpointer data) +static void preferences_dialog(GtkWidget *w, gpointer data) { int result; - GtkWidget *dialog; + GtkWidget *dialog, *font, *frame, *box; menu_units = output_units; - dialog = gtk_dialog_new_with_buttons("Units", + dialog = gtk_dialog_new_with_buttons("Preferences", GTK_WINDOW(main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); - create_radio(dialog, "Depth:", + frame = gtk_frame_new("Units"); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5); + + box = gtk_vbox_new(FALSE, 6); + gtk_container_add(GTK_CONTAINER(frame), box); + + create_radio(box, "Depth:", "Meter", set_meter, (output_units.length == METERS), "Feet", set_feet, (output_units.length == FEET), NULL); - create_radio(dialog, "Pressure:", + create_radio(box, "Pressure:", "Bar", set_bar, (output_units.pressure == BAR), "PSI", set_psi, (output_units.pressure == PSI), NULL); - create_radio(dialog, "Volume:", + create_radio(box, "Volume:", "Liter", set_liter, (output_units.volume == LITER), "CuFt", set_cuft, (output_units.volume == CUFT), NULL); - create_radio(dialog, "Temperature:", + create_radio(box, "Temperature:", "Celsius", set_celsius, (output_units.temperature == CELSIUS), "Fahrenheit", set_fahrenheit, (output_units.temperature == FAHRENHEIT), NULL); + font = gtk_font_button_new_with_font(divelist_font); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), font, FALSE, FALSE, 5); + gtk_widget_show_all(dialog); result = gtk_dialog_run(GTK_DIALOG(dialog)); if (result == GTK_RESPONSE_ACCEPT) { /* Make sure to flush any modified old dive data with old units */ update_dive(NULL); + + divelist_font = strdup(gtk_font_button_get_font_name(GTK_FONT_BUTTON(font))); + set_divelist_font(divelist_font); + output_units = menu_units; update_dive_list_units(); repaint_dive(); @@ -321,6 +337,7 @@ static void unit_dialog(GtkWidget *w, gpointer data) 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_string(gconf, GCONF_NAME(divelist_font), divelist_font, NULL); } gtk_widget_destroy(dialog); } @@ -370,7 +387,7 @@ static GtkActionEntry menu_items[] = { { "SaveFile", GTK_STOCK_SAVE, NULL, "S", NULL, G_CALLBACK(file_save) }, { "Print", GTK_STOCK_PRINT, NULL, "P", NULL, G_CALLBACK(do_print) }, { "Import", NULL, "Import", NULL, NULL, G_CALLBACK(import_dialog) }, - { "Units", NULL, "Units", NULL, NULL, G_CALLBACK(unit_dialog) }, + { "Preferences", NULL, "Preferences", NULL, NULL, G_CALLBACK(preferences_dialog) }, { "Renumber", NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) }, { "Quit", GTK_STOCK_QUIT, NULL, "Q", NULL, G_CALLBACK(quit) }, }; @@ -386,10 +403,11 @@ static const gchar* ui_string = " \ \ \ \ + \ + \ \ \ \ - \ \ \ \ @@ -447,6 +465,10 @@ int main(int argc, char **argv) if (gconf_client_get_bool(gconf, GCONF_NAME(fahrenheit), NULL)) output_units.temperature = FAHRENHEIT; + divelist_font = gconf_client_get_string(gconf, GCONF_NAME(divelist_font), NULL); + 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);