application menu defined in the .glade.
[psensor.git] / src / ui.c
index 8aab320..9bc6743 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2012 jeanfi@gmail.com
+ * Copyright (C) 2010-2013 jeanfi@gmail.com
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -92,22 +92,22 @@ void ui_show_about_dialog()
                 NULL);
 }
 
-static void cb_about(GtkMenuItem *mi, gpointer data)
+void ui_cb_about(GtkMenuItem *mi, gpointer data)
 {
        ui_show_about_dialog();
 }
 
-static void cb_menu_quit(GtkMenuItem *mi, gpointer data)
+void ui_cb_menu_quit(GtkMenuItem *mi, gpointer data)
 {
        ui_psensor_quit((struct ui_psensor *)data);
 }
 
-static void cb_preferences(GtkMenuItem *mi, gpointer data)
+void ui_cb_preferences(GtkMenuItem *mi, gpointer data)
 {
        ui_pref_dialog_run((struct ui_psensor *)data);
 }
 
-static void cb_sensor_preferences(GtkMenuItem *mi, gpointer data)
+void ui_cb_sensor_preferences(GtkMenuItem *mi, gpointer data)
 {
        struct ui_psensor *ui = data;
 
@@ -124,69 +124,6 @@ void ui_psensor_quit(struct ui_psensor *ui)
        gtk_main_quit();
 }
 
-static const char *menu_desc =
-"<ui>"
-"  <menubar name='MainMenu'>"
-"    <menu name='Psensor' action='PsensorMenuAction'>"
-"      <menuitem name='Preferences' action='PreferencesAction' />"
-"      <menuitem name='SensorPreferences' action='SensorPreferencesAction' />"
-"      <separator />"
-"      <menuitem name='Quit' action='QuitAction' />"
-"    </menu>"
-"    <menu name='Help' action='HelpMenuAction'>"
-"      <menuitem name='About' action='AboutAction' />"
-"    </menu>"
-"  </menubar>"
-"</ui>";
-
-static GtkActionEntry entries[] = {
-       { "PsensorMenuAction", NULL, "_Psensor" },
-
-       { "PreferencesAction", GTK_STOCK_PREFERENCES,
-         N_("_Preferences"), NULL,
-         N_("Preferences"),
-         G_CALLBACK(cb_preferences) },
-
-       { "SensorPreferencesAction", GTK_STOCK_PREFERENCES,
-         N_("S_ensor Preferences"), NULL,
-         N_("Sensor Preferences"),
-         G_CALLBACK(cb_sensor_preferences) },
-
-       { "QuitAction",
-         GTK_STOCK_QUIT, N_("_Quit"), NULL, N_("Quit"),
-         G_CALLBACK(cb_menu_quit) },
-
-       { "HelpMenuAction", NULL, N_("_Help") },
-
-       { "AboutAction", GTK_STOCK_PREFERENCES,
-         N_("_About"), NULL,
-         N_("About"),
-         G_CALLBACK(cb_about) }
-};
-static guint n_entries = G_N_ELEMENTS(entries);
-
-static GtkWidget *get_menu(struct ui_psensor *ui)
-{
-       GtkActionGroup *action_group;
-       GtkUIManager *menu_manager;
-       GError *error;
-
-       action_group = gtk_action_group_new("PsensorActions");
-       gtk_action_group_set_translation_domain(action_group, PACKAGE);
-       menu_manager = gtk_ui_manager_new();
-
-       gtk_action_group_add_actions(action_group, entries, n_entries, ui);
-       gtk_ui_manager_insert_action_group(menu_manager, action_group, 0);
-
-       error = NULL;
-       gtk_ui_manager_add_ui_from_string(menu_manager, menu_desc, -1, &error);
-
-       if (error)
-               g_error(_("building menus failed: %s"), error->message);
-
-       return gtk_ui_manager_get_widget(menu_manager, "/MainMenu");
-}
-
 void ui_enable_alpha_channel(struct ui_psensor *ui)
 {
        GdkScreen *screen;
@@ -211,7 +148,6 @@ void ui_enable_alpha_channel(struct ui_psensor *ui)
        } else {
                cfg->alpha_channel_enabled = 0;
        }
-
 }
 
 static void on_slog_enabled_cb(GConfClient *client,
@@ -232,7 +168,7 @@ static void on_slog_enabled_cb(GConfClient *client,
        if (is_slog_enabled())
                slog_activate(NULL, sensors, mutex, config_get_slog_interval());
        else
-               slog_close(NULL, sensors);
+               slog_close();
 }
 
 void ui_window_create(struct ui_psensor *ui)
@@ -241,9 +177,26 @@ void ui_window_create(struct ui_psensor *ui)
        GdkPixbuf *icon;
        GtkIconTheme *icon_theme;
        struct config *cfg;
+       guint ok;
+       GtkBuilder *builder;
+       GError *error;
 
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       builder = gtk_builder_new();
 
+       error = NULL;
+       ok = gtk_builder_add_from_file
+               (builder,
+                PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "psensor.glade",
+                &error);
+
+       if (!ok) {
+               log_printf(LOG_ERR, error->message);
+               g_error_free(error);
+               return ;
+       }
+
+       window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
+       gtk_builder_connect_signals(builder, ui);
        cfg = ui->config;
        if (cfg->window_restore_enabled)
                gtk_window_move(GTK_WINDOW(window),
@@ -256,10 +209,6 @@ void ui_window_create(struct ui_psensor *ui)
                                    cfg->window_w,
                                    cfg->window_h);
 
-       gtk_window_set_title(GTK_WINDOW(window),
-                            _("Psensor - Temperature Monitor"));
-       gtk_window_set_role(GTK_WINDOW(window), "psensor");
-
        icon_theme = gtk_icon_theme_get_default();
        icon = gtk_icon_theme_load_icon(icon_theme, "psensor", 48, 0, NULL);
        if (icon)
@@ -277,10 +226,9 @@ void ui_window_create(struct ui_psensor *ui)
                                  cfg->window_keep_below_enabled);
 
        /* main box */
-       menubar = get_menu(ui);
+       menubar = GTK_WIDGET(gtk_builder_get_object(builder, "menu_bar"));
 
-       ui->main_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
-       gtk_box_set_homogeneous(GTK_BOX(ui->main_box), FALSE);
+       ui->main_box = GTK_WIDGET(gtk_builder_get_object(builder, "main_box"));
        gtk_box_pack_start(GTK_BOX(ui->main_box), menubar,
                           FALSE, TRUE, 0);
 
@@ -360,5 +308,6 @@ void ui_window_update(struct ui_psensor *ui)
 void ui_window_show(struct ui_psensor *ui)
 {
        log_debug("ui_window_show()");
+       ui_window_update(ui);
        gtk_window_present(GTK_WINDOW(ui->main_window));
 }