totem r5421 - in trunk: . browser-plugin src/backend



Author: hadess
Date: Fri May 23 14:18:49 2008
New Revision: 5421
URL: http://svn.gnome.org/viewvc/totem?rev=5421&view=rev

Log:
2008-05-23  Bastien Nocera  <hadess hadess net>

	* browser-plugin/totem-plugin-viewer.c
	(totem_embedded_launch_player), (totem_embedded_get_app_for_uri),
	(totem_embedded_update_menu), (on_open1_activate), (main):
	Use GIO and GDK to launch the full-blown player, startup notification
	only available with GTK+ 2.13 (Closes: #512587)
	* src/backend/bacon-video-widget-xine.c
	(bacon_video_widget_open_with_subtitle): Remove remains of gnome-vfs
	code, gvfs doesn't support passing credentials in the URI anyway
	* configure.in: Remove gnome-vfs deps, not used anymore



Modified:
   trunk/ChangeLog
   trunk/browser-plugin/totem-plugin-viewer.c
   trunk/configure.in
   trunk/src/backend/bacon-video-widget-xine.c

Modified: trunk/browser-plugin/totem-plugin-viewer.c
==============================================================================
--- trunk/browser-plugin/totem-plugin-viewer.c	(original)
+++ trunk/browser-plugin/totem-plugin-viewer.c	Fri May 23 14:18:49 2008
@@ -29,12 +29,11 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <gio/gio.h>
 #include <gdk/gdkx.h>
 #include <gtk/gtk.h>
 #include <gconf/gconf-client.h>
 
-#define SN_API_NOT_YET_FROZEN
-#include <libsn/sn.h>
 #include <gdk/gdk.h>
 #include <gdk/gdkkeysyms.h>
 
@@ -43,9 +42,6 @@
 
 #include <dbus/dbus-glib.h>
 
-#include <libgnomevfs/gnome-vfs.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
-
 #include "bacon-video-widget.h"
 #include "totem-interface.h"
 #include "totem-statusbar.h"
@@ -122,7 +118,7 @@
 	int num_items;
 
 	/* Open menu item */
-	GnomeVFSMimeApplication *app;
+	GAppInfo *app;
 	GtkWidget *menu_item;
 
 	/* Seek bits */
@@ -629,237 +625,19 @@
 	return TRUE;
 }
 
