totem r5847 - in trunk: . src



Author: hadess
Date: Wed Dec 10 23:28:22 2008
New Revision: 5847
URL: http://svn.gnome.org/viewvc/totem?rev=5847&view=rev

Log:
2008-12-10  Bastien Nocera  <hadess hadess net>

	* src/totem-uri.c (totem_uri_is_subtitle):
	* src/totem-uri.h: Add totem_uri_is_subtitle() to check
	whether a URI is a subtitle

	* src/totem-playlist.c (totem_playlist_set_current_subtitle):
	* src/totem-playlist.h: Add totem_playlist_set_current_subtitle()
	to set the subtitle for the currently playing movie

	* src/totem.c (totem_action_drop_files): When dropping files
	on the video widget, if there's only one file, and it looks
	like a subtitle, use it for the currently playing movie

	(Closes: #469566)



Modified:
   trunk/ChangeLog
   trunk/src/totem-playlist.c
   trunk/src/totem-playlist.h
   trunk/src/totem-uri.c
   trunk/src/totem-uri.h
   trunk/src/totem.c

Modified: trunk/src/totem-playlist.c
==============================================================================
--- trunk/src/totem-playlist.c	(original)
+++ trunk/src/totem-playlist.c	Wed Dec 10 23:28:22 2008
@@ -311,7 +311,7 @@
 			    PLAYING_COL, &playing,
 			    -1);
 
-	gtk_list_store_set (GTK_LIST_STORE(playlist->priv->model), &iter, 
+	gtk_list_store_set (GTK_LIST_STORE(playlist->priv->model), &iter,
 			    SUBTITLE_URI_COL, subtitle,
 			    -1);
 
@@ -324,6 +324,24 @@
 	g_free(subtitle);
 }
 
