[gnome-power-manager] Remove the suspend and hibernate menu items



commit 58862f1ceaf1a6fe894956e74d9304cd91f162e2
Author: Richard Hughes <richard hughsie com>
Date:   Thu Oct 15 15:51:47 2009 +0100

    Remove the suspend and hibernate menu items

 data/gnome-power-manager.schemas.in |   24 -------
 src/gpm-common.h                    |    2 -
 src/gpm-control.c                   |   12 +--
 src/gpm-manager.c                   |   66 ------------------
 src/gpm-tray-icon.c                 |  125 +----------------------------------
 5 files changed, 6 insertions(+), 223 deletions(-)
---
diff --git a/data/gnome-power-manager.schemas.in b/data/gnome-power-manager.schemas.in
index 13a61fd..f68d6e7 100644
--- a/data/gnome-power-manager.schemas.in
+++ b/data/gnome-power-manager.schemas.in
@@ -288,30 +288,6 @@
     </schema>
 
     <schema>
-      <key>/schemas/apps/gnome-power-manager/general/can_suspend</key>
-      <applyto>/apps/gnome-power-manager/general/can_suspend</applyto>
-      <owner>gnome-power-manager</owner>
-      <type>bool</type>
-      <default>true</default>
-      <locale name="C">
-        <short>Suspend enabled</short>
-        <long>If the user is authorized to suspend the computer.</long>
-      </locale>
-    </schema>
-
-    <schema>
-      <key>/schemas/apps/gnome-power-manager/general/can_hibernate</key>
-      <applyto>/apps/gnome-power-manager/general/can_hibernate</applyto>
-      <owner>gnome-power-manager</owner>
-      <type>bool</type>
-      <default>true</default>
-      <locale name="C">
-        <short>Hibernate enabled</short>
-        <long>If the user is authorized to hibernate the computer.</long>
-      </locale>
-    </schema>
-
-    <schema>
       <key>/schemas/apps/gnome-power-manager/general/network_sleep</key>
       <applyto>/apps/gnome-power-manager/general/network_sleep</applyto>
       <owner>gnome-power-manager</owner>
diff --git a/src/gpm-common.h b/src/gpm-common.h
index 521f683..8a21b57 100644
--- a/src/gpm-common.h
+++ b/src/gpm-common.h
@@ -80,8 +80,6 @@ G_BEGIN_DECLS
 
 /* general */
 #define GPM_CONF_SCHEMA_VERSION			GPM_CONF_DIR "/general/installed_schema"
-#define GPM_CONF_CAN_SUSPEND			GPM_CONF_DIR "/general/can_suspend"
-#define GPM_CONF_CAN_HIBERNATE			GPM_CONF_DIR "/general/can_hibernate"
 #define GPM_CONF_USE_TIME_POLICY		GPM_CONF_DIR "/general/use_time_for_policy"
 #define GPM_CONF_USE_PROFILE_TIME		GPM_CONF_DIR "/general/use_profile_time"
 #define GPM_CONF_NETWORKMANAGER_SLEEP		GPM_CONF_DIR "/general/network_sleep"
diff --git a/src/gpm-control.c b/src/gpm-control.c
index 36bed3d..ebfe1cc 100644
--- a/src/gpm-control.c
+++ b/src/gpm-control.c
@@ -111,7 +111,6 @@ gpm_control_check_foreground_console (GpmControl *control)
 gboolean
 gpm_control_allowed_suspend (GpmControl *control, gboolean *can, GError **error)
 {
-	gboolean conf_ok;
 	gboolean hardware_ok;
 	gboolean fg;
 	g_return_val_if_fail (can, FALSE);
@@ -123,14 +122,13 @@ gpm_control_allowed_suspend (GpmControl *control, gboolean *can, GError **error)
 		      "can-suspend", &hardware_ok,
 		      NULL);
 
