commit bec268fa95093b8ca5e87b8e86721f7b237382c5
Author: phantomjinx <p.g.richard...@phantomjinx.co.uk>
Date:   Thu Sep 8 21:04:36 2011 +0100

    Implement the updating of a track in clarity
    
    * If a track has been changed, clarity should react and if necessary update
      the artwork cover accordingly. This may mean changing the artwork, text
      or moving the track completely to a new album item.
    
    * AlbumItem
     * data reference no longer necessary
    
    * clarity_canvas
     * Formally defines the FLOOR constant better to understand the location
       set or each cover
    
    * Support for shift + mouse-button-1 to select the tracks referenced by the
      cover art.

 plugins/clarity/album_model.c            |   19 +++-
 plugins/clarity/album_model.h            |    4 +-
 plugins/clarity/clarity_canvas.c         |  240 ++++++++++++++++++++++--------
 plugins/clarity/clarity_canvas.h         |    4 +
 plugins/clarity/clarity_context_menu.c   |   72 ++++------
 plugins/clarity/clarity_context_menu.h   |   12 +-
 plugins/clarity/clarity_cover.c          |   45 +++++--
 plugins/clarity/clarity_cover.h          |    4 +
 plugins/clarity/clarity_widget.c         |   84 +++++------
 plugins/cover_display/display_coverart.c |    3 +-
 plugins/details_editor/details.c         |    1 +
 11 files changed, 322 insertions(+), 166 deletions(-)
---
diff --git a/plugins/clarity/album_model.c b/plugins/clarity/album_model.c
index 2779f6a..7c4b5b2 100644
--- a/plugins/clarity/album_model.c
+++ b/plugins/clarity/album_model.c
@@ -30,6 +30,7 @@
 #define ALBUM_MODEL_C_
 
 #include "album_model.h"
+#include "clarity_utils.h"
 #include "libgtkpod/prefs.h"
 #include "libgtkpod/misc.h"
 #include "libgtkpod/gp_private.h"
