From: Julien M. <do...@us...> - 2003-04-13 21:22:18
|
CVS Root: /cvsroot/gstreamer Module: gst-player Changes by: dolphy Date: Sun Apr 13 2003 14:22:17 PDT Log message: make Uraeus happy : drag n drop works Modified files: libs/gst/player : gstmediaplay.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-player/libs/gst/player/gstmediaplay.c.diff?r1=1.108&r2=1.109 ====Begin Diffs==== Index: gstmediaplay.c =================================================================== RCS file: /cvsroot/gstreamer/gst-player/libs/gst/player/gstmediaplay.c,v retrieving revision 1.108 retrieving revision 1.109 diff -u -d -r1.108 -r1.109 --- gstmediaplay.c 13 Apr 2003 09:56:46 -0000 1.108 +++ gstmediaplay.c 13 Apr 2003 21:22:04 -0000 1.109 @@ -38,6 +38,10 @@ #include "gstplayer-marshal.h" #include "gtk-playlist.h" +static const GtkTargetEntry target_table[] = { + { "text/uri-list", 0, 0 }, +}; + static GtkVBoxClass *parent_class = NULL; enum { @@ -312,7 +316,6 @@ GST_VIDEO_WIDGET(mplay->video_widget), xid); } - } static void @@ -344,6 +347,105 @@ } +static gboolean +gst_media_play_add_droped_files ( GstMediaPlay *mplay, + GtkSelectionData *data, + gboolean empty_pl) +{ + GList *list, *p, *file_list; + gboolean cleared = FALSE; + + list = gnome_vfs_uri_list_parse (data->data); + + if (list == NULL) + return FALSE; + + p = list; + file_list = NULL; + + while (p != NULL) + { + file_list = g_list_prepend (file_list, + gnome_vfs_uri_to_string + ((const GnomeVFSURI*)(p->data), 0)); + p = p->next; + } + + gnome_vfs_uri_list_free (list); + file_list = g_list_reverse (file_list); + + if (file_list == NULL) + return FALSE; + + for (p = file_list; p != NULL; p = p->next) + { + char *filename; + + if (p->data == NULL) + continue; + + /* We can't use g_filename_from_uri, as we don't know if + * the uri is in locale or UTF8 encoding */ + filename = gnome_vfs_get_local_path_from_uri (p->data); + if (filename == NULL) + filename = g_strdup (p->data); + + if (filename != NULL && + (g_file_test (filename, G_FILE_TEST_IS_REGULAR + | G_FILE_TEST_EXISTS) + || strstr (filename, "://") != NULL)) + { + if (empty_pl == TRUE && cleared == FALSE) + { + /* The function that calls us knows better + * if we should be doing something with the + * changed playlist ... */ + g_signal_handlers_disconnect_by_func + (G_OBJECT (mplay->playlist), + gst_media_play_playlist_changed, (gpointer) mplay); + gtk_playlist_clear (GTK_PLAYLIST(mplay->playlist)); + cleared = TRUE; + } + gtk_playlist_add_mrl ( GTK_PLAYLIST(mplay->playlist), + filename, NULL); + } + g_free (filename); + g_free (p->data); + } + + g_list_free (file_list); + + /* ... and reconnect because we're nice people */ + if (cleared == TRUE) + { + g_signal_connect (G_OBJECT (mplay->playlist), + "changed", G_CALLBACK (gst_media_play_playlist_changed), + (gpointer) mplay); + gst_media_play_set_location ( + mplay, + gtk_playlist_get_current_mrl (GTK_PLAYLIST(mplay->playlist))); + gst_media_play_toggle_play_pause (GTK_WIDGET (mplay), mplay); + } + + return TRUE; +} + +static void +gst_media_play_drop_files ( GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *data, + guint info, + guint time, + GstMediaPlay *mplay) +{ + gboolean retval; + + retval = gst_media_play_add_droped_files (mplay, data, TRUE); + gtk_drag_finish (context, retval, FALSE, time); +} + static gint gst_media_play_motion_notify_callback ( GtkWidget *widget, GdkEventMotion *event, @@ -783,21 +885,27 @@ /* Control signals */ g_signal_connect (G_OBJECT (mplay->control), "fullscreen_toggled", - G_CALLBACK (gst_media_play_display_mode_changed), mplay); + G_CALLBACK (gst_media_play_display_mode_changed), mplay); g_signal_connect (G_OBJECT (mplay->control), "toggle_play", - G_CALLBACK (gst_media_play_toggle_play_pause), mplay); + G_CALLBACK (gst_media_play_toggle_play_pause), mplay); g_signal_connect (G_OBJECT (mplay->control), "toggle_playlist", - G_CALLBACK (gst_media_play_toggle_playlist), mplay); + G_CALLBACK (gst_media_play_toggle_playlist), mplay); g_signal_connect (G_OBJECT (mplay->control), "clicked_next", - G_CALLBACK (gst_media_play_next), mplay); + G_CALLBACK (gst_media_play_next), mplay); g_signal_connect (G_OBJECT (mplay->control), "clicked_previous", - G_CALLBACK (gst_media_play_previous), mplay); + G_CALLBACK (gst_media_play_previous), mplay); g_signal_connect (G_OBJECT (mplay->control), "stop", - G_CALLBACK (gst_media_play_stop), mplay); + G_CALLBACK (gst_media_play_stop), mplay); g_signal_connect (G_OBJECT (mplay->control), "volume_change", - G_CALLBACK (gst_media_play_volume_changed), mplay); + G_CALLBACK (gst_media_play_volume_changed), mplay); g_signal_connect (G_OBJECT (mplay->control), "seek_change", - G_CALLBACK (gst_media_play_seek_to_pos), mplay); + G_CALLBACK (gst_media_play_seek_to_pos), mplay); + + g_signal_connect (G_OBJECT (mplay), "drag_data_received", + G_CALLBACK (gst_media_play_drop_files), mplay); + + gtk_drag_dest_set (GTK_WIDGET(mplay), GTK_DEST_DEFAULT_ALL, + target_table, 1, GDK_ACTION_COPY); mplay->display_mode = GST_MEDIA_PLAY_NORMAL; |