nautilus r14710 - in trunk: . cut-n-paste-code/libegg



Author: alexl
Date: Thu Oct  9 09:37:45 2008
New Revision: 14710
URL: http://svn.gnome.org/viewvc/nautilus?rev=14710&view=rev

Log:
2008-10-09  Alexander Larsson  <alexl redhat com>

        * cut-n-paste-code/libegg/eggdesktopfile.c:
        * cut-n-paste-code/libegg/eggdesktopfile.h:
        * cut-n-paste-code/libegg/eggsmclient-xsmp.c:
        * cut-n-paste-code/libegg/eggsmclient.c:
	Update EggSMClient from libegg




Modified:
   trunk/ChangeLog
   trunk/cut-n-paste-code/libegg/eggdesktopfile.c
   trunk/cut-n-paste-code/libegg/eggdesktopfile.h
   trunk/cut-n-paste-code/libegg/eggsmclient-xsmp.c
   trunk/cut-n-paste-code/libegg/eggsmclient.c

Modified: trunk/cut-n-paste-code/libegg/eggdesktopfile.c
==============================================================================
--- trunk/cut-n-paste-code/libegg/eggdesktopfile.c	(original)
+++ trunk/cut-n-paste-code/libegg/eggdesktopfile.c	Thu Oct  9 09:37:45 2008
@@ -125,7 +125,7 @@
 
   key_file = g_key_file_new ();
   if (!g_key_file_load_from_dirs (key_file, desktop_file_path, search_dirs,
-				       &full_path, 0, error))
+				  &full_path, 0, error))
     {
       g_key_file_free (key_file);
       return NULL;
@@ -426,13 +426,9 @@
 			      const char      *key,
 			      GError         **error)
 {
-#if 0
   return g_key_file_get_double (desktop_file->key_file,
 				EGG_DESKTOP_FILE_GROUP, key,
 				error);
-#else
-  return 0.0;
-#endif
 }
 
 char **
@@ -913,7 +909,7 @@
   return TRUE;
 }
 
-#ifdef HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE
+#if GTK_CHECK_VERSION (2, 12, 0)
 static char *
 start_startup_notification (GdkDisplay     *display,
 			    EggDesktopFile *desktop_file,
@@ -1024,9 +1020,7 @@
   g_timeout_add (EGG_DESKTOP_FILE_SN_TIMEOUT_LENGTH,
 		 startup_notification_timeout, sn_data);
 }
-#endif /* HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE */
-
-extern char **environ;
+#endif /* GTK 2.12 */
 
 static GPtrArray *
 array_putenv (GPtrArray *env, char *variable)
@@ -1035,10 +1029,20 @@
 
   if (!env)
     {
+      char **envp;
+
       env = g_ptr_array_new ();
 
-      for (i = 0; environ[i]; i++)
-	g_ptr_array_add (env, g_strdup (environ[i]));
+      envp = g_listenv ();
+      for (i = 0; envp[i]; i++)
+        {
+          const char *value;
+
+          value = g_getenv (envp[i]);
+          g_ptr_array_add (env, g_strdup_printf ("%s=%s", envp[i],
+                                                 value ? value : ""));
+        }
+      g_strfreev (envp);
     }
 
   keylen = strcspn (variable, "=");
@@ -1068,7 +1072,7 @@
 			  GError **error)
 {
   EggDesktopFileLaunchOption option;
-  GSList *translated_documents = NULL, *docs;
+  GSList *translated_documents, *docs;
   char *command, **argv;
   int argc, i, screen_num;
   gboolean success, current_success;
@@ -1203,7 +1207,7 @@
 	}
       g_free (command);
 
-#ifdef HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE
+#if GTK_CHECK_VERSION (2, 12, 0)
       startup_id = start_startup_notification (display, desktop_file,
 					       argv[0], screen_num,
 					       workspace, launch_time);
@@ -1216,13 +1220,10 @@
 	}
 #else
       startup_id = NULL;
-#endif /* HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE */
+#endif /* GTK 2.12 */
 
       if (env != NULL)
