[Xfce4-commits] <xfce4-power-manager:master> Replace Information tray menu item by Power information, the new dialog in an external program, xfce4-power-information will be able to show information about power devices+processor wakeups.
Ali Abdallah
noreply at xfce.org
Sat Jan 30 02:18:39 CET 2010
Updating branch refs/heads/master
to 86c848dc1aad88f772500c4e25feabdd36e41a4f (commit)
from f654a43b5d33a50ac63c15178c75c2a9d80b6012 (commit)
commit 86c848dc1aad88f772500c4e25feabdd36e41a4f
Author: Ali Abdallah <aliov at xfce.org>
Date: Fri Jan 22 16:16:10 2010 +0100
Replace Information tray menu item by Power information, the new dialog in an external program, xfce4-power-information
will be able to show information about power devices+processor wakeups.
common/xfpm-icons.h | 8 +
configure.ac.in | 6 +
data/icons/Makefile.am | 9 +-
data/interfaces/xfpm-settings.ui | 4 +-
settings/xfpm-settings-main.c | 140 +++---
settings/xfpm-settings.c | 4 +-
settings/xfpm-settings.h | 2 +-
src/Makefile.am | 28 +-
src/xfpm-battery.c | 16 +-
src/xfpm-battery.h | 2 -
src/xfpm-dkp.c | 70 ++--
src/xfpm-dkp.h | 5 -
src/xfpm-power-common.c | 197 ++++++++
src/xfpm-power-common.h | 61 +++
src/xfpm-power-info.c | 986 ++++++++++++++++++++++++++++++++++++++
15 files changed, 1405 insertions(+), 133 deletions(-)
diff --git a/common/xfpm-icons.h b/common/xfpm-icons.h
index e00a96d..6d6bba9 100644
--- a/common/xfpm-icons.h
+++ b/common/xfpm-icons.h
@@ -24,7 +24,15 @@
G_BEGIN_DECLS
#define XFPM_AC_ADAPTER_ICON "xfpm-ac-adapter"
+
#define XFPM_BATTERY_ICON "battery"
+#define XFPM_UPS_ICON "xfpm-ups-100"
+#define XFPM_KBD_ICON "xfpm-keyboard-100"
+#define XFPM_MOUSE_ICON "xfpm-mouse-100"
+#define XFPM_PHONE_ICON "xfpm-phone-100"
+#define XFPM_PDA_ICON "xfpm-pda-100"
+
+#define XFPM_PROCESSOR_ICON "processor"
#define XFPM_PRIMARY_ICON_PREFIX "xfpm-primary-"
#define XFPM_UPS_ICON_PREFIX "xfpm-ups-"
diff --git a/configure.ac.in b/configure.ac.in
index 8ca5377..8290d00 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -199,6 +199,12 @@ panel-plugins/Makefile
panel-plugins/brightness/Makefile
data/Makefile
data/icons/Makefile
+data/icons/16x16/Makefile
+data/icons/24x24/Makefile
+data/icons/32x32/Makefile
+data/icons/48x48/Makefile
+data/icons/128x128/Makefile
+data/icons/128x128/devices/Makefile
data/icons/scalable/Makefile
data/icons/scalable/status/Makefile
data/icons/scalable/actions/Makefile
diff --git a/data/icons/Makefile.am b/data/icons/Makefile.am
index ce27290..e15d824 100644
--- a/data/icons/Makefile.am
+++ b/data/icons/Makefile.am
@@ -1,7 +1,10 @@
SUBDIRS = \
- scalable
-
-
+ scalable \
+ 16x16 \
+ 24x24 \
+ 32x32 \
+ 48x48 \
+ 128x128
gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor
diff --git a/data/interfaces/xfpm-settings.ui b/data/interfaces/xfpm-settings.ui
index b4175f4..f78bdb2 100644
--- a/data/interfaces/xfpm-settings.ui
+++ b/data/interfaces/xfpm-settings.ui
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<interface>
<!-- interface-requires gtk+ 2.12 -->
- <!-- interface-requires xfce4 4.6 -->
+ <!-- interface-requires libxfce4ui 4.5 -->
<!-- interface-naming-policy toplevel-contextual -->
<object class="GtkAdjustment" id="adjustment1">
<property name="value">14</property>
@@ -156,6 +156,8 @@
</child>
</object>
<packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
diff --git a/settings/xfpm-settings-main.c b/settings/xfpm-settings-main.c
index 708b60d..49d31da 100644
--- a/settings/xfpm-settings-main.c
+++ b/settings/xfpm-settings-main.c
@@ -44,8 +44,11 @@
#include "xfpm-config.h"
#include "xfpm-dbus.h"
+#include "xfpm-unique.h"
+
int main (int argc, char **argv)
{
+
GError *error = NULL;
DBusGConnection *bus;
GHashTable *config_hash;
@@ -103,79 +106,82 @@ int main (int argc, char **argv)
if ( xfpm_dbus_name_has_owner (dbus_g_connection_get_connection(bus), "org.xfce.PowerManager") )
{
+ GtkWidget *dialog;
+ XfpmUnique *unique;
TRACE("Xfce power manager is running\n");
- if ( xfpm_dbus_name_has_owner(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config") )
- {
- TRACE("Settings dialog already open\n");
- dbus_g_connection_unref(bus);
- return EXIT_SUCCESS;
- }
-
- xfpm_dbus_register_name(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config");
-
- if ( !xfconf_init(&error) )
- {
- g_critical("xfconf init failed: %s using default settings\n", error->message);
- xfce_dialog_show_warning (NULL,
- _("Xfce Power Manager"),
- "%s",
- _("Failed to load power manager configuration, using defaults"));
- g_error_free (error);
- error = NULL;
- return EXIT_FAILURE;
- }
+ unique = xfpm_unique_new ("org.xfce.PowerManager.Config");
- if ( !g_thread_supported () )
- g_thread_init (NULL);
-
- dbus_g_thread_init ();
-
- channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
-
- proxy = dbus_g_proxy_new_for_name(bus,
- "org.xfce.PowerManager",
- "/org/xfce/PowerManager",
- "org.xfce.Power.Manager");
-
- xfpm_manager_dbus_client_get_config (proxy,
- &config_hash,
- &error);
-
- if ( error )
+ if ( !xfpm_unique_app_is_running (unique) )
{
- g_critical ("Unable to get configuration information from xfce power manager: %s", error->message);
- xfce_dialog_show_error (NULL, error, "%s", _("Unable to connect to Xfce Power Manager"));
- g_error_free (error);
- return EXIT_FAILURE;
+ if ( !xfconf_init(&error) )
+ {
+ g_critical("xfconf init failed: %s using default settings\n", error->message);
+ xfce_dialog_show_warning (NULL,
+ _("Xfce Power Manager"),
+ "%s",
+ _("Failed to load power manager configuration, using defaults"));
+ g_error_free (error);
+ error = NULL;
+ return EXIT_FAILURE;
+ }
+
+ if ( !g_thread_supported () )
+ g_thread_init (NULL);
+
+ dbus_g_thread_init ();
+
+ channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
+
+ proxy = dbus_g_proxy_new_for_name(bus,
+ "org.xfce.PowerManager",
+ "/org/xfce/PowerManager",
+ "org.xfce.Power.Manager");
+
+ xfpm_manager_dbus_client_get_config (proxy,
+ &config_hash,
+ &error);
+
+ if ( error )
+ {
+ g_critical ("Unable to get configuration information from xfce power manager: %s", error->message);
+ xfce_dialog_show_error (NULL, error, "%s", _("Unable to connect to Xfce Power Manager"));
+ g_error_free (error);
+ return EXIT_FAILURE;
+ }
+
+ has_battery = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-battery"));
+ has_lid = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-lid"));
+ can_suspend = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-suspend"));
+ can_hibernate = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-hibernate"));
+ auth_suspend = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "auth-suspend"));
+ auth_hibernate = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "auth-hibernate"));
+ has_lcd_brightness = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-brightness"));
+ has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "sleep-button"));
+ has_power_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "power-button"));
+ has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "hibernate-button"));
+ can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-shutdown"));
+ can_spin_down = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-spin"));
+ devkit_disk = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "devkit-disk"));
+
+ g_hash_table_destroy (config_hash);
+
+ dialog = xfpm_settings_dialog_new (channel, has_battery, auth_hibernate, auth_suspend,
+ can_shutdown, can_suspend, can_hibernate, has_lcd_brightness,
+ has_lid, has_sleep_button, has_hibernate_button, has_power_button,
+ devkit_disk, can_spin_down, socket_id);
+
+ g_signal_connect_swapped (unique, "ping-received",
+ G_CALLBACK (gtk_window_present), dialog);
+
+ gtk_main();
+
+ xfpm_dbus_release_name(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config");
+ dbus_g_connection_unref (bus);
+ g_object_unref (proxy);
}
- has_battery = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-battery"));
- has_lid = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-lid"));
- can_suspend = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-suspend"));
- can_hibernate = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-hibernate"));
- auth_suspend = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "auth-suspend"));
- auth_hibernate = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "auth-hibernate"));
- has_lcd_brightness = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-brightness"));
- has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "sleep-button"));
- has_power_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "power-button"));
- has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "hibernate-button"));
- can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-shutdown"));
- can_spin_down = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-spin"));
- devkit_disk = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "devkit-disk"));
-
- g_hash_table_destroy (config_hash);
-
- xfpm_settings_dialog_new (channel, has_battery, auth_hibernate, auth_suspend,
- can_shutdown, can_suspend, can_hibernate, has_lcd_brightness,
- has_lid, has_sleep_button, has_hibernate_button, has_power_button,
- devkit_disk, can_spin_down, socket_id);
-
- gtk_main();
-
- xfpm_dbus_release_name(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config");
- dbus_g_connection_unref (bus);
- g_object_unref (proxy);
+ g_object_unref (unique);
return EXIT_SUCCESS;
}
diff --git a/settings/xfpm-settings.c b/settings/xfpm-settings.c
index aa8ef6c..c15dbfb 100644
--- a/settings/xfpm-settings.c
+++ b/settings/xfpm-settings.c
@@ -1571,7 +1571,7 @@ delete_event_cb (GtkWidget *plug, GdkEvent *ev, XfconfChannel *channel)
settings_quit (plug, channel);
}
-void
+GtkWidget *
xfpm_settings_dialog_new (XfconfChannel *channel, gboolean system_laptop,
gboolean auth_hibernate, gboolean auth_suspend,
gboolean can_shutdown, gboolean can_suspend,
@@ -1661,4 +1661,6 @@ xfpm_settings_dialog_new (XfconfChannel *channel, gboolean system_laptop,
}
gtk_builder_connect_signals (xml, channel);
+
+ return dialog;
}
diff --git a/settings/xfpm-settings.h b/settings/xfpm-settings.h
index 0d39852..b23dd0f 100644
--- a/settings/xfpm-settings.h
+++ b/settings/xfpm-settings.h
@@ -22,7 +22,7 @@
#define __XFPM_SETTINGS_H
-void xfpm_settings_dialog_new (XfconfChannel *channel,
+GtkWidget *xfpm_settings_dialog_new (XfconfChannel *channel,
gboolean has_battery,
gboolean auth_hibernate,
gboolean auth_suspend,
diff --git a/src/Makefile.am b/src/Makefile.am
index 3074f40..560dd8f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,5 @@
-bin_PROGRAMS = xfce4-power-manager
+bin_PROGRAMS = xfce4-power-manager \
+ xfce4-power-information
xfce4_power_manager_SOURCES = \
$(BUILT_SOURCES) \
@@ -9,10 +10,10 @@ xfce4_power_manager_SOURCES = \
xfpm-manager.h \
xfpm-dkp.c \
xfpm-dkp.h \
+ xfpm-power-common.c \
+ xfpm-power-common.h \
xfpm-battery.c \
xfpm-battery.h \
- xfpm-battery-info.c \
- xfpm-battery-info.h \
xfpm-xfconf.c \
xfpm-xfconf.h \
xfpm-disks.c \
@@ -70,6 +71,27 @@ xfce4_power_manager_LDADD = \
$(POLKIT_LIBS) \
$(DPMS_LIBS)
+xfce4_power_information_SOURCES = \
+ xfpm-power-info.c \
+ xfpm-power-common.c \
+ xfpm-power-common.h
+
+xfce4_power_information_CFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/common \
+ -I$(top_srcdir)/libdbus \
+ -DLOCALEDIR=\"$(localedir)\" \
+ -DG_LOG_DOMAIN=\"xfce4-power-information\"\
+ $(GOBJECT_CFLAGS) \
+ $(DBUS_GLIB_CFLAGS) \
+ $(LIBXFCE4UI_CFLAGS)
+
+xfce4_power_information_LDADD = \
+ $(GOBJECT_LIBS) \
+ $(DBUS_GLIB_LIBS) \
+ $(LIBXFCE4UI_LIBS) \
+ $(top_builddir)/libdbus/libxfpmdbus.la
+
manpagedir = $(mandir)/man1
manpage_DATA = xfce4-power-manager.1
diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 9df5b36..aed541a 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -31,7 +31,6 @@
#include <libxfce4util/libxfce4util.h>
#include "xfpm-battery.h"
-#include "xfpm-battery-info.h"
#include "xfpm-dbus.h"
#include "xfpm-icons.h"
#include "xfpm-xfconf.h"
@@ -40,6 +39,7 @@
#include "xfpm-enum-glib.h"
#include "xfpm-enum-types.h"
#include "xfpm-debug.h"
+#include "xfpm-power-common.h"
#include "xfpm-common.h"
static void xfpm_battery_finalize (GObject *object);
@@ -510,7 +510,7 @@ xfpm_battery_changed_cb (DBusGProxy *proxy, XfpmBattery *battery)
{
GHashTable *props;
- props = xfpm_dbus_get_interface_properties (battery->priv->proxy_prop, DKP_IFACE_DEVICE);
+ props = xfpm_power_get_interface_properties (battery->priv->proxy_prop, DKP_IFACE_DEVICE);
if ( props )
xfpm_battery_refresh (battery, props);
@@ -752,15 +752,3 @@ XfpmBatteryCharge xfpm_battery_get_charge (XfpmBattery *battery)
return battery->priv->charge;
}
-
-void xfpm_battery_show_info (XfpmBattery *battery)
-{
- GHashTable *props;
- gchar *icon;
-
- props = xfpm_dbus_get_interface_properties (battery->priv->proxy_prop, DKP_IFACE_DEVICE);
- icon = g_strdup_printf ("%s100", battery->priv->icon_prefix);
- xfpm_battery_info_show (props, icon);
- g_free (icon);
- g_hash_table_destroy (props);
-}
diff --git a/src/xfpm-battery.h b/src/xfpm-battery.h
index 02ff781..57fd30e 100644
--- a/src/xfpm-battery.h
+++ b/src/xfpm-battery.h
@@ -65,8 +65,6 @@ XfpmDkpDeviceType xfpm_battery_get_device_type (XfpmBattery *battery);
XfpmBatteryCharge xfpm_battery_get_charge (XfpmBattery *battery);
-void xfpm_battery_show_info (XfpmBattery *battery);
-
G_END_DECLS
#endif /* __XFPM_BATTERY_H */
diff --git a/src/xfpm-dkp.c b/src/xfpm-dkp.c
index 7e5a6f9..f30d759 100644
--- a/src/xfpm-dkp.c
+++ b/src/xfpm-dkp.c
@@ -44,6 +44,7 @@
#include "xfpm-network-manager.h"
#include "xfpm-icons.h"
#include "xfpm-common.h"
+#include "xfpm-power-common.h"
#include "xfpm-config.h"
#include "xfpm-enum-glib.h"
#include "xfpm-debug.h"
@@ -96,6 +97,10 @@ struct XfpmDkpPrivate
gboolean can_suspend;
gboolean can_hibernate;
+ /**
+ * Warning dialog to use when notification daemon
+ * doesn't support actions.
+ **/
GtkWidget *dialog;
};
@@ -323,7 +328,7 @@ xfpm_dkp_get_properties (XfpmDkp *dkp)
{
GHashTable *props;
- props = xfpm_dbus_get_interface_properties (dkp->priv->proxy_prop, DKP_IFACE);
+ props = xfpm_power_get_interface_properties (dkp->priv->proxy_prop, DKP_IFACE);
xfpm_dkp_check_pm (dkp, props);
xfpm_dkp_check_lid (dkp, props);
@@ -466,9 +471,9 @@ xfpm_dkp_shutdown_clicked (XfpmDkp *dkp)
}
static void
-xfpm_dkp_battery_info_cb (GtkStatusIcon *icon)
+xfpm_dkp_power_info_cb (gpointer data)
{
- xfpm_battery_show_info (XFPM_BATTERY (icon));
+ g_spawn_command_line_async ("xfce4-power-information", NULL);
}
static void
@@ -544,32 +549,29 @@ xfpm_dkp_show_tray_menu (XfpmDkp *dkp,
gtk_widget_show(mi);
gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
*/
- if ( show_info_item )
- {
- mi = gtk_separator_menu_item_new ();
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- // Battery informations
+ mi = gtk_separator_menu_item_new ();
+ gtk_widget_show (mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+
+ // Power information
- mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_INFO, NULL);
-
- gtk_widget_set_sensitive (mi,FALSE);
- gtk_widget_set_sensitive (mi,TRUE);
-
- g_signal_connect_swapped (mi,"activate",
- G_CALLBACK (xfpm_dkp_battery_info_cb), icon);
-
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ mi = gtk_image_menu_item_new_with_label (_("Power Information"));
+ img = gtk_image_new_from_stock (GTK_STOCK_INFO, GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img);
+
+ gtk_widget_set_sensitive (mi,TRUE);
+ g_signal_connect_swapped (mi, "activate",
+ G_CALLBACK (xfpm_dkp_power_info_cb), icon);
+
+ gtk_widget_show (mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- // Separator
- mi = gtk_separator_menu_item_new ();
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- }
-
+ mi = gtk_separator_menu_item_new ();
+ gtk_widget_show (mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+
mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_HELP, NULL);
gtk_widget_set_sensitive (mi, TRUE);
gtk_widget_show (mi);
@@ -953,19 +955,15 @@ xfpm_dkp_add_device (XfpmDkp *dkp, const gchar *object_path)
return;
}
- value = xfpm_dbus_get_interface_property (proxy_prop, DKP_IFACE_DEVICE, "Type");
+ value = xfpm_power_get_interface_property (proxy_prop, DKP_IFACE_DEVICE, "Type");
device_type = g_value_get_uint (&value);
- if ( device_type == XFPM_DKP_DEVICE_TYPE_LINE_POWER )
- {
- //FIXME: Handel adaptor.
- }
- else if ( device_type == XFPM_DKP_DEVICE_TYPE_BATTERY ||
- device_type == XFPM_DKP_DEVICE_TYPE_UPS ||
- device_type == XFPM_DKP_DEVICE_TYPE_MOUSE ||
- device_type == XFPM_DKP_DEVICE_TYPE_KBD ||
- device_type == XFPM_DKP_DEVICE_TYPE_PHONE)
+ if ( device_type == XFPM_DKP_DEVICE_TYPE_BATTERY ||
+ device_type == XFPM_DKP_DEVICE_TYPE_UPS ||
+ device_type == XFPM_DKP_DEVICE_TYPE_MOUSE ||
+ device_type == XFPM_DKP_DEVICE_TYPE_KBD ||
+ device_type == XFPM_DKP_DEVICE_TYPE_PHONE)
{
GtkStatusIcon *battery;
DBusGProxy *proxy;
@@ -988,7 +986,7 @@ xfpm_dkp_add_device (XfpmDkp *dkp, const gchar *object_path)
xfpm_dkp_refresh_adaptor_visible (dkp);
}
- else
+ else if ( device_type != XFPM_DKP_DEVICE_TYPE_LINE_POWER )
{
g_warning ("Unable to monitor unkown power device with object_path : %s", object_path);
g_object_unref (proxy_prop);
diff --git a/src/xfpm-dkp.h b/src/xfpm-dkp.h
index 609a9c7..5af2c39 100644
--- a/src/xfpm-dkp.h
+++ b/src/xfpm-dkp.h
@@ -29,11 +29,6 @@ G_BEGIN_DECLS
#define XFPM_DKP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XFPM_TYPE_DKP, XfpmDkp))
#define XFPM_IS_DKP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XFPM_TYPE_DKP))
-#define DKP_NAME "org.freedesktop.DeviceKit.Power"
-#define DKP_PATH "/org/freedesktop/DeviceKit/Power"
-#define DKP_IFACE "org.freedesktop.DeviceKit.Power"
-#define DKP_IFACE_DEVICE "org.freedesktop.DeviceKit.Power.Device"
-
typedef struct XfpmDkpPrivate XfpmDkpPrivate;
typedef struct
diff --git a/src/xfpm-power-common.c b/src/xfpm-power-common.c
new file mode 100644
index 0000000..565851a
--- /dev/null
+++ b/src/xfpm-power-common.c
@@ -0,0 +1,197 @@
+/*
+ * * Copyright (C) 2010 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <libxfce4util/libxfce4util.h>
+
+#include "xfpm-power-common.h"
+#include "xfpm-enum-glib.h"
+
+#include "xfpm-icons.h"
+
+/**
+ * xfpm_power_enumerate_devices:
+ *
+ **/
+GPtrArray *
+xfpm_power_enumerate_devices (DBusGProxy *proxy)
+{
+ gboolean ret;
+ GError *error = NULL;
+ GPtrArray *array = NULL;
+ GType g_type_array;
+
+ g_type_array = dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH);
+
+ ret = dbus_g_proxy_call (proxy, "EnumerateDevices", &error,
+ G_TYPE_INVALID,
+ g_type_array, &array,
+ G_TYPE_INVALID);
+ if (!ret)
+ {
+ g_critical ("Couldn't enumerate power devices: %s", error->message);
+ g_error_free (error);
+ }
+
+ return array;
+}
+
+/**
+ * xfpm_power_get_interface_properties:
+ *
+ **/
+GHashTable *xfpm_power_get_interface_properties (DBusGProxy *proxy_prop, const gchar *iface_name)
+{
+ gboolean ret;
+ GError *error = NULL;
+ GHashTable *props = NULL;
+
+ props = NULL;
+
+ ret = dbus_g_proxy_call (proxy_prop, "GetAll", &error,
+ G_TYPE_STRING, iface_name,
+ G_TYPE_INVALID,
+ dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props,
+ G_TYPE_INVALID);
+
+ if (!ret)
+ {
+ g_warning ("Unable to get interface properties for : %s : %s", iface_name, error->message);
+ g_error_free (error);
+ }
+
+ return props;
+}
+
+/**
+ * xfpm_power_get_interface_property:
+ *
+ **/
+GValue xfpm_power_get_interface_property (DBusGProxy *proxy, const gchar *iface_name, const gchar *prop_name)
+{
+ gboolean ret;
+ GError *error = NULL;
+ GValue value = { 0, };
+
+ ret = dbus_g_proxy_call (proxy, "Get", &error,
+ G_TYPE_STRING, iface_name,
+ G_TYPE_STRING, prop_name,
+ G_TYPE_INVALID,
+ G_TYPE_VALUE, &value, G_TYPE_INVALID);
+
+ if (!ret)
+ {
+ g_warning ("Unable to get property %s on interface %s : %s", prop_name, iface_name, error->message);
+ g_error_free (error);
+ }
+
+ return value;
+}
+
+/**
+ * xfpm_power_translate_device_type:
+ *
+ **/
+const gchar *
+xfpm_power_translate_device_type (guint type)
+{
+ switch (type)
+ {
+ case XFPM_DKP_DEVICE_TYPE_BATTERY:
+ return _("Battery");
+ case XFPM_DKP_DEVICE_TYPE_UPS:
+ return _("UPS");
+ case XFPM_DKP_DEVICE_TYPE_LINE_POWER:
+ return _("Line power");
+ case XFPM_DKP_DEVICE_TYPE_MOUSE:
+ return _("Mouse");
+ case XFPM_DKP_DEVICE_TYPE_KBD:
+ return _("Keyboard");
+ case XFPM_DKP_DEVICE_TYPE_MONITOR:
+ return _("Monitor");
+ case XFPM_DKP_DEVICE_TYPE_PDA:
+ return _("PDA");
+ case XFPM_DKP_DEVICE_TYPE_PHONE:
+ return _("Phone");
+ case XFPM_DKP_DEVICE_TYPE_UNKNOWN:
+ return _("Unknown");
+ }
+
+ return _("Battery");
+}
+
+/**
+ * xfpm_power_translate_technology:
+ *
+ **/
+const gchar *xfpm_power_translate_technology (guint value)
+{
+ switch (value)
+ {
+ case 0:
+ return _("Unknown");
+ case 1:
+ return _("Lithium ion");
+ case 2:
+ return _("Lithium polymer");
+ case 3:
+ return _("Lithium iron phosphate");
+ case 4:
+ return _("Lead acid");
+ case 5:
+ return _("Nickel cadmium");
+ case 6:
+ return _("Nickel metal hybride");
+ }
+
+ return _("Unknown");
+}
+
+const gchar *xfpm_power_get_icon_name (guint device_type)
+{
+ switch (device_type)
+ {
+ case XFPM_DKP_DEVICE_TYPE_BATTERY:
+ return XFPM_BATTERY_ICON;
+ case XFPM_DKP_DEVICE_TYPE_UPS:
+ return XFPM_UPS_ICON;
+ case XFPM_DKP_DEVICE_TYPE_LINE_POWER:
+ return XFPM_AC_ADAPTER_ICON;
+ case XFPM_DKP_DEVICE_TYPE_MOUSE:
+ return XFPM_MOUSE_ICON;
+ case XFPM_DKP_DEVICE_TYPE_KBD:
+ return XFPM_KBD_ICON;
+ case XFPM_DKP_DEVICE_TYPE_MONITOR:
+ return "monitor";
+ case XFPM_DKP_DEVICE_TYPE_PDA:
+ return XFPM_PDA_ICON;
+ case XFPM_DKP_DEVICE_TYPE_PHONE:
+ return XFPM_PHONE_ICON;
+ case XFPM_DKP_DEVICE_TYPE_UNKNOWN:
+ return XFPM_BATTERY_ICON;
+ }
+
+ return XFPM_BATTERY_ICON;
+}
+
+
diff --git a/src/xfpm-power-common.h b/src/xfpm-power-common.h
new file mode 100644
index 0000000..83c530d
--- /dev/null
+++ b/src/xfpm-power-common.h
@@ -0,0 +1,61 @@
+/*
+ * * Copyright (C) 2010 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef XFPM_UPOWER_COMMON
+#define XFPM_UPOWER_COMMON
+
+#include <dbus/dbus-glib.h>
+
+#define DKP_NAME "org.freedesktop.DeviceKit.Power"
+#define DKP_PATH "/org/freedesktop/DeviceKit/Power"
+
+#define DKP_IFACE "org.freedesktop.DeviceKit.Power"
+#define DKP_IFACE_DEVICE "org.freedesktop.DeviceKit.Power.Device"
+#define DKP_PATH_DEVICE "/org/freedesktop/DeviceKit/Power/devices/"
+
+#define DKP_PATH_WAKEUPS "/org/freedesktop/DeviceKit/Power/Wakeups"
+#define DKP_IFACE_WAKEUPS "org.freedesktop.DeviceKit.Power.Wakeups"
+
+#define UPOWER_NAME "org.freedesktop.DeviceKit.Power"
+#define UPOWER_PATH "/org/freedesktop/DeviceKit/Power"
+
+#define UPOWER_IFACE "org.freedesktop.DeviceKit.Power"
+#define UPOWER_IFACE_DEVICE "org.freedesktop.DeviceKit.Power.Device"
+
+#define UPOWER_PATH_WAKEUPS "/org/freedesktop/DeviceKit/Power/Wakeups"
+#define UPOWER_IFACE_WAKEUPS "org.freedesktop.DeviceKit.Power.Wakeups"
+
+
+GPtrArray *xfpm_power_enumerate_devices (DBusGProxy *proxy);
+
+GHashTable *xfpm_power_get_interface_properties (DBusGProxy *proxy_prop,
+ const gchar *iface_name);
+
+GValue xfpm_power_get_interface_property (DBusGProxy *proxy,
+ const gchar *iface_name,
+ const gchar *prop_name);
+
+const gchar *xfpm_power_translate_device_type (guint type);
+
+const gchar *xfpm_power_translate_technology (guint value);
+
+const gchar *xfpm_power_get_icon_name (guint device_type);
+
+#endif /* XFPM_UPOWER_COMMON */
diff --git a/src/xfpm-power-info.c b/src/xfpm-power-info.c
new file mode 100644
index 0000000..4f732c8
--- /dev/null
+++ b/src/xfpm-power-info.c
@@ -0,0 +1,986 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <signal.h>
+
+#include <gtk/gtk.h>
+#include <glib.h>
+
+#include <libxfce4util/libxfce4util.h>
+#include <libxfce4ui/libxfce4ui.h>
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "xfpm-icons.h"
+#include "xfpm-power-common.h"
+#include "xfpm-enum-glib.h"
+
+#include "xfpm-unique.h"
+
+typedef struct
+{
+ DBusGConnection *bus;
+
+ DBusGProxy *power_proxy;
+ DBusGProxy *wakeups_proxy;
+
+ GtkWidget *dialog;
+ GtkWidget *notebook;
+ GtkWidget *sideview; /*Sidebar tree view*/
+
+ GtkWidget *wakeups; /* Tree view processor wakeups*/
+
+} XfpmInfo;
+
+enum
+{
+ XFPM_DEVICE_INFO_NAME,
+ XFPM_DEVICE_INFO_VALUE,
+ XFPM_DEVICE_INFO_LAST
+};
+
+enum
+{
+ COL_SIDEBAR_ICON,
+ COL_SIDEBAR_NAME,
+ COL_SIDEBAR_INT,
+ NCOLS_SIDEBAR
+
+};
+
+enum
+{
+ COL_WAKEUPS_TYPE,
+ COL_WAKEUPS_PID,
+ COL_WAKEUPS_CMD,
+ COL_WAKEUPS_VALUE,
+ COL_WAKEUPS_DETAILS,
+ NCOLS_WAKEUPS
+};
+
+static void G_GNUC_NORETURN
+show_version (void)
+{
+ g_print (_("\n"
+ "Xfce Power Manager %s\n\n"
+ "Part of the Xfce Goodies Project\n"
+ "http://goodies.xfce.org\n\n"
+ "Licensed under the GNU GPL.\n\n"), VERSION);
+
+ exit (EXIT_SUCCESS);
+}
+
+
+/**
+ * Copyright (C) 2008 Richard Hughes <richard at hughsie.com>
+ * gpm_stats_format_cmdline:
+ **/
+static gchar *
+gpm_stats_format_cmdline (const gchar *command, gboolean is_userspace)
+{
+ gchar *found;
+ gchar *temp = NULL;
+ gchar *cmdline;
+ const gchar *temp_ptr;
+
+ /* nothing */
+ if (command == NULL) {
+ /* TRANSLATORS: the command line was not provided */
+ temp_ptr = _("No data");
+ goto out;
+ }
+
+ /* common kernel cmd names */
+ if (g_strcmp0 (command, "insmod") == 0) {
+ /* TRANSLATORS: kernel module, usually a device driver */
+ temp_ptr = _("Kernel module");
+ goto out;
+ }
+ if (g_strcmp0 (command, "modprobe") == 0) {
+ /* TRANSLATORS: kernel module, usually a device driver */
+ temp_ptr = _("Kernel module");
+ goto out;
+ }
+ if (g_strcmp0 (command, "swapper") == 0) {
+ /* TRANSLATORS: kernel housekeeping */
+ temp_ptr = _("Kernel core");
+ goto out;
+ }
+ if (g_strcmp0 (command, "kernel-ipi") == 0) {
+ /* TRANSLATORS: interrupt between processors */
+ temp_ptr = _("Interprocessor interrupt");
+ goto out;
+ }
+ if (g_strcmp0 (command, "interrupt") == 0) {
+ /* TRANSLATORS: unknown interrupt */
+ temp_ptr = _("Interrupt");
+ goto out;
+ }
+
+ /* truncate at first space or ':' */
+ temp = g_strdup (command);
+ found = strstr (temp, ":");
+ if (found != NULL)
+ *found = '\0';
+ found = strstr (temp, " ");
+ if (found != NULL)
+ *found = '\0';
+
+ /* remove path */
+ found = g_strrstr (temp, "/");
+ if (found != NULL && strncmp (temp, "event", 5) != 0)
+ temp_ptr = found + 1;
+ else
+ temp_ptr = temp;
+
+out:
+ /* format command line */
+ if (is_userspace)
+ cmdline = g_markup_escape_text (temp_ptr, -1);
+ else
+ cmdline = g_markup_printf_escaped ("<i>%s</i>", temp_ptr);
+ g_free (temp);
+
+ /* return */
+ return cmdline;
+}
+
+/**
+ * Copyright (C) 2008 Richard Hughes <richard at hughsie.com>
+ * gpm_stats_format_details:
+ **/
+static gchar *
+gpm_stats_format_details (const gchar *command_details)
+{
+ gchar *details;
+
+ /* replace common driver names */
+ if (g_strcmp0 (command_details, "i8042") == 0) {
+ /* TRANSLATORS: the keyboard and mouse device event */
+ details = g_strdup (_("PS/2 keyboard/mouse/touchpad"));
+ } else if (g_strcmp0 (command_details, "acpi") == 0) {
+ /* TRANSLATORS: ACPI, the Intel power standard on laptops and desktops */
+ details = g_strdup (_("ACPI"));
+ } else if (g_strcmp0 (command_details, "ata_piix") == 0) {
+ /* TRANSLATORS: serial ATA is a new style of hard disk interface */
+ details = g_strdup (_("Serial ATA"));
+ } else if (g_strcmp0 (command_details, "libata") == 0) {
+ /* TRANSLATORS: this is the old-style ATA interface */
+ details = g_strdup (_("ATA host controller"));
+ } else if (g_strcmp0 (command_details, "iwl3945") == 0 || g_strcmp0 (command_details, "iwlagn") == 0) {
+ /* TRANSLATORS: 802.11 wireless adaptor */
+ details = g_strdup (_("Intel wireless adaptor"));
+
+ /* try to make the wakeup type nicer */
+ } else if (g_str_has_prefix (command_details, "__mod_timer")) {
+ /* TRANSLATORS: a timer is something that fires periodically */
+ details = g_strdup_printf (_("Timer %s"), command_details+12);
+ } else if (g_str_has_prefix (command_details, "mod_timer")) {
+ /* TRANSLATORS: a timer is something that fires periodically */
+ details = g_strdup_printf (_("Timer %s"), command_details+10);
+ } else if (g_str_has_prefix (command_details, "hrtimer_start_expires")) {
+ /* TRANSLATORS: a timer is something that fires periodically */
+ details = g_strdup_printf (_("Timer %s"), command_details+22);
+ } else if (g_str_has_prefix (command_details, "hrtimer_start")) {
+ /* TRANSLATORS: a timer is something that fires periodically */
+ details = g_strdup_printf (_("Timer %s"), command_details+14);
+ } else if (g_str_has_prefix (command_details, "do_setitimer")) {
+ /* TRANSLATORS: a timer is something that fires periodically */
+ details = g_strdup_printf (_("Timer %s"), command_details+10);
+ } else if (g_str_has_prefix (command_details, "do_nanosleep")) {
+ /* TRANSLATORS: this is a task that's woken up from sleeping */
+ details = g_strdup_printf (_("Sleep %s"), command_details+13);
+ } else if (g_str_has_prefix (command_details, "enqueue_task_rt")) {
+ /* TRANSLATORS: this is a new realtime task */
+ details = g_strdup_printf (_("New task %s"), command_details+16);
+ } else if (g_str_has_prefix (command_details, "futex_wait")) {
+ /* TRANSLATORS: this is a task thats woken to check state */
+ details = g_strdup_printf (_("Wait %s"), command_details+11);
+ } else if (g_str_has_prefix (command_details, "queue_delayed_work_on")) {
+ /* TRANSLATORS: a work queue is a list of work that has to be done */
+ details = g_strdup_printf (_("Work queue %s"), command_details+22);
+ } else if (g_str_has_prefix (command_details, "queue_delayed_work")) {
+ /* TRANSLATORS: a work queue is a list of work that has to be done */
+ details = g_strdup_printf (_("Work queue %s"), command_details+19);
+ } else if (g_str_has_prefix (command_details, "dst_run_gc")) {
+ /* TRANSLATORS: this is when the networking subsystem clears out old entries */
+ details = g_strdup_printf (_("Network route flush %s"), command_details+11);
+ } else if (g_str_has_prefix (command_details, "usb_hcd_poll_rh_status")) {
+ /* TRANSLATORS: activity on the USB bus */
+ details = g_strdup_printf (_("USB activity %s"), command_details+23);
+ } else if (g_str_has_prefix (command_details, "schedule_hrtimeout_range")) {
+ /* TRANSLATORS: we've timed out of an aligned timer */
+ details = g_strdup_printf (_("Wakeup %s"), command_details+25);
+ } else if (g_str_has_prefix (command_details, "Local timer interrupts")) {
+ /* TRANSLATORS: interupts on the system required for basic operation */
+ details = g_strdup (_("Local interrupts"));
+ } else if (g_str_has_prefix (command_details, "Rescheduling interrupts")) {
+ /* TRANSLATORS: interrupts when a task gets moved from one core to another */
+ details = g_strdup (_("Rescheduling interrupts"));
+ } else
+ details = g_markup_escape_text (command_details, -1);
+
+ return details;
+}
+
+static gchar *
+xfpm_info_get_energy_property (GHashTable *props, const gchar *prop, const gchar *unit)
+{
+ GValue *value;
+ gchar *val = NULL;
+ gdouble energy;
+
+ value = g_hash_table_lookup (props, prop);
+
+ if ( !value )
+ return NULL;
+
+ energy = g_value_get_double (value);
+
+ val = g_strdup_printf ("%.1f %s", energy, unit);
+
+ return val;
+}
+
+static void
+xfpm_info_add_sidebar_icon (XfpmInfo *info, const gchar *name, const gchar *icon_name)
+{
+ GtkListStore *list_store;
+ GtkTreeIter iter;
+ GdkPixbuf *pix;
+ guint nt;
+
+ list_store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (info->sideview)));
+
+ nt = gtk_notebook_get_n_pages (GTK_NOTEBOOK (info->notebook));
+
+ pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ icon_name,
+ 48,
+ GTK_ICON_LOOKUP_USE_BUILTIN,
+ NULL);
+
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ COL_SIDEBAR_ICON, pix,
+ COL_SIDEBAR_NAME, name,
+ COL_SIDEBAR_INT, nt,
+ -1);
+
+ if ( pix )
+ g_object_unref (pix);
+}
+
+static void
+xfpm_info_add_device_view (XfpmInfo *info, GHashTable *props, const gchar *object_path)
+{
+ GtkWidget *view;
+
+ GtkListStore *list_store;
+ GtkTreeIter iter;
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *renderer;
+ GValue *value;
+ const gchar *cstr;
+ gchar *str;
+ gint i = 0;
+ guint type = 0;
+ const gchar *battery_type = NULL;
+
+ view = gtk_tree_view_new ();
+
+ list_store = gtk_list_store_new (XFPM_DEVICE_INFO_LAST, G_TYPE_STRING, G_TYPE_STRING);
+
+ gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (list_store));
+
+ renderer = gtk_cell_renderer_text_new ();
+
+ /*Device Attribute*/
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "text", XFPM_DEVICE_INFO_NAME, NULL);
+ gtk_tree_view_column_set_title (col, _("Attribute"));
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
+
+ /*Device Attribute Value*/
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "text", XFPM_DEVICE_INFO_VALUE, NULL);
+ gtk_tree_view_column_set_title (col, _("Value"));
+
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
+
+ /**
+ * Add Device information:
+ **/
+ /*Device*/
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ XFPM_DEVICE_INFO_NAME, _("Device"),
+ XFPM_DEVICE_INFO_VALUE, g_str_has_prefix (object_path, DKP_PATH_DEVICE) ? object_path + strlen (DKP_PATH_DEVICE) : object_path,
+ -1);
+ i++;
+
+
+ /*Type*/
+ value = g_hash_table_lookup (props, "Type");
+
+ if ( value )
+ {
+ type = g_value_get_uint (value);
+ battery_type = xfpm_power_translate_device_type (type);
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ XFPM_DEVICE_INFO_NAME, _("Type"),
+ XFPM_DEVICE_INFO_VALUE, battery_type,
+ -1);
+ i++;
+ }
+
+ value = g_hash_table_lookup (props, "PowerSupply");
+
+ if ( value )
+ {
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ XFPM_DEVICE_INFO_NAME, _("PowerSupply"),
+ XFPM_DEVICE_INFO_VALUE, g_value_get_boolean (value) == TRUE ? _("True") : _("False"),
+ -1);
+ i++;
+ }
+
+ if ( type != XFPM_DKP_DEVICE_TYPE_LINE_POWER )
+ {
+ /*Model*/
+ value = g_hash_table_lookup (props, "Model");
+
+ if ( value )
+ {
+ cstr = g_value_get_string (value);
+ if ( cstr && strlen (cstr) > 0)
+ {
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ XFPM_DEVICE_INFO_NAME, _("Model"),
+ XFPM_DEVICE_INFO_VALUE, g_value_get_string (value),
+ -1);
+ i++;
+ }
+ }
+
+ /*Technology*/
+ value = g_hash_table_lookup (props, "Technology");
+
+ if ( value )
+ {
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ XFPM_DEVICE_INFO_NAME, _("Technology"),
+ XFPM_DEVICE_INFO_VALUE, xfpm_power_translate_technology (g_value_get_uint (value)),
+ -1);
+ i++;
+ }
+
+ /* TRANSLATORS: Unit here is What hour*/
+ str = xfpm_info_get_energy_property (props, "EnergyFullDesign", _("Wh"));
+
+ if ( str )
+ {
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ XFPM_DEVICE_INFO_NAME, _("Energy full design"),
+ XFPM_DEVICE_INFO_VALUE, str,
+ -1);
+ i++;
+ g_free (str);
+ }
+
+ /* TRANSLATORS: Unit here is What hour*/
+ str = xfpm_info_get_energy_property (props, "EnergyFull", _("Wh"));
+
+ if ( str )
+ {
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ XFPM_DEVICE_INFO_NAME, _("Energy full"),
+ XFPM_DEVICE_INFO_VALUE, str,
+ -1);
+ i++;
+ g_free (str);
+ }
+
+ /* TRANSLATORS: Unit here is What hour*/
+ str = xfpm_info_get_energy_property (props, "EnergyEmpty", _("Wh"));
+
+ if ( str )
+ {
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ XFPM_DEVICE_INFO_NAME, _("Energy empty"),
+ XFPM_DEVICE_INFO_VALUE, str,
+ -1);
+ i++;
+ g_free (str);
+ }
+
+ /* TRANSLATORS: Unit here is volt*/
+ str = xfpm_info_get_energy_property (props, "Voltage", _("V"));
+ if ( str )
+ {
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ XFPM_DEVICE_INFO_NAME, _("Voltage"),
+ XFPM_DEVICE_INFO_VALUE, str,
+ -1);
+ i++;
+ g_free (str);
+ }
+
+ /*Vendor*/
+ value = g_hash_table_lookup (props, "Vendor");
+
+ if ( value )
+ {
+ cstr = g_value_get_string (value);
+ if ( cstr && strlen (cstr) > 0)
+ {
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ XFPM_DEVICE_INFO_NAME, _("Vendor"),
+ XFPM_DEVICE_INFO_VALUE, g_value_get_string (value),
+ -1);
+ i++;
+ }
+ }
+
+ /*Serial*/
+ value = g_hash_table_lookup (props, "Serial");
+
+ if ( value )
+ {
+ cstr = g_value_get_string (value);
+ if ( cstr && strlen (cstr) > 0)
+ {
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ XFPM_DEVICE_INFO_NAME, _("Serial"),
+ XFPM_DEVICE_INFO_VALUE, g_value_get_string (value),
+ -1);
+ i++;
+ }
+ }
+ }
+
+ xfpm_info_add_sidebar_icon (info, battery_type, xfpm_power_get_icon_name (type));
+
+ gtk_notebook_append_page (GTK_NOTEBOOK (info->notebook), view, NULL);
+ gtk_widget_show (view);
+}
+
+static void
+xfpm_info_add_device (XfpmInfo *info, const gchar *object_path)
+{
+ DBusGProxy *proxy_prop;
+ GHashTable *props;
+
+ proxy_prop = dbus_g_proxy_new_for_name (info->bus,
+ DKP_NAME,
+ object_path,
+ DBUS_INTERFACE_PROPERTIES);
+
+ if ( !proxy_prop )
+ {
+ g_warning ("Unable to create proxy for : %s", object_path);
+ return;
+ }
+
+ props = xfpm_power_get_interface_properties (proxy_prop, DKP_IFACE_DEVICE);
+
+ if ( props )
+ {
+ xfpm_info_add_device_view (info, props, object_path);
+ g_hash_table_destroy (props);
+ }
+}
+
+static void
+xfpm_info_power_devices (XfpmInfo *info)
+{
+ GPtrArray *array = NULL;
+ guint i;
+
+ info->power_proxy = dbus_g_proxy_new_for_name (info->bus,
+ DKP_NAME,
+ DKP_PATH,
+ DKP_IFACE);
+
+ if ( !info->power_proxy )
+ {
+ g_warning ("Unable to create proxy for : %s", DKP_NAME);
+ return;
+ }
+
+ array = xfpm_power_enumerate_devices (info->power_proxy);
+
+ if ( array )
+ {
+ for ( i = 0; i < array->len; i++)
+ {
+ const gchar *object_path = ( const gchar *) g_ptr_array_index (array, i);
+ xfpm_info_add_device (info, object_path);
+ }
+ g_ptr_array_free (array, TRUE);
+ }
+}
+
+
+/**
+ *
+ * Method GetData on /org/freedesktop/DeviceKit/Power/Wakeups
+ *
+ * <method name="GetData">
+ * <arg name="data" type="a(budss)" direction="out"/> (1)
+ * </method>
+ * (1): array | boolean Wheter the proceess on userspace
+ * | uint PID
+ * | double Wakeups value
+ * | string command line
+ * | string details
+ **/
+static void
+xfpm_info_update_wakeups (XfpmInfo *info)
+{
+ GtkListStore *store;
+
+ GError *error = NULL;
+
+ GType collection_type;
+ GType struct_type;
+
+ GPtrArray *array = NULL;
+
+ gboolean ret;
+ guint i;
+
+ struct_type = dbus_g_type_get_struct ("GValueArray",
+ G_TYPE_BOOLEAN,
+ G_TYPE_UINT,
+ G_TYPE_DOUBLE,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_INVALID);
+
+ collection_type = dbus_g_type_get_collection ("GPtrArray", struct_type);
+
+ ret = dbus_g_proxy_call (info->wakeups_proxy, "GetData", &error,
+ G_TYPE_INVALID,
+ collection_type, &array,
+ NULL);
+
+ if ( !ret )
+ {
+ g_warning ("GetData Failed on %s : %s", DKP_PATH_WAKEUPS, error->message);
+ g_error_free (error);
+ return;
+ }
+
+ store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (info->wakeups)));
+
+ gtk_list_store_clear (GTK_LIST_STORE (store));
+
+ for ( i = 0; i < array->len; i++ )
+ {
+ GValue elem = { 0 };
+ GtkTreeIter iter;
+
+ gboolean userspace;
+ guint pid;
+ gdouble value;
+ gchar *cmd;
+ gchar *formatted_cmd;
+ gchar *details;
+ gchar *formatted_details;
+ gchar *pid_str;
+ gchar *value_str;
+ const gchar *icon;
+
+ g_value_init (&elem, struct_type);
+ g_value_set_static_boxed (&elem, g_ptr_array_index (array, i));
+
+ dbus_g_type_struct_get (&elem,
+ 0, &userspace,
+ 1, &pid,
+ 2, &value,
+ 3, &cmd,
+ 4, &details,
+ G_MAXUINT);
+
+ if ( userspace )
+ {
+ pid_str = g_strdup_printf ("%i", pid);
+ }
+ else
+ {
+ if ( pid < 0xff0 )
+ {
+ pid_str = g_strdup_printf ("IRQ%i", pid);
+ }
+ else
+ {
+ pid_str = g_strdup("IRQx");
+ }
+ }
+ value_str = g_strdup_printf ("%.1f", value);
+
+ icon = userspace ? "application-x-executable" : "applications-system";
+
+ formatted_cmd = gpm_stats_format_cmdline (cmd, userspace);
+ formatted_details = gpm_stats_format_details (details);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COL_WAKEUPS_TYPE, icon,
+ COL_WAKEUPS_PID, pid_str,
+ COL_WAKEUPS_VALUE, value_str,
+ COL_WAKEUPS_CMD, formatted_cmd,
+ COL_WAKEUPS_DETAILS, formatted_details,
+ -1);
+
+ g_free (cmd);
+ g_free (details);
+ g_free (formatted_cmd);
+ g_free (formatted_details);
+
+ g_value_unset (&elem);
+ }
+
+ g_ptr_array_free (array, TRUE);
+}
+
+static gboolean
+xfpm_info_update_wakeups_idle (gpointer data)
+{
+ XfpmInfo *info;
+
+ info = (XfpmInfo*)data;
+
+ if ( GTK_WIDGET_VISIBLE (info->wakeups) )
+ xfpm_info_update_wakeups (info);
+
+ return TRUE;
+}
+
+static void
+xfpm_info_cpu_wakeups (XfpmInfo *info)
+{
+ GtkWidget *vbox;
+ GtkWidget *scrolled;
+ GtkListStore *list_store;
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *renderer;
+
+ info->wakeups_proxy = dbus_g_proxy_new_for_name (info->bus,
+ DKP_NAME,
+ DKP_PATH_WAKEUPS,
+ DKP_IFACE_WAKEUPS);
+
+ if ( !info->wakeups_proxy )
+ {
+ g_warning ("Unable to create proxy for %s", DKP_PATH_WAKEUPS);
+ return;
+ }
+
+ list_store = gtk_list_store_new (NCOLS_WAKEUPS,
+ G_TYPE_STRING, /*type*/
+ G_TYPE_STRING, /*pid*/
+ G_TYPE_STRING, /*value*/
+ G_TYPE_STRING, /*command*/
+ G_TYPE_STRING); /*details*/
+
+ info->wakeups = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
+
+ xfpm_info_add_sidebar_icon (info, _("Processor"), XFPM_PROCESSOR_ICON);
+
+ col = gtk_tree_view_column_new ();
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ g_object_set (G_OBJECT (renderer), "stock-size", GTK_ICON_SIZE_BUTTON, NULL);
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "icon-name", COL_WAKEUPS_TYPE, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (info->wakeups), col);
+ gtk_tree_view_column_set_title (col, _("Type"));
+
+ renderer = gtk_cell_renderer_text_new ();
+
+ col = gtk_tree_view_column_new ();
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "text", COL_WAKEUPS_PID, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (info->wakeups), col);
+ /* TANSLATORS: PID, is the process id, e.g what ps x gives*/
+ gtk_tree_view_column_set_title (col, _("PID"));
+
+ col = gtk_tree_view_column_new ();
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "markup", COL_WAKEUPS_VALUE, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (info->wakeups), col);
+ gtk_tree_view_column_set_title (col, _("Wakeups"));
+
+ col = gtk_tree_view_column_new ();
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "markup", COL_WAKEUPS_CMD, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (info->wakeups), col);
+ gtk_tree_view_column_set_title (col, _("Command"));
+
+ col = gtk_tree_view_column_new ();
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "markup", COL_WAKEUPS_DETAILS, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (info->wakeups), col);
+ gtk_tree_view_column_set_title (col, _("Details"));
+
+ vbox = gtk_vbox_new (FALSE, 4);
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_NEVER,
+ GTK_POLICY_AUTOMATIC);
+ gtk_container_add (GTK_CONTAINER (scrolled), info->wakeups);
+
+ gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 0);
+ gtk_notebook_append_page (GTK_NOTEBOOK (info->notebook), vbox, NULL);
+
+ xfpm_info_update_wakeups (info);
+
+ g_timeout_add_seconds (4, (GSourceFunc) xfpm_info_update_wakeups_idle, info);
+
+ gtk_widget_show (vbox);
+}
+
+static void
+view_cursor_changed_cb (GtkTreeView *view, XfpmInfo *info)
+{
+ GtkTreeSelection *sel;
+ GtkTreeModel *model;
+ GtkTreeIter selected_row;
+ gint int_data = 0;
+
+ sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+
+ if ( !gtk_tree_selection_get_selected (sel, &model, &selected_row))
+ return;
+
+ gtk_tree_model_get(model,
+ &selected_row,
+ COL_SIDEBAR_INT,
+ &int_data,
+ -1);
+
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (info->notebook), int_data);
+}
+
+static void
+xfpm_info_create (XfpmInfo *info)
+{
+ GtkWidget *content_area;
+ GtkWidget *hbox;
+ GtkWidget *viewport;
+ GtkListStore *list_store;
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *renderer;
+
+ info->dialog = xfce_titled_dialog_new_with_buttons (_("Power Information"),
+ NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+ NULL);
+
+ gtk_window_set_default_size (GTK_WINDOW (info->dialog), -1, 400);
+
+ gtk_window_set_icon_name (GTK_WINDOW (info->dialog), GTK_STOCK_INFO);
+
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (info->dialog));
+
+ hbox = gtk_hbox_new (FALSE, 4);
+
+ gtk_container_add (GTK_CONTAINER (content_area), hbox);
+
+ viewport = gtk_viewport_new (NULL, NULL);
+ info->sideview = gtk_tree_view_new ();
+ list_store = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT);
+
+ gtk_tree_view_set_model (GTK_TREE_VIEW (info->sideview), GTK_TREE_MODEL (list_store));
+
+ gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (info->sideview),TRUE);
+ col = gtk_tree_view_column_new ();
+
+ renderer = gtk_cell_renderer_pixbuf_new ();
+
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "pixbuf", 0, NULL);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "markup", 1, NULL);
+
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (info->sideview), FALSE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (info->sideview), col);
+
+ g_signal_connect (info->sideview, "cursor-changed",
+ G_CALLBACK (view_cursor_changed_cb), info);
+
+ gtk_container_add (GTK_CONTAINER (viewport), info->sideview);
+
+ gtk_box_pack_start (GTK_BOX (hbox), viewport, FALSE, FALSE, 0);
+
+ info->notebook = gtk_notebook_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), info->notebook, TRUE, TRUE, 0);
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK (info->notebook), FALSE);
+
+ /*Show power devices information, AC adapter, batteries*/
+ xfpm_info_power_devices (info);
+
+ /*Sow CPU wakeups*/
+ xfpm_info_cpu_wakeups (info);
+
+ g_object_set (G_OBJECT (hbox),
+ "border-width", 4,
+ NULL);
+
+ gtk_widget_show_all (hbox);
+}
+
+static void
+xfpm_info_connect (XfpmInfo *info)
+{
+ GError *error = NULL;
+
+ info->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+
+ if ( error )
+ {
+ xfce_dialog_show_error (NULL,
+ error,
+ NULL);
+ g_error ("Cannot connect to system bus : %s", error->message);
+ }
+}
+
+static XfpmInfo *
+xfpm_info_new (void)
+{
+ XfpmInfo *info;
+
+ info = g_new0 (XfpmInfo, 1);
+
+ info->bus = NULL;
+ info->power_proxy = NULL;
+ info->wakeups_proxy = NULL;
+ info->dialog = NULL;
+
+ return info;
+}
+
+static void
+xfpm_info_free (XfpmInfo *info)
+{
+ if ( info->bus )
+ dbus_g_connection_unref (info->bus);
+
+ if ( info->power_proxy )
+ g_object_unref (info->power_proxy);
+
+ if ( info->wakeups_proxy )
+ g_object_unref (info->wakeups_proxy);
+
+ g_free (info);
+}
+
+int main (int argc, char **argv)
+{
+ XfpmInfo *info;
+ XfpmUnique *unique;
+
+ GError *error = NULL;
+ gboolean version = FALSE;
+
+ GOptionEntry option_entries[] =
+ {
+ { "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version, N_("Version information"), NULL },
+ { NULL, },
+ };
+
+ xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
+
+ g_set_application_name (PACKAGE_NAME);
+
+ if (!gtk_init_with_args (&argc, &argv, (gchar *)"", option_entries, (gchar *)PACKAGE, &error))
+ {
+ if (G_LIKELY (error))
+ {
+ g_printerr ("%s: %s.\n", G_LOG_DOMAIN, error->message);
+ g_printerr (_("Type '%s --help' for usage."), G_LOG_DOMAIN);
+ g_printerr ("\n");
+ g_error_free (error);
+ }
+ else
+ {
+ g_error ("Unable to open display.");
+ }
+
+ return EXIT_FAILURE;
+ }
+
+ if ( version )
+ {
+ show_version ();
+ }
+
+
+ unique = xfpm_unique_new ("org.Xfce.PowerManager.Info");
+
+ if ( !xfpm_unique_app_is_running (unique ) )
+ {
+ info = xfpm_info_new ();
+ xfpm_info_connect (info);
+ xfpm_info_create (info);
+
+ g_signal_connect_swapped (unique, "ping-received",
+ G_CALLBACK (gtk_window_present), info->dialog);
+
+ gtk_dialog_run (GTK_DIALOG (info->dialog));
+
+ gtk_widget_destroy (info->dialog);
+
+ xfpm_info_free (info);
+ }
+
+ g_object_unref (unique);
+
+ return EXIT_SUCCESS;
+}
More information about the Xfce4-commits
mailing list