[rhythmbox] audioscrobbler: add border around all images displayed in profile source
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] audioscrobbler: add border around all images displayed in profile source
- Date: Tue, 21 Sep 2010 10:49:51 +0000 (UTC)
commit e2178ee4cafedcec06379bc6bac059ec325f3556
Author: Jamie Nicol <jamie thenicols net>
Date: Sat Jun 26 22:10:23 2010 +0100
audioscrobbler: add border around all images displayed in profile source
Pack GtkImage objects inside GtkViewport objects so the viewport's
shadow acts as a border.
plugins/audioscrobbler/audioscrobbler-profile.ui | 8 ++-
.../rb-audioscrobbler-profile-source.c | 84 +++++++++++--------
plugins/audioscrobbler/rb-audioscrobbler-user.c | 88 ++++++++------------
plugins/audioscrobbler/rb-audioscrobbler-user.h | 5 +-
4 files changed, 95 insertions(+), 90 deletions(-)
---
diff --git a/plugins/audioscrobbler/audioscrobbler-profile.ui b/plugins/audioscrobbler/audioscrobbler-profile.ui
index cd5fe62..ea582a9 100644
--- a/plugins/audioscrobbler/audioscrobbler-profile.ui
+++ b/plugins/audioscrobbler/audioscrobbler-profile.ui
@@ -10,8 +10,14 @@
<object class="GtkHBox" id="user_info_area">
<property name="visible">True</property>
<child>
- <object class="GtkImage" id="profile_image">
+ <object class="GtkViewport" id="viewport1">
<property name="visible">True</property>
+ <property name="resize_mode">queue</property>
+ <child>
+ <object class="GtkImage" id="profile_image">
+ <property name="visible">True</property>
+ </object>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
index 1ec475c..cacd862 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-profile-source.c
@@ -44,6 +44,7 @@
#include "rb-util.h"
#define CONF_AUDIOSCROBBLER_ENABLE_SCROBBLING CONF_PLUGINS_PREFIX "/audioscrobbler/%s/scrobbling_enabled"
+#define LIST_ITEM_IMAGE_SIZE 34
struct _RBAudioscrobblerProfileSourcePrivate {
RBAudioscrobblerService *service;
@@ -629,7 +630,9 @@ rb_audioscrobbler_profile_source_set_user_list (RBAudioscrobblerProfileSource *s
GList *button_node;
/* delete all existing buttons */
- for (button_node = gtk_container_get_children (GTK_CONTAINER (list_table)); button_node != NULL; button_node = g_list_next (button_node)) {
+ for (button_node = gtk_container_get_children (GTK_CONTAINER (list_table));
+ button_node != NULL;
+ button_node = g_list_next (button_node)) {
gtk_widget_destroy (button_node->data);
}
@@ -637,6 +640,10 @@ rb_audioscrobbler_profile_source_set_user_list (RBAudioscrobblerProfileSource *s
for (i = 0; i < list_data->len; i++) {
GtkWidget *button;
RBAudioscrobblerUserData *data;
+ char *button_text;
+ GtkWidget *label;
+ GtkWidget *label_alignment;
+ GtkWidget *button_contents;
button = gtk_button_new ();
gtk_button_set_alignment (GTK_BUTTON (button),
@@ -646,16 +653,12 @@ rb_audioscrobbler_profile_source_set_user_list (RBAudioscrobblerProfileSource *s
gtk_button_set_relief (GTK_BUTTON (button),
GTK_RELIEF_NONE);
- rb_audioscrobbler_profile_source_list_table_pack_start (GTK_TABLE (list_table), button);
-
data = g_ptr_array_index (list_data, i);
+ button_text = NULL;
if (data->type == RB_AUDIOSCROBBLER_USER_DATA_TYPE_TRACK) {
- char *button_text;
char *escaped_title_text;
char *escaped_artist_text;
- GtkWidget *contents;
- GtkWidget *label;
escaped_title_text = g_markup_escape_text (data->track.title, -1);
escaped_artist_text = g_markup_escape_text (data->track.artist, -1);
@@ -663,39 +666,52 @@ rb_audioscrobbler_profile_source_set_user_list (RBAudioscrobblerProfileSource *s
escaped_title_text,
escaped_artist_text);
- contents = gtk_hbox_new (FALSE, 4);
- if (data->track.image != NULL) {
- gtk_box_pack_start (GTK_BOX(contents),
- gtk_image_new_from_pixbuf (data->track.image),
- FALSE, FALSE, 0);
- }
- label = gtk_label_new ("");
- gtk_label_set_markup (GTK_LABEL (label), button_text);
- gtk_box_pack_start (GTK_BOX(contents),
- label,
- FALSE, FALSE, 0);
- gtk_container_add (GTK_CONTAINER (button), contents);
-
g_free (escaped_title_text);
g_free (escaped_artist_text);
- g_free (button_text);
} else if (data->type == RB_AUDIOSCROBBLER_USER_DATA_TYPE_ARTIST) {
- GtkWidget *contents;
- GtkWidget *label;
-
- contents = gtk_hbox_new (FALSE, 4);
- if (data->artist.image != NULL) {
- gtk_box_pack_start (GTK_BOX(contents),
- gtk_image_new_from_pixbuf (data->artist.image),
- FALSE, FALSE, 0);
- }
- label = gtk_label_new (data->artist.name);
- gtk_box_pack_start (GTK_BOX(contents),
- label,
+ button_text = g_markup_escape_text (data->artist.name, -1);
+ }
+
+ label = gtk_label_new ("");
+ gtk_label_set_markup (GTK_LABEL (label), button_text);
+ g_free (button_text);
+
+ label_alignment = gtk_alignment_new (0, 0.5, 0, 0);
+ gtk_container_add (GTK_CONTAINER (label_alignment), label);
+
+ button_contents = gtk_hbox_new (FALSE, 4);
+ if (data->image != NULL) {
+ GtkWidget *image;
+ GtkWidget *viewport;
+ GtkWidget *alignment;
+
+ image = gtk_image_new_from_pixbuf (data->image);
+
+ viewport = gtk_viewport_new (NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (viewport), image);
+
+ alignment = gtk_alignment_new (0, 0.5, 0, 0);
+ gtk_container_add (GTK_CONTAINER (alignment), viewport);
+
+ gtk_box_pack_start (GTK_BOX (button_contents),
+ alignment,
FALSE, FALSE, 0);
- gtk_container_add (GTK_CONTAINER (button), contents);
+
+
+ gtk_alignment_set_padding (GTK_ALIGNMENT (label_alignment),
+ 0, 0,
+ LIST_ITEM_IMAGE_SIZE - gdk_pixbuf_get_width (data->image), 0);
+ } else {
+ gtk_alignment_set_padding (GTK_ALIGNMENT (label_alignment), 0, 0, LIST_ITEM_IMAGE_SIZE + 4, 0);
}
+
+ gtk_box_pack_start (GTK_BOX (button_contents),
+ label_alignment,
+ FALSE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (button), button_contents);
+
+ rb_audioscrobbler_profile_source_list_table_pack_start (GTK_TABLE (list_table), button);
}
}
@@ -718,7 +734,7 @@ rb_audioscrobbler_profile_source_user_info_updated_cb (RBAudioscrobblerUser *use
gtk_link_button_set_uri (GTK_LINK_BUTTON (source->priv->view_profile_link),
data->user_info.url);
- gtk_image_set_from_pixbuf (GTK_IMAGE (source->priv->profile_image), data->user_info.image);
+ gtk_image_set_from_pixbuf (GTK_IMAGE (source->priv->profile_image), data->image);
gtk_widget_show_all (source->priv->user_info_area);
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-user.c b/plugins/audioscrobbler/rb-audioscrobbler-user.c
index ad06bb3..c621611 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-user.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-user.c
@@ -35,36 +35,33 @@
#include "rb-debug.h"
#include "rb-file-helpers.h"
-#define SMALL_IMAGE_SIZE 34
+#define USER_PROFILE_IMAGE_SIZE 126
+#define LIST_ITEM_IMAGE_SIZE 34
static RBAudioscrobblerUserData *
rb_audioscrobbler_user_data_copy (RBAudioscrobblerUserData *data)
{
RBAudioscrobblerUserData *d = g_slice_new0 (RBAudioscrobblerUserData);
+ d->type = data->type;
+ if (data->image != NULL) {
+ d->image = g_object_ref (data->image);
+ }
+
switch (d->type) {
case RB_AUDIOSCROBBLER_USER_DATA_TYPE_USER_INFO:
d->user_info.username = g_strdup (data->user_info.username);
d->user_info.url = g_strdup (data->user_info.url);
d->user_info.playcount = g_strdup (data->user_info.playcount);
- if (data->user_info.image != NULL) {
- d->user_info.image = g_object_ref (data->user_info.image);
- }
break;
case RB_AUDIOSCROBBLER_USER_DATA_TYPE_TRACK:
d->track.title = g_strdup (data->track.title);
d->track.artist = g_strdup (data->track.artist);
d->track.url = g_strdup (data->track.url);
- if (data->track.image != NULL) {
- d->track.image = g_object_ref (data->track.image);
- }
break;
case RB_AUDIOSCROBBLER_USER_DATA_TYPE_ARTIST:
d->artist.name = g_strdup (data->artist.name);
d->artist.url = g_strdup (data->artist.url);
- if (data->artist.image != NULL) {
- d->artist.image = g_object_ref (data->artist.image);
- }
break;
}
@@ -74,29 +71,23 @@ rb_audioscrobbler_user_data_copy (RBAudioscrobblerUserData *data)
static void
rb_audioscrobbler_user_data_free (RBAudioscrobblerUserData *data)
{
+ if (data->image != NULL) {
+ g_object_unref (data->image);
+ }
switch (data->type) {
case RB_AUDIOSCROBBLER_USER_DATA_TYPE_USER_INFO:
g_free (data->user_info.username);
g_free (data->user_info.url);
g_free (data->user_info.playcount);
- if (data->user_info.image != NULL) {
- g_object_unref (data->user_info.image);
- }
break;
case RB_AUDIOSCROBBLER_USER_DATA_TYPE_TRACK:
g_free (data->track.title);
g_free (data->track.artist);
g_free (data->track.url);
- if (data->track.image != NULL) {
- g_object_unref (data->track.image);
- }
break;
case RB_AUDIOSCROBBLER_USER_DATA_TYPE_ARTIST:
g_free (data->artist.name);
g_free (data->artist.url);
- if (data->track.image != NULL) {
- g_object_unref (data->artist.image);
- }
break;
}
@@ -691,8 +682,9 @@ rb_audioscrobbler_user_parse_user_info (RBAudioscrobblerUser *user, const char *
user_info->user_info.url = g_strdup (json_object_get_string_member (user_object, "url"));
user_info->user_info.playcount = g_strdup (json_object_get_string_member (user_object, "playcount"));
- user_info->user_info.image = gdk_pixbuf_new_from_file (rb_audioscrobbler_user_calculate_cached_image_path (user, user_info), NULL);
- if (user_info->user_info.image == NULL && json_object_has_member (user_object, "image") == TRUE) {
+ user_info->image = gdk_pixbuf_new_from_file_at_size (rb_audioscrobbler_user_calculate_cached_image_path (user, user_info),
+ USER_PROFILE_IMAGE_SIZE, -1, NULL);
+ if (user_info->image == NULL && json_object_has_member (user_object, "image") == TRUE) {
JsonArray *image_array;
JsonObject *image_object;
@@ -829,9 +821,9 @@ rb_audioscrobbler_user_parse_recent_tracks (RBAudioscrobblerUser *user, const ch
g_ptr_array_add (recent_tracks, track);
- track->track.image = gdk_pixbuf_new_from_file_at_size (rb_audioscrobbler_user_calculate_cached_image_path (user, track),
- SMALL_IMAGE_SIZE, SMALL_IMAGE_SIZE, NULL);
- if (track->track.image == NULL && json_object_has_member (track_object, "image") == TRUE) {
+ track->image = gdk_pixbuf_new_from_file_at_size (rb_audioscrobbler_user_calculate_cached_image_path (user, track),
+ LIST_ITEM_IMAGE_SIZE, LIST_ITEM_IMAGE_SIZE, NULL);
+ if (track->image == NULL && json_object_has_member (track_object, "image") == TRUE) {
JsonArray *image_array;
JsonObject *image_object;
@@ -969,9 +961,9 @@ rb_audioscrobbler_user_parse_top_tracks (RBAudioscrobblerUser *user, const char
g_ptr_array_add (top_tracks, track);
- track->track.image = gdk_pixbuf_new_from_file_at_size (rb_audioscrobbler_user_calculate_cached_image_path (user, track),
- SMALL_IMAGE_SIZE, SMALL_IMAGE_SIZE, NULL);
- if (track->track.image == NULL && json_object_has_member (track_object, "image") == TRUE) {
+ track->image = gdk_pixbuf_new_from_file_at_size (rb_audioscrobbler_user_calculate_cached_image_path (user, track),
+ LIST_ITEM_IMAGE_SIZE, LIST_ITEM_IMAGE_SIZE, NULL);
+ if (track->image == NULL && json_object_has_member (track_object, "image") == TRUE) {
JsonArray *image_array;
JsonObject *image_object;
@@ -1109,9 +1101,9 @@ rb_audioscrobbler_user_parse_loved_tracks (RBAudioscrobblerUser *user, const cha
g_ptr_array_add (loved_tracks, track);
- track->track.image = gdk_pixbuf_new_from_file_at_size (rb_audioscrobbler_user_calculate_cached_image_path (user, track),
- SMALL_IMAGE_SIZE, SMALL_IMAGE_SIZE, NULL);
- if (track->track.image == NULL && json_object_has_member (track_object, "image") == TRUE) {
+ track->image = gdk_pixbuf_new_from_file_at_size (rb_audioscrobbler_user_calculate_cached_image_path (user, track),
+ LIST_ITEM_IMAGE_SIZE, LIST_ITEM_IMAGE_SIZE, NULL);
+ if (track->image == NULL && json_object_has_member (track_object, "image") == TRUE) {
JsonArray *image_array;
JsonObject *image_object;
@@ -1246,9 +1238,9 @@ rb_audioscrobbler_user_parse_top_artists (RBAudioscrobblerUser *user, const char
g_ptr_array_add (top_artists, artist);
- artist->artist.image = gdk_pixbuf_new_from_file_at_size (rb_audioscrobbler_user_calculate_cached_image_path (user, artist),
- SMALL_IMAGE_SIZE, SMALL_IMAGE_SIZE, NULL);
- if (artist->artist.image == NULL && json_object_has_member (artist_object, "image") == TRUE) {
+ artist->image = gdk_pixbuf_new_from_file_at_size (rb_audioscrobbler_user_calculate_cached_image_path (user, artist),
+ LIST_ITEM_IMAGE_SIZE, LIST_ITEM_IMAGE_SIZE, NULL);
+ if (artist->image == NULL && json_object_has_member (artist_object, "image") == TRUE) {
JsonArray *image_array;
JsonObject *image_object;
@@ -1401,9 +1393,9 @@ rb_audioscrobbler_user_parse_recommended_artists (RBAudioscrobblerUser *user, co
g_ptr_array_add (recommended_artists, artist);
- artist->artist.image = gdk_pixbuf_new_from_file_at_size (rb_audioscrobbler_user_calculate_cached_image_path (user, artist),
- SMALL_IMAGE_SIZE, SMALL_IMAGE_SIZE, NULL);
- if (artist->artist.image == NULL && json_object_has_member (artist_object, "image") == TRUE) {
+ artist->image = gdk_pixbuf_new_from_file_at_size (rb_audioscrobbler_user_calculate_cached_image_path (user, artist),
+ LIST_ITEM_IMAGE_SIZE, LIST_ITEM_IMAGE_SIZE, NULL);
+ if (artist->image == NULL && json_object_has_member (artist_object, "image") == TRUE) {
JsonArray *image_array;
JsonObject *image_object;
@@ -1534,23 +1526,15 @@ rb_audioscrobbler_user_image_download_cb (GObject *source_object, GAsyncResult *
g_hash_table_remove (user->priv->file_to_data_map, src_file);
dest_file_path = rb_audioscrobbler_user_calculate_cached_image_path (user, data);
- if (data->type == RB_AUDIOSCROBBLER_USER_DATA_TYPE_USER_INFO) {
- if (data->user_info.image != NULL) {
- g_object_unref (data->user_info.image);
- }
- data->user_info.image = gdk_pixbuf_new_from_file (dest_file_path, NULL);
-
- } else if (data->type == RB_AUDIOSCROBBLER_USER_DATA_TYPE_TRACK) {
- if (data->track.image != NULL) {
- g_object_unref (data->track.image);
- }
- data->track.image = gdk_pixbuf_new_from_file_at_size (dest_file_path, SMALL_IMAGE_SIZE, SMALL_IMAGE_SIZE, NULL);
+ if (data->image != NULL) {
+ g_object_unref (data->image);
+ }
- } else if (data->type == RB_AUDIOSCROBBLER_USER_DATA_TYPE_ARTIST) {
- if (data->artist.image != NULL) {
- g_object_unref (data->artist.image);
- }
- data->artist.image = gdk_pixbuf_new_from_file_at_size (dest_file_path, SMALL_IMAGE_SIZE, SMALL_IMAGE_SIZE, NULL);
+ /* load image at correct size for the data type */
+ if (data->type == RB_AUDIOSCROBBLER_USER_DATA_TYPE_USER_INFO) {
+ data->image = gdk_pixbuf_new_from_file_at_size (dest_file_path, USER_PROFILE_IMAGE_SIZE, -1, NULL);
+ } else {
+ data->image = gdk_pixbuf_new_from_file_at_size (dest_file_path, LIST_ITEM_IMAGE_SIZE, LIST_ITEM_IMAGE_SIZE, NULL);
}
/* emit appropriate signal - quite ugly, surely this could be done in a nicer way */
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-user.h b/plugins/audioscrobbler/rb-audioscrobbler-user.h
index 7ecccdd..ad8b2bc 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-user.h
+++ b/plugins/audioscrobbler/rb-audioscrobbler-user.h
@@ -45,25 +45,24 @@ typedef struct {
RB_AUDIOSCROBBLER_USER_DATA_TYPE_ARTIST
} type;
+ GdkPixbuf *image;
+
union {
struct {
char *username;
char *url;
char *playcount;
- GdkPixbuf *image;
} user_info;
struct {
char *title;
char *artist;
char *url;
- GdkPixbuf *image;
} track;
struct {
char *name;
char *url;
- GdkPixbuf *image;
} artist;
};
} RBAudioscrobblerUserData;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]