@@ -142,6 +143,10 @@ static gboolean _insert_track(AlbumModelPrivate *priv, 
Track *track) {
     AlbumItem *item;
     gchar *album_key;
 
+    Updating tracks by removing then adding is not working as the item
+    is never removed so the album item image is never updated!
+
+
     album_key = _create_key_from_track(track);
     /* Check whether an album item has already been created in connection
      * with the track's artist and album
@@ -181,7 +186,6 @@ static void album_model_free_album_item(AlbumItem *item) {
         if (item->albumart)
             g_object_unref(item->albumart);
 
-        item->data = NULL;
     }
 }
 
@@ -323,6 +327,19 @@ void album_model_foreach (AlbumModel *model, AMFunc func, 
gpointer user_data) {
     }
 }
 
+void album_model_init_coverart(AlbumModel *model, AlbumItem *item) {
+    g_return_if_fail(item);
+
+    Track *track = g_list_nth_data(item->tracks, 0);
+
+    if (item->albumart) {
+        g_object_unref(item->albumart);
+        item->albumart = NULL;
+    }
+
+    item->albumart = _get_track_image(track);
+}
+
 AlbumItem *album_model_get_item_with_index(AlbumModel *model, gint index) {
     g_return_val_if_fail(model, NULL);
 
diff --git a/plugins/clarity/album_model.h b/plugins/clarity/album_model.h
index 00acc8b..617a6cb 100644
--- a/plugins/clarity/album_model.h
+++ b/plugins/clarity/album_model.h
@@ -41,8 +41,6 @@ typedef struct {
     gchar *artist;
     GdkPixbuf *albumart;
 
-    gpointer data;
-
 } AlbumItem;
 
 typedef void (*AMFunc) (gpointer value, gint index, gpointer user_data);
@@ -107,6 +105,8 @@ gboolean album_model_add_track(AlbumModel *model, Track 
*track);
  */
 gboolean album_model_remove_track(AlbumModel *model, AlbumItem *item, Track 
*track);
 
+void album_model_init_coverart(AlbumModel *model, AlbumItem *item);
+
 AlbumItem *album_model_get_item_with_index(AlbumModel *model, gint index);
 
 AlbumItem *album_model_get_item_with_track(AlbumModel *model, Track *track);
diff --git a/plugins/clarity/clarity_canvas.c b/plugins/clarity/clarity_canvas.c
index 26b86fe..865a114 100644
--- a/plugins/clarity/clarity_canvas.c
+++ b/plugins/clarity/clarity_canvas.c
@@ -27,11 +27,14 @@
  */
 #include <clutter-gtk/clutter-gtk.h>
 #include "libgtkpod/gp_itdb.h"
+#include "libgtkpod/fileselection.h"
+#include "libgtkpod/misc.h"
 #include "plugin.h"
 #include "clarity_cover.h"
 #include "clarity_canvas.h"
 #include "clarity_preview.h"
 #include "clarity_utils.h"
+#include "clarity_context_menu.h"
 
 G_DEFINE_TYPE( ClarityCanvas, clarity_canvas, GTK_TYPE_BOX);
 
@@ -43,6 +46,7 @@ G_DEFINE_TYPE( ClarityCanvas, clarity_canvas, GTK_TYPE_BOX);
 #define FRONT_COVER_SPACE     150
 #define MAX_SCALE                          1.4
 #define VISIBLE_ITEMS                     8
+#define FLOOR                              110
 
 struct _ClarityCanvasPrivate {
 
@@ -99,12 +103,46 @@ static void clarity_canvas_class_init(ClarityCanvasClass 
*klass) {
     g_type_class_add_private(klass, sizeof(ClarityCanvasPrivate));
 }
 
-static gboolean _preview_cover_cb(GtkWidget *widget, GdkEvent *event, gpointer 
user_data) {
-    ClarityCanvas *ccanvas = CLARITY_CANVAS(widget);
-    ClarityCanvasPrivate *priv = ccanvas->priv;
+static void _update_text(ClarityCanvasPrivate *priv) {
+    g_return_if_fail(priv);
+
+    if (g_list_length(priv->covers) == 0)
+            return;
+
+    ClarityCover *ccover = g_list_nth_data(priv->covers, priv->curr_index);
+
+    gchar *title = clarity_cover_get_title(ccover);
+    gchar *artist = clarity_cover_get_artist(ccover);
+
+    clutter_text_set_text(CLUTTER_TEXT(priv->title_text), title);
+    clutter_text_set_text(CLUTTER_TEXT(priv->artist_text), artist);
+
+    g_free(title);
+    g_free(artist);
 
+    clutter_actor_raise_top(priv->title_text);
+    clutter_actor_raise_top(priv->artist_text);
+
+    gfloat artistx = (clutter_actor_get_width(priv->artist_text) / 2) * -1;
+    gfloat artisty = FLOOR - (clarity_cover_get_artwork_height(ccover) * 
MAX_SCALE);
+    clutter_actor_set_position(priv->artist_text, artistx, artisty);
+
+    gfloat titlex = (clutter_actor_get_width(priv->title_text) / 2) * -1;
+    gfloat titley = artisty - clutter_actor_get_height(priv->artist_text) - 2;
+    clutter_actor_set_position(priv->title_text, titlex, titley);
+}
+
+static void _set_loading_complete(ClarityCanvasPrivate *priv, gboolean value) {
+    priv->loading_complete = value;
+
+    if (value) {
+        _update_text(priv);
+    }
+}
+
+static void _preview_cover(ClarityCanvasPrivate *priv) {
     if (!priv->model)
-        return TRUE;
+        return;
 
     AlbumItem *item = album_model_get_item_with_index(priv->model, 
priv->curr_index);
 
@@ -112,8 +150,58 @@ static gboolean _preview_cover_cb(GtkWidget *widget, 
GdkEvent *event, gpointer u
 
     /* Display the dialog */
     gtk_widget_show_all(dialog);
+}
+
+/**
+ * on_main_cover_image_clicked_cb:
+ *
+ * Call handler used for displaying the tracks associated with
+ * the main displayed album cover.
+ *
+ * @ClarityCanvas
+ * @event: event object used to determine the event type
+ * @data: any data needed by the function (not required)
+ *
+ */
+static gint _on_main_cover_image_clicked_cb(GtkWidget *widget, GdkEvent 
*event, gpointer data) {
+    ClarityCanvas *ccanvas = CLARITY_CANVAS(widget);
+    ClarityCanvasPrivate *priv = ccanvas->priv;
+    guint mbutton;
+
+    if (event->type != GDK_BUTTON_PRESS)
+            return FALSE;
+
+    mbutton = event->button.button;
+
+    if ((mbutton == 1) && (event->button.state & GDK_SHIFT_MASK)) {
+        _set_loading_complete(priv, FALSE);
+
+        AlbumItem *item = album_model_get_item_with_index(priv->model, 
priv->curr_index);
+        if (item) {
+            gtkpod_set_displayed_tracks(item->tracks);
+        }
 
-    return TRUE;
+        _set_loading_complete(priv, TRUE);
+    }
+    else if (mbutton == 1) {
+        _preview_cover(priv);
+    }
+    else if ((mbutton == 3) && (event->button.state & GDK_SHIFT_MASK)) {
+        /* Right mouse button clicked and shift pressed.
+         * Go straight to edit details window
+         */
+        AlbumItem *item = album_model_get_item_with_index(priv->model, 
priv->curr_index);
+        GList *tracks = item->tracks;
+        gtkpod_edit_details(tracks);
+    }
+    else if (mbutton == 3) {
+        /* Right mouse button clicked on its own so display
+         * popup menu
+         */
+        clarity_context_menu_init(ccanvas);
+    }
+
+    return FALSE;
 }
 
 /**
@@ -154,7 +242,7 @@ static void clarity_canvas_init(ClarityCanvas *self) {
     clutter_actor_set_reactive(priv->container, TRUE);
     priv->preview_signal = g_signal_connect (self,
                                 "button-press-event",
-                                G_CALLBACK (_preview_cover_cb),
+                                G_CALLBACK (_on_main_cover_image_clicked_cb),
                                 priv);
     clutter_container_add(CLUTTER_CONTAINER(priv->container), 
priv->title_text, priv->artist_text, NULL);
 
@@ -345,35 +433,6 @@ static gint _calculate_index_opacity (gint 
dist_from_front) {
     return CLAMP ( 255 * (VISIBLE_ITEMS - ABS(dist_from_front)) / 
VISIBLE_ITEMS, 0, 255);
 }
 
-static void _update_text(ClarityCanvasPrivate *priv) {
-    g_return_if_fail(priv);
-
-    if (g_list_length(priv->covers) == 0)
-            return;
-
-    ClarityCover *ccover = g_list_nth_data(priv->covers, priv->curr_index);
-
-    gchar *title = clarity_cover_get_title(ccover);
-    gchar *artist = clarity_cover_get_artist(ccover);
-
-    clutter_text_set_text(CLUTTER_TEXT(priv->title_text), title);
-    clutter_text_set_text(CLUTTER_TEXT(priv->artist_text), artist);
-
-    g_free(title);
-    g_free(artist);
-
-    clutter_actor_raise_top(priv->title_text);
-    clutter_actor_raise_top(priv->artist_text);
-
-    gfloat artistx = (clutter_actor_get_width(priv->artist_text) / 2) * -1;
-    gfloat artisty = ((clutter_actor_get_height(CLUTTER_ACTOR(ccover)) / 2) - 
25) * -1;
-    clutter_actor_set_position(priv->artist_text, artistx, artisty);
-
-    gfloat titlex = (clutter_actor_get_width(priv->title_text) / 2) * -1;
-    gfloat titley = artisty - clutter_actor_get_height(priv->artist_text) - 2;
-    clutter_actor_set_position(priv->title_text, titlex, titley);
-}
-
 static void _display_clarity_cover(ClarityCover *ccover, gint index) {
     ClutterTimeline  *timeline = clutter_timeline_new(1600 * 5);
     ClutterAlpha *alpha = clutter_alpha_new_full (timeline, 
CLUTTER_EASE_OUT_EXPO);
@@ -383,12 +442,12 @@ static void _display_clarity_cover(ClarityCover *ccover, 
gint index) {
     clutter_timeline_start (timeline);
 }
 
-static void _set_loading_complete(ClarityCanvasPrivate *priv, gboolean value) {
-    priv->loading_complete = value;
-
-    if (value) {
-        _update_text(priv);
-    }
+static void _set_cover_position(ClarityCover *ccover, gint index) {
+    gint pos = _calculate_index_distance(index);
+    clutter_actor_set_position(
+                    CLUTTER_ACTOR(ccover),
+                    pos - clarity_cover_get_artwork_width(ccover) / 2,
+                    FLOOR - clarity_cover_get_artwork_height(ccover));
 }
 
 static gboolean _create_cover_actors(ClarityCanvasPrivate *priv, AlbumItem 
*album_item, gint index) {
@@ -406,11 +465,7 @@ static gboolean _create_cover_actors(ClarityCanvasPrivate 
*priv, AlbumItem *albu
 
     clarity_cover_set_album_item(ccover, album_item);
 
-    gint pos = _calculate_index_distance(index);
-    clutter_actor_set_position(
-                CLUTTER_ACTOR(ccover),
-                pos - clutter_actor_get_width(CLUTTER_ACTOR(ccover)) / 2,
-                110 - clutter_actor_get_height(CLUTTER_ACTOR(ccover)));
+    _set_cover_position(ccover, index);
 
     if((priv->curr_index + VISIBLE_ITEMS < index) ||
             (priv->curr_index - VISIBLE_ITEMS > index)) {
@@ -435,8 +490,8 @@ static gboolean _create_cover_actors(ClarityCanvasPrivate 
*priv, AlbumItem *albu
             CLUTTER_ACTOR(ccover),
             scale,
             scale,
-            clutter_actor_get_width(CLUTTER_ACTOR(ccover)) / 2,
-            clutter_actor_get_height(CLUTTER_ACTOR(ccover)) / 2);
+            clarity_cover_get_artwork_width(ccover) / 2,
+            clarity_cover_get_artwork_height(ccover) / 2);
 
     clutter_actor_lower_bottom(CLUTTER_ACTOR(ccover));
 
@@ -452,9 +507,7 @@ void _init_album_item(gpointer value, gint index, gpointer 
user_data) {
     ClarityCanvas *cc = CLARITY_CANVAS(user_data);
     ClarityCanvasPrivate *priv = CLARITY_CANVAS_GET_PRIVATE(cc);
 
-    Track *track = g_list_nth_data(item->tracks, 0);
-    item->albumart = _get_track_image(track);
-    item->data = cc;
+    album_model_init_coverart(priv->model, item);
 
     _create_cover_actors(priv, item, index);
 }
@@ -516,18 +569,17 @@ static void _clear_rotation_behaviours(GList *covers) {
 static void _animate_indices(ClarityCanvasPrivate *priv, gint direction, gint 
increment) {
 
     for (gint i = 0; i < g_list_length(priv->covers); ++i) {
-
         ClarityCover *ccover = g_list_nth_data(priv->covers, i);
 
         gint dist = i - priv->curr_index + (direction * increment);
-        gfloat depth = 1;
+        gfloat scale = 1;
         gint pos = 0;
         gint opacity = 0;
         gint angle = 0;
         ClutterRotateDirection rotation_dir;
 
         opacity = _calculate_index_opacity(dist);
-        depth = _calculate_index_scale(dist);
+        scale = _calculate_index_scale(dist);
         pos = _calculate_index_distance(dist);
         _calculate_index_angle_and_dir(dist, direction, &angle, &rotation_dir);
 
@@ -539,13 +591,17 @@ static void _animate_indices(ClarityCanvasPrivate *priv, 
gint direction, gint in
                         "opacity", opacity,
                         NULL);
 
+        gfloat w = clarity_cover_get_artwork_width(ccover);
+        gfloat h = clarity_cover_get_artwork_height(ccover);
+
         /* Position and scale */
         clutter_actor_animate_with_alpha (CLUTTER_ACTOR(ccover), priv->alpha,
-                        "scale-x",          depth,
-                        "scale-y",          depth,
-                        "scale-center-x" ,  
clutter_actor_get_width(CLUTTER_ACTOR(ccover)) / 2,
-                        "scale-center-y" ,  
clutter_actor_get_height(CLUTTER_ACTOR(ccover)) / 2,
-                        "x", pos - 
clutter_actor_get_width(CLUTTER_ACTOR(ccover)) / 2,
+                        "scale-x",          scale,
+                        "scale-y",          scale,
+                        "scale-center-x" ,  w / 2,
+                        "scale-center-y", h / 2,
+                        "x", pos - (w / 2),
+                        "y", FLOOR - h,
                         NULL);
      }
 }
@@ -661,3 +717,69 @@ void clarity_canvas_remove_album_item(ClarityCanvas *self, 
AlbumItem *item) {
 
     _set_loading_complete(priv, TRUE);
 }
+
+void clarity_canvas_update(ClarityCanvas *cc, AlbumItem *item) {
+    g_return_if_fail(cc);
+
+    ClarityCanvasPrivate *priv = CLARITY_CANVAS_GET_PRIVATE(cc);
+
+    gint index = album_model_get_index_with_album_item(priv->model, item);
+
+    _set_loading_complete(priv, FALSE);
+
+    album_model_init_coverart(priv->model, item);
+
+    ClarityCover *ccover = (ClarityCover *) g_list_nth_data(priv->covers, 
index);
+    if (!ccover)
+        return;
+
+    clarity_cover_set_album_item(ccover, item);
+
+    _set_cover_position(ccover, index);
+
+    _animate_indices(priv, 0, 0);
+
+    _set_loading_complete(priv, TRUE);
+}
+
+static void _set_cover_from_file(ClarityCanvas *self) {
+    g_return_if_fail(self);
+
+    ClarityCanvasPrivate *priv = CLARITY_CANVAS_GET_PRIVATE(self);
+
+    gchar *filename;
+    Track *track;
+    GList *tracks;
+
+    filename = fileselection_get_cover_filename();
+
+    if (filename) {
+        AlbumItem *item = album_model_get_item_with_index(priv->model, 
priv->curr_index);
+        tracks = g_list_copy(item->tracks);
+
+        while (tracks) {
+            track = tracks->data;
+
+            if (gp_track_set_thumbnails(track, filename)) {
+                ExtraTrackData *etd;
+                etd = track->userdata;
+                etd->tartwork_changed = TRUE;
+
+                gtkpod_track_updated(track);
+                data_changed(track->itdb);
+
+                etd->tartwork_changed = FALSE;
+            }
+
+            tracks = tracks->next;
+        }
+    }
+
+    g_free(filename);
+}
+
+void on_clarity_set_cover_menuitem_activate(GtkMenuItem *mi, gpointer data) {
+    g_return_if_fail(CLARITY_IS_CANVAS(data));
+
+    _set_cover_from_file(CLARITY_CANVAS(data));
+}
diff --git a/plugins/clarity/clarity_canvas.h b/plugins/clarity/clarity_canvas.h
index 3a1a691..e5bc41b 100644
--- a/plugins/clarity/clarity_canvas.h
+++ b/plugins/clarity/clarity_canvas.h
@@ -92,6 +92,10 @@ void clarity_canvas_add_album_item(ClarityCanvas *self, 
AlbumItem *item);
 
 void clarity_canvas_remove_album_item(ClarityCanvas *self, AlbumItem *item);
 
+void clarity_canvas_update(ClarityCanvas *cc, AlbumItem *item);
+
+void on_clarity_set_cover_menuitem_activate(GtkMenuItem *mi, gpointer data);
+
 G_END_DECLS
 
 #endif /* CLARITY_CANVAS_H_ */
diff --git a/plugins/clarity/clarity_context_menu.c 
b/plugins/clarity/clarity_context_menu.c
index aeea9ea..a863d9d 100644
--- a/plugins/clarity/clarity_context_menu.c
+++ b/plugins/clarity/clarity_context_menu.c
@@ -34,47 +34,33 @@
 #include "libgtkpod/context_menus.h"
 #include "libgtkpod/misc.h"
 #include "clarity_context_menu.h"
+#include "clarity_canvas.h"
 
-//static GtkWidget *add_get_cover_from_file(GtkWidget *menu) {
-//    return hookup_menu_item(menu, _("Select Cover From File"), 
GTK_STOCK_FLOPPY, G_CALLBACK (clarity_set_cover_from_file), NULL);
-//}
-//
-///*
-// * display the dialog with the full size cd artwork cover
-// * @mi - the menu item selected
-// * @data - Ignored, should be NULL
-// */
-//static void display_track_artwork(GtkMenuItem *mi, gpointer data) {
-//    if (gtkpod_get_selected_tracks())
-//        clarity_display_big_artwork(gtkpod_get_selected_tracks());
-//}
-//
-//static GtkWidget *add_display_big_coverart(GtkWidget *menu) {
-//    return hookup_menu_item(menu, _("View Full Size Artwork"), 
GTK_STOCK_FULLSCREEN, G_CALLBACK (display_track_artwork), NULL);
-//}
-//
-///**
-// * cad_context_menu_init - initialize the right click menu for coverart 
display
-// */
-//void cad_context_menu_init(void) {
-//    if (widgets_blocked)
-//        return;
-//
-//    GtkWidget *menu = NULL;
-//
-//    if (gtkpod_get_selected_tracks()) {
-//        menu = gtk_menu_new();
-//
-//        add_get_cover_from_file(menu);
-//        add_display_big_coverart(menu);
-//        add_edit_track_details(menu);
-//
-//        /*
-//         * button should be button 0 as per the docs because we're calling
-//         * from a button release event
-//         */
-//        if (menu) {
-//            gtk_menu_popup(GTK_MENU (menu), NULL, NULL, NULL, NULL, 0, 
gtk_get_current_event_time());
-//        }
-//    }
-//}
+static GtkWidget *add_get_cover_from_file(GtkWidget *menu, ClarityCanvas 
*ccanvas) {
+    return hookup_menu_item(menu, _("Select Cover From File"), 
GTK_STOCK_FLOPPY, G_CALLBACK (on_clarity_set_cover_menuitem_activate), ccanvas);
+}
+
+/**
+ * clarity_context_menu_init - initialize the right click menu for clarity
+ */
+void clarity_context_menu_init(ClarityCanvas *ccanvas) {
+    if (widgets_blocked)
+        return;
+
+    GtkWidget *menu = NULL;
+
+    if (gtkpod_get_selected_tracks()) {
+        menu = gtk_menu_new();
+
+        add_get_cover_from_file(menu, ccanvas);
+        add_edit_track_details(menu);
+
+        /*
+         * button should be button 0 as per the docs because we're calling
+         * from a button release event
+         */
+        if (menu) {
+            gtk_menu_popup(GTK_MENU (menu), NULL, NULL, NULL, NULL, 0, 
gtk_get_current_event_time());
+        }
+    }
+}
diff --git a/plugins/clarity/clarity_context_menu.h 
b/plugins/clarity/clarity_context_menu.h
index a2b4606..ce38587 100644
--- a/plugins/clarity/clarity_context_menu.h
+++ b/plugins/clarity/clarity_context_menu.h
@@ -26,12 +26,14 @@
  |
  */
 
