[totem] main: Don't poke at web servers for info



commit 73c71a93b5d157653fc2c361c673ea814cac5247
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Mar 17 01:42:34 2011 +0000

    main: Don't poke at web servers for info
    
    When loading videos from some websites, through quvi, we
    already have a lot of information about the file, so we
    don't really need to go and look for that information
    ourselves.
    
    We now store the content-type of the stream in question, and
    don't hit the web server to fill in GtkRecent if that's the case.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=644949

 data/playlist.ui     |    2 ++
 src/totem-menu.c     |   34 +++++++++++++++++++++++++++++++---
 src/totem-menu.h     |    5 +++--
 src/totem-object.c   |   14 +++++++-------
 src/totem-playlist.c |   23 +++++++++++++++--------
 src/totem-playlist.h |    2 +-
 6 files changed, 59 insertions(+), 21 deletions(-)
---
diff --git a/data/playlist.ui b/data/playlist.ui
index 888d0b8..9fe6fc6 100644
--- a/data/playlist.ui
+++ b/data/playlist.ui
@@ -56,6 +56,8 @@
       <column type="gchararray"/>
       <!-- column-name gobject -->
       <column type="GObject"/>
+      <!-- column-name mime-type -->
+      <column type="gchararray"/>
     </columns>
   </object>
   <object class="GtkVBox" id="vbox4">
diff --git a/src/totem-menu.c b/src/totem-menu.c
index 3a8fb50..e08e0f5 100644
--- a/src/totem-menu.c
+++ b/src/totem-menu.c
@@ -382,12 +382,13 @@ on_recent_file_item_activated (GtkAction *action,
                                Totem *totem)
 {
 	GtkRecentInfo *recent_info;
-	const gchar *uri;
+	const gchar *uri, *display_name;
 
 	recent_info = g_object_get_data (G_OBJECT (action), "recent-info");
 	uri = gtk_recent_info_get_uri (recent_info);
+	display_name = gtk_recent_info_get_display_name (recent_info);
 
-	totem_add_to_playlist_and_play (totem, uri, NULL, FALSE);
+	totem_add_to_playlist_and_play (totem, uri, display_name, FALSE);
 }
 
 static gint
@@ -579,13 +580,40 @@ recent_info_cb (GFile *file,
 }
 
 void
