gnome-panel r10908 - trunk/applets/clock



Author: davidz
Date: Thu Feb 28 20:48:16 2008
New Revision: 10908
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=10908&view=rev

Log:
2008-02-28  David Zeuthen  <davidz redhat com>

        * set-timezone.c (can_do): Don't hardcode the polkit results for
        determining when we can authenticate to gain an
        authorization. This fixes a bug where ONE_SHOT auths weren't
        handled because PolKitResult enumerations for these were added
        after this code was written.
        (get_pk_context): Integrate libpolkit into the main loop. Need
        this to refresh the authorization cache. This fixes a bug where
        the Set buttons were not updated. Now it works as expected, e.g.
        the "Set..." becomes a "Set" if you gain the authorization (and
        it's not a one shot one)
        (pk_io_remove_watch_fn, pk_io_add_watch_fn)
        (pk_io_watch_have_data): libpolkit mainloop integration functions.



Modified:
   trunk/applets/clock/ChangeLog
   trunk/applets/clock/set-timezone.c

Modified: trunk/applets/clock/set-timezone.c
==============================================================================
--- trunk/applets/clock/set-timezone.c	(original)
+++ trunk/applets/clock/set-timezone.c	Thu Feb 28 20:48:16 2008
@@ -75,6 +75,40 @@
         return bus;
 }
 
+static gboolean
+pk_io_watch_have_data (GIOChannel *channel, GIOCondition condition, gpointer user_data)
+{
+        int fd;
+        PolKitContext *pk_context = user_data;
+        fd = g_io_channel_unix_get_fd (channel);
+        polkit_context_io_func (pk_context, fd);
+        return TRUE;
+}
+
+static int 
+pk_io_add_watch_fn (PolKitContext *pk_context, int fd)
+{
+        guint id = 0;
+        GIOChannel *channel;
+        channel = g_io_channel_unix_new (fd);
+        if (channel == NULL)
+                goto out;
+        id = g_io_add_watch (channel, G_IO_IN, pk_io_watch_have_data, pk_context);
+        if (id == 0) {
+                g_io_channel_unref (channel);
+                goto out;
+        }
+        g_io_channel_unref (channel);
+out:
+        return id;
+}
+
+static void 
+pk_io_remove_watch_fn (PolKitContext *pk_context, int watch_id)
+{
+        g_source_remove (watch_id);
+}
+
 static PolKitContext *
 get_pk_context (void)
 {
@@ -82,6 +116,9 @@
 
 	if (pk_context == NULL) {
 		pk_context = polkit_context_new ();
+                polkit_context_set_io_watch_functions (pk_context,
+                                                       pk_io_add_watch_fn,
+                                                       pk_io_remove_watch_fn);
 		if (!polkit_context_init (pk_context, NULL)) {
 			polkit_context_unref (pk_context);
 			pk_context = NULL;
@@ -126,22 +163,19 @@
         pk_result = polkit_context_can_caller_do_action (pk_context, pk_action, pk_caller);
 
 	switch (pk_result) {
-        default:
         case POLKIT_RESULT_UNKNOWN:
         case POLKIT_RESULT_NO:
  		res = 0;
 		break;
-        case POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH:
-        case POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_KEEP_SESSION:
-        case POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_KEEP_ALWAYS:
-        case POLKIT_RESULT_ONLY_VIA_SELF_AUTH:
-        case POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_SESSION:
-        case POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_ALWAYS:
-		res = 1;
-		break;
         case POLKIT_RESULT_YES:
 		res = 2;
 		break;
+        default:
+                /* This covers all the POLKIT_RESULT_ONLY_VIA_[SELF|ADMIN]_AUTH_* cases as more of these
+                 * may be added in the future.
+                 */
+		res = 1;
+		break;
 	}
 	
 out:



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