-#ifndef COVER_DISPLAY_CONTEXT_MENU_H_
-#define COVER_DISPLAY_CONTEXT_MENU_H_
+#ifndef CLARITY_CONTEXT_MENU_H_
+#define CLARTIY_CONTEXT_MENU_H_
+
+#include "clarity_canvas.h"
 
 /**
- * cad_context_menu_init - initialize the right click menu for coverart display
+ * clarity_context_menu_init - initialize the right click menu for clarity
  */
-void cad_context_menu_init(void);
+void clarity_context_menu_init(ClarityCanvas *ccanvas);
 
-#endif /* COVER_DISPLAY_CONTEXT_MENU_H_ */
+#endif /* CLARITY_CONTEXT_MENU_H_ */
diff --git a/plugins/clarity/clarity_cover.c b/plugins/clarity/clarity_cover.c
index d5d44e6..32e3943 100644
--- a/plugins/clarity/clarity_cover.c
+++ b/plugins/clarity/clarity_cover.c
@@ -233,9 +233,13 @@ void clarity_cover_set_album_item (ClarityCover *self, 
AlbumItem *item) {
     GError *error = NULL;
     gint y_offset;
 
-    priv->texture = gtk_clutter_texture_new();
-    gtk_clutter_texture_set_from_pixbuf (GTK_CLUTTER_TEXTURE(priv->texture), 
item->albumart, &error);
+    if (!priv->texture) {
+        priv->texture = gtk_clutter_texture_new();
+        clutter_container_add_actor(CLUTTER_CONTAINER(self), priv->texture);
+    }
 
+    // Set cover artwork
+    gtk_clutter_texture_set_from_pixbuf (GTK_CLUTTER_TEXTURE(priv->texture), 
item->albumart, &error);
     if (error) {
         g_warning(error->message);
         g_error_free(error);
@@ -243,19 +247,21 @@ void clarity_cover_set_album_item (ClarityCover *self, 
AlbumItem *item) {
     }
 
     // Add reflection
-    y_offset = clutter_actor_get_height (priv->texture) + V_PADDING;
-
-    priv->reflection = clutter_clone_new (priv->texture);
-    clutter_actor_add_constraint (priv->reflection, 
clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_X, 0.0));
-    clutter_actor_add_constraint (priv->reflection, 
clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_Y, y_offset));
-    clutter_actor_add_constraint (priv->reflection, 
clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_WIDTH, 0.0));
-    clutter_actor_add_constraint (priv->reflection, 
clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_HEIGHT, 0.0));
-    g_signal_connect (priv->reflection,
+    if (! priv->reflection) {
+        y_offset = clutter_actor_get_height (priv->texture) + V_PADDING;
+
+        priv->reflection = clutter_clone_new (priv->texture);
+        clutter_actor_add_constraint (priv->reflection, 
clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_X, 0.0));
+        clutter_actor_add_constraint (priv->reflection, 
clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_Y, y_offset));
+        clutter_actor_add_constraint (priv->reflection, 
clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_WIDTH, 0.0));
+        clutter_actor_add_constraint (priv->reflection, 
clutter_bind_constraint_new (priv->texture, CLUTTER_BIND_HEIGHT, 0.0));
+        g_signal_connect (priv->reflection,
                        "paint",
                        G_CALLBACK (_clone_paint_cb),
                        NULL);
 
