[totem] grilo: Load icons for sources
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem] grilo: Load icons for sources
- Date: Fri, 17 Jan 2014 09:13:12 +0000 (UTC)
commit 49815afdd24b815b302e2faa5240254d9ba74da5
Author: Bastien Nocera <hadess hadess net>
Date: Fri Jan 17 00:53:00 2014 +0100
grilo: Load icons for sources
src/plugins/grilo/icon-helpers.c | 24 ++++++++++++++++++---
src/plugins/grilo/icon-helpers.h | 2 +-
src/plugins/grilo/totem-grilo.c | 41 +++++++++++++++++++++++++++++++------
3 files changed, 55 insertions(+), 12 deletions(-)
---
diff --git a/src/plugins/grilo/icon-helpers.c b/src/plugins/grilo/icon-helpers.c
index 3178229..68bb702 100644
--- a/src/plugins/grilo/icon-helpers.c
+++ b/src/plugins/grilo/icon-helpers.c
@@ -115,20 +115,36 @@ get_stream_thumbnail_cb (GObject *source_object,
}
void
-totem_grilo_get_thumbnail (GrlMedia *media,
+totem_grilo_get_thumbnail (GObject *object,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
- const char *url_thumb;
+ const char *url_thumb = NULL;
const GdkPixbuf *thumbnail;
GFile *file;
- url_thumb = grl_media_get_thumbnail (media);
+ if (GRL_IS_MEDIA (object))
+ url_thumb = grl_media_get_thumbnail (GRL_MEDIA (object));
+ else if (GRL_IS_SOURCE (object)) {
+ GIcon *icon;
+
+ icon = grl_source_get_icon (GRL_SOURCE (object));
+ if (icon) {
+ GFile *file;
+
+ file = g_file_icon_get_file (G_FILE_ICON (icon));
+ url_thumb = g_file_get_uri (file);
+ g_object_unref (file);
+ } else {
+ //FIXME
+ return;
+ }
+ }
g_return_if_fail (url_thumb != NULL);
- simple = g_simple_async_result_new (G_OBJECT (media),
+ simple = g_simple_async_result_new (G_OBJECT (object),
callback,
user_data,
totem_grilo_get_thumbnail);
diff --git a/src/plugins/grilo/icon-helpers.h b/src/plugins/grilo/icon-helpers.h
index dc29f3c..0920ef2 100644
--- a/src/plugins/grilo/icon-helpers.h
+++ b/src/plugins/grilo/icon-helpers.h
@@ -35,7 +35,7 @@ GdkPixbuf *totem_grilo_get_icon (GrlMedia *media,
const GdkPixbuf *totem_grilo_get_video_icon (void);
const GdkPixbuf *totem_grilo_get_box_icon (void);
-void totem_grilo_get_thumbnail (GrlMedia *media,
+void totem_grilo_get_thumbnail (GObject *object,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
diff --git a/src/plugins/grilo/totem-grilo.c b/src/plugins/grilo/totem-grilo.c
index 7e43122..5158ec0 100644
--- a/src/plugins/grilo/totem-grilo.c
+++ b/src/plugins/grilo/totem-grilo.c
@@ -138,6 +138,7 @@ typedef struct {
typedef struct {
TotemGriloPlugin *totem_grilo;
GrlMedia *media;
+ GrlSource *source;
GtkTreeModel *model;
GtkTreeRowReference *reference;
} SetThumbnailData;
@@ -241,18 +242,19 @@ get_thumbnail_cb (GObject *source_object,
if (GTK_IS_TREE_MODEL_FILTER (view_model)) {
path = gtk_tree_model_filter_convert_child_path_to_path (GTK_TREE_MODEL_FILTER (view_model),
path);
- if (gtk_tree_model_get_iter (view_model, &iter, path))
+ if (path != NULL && gtk_tree_model_get_iter (view_model, &iter, path))
gtk_tree_model_row_changed (view_model, path, &iter);
}
- gtk_tree_path_free (path);
+ g_clear_pointer (&path, gtk_tree_path_free);
out:
g_clear_error (&error);
/* Free thumb data */
g_object_unref (thumb_data->totem_grilo);
- g_object_unref (thumb_data->media);
+ g_clear_object (&thumb_data->media);
+ g_clear_object (&thumb_data->source);
g_object_unref (thumb_data->model);
gtk_tree_row_reference_free (thumb_data->reference);
g_slice_free (SetThumbnailData, thumb_data);
@@ -267,14 +269,33 @@ set_thumbnail_async (TotemGriloPlugin *self,
SetThumbnailData *thumb_data;
/* Let's read the thumbnail stream and set the thumbnail */
- thumb_data = g_slice_new (SetThumbnailData);
+ thumb_data = g_slice_new0 (SetThumbnailData);
thumb_data->totem_grilo = g_object_ref (self);
thumb_data->media = g_object_ref (media);
thumb_data->model = g_object_ref (model);
thumb_data->reference = gtk_tree_row_reference_new (model, path);
//FIXME cancellable?
- totem_grilo_get_thumbnail (media, NULL, get_thumbnail_cb, thumb_data);
+ totem_grilo_get_thumbnail (G_OBJECT (media), NULL, get_thumbnail_cb, thumb_data);
+}
+
+static void
+set_thumbnail_source_async (TotemGriloPlugin *self,
+ GrlSource *source,
+ GtkTreeModel *model,
+ GtkTreePath *path)
+{
+ SetThumbnailData *thumb_data;
+
+ /* Let's read the thumbnail stream and set the thumbnail */
+ thumb_data = g_slice_new0 (SetThumbnailData);
+ thumb_data->totem_grilo = g_object_ref (self);
+ thumb_data->source = g_object_ref (source);
+ thumb_data->model = g_object_ref (model);
+ thumb_data->reference = gtk_tree_row_reference_new (model, path);
+
+ //FIXME cancellable?
+ totem_grilo_get_thumbnail (G_OBJECT (source), NULL, get_thumbnail_cb, thumb_data);
}
static gboolean
@@ -282,6 +303,7 @@ update_search_thumbnails_idle (TotemGriloPlugin *self)
{
GtkTreePath *start_path;
GtkTreePath *end_path;
+ GrlSource *source;
gboolean is_prethumbnail = FALSE;
GtkTreeModel *view_model, *model;
GtkIconView *icon_view;
@@ -320,10 +342,14 @@ update_search_thumbnails_idle (TotemGriloPlugin *self)
gtk_tree_model_get (model,
&iter,
MODEL_RESULTS_CONTENT, &media,
+ MODEL_RESULTS_SOURCE, &source,
MODEL_RESULTS_IS_PRETHUMBNAIL, &is_prethumbnail,
-1);
- if (media != NULL && is_prethumbnail) {
- set_thumbnail_async (self, media, model, path);
+ if ((media != NULL || source != NULL) && is_prethumbnail) {
+ if (media)
+ set_thumbnail_async (self, media, model, path);
+ else
+ set_thumbnail_source_async (self, source, model, path);
gtk_tree_store_set (GTK_TREE_STORE (model),
&iter,
MODEL_RESULTS_IS_PRETHUMBNAIL, FALSE,
@@ -331,6 +357,7 @@ update_search_thumbnails_idle (TotemGriloPlugin *self)
}
g_clear_object (&media);
+ g_clear_object (&source);
}
gtk_tree_path_free (start_path);
gtk_tree_path_free (end_path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]