-	conf_ok = gconf_client_get_bool (control->priv->conf, GPM_CONF_CAN_SUSPEND, NULL);
 	g_object_get (control->priv->client,
 		      "can-suspend", &hardware_ok,
 		      NULL);
 	fg = gpm_control_check_foreground_console (control);
-	if (conf_ok && hardware_ok && fg)
+	if (hardware_ok && fg)
 		*can = TRUE;
-	egg_debug ("conf=%i, fg=%i, can=%i", conf_ok, fg, *can);
+	egg_debug ("fg=%i, can=%i", fg, *can);
 	return TRUE;
 }
 
@@ -145,7 +143,6 @@ gpm_control_allowed_suspend (GpmControl *control, gboolean *can, GError **error)
 gboolean
 gpm_control_allowed_hibernate (GpmControl *control, gboolean *can, GError **error)
 {
-	gboolean conf_ok;
 	gboolean hardware_ok;
 	gboolean fg;
 	g_return_val_if_fail (can, FALSE);
@@ -156,14 +153,13 @@ gpm_control_allowed_hibernate (GpmControl *control, gboolean *can, GError **erro
 		      NULL);
 
 	*can = FALSE;
-	conf_ok = gconf_client_get_bool (control->priv->conf, GPM_CONF_CAN_HIBERNATE, NULL);
 	fg = gpm_control_check_foreground_console (control);
 	g_object_get (control->priv->client,
 		      "can-hibernate", &hardware_ok,
 		      NULL);
-	if (conf_ok && hardware_ok && fg)
+	if (hardware_ok && fg)
 		*can = TRUE;
-	egg_debug ("conf=%i, fg=%i, can=%i", conf_ok, fg, *can);
+	egg_debug ("fg=%i, can=%i", fg, *can);
 	return TRUE;
 }
 