-    clutter_container_add(CLUTTER_CONTAINER(self), priv->texture, 
priv->reflection, NULL);
+        clutter_container_add_actor(CLUTTER_CONTAINER(self), priv->reflection);
+    }
 
     ClutterActorBox box;
     gfloat w, h;
@@ -268,7 +274,14 @@ void clarity_cover_set_album_item (ClarityCover *self, 
AlbumItem *item) {
     }
 
     // Add title / artist data
+    if (priv->title)
+        g_free(priv->title);
+
     priv->title = g_strdup(item->albumname);
+
+    if (priv->artist)
+            g_free(priv->artist);
+
     priv->artist = g_strdup(item->artist);
 }
 
@@ -320,6 +333,16 @@ gchar *clarity_cover_get_artist(ClarityCover *self) {
     return g_strdup(priv->artist);
 }
 
+gfloat clarity_cover_get_artwork_height(ClarityCover *self) {
+    ClarityCoverPrivate *priv = self->priv;
+    return clutter_actor_get_height(priv->texture);
+}
+
+gfloat clarity_cover_get_artwork_width(ClarityCover *self) {
+    ClarityCoverPrivate *priv = self->priv;
+    return clutter_actor_get_width(priv->texture);
+}
+
 /**
  * clarity_cover_new:
  *
diff --git a/plugins/clarity/clarity_cover.h b/plugins/clarity/clarity_cover.h
index 8b8f18b..3f52dfa 100644
--- a/plugins/clarity/clarity_cover.h
+++ b/plugins/clarity/clarity_cover.h
@@ -105,6 +105,10 @@ gchar *clarity_cover_get_title(ClarityCover *self);
 
 gchar *clarity_cover_get_artist(ClarityCover *self);
 
+gfloat clarity_cover_get_artwork_height(ClarityCover *self);
+
+gfloat clarity_cover_get_artwork_width(ClarityCover *self);
+
 /* constructor - note this returns a ClutterActor instance */
 ClarityCover *clarity_cover_new (void);
 
