[Xfce4-commits] [xfce/xfce4-power-manager] 04/63: More GTK3 work

noreply at xfce.org noreply at xfce.org
Sun Mar 22 13:01:59 CET 2015


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 80e4430ec4bca49fa748539ad53d29b12260db3d
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Mon Mar 2 10:06:45 2015 +0300

    More GTK3 work
    
    XfpmBattery was a GtkStatusIcon which has been dropped, so switch
    it to a normal GtkWidget. Other minor changes to support things
    removed from the Gtk toolkit.
---
 src/xfpm-backlight.c     |    3 +-
 src/xfpm-battery.c       |  123 ++++++----------------------------------------
 src/xfpm-battery.h       |   16 +++---
 src/xfpm-button.c        |    2 +-
 src/xfpm-kbd-backlight.c |    3 +-
 src/xfpm-notify.c        |   28 +++--------
 src/xfpm-notify.h        |    6 +--
 src/xfpm-power.c         |   61 +++++++++++++----------
 8 files changed, 69 insertions(+), 173 deletions(-)

diff --git a/src/xfpm-backlight.c b/src/xfpm-backlight.c
index 97a386f..5ce147a 100644
--- a/src/xfpm-backlight.c
+++ b/src/xfpm-backlight.c
@@ -164,8 +164,7 @@ xfpm_backlight_show_notification (XfpmBacklight *backlight, gfloat value)
 							   "",
 							   "xfpm-brightness-lcd",
 							   0,
-							   XFPM_NOTIFY_NORMAL,
-							   NULL);
+							   XFPM_NOTIFY_NORMAL);
     }
 
     /* generate a human-readable summary for the notification */
diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 7d95d49..1c9a3ba 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -97,7 +97,7 @@ enum
 
 static guint signals [LAST_SIGNAL] = { 0 };
 
-G_DEFINE_TYPE (XfpmBattery, xfpm_battery, GTK_TYPE_STATUS_ICON)
+G_DEFINE_TYPE (XfpmBattery, xfpm_battery, GTK_TYPE_WIDGET)
 
 
 static gchar *
@@ -182,67 +182,6 @@ xfpm_battery_get_message_from_battery_state (XfpmBattery *battery)
 }
 
 static void
-xfpm_battery_refresh_icon (XfpmBattery *battery)
-{
-    gchar icon_name[128];
-
-    XFPM_DEBUG ("Battery state %d", battery->priv->state);
-
-    if ( battery->priv->type == UP_DEVICE_KIND_BATTERY ||
-	 battery->priv->type == UP_DEVICE_KIND_UPS )
-    {
-	if (!battery->priv->present)
-	{
-	    g_snprintf (icon_name, 128, "%s%s", battery->priv->icon_prefix, "missing");
-	}
-	else if (battery->priv->state == UP_DEVICE_STATE_FULLY_CHARGED )
-	{
-	    g_snprintf (icon_name, 128, "%s%s", battery->priv->icon_prefix, battery->priv->ac_online ? "charged" : "100");
-	}
-	else if ( battery->priv->state == UP_DEVICE_STATE_CHARGING ||
-		  battery->priv->state == UP_DEVICE_STATE_PENDING_CHARGE)
-	{
-	    g_snprintf (icon_name, 128, "%s%s-%s",
-			battery->priv->icon_prefix,
-			xfpm_battery_get_icon_index (battery->priv->type, battery->priv->percentage),
-			"charging");
-	}
-	else if ( battery->priv->state == UP_DEVICE_STATE_DISCHARGING ||
-		  battery->priv->state == UP_DEVICE_STATE_PENDING_DISCHARGE)
-	{
-	    g_snprintf (icon_name, 128, "%s%s",
-			battery->priv->icon_prefix,
-			xfpm_battery_get_icon_index (battery->priv->type, battery->priv->percentage));
-	}
-	else if ( battery->priv->state == UP_DEVICE_STATE_EMPTY)
-	{
-	    g_snprintf (icon_name, 128, "%s%s", battery->priv->icon_prefix, battery->priv->ac_online ? "000-charging" : "000");
-	}
-    }
-    else
-    {
-	if ( !battery->priv->present || battery->priv->state == UP_DEVICE_STATE_EMPTY )
-	{
-	    g_snprintf (icon_name, 128, "%s000", battery->priv->icon_prefix);
-	}
-	else if ( battery->priv->state == UP_DEVICE_STATE_FULLY_CHARGED )
-	{
-	    g_snprintf (icon_name, 128, "%s100", battery->priv->icon_prefix);
-	}
-	else if ( battery->priv->state == UP_DEVICE_STATE_DISCHARGING || battery->priv->state == UP_DEVICE_STATE_CHARGING )
-	{
-	    g_snprintf (icon_name, 128, "%s%s",
-			battery->priv->icon_prefix,
-			xfpm_battery_get_icon_index (battery->priv->type, battery->priv->percentage));
-	}
-    }
-
-    XFPM_DEBUG ("Battery icon %s", icon_name);
-
-    gtk_status_icon_set_from_icon_name (GTK_STATUS_ICON (battery), icon_name);
-}
-
-static void
 xfpm_battery_notify (XfpmBattery *battery)
 {
     gchar *message = NULL;
@@ -255,11 +194,10 @@ xfpm_battery_notify (XfpmBattery *battery)
     xfpm_notify_show_notification (battery->priv->notify,
 				   _("Power Manager"),
 				   message,
-				   gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
+				   xfpm_battery_get_icon_name (battery),
 				   8000,
 				   FALSE,
-				   XFPM_NOTIFY_NORMAL,
-				   GTK_STATUS_ICON (battery));
+				   XFPM_NOTIFY_NORMAL);
 
     g_free (message);
 }