-totem_action_add_recent (Totem *totem, const char *uri, const char *display_name)
+totem_action_add_recent (Totem      *totem,
+			 const char *uri,
+			 const char *display_name,
+			 const char *content_type)
 {
 	GFile *file;
 
 	if (totem_is_special_mrl (uri) != FALSE)
 		return;
 
+	/* If we already have a content-type, the display_name is
+	 * probably decent as well */
+	if (content_type != NULL) {
+		GtkRecentData data;
+		char *groups[] = { NULL, NULL };
+
+		memset (&data, 0, sizeof (data));
+
+		data.mime_type = (char *) content_type;
+		data.display_name = (char *) display_name;
+		groups[0] = (char*) "Totem";
+		data.app_name = (char *) g_get_application_name ();
+		data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
+		data.groups = groups;
+
+		if (gtk_recent_manager_add_full (totem->recent_manager,
+						 uri, &data) == FALSE) {
+			g_warning ("Couldn't add recent file for '%s'", uri);
+		}
+		g_free (data.app_exec);
+
+		return;
+	}
+
 	file = g_file_new_for_uri (uri);
 	g_object_set_data_full (G_OBJECT (file), "uri", g_strdup (uri), g_free);
 	g_object_set_data_full (G_OBJECT (file), "display_name", g_strdup (display_name), g_free);
diff --git a/src/totem-menu.h b/src/totem-menu.h
index ba93fa8..6275b5c 100644
--- a/src/totem-menu.h
+++ b/src/totem-menu.h
@@ -35,9 +35,10 @@ void totem_sublang_exit (Totem *totem);
 void totem_setup_play_disc (Totem *totem);
 
 void totem_setup_recent (Totem *totem);
-void totem_action_add_recent (Totem *totem,
+void totem_action_add_recent (Totem      *totem,
 			      const char *uri,
-			      const char *display_name);
+			      const char *display_name,
+			      const char *content_type);
 
 G_END_DECLS
 
diff --git a/src/totem-object.c b/src/totem-object.c
index 159fb05..22c234c 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -505,7 +505,7 @@ add_to_playlist_and_play_cb (TotemPlaylist *playlist, GAsyncResult *async_result
 	playlist_changed = totem_playlist_add_mrl_finish (playlist, async_result);
 
 	if (data->add_to_recent != FALSE)
-		totem_action_add_recent (data->totem, data->uri, data->display_name);
+		totem_action_add_recent (data->totem, data->uri, data->display_name, NULL);
 	end = totem_playlist_get_last (playlist);
 
 	totem_signal_unblock_by_data (playlist, data->totem);
@@ -635,8 +635,7 @@ totem_object_get_title_at_playlist_pos (TotemObject *totem, guint playlist_index
 char *
 totem_get_short_title (TotemObject *totem)
 {
-	gboolean custom;
-	return totem_playlist_get_current_title (totem->playlist, &custom);
+	return totem_playlist_get_current_title (totem->playlist, NULL);
 }
 
 /**
@@ -1688,7 +1687,7 @@ update_mrl_label (TotemObject *totem, const char *name)
  **/
 gboolean
 totem_action_set_mrl_with_warning (TotemObject *totem,
-				   const char *mrl, 
+				   const char *mrl,
 				   const char *subtitle,
 				   gboolean warn)
 {
@@ -1814,7 +1813,7 @@ totem_action_set_mrl_with_warning (TotemObject *totem,
 			totem->mrl = NULL;
 			bacon_video_widget_set_logo_mode (totem->bvw, TRUE);
 		} else {
-			char *display_name;
+			char *display_name, *content_type;
 			/* cast is to shut gcc up */
 			const GtkTargetEntry source_table[] = {
 				{ (gchar*) "text/uri-list", 0, 0 }
@@ -1828,9 +1827,10 @@ totem_action_set_mrl_with_warning (TotemObject *totem,
 					     source_table, G_N_ELEMENTS (source_table),
 					     GDK_ACTION_COPY);
 
-			display_name = totem_playlist_get_current_title (totem->playlist, NULL);
-			totem_action_add_recent (totem, totem->mrl, display_name);
+			display_name = totem_playlist_get_current_title (totem->playlist, &content_type);
+			totem_action_add_recent (totem, totem->mrl, display_name, content_type);
 			g_free (display_name);
+			g_free (content_type);
 		}
 	}
 	update_buttons (totem);
diff --git a/src/totem-playlist.c b/src/totem-playlist.c
index 40bcd9b..6f44487 100644
--- a/src/totem-playlist.c
+++ b/src/totem-playlist.c
@@ -40,7 +40,10 @@
 #define PL_LEN (gtk_tree_model_iter_n_children (playlist->priv->model, NULL))
 
 static void ensure_shuffled (TotemPlaylist *playlist);
-static gboolean totem_playlist_add_one_mrl (TotemPlaylist *playlist, const char *mrl, const char *display_name);
+static gboolean totem_playlist_add_one_mrl (TotemPlaylist *playlist,
+					    const char    *mrl,
+					    const char    *display_name,
+					    const char    *content_type);
 
 typedef gboolean (*ClearComparisonFunc) (TotemPlaylist *playlist, GtkTreeIter *iter, gconstpointer data);
 
@@ -143,6 +146,7 @@ enum {
 	TITLE_CUSTOM_COL,
 	SUBTITLE_URI_COL,
 	FILE_MONITOR_COL,
+	MIME_TYPE_COL,
 	NUM_COLS
 };
 
@@ -1562,7 +1566,7 @@ totem_playlist_entry_parsed (TotemPlParser *parser,
 			     GHashTable *metadata,
 			     TotemPlaylist *playlist)
 {
-	const char *title;
+	const char *title, *content_type;
 	gint64 duration;
 
 	/* We ignore 0-length items in playlists, they're usually just banners */
@@ -1571,7 +1575,8 @@ totem_playlist_entry_parsed (TotemPlParser *parser,
 	if (duration == 0)
 		return;
 	title = g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_TITLE);
-	totem_playlist_add_one_mrl (playlist, uri, title);
+	content_type = g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_CONTENT_TYPE);
+	totem_playlist_add_one_mrl (playlist, uri, title, content_type);
 }
 
 static gboolean
@@ -1746,7 +1751,8 @@ totem_playlist_new (void)
 static gboolean
 totem_playlist_add_one_mrl (TotemPlaylist *playlist,
 			    const char *mrl,
-			    const char *display_name)
+			    const char *display_name,
+			    const char *content_type)
 {
 	GtkListStore *store;
 	GtkTreeIter iter;
@@ -1803,6 +1809,7 @@ totem_playlist_add_one_mrl (TotemPlaylist *playlist,
 			URI_COL, uri ? uri : mrl,
 			TITLE_CUSTOM_COL, display_name ? TRUE : FALSE,
 			FILE_MONITOR_COL, monitor,
+			MIME_TYPE_COL, content_type,
 			-1);
 	g_free (escaped_filename);
 
@@ -1855,7 +1862,7 @@ static gboolean
 handle_parse_result (TotemPlParserResult res, TotemPlaylist *playlist, const gchar *mrl, const gchar *display_name)
 {
 	if (res == TOTEM_PL_PARSER_RESULT_UNHANDLED)
-		return totem_playlist_add_one_mrl (playlist, mrl, display_name);
+		return totem_playlist_add_one_mrl (playlist, mrl, display_name, NULL);
 	if (res == TOTEM_PL_PARSER_RESULT_ERROR) {
 		char *msg;
 
@@ -2470,7 +2477,7 @@ totem_playlist_get_current_mrl (TotemPlaylist *playlist, char **subtitle)
 }
 
 char *
-totem_playlist_get_current_title (TotemPlaylist *playlist, gboolean *custom)
+totem_playlist_get_current_title (TotemPlaylist *playlist, char **content_type)
 {
 	GtkTreeIter iter;
 	char *path;
@@ -2484,11 +2491,11 @@ totem_playlist_get_current_title (TotemPlaylist *playlist, gboolean *custom)
 			&iter,
 			playlist->priv->current);
 
-	if (custom != NULL) {
+	if (content_type != NULL) {
 		gtk_tree_model_get (playlist->priv->model,
 				    &iter,
 				    FILENAME_COL, &path,
-				    TITLE_CUSTOM_COL, custom,
+				    MIME_TYPE_COL, content_type,
 				    -1);
 	} else {
 		gtk_tree_model_get (playlist->priv->model,
diff --git a/src/totem-playlist.h b/src/totem-playlist.h
index 8d4f9d9..11305f9 100644
--- a/src/totem-playlist.h
+++ b/src/totem-playlist.h
@@ -131,7 +131,7 @@ void       totem_playlist_clear_with_g_mount (TotemPlaylist *playlist,
 char      *totem_playlist_get_current_mrl (TotemPlaylist *playlist,
 					   char **subtitle);
 char      *totem_playlist_get_current_title (TotemPlaylist *playlist,
-					     gboolean *custom);
+					     char         **content_type);
 char      *totem_playlist_get_title (TotemPlaylist *playlist,
 				     guint title_index);
 



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