diff --git a/plugins/clarity/clarity_widget.c b/plugins/clarity/clarity_widget.c
index ca50d74..b379f23 100644
--- a/plugins/clarity/clarity_widget.c
+++ b/plugins/clarity/clarity_widget.c
@@ -541,72 +541,70 @@ void clarity_widget_track_updated_cb(GtkPodApp *app, 
gpointer tk, gpointer data)
     if (clarity_canvas_is_loading(ccanvas))
         return;
 
-    AlbumItem *item;
-    gboolean findremove = FALSE;
+    AlbumItem *item = NULL;
 
     gint index = album_model_get_index_with_track(priv->album_model, track);
-    if (index == -1) {
-        /* The track's key could not be found according to the track!
-         * The ONLY way this could happen is if the user changed the
-         * components of the track's key. Well it should be rare but the only
-         * way to remove it from its "old" album item is to search each one
-         */
-        findremove = TRUE;
-    }
-    else {
-        /* Track has a valid key so can get the album back.
+    if (index > -1) {
+        /*
+         * Track has a valid key so can get the album back.
          * Either has happened:
          * a) Artist/Album key has been changed so the track is being moved
          *     to another existing album
-         * b) Some other change has occurred that is irrelevant to this code.
+         * b) Artwork has been updated
+         * c) Some other change has occurred that is irrelevant to this code.
          *
          * To determine if a) is the case need to determine whether track 
exists
-         * in the album items track list. If it does then b) is true and 
nothing
-         * more is required.
+         * in the album items track list. If it does then b) or c) is true.
          */
         item = album_model_get_item_with_track(priv->album_model, track);
         g_return_if_fail (item);
 
         index = g_list_index(item->tracks, track);
         if (index != -1) {
-            /* Track exists in the album list so ignore the change and return 
*/
+            /*
+             * Track exists in the album list so determine whether
+             * its artwork is up to date
+             */
             ExtraTrackData *etd;
             etd = track->userdata;
-            if (etd->tartwork_changed == TRUE) {
-                etd->tartwork_changed = FALSE;
+            if (etd->tartwork_changed) {
+                clarity_canvas_update(ccanvas, item);
+                return;
+            }
+            else {
+                /*
+                 *  Artwork is up to date so nothing changed relevant
+                 *  to the display.
+                 */
+                return;
             }
-
-            return;
         }
         else {
-            /* Track does not exist in the album list so the artist/album
-             * key has definitely changed */
-            findremove = TRUE;
-        }
-    }
-
-    if (findremove) {
-        /* It has been determined that the track has had its key changed
-         * and thus a search must be performed to find the "original" album
-         * that the track belonged to, remove it then add the track to the
-         * new album.
-         */
-        item = album_model_search_for_track(priv->album_model, track);
-        /* item represents the album item containing the track */
-        if (item) {
-            g_warning("Item %s %s", item->albumname, item->artist);
-
-            /* The track is in this album so remove it in preparation for
-             * readding under the new album key
+            /*
+             * Track does not exist in the album list so the artist/album
+             * key has definitely changed so find the old album item the long
+             * way.
              */
-            _remove_track(priv, item, track);
+            item = album_model_search_for_track(priv->album_model, track);
         }
+    }
 
-        /* Create a new album item or find existing album to house the
-         * "brand new" track
+    /* item represents the old album item containing the track */
+    if (item) {
+        /*
+         * The track is in this album so remove it in preparation for
+         * readding it back either under the same album item but with
+         * a different cover or under a different album item due to a
+         * different album key.
          */
-        _add_track(priv, track);
+        _remove_track(priv, item, track);
     }
+
+    /*
+     * Create a new album item or find existing album to house the
+     * "brand new" track
+     */
+    _add_track(priv, track);
 }
 
 
