kov changed libgksu/trunk/ChangeLog, libgksu/trunk/libgksu/libgksu.c

Gustavo Noronha kov at costa.debian.org
Sun Aug 6 18:33:23 UTC 2006


Mensagem de log: 
startup notification is now done completely by the
library


-----


Modified: libgksu/trunk/ChangeLog
===================================================================
--- libgksu/trunk/ChangeLog	2006-08-06 17:31:35 UTC (rev 674)
+++ libgksu/trunk/ChangeLog	2006-08-06 18:33:22 UTC (rev 675)
@@ -1,3 +1,9 @@
+2006-08-06  Gustavo Noronha Silva  <kov at debian.org>
+
+	* libgksu/libgksu.[ch]:
+	- bring the rest of the startup notification code from the
+	  application
+
 2006-07-19  Gustavo Noronha Silva  <kov at debian.org>
 
 	* Release 1.9.7

Modified: libgksu/trunk/libgksu/libgksu.c
===================================================================
--- libgksu/trunk/libgksu/libgksu.c	2006-08-06 17:31:35 UTC (rev 674)
+++ libgksu/trunk/libgksu/libgksu.c	2006-08-06 18:33:22 UTC (rev 675)
@@ -34,6 +34,9 @@
 #include <glibtop.h>
 #include <glibtop/procstate.h>
 
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+
 #define SN_API_NOT_YET_FROZEN
 #include <libsn/sn.h>
 
@@ -1236,6 +1239,17 @@
   g_free (xauth);
 }
 
+static void
+startup_notification_initialize (GksuContext *context)
+{
+  SnDisplay *sn_display;
+  sn_display = sn_display_new (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
+			       NULL, NULL);
+  context->sn_context = sn_launcher_context_new (sn_display, gdk_screen_get_number (gdk_display_get_default_screen (gdk_display_get_default ())));
+  sn_launcher_context_set_description (context->sn_context, _("Granting Rights"));
+  sn_launcher_context_set_name (context->sn_context, g_get_prgname ());
+}
+
 /**
  * gksu_context_new
  *
@@ -1276,6 +1290,7 @@
   context->sn_context = NULL;
 
   get_configuration_options (context);
+  startup_notification_initialize (context);
 
   return context;
 }
@@ -1330,6 +1345,10 @@
   if (context->command)
     g_free (context->command);
   context->command = g_strdup (command);
+
+  /* startup notification */
+  sn_launcher_context_set_binary_name (context->sn_context,
+				       command);
 }
 
 /**
@@ -1546,7 +1565,13 @@
  * Returns: the #SnLauncherContext which is set, or NULL if none was set
  */
 void
-gksu_context_set_launcher_context (GksuContext *context, SnLauncherContext *sn_context);
+gksu_context_set_launcher_context (GksuContext *context,
+				   SnLauncherContext *sn_context)
+{
+  if (context->sn_context)
+    sn_launcher_context_unref (context->sn_context);
+  context->sn_context = sn_context;
+}
 
 /**
  * gksu_context_get_launcher_context:
@@ -1563,6 +1588,42 @@
 }
 
 /**
+ * gksu_context_launch_initiate:
+ * @context: the #GksuContext you want to initiate the launch for
+ *
+ * Initiates the launch, as far as Startup Notification is concerned;
+ * This will only be used internally, usually.
+ */
+static void
+gksu_context_launch_initiate (GksuContext *context)
+{
+  gchar *sid = g_strdup_printf ("%s", sn_launcher_context_get_startup_id (context->sn_context));
+  guint32 launch_time = gdk_x11_display_get_user_time ((GdkDisplay*)GDK_DISPLAY());
+
+  sn_launcher_context_initiate (context->sn_context,
+				g_get_prgname (),
+				gksu_context_get_command (context),
+				launch_time);
+  if (context->debug)
+    fprintf (stderr, "STARTUP_ID: %s\n", sid);
+  setenv ("DESKTOP_STARTUP_ID", sid, TRUE);
+  g_free(sid);
+}
+
+/**
+ * gksu_context_launch_complete:
+ * @context: the #GksuContext you want to complete the launch for
+ *
+ * Completes the launch, as far as Startup Notification is concerned;
+ * This will only be used internally, usually.
+ */
+static void
+gksu_context_launch_complete (GksuContext *context)
+{
+  sn_launcher_context_complete(context->sn_context);
+}
+
+/**
  * gksu_context_set_debug:
  * @context: the #GksuContext you want to modify
  * @value: TRUE or FALSE
@@ -1687,14 +1748,8 @@
       return FALSE;
     }
 
-  if(context->sn_context)
-    {
-       gchar *sid = g_strdup_printf ("%s",sn_launcher_context_get_startup_id (context->sn_context));
-       if (context->debug)
-	 fprintf (stderr, "STARTUP_ID: %s\n", sid);
-       setenv ("DESKTOP_STARTUP_ID", sid, TRUE);
-       g_free(sid);
-    }
+  if (context->sn_context)
+    gksu_context_launch_initiate (context);
 
   pid = forkpty (&fdpty, NULL, NULL, NULL);
   if (pid == 0)
@@ -1992,6 +2047,9 @@
 	  fprintf (stderr, "%s", buf);
 	}
 
+      if (context->sn_context)
+	gksu_context_launch_complete (context);
+
       if (WIFEXITED(status))
 	{
 	  if (WEXITSTATUS(status))
@@ -2146,19 +2204,13 @@
   xauth = g_strdup_printf ("%s/.Xauthority", context->dir);
   xauth_env = getenv ("XAUTHORITY");
   setenv ("XAUTHORITY", xauth, TRUE);
-
-  /* set startup id */
-  if(context->sn_context)
-    {
-       gchar *sid = g_strdup_printf ("%s",sn_launcher_context_get_startup_id (context->sn_context));
-       if (context->debug)
-	 fprintf (stderr, "STARTUP_ID: %s\n", sid);
-       setenv ("DESKTOP_STARTUP_ID", sid, TRUE);
-       g_free(sid);
-    }
   if (context->debug)
     fprintf (stderr, "xauth: %s\n", xauth);
 
+  /* set startup id */
+  if (context->sn_context)
+    gksu_context_launch_initiate (context);
+
   cmd = g_new (gchar *, argcount + 1);
 
   argcount = 0;
@@ -2433,12 +2485,6 @@
 			       "the system administrator."));
 	    }
 	}
-#if 0
-      // stop startup notification (we may want something smarter here,
-      // like using SnMonitorContext)
-      if(context->sn_context)
-	 sn_launcher_context_complete(context->sn_context);
-#endif
       while (!waitpid (pid, &status, WNOHANG))
 	{
 	  if (cmdline)
@@ -2463,6 +2509,8 @@
 	  fflush (stderr);
 	}
 
+      if (context->sn_context)
+	gksu_context_launch_complete (context);
       sudo_reset_xauth (context, xauth, xauth_env);
 
       if (WIFEXITED(status))
@@ -2625,7 +2673,10 @@
 gksu_ask_password_full (GksuContext *context, gchar *prompt,
 			GError **error)
 {
-  return su_ask_password (context, prompt, NULL, error);
+  gchar *ret_value = su_ask_password (context, prompt, NULL, error);
+  if (context->sn_context)
+    gksu_context_launch_complete (context);
+  return ret_value;
 }
 
 /**




More information about the gksu-commits mailing list