[rygel] core: Thumbnailer should be singleton
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [rygel] core: Thumbnailer should be singleton
- Date: Tue, 8 Sep 2009 16:23:37 +0000 (UTC)
commit 89fafbabf642d201c8ea026dc3ad26032cf049cb
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Sep 8 16:47:18 2009 +0300
core: Thumbnailer should be singleton
src/rygel/rygel-http-server.vala | 13 ++++++-------
src/rygel/rygel-thumbnailer.vala | 19 ++++++++++++++++++-
2 files changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/src/rygel/rygel-http-server.vala b/src/rygel/rygel-http-server.vala
index 6e470a2..38b1d55 100644
--- a/src/rygel/rygel-http-server.vala
+++ b/src/rygel/rygel-http-server.vala
@@ -33,7 +33,6 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
public MediaContainer root_container;
public GUPnP.Context context;
private ArrayList<HTTPRequest> requests;
- private Thumbnailer thumbnailer;
private Cancellable cancellable;
@@ -47,12 +46,10 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
this.path_root = SERVER_PATH_PREFIX + "/" + name;
- try {
- this.thumbnailer = new Thumbnailer ();
+ var thumbnailer = Thumbnailer.get_default ();
+ if (thumbnailer != null) {
this.context.host_path (thumbnailer.directory,
this.path_root + "/thumbnails");
- } catch (ThumbnailerError err) {
- warning ("No thumbnailer available: %s", err.message);
}
}
@@ -86,13 +83,15 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
if (item.upnp_class.has_prefix (MediaItem.IMAGE_CLASS) ||
item.upnp_class.has_prefix (MediaItem.VIDEO_CLASS) &&
item.thumbnails.size == 0) {
+ var thumbnailer = Thumbnailer.get_default ();
+
// Lets see if we can provide the thumbnails
- if (this.thumbnailer != null) {
+ if (thumbnailer != null) {
foreach (var uri in item.uris) {
Thumbnail thumbnail = null;
try {
- thumbnail = this.thumbnailer.get_thumbnail (uri);
+ thumbnail = thumbnailer.get_thumbnail (uri);
thumbnail.add_resource (didl_item, "internal");
// Now create the HTTP URI
diff --git a/src/rygel/rygel-thumbnailer.vala b/src/rygel/rygel-thumbnailer.vala
index 40ae3dc..6918e21 100644
--- a/src/rygel/rygel-thumbnailer.vala
+++ b/src/rygel/rygel-thumbnailer.vala
@@ -31,12 +31,15 @@ internal errordomain ThumbnailerError {
* Provides thumbnails for images and vidoes.
*/
internal class Rygel.Thumbnailer : GLib.Object {
+ private static Thumbnailer thumbnailer; // Our singleton object
+ private static bool first_time = true;
+
public string directory;
private Thumbnail template;
private string extension;
- public Thumbnailer () throws ThumbnailerError {
+ private Thumbnailer () throws ThumbnailerError {
var dir = Path.build_filename (Environment.get_home_dir (),
".thumbnails",
"cropped");
@@ -70,6 +73,20 @@ internal class Rygel.Thumbnailer : GLib.Object {
this.directory = dir;
}
+ public static Thumbnailer? get_default () {
+ if (first_time) {
+ try {
+ thumbnailer = new Thumbnailer ();
+ } catch (ThumbnailerError err) {
+ warning ("No thumbnailer available: %s", err.message);
+ }
+
+ first_time = false;
+ }
+
+ return thumbnailer;
+ }
+
public Thumbnail get_thumbnail (string uri) throws ThumbnailerError {
Thumbnail thumbnail = null;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]