This is an automated email from the git hooks/post-receive script. o c h o s i p u s h e d a c o m m i t t o b r a n c h m a s t e r in repository xfce/xfce4-power-manager.
commit e319a4932617fed22d8ddb27fe4a917f973f2e58 Author: Simon Steinbeiss <[email protected]> Date: Sun Oct 29 23:28:12 2017 +0100 panel-plugin: Add properties dialog (Bug #13270) So far the only option we have there is the formerly hidden option show-panel-label. --- .../xfce/xfce-power-manager-plugin.c | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/panel-plugins/power-manager-plugin/xfce/xfce-power-manager-plugin.c b/panel-plugins/power-manager-plugin/xfce/xfce-power-manager-plugin.c index 66e1de4..28159fb 100644 --- a/panel-plugins/power-manager-plugin/xfce/xfce-power-manager-plugin.c +++ b/panel-plugins/power-manager-plugin/xfce/xfce-power-manager-plugin.c @@ -33,10 +33,13 @@ #ifdef XFCE_PLUGIN #include <libxfce4panel/libxfce4panel.h> #include <libxfce4panel/xfce-panel-plugin.h> +#include <libxfce4ui/libxfce4ui.h> #include <libxfce4util/libxfce4util.h> +#include <xfconf/xfconf.h> #endif #include "../power-manager-button.h" +#include "common/xfpm-config.h" /* plugin structure */ typedef struct @@ -49,12 +52,169 @@ typedef struct } PowerManagerPlugin; +enum { + COLUMN_INT, + COLUMN_STRING, + N_COLUMNS +}; /* prototypes */ static void power_manager_plugin_construct (XfcePanelPlugin *plugin); /* register the plugin */ XFCE_PANEL_PLUGIN_REGISTER (power_manager_plugin_construct); +static void +power_manager_plugin_configure_response (GtkWidget *dialog, + gint response, + PowerManagerPlugin *power_manager_plugin) +{ + gboolean result; + + if (response == GTK_RESPONSE_HELP) + { + result = g_spawn_command_line_async ("exo-open --launch WebBrowser " "http://docs.xfce.org/xfce/xfce4-power-manager/1.6/start", NULL); + + if (G_UNLIKELY (result == FALSE)) + g_warning (_("Unable to open the following url: %s"), "http://docs.xfce.org/xfce/xfce4-power-manager/1.6/start"); + } + else + { + g_object_set_data (G_OBJECT (power_manager_plugin->plugin), "dialog", NULL); + xfce_panel_plugin_unblock_menu (power_manager_plugin->plugin); + gtk_widget_destroy (dialog); + } +} + +/* Update xfconf property if combobox selection is changed */ +static void +power_manager_plugin_panel_label_changed (XfconfChannel *channel, + const gchar *property, + const GValue *value, + gpointer user_data) +{ + GtkWidget *combo = user_data; + GtkListStore *list_store; + GtkTreeIter iter; + int show_panel_label, current_setting; + + list_store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo))); + current_setting = g_value_get_int (value); + + for (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter); + gtk_list_store_iter_is_valid (list_store, &iter); + gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter)) + { + gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter, 0, &show_panel_label, -1); + if (show_panel_label == current_setting) + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), + &iter); + } +} + +/* Update combo if property in channel changes */ +static void +power_manager_plugin_combo_changed (GtkComboBox *combo, + gpointer user_data) +{ + XfconfChannel *channel = user_data; + GtkTreeModel *model; + GtkTreeIter iter; + int show_panel_label; + + if(!gtk_combo_box_get_active_iter(combo, &iter)) + return; + + model = gtk_combo_box_get_model (combo); + + gtk_tree_model_get (model, &iter, 0, &show_panel_label, -1); + xfconf_channel_set_int(channel, PROPERTIES_PREFIX SHOW_PANEL_LABEL, show_panel_label); +} + +void +power_manager_plugin_configure (XfcePanelPlugin *plugin, + PowerManagerPlugin *power_manager_plugin) +{ + GtkWidget *dialog; + GtkWidget *grid, *combo, *label, *check; + GtkAdjustment *adjustment; + gint show_panel_label; + XfconfChannel *channel; + GtkListStore *list_store; + GtkTreePath *path; + GtkTreeIter iter, active_iter; + GtkCellRenderer *cell; + gint i; + gchar *options[] = { _("None"), _("Percentage"), _("Remaining time"), _("Percentage and remaining time") }; + + channel = xfconf_channel_get ("xfce4-power-manager"); + + /* block the plugin menu */ + xfce_panel_plugin_block_menu (plugin); + + /* create the dialog */ + dialog = xfce_titled_dialog_new_with_buttons (_("Power Manager Plugin Settings"), + GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))), + GTK_DIALOG_DESTROY_WITH_PARENT, + "gtk-help", GTK_RESPONSE_HELP, + "gtk-close", GTK_RESPONSE_OK, + NULL); + gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); + gtk_window_set_icon_name (GTK_WINDOW (dialog), "xfce4-power-manager-settings"); + gtk_widget_show (dialog); + + /* Set up the main grid for all settings */ + grid = gtk_grid_new (); + gtk_grid_set_row_spacing (GTK_GRID (grid), 6); + gtk_grid_set_column_spacing (GTK_GRID (grid), 12); + gtk_widget_set_margin_start (grid, 12); + gtk_widget_set_margin_end (grid, 12); + gtk_widget_set_margin_top (grid, 12); + gtk_widget_set_margin_bottom (grid, 12); + gtk_container_add_with_properties (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), + grid, "expand", TRUE, "fill", TRUE, NULL); + + /* show-panel-label setting */ + label = gtk_label_new (_("Show label:")); + gtk_label_set_xalign (GTK_LABEL (label), 0.0); + gtk_grid_attach (GTK_GRID (grid), GTK_WIDGET (label), 0, 0, 1, 1); + show_panel_label = xfconf_channel_get_int (channel, PROPERTIES_PREFIX SHOW_PANEL_LABEL, -1); + + list_store = gtk_list_store_new (N_COLUMNS, + G_TYPE_INT, + G_TYPE_STRING); + + for (i = 0; i < 4; i++) { + gtk_list_store_append (list_store, &iter); + gtk_list_store_set (list_store, &iter, + COLUMN_INT, i, + COLUMN_STRING, options[i], + -1); + if (i == show_panel_label) + active_iter = iter; + } + combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (list_store)); + cell = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE ); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell, "text", COLUMN_STRING, NULL); + gtk_combo_box_set_id_column (GTK_COMBO_BOX (combo), COLUMN_STRING); + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &active_iter); + gtk_grid_attach (GTK_GRID (grid), GTK_WIDGET (combo), 1, 0, 1, 1); + g_signal_connect (G_OBJECT (combo), "changed", + G_CALLBACK (power_manager_plugin_combo_changed), + channel); + g_signal_connect (G_OBJECT (channel), "property-changed::" PROPERTIES_PREFIX SHOW_PANEL_LABEL, + G_CALLBACK (power_manager_plugin_panel_label_changed), + combo); + + /* link the dialog to the plugin, so we can destroy it when the plugin + * is closed, but the dialog is still open */ + g_object_set_data (G_OBJECT (plugin), "dialog", dialog); + + g_signal_connect (G_OBJECT (dialog), "response", + G_CALLBACK(power_manager_plugin_configure_response), power_manager_plugin); + gtk_widget_show_all (grid); +} + static PowerManagerPlugin * power_manager_plugin_new (XfcePanelPlugin *plugin) @@ -90,6 +250,11 @@ power_manager_plugin_construct (XfcePanelPlugin *plugin) /* create the plugin */ power_manager_plugin = power_manager_plugin_new (plugin); + /* show the configure menu item and connect signal */ + xfce_panel_plugin_menu_show_configure (plugin); + g_signal_connect (G_OBJECT (plugin), "configure-plugin", + G_CALLBACK (power_manager_plugin_configure), power_manager_plugin); + /* add the ebox to the panel */ gtk_container_add (GTK_CONTAINER (plugin), power_manager_plugin->ebox); } -- To stop receiving notification emails like this one, please contact the administrator of this repository. _______________________________________________ Xfce4-commits mailing list [email protected] https://mail.xfce.org/mailman/listinfo/xfce4-commits
