patches/gnome-power-manager-06-interactive-dialog.diff
author yippi
Mon, 27 Sep 2010 21:07:51 +0000
changeset 20108 51df67ca9307
parent 17490 946bf3251f47
permissions -rw-r--r--
I had these modules listed as being owned by me, but they are really owned by wangke, correcting.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12259
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
     1
--- src/gpm-manager.c.orig	2008-03-30 01:28:02.535684000 +0800
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
     2
+++ src/gpm-manager.c	2008-03-30 01:23:38.211239000 +0800
17490
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
     3
@@ -436,6 +414,61 @@
12259
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
     4
 	return TRUE;
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
     5
 }
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
     6
 
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
     7
+
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
     8
+#define GSM_DBUS_SERVICE "org.gnome.SessionManager"
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
     9
+#define GSM_DBUS_PATH "/org/gnome/SessionManager"
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    10
+#define GSM_DBUS_INTERFACE "org.gnome.SessionManager"
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    11
+
17490
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    12
+#include <pwd.h>
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    13
+
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    14
+static gboolean
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    15
+can_shutdown ()
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    16
+{
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    17
+	uid_t uid;
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    18
+	struct passwd *pw;
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    19
+
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    20
+	uid = getuid ();                       
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    21
+	if ((pw = getpwuid (uid)) != NULL) {
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    22
+		return (gboolean)chkauthattr ("solaris.system.shutdown", pw->pw_name);
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    23
+	}
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    24
+	return FALSE;
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    25
+}
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    26
+
12259
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    27
+/**
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    28
+ * gsm_dbus_method:
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    29
+ * @method: The g-s-m DBUS method name, e.g. "Logout" or "Shutdown"
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    30
+ **/
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    31
+static gboolean
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    32
+gpm_manager_action_interactive (GpmManager *manager)
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    33
+{
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    34
+	DBusGConnection *connection;
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    35
+	DBusGProxy *proxy;
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    36
+	GError *error = NULL;
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    37
+	
17490
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    38
+	if (can_shutdown() == FALSE)
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    39
+		return FALSE;
946bf3251f47 2010-02-02 Jedy Wang <[email protected]>
jedy
parents: 13729
diff changeset
    40
+
12259
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    41
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    42
+	if (connection == NULL) {
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    43
+		if (error) {
13729
78c5ead117e2 2008-09-23 simon.zheng <[email protected]>
xz159989
parents: 12259
diff changeset
    44
+			egg_warning ("Couldn't connect to PowerManager %s",
12259
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    45
+				     error->message);
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    46
+			g_error_free (error);
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    47
+		}
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    48
+		return FALSE;
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    49
+	}
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    50
+
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    51
+	proxy = dbus_g_proxy_new_for_name (connection,
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    52
+					   GSM_DBUS_SERVICE,
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    53
+					   GSM_DBUS_PATH,
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    54
+					   GSM_DBUS_INTERFACE);
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    55
+	dbus_g_proxy_call_no_reply (proxy, "Shutdown", 
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    56
+				 G_TYPE_INVALID,
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    57
+				 G_TYPE_INVALID);
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    58
+	g_object_unref (proxy);
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    59
+	return TRUE;	
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    60
+}
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    61
+
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    62
 /**
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    63
  * manager_policy_do:
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    64
  * @manager: This class instance
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    65
@@ -495,9 +510,8 @@
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    66
 	} else if (strcmp (action, ACTION_INTERACTIVE) == 0) {
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    67
 		gpm_info_explain_reason (manager->priv->info, GPM_EVENT_NOTIFICATION,
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    68
 					_("GNOME interactive logout."), reason);
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    69
-		gnome_client_request_save (gnome_master_client (),
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    70
-					   GNOME_SAVE_GLOBAL,
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    71
-					   TRUE, GNOME_INTERACT_ANY, FALSE, TRUE);
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    72
+		if (gpm_manager_action_interactive (manager) == FALSE)
13729
78c5ead117e2 2008-09-23 simon.zheng <[email protected]>
xz159989
parents: 12259
diff changeset
    73
+			egg_warning ("Couldn't ask for interactive dialog from session manager");
12259
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    74
 	} else {
13729
78c5ead117e2 2008-09-23 simon.zheng <[email protected]>
xz159989
parents: 12259
diff changeset
    75
 		egg_warning ("unknown action %s", action);
12259
62ebb711692b 2008-05-07 simon.zheng <[email protected]>
xz159989
parents:
diff changeset
    76
 	}