[gnome-power-manager] Allow GNOME Power Manager to use the symbolic icons present in some themes
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-power-manager] Allow GNOME Power Manager to use the symbolic icons present in some themes
- Date: Wed, 31 Mar 2010 18:21:02 +0000 (UTC)
commit 83ada8cd71ca7951799d5f42ec7a125d0053a3e9
Author: Richard Hughes <richard hughsie com>
Date: Wed Mar 31 19:20:54 2010 +0100
Allow GNOME Power Manager to use the symbolic icons present in some themes
src/gpm-engine.c | 6 ++--
src/gpm-manager.c | 8 +++---
src/gpm-statistics.c | 2 +-
src/gpm-tray-icon.c | 2 +-
src/gpm-upower.c | 53 +++++++++++++++++++++++++++----------------------
src/gpm-upower.h | 3 +-
6 files changed, 40 insertions(+), 34 deletions(-)
---
diff --git a/src/gpm-engine.c b/src/gpm-engine.c
index d221ed7..f9e628a 100644
--- a/src/gpm-engine.c
+++ b/src/gpm-engine.c
@@ -302,15 +302,15 @@ gpm_engine_get_icon_priv (GpmEngine *engine, UpDeviceKind device_kind, GpmEngine
if (kind == device_kind && is_present) {
if (warning != GPM_ENGINE_WARNING_NONE) {
if (warning_temp == warning)
- return gpm_upower_get_device_icon (device);
+ return gpm_upower_get_device_icon (device, TRUE);
continue;
}
if (use_state) {
if (state == UP_DEVICE_STATE_CHARGING || state == UP_DEVICE_STATE_DISCHARGING)
- return gpm_upower_get_device_icon (device);
+ return gpm_upower_get_device_icon (device, TRUE);
continue;
}
- return gpm_upower_get_device_icon (device);
+ return gpm_upower_get_device_icon (device, TRUE);
}
}
return NULL;
diff --git a/src/gpm-manager.c b/src/gpm-manager.c
index 667c9ae..a9b7ef9 100644
--- a/src/gpm-manager.c
+++ b/src/gpm-manager.c
@@ -1427,7 +1427,7 @@ gpm_manager_engine_discharging_cb (GpmEngine *engine, UpDevice *device, GpmManag
goto out;
}
- icon = gpm_upower_get_device_icon (device);
+ icon = gpm_upower_get_device_icon (device, TRUE);
/* show the notification */
gpm_manager_notify (manager, &manager->priv->notification_discharging, title, message, GPM_MANAGER_NOTIFY_TIMEOUT_LONG,
gpm_manager_get_icon_name (icon), NOTIFY_URGENCY_NORMAL);
@@ -1550,7 +1550,7 @@ gpm_manager_engine_charge_low_cb (GpmEngine *engine, UpDevice *device, GpmManage
}
/* get correct icon */
- icon = gpm_upower_get_device_icon (device);
+ icon = gpm_upower_get_device_icon (device, TRUE);
gpm_manager_notify (manager, &manager->priv->notification_warning_low, title, message,
GPM_MANAGER_NOTIFY_TIMEOUT_LONG, gpm_manager_get_icon_name (icon), NOTIFY_URGENCY_NORMAL);
gpm_manager_play (manager, GPM_MANAGER_SOUND_BATTERY_CAUTION, TRUE);
@@ -1675,7 +1675,7 @@ gpm_manager_engine_charge_critical_cb (GpmEngine *engine, UpDevice *device, GpmM
}
/* get correct icon */
- icon = gpm_upower_get_device_icon (device);
+ icon = gpm_upower_get_device_icon (device, TRUE);
gpm_manager_notify (manager, &manager->priv->notification_warning_low, title, message,
GPM_MANAGER_NOTIFY_TIMEOUT_NEVER, gpm_manager_get_icon_name (icon), NOTIFY_URGENCY_CRITICAL);
@@ -1801,7 +1801,7 @@ gpm_manager_engine_charge_action_cb (GpmEngine *engine, UpDevice *device, GpmMan
return;
/* get correct icon */
- icon = gpm_upower_get_device_icon (device);
+ icon = gpm_upower_get_device_icon (device, TRUE);
gpm_manager_notify (manager, &manager->priv->notification_warning_low,
title, message, GPM_MANAGER_NOTIFY_TIMEOUT_NEVER,
gpm_manager_get_icon_name (icon), NOTIFY_URGENCY_CRITICAL);
diff --git a/src/gpm-statistics.c b/src/gpm-statistics.c
index 2023b5e..623d8c1 100644
--- a/src/gpm-statistics.c
+++ b/src/gpm-statistics.c
@@ -1156,7 +1156,7 @@ gpm_stats_add_device (UpDevice *device)
id = up_device_get_object_path (device);
text = gpm_device_kind_to_localised_string (kind, 1);
- icon = gpm_upower_get_device_icon (device);
+ icon = gpm_upower_get_device_icon (device, FALSE);
gtk_list_store_append (list_store_devices, &iter);
gtk_list_store_set (list_store_devices, &iter,
diff --git a/src/gpm-tray-icon.c b/src/gpm-tray-icon.c
index 6e783ac..4e83533 100644
--- a/src/gpm-tray-icon.c
+++ b/src/gpm-tray-icon.c
@@ -249,7 +249,7 @@ gpm_tray_icon_add_device (GpmTrayIcon *icon, GtkMenu *menu, const GPtrArray *arr
gtk_box_pack_start (GTK_BOX (hbox), label_percentage, FALSE, FALSE, 3);
/* generate the image */
- gicon = gpm_upower_get_device_icon (device);
+ gicon = gpm_upower_get_device_icon (device, TRUE);
image = gtk_image_new_from_gicon (gicon, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
diff --git a/src/gpm-upower.c b/src/gpm-upower.c
index 8c00102..bd1d74c 100644
--- a/src/gpm-upower.c
+++ b/src/gpm-upower.c
@@ -73,9 +73,9 @@ gpm_upower_get_device_icon_index (UpDevice *device)
*
**/
GIcon *
-gpm_upower_get_device_icon (UpDevice *device)
+gpm_upower_get_device_icon (UpDevice *device, gboolean use_symbolic)
{
- gchar *filename = NULL;
+ GString *filename;
const gchar *prefix = NULL;
const gchar *index_str;
UpDeviceKind kind;
@@ -95,58 +95,59 @@ gpm_upower_get_device_icon (UpDevice *device)
NULL);
/* get correct icon prefix */
+ filename = g_string_new (NULL);
prefix = up_device_kind_to_string (kind);
/* get the icon from some simple rules */
if (kind == UP_DEVICE_KIND_LINE_POWER) {
- filename = g_strdup ("ac-adapter");
+ g_string_append (filename, "ac-adapter");
} else if (kind == UP_DEVICE_KIND_MONITOR) {
- filename = g_strdup ("gpm-monitor");
+ g_string_append (filename, "gpm-monitor");
} else if (kind == UP_DEVICE_KIND_UPS) {
if (!is_present) {
/* battery missing */
- filename = g_strdup_printf ("gpm-%s-missing", prefix);
+ g_string_append_printf (filename, "gpm-%s-missing", prefix);
} else if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
- filename = g_strdup_printf ("gpm-%s-100", prefix);
+ g_string_append_printf (filename, "gpm-%s-100", prefix);
} else if (state == UP_DEVICE_STATE_CHARGING) {
index_str = gpm_upower_get_device_icon_index (device);
- filename = g_strdup_printf ("gpm-%s-%s-charging", prefix, index_str);
+ g_string_append_printf (filename, "gpm-%s-%s-charging", prefix, index_str);
} else if (state == UP_DEVICE_STATE_DISCHARGING) {
index_str = gpm_upower_get_device_icon_index (device);
- filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
+ g_string_append_printf (filename, "gpm-%s-%s", prefix, index_str);
}
} else if (kind == UP_DEVICE_KIND_BATTERY) {
if (!is_present) {
/* battery missing */
- filename = g_strdup_printf ("gpm-%s-missing", prefix);
+ g_string_append_printf (filename, "gpm-%s-missing", prefix);
} else if (state == UP_DEVICE_STATE_EMPTY) {
- filename = g_strdup_printf ("gpm-%s-empty", prefix);
+ g_string_append_printf (filename, "gpm-%s-empty", prefix);
} else if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
- filename = g_strdup_printf ("gpm-%s-charged", prefix);
+ g_string_append_printf (filename, "gpm-%s-charged", prefix);
} else if (state == UP_DEVICE_STATE_CHARGING) {
index_str = gpm_upower_get_device_icon_index (device);
- filename = g_strdup_printf ("gpm-%s-%s-charging", prefix, index_str);
+ g_string_append_printf (filename, "gpm-%s-%s-charging", prefix, index_str);
} else if (state == UP_DEVICE_STATE_DISCHARGING) {
index_str = gpm_upower_get_device_icon_index (device);
- filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
+ g_string_append_printf (filename, "gpm-%s-%s", prefix, index_str);
} else if (state == UP_DEVICE_STATE_PENDING_CHARGE) {
index_str = gpm_upower_get_device_icon_index (device);
/* FIXME: do new grey icons */
- filename = g_strdup_printf ("gpm-%s-%s-charging", prefix, index_str);
+ g_string_append_printf (filename, "gpm-%s-%s-charging", prefix, index_str);
} else if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) {
index_str = gpm_upower_get_device_icon_index (device);
- filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
+ g_string_append_printf (filename, "gpm-%s-%s", prefix, index_str);
} else {
- filename = g_strdup ("gpm-battery-missing");
+ g_string_append (filename, "gpm-battery-missing");
}
} else if (kind == UP_DEVICE_KIND_MOUSE ||
@@ -154,26 +155,30 @@ gpm_upower_get_device_icon (UpDevice *device)
kind == UP_DEVICE_KIND_PHONE) {
if (!is_present) {
/* battery missing */
- filename = g_strdup_printf ("gpm-%s-000", prefix);
+ g_string_append_printf (filename, "gpm-%s-000", prefix);
} else if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
- filename = g_strdup_printf ("gpm-%s-100", prefix);
+ g_string_append_printf (filename, "gpm-%s-100", prefix);
} else if (state == UP_DEVICE_STATE_DISCHARGING) {
index_str = gpm_upower_get_device_icon_index (device);
- filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
+ g_string_append_printf (filename, "gpm-%s-%s", prefix, index_str);
}
}
/* nothing matched */
- if (filename == NULL) {
+ if (filename->len == 0) {
egg_warning ("nothing matched, falling back to default icon");
- filename = g_strdup ("dialog-warning");
+ g_string_append (filename, "dialog-warning");
}
- egg_debug ("got filename: %s", filename);
- icon = g_themed_icon_new (filename);
- g_free (filename);
+ /* symbolic icon set */
+ if (use_symbolic)
+ g_string_append (filename, "-symbolic");
+
+ egg_debug ("got filename: %s", filename->str);
+ icon = g_themed_icon_new_with_default_fallbacks (filename->str);
+ g_string_free (filename, TRUE);
return icon;
}
diff --git a/src/gpm-upower.h b/src/gpm-upower.h
index 4bd70ed..7a01211 100644
--- a/src/gpm-upower.h
+++ b/src/gpm-upower.h
@@ -32,7 +32,8 @@ const gchar *gpm_device_kind_to_localised_string (UpDeviceKind kind,
const gchar *gpm_device_kind_to_icon (UpDeviceKind kind);
const gchar *gpm_device_technology_to_localised_string (UpDeviceTechnology technology_enum);
const gchar *gpm_device_state_to_localised_string (UpDeviceState state);
-GIcon *gpm_upower_get_device_icon (UpDevice *device);
+GIcon *gpm_upower_get_device_icon (UpDevice *device,
+ gboolean use_symbolic);
gchar *gpm_upower_get_device_summary (UpDevice *device);
gchar *gpm_upower_get_device_description (UpDevice *device);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]