[Xfce4-commits] [xfce/xfce4-power-manager] 01/02: Selecting a device in the plugin displays the details

noreply at xfce.org noreply at xfce.org
Sun Jul 13 21:18:54 CEST 2014


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.

commit e63d7680e0eaf3541d4b585f807a635a97fbd0e0
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Mon Jul 7 17:55:04 2014 +0300

    Selecting a device in the plugin displays the details
    
    When the user selects a device in the battery plugin, the xfpm
    settings dialog is activated, the devices tab is brought to focus,
    and the device is selected with the details shown.
---
 common/xfpm-common.c                   |   11 +++++++++++
 common/xfpm-common.h                   |    2 ++
 panel-plugins/battery/battery-button.c |   22 ++++++++++++++++++++++
 settings/xfpm-settings-main.c          |    6 ++++--
 settings/xfpm-settings.c               |   30 +++++++++++++++++++++++++-----
 settings/xfpm-settings.h               |    3 ++-
 6 files changed, 66 insertions(+), 8 deletions(-)

diff --git a/common/xfpm-common.c b/common/xfpm-common.c
index 9073d85..51283b6 100644
--- a/common/xfpm-common.c
+++ b/common/xfpm-common.c
@@ -88,6 +88,17 @@ xfpm_preferences (void)
 }
 
 void
+xfpm_preferences_device_id (const gchar* object_path)
+{
+    gchar *string = g_strdup_printf("xfce4-power-manager-settings -d %s", object_path);
+
+    if (string)
+	g_spawn_command_line_async (string, NULL);
+
+    g_free (string);
+}
+
+void
 xfpm_quit (void)
 {
     g_spawn_command_line_async ("xfce4-power-manager -q", NULL);
diff --git a/common/xfpm-common.h b/common/xfpm-common.h
index ec3dd9f..afa3b6f 100644
--- a/common/xfpm-common.h
+++ b/common/xfpm-common.h
@@ -44,6 +44,8 @@ gboolean   	xfpm_lock_screen  		(void);
 
 void       	xfpm_preferences		(void);
 
+void        xfpm_preferences_device_id (const gchar* object_path);
+
 void            xfpm_quit                       (void);
 
 void       	xfpm_about			(GtkWidget *widget, 
diff --git a/panel-plugins/battery/battery-button.c b/panel-plugins/battery/battery-button.c
index 0012adb..09f9258 100644
--- a/panel-plugins/battery/battery-button.c
+++ b/panel-plugins/battery/battery-button.c
@@ -605,6 +605,25 @@ menu_item_destroyed_cb(GtkWidget *object, gpointer user_data)
 }
 
 static void
+menu_item_activate_cb(GtkWidget *object, gpointer user_data)
+{
+    BatteryButton *button = BATTERY_BUTTON (user_data);
+    GList *item;
+
+    for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+    {
+        BatteryDevice *battery_device = item->data;
+
+        if (battery_device->menu_item == object)
+        {
+            /* Call xfpm settings with the device id */
+            xfpm_preferences_device_id (battery_device->object_path);
+            return;
+        }
+    }
+}
+
+static void
 battery_button_menu_add_device (BatteryButton *button, BatteryDevice *battery_device, gboolean append)
 {
     GtkWidget *mi, *label, *img;
@@ -634,6 +653,9 @@ battery_button_menu_add_device (BatteryButton *button, BatteryDevice *battery_de
     battery_device->menu_item = mi;
     g_signal_connect(G_OBJECT(mi), "destroy", G_CALLBACK(menu_item_destroyed_cb), button);
 
+    /* Active calls xfpm settings with the device's id to display details */
+    g_signal_connect(G_OBJECT(mi), "activate", G_CALLBACK(menu_item_activate_cb), button);
+
     /* Add it to the menu */
     gtk_widget_show(mi);
     if (append)
diff --git a/settings/xfpm-settings-main.c b/settings/xfpm-settings-main.c
index 563aba9..9a00d19 100644
--- a/settings/xfpm-settings-main.c
+++ b/settings/xfpm-settings-main.c
@@ -69,13 +69,15 @@ int main (int argc, char **argv)
     gboolean start_xfpm_if_not_running;
     
     GdkNativeWindow socket_id = 0;
-	
+    gchar *device_id = NULL;
+
     XfconfChannel *channel;
     DBusGProxy *proxy;
     
     GOptionEntry option_entries[] = 
     {
 	{ "socket-id", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &socket_id, N_("Settings manager socket"), N_("SOCKET ID") },
+	{ "device-id", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &device_id, N_("Display a specific device by UpDevice object path"), N_("UpDevice object path") },
 	{ NULL, },
     };
 
@@ -171,7 +173,7 @@ int main (int argc, char **argv)
 	    dialog = xfpm_settings_dialog_new (channel, auth_suspend, auth_hibernate,
 					       can_suspend, can_hibernate, can_shutdown, has_battery, has_lcd_brightness,
 					       has_lid, has_sleep_button, has_hibernate_button, has_power_button,
-					       devkit_disk, can_spin_down, socket_id);
+					       devkit_disk, can_spin_down, socket_id, device_id);
 	    
 	    g_signal_connect_swapped (unique, "ping-received",
 				      G_CALLBACK (gtk_window_present), dialog);
diff --git a/settings/xfpm-settings.c b/settings/xfpm-settings.c
index 4fb7202..eacbdbf 100644
--- a/settings/xfpm-settings.c
+++ b/settings/xfpm-settings.c
@@ -61,7 +61,7 @@ static  GtkWidget *sideview                 = NULL; /* Sidebar tree view - all d
 static  GtkWidget *device_details_notebook  = NULL; /* Displays the details of a deivce */
 
 static  gboolean  lcd_brightness = FALSE;
-
+static  gchar *starting_device_id = NULL;
 static  UpClient *upower = NULL;
 
 enum
@@ -177,8 +177,8 @@ void        lock_screen_toggled_cb                 (GtkWidget *w,
 void        on_spindown_hdd_changed		   (GtkWidget *w,
 						    XfconfChannel *channel);
 
-void        _cursor_changed_cb 			   (GtkTreeView *view, 
-						    gpointer data);
+static void view_cursor_changed_cb 		   (GtkTreeView *view,
+						    gpointer *user_data);
 
 
 
@@ -1857,6 +1857,19 @@ add_device (UpDevice *device)
 
     /* Add the icon and description for the device */
     update_device_details (device);
+
+    /* See if we're to select this device */
+    if (g_strcmp0 (object_path, starting_device_id) == 0)
+    {
+	GtkTreeSelection *selection;
+
+	DBG("object_path == starting_device_id, selecting device");
+
+	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sideview));
+
+	gtk_tree_selection_select_iter (selection, &iter);
+	view_cursor_changed_cb (GTK_TREE_VIEW (sideview), NULL);
+    }
 }
 
 static void