-/* Copied from nautilus-program-choosing.c */
-
-extern char **environ;
-
-/* Cut and paste from gdkspawn-x11.c */
-static gchar **
-my_gdk_spawn_make_environment_for_screen (GdkScreen  *screen,
-					  gchar     **envp)
-{
-  gchar **retval = NULL;
-  gchar  *display_name;
-  gint    display_index = -1;
-  gint    i, env_len;
-
-  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
-
-  if (envp == NULL)
-    envp = environ;
-
-  for (env_len = 0; envp[env_len]; env_len++)
-    if (strncmp (envp[env_len], "DISPLAY", strlen ("DISPLAY")) == 0)
-      display_index = env_len;
-
-  retval = g_new (char *, env_len + 1);
-  retval[env_len] = NULL;
-
-  display_name = gdk_screen_make_display_name (screen);
-
-  for (i = 0; i < env_len; i++)
-    if (i == display_index)
-      retval[i] = g_strconcat ("DISPLAY=", display_name, NULL);
-    else
-      retval[i] = g_strdup (envp[i]);
-
-  g_assert (i == env_len);
-
-  g_free (display_name);
-
-  return retval;
-}
-
-
-static void
-sn_error_trap_push (SnDisplay *display,
-		    Display   *xdisplay)
-{
-	gdk_error_trap_push ();
-}
-
-static void
-sn_error_trap_pop (SnDisplay *display,
-		   Display   *xdisplay)
-{
-	gdk_error_trap_pop ();
-}
-
-static char **
-make_spawn_environment_for_sn_context (SnLauncherContext *sn_context,
-				       char             **envp)
-{
-	char **retval;
-	int    i, j;
-
-	retval = NULL;
-	
-	if (envp == NULL) {
-		envp = environ;
-	}
-	
-	for (i = 0; envp[i]; i++) {
-		/* Count length */
-	}
-
-	retval = g_new (char *, i + 2);
-
-	for (i = 0, j = 0; envp[i]; i++) {
-		if (!g_str_has_prefix (envp[i], "DESKTOP_STARTUP_ID=")) {
-			retval[j] = g_strdup (envp[i]);
-			++j;
-	        }
-	}
-
-	retval[j] = g_strdup_printf ("DESKTOP_STARTUP_ID=%s",
-				     sn_launcher_context_get_startup_id (sn_context));
-	++j;
-	retval[j] = NULL;
-
-	return retval;
-}
-
-/* This should be fairly long, as it's confusing to users if a startup
- * ends when it shouldn't (it appears that the startup failed, and
- * they have to relaunch the app). Also the timeout only matters when
- * there are bugs and apps don't end their own startup sequence.
- *
- * This timeout is a "last resort" timeout that ignores whether the
- * startup sequence has shown activity or not.  Metacity and the
- * tasklist have smarter, and correspondingly able-to-be-shorter
- * timeouts. The reason our timeout is dumb is that we don't monitor
- * the sequence (don't use an SnMonitorContext)
- */
-#define STARTUP_TIMEOUT_LENGTH (30 /* seconds */ * 1000)
-
-typedef struct
-{
-	GdkScreen *screen;
-	GSList *contexts;
-	guint timeout_id;
-} StartupTimeoutData;
-
-static void
-free_startup_timeout (void *data)
-{
-	StartupTimeoutData *std;
-
-	std = data;
-
-	g_slist_foreach (std->contexts,
-			 (GFunc) sn_launcher_context_unref,
-			 NULL);
-	g_slist_free (std->contexts);
-
-	if (std->timeout_id != 0) {
-		g_source_remove (std->timeout_id);
-		std->timeout_id = 0;
-	}
-
-	g_free (std);
-}
-
-static gboolean
-startup_timeout (void *data)
-{
-	StartupTimeoutData *std;
-	GSList *tmp;
-	GTimeVal now;
-	int min_timeout;
-
-	std = data;
-
-	min_timeout = STARTUP_TIMEOUT_LENGTH;
-	
-	g_get_current_time (&now);
-	
-	tmp = std->contexts;
-	while (tmp != NULL) {
-		SnLauncherContext *sn_context;
-		GSList *next;
-		long tv_sec, tv_usec;
-		double elapsed;
-		
-		sn_context = tmp->data;
-		next = tmp->next;
-		
-		sn_launcher_context_get_last_active_time (sn_context,
-							  &tv_sec, &tv_usec);
-
-		elapsed =
-			((((double)now.tv_sec - tv_sec) * G_USEC_PER_SEC +
-			  (now.tv_usec - tv_usec))) / 1000.0;
-
-		if (elapsed >= STARTUP_TIMEOUT_LENGTH) {
-			std->contexts = g_slist_remove (std->contexts,
-							sn_context);
-			sn_launcher_context_complete (sn_context);
-			sn_launcher_context_unref (sn_context);
-		} else {
-			min_timeout = MIN (min_timeout, (STARTUP_TIMEOUT_LENGTH - elapsed));
-		}
-		
-		tmp = next;
-	}
-
-	if (std->contexts == NULL) {
-		std->timeout_id = 0;
-	} else {
-		std->timeout_id = g_timeout_add (min_timeout,
-						 startup_timeout,
-						 std);
-	}
-
-	/* always remove this one, but we may have reinstalled another one. */
-	return FALSE;
-}
-
-static void
-add_startup_timeout (GdkScreen         *screen,
-		     SnLauncherContext *sn_context)
-{
-	StartupTimeoutData *data;
-
-	data = g_object_get_data (G_OBJECT (screen), "nautilus-startup-data");
-	if (data == NULL) {
-		data = g_new (StartupTimeoutData, 1);
-		data->screen = screen;
-		data->contexts = NULL;
-		data->timeout_id = 0;
-		
-		g_object_set_data_full (G_OBJECT (screen),
-					"nautilus-startup-data",
-					data, free_startup_timeout);		
-	}
-
-	sn_launcher_context_ref (sn_context);
-	data->contexts = g_slist_prepend (data->contexts, sn_context);
-	
-	if (data->timeout_id == 0) {
-		data->timeout_id = g_timeout_add (STARTUP_TIMEOUT_LENGTH,
-						  startup_timeout,
-						  data);		
-	}
-}
-
 static gboolean
 totem_embedded_launch_player (TotemEmbedded *embedded,
-			      const char *uri,
- 			      guint32 user_time,
-			      GError *error)
+ 			      guint32 user_time)
 {
 	GList *uris = NULL;
 	GdkScreen *screen;
-	GnomeVFSResult result;
-	SnLauncherContext *sn_context;
-	SnDisplay *sn_display;
-	char **envp;
+	GAppLaunchContext *ctx;
+	gboolean result;
+	const char *uri;
 
 	g_return_val_if_fail (embedded->app != NULL, FALSE);
 
-	if (uri != NULL) {
-		uris = g_list_prepend (uris, (gpointer) uri);
-	} else if (embedded->type == TOTEM_PLUGIN_TYPE_NARROWSPACE
+	if (embedded->type == TOTEM_PLUGIN_TYPE_NARROWSPACE
 		   && embedded->href_uri != NULL) {
 		uris = g_list_prepend (uris, embedded->href_uri);
 		uri = embedded->href_uri;
@@ -868,75 +646,23 @@
 		uri = embedded->current_uri;
 	}
 
+#if GTK_CHECK_VERSION(2,13,0)
+	ctx = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
 	screen = gtk_widget_get_screen (embedded->window);
-	g_return_val_if_fail (screen != NULL, FALSE);
-	envp = my_gdk_spawn_make_environment_for_screen (screen, NULL);
-
-	sn_display = sn_display_new (gdk_display,
-				     sn_error_trap_push,
-				     sn_error_trap_pop);
-
-	if (gnome_vfs_mime_application_supports_startup_notification (embedded->app)) {
-		char *name;
-
-		sn_context = sn_launcher_context_new (sn_display,
-						      gdk_screen_get_number (screen));
-
-		name = g_filename_display_basename (uri);
-		if (name != NULL) {
-			char *description;
-
-			sn_launcher_context_set_name (sn_context, name);
-			description = g_strdup_printf (_("Opening %s"), name);
-			sn_launcher_context_set_description (sn_context,
-							     description);
-			g_free (name);
-			g_free (description);
-		}
+	gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (ctx), screen);
 
-		if (!sn_launcher_context_get_initiated (sn_context)) {
-			const char *binary_name;
-			char **old_envp;
-
-			binary_name = gnome_vfs_mime_application_get_binary_name
-				(embedded->app);
-
-			sn_launcher_context_set_binary_name (sn_context,
-							     binary_name);
-
-			sn_launcher_context_initiate (sn_context,
-						      g_get_prgname (),
-						      binary_name,
-						      (Time) user_time);
-
-			old_envp = envp;
-			envp = make_spawn_environment_for_sn_context
-				(sn_context, envp);
-			g_strfreev (old_envp);
-		}
-	} else {
-		sn_context = NULL;
-  	}
-  
-	result = gnome_vfs_mime_application_launch_with_env (embedded->app,
-							     uris, envp);
-
-	if (sn_context != NULL) {
-		if (result != GNOME_VFS_OK) {
-			/* end sequence */
-			sn_launcher_context_complete (sn_context);
-		} else {
-			add_startup_timeout (screen, sn_context);
-		}
-		sn_launcher_context_unref (sn_context);
-	}
+	gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (ctx), user_time);
+	gdk_app_launch_context_set_icon (GDK_APP_LAUNCH_CONTEXT (ctx), g_app_info_get_icon (embedded->app));
+#else
+	ctx = NULL;
+	screen = NULL;
+#endif
 