+void
+totem_playlist_set_current_subtitle (TotemPlaylist *playlist, const char *subtitle_uri)
+{
+	GtkTreeIter iter;
+
+	if (playlist->priv->current == NULL)
+		return;
+
+	gtk_tree_model_get_iter (playlist->priv->model, &iter, playlist->priv->current);
+
+	gtk_list_store_set (GTK_LIST_STORE(playlist->priv->model), &iter,
+			    SUBTITLE_URI_COL, subtitle_uri,
+			    -1);
+
+	g_signal_emit (G_OBJECT (playlist),
+		       totem_playlist_table_signals[SUBTITLE_CHANGED], 0,
+		       NULL);
+}
 
 /* This one returns a new string, in UTF8 even if the MRL is encoded
  * in the locale's encoding

Modified: trunk/src/totem-playlist.h
==============================================================================
--- trunk/src/totem-playlist.h	(original)
+++ trunk/src/totem-playlist.h	Wed Dec 10 23:28:22 2008
@@ -116,6 +116,8 @@
 gboolean   totem_playlist_set_title (TotemPlaylist *playlist,
 				     const char *title,
 				     gboolean force);
+void       totem_playlist_set_current_subtitle (TotemPlaylist *playlist,
+						const char *subtitle_uri);
 
 #define    totem_playlist_has_direction(playlist, direction) (direction == TOTEM_PLAYLIST_DIRECTION_NEXT ? totem_playlist_has_next_mrl (playlist) : totem_playlist_has_previous_mrl (playlist))
 gboolean   totem_playlist_has_previous_mrl (TotemPlaylist *playlist);

Modified: trunk/src/totem-uri.c
==============================================================================
--- trunk/src/totem-uri.c	(original)
+++ trunk/src/totem-uri.c	Wed Dec 10 23:28:22 2008
@@ -260,6 +260,21 @@
 	"ass"
 };
 
+gboolean
+totem_uri_is_subtitle (const char *uri)
+{
+	guint len, i;
+
+	len = strlen (uri);
+	if (len < 4 || uri[len - 4] != '.')
+		return FALSE;
+	for (i = 0; i < G_N_ELEMENTS (subtitle_ext); i++) {
+		if (g_str_has_suffix (uri, subtitle_ext[i]) != FALSE)
+			return TRUE;
+	}
+	return FALSE;
+}
+
 static inline gboolean
 totem_uri_exists (const char *uri)
 {

Modified: trunk/src/totem-uri.h
==============================================================================
--- trunk/src/totem-uri.h	(original)
+++ trunk/src/totem-uri.h	Wed Dec 10 23:28:22 2008
@@ -35,6 +35,7 @@
 char *		totem_create_full_path		(const char *path);
 GMount *	totem_get_mount_for_media	(const char *uri);
 gboolean	totem_playing_dvd		(const char *uri);
+gboolean	totem_uri_is_subtitle		(const char *uri);
 gboolean	totem_is_special_mrl		(const char *uri);
 gboolean	totem_is_block_device		(const char *uri);
 void		totem_setup_file_monitoring	(Totem *totem);

Modified: trunk/src/totem.c
==============================================================================
--- trunk/src/totem.c	(original)
+++ trunk/src/totem.c	Wed Dec 10 23:28:22 2008
@@ -1501,15 +1501,24 @@
 		int drop_type, gboolean empty_pl)
 {
 	char **list;
-	guint i;
+	guint i, len;
 	GList *p, *file_list;
 	gboolean cleared = FALSE;
 
 	list = g_uri_list_extract_uris ((const char *)data->data);
 	file_list = NULL;
 
-	for (i = 0; list[i] != NULL; ++i)
-		file_list = g_list_prepend (file_list, list[i]);
+	for (i = 0; list[i] != NULL; i++) {
+		char *filename;
+
+		if (list[i] == NULL)
+			continue;
+
+		filename = totem_create_full_path (list[i]);
+		file_list = g_list_prepend (file_list,
+					    filename ? filename : g_strdup (list[i]));
+	}
+	g_strfreev (list);
 
 	if (file_list == NULL)
 		return FALSE;
@@ -1521,20 +1530,23 @@
 	else
 		file_list = g_list_reverse (file_list);
 
-	for (p = file_list; p != NULL; p = p->next)
-	{
-		char *filename, *title;
+	/* How many files? Check whether those could be subtitles */
+	len = g_list_length (file_list);
+	if (len == 1 || (len == 2 && drop_type == 1)) {
+		if (totem_uri_is_subtitle (file_list->data) != FALSE) {
+			totem_playlist_set_current_subtitle (totem->playlist, file_list->data);
+			goto bail;
+		}
+	}
 
-		if (p->data == NULL)
-			continue;
+	for (p = file_list; p != NULL; p = p->next) {
+		const char *filename;
+		char *title;
 
-		filename = totem_create_full_path (p->data);
-		if (filename == NULL)
-			filename = g_strdup (p->data);
+		filename = p->data;
 		title = NULL;
 
-		if (empty_pl != FALSE && cleared == FALSE)
-		{
+		if (empty_pl != FALSE && cleared == FALSE) {
 			/* The function that calls us knows better
 			 * if we should be doing something with the 
 			 * changed playlist ... */
@@ -1546,11 +1558,10 @@
 		}
 
 		/* Super _NETSCAPE_URL trick */
-		if (drop_type == 1)
-		{
+		if (drop_type == 1) {
 			p = p->next;
 			if (p != NULL) {
-				if (g_str_has_prefix (p->data, "file:") != FALSE)
+				if (g_str_has_prefix (p->data, "File:") != FALSE)
 					title = (char *)p->data + 5;
 				else
 					title = p->data;
@@ -1558,11 +1569,10 @@
 		}
 
 		totem_playlist_add_mrl (totem->playlist, filename, title);
-
-		g_free (filename);
 	}
 
-	g_strfreev (list);
+bail:
+	g_list_foreach (file_list, (GFunc) g_free, NULL);
 	g_list_free (file_list);
 	gdk_window_set_cursor (totem->win->window, NULL);
 



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