From d92bb15bcf27f77b27cea7554686fce24f86e042 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 25 Apr 2011 10:14:35 +0000 Subject: [PATCH] added support of enabling/disabling menu --- src/cfg.c | 13 +++++++++++++ src/cfg.h | 2 ++ src/main.c | 6 +----- src/ui.c | 18 +++++++++++++++++- src/ui.h | 10 +++++++++- src/ui_pref.c | 15 +++++++++++++-- 6 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/cfg.c b/src/cfg.c index be544bb..2baadf5 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -52,6 +52,10 @@ #define KEY_INTERFACE_WINDOW_KEEP_BELOW_ENABLED \ "/apps/psensor/interface/window_keep_below_enabled" +#define KEY_INTERFACE_MENU_BAR_DISABLED \ +"/apps/psensor/interface/menu_bar_disabled" + + GConfClient *client; char *config_get_string(char *key, char *default_value) @@ -429,6 +433,11 @@ struct config *config_load() if (cfg->sensor_values_max_length < 3) cfg->sensor_values_max_length = 3; + cfg->menu_bar_disabled = gconf_client_get_bool + (client, + KEY_INTERFACE_MENU_BAR_DISABLED, + NULL); + return cfg; } @@ -453,4 +462,8 @@ void config_save(struct config *cfg) KEY_SENSOR_UPDATE_INTERVAL, cfg->sensor_update_interval, NULL); + gconf_client_set_bool(client, + KEY_INTERFACE_MENU_BAR_DISABLED, + cfg->menu_bar_disabled, NULL); + } diff --git a/src/cfg.h b/src/cfg.h index d88dc29..00331d9 100644 --- a/src/cfg.h +++ b/src/cfg.h @@ -49,6 +49,8 @@ struct config { int sensor_values_max_length; int sensor_update_interval; + + int menu_bar_disabled; }; /* diff --git a/src/main.c b/src/main.c index 2fa038f..6afbfa2 100644 --- a/src/main.c +++ b/src/main.c @@ -389,9 +389,7 @@ int main(int argc, char **argv) /* sensor list */ ui.ui_sensorlist = ui_sensorlist_create(ui.sensors); - ui_sensor_box_create(&ui); - - gtk_widget_show_all(ui.main_window); + ui_window_update(&ui); thread = g_thread_create((GThreadFunc) update_psensor_measures, &ui, TRUE, &error); @@ -414,7 +412,5 @@ int main(int argc, char **argv) psensor_list_free(ui.sensors); - /* gdk_threads_leave(); */ - return 0; } diff --git a/src/ui.c b/src/ui.c index 8ae8f41..8701355 100644 --- a/src/ui.c +++ b/src/ui.c @@ -125,9 +125,20 @@ void ui_window_create(struct ui_psensor *ui) gtk_container_add(GTK_CONTAINER(window), ui->main_box); ui->main_window = window; + ui->menu_bar = menubar; + + gtk_widget_show_all(ui->main_window); } -void ui_sensor_box_create(struct ui_psensor *ui) +static void menu_bar_show(unsigned int show, struct ui_psensor *ui) +{ + if (show) + gtk_widget_show(ui->menu_bar); + else + gtk_widget_hide(ui->menu_bar); +} + +void ui_window_update(struct ui_psensor *ui) { struct config *cfg; GtkWidget *w_sensorlist; @@ -172,4 +183,9 @@ void ui_sensor_box_create(struct ui_psensor *ui) } gtk_widget_show_all(ui->sensor_box); + + if (cfg->menu_bar_disabled) + menu_bar_show(0, ui); + else + menu_bar_show(1, ui); } diff --git a/src/ui.h b/src/ui.h index a1867e0..236a89d 100644 --- a/src/ui.h +++ b/src/ui.h @@ -42,6 +42,8 @@ struct ui_psensor { GtkWidget *main_window; + GtkWidget *menu_bar; + /* The main vertical box, top contains the menubar, bottom contains the sensor_box. @@ -73,10 +75,14 @@ struct ui_psensor { }; /* + Update the window according to the configuration. + Creates or re-creates the sensor_box according to the position of the list of sensors in the configuration. + + Show or hide the menu bar. */ -void ui_sensor_box_create(struct ui_psensor *); +void ui_window_update(struct ui_psensor *); /* Must be called to terminate Psensor UI. @@ -88,4 +94,6 @@ void ui_psensor_quit(); */ void ui_window_create(struct ui_psensor *ui); +void ui_menu_bar_show(unsigned int show, struct ui_psensor *ui); + #endif diff --git a/src/ui_pref.c b/src/ui_pref.c index 44b5349..32cc35f 100644 --- a/src/ui_pref.c +++ b/src/ui_pref.c @@ -51,7 +51,8 @@ void ui_pref_dialog_run(struct ui_psensor *ui) GtkSpinButton *w_update_interval, *w_monitoring_duration, *w_s_update_interval; GtkComboBox *w_sensorlist_pos; - GtkToggleButton *w_hide_window_decoration, *w_keep_window_below; + GtkToggleButton *w_hide_window_decoration, *w_keep_window_below, + *w_enable_menu; cfg = ui->config; @@ -118,6 +119,13 @@ void ui_pref_dialog_run(struct ui_psensor *ui) gtk_toggle_button_set_active(w_keep_window_below, cfg->window_keep_below_enabled); + w_enable_menu = GTK_TOGGLE_BUTTON + (gtk_builder_get_object(builder, + "enable_menu")); + gtk_toggle_button_set_active(w_enable_menu, + !cfg->menu_bar_disabled); + + result = gtk_dialog_run(diag); if (result == GTK_RESPONSE_ACCEPT) { @@ -151,6 +159,9 @@ void ui_pref_dialog_run(struct ui_psensor *ui) cfg->window_keep_below_enabled = gtk_toggle_button_get_active(w_keep_window_below); + cfg->menu_bar_disabled + = !gtk_toggle_button_get_active(w_enable_menu); + gtk_window_set_decorated(GTK_WINDOW(ui->main_window), cfg->window_decoration_enabled); @@ -175,7 +186,7 @@ void ui_pref_dialog_run(struct ui_psensor *ui) g_mutex_unlock(ui->sensors_mutex); - ui_sensor_box_create(ui); + ui_window_update(ui); } g_object_unref(G_OBJECT(builder)); gtk_widget_destroy(GTK_WIDGET(diag)); -- 2.7.4