-        {
-          /* Add NULL item in the end of array  */
-          g_ptr_array_add (env, NULL);
-        }
+	g_ptr_array_add (env, NULL);
 
       current_success =
 	g_spawn_async_with_pipes (directory,
@@ -1237,7 +1238,7 @@
 
       if (startup_id)
 	{
-#ifdef HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE
+#if GTK_CHECK_VERSION (2, 12, 0)
 	  if (current_success)
 	    {
 	      set_startup_notification_timeout (display, startup_id);
@@ -1248,7 +1249,7 @@
 		g_free (startup_id);
 	    }
 	  else
-#endif /* HAVE_GDK_X11_DISPLAY_BROADCAST_STARTUP_MESSAGE */
+#endif /* GTK 2.12 */
 	    g_free (startup_id);
 	}
       else if (ret_startup_id)
@@ -1273,8 +1274,8 @@
  out:
   if (env)
     {
-      g_ptr_array_foreach (env, (GFunc)g_free, NULL);
-      g_ptr_array_free (env, TRUE);
+      g_strfreev ((char **)env->pdata);
+      g_ptr_array_free (env, FALSE);
     }
   free_document_list (translated_documents);
 

Modified: trunk/cut-n-paste-code/libegg/eggdesktopfile.h
==============================================================================
--- trunk/cut-n-paste-code/libegg/eggdesktopfile.h	(original)
+++ trunk/cut-n-paste-code/libegg/eggdesktopfile.h	Thu Oct  9 09:37:45 2008
@@ -48,12 +48,12 @@
 
 void                egg_desktop_file_free               (EggDesktopFile  *desktop_file);
 
-const char         *egg_desktop_file_get_source         (EggDesktopFile  *desktop_file) G_GNUC_PURE;
+const char         *egg_desktop_file_get_source         (EggDesktopFile  *desktop_file);
 
-EggDesktopFileType  egg_desktop_file_get_desktop_file_type (EggDesktopFile  *desktop_file) G_GNUC_PURE;
+EggDesktopFileType  egg_desktop_file_get_desktop_file_type (EggDesktopFile  *desktop_file);
 
-const char         *egg_desktop_file_get_name           (EggDesktopFile  *desktop_file) G_GNUC_PURE;
-const char         *egg_desktop_file_get_icon           (EggDesktopFile  *desktop_file) G_GNUC_PURE;
+const char         *egg_desktop_file_get_name           (EggDesktopFile  *desktop_file);
+const char         *egg_desktop_file_get_icon           (EggDesktopFile  *desktop_file);
 
 gboolean            egg_desktop_file_can_launch         (EggDesktopFile  *desktop_file,
 							 const char      *desktop_environment);

Modified: trunk/cut-n-paste-code/libegg/eggsmclient-xsmp.c
==============================================================================
--- trunk/cut-n-paste-code/libegg/eggsmclient-xsmp.c	(original)
+++ trunk/cut-n-paste-code/libegg/eggsmclient-xsmp.c	Thu Oct  9 09:37:45 2008
@@ -56,7 +56,6 @@
  */
 typedef enum
 {
-  XSMP_STATE_START,
   XSMP_STATE_IDLE,
   XSMP_STATE_SAVE_YOURSELF,
   XSMP_STATE_INTERACT_REQUEST,
@@ -67,7 +66,6 @@
 } EggSMClientXSMPState;
 
 static const char *state_names[] = {
-  "start",
   "idle",
   "save-yourself",
   "interact-request",
@@ -101,6 +99,7 @@
   guint shutting_down : 1;
 
   /* Todo list */
+  guint waiting_to_set_initial_properties : 1;
   guint waiting_to_emit_quit : 1;
   guint waiting_to_emit_quit_cancelled : 1;
   guint waiting_to_save_myself : 1;
@@ -200,72 +199,19 @@
 }
 
 static gboolean
-sm_client_xsmp_connect (gpointer user_data)
+sm_client_xsmp_set_initial_properties (gpointer user_data)
 {
   EggSMClientXSMP *xsmp = user_data;
-  SmcCallbacks callbacks;
-  char *client_id;
-  char error_string_ret[256];
-  char pid_str[64];
   EggDesktopFile *desktop_file;
   GPtrArray *clone, *restart;
+  char pid_str[64];
 
-  g_source_remove (xsmp->idle);
-  xsmp->idle = 0;
-
-  ice_init ();
-  SmcSetErrorHandler (smc_error_handler);
-
-  callbacks.save_yourself.callback      = xsmp_save_yourself;
-  callbacks.die.callback                = xsmp_die;
-  callbacks.save_complete.callback      = xsmp_save_complete;
-  callbacks.shutdown_cancelled.callback = xsmp_shutdown_cancelled;
-
-  callbacks.save_yourself.client_data      = xsmp;
-  callbacks.die.client_data                = xsmp;
-  callbacks.save_complete.client_data      = xsmp;
-  callbacks.shutdown_cancelled.client_data = xsmp;
-
-  client_id = NULL;
-  error_string_ret[0] = '\0';
-  xsmp->connection =
-    SmcOpenConnection (NULL, xsmp, SmProtoMajor, SmProtoMinor,
-		       SmcSaveYourselfProcMask | SmcDieProcMask |
-		       SmcSaveCompleteProcMask |
-		       SmcShutdownCancelledProcMask,
-		       &callbacks,
-		       xsmp->client_id, &client_id,
-		       sizeof (error_string_ret), error_string_ret);
-
-  if (!xsmp->connection)
-    {
-      g_warning ("Failed to connect to the session manager: %s\n",
-		 error_string_ret[0] ?
-		 error_string_ret : "no error message given");
-      xsmp->state = XSMP_STATE_CONNECTION_CLOSED;
-      return FALSE;
-    }
-
-  /* We expect a pointless initial SaveYourself if either (a) we
-   * didn't have an initial client ID, or (b) we DID have an initial
-   * client ID, but the server rejected it and gave us a new one.
-   */
-  if (!xsmp->client_id ||
-      (client_id && strcmp (xsmp->client_id, client_id) != 0))
-    xsmp->expecting_initial_save_yourself = TRUE;
-
-  if (client_id)
+  if (xsmp->idle)
     {
-      g_free (xsmp->client_id);
-      xsmp->client_id = g_strdup (client_id);
-      free (client_id);
-
-      gdk_threads_enter ();
-      gdk_set_sm_client_id (xsmp->client_id);
-      gdk_threads_leave ();
-
-      g_debug ("Got client ID \"%s\"", xsmp->client_id);
+      g_source_remove (xsmp->idle);
+      xsmp->idle = 0;
     }
+  xsmp->waiting_to_set_initial_properties = FALSE;
 
   if (egg_sm_client_get_mode () == EGG_SM_CLIENT_MODE_NO_RESTART)
     xsmp->restart_style = SmRestartNever;
@@ -300,7 +246,7 @@
 			 err->message);
 	      g_error_free (err);
 	    }