diff --git a/src/gpm-manager.c b/src/gpm-manager.c
index ddd6f7b..7f9c495 100644
--- a/src/gpm-manager.c
+++ b/src/gpm-manager.c
@@ -421,24 +421,8 @@ out:
 static gboolean
 gpm_manager_action_suspend (GpmManager *manager, const gchar *reason)
 {
-	gboolean allowed;
 	GError *error = NULL;
 
-	/* check if the admin has disabled */
-	allowed = gconf_client_get_bool (manager->priv->conf, GPM_CONF_CAN_SUSPEND, NULL);
-	if (allowed == FALSE) {
-		/* error msg as disabled in gconf */
-		gpm_manager_notify (manager, &manager->priv->notification,
-				    /* TRANSLATORS: the action was not done */
-				    _("Action disallowed"),
-				    /* TRANSLATORS: admin has disabled ability to do this */
-				    _("Suspend support has been disabled. Contact your administrator for more details."),
-				    GPM_MANAGER_NOTIFY_TIMEOUT_SHORT,
-				    GPM_STOCK_APP_ICON,
-				    NOTIFY_URGENCY_NORMAL);
-		return FALSE;
-	}
-
 	/* check to see if we are inhibited */
 	if (gpm_manager_is_inhibit_valid (manager, FALSE, "suspend") == FALSE)
 		return FALSE;
@@ -457,24 +441,8 @@ gpm_manager_action_suspend (GpmManager *manager, const gchar *reason)
 static gboolean
 gpm_manager_action_hibernate (GpmManager *manager, const gchar *reason)
 {
-	gboolean allowed;
 	GError *error = NULL;
 
-	/* check if the admin has disabled */
-	allowed = gconf_client_get_bool (manager->priv->conf, GPM_CONF_CAN_HIBERNATE, NULL);
-	if (allowed == FALSE) {
-		/* error msg as disabled in gconf */
-		gpm_manager_notify (manager, &manager->priv->notification,
-				    /* TRANSLATORS: the action was not done */
-				    _("Action disallowed"),
-				    /* TRANSLATORS: admin has disabled ability to do this */
-				    _("Hibernate support has been disabled. Contact your administrator for more details."),
-				    GPM_MANAGER_NOTIFY_TIMEOUT_SHORT,
-				    GPM_STOCK_APP_ICON,
-				    NOTIFY_URGENCY_NORMAL);
-		return FALSE;
-	}
-
 	/* check to see if we are inhibited */
 	if (gpm_manager_is_inhibit_valid (manager, FALSE, "hibernate") == FALSE)
 		return FALSE;
@@ -926,34 +894,6 @@ gpm_conf_gconf_key_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *e
 		gpm_manager_sync_policy_sleep (manager);
 }
 
-/**
- * gpm_manager_tray_icon_hibernate:
- * @manager: This class instance
- * @tray: The tray object
- *
- * The icon tray hibernate callback, which only should happen if both policy and
- * the inhibit states are valid.
- **/
-static void
-gpm_manager_tray_icon_hibernate (GpmManager *manager, GpmTrayIcon *tray)
-{
-	gpm_manager_action_hibernate (manager, "User clicked on tray");
-}
-
-/**
- * gpm_manager_tray_icon_suspend:
- * @manager: This class instance
- * @tray: The tray object
- *
- * The icon tray suspend callback, which only should happen if both policy and
- * the inhibit states are valid.
- **/
-static void
-gpm_manager_tray_icon_suspend (GpmManager *manager, GpmTrayIcon *tray)
-{
-	gpm_manager_action_suspend (manager, "User clicked on tray");
-}
-
 #if 0
 /**
  * gpm_manager_screensaver_auth_request_cb:
@@ -1902,12 +1842,6 @@ gpm_manager_init (GpmManager *manager)
 
 	egg_debug ("creating new tray icon");
 	manager->priv->tray_icon = gpm_tray_icon_new ();
-	g_signal_connect_object (G_OBJECT (manager->priv->tray_icon),
-				 "suspend", G_CALLBACK (gpm_manager_tray_icon_suspend),
-				 manager, G_CONNECT_SWAPPED);
-	g_signal_connect_object (G_OBJECT (manager->priv->tray_icon),
-				 "hibernate", G_CALLBACK (gpm_manager_tray_icon_hibernate),
-				 manager, G_CONNECT_SWAPPED);
 
 	/* keep a reference for the notifications */
 	manager->priv->status_icon = gpm_tray_icon_get_status_icon (manager->priv->tray_icon);
diff --git a/src/gpm-tray-icon.c b/src/gpm-tray-icon.c
index 8e4cba4..b65ea20 100644
--- a/src/gpm-tray-icon.c
+++ b/src/gpm-tray-icon.c
@@ -45,7 +45,6 @@
 
 #include "gpm-devicekit.h"
 #include "gpm-engine.h"
-#include "gpm-control.h"
 #include "gpm-common.h"
 #include "gpm-stock-icons.h"
 #include "gpm-tray-icon.h"
@@ -57,47 +56,14 @@ static void     gpm_tray_icon_finalize   (GObject	   *object);
 struct GpmTrayIconPrivate
 {
 	GConfClient		*conf;
-	GpmControl		*control;
 	GpmEngine		*engine;
 	GtkStatusIcon		*status_icon;
-	gboolean		 show_suspend;
-	gboolean		 show_hibernate;
 	gboolean		 show_actions;
 };
 
-enum {
-	SUSPEND,
-	HIBERNATE,
-	LAST_SIGNAL
-};
-
-static guint signals [LAST_SIGNAL] = { 0 };
-
 G_DEFINE_TYPE (GpmTrayIcon, gpm_tray_icon, G_TYPE_OBJECT)
 
 /**
- * gpm_tray_icon_enable_suspend:
- * @enabled: If we should enable (i.e. show) the suspend icon
- **/
-static void
-gpm_tray_icon_enable_suspend (GpmTrayIcon *icon, gboolean enabled)
-{
-	g_return_if_fail (GPM_IS_TRAY_ICON (icon));
-	icon->priv->show_suspend = enabled;
-}
-
-/**
- * gpm_tray_icon_enable_hibernate:
- * @enabled: If we should enable (i.e. show) the hibernate icon
- **/
-static void
-gpm_tray_icon_enable_hibernate (GpmTrayIcon *icon, gboolean enabled)
-{
-	g_return_if_fail (GPM_IS_TRAY_ICON (icon));
-	icon->priv->show_hibernate = enabled;
-}
-
-/**
  * gpm_tray_icon_enable_actions:
  **/
 static void
@@ -192,30 +158,6 @@ gpm_tray_icon_show_info_cb (GtkMenuItem *item, gpointer data)
 }
 
 /**
- * gpm_tray_icon_hibernate_cb:
- * @action: A valid GtkAction
- **/
-static void
-gpm_tray_icon_hibernate_cb (GtkMenuItem *item, gpointer data)
-{
-	GpmTrayIcon *icon = GPM_TRAY_ICON (data);
-	egg_debug ("emitting hibernate");
-	g_signal_emit (icon, signals [HIBERNATE], 0);
-}
-
-/**
- * gpm_tray_icon_suspend_cb:
- * @action: A valid GtkAction
- **/
-static void
-gpm_tray_icon_suspend_cb (GtkMenuItem *item, gpointer data)
-{
-	GpmTrayIcon *icon = GPM_TRAY_ICON (data);
-	egg_debug ("emitting suspend");
-	g_signal_emit (icon, signals [SUSPEND], 0);
-}
-
-/**
  * gpm_tray_icon_show_statistics_cb:
  * @action: A valid GtkAction
  **/