@@ -360,8 +298,6 @@ xfpm_battery_refresh (XfpmBattery *battery, UpDevice *device)
 
     xfpm_battery_check_charge (battery);
 
-    xfpm_battery_refresh_icon (battery);
-
     if ( battery->priv->type == UP_DEVICE_KIND_BATTERY ||
 	 battery->priv->type == UP_DEVICE_KIND_UPS )
     {
@@ -419,7 +355,6 @@ static void xfpm_battery_set_property (GObject *object,
     {
 	case PROP_AC_ONLINE:
 	    battery->priv->ac_online = g_value_get_boolean (value);
-	    xfpm_battery_refresh_icon (battery);
 	    break;
 	default:
 	    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -518,55 +453,17 @@ xfpm_battery_finalize (GObject *object)
     g_object_unref (battery->priv->notify);
     g_object_unref (battery->priv->button);
 
-    gtk_status_icon_set_visible(GTK_STATUS_ICON(battery), FALSE);
-
     G_OBJECT_CLASS (xfpm_battery_parent_class)->finalize (object);
 }
 
-static const gchar *
-xfpm_battery_get_name (UpDeviceKind type)
-{
-    const gchar *name = NULL;
-
-    switch (type)
-    {
-	case UP_DEVICE_KIND_BATTERY:
-	    name = _("battery");
-	    break;
-	case UP_DEVICE_KIND_UPS:
-	    name = _("UPS");
-	    break;
-	case UP_DEVICE_KIND_MONITOR:
-	    name = _("monitor battery");
-	    break;
-	case UP_DEVICE_KIND_MOUSE:
-	    name = _("mouse battery");
-	    break;
-	case UP_DEVICE_KIND_KEYBOARD:
-	    name = _("keyboard battery");
-	    break;
-	case UP_DEVICE_KIND_PDA:
-	    name = _("PDA battery");
-	    break;
-	case UP_DEVICE_KIND_PHONE:
-	    name = _("Phone battery");
-	    break;
-	default:
-	    name = _("Unknown");
-	    break;
-    }
-
-    return name;
-}
-
-GtkStatusIcon *
+GtkWidget *
 xfpm_battery_new (void)
 {
     XfpmBattery *battery = NULL;
 
     battery = g_object_new (XFPM_TYPE_BATTERY, NULL);
 
-    return GTK_STATUS_ICON (battery);
+    return GTK_WIDGET (battery);
 }
 
 void xfpm_battery_monitor_device (XfpmBattery *battery,
@@ -577,7 +474,7 @@ void xfpm_battery_monitor_device (XfpmBattery *battery,
     battery->priv->type = device_type;
     battery->priv->client = up_client_new();
     battery->priv->icon_prefix = xfpm_battery_get_icon_prefix_device_enum_type (device_type);
-    battery->priv->battery_name = xfpm_battery_get_name (device_type);
+    battery->priv->battery_name = xfpm_power_translate_device_type (device_type);
 
     device = up_device_new();
     up_device_set_object_path_sync (device, object_path, NULL, NULL);
@@ -621,3 +518,11 @@ gchar *xfpm_battery_get_time_left (XfpmBattery *battery)
 
     return xfpm_battery_get_time_string (battery->priv->time_to_empty);
 }
+
+const gchar*
+xfpm_battery_get_icon_name (XfpmBattery *battery)
+{
+    g_return_val_if_fail (XFPM_IS_BATTERY (battery), NULL);
+
+    return get_device_icon_name (battery->priv->client, battery->priv->device);
+}
diff --git a/src/xfpm-battery.h b/src/xfpm-battery.h
index 049e335..3039f6e 100644
--- a/src/xfpm-battery.h
+++ b/src/xfpm-battery.h
@@ -38,23 +38,23 @@ typedef struct XfpmBatteryPrivate XfpmBatteryPrivate;
 
 typedef struct
 {
-    GtkStatusIcon      	    parent;
-    
+    GtkWidget      	        parent;
+
     XfpmBatteryPrivate     *priv;
-    
+
 } XfpmBattery;
 
 typedef struct
 {
-    GtkStatusIconClass 	    parent_class;
-    
+    GtkWidgetClass 	    parent_class;
+
     void		    (*battery_charge_changed)	 (XfpmBattery *battery);
-    
+
 } XfpmBatteryClass;
 
 GType        		    xfpm_battery_get_type        (void) G_GNUC_CONST;
 
-GtkStatusIcon              *xfpm_battery_new             (void);
+GtkWidget              *xfpm_battery_new             (void);
 
 void			    xfpm_battery_monitor_device  (XfpmBattery *battery,
 							  const char *object_path,
@@ -68,6 +68,8 @@ const gchar 		   *xfpm_battery_get_battery_name(XfpmBattery *battery);
 
 gchar 			   *xfpm_battery_get_time_left   (XfpmBattery *battery);
 
+const gchar        *xfpm_battery_get_icon_name   (XfpmBattery *battery);
+
 G_END_DECLS
 
 #endif /* __XFPM_BATTERY_H */
diff --git a/src/xfpm-button.c b/src/xfpm-button.c
index d894d0d..3f8f966 100644
--- a/src/xfpm-button.c
+++ b/src/xfpm-button.c
@@ -158,7 +158,7 @@ xfpm_button_grab_keystring (XfpmButton *button, guint keycode)
     }
 
     gdk_flush ();
-    gdk_error_trap_pop ();
+    gdk_error_trap_pop_ignored ();
     return TRUE;
 }
 
diff --git a/src/xfpm-kbd-backlight.c b/src/xfpm-kbd-backlight.c
index 7e1886b..83ebbc0 100644
--- a/src/xfpm-kbd-backlight.c
+++ b/src/xfpm-kbd-backlight.c
@@ -107,8 +107,7 @@ xfpm_kbd_backlight_show_notification (XfpmKbdBacklight *self, gfloat value)
                 "",
                 "xfpm-brightness-keyboard",
                 0,
-                XFPM_NOTIFY_NORMAL,
-                NULL);
+                XFPM_NOTIFY_NORMAL);
     }
 
     /* generate a human-readable summary for the notification */