-          g_free (cmdline);
+	  g_free (cmdline);
 	}
     }
 
@@ -335,7 +281,7 @@
 		      NULL);
     }
 
-  xsmp->state = XSMP_STATE_IDLE;
+  update_pending_events (xsmp);
   return FALSE;
 }
 
@@ -367,19 +313,76 @@
 			const char  *client_id)
 {
   EggSMClientXSMP *xsmp = (EggSMClientXSMP *)client;
+  SmcCallbacks callbacks;
+  char *ret_client_id;
+  char error_string_ret[256];
 
-  xsmp->state = XSMP_STATE_START;
-  if (xsmp->client_id)
-    g_free (xsmp->client_id);
   xsmp->client_id = g_strdup (client_id);
 
-  /* Don't connect to the session manager until we reach the main
-   * loop, since the session manager may assume we're fully up and
-   * running once we connect. (This also gives the application a
-   * chance to call egg_set_desktop_file() before we set the initial
-   * properties.)
+  ice_init ();
+  SmcSetErrorHandler (smc_error_handler);
+
+  callbacks.save_yourself.callback      = xsmp_save_yourself;
+  callbacks.die.callback                = xsmp_die;
+  callbacks.save_complete.callback      = xsmp_save_complete;
+  callbacks.shutdown_cancelled.callback = xsmp_shutdown_cancelled;
+
+  callbacks.save_yourself.client_data      = xsmp;
+  callbacks.die.client_data                = xsmp;
+  callbacks.save_complete.client_data      = xsmp;
+  callbacks.shutdown_cancelled.client_data = xsmp;
+
+  client_id = NULL;
+  error_string_ret[0] = '\0';
+  xsmp->connection =
+    SmcOpenConnection (NULL, xsmp, SmProtoMajor, SmProtoMinor,
+		       SmcSaveYourselfProcMask | SmcDieProcMask |
+		       SmcSaveCompleteProcMask |
+		       SmcShutdownCancelledProcMask,
+		       &callbacks,
+		       xsmp->client_id, &ret_client_id,
+		       sizeof (error_string_ret), error_string_ret);
+
+  if (!xsmp->connection)
+    {
+      g_warning ("Failed to connect to the session manager: %s\n",
+		 error_string_ret[0] ?
+		 error_string_ret : "no error message given");
+      xsmp->state = XSMP_STATE_CONNECTION_CLOSED;
+      return;
+    }
+
+  /* We expect a pointless initial SaveYourself if either (a) we
+   * didn't have an initial client ID, or (b) we DID have an initial
+   * client ID, but the server rejected it and gave us a new one.
+   */
+  if (!xsmp->client_id ||
+      (ret_client_id && strcmp (xsmp->client_id, ret_client_id) != 0))
+    xsmp->expecting_initial_save_yourself = TRUE;
+
+  if (ret_client_id)
+    {
+      g_free (xsmp->client_id);
+      xsmp->client_id = g_strdup (ret_client_id);
+      free (ret_client_id);
+
+      gdk_threads_enter ();
+      gdk_set_sm_client_id (xsmp->client_id);
+      gdk_threads_leave ();
+
+      g_debug ("Got client ID \"%s\"", xsmp->client_id);
+    }
+
+  xsmp->state = XSMP_STATE_IDLE;
+
+  /* Do not set the initial properties until we reach the main loop,
+   * so that the application has a chance to call
+   * egg_set_desktop_file(). (This may also help the session manager
+   * have a better idea of when the application is fully up and
+   * running.)
    */
-  xsmp->idle = g_idle_add (sm_client_xsmp_connect, client);
+  xsmp->waiting_to_set_initial_properties = TRUE;
+  xsmp->idle = g_idle_add (sm_client_xsmp_set_initial_properties, client);
 }
 
 static void