@@ -2002,7 +2015,7 @@ xfpm_settings_dialog_new (XfconfChannel *channel, gboolean auth_suspend,
                           gboolean has_lid, gboolean has_sleep_button,
                           gboolean has_hibernate_button, gboolean has_power_button,
                           gboolean devkit_disk, gboolean can_spin_down,
-                          GdkNativeWindow id)
+                          GdkNativeWindow id, gchar *device_id)
 {
     GtkWidget *plug;
     GtkWidget *dialog;
@@ -2035,6 +2048,7 @@ xfpm_settings_dialog_new (XfconfChannel *channel, gboolean auth_suspend,
     }
     
     lcd_brightness = has_lcd_brightness;
+    starting_device_id = device_id;
     
     on_battery_dpms_sleep = GTK_WIDGET (gtk_builder_get_object (xml, "sleep-dpms-on-battery"));
     on_battery_dpms_off = GTK_WIDGET (gtk_builder_get_object (xml, "off-dpms-on-battery"));
@@ -2164,6 +2178,12 @@ xfpm_settings_dialog_new (XfconfChannel *channel, gboolean auth_suspend,
     }
     
     gtk_builder_connect_signals (xml, channel);
-    
+
+    /* If we passed in a device to display, show the devices tab now */
+    if (device_id != NULL)
+    {
+	gtk_notebook_set_current_page (GTK_NOTEBOOK (nt), 3);
+    }
+
     return dialog;
 }
diff --git a/settings/xfpm-settings.h b/settings/xfpm-settings.h
index b70a002..739119d 100644
--- a/settings/xfpm-settings.h
+++ b/settings/xfpm-settings.h
@@ -36,6 +36,7 @@ GtkWidget *xfpm_settings_dialog_new (XfconfChannel *channel,
                                      gboolean has_power_button,
                                      gboolean devkit_disk,
                                      gboolean can_spin_down,
-                                     GdkNativeWindow id);
+                                     GdkNativeWindow id,
+                                     gchar    *device_id);
 
 #endif /* __XFPM_SETTINGS_H */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list