diff --git a/src/xfpm-notify.c b/src/xfpm-notify.c
index e4fd548..19e4c5a 100644
--- a/src/xfpm-notify.c
+++ b/src/xfpm-notify.c
@@ -52,8 +52,7 @@ static NotifyNotification * xfpm_notify_new_notification_internal (const gchar *
 								   const gchar *message, 
 								   const gchar *icon_name, 
 								   guint timeout, 
-								   XfpmNotifyUrgency urgency, 
-								   GtkStatusIcon *icon) G_GNUC_MALLOC;
+								   XfpmNotifyUrgency urgency) G_GNUC_MALLOC;
 
 #define XFPM_NOTIFY_GET_PRIVATE(o) \
 (G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_NOTIFY, XfpmNotifyPrivate))
@@ -211,7 +210,7 @@ xfpm_notify_set_notification_icon (NotifyNotification *n, const gchar *icon_name
 static NotifyNotification *
 xfpm_notify_new_notification_internal (const gchar *title, const gchar *message,
 				       const gchar *icon_name, guint timeout,
-				       XfpmNotifyUrgency urgency, GtkStatusIcon *icon)
+				       XfpmNotifyUrgency urgency)
 {
     NotifyNotification *n;
     
@@ -229,16 +228,6 @@ xfpm_notify_new_notification_internal (const gchar *title, const gchar *message,
     if ( icon_name )
     	xfpm_notify_set_notification_icon (n, icon_name);
 
-#ifdef NOTIFY_CHECK_VERSION
-#if !NOTIFY_CHECK_VERSION (0, 7, 0) 
-    if ( icon )
-    	notify_notification_attach_to_status_icon (n, icon);
-#endif
-#else
-     if ( icon )
-     	notify_notification_attach_to_status_icon (n, icon);
-#endif
-	
     notify_notification_set_urgency (n, (NotifyUrgency)urgency);
     
     if ( timeout != 0)
@@ -307,7 +296,7 @@ xfpm_notify_new (void)
 void xfpm_notify_show_notification (XfpmNotify *notify, const gchar *title,
 				    const gchar *text,  const gchar *icon_name,
 				    gint timeout, gboolean simple,
-				    XfpmNotifyUrgency urgency, GtkStatusIcon *icon)
+				    XfpmNotifyUrgency urgency)
 {
     NotifyNotification *n;
     
@@ -316,9 +305,8 @@ void xfpm_notify_show_notification (XfpmNotify *notify, const gchar *title,
     
     n = xfpm_notify_new_notification_internal (title, 
 				               text, icon_name, 
-					       timeout, urgency, 
-					       icon);
-					       
+					       timeout, urgency);
+
     xfpm_notify_present_notification (notify, n, simple);
 }
 
@@ -327,13 +315,11 @@ NotifyNotification *xfpm_notify_new_notification (XfpmNotify *notify,
 						  const gchar *text,
 						  const gchar *icon_name,
 						  guint timeout,
-						  XfpmNotifyUrgency urgency,
-						  GtkStatusIcon *icon)
+						  XfpmNotifyUrgency urgency)
 {
     NotifyNotification *n = xfpm_notify_new_notification_internal (title, 
 							           text, icon_name, 
-								   timeout, urgency, 
-								   icon);
+								   timeout, urgency);
     return n;
 }
 