@@ -469,11 +472,6 @@
 
       switch (xsmp->state)
 	{
-	case XSMP_STATE_START:
-	  /* Force the connection to complete (or fail) now. */
-	  sm_client_xsmp_connect (xsmp);
-	  break;
-
 	case XSMP_STATE_CONNECTION_CLOSED:
 	  return FALSE;
 
@@ -494,6 +492,9 @@
 	  return TRUE;
 
 	case XSMP_STATE_IDLE:
+	  if (xsmp->waiting_to_set_initial_properties)
+	    sm_client_xsmp_set_initial_properties (xsmp);
+
 	  if (!xsmp->expecting_initial_save_yourself)
 	    break;
 	  /* else fall through */
@@ -634,6 +635,9 @@
       return;
     }
 
+  if (xsmp->waiting_to_set_initial_properties)
+    sm_client_xsmp_set_initial_properties (xsmp);
+
   /* If this is the initial SaveYourself, ignore it; we've already set
    * properties and there's no reason to actually save state too.
    */

Modified: trunk/cut-n-paste-code/libegg/eggsmclient.c
==============================================================================
--- trunk/cut-n-paste-code/libegg/eggsmclient.c	(original)
+++ trunk/cut-n-paste-code/libegg/eggsmclient.c	Thu Oct  9 09:37:45 2008
@@ -189,6 +189,10 @@
   { "sm-client-id", 0, 0,
     G_OPTION_ARG_STRING, &sm_client_id,
     N_("Specify session management ID"), N_("ID") },
+  /* Compatibility options */
+  { "sm-disable", 0, G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_NONE, &sm_client_disable,
+    NULL, NULL },
   { NULL }
 };
 
@@ -263,7 +267,7 @@
  *    user is logging out, etc), but will request to not be
  *    automatically restarted with saved state in future sessions.
  *
- *    %EGG_SM_CLIENT_MODE_NORMAL: The default. #EggSMClient will
+ *    %EGG_SM_CLIENT_MODE_NORMAL: The default. #EggSMCLient will
  *    function normally.
  *
  * This must be called before the application's main loop begins.
@@ -314,16 +318,16 @@
 #elif defined (GDK_WINDOWING_QUARTZ)
 	  global_client = egg_sm_client_osx_new ();
 #else
-	  /* If both D-Bus and XSMP are compiled in, try D-Bus first
-	   * and fall back to XSMP if D-Bus session management isn't
-	   * available.
+	  /* If both D-Bus and XSMP are compiled in, try XSMP first
+	   * (since it supports state saving) and fall back to D-Bus
+	   * if XSMP isn't available.
 	   */
-# ifdef EGG_SM_CLIENT_BACKEND_DBUS
-	  global_client = egg_sm_client_dbus_new ();
-# endif
 # ifdef EGG_SM_CLIENT_BACKEND_XSMP
+	  global_client = egg_sm_client_xsmp_new ();
+# endif
+# ifdef EGG_SM_CLIENT_BACKEND_DBUS
 	  if (!global_client)
-	    global_client = egg_sm_client_xsmp_new ();
+	    global_client = egg_sm_client_dbus_new ();
 # endif
 #endif
 	}



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