diff --git a/plugins/cover_display/display_coverart.c 
b/plugins/cover_display/display_coverart.c
index c797dff..ad62e06 100644
--- a/plugins/cover_display/display_coverart.c
+++ b/plugins/cover_display/display_coverart.c
@@ -949,8 +949,7 @@ void coverart_track_changed(Track *track, gint signal) {
                 /* Track exists in the album list so ignore the change and 
return */
                 ExtraTrackData *etd;
                 etd = track->userdata;
-                if (etd->tartwork_changed == TRUE) {
-                    etd->tartwork_changed = FALSE;
+                if (etd->tartwork_changed) {
                     redraw(TRUE);
                 }
 
diff --git a/plugins/details_editor/details.c b/plugins/details_editor/details.c
index 4e0b48c..91087ef 100644
--- a/plugins/details_editor/details.c
+++ b/plugins/details_editor/details.c
@@ -354,6 +354,7 @@ static void details_button_apply_clicked(GtkButton *button) 
{
 
             changed |= tr_changed;
             etr->tchanged = FALSE;
+            etr->tartwork_changed = FALSE;
         }
     }
 

------------------------------------------------------------------------------
Malware Security Report: Protecting Your Business, Customers, and the 
Bottom Line. Protect your business and customers by understanding the 
threat from malware and how it can impact your online business. 
http://www.accelacomm.com/jaw/sfnl/114/51427462/
_______________________________________________
gtkpod-cvs2 mailing list
gtkpod-cvs2@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to