-	sn_display_unref (sn_display);
+	result = g_app_info_launch_uris (embedded->app, uris, ctx, NULL);
 
 	g_list_free (uris);
-	g_strfreev (envp);
 
-	return (result == GNOME_VFS_OK);
+	return result;
 }
 
 static void
@@ -1244,6 +970,19 @@
 	return TRUE;
 }
 
+static GAppInfo *
+totem_embedded_get_app_for_uri (const char *uri)
+{
+	char *type;
+	GAppInfo *info;
+
+	type = g_content_type_guess (uri, NULL, 0, NULL);
+	info = g_app_info_get_default_for_type (type, TRUE);
+	g_free (type);
+
+	return info;
+}
+
 static void
 totem_embedded_update_menu (TotemEmbedded *emb)
 {
@@ -1256,13 +995,12 @@
 		emb->menu_item = NULL;
 	}
 	if (emb->app != NULL) {
-		gnome_vfs_mime_application_free (emb->app);
+		g_object_unref (emb->app);
 		emb->app = NULL;
 	}
 
 	if (emb->mimetype && strcmp (emb->mimetype, "application/octet-stream") != 0) {
-		emb->app = gnome_vfs_mime_get_default_application_for_uri
-				(emb->current_uri, emb->mimetype);
+		emb->app = g_app_info_get_default_for_type (emb->mimetype, TRUE);
 	} else {
 		const char *uri;
 
@@ -1272,17 +1010,19 @@
 			uri = emb->stream_uri;
 		else
 			uri = emb->current_uri;
-		emb->app = gnome_vfs_mime_get_default_application_for_uri
-				(uri, gnome_vfs_get_mime_type_for_name (uri));
+		emb->app = totem_embedded_get_app_for_uri (uri);
 	}
 
 	if (emb->app == NULL) {
 		if (emb->mimetype != NULL) {
 			g_message ("Mimetype '%s' doesn't have a handler", emb->mimetype);
 		} else {
+			char *type;
+
+			type = g_content_type_guess (emb->current_uri, NULL, 0, NULL);
 			g_message ("No handler for URI '%s' (guessed mime-type '%s')",
-				   emb->current_uri,
-				   gnome_vfs_get_mime_type_for_name (emb->current_uri));
+				   emb->current_uri, type);
+			g_free (type);
 		}
 		return;
 	}