diff --git a/src/xfpm-notify.h b/src/xfpm-notify.h
index 256eebd..04d2520 100644
--- a/src/xfpm-notify.h
+++ b/src/xfpm-notify.h
@@ -64,16 +64,14 @@ void             	  xfpm_notify_show_notification 	    (XfpmNotify *notify,
 								     const gchar *icon_name,
 								     gint timeout,
 								     gboolean simple,
-								     XfpmNotifyUrgency urgency,
-								     GtkStatusIcon *icon);
+								     XfpmNotifyUrgency urgency);
 
 NotifyNotification       *xfpm_notify_new_notification  	    (XfpmNotify *notify,
 								     const gchar *title,
 								     const gchar *text,
 								     const gchar *icon_name,
 								     guint timeout,
-								     XfpmNotifyUrgency urgency,
-								     GtkStatusIcon *icon) G_GNUC_MALLOC;
+								     XfpmNotifyUrgency urgency) G_GNUC_MALLOC;
 
 void 			  xfpm_notify_add_action_to_notification    (XfpmNotify *notify, 
 								     NotifyNotification *n,
diff --git a/src/xfpm-power.c b/src/xfpm-power.c
index 967aab4..c2620c4 100644
--- a/src/xfpm-power.c
+++ b/src/xfpm-power.c
@@ -369,8 +369,7 @@ xfpm_power_report_error (XfpmPower *power, const gchar *error, const gchar *icon
 				   icon_name,
 				   10000,
 				   FALSE,
-				   XFPM_NOTIFY_CRITICAL,
-				   battery);
+				   XFPM_NOTIFY_CRITICAL);
 
 }
 
