From d15bffa872c136c174eee0cfbde20d3ea54ee5d5 Mon Sep 17 00:00:00 2001 From: Jens Georg Date: Sun, 10 May 2009 17:30:20 +0200 Subject: [PATCH] Remove MediaItem subclass A special media item is no longer needed since commit 5da6e0be3c9d1162b9a39802157b1fd4facce86c --- src/plugins/folder/Makefile.am | 5 +- .../rygel-folder-directory-search-result.vala | 46 ++++++++-- .../folder/rygel-folder-gio-media-item.vala | 98 ---------------------- 3 files changed, 38 insertions(+), 111 deletions(-) delete mode 100644 src/plugins/folder/rygel-folder-gio-media-item.vala diff --git a/src/plugins/folder/Makefile.am b/src/plugins/folder/Makefile.am index 61eab36..66d7d98 100644 --- a/src/plugins/folder/Makefile.am +++ b/src/plugins/folder/Makefile.am @@ -13,7 +13,6 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ BUILT_SOURCES = rygel-folder-root-container.c \ rygel-folder-container.c \ rygel-folder-directory-search-result.c \ - rygel-folder-gio-media-item.c \ rygel-folder-plugin.c $(BUILT_SOURCES) : rygel-media-folder.stamp @@ -26,9 +25,7 @@ librygel_media_folder_la_SOURCES = \ rygel-folder-container.c \ rygel-folder-container.vala \ rygel-folder-directory-search-result.c \ - rygel-folder-directory-search-result.vala \ - rygel-folder-gio-media-item.c \ - rygel-folder-gio-media-item.vala + rygel-folder-directory-search-result.vala rygel-media-folder.stamp: $(filter %.vala,$(librygel_media_folder_la_SOURCES)) $(VALAC) -g -C --vapidir=$(top_srcdir)/src/rygel \ diff --git a/src/plugins/folder/rygel-folder-directory-search-result.vala b/src/plugins/folder/rygel-folder-directory-search-result.vala index ac194d5..1fdd781 100644 --- a/src/plugins/folder/rygel-folder-directory-search-result.vala +++ b/src/plugins/folder/rygel-folder-directory-search-result.vala @@ -67,13 +67,9 @@ public class Rygel.FolderDirectorySearchResult : f); } else { - try { - item = FolderGioMediaItem.create ( - (MediaContainer) source_object, - f, - file_info); - } catch (Error error) { - } + item = get_media_item ((MediaContainer) source_object, + f, + file_info); } if (item != null) { @@ -89,8 +85,7 @@ public class Rygel.FolderDirectorySearchResult : null, enumerator_closed); } - } - catch (Error e) { + } catch (Error e) { this.error = e; this.complete (); } @@ -119,6 +114,39 @@ public class Rygel.FolderDirectorySearchResult : return children; } + + private MediaItem? get_media_item (MediaContainer parent, + File file, + FileInfo info) { + string content_type = info.get_content_type (); + string item_class = null; + string id = Checksum.compute_for_string (ChecksumType.MD5, + info.get_name ()); + + // use heuristics based on content type; will use MediaHarvester + // when it's ready + + if (content_type.has_prefix ("video/")) { + item_class = MediaItem.VIDEO_CLASS; + } else if (content_type.has_prefix ("audio/")) { + item_class = MediaItem.AUDIO_CLASS; + } else if (content_type.has_prefix ("image/")) { + item_class = MediaItem.IMAGE_CLASS; + } + + if (null == item_class) { + return null; + } + + MediaItem item = new Rygel.MediaItem (id, + parent, + info.get_name (), + item_class); + item.mime_type = content_type; + item.uris.add (GLib.Markup.escape_text (file.get_uri ())); + + return item; + } } diff --git a/src/plugins/folder/rygel-folder-gio-media-item.vala b/src/plugins/folder/rygel-folder-gio-media-item.vala deleted file mode 100644 index d410091..0000000 --- a/src/plugins/folder/rygel-folder-gio-media-item.vala +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2009 Jens Georg . - * - * This file is part of Rygel. - * - * Rygel is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Rygel is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -using GLib; -using Rygel; -using Gst; - -/** - * Very simple media item. - */ -public class Rygel.FolderGioMediaItem : Rygel.MediaItem { - private bool need_source; - private string raw_uri; - - private static string? get_upnp_class (string content_type) { - if (content_type.has_prefix ("video/")) { - return MediaItem.VIDEO_CLASS; - } else if (content_type.has_prefix ("audio/")) { - return MediaItem.AUDIO_CLASS; - } else if (content_type.has_prefix ("image/")) { - return MediaItem.IMAGE_CLASS; - } - - return null; - } - - - public static FolderGioMediaItem? create(MediaContainer parent, - File file, - FileInfo file_info) { - var upnp_class = get_upnp_class (file_info.get_content_type ()); - if (upnp_class != null) { - return new FolderGioMediaItem (parent, - file, - upnp_class, - file_info); - } - - return null; - } - - public FolderGioMediaItem(MediaContainer parent, - File file, - string item_class, - FileInfo file_info) { - - base (Checksum.compute_for_string (ChecksumType.MD5, - file_info.get_name ()), - parent, - file_info.get_name (), - item_class); - - var content_type = file_info.get_content_type (); - need_source = false; - - - this.mime_type = content_type; - // check if rygel can handle this uri type itself - if (file.get_uri ().has_prefix ("file:") || - file.get_uri ().has_prefix ("http:")) { - this.uris.add (GLib.Markup.escape_text (file.get_uri ())); - } - else { - need_source = true; - raw_uri = file.get_uri (); - } - } - - public override Gst.Element? create_stream_source () { - if (need_source) { - dynamic Element src = ElementFactory.make ("giosrc", null); - if (src != null) { - src.location = raw_uri; - } - - return src; - } - - return null; - } -} -- 2.7.4