@@ -1290,7 +1030,7 @@
 	/* translators: this is:
 	 * Open With ApplicationName
 	 * as in nautilus' right-click menu */
-	label = g_strdup_printf (_("_Open with \"%s\""), emb->app->name);
+	label = g_strdup_printf (_("_Open with \"%s\""), g_app_info_get_name (emb->app));
 	item = gtk_image_menu_item_new_with_mnemonic (label);
 	g_free (label);
 	image = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
@@ -1309,7 +1049,7 @@
 {
 	GTimeVal val;
 	g_get_current_time (&val);
-	totem_embedded_launch_player (emb, NULL, val.tv_sec, NULL);
+	totem_embedded_launch_player (emb, val.tv_sec);
 	totem_embedded_stop (emb, NULL);
 }
 
@@ -2425,6 +2165,8 @@
 
 	/* FIXME: check the UA strings of the legacy plugins themselves */
 	/* FIXME: at least hxplayer seems to send different UAs depending on the protocol!? */
+	/* FIXME: this won't work with gvfs:
+	 * http://bugzilla.gnome.org/show_bug.cgi?id=534482 */
 	if (arg_user_agent != NULL) {
 		g_setenv ("GNOME_VFS_HTTP_USER_AGENT", arg_user_agent, TRUE);
 		g_free (arg_user_agent);
@@ -2432,7 +2174,6 @@
 	}
 
 	bacon_video_widget_init_backend (NULL, NULL);
-	gnome_vfs_init ();
 
 	dbus_g_object_type_install_info (TOTEM_TYPE_EMBEDDED,
 					 &dbus_glib_totem_embedded_object_info);

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Fri May 23 14:18:49 2008
@@ -176,7 +176,7 @@
 fi
 
 if test x$HAVE_GSTREAMER = xno; then