@@ -268,23 +210,6 @@ gpm_tray_icon_class_init (GpmTrayIconClass *klass)
 
 	object_class->finalize = gpm_tray_icon_finalize;
 	g_type_class_add_private (klass, sizeof (GpmTrayIconPrivate));
-
-	signals [SUSPEND] =
-		g_signal_new ("suspend",
-			      G_TYPE_FROM_CLASS (object_class),
-			      G_SIGNAL_RUN_LAST,
-			      G_STRUCT_OFFSET (GpmTrayIconClass, suspend),
-			      NULL, NULL, g_cclosure_marshal_VOID__VOID,
-			      G_TYPE_NONE,
-			      0);
-	signals [HIBERNATE] =
-		g_signal_new ("hibernate",
-			      G_TYPE_FROM_CLASS (object_class),
-			      G_SIGNAL_RUN_LAST,
-			      G_STRUCT_OFFSET (GpmTrayIconClass, hibernate),
-			      NULL, NULL, g_cclosure_marshal_VOID__VOID,
-			      G_TYPE_NONE,
-			      0);
 }
 
 /**
@@ -409,7 +334,6 @@ gpm_tray_icon_activate_cb (GtkStatusIcon *status_icon, GpmTrayIcon *icon)
 {
 	GtkMenu *menu = (GtkMenu*) gtk_menu_new ();
 	GtkWidget *item;
-	GtkWidget *image;
 	guint dev_cnt = 0;
 	GPtrArray *array;
 	egg_debug ("icon left clicked");
@@ -424,36 +348,12 @@ gpm_tray_icon_activate_cb (GtkStatusIcon *status_icon, GpmTrayIcon *icon)
 	dev_cnt += gpm_tray_icon_add_device (icon, menu, array, DKP_DEVICE_TYPE_PHONE);
 	g_ptr_array_unref (array);
 
-	/* nothing to display! */
-	if (dev_cnt == 0 && !icon->priv->show_suspend && !icon->priv->show_hibernate)
-		return;
-
 	/* only do the seporator if we have at least one device and can do an action */
