added support of enabling/disabling menu
authorJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 25 Apr 2011 10:14:35 +0000 (10:14 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 25 Apr 2011 10:14:35 +0000 (10:14 +0000)
src/cfg.c
src/cfg.h
src/main.c
src/ui.c
src/ui.h
src/ui_pref.c

index be544bb..2baadf5 100644 (file)
--- a/src/cfg.c
+++ b/src/cfg.c
 #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);
+
 }
index d88dc29..00331d9 100644 (file)
--- 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;
 };
 
 /*
index 2fa038f..6afbfa2 100644 (file)
@@ -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;
 }
index 8ae8f41..8701355 100644 (file)
--- 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);
 }
index a1867e0..236a89d 100644 (file)
--- 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
index 44b5349..32cc35f 100644 (file)
@@ -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));