Update of /cvsroot/gtkpod/gtkpod/src
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv2522/src
Modified Files:
display_coverart.c display_sorttabs.c misc_confirm.c
display_coverart.h display_playlists.c
Log Message:
2007-04-21 P.G. Richardson <phantom_sf at users.sourceforge.net>
* Changed the way coverart display is updated when a track is
removed, added and changed (Thanks to Jorg for thoughts on
this. Much quicker response):
** display_coverart.h & display_coverart.c:
- coverart_sort_images() made static
- slider initialization broken out into own function
- select_cover() will silently return rather than
throwing an error if selected trk not found in display.
- coverart_track_changed() added for deciding action to
be taken when a track changes. Instead of expensive call
to coverart_set_images()
- coverart_set_images() extra parameter to stop recreation
of display track list every time its called.
** display_playlists.c: pm_add_track, pm_remove_track,
pm_track_changed all call coverart_track_changed
** display_sorttabs.c: resets coverart but only reloads all
tracks if sort is set to none. No way to detect original
sort order efficiently.
** misc_confirm.c: removal of coverart_set_image calls so pm
functions relied on instead.
Index: display_coverart.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/display_coverart.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- display_coverart.c 16 Apr 2007 21:57:57 -0000 1.10
+++ display_coverart.c 22 Apr 2007 18:06:16 -0000 1.11
@@ -51,7 +51,9 @@
static gint on_main_cover_image_clicked (GnomeCanvasItem *canvasitem, GdkEvent
*event, gpointer data);
static void on_cover_display_slider_value_changed (GtkRange *range, gpointer
user_data);
static void set_cover_dimensions (Cover_Item *cover, int cover_index);
+static void coverart_sort_images (GtkSortType order);
static void prepare_canvas ();
+static void set_slider_range (gint index);
static void set_covers ();
static gint search_tracks (Track *a, Track *b);
@@ -905,7 +907,7 @@
}
/**
- * set_cover_dimensions::
+ * set_cover_dimensions:
*
* Utility function for set all the x, y, width and height
* dimensions applicable to a single cover widget
@@ -999,6 +1001,42 @@
}
/**
+ *
+ * set_scale_range:
+ *
+ * Set the scale range - maximum value should be display
+ * track list length - (8 NULL images + 1 as index value),
+ * ie. the ones either end of the list.
+ *
+ */
+static void set_slider_range (gint index)
+{
+ gint slider_ubound = g_list_length (cdwidget->displaytracks) - 9;
+ if(slider_ubound < 1)
+ {
+ /* If only one album cover is displayed then slider_ubbound
returns
+ * 0 and causes a slider assertion error. Avoid this by
disabling the
+ * slider, which makes sense because only one cover is
displayed.
+ */
+ slider_ubound = 1;
+ gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->cdslider),
FALSE);
+ gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->leftbutton),
FALSE);
+ gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->rightbutton),
FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->cdslider), TRUE);
+ gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->leftbutton),
TRUE);
+ gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->rightbutton),
TRUE);
+ }
+
+ gtk_range_set_range (GTK_RANGE (cdwidget->cdslider), 0, slider_ubound);
+ if (index >= 0 && index <= slider_ubound)
+ gtk_range_set_value (GTK_RANGE (cdwidget->cdslider), index);
+ else
+ gtk_range_set_value (GTK_RANGE (cdwidget->cdslider), 0);
+}
+/**
* prepare_canvas:
*
* Initialise the canvas and prepare the 9 cover items, along
@@ -1205,7 +1243,14 @@
/* Find the track that matches the given album */
selectedtrk = g_list_find_custom (cdwidget->displaytracks, track,
(GCompareFunc) search_tracks);
- g_return_if_fail (selectedtrk);
+ if (selectedtrk == NULL)
+ {
+ /* Maybe the track has just been created so might not be in the
list yet
+ * Not a perfect solution but avoid throwing around
block_display_change
+ * and potentially leaving everything permanently blocked
+ */
+ return;
+ }
/* Determine the index of the found track */
index = g_list_position (cdwidget->displaytracks, selectedtrk);
@@ -1232,19 +1277,8 @@
* @order: order type
*
*/
-void coverart_sort_images (GtkSortType order)
-{
- /*
- if (order == SORT_NONE)
- {
- pl = pm_get_selected_playlist ();
- newlist = pl->members;
- return;
- }
- else
- {
- */
-
+static void coverart_sort_images (GtkSortType order)
+{
if (order == SORT_NONE)
{
/* Due to list being prepended together and remaining unsorted
need to reverse */
@@ -1252,8 +1286,6 @@
}
else
{
- /* Remove all the null tracks before sorting */
- cdwidget->displaytracks = g_list_remove_all
(cdwidget->displaytracks, NULL);
cdwidget->displaytracks = g_list_sort (cdwidget->displaytracks,
(GCompareFunc) sort_tracks);
}
@@ -1264,14 +1296,149 @@
}
/**
+ *
+ * Convenience function that will only allow set images to be
+ * called if the track that was affected was in the list of displaytracks
+ * used by the coverart display. So if a whole album is deleted then this
+ * will only reset the display if the first track in the album is deleted.
+ *
+ * @track: affected track
+ */
+void coverart_track_changed (Track *track, gint signal)
+{
+ GList *trkpos;
+ gint index;
+
+ cdwidget->block_display_change = TRUE;
+
+ /*
+ * Scenarios:
+ * a) A track is being deleted that is not in the display
+ * b) A track is being deleted that is in the display
+ * c) A track has changed is some way so maybe the coverart
+ * d) A track has been created and its artist and album are already in
the displaylist
+ * e) A track has been created and its artist and album are not in the
displaylist
+ */
+ trkpos = g_list_find_custom (cdwidget->displaytracks, track,
(GCompareFunc) search_tracks);
+
+ switch (signal)
+ {
+ case COVERART_REMOVE_SIGNAL:
+ if (trkpos == NULL)
+ {
+ /* Track is not in the displaylist so can
safely ignore its deletion */
+ cdwidget->block_display_change = FALSE;
+ return;
+ }
+
+ /* Track in displaylist is going to be removed so
remove from display
+ * and remove any references to it
+ */
+
+ /* Determine the index of the found track */
+ index = g_list_position (cdwidget->displaytracks,
trkpos);
+
+ /* Use the index value to determine if the cover is
being displayed */
+ if (index >= cdwidget->first_imgindex && index <=
(cdwidget->first_imgindex + IMG_TOTAL))
+ {
+ /* Cover is being displayed so need to do some
clearing up */
+
+ /* Reset the display back to black, black and
more black
+ * Frees the cdcover widget of the track ready
for deletion
+ */
+ coverart_clear_images ();
+ /* Remove the track from displaytracks */
+ cdwidget->displaytracks = g_list_delete_link
(cdwidget->displaytracks, trkpos);
+ /* reset the covers and should reset to
original position but without the index */
+ set_covers ();
+ }
+ else
+ {
+ /* index value is outside the displayed covers
so safe to just remove the track from displaytracks */
+ /* Remove the track from displaytracks */
+ cdwidget->displaytracks = g_list_remove
(cdwidget->displaytracks, trkpos);
+ }
+
+ /* Size of displaytracks has changed so reset the
slider to appropriate range and index */
+ set_slider_range (index);
+ break;
+ case COVERART_CREATE_SIGNAL:
+ if (trkpos != NULL)
+ {
+ /* A track with the same artist and album
already exists in the displaylist so there is no
+ * need to add it to the displaylist so can
safely ignore its creation
+ */
+ cdwidget->block_display_change = FALSE;
+ return;
+ }
+ gint i = 0;
+
+ /* Track details have not been seen before so need to
add to the displaylist */
+
+ /* Remove all null tracks before any sorting should
take place */
+ cdwidget->displaytracks = g_list_remove_all
(cdwidget->displaytracks, NULL);
+
+ if (prefs_get_int("st_sort") == SORT_ASCENDING)
+ {
+ cdwidget->displaytracks = g_list_insert_sorted
(cdwidget->displaytracks, track, (GCompareFunc) sort_tracks);
+ }
+ else if (prefs_get_int("st_sort") == SORT_DESCENDING)
+ {
+ /* Already in descending order so reverse into
ascending order */
+ cdwidget->displaytracks = g_list_reverse
(cdwidget->displaytracks);
+ /* Insert the track */
+ cdwidget->displaytracks = g_list_insert_sorted
(cdwidget->displaytracks, track, (GCompareFunc) sort_tracks);
+ /* Reverse again */
+ cdwidget->displaytracks = g_list_reverse
(cdwidget->displaytracks);
+ }
+ else
+ {
+ /* NO SORT */
+ cdwidget->displaytracks = g_list_append
(cdwidget->displaytracks, track);
+ }
+
+ /* Readd in the null tracks */
+ /* Add 4 null tracks to the end of the track list for
padding */
+ for (i = 0; i < IMG_MAIN; ++i)
+ cdwidget->displaytracks = g_list_append
(cdwidget->displaytracks, NULL);
+
+ /* Add 4 null tracks to the start of the track list for
padding */
+ for (i = 0; i < IMG_MAIN; ++i)
+ cdwidget->displaytracks = g_list_prepend
(cdwidget->displaytracks, NULL);
+
+ set_covers ();
+
+ /* Size of displaytracks has changed so reset the
slider to appropriate range and index */
+ set_slider_range (g_list_index(cdwidget->displaytracks,
track));
+ break;
+ case COVERART_CHANGE_SIGNAL:
+ /* A track is declaring itself as changed so what to
do? */
+ if (trkpos == NULL)
+ {
+ /* The track is not in the displaylist so who
cares if it has changed! */
+ cdwidget->block_display_change = FALSE;
+ return;
+ }
+
+ /* Track is in the displaylist and something about it
has changed.
+ * Dont know how it has changed so all I can really do
is resort the list according
+ * to the current sort order and redisplay
+ */
+ coverart_set_images (FALSE);
+ }
+
+ cdwidget->block_display_change = FALSE;
+}
+
+/**
* coverart_set_images:
*
* Takes a list of tracks and sets the 9 image cover display.
*
- * @tracks: list of tracks taken from a playlist
+ * @gboolean: flag indicating whether to clear the displaytracks list or not
*
*/
-void coverart_set_images ()
+void coverart_set_images (gboolean clear_track_list)
{
gint i;
GList *tracks;
@@ -1290,31 +1457,37 @@
/* Reset the display back to black, black and more black */
coverart_clear_images ();
- /* Find the selected playlist */
- playlist = pm_get_selected_playlist ();
- if (playlist == NULL)
- return;
+ if (clear_track_list)
+ {
+ /* Find the selected playlist */
+ playlist = pm_get_selected_playlist ();
+ if (playlist == NULL)
+ return;
- tracks = playlist->members;
-
- cdwidget->first_imgindex = 0;
-
- g_list_free (cdwidget->displaytracks);
- cdwidget->displaytracks = NULL;
+ tracks = playlist->members;
+
+ g_list_free (cdwidget->displaytracks);
+ cdwidget->displaytracks = NULL;
- if (tracks == NULL)
- return;
+ if (tracks == NULL)
+ return;
- while (tracks)
- {
- track = tracks->data;
+ while (tracks)
+ {
+ track = tracks->data;
- if (g_list_find_custom (cdwidget->displaytracks, track,
(GCompareFunc) search_tracks) == NULL)
- cdwidget->displaytracks = g_list_prepend
(cdwidget->displaytracks, track);
+ if (g_list_find_custom (cdwidget->displaytracks, track,
(GCompareFunc) search_tracks) == NULL)
+ cdwidget->displaytracks = g_list_prepend
(cdwidget->displaytracks, track);
- tracks = tracks->next;
+ tracks = tracks->next;
+ }
+
+ cdwidget->first_imgindex = 0;
}
-
+
+ /* Remove all null tracks before any sorting should take place */
+ cdwidget->displaytracks = g_list_remove_all (cdwidget->displaytracks,
NULL);
+
/* Sort the tracks to the order set in the preference */
coverart_sort_images (prefs_get_int("st_sort"));
@@ -1325,34 +1498,10 @@
/* Add 4 null tracks to the start of the track list for padding */
for (i = 0; i < IMG_MAIN; ++i)
cdwidget->displaytracks = g_list_prepend
(cdwidget->displaytracks, NULL);
-
+
set_covers ();
- /* Set the scale range - maximum value should be display
- * track list length - (8 NULL images + 1 as index value),
- * ie. the ones either end of the list.
- */
- gint slider_ubound = g_list_length (cdwidget->displaytracks) - 9;
- if(slider_ubound < 1)
- {
- /* If only one album cover is displayed then slider_ubbound
returns
- * 0 and causes a slider assertion error. Avoid this by
disabling the
- * slider, which makes sense because only one cover is
displayed.
- */
- slider_ubound = 1;
- gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->cdslider),
FALSE);
- gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->leftbutton),
FALSE);
- gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->rightbutton),
FALSE);
- }
- else
- {
- gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->cdslider), TRUE);
- gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->leftbutton),
TRUE);
- gtk_widget_set_sensitive (GTK_WIDGET(cdwidget->rightbutton),
TRUE);
- }
-
- gtk_range_set_range (GTK_RANGE (cdwidget->cdslider), 0, slider_ubound);
- gtk_range_set_value (GTK_RANGE (cdwidget->cdslider), 0);
+ set_slider_range (cdwidget->first_imgindex);
/*printf("######### ORIGINAL LINE UP ########\n");
debug_albums ();
Index: display_sorttabs.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/display_sorttabs.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -d -r1.91 -r1.92
--- display_sorttabs.c 25 Mar 2007 13:18:26 -0000 1.91
+++ display_sorttabs.c 22 Apr 2007 18:06:16 -0000 1.92
@@ -1961,7 +1961,13 @@
for (i=0; i < prefs_get_int("sort_tab_num"); ++i)
st_sort_inst (i, order);
- coverart_set_images ();
+ /* Reset the cover images. Unfortunately the track order is not
maintained when the
+ * display list of tracks is created. Thus, if the desired track order
is the original order
+ * then unfortunately the tracks must be collected from the playlist
once again and the
+ * displaytracks list in coverart recreated.
+ * ie. easy to sort ascending and descending but difficult to return to
unsorted state
+ */
+ coverart_set_images (order == SORT_NONE);
}
gboolean st_set_selection (Itdb_Track *track)
Index: misc_confirm.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc_confirm.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- misc_confirm.c 17 Apr 2007 13:52:03 -0000 1.52
+++ misc_confirm.c 22 Apr 2007 18:06:16 -0000 1.53
@@ -312,7 +312,6 @@
/* Awaken coverart selection */
coverart_block_change (FALSE);
- coverart_set_images();
g_list_free (dd->tracks);
g_free (dd);
@@ -653,8 +652,6 @@
delete_playlist_cleanup (dd);
gtkpod_tracks_statusbar_update ();
-
- coverart_set_images ();
}
Index: display_coverart.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/display_coverart.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- display_coverart.h 16 Apr 2007 21:57:57 -0000 1.6
+++ display_coverart.h 22 Apr 2007 18:06:16 -0000 1.7
@@ -10,6 +10,10 @@
#define IMG_TOTAL 9
#define BORDER 10
+#define COVERART_REMOVE_SIGNAL 1
+#define COVERART_CREATE_SIGNAL 2
+#define COVERART_CHANGE_SIGNAL 3
+
typedef struct {
Itdb_Track *track;
gdouble img_x;
@@ -45,9 +49,9 @@
GList *coverart_get_displayed_tracks (void);
GdkPixbuf *coverart_get_default_track_thumb (void);
void coverart_init (gchar *progpath);
-void coverart_sort_images (GtkSortType order);
void coverart_select_cover (Itdb_Track *track);
-void coverart_set_images ();
+void coverart_set_images (gboolean clear_track_list);
+void coverart_track_changed (Track *track, gint signal);
void coverart_clear_images ();
void coverart_block_change (gboolean val);
void coverart_init_display ();
Index: display_playlists.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/display_playlists.c,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- display_playlists.c 1 Apr 2007 04:27:55 -0000 1.101
+++ display_playlists.c 22 Apr 2007 18:06:16 -0000 1.102
@@ -1114,7 +1114,7 @@
if (prefs_get_int (KEY_DISPLAY_COVERART))
{
- coverart_set_images ();
+ coverart_track_changed (track, COVERART_REMOVE_SIGNAL);
}
}
@@ -1126,12 +1126,13 @@
if (playlist == current_playlist)
{
st_add_track (track, TRUE, display, 0); /* Add to first sort tab */
- }
- if (prefs_get_int (KEY_DISPLAY_COVERART))
- {
- coverart_set_images ();
- }
+ /* As with add_track above, only add to the playlist if it is the
current one */
+ if (prefs_get_int (KEY_DISPLAY_COVERART))
+ {
+ coverart_track_changed (track, COVERART_CREATE_SIGNAL);
+ }
+ }
}
/* One of the playlist names has changed (this happens when the
@@ -1166,7 +1167,7 @@
if (prefs_get_int (KEY_DISPLAY_COVERART))
{
- coverart_set_images ();
+ coverart_track_changed (track, COVERART_CHANGE_SIGNAL);
}
}
@@ -1429,7 +1430,7 @@
/* Reallow the coverart selection update */
coverart_block_change (FALSE);
/* Set the coverart display based on the selected playlist */
- coverart_set_images();
+ coverart_set_images(TRUE);
space_data_update ();
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2