@@ -387,13 +386,19 @@ xfpm_power_sleep (XfpmPower *power, const gchar *sleep_time, gboolean force)
 
     if ( power->priv->inhibited && force == FALSE)
     {
+	GtkWidget *dialog;
 	gboolean ret;
 
-	ret = xfce_dialog_confirm (NULL,
-				   GTK_STOCK_OK, _("_Hibernate"),
-				   _("An application is currently disabling the automatic sleep. "
-				     "Doing this action now may damage the working state of this application."),
-				   _("Are you sure you want to hibernate the system?"));
+	dialog = gtk_message_dialog_new (NULL,
+                                         GTK_DIALOG_MODAL,
+                                         GTK_MESSAGE_QUESTION,
+                                         GTK_BUTTONS_YES_NO,
+                                         _("An application is currently disabling the automatic sleep. "
+				           "Doing this action now may damage the working state of this application.\n"
+				           "Are you sure you want to hibernate the system?"));
+	ret = gtk_dialog_run (GTK_DIALOG (dialog));
+	gtk_widget_destroy (dialog);
+
 
 	if ( !ret )
 	    return;
@@ -431,15 +436,20 @@ xfpm_power_sleep (XfpmPower *power, const gchar *sleep_time, gboolean force)
 #endif
         if (!xfpm_lock_screen ())
         {
+	    GtkWidget *dialog;
 	    gboolean ret;
 
-	    ret = xfce_dialog_confirm (NULL,
-				       GTK_STOCK_OK, _("Continue"),
-			               _("None of the screen lock tools ran "
-				         "successfully, the screen will not "
-					 "be locked."),
-				       _("Do you still want to continue to "
-				         "suspend the system?"));
+	    dialog = gtk_message_dialog_new (NULL,
+				             GTK_DIALOG_MODAL,
+				             GTK_MESSAGE_QUESTION,
+				             GTK_BUTTONS_YES_NO,
+				             _("None of the screen lock tools ran "
+				               "successfully, the screen will not "
+				               "be locked.\n"
+				               "Do you still want to continue to "
+				               "suspend the system?"));
+	    ret = gtk_dialog_run (GTK_DIALOG (dialog));
+	    gtk_widget_destroy (dialog);
 
 	    if ( !ret )
 		return;
@@ -649,10 +659,9 @@ xfpm_power_show_critical_action_notification (XfpmPower *power, XfpmBattery *bat
 	xfpm_notify_new_notification (power->priv->notify,
 				      _("Power Manager"),
 				      message,
-				      gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
+				      xfpm_battery_get_icon_name (battery),
 				      20000,
-				      XFPM_NOTIFY_CRITICAL,
-				      GTK_STATUS_ICON (battery));
+				      XFPM_NOTIFY_CRITICAL);
 
     xfpm_power_add_actions_to_notification (power, n);
     xfpm_notify_critical (power->priv->notify, n);
@@ -692,7 +701,7 @@ xfpm_power_show_critical_action_gtk (XfpmPower *power)
                "Save your work to avoid losing data");
 
     dialog = gtk_dialog_new_with_buttons (_("Power Manager"), NULL, GTK_DIALOG_MODAL,
-                                          NULL);
+                                          NULL, NULL);
 
     gtk_dialog_set_default_response (GTK_DIALOG (dialog),
                                      GTK_RESPONSE_CANCEL);
@@ -734,7 +743,7 @@ xfpm_power_show_critical_action_gtk (XfpmPower *power)
 			          G_CALLBACK (xfpm_power_shutdown_clicked), power);
     }
 
-    cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
+    cancel = gtk_button_new_with_label (_("_Cancel"));
     gtk_dialog_add_action_widget (GTK_DIALOG (dialog), cancel, GTK_RESPONSE_NONE);
 
     g_signal_connect_swapped (cancel, "clicked",
@@ -857,11 +866,10 @@ xfpm_power_battery_charge_changed_cb (XfpmBattery *battery, XfpmPower *power)
 		xfpm_notify_show_notification (power->priv->notify,
 					       _("Power Manager"),
 					       _("System is running on low power"),
-					       gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
+					       xfpm_battery_get_icon_name (battery),
 					       10000,
 					       FALSE,
-					       XFPM_NOTIFY_NORMAL,
-					       GTK_STATUS_ICON (battery));
+					       XFPM_NOTIFY_NORMAL);
 
 	}
 	else if ( battery_charge == XFPM_BATTERY_CHARGE_LOW )
@@ -881,11 +889,10 @@ xfpm_power_battery_charge_changed_cb (XfpmBattery *battery, XfpmPower *power)
 		xfpm_notify_show_notification (power->priv->notify,
 					       _("Power Manager"),
 					       msg,
-					       gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
+					       xfpm_battery_get_icon_name (battery),
 					       10000,
 					       FALSE,
-					       XFPM_NOTIFY_NORMAL,
-					       GTK_STATUS_ICON (battery));
+					       XFPM_NOTIFY_NORMAL);
 		g_free (msg);
 		g_free (time_str);
 	    }
@@ -919,11 +926,11 @@ xfpm_power_add_device (UpDevice *device, XfpmPower *power)
 	 device_type == UP_DEVICE_KIND_KEYBOARD	||
 	 device_type == UP_DEVICE_KIND_PHONE)
     {
-	GtkStatusIcon *battery;
+	GtkWidget *battery;
 	XFPM_DEBUG( "Battery device type '%s' detected at: %s",
 		     up_device_kind_to_string(device_type), object_path);
 	battery = xfpm_battery_new ();
-	gtk_status_icon_set_visible (battery, FALSE);
+
 	xfpm_battery_monitor_device (XFPM_BATTERY (battery),
 				     object_path,
 				     device_type);

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


More information about the Xfce4-commits mailing list