-	MM="libxine >= $XINE_REQS gconf-2.0 gnome-keyring-1 gnome-vfs-2.0"
+	MM="libxine >= $XINE_REQS gconf-2.0"
 	PKG_CHECK_MODULES(XINE, $MM, HAVE_XINE=yes,
 		[
 			AC_MSG_RESULT(no)
@@ -646,8 +646,6 @@
 if test "$enable_browser_plugins" = "yes" ; then
 	PKG_CHECK_MODULES([BROWSER_PLUGIN],
 		[glib-2.0
-		 gnome-vfs-2.0 >= $GNOMEVFS_REQS
-		 gnome-vfs-module-2.0 >= $GNOMEVFS_REQS
 		 gthread-2.0
 		 totem-plparser-mini >= $TOTEM_PLPARSER_REQS],
 		[],[enable_browser_plugins=no])

Modified: trunk/src/backend/bacon-video-widget-xine.c
==============================================================================
--- trunk/src/backend/bacon-video-widget-xine.c	(original)
+++ trunk/src/backend/bacon-video-widget-xine.c	Fri May 23 14:18:49 2008
@@ -49,12 +49,6 @@
 #define XINE_ENABLE_EXPERIMENTAL_FEATURES
 #include <xine.h>
 
-#ifndef HAVE_GTK_ONLY
-/* gnome keyring and vfs */
-#include <libgnomevfs/gnome-vfs.h>
-#include <gnome-keyring.h>
-#endif /* !HAVE_GTK_ONLY */
-
 #include "debug.h"
 #include "bacon-video-widget.h"
 #include "bacon-video-widget-common.h"
@@ -2368,57 +2362,6 @@
 	return TRUE;
 }
 
-#ifndef HAVE_GTK_ONLY
-/* Return a new MRL with a username and password embedded into it from the GNOME keychain.
- * This function should be called right before sending a URL to xine-lib. */
-static char *
-add_auth_to_uri (const char* mrl)
-{
-	if (g_str_has_prefix (mrl, "http:") != FALSE) {
-		guint port;
-		const char *host, *scheme, *user;
-		GList *items;
-		GnomeKeyringResult result;
-		GnomeVFSURI* uri;
-		
-		uri = gnome_vfs_uri_new (mrl);
-		if (uri == NULL)
-			return NULL;
-
-		host = gnome_vfs_uri_get_host_name (uri);
-		user = gnome_vfs_uri_get_user_name (uri);
-		port = gnome_vfs_uri_get_host_port (uri);
-		scheme = gnome_vfs_uri_get_scheme (uri);
-
-		result = gnome_keyring_find_network_password_sync (user, NULL,
-								   host ,NULL,
-								   scheme, NULL,
-								   port, &items);
-
-		if (result == GNOME_KEYRING_RESULT_OK && items != NULL) {
-			char *parsed_uri;
-			GnomeKeyringNetworkPasswordData *pwd_data;
-
-			pwd_data = items->data;
-
-			gnome_vfs_uri_set_user_name (uri, pwd_data->user);
-			gnome_vfs_uri_set_password (uri, pwd_data->password);
-
-			parsed_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
-
-			gnome_keyring_network_password_list_free (items);
-			gnome_vfs_uri_unref (uri);
-
-			return parsed_uri;
-		} else {
-			gnome_vfs_uri_unref (uri);
-		}
-	}
-
-	return NULL;
-}
-#endif /* !HAVE_GTK_ONLY */
-
 gboolean
 bacon_video_widget_open_with_subtitle (BaconVideoWidget *bvw, const char *mrl,
 		const char *subtitle_uri, GError **error)
@@ -2478,25 +2421,6 @@
 		err = xine_open (bvw->priv->stream, bvw->com->mrl);
 	}
 
-#ifndef HAVE_GTK_ONLY
-	/* If xine-lib reported a permission error, try to fetch credentials from the keychain and
-	 * try xine_open again. This only applies to HTTP for now */
-	if (err == 0 && g_str_has_prefix (mrl, "http:") != FALSE) {
-		xine_error (bvw, error);
-		
-		if (error != NULL && *error != NULL && g_error_matches (*error, BVW_ERROR, BVW_ERROR_FILE_PERMISSION)) {
-			char *authed_mrl;
-
-			authed_mrl = add_auth_to_uri (bvw->com->mrl);
-			if (authed_mrl != NULL) {
-				g_clear_error (error);
-				xine_close (bvw->priv->stream);
-				err = xine_open (bvw->priv->stream, authed_mrl);
-				g_free (authed_mrl);
-			}
-		}
-	}
-#endif /* !HAVE_GTK_ONLY */
 	xine_plugins_garbage_collector (bvw->priv->xine);
 
 	if (err == 0) {



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