-	if (dev_cnt != 0 && (icon->priv->show_suspend || icon->priv->show_hibernate)) {
+	if (dev_cnt != 0) {
 		item = gtk_separator_menu_item_new ();
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	}
 
-	/* Suspend if available */
-	if (icon->priv->show_suspend) {
-		item = gtk_image_menu_item_new_with_mnemonic (_("_Suspend"));
-		image = gtk_image_new_from_icon_name (GPM_STOCK_SUSPEND, GTK_ICON_SIZE_MENU);
-		gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
-		g_signal_connect (G_OBJECT (item), "activate",
-				  G_CALLBACK (gpm_tray_icon_suspend_cb), icon);
-		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-	}
-
-	/* Hibernate if available */
-	if (icon->priv->show_hibernate) {
-		item = gtk_image_menu_item_new_with_mnemonic (_("Hi_bernate"));
-		image = gtk_image_new_from_icon_name (GPM_STOCK_HIBERNATE, GTK_ICON_SIZE_MENU);
-		gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
-		g_signal_connect (G_OBJECT (item), "activate",
-				  G_CALLBACK (gpm_tray_icon_hibernate_cb), icon);
-		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-	}
-
 	/* show the menu */
 	gtk_widget_show_all (GTK_WIDGET (menu));
 	gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
@@ -473,22 +373,13 @@ static void
 gpm_conf_gconf_key_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *entry, GpmTrayIcon *icon)
 {
 	GConfValue *value;
-	gboolean enabled;
 	gboolean allowed_in_menu;
 
 	value = gconf_entry_get_value (entry);
 	if (value == NULL)
 		return;
 
-	if (strcmp (entry->key, GPM_CONF_CAN_SUSPEND) == 0) {
-		gpm_control_allowed_suspend (icon->priv->control, &enabled, NULL);
-		gpm_tray_icon_enable_suspend (icon, enabled);
-
-	} else if (strcmp (entry->key, GPM_CONF_CAN_HIBERNATE) == 0) {
-		gpm_control_allowed_hibernate (icon->priv->control, &enabled, NULL);
-		gpm_tray_icon_enable_hibernate (icon, enabled);
-
-	} else if (strcmp (entry->key, GPM_CONF_UI_SHOW_ACTIONS) == 0) {
+	if (strcmp (entry->key, GPM_CONF_UI_SHOW_ACTIONS) == 0) {
 		allowed_in_menu = gconf_value_get_bool (value);
 		gpm_tray_icon_enable_actions (icon, allowed_in_menu);
 	}
@@ -502,16 +393,12 @@ gpm_conf_gconf_key_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *e
 static void
 gpm_tray_icon_init (GpmTrayIcon *icon)
 {
-	gboolean enabled;
 	gboolean allowed_in_menu;
 
 	icon->priv = GPM_TRAY_ICON_GET_PRIVATE (icon);
 
 	icon->priv->engine = gpm_engine_new ();
 
-	/* use the policy object */
-	icon->priv->control = gpm_control_new ();
-
 	icon->priv->conf = gconf_client_get_default ();
 	/* watch gnome-power-manager keys */
 	gconf_client_add_dir (icon->priv->conf, GPM_CONF_DIR,
@@ -530,13 +417,6 @@ gpm_tray_icon_init (GpmTrayIcon *icon)
 				 G_CALLBACK (gpm_tray_icon_activate_cb),
 				 icon, 0);
 
-	/* only show the suspend and hibernate icons if we can do the action,
-	   and the policy allows the actions in the menu */
-	gpm_control_allowed_suspend (icon->priv->control, &enabled, NULL);
-	gpm_tray_icon_enable_suspend (icon, enabled);
-	gpm_control_allowed_hibernate (icon->priv->control, &enabled, NULL);
-	gpm_tray_icon_enable_hibernate (icon, enabled);
-
 	allowed_in_menu = gconf_client_get_bool (icon->priv->conf, GPM_CONF_UI_SHOW_ACTIONS, NULL);
 	gpm_tray_icon_enable_actions (icon, allowed_in_menu);
 }
@@ -555,7 +435,6 @@ gpm_tray_icon_finalize (GObject *object)
 
 	tray_icon = GPM_TRAY_ICON (object);
 
-	g_object_unref (tray_icon->priv->control);
 	g_object_unref (tray_icon->priv->status_icon);
 	g_object_unref (tray_icon->priv->engine);
 	g_return_if_fail (tray_icon->priv != NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]