Revision: 1561
http://gtkpod.svn.sourceforge.net/gtkpod/?rev=1561&view=rev
Author: phantom_sf
Date: 2007-06-18 15:39:26 -0700 (Mon, 18 Jun 2007)
Log Message:
-----------
2007-06-17 P.G. Richardson <phantom_sf at users.sourceforge.net>
Bug fixes spotted by Daniele Forsi.
Change in coverart not made to coverart display when apply button
clicked on Details window.
Fetchcover behaved awkwardly with naming the downloaded image files if
the tracks concerned lacked album info in their ID3 tags.
Coverart files from fetchcover subject to template values in the prefs.
Should always be a default value of folder.jpg if none of the templates
provide a non-null value.
* details.c:
details_copy_artwork() has to now always recopy the artwork
from file. The reason being, fetchcover overwrites the artwork hence
the file name will still be the same while different artwork.
* display_coverart.h
display_coverart.c:
set_covers() and set_cover_item() now has a
parameter to force an update of the cover images from file. Only used
by details_copy_artwork() when the apply button is clicked on the
details window.
* fetchcover.c:
dialog will now appear if a cover image file already exists in the
tracks directory. Gives the options to overwrite, save as unique name
or cancel completely.
Modified Paths:
--------------
gtkpod/trunk/ChangeLog_detailed
gtkpod/trunk/src/details.c
gtkpod/trunk/src/display_coverart.c
gtkpod/trunk/src/display_coverart.h
gtkpod/trunk/src/fetchcover.c
Modified: gtkpod/trunk/ChangeLog_detailed
===================================================================
--- gtkpod/trunk/ChangeLog_detailed 2007-06-18 16:16:31 UTC (rev 1560)
+++ gtkpod/trunk/ChangeLog_detailed 2007-06-18 22:39:26 UTC (rev 1561)
@@ -1,3 +1,32 @@
+2007-06-17 P.G. Richardson <phantom_sf at users.sourceforge.net>
+
+ Bug fixes spotted by Daniele Forsi.
+
+ Change in coverart not made to coverart display when apply button
+ clicked on Details window.
+ Fetchcover behaved awkwardly with naming the downloaded image files if
+ the tracks concerned lacked album info in their ID3 tags.
+ Coverart files from fetchcover subject to template values in the prefs.
+ Should always be a default value of folder.jpg if none of the templates
+ provide a non-null value.
+
+ * details.c:
+ details_copy_artwork() has to now always recopy the artwork
+ from file. The reason being, fetchcover overwrites the artwork hence
+ the file name will still be the same while different artwork.
+
+ * display_coverart.h
+ display_coverart.c:
+ set_covers() and set_cover_item() now has a
+ parameter to force an update of the cover images from file. Only used
+ by details_copy_artwork() when the apply button is clicked on the
+ details window.
+
+ * fetchcover.c:
+ dialog will now appear if a cover image file already exists in the
+ tracks directory. Gives the options to overwrite, save as unique name
+ or cancel completely.
+
2007-06-17 Jorg Schuler <jcsjcs at users.sourceforge.net>
* src/misc.h
Modified: gtkpod/trunk/src/details.c
===================================================================
--- gtkpod/trunk/src/details.c 2007-06-18 16:16:31 UTC (rev 1560)
+++ gtkpod/trunk/src/details.c 2007-06-18 22:39:26 UTC (rev 1561)
@@ -34,6 +34,7 @@
#include "fileselection.h"
#include "misc.h"
#include "fetchcover.h"
+#include "display_coverart.h"
#include "misc_track.h"
#include "prefs.h"
#include <string.h>
@@ -514,8 +515,6 @@
g_return_val_if_fail (fretr->thumb_path_locale, FALSE);
g_return_val_if_fail (toetr->thumb_path_locale, FALSE);
- if (strcmp (fretr->thumb_path_locale, toetr->thumb_path_locale) != 0)
- {
itdb_artwork_free (totrack->artwork);
totrack->artwork = itdb_artwork_duplicate (frtrack->artwork);
totrack->artwork_size = frtrack->artwork_size;
@@ -526,13 +525,19 @@
toetr->thumb_path_locale = g_strdup (fretr->thumb_path_locale);
toetr->thumb_path_utf8 = g_strdup (fretr->thumb_path_utf8);
changed = TRUE;
- }
+
/* make sure artwork gets removed, even if both thumb_paths were
unset ("") */
if (!frtrack->artwork->thumbnails)
{
changed |= gp_track_remove_thumbnails (totrack);
}
+
+ /* Since no data changes affect the coverart display.
+ * Need to force a change by calling set covers directly.
+ */
+ force_update_covers ();
+
return changed;
}
Modified: gtkpod/trunk/src/display_coverart.c
===================================================================
--- gtkpod/trunk/src/display_coverart.c 2007-06-18 16:16:31 UTC (rev 1560)
+++ gtkpod/trunk/src/display_coverart.c 2007-06-18 22:39:26 UTC (rev 1561)
@@ -42,7 +42,7 @@
/* Declarations */
static void free_album (Album_Item *album);
- static void free_CDWidget ();
+static void free_CDWidget ();
static gint compare_album_keys (gchar *a, gchar *b);
static void set_display_dimensions ();
static GdkPixbuf *draw_blank_cdimage ();
@@ -57,8 +57,8 @@
static void coverart_sort_images (GtkSortType order);
static void prepare_canvas ();
static void set_slider_range (gint index);
-static void set_covers ();
-static void set_cover_item (gint ndex, Cover_Item *cover, gchar *key);
+static void set_covers (gboolean force_imgupdate);
+static void set_cover_item (gint ndex, Cover_Item *cover, gchar *key, gboolean
force_imgupdate);
/* Prefs keys */
const gchar *KEY_DISPLAY_COVERART="display_coverart";
@@ -291,14 +291,29 @@
}
/**
+ *
+ * force_update_covers:
+ *
+ * Call the resetting of the covers and override the cached images so that they
+ * are loaded with the latest files existing on the filesystem.
+ *
+ */
+void force_update_covers ()
+{
+ set_covers (TRUE);
+}
+
+/**
* set_covers:
*
* Internal function responsible for the resetting of the artwork
* covers in response to some kind of change in selection, eg. new
* selection in sort tab, button click etc...
*
+ * @force_imgupdate: forces the resetting of the cached images so that the
+ * values are reread from the tracks and updated. Used sparingly.
*/
-static void set_covers ()
+static void set_covers (gboolean force_imgupdate)
{
gint i, dataindex;
gchar *key;
@@ -314,7 +329,7 @@
*/
key = g_list_nth_data (album_key_list, dataindex);
- set_cover_item (i, cover, key);
+ set_cover_item (i, cover, key, force_imgupdate);
}
}
@@ -324,7 +339,7 @@
* Internal function called by set_covers to reset an artwork cover.
*
*/
-static void set_cover_item (gint index, Cover_Item *cover, gchar *key)
+static void set_cover_item (gint index, Cover_Item *cover, gchar *key,
gboolean force_imgupdate)
{
GdkPixbuf *reflection;
GdkPixbuf *scaled;
@@ -375,6 +390,12 @@
cover->album = album;
Track *track;
+ if (force_imgupdate)
+ {
+ gdk_pixbuf_unref (album->albumart);
+ album->albumart = NULL;
+ }
+
if (album->albumart == NULL)
{
track = g_list_nth_data (album->tracks, 0);
@@ -451,7 +472,7 @@
if (cdwidget->first_imgindex > (displaytotal - IMG_MAIN))
cdwidget->first_imgindex = displaytotal - IMG_MAIN;
- set_covers ();
+ set_covers (FALSE);
}
/**
@@ -956,7 +977,7 @@
set_highlight (cover, TRUE);
}
- set_covers ();
+ set_covers (FALSE);
}
@@ -1412,7 +1433,7 @@
else if((cdwidget->first_imgindex + IMG_TOTAL) >= displaytotal)
cdwidget->first_imgindex = displaytotal - IMG_TOTAL;
- set_covers ();
+ set_covers (FALSE);
/* Set the index value of the slider but avoid causing an infinite
* cover selection by blocking the event
@@ -1523,7 +1544,7 @@
if (index >= cdwidget->first_imgindex && index <=
(cdwidget->first_imgindex + IMG_TOTAL))
{
/* reset the covers and should reset to
original position but without the index */
- set_covers ();
+ set_covers (FALSE);
}
/* Size of key list may have changed so reset the
slider
@@ -1583,7 +1604,7 @@
for (i = 0; i < IMG_MAIN; ++i)
album_key_list = g_list_prepend
(album_key_list, NULL);
- set_covers ();
+ set_covers (FALSE);
}
else
{
@@ -1632,7 +1653,7 @@
index = g_list_index (album->tracks, track);
if (index != -1)
{
- /* Track exists in the album list so return and
ignore the change */
+ /* Track exists in the album list so ignore the
change and return */
return;
}
else
@@ -1668,7 +1689,7 @@
* under the new album
key
*/
remove_track_from_album
(album, track, key, index, klist);
- set_covers();
+ set_covers(FALSE);
/* Found the album and
removed so no need to continue the loop */
break;
}
@@ -1833,7 +1854,7 @@
for (i = 0; i < IMG_MAIN; ++i)
album_key_list = g_list_prepend (album_key_list, NULL);
- set_covers ();
+ set_covers (FALSE);
set_slider_range (cdwidget->first_imgindex);
@@ -1908,7 +1929,7 @@
g_free (filename);
- set_covers ();
+ set_covers (FALSE);
}
/**
@@ -1946,5 +1967,5 @@
on_coverart_context_menu_click (tracks);
- set_covers ();
+ set_covers (FALSE);
}
Modified: gtkpod/trunk/src/display_coverart.h
===================================================================
--- gtkpod/trunk/src/display_coverart.h 2007-06-18 16:16:31 UTC (rev 1560)
+++ gtkpod/trunk/src/display_coverart.h 2007-06-18 22:39:26 UTC (rev 1561)
@@ -54,6 +54,7 @@
GList *coverart_get_displayed_tracks (void);
GdkPixbuf *coverart_get_default_track_thumb (void);
void coverart_init (gchar *progpath);
+void force_update_covers ();
void coverart_select_cover (Itdb_Track *track);
void coverart_set_images (gboolean clear_track_list);
void coverart_track_changed (Track *track, gint signal);
Modified: gtkpod/trunk/src/fetchcover.c
===================================================================
--- gtkpod/trunk/src/fetchcover.c 2007-06-18 16:16:31 UTC (rev 1560)
+++ gtkpod/trunk/src/fetchcover.c 2007-06-18 22:39:26 UTC (rev 1561)
@@ -67,6 +67,8 @@
static GtkWidget *fetchcover_statusbar;
/* Flag indicating whether a new net search should be initiated */
static gboolean netsearched = FALSE;
+/* Display a dialog explaining the options if a file with the proposed name
already exists */
+static gchar *display_file_exist_dialog (gchar *filename);
#define IMGSCALE 256
@@ -337,19 +339,33 @@
gchar *template = prefs_get_string("coverart_template");
gchar **template_items = g_strsplit(template, ";", 0);
- gchar *filename = get_string_from_template(fetchcover_track,
*template_items, FALSE, FALSE);
+ gint i;
+ gchar *filename = NULL;
+ for (i = 0; filename == NULL && i < g_strv_length (template_items); ++i)
+ {
+ filename = get_string_from_template(fetchcover_track,
template_items[i], FALSE, FALSE);
+ if (strlen(filename) == 0)
+ filename = NULL;
+ }
+
+ /* Check filename still equals null then take a default stance
+ * to ensure the file has a name.
+ */
+ if (filename == NULL)
+ filename = "folder.jpg";
+
/* Use the index position of the cover in the glist to create a unique
filename
* Convert the index number to a string and prefix with a dot (hidden
file)
*/
gint display_cover_index;
display_cover_index = g_list_index (fetchcover_image_list,
displayed_cover);
gchar *dcstr_index = NULL;
- dcstr_index = (gchar *) g_malloc (4);
+ dcstr_index = (gchar *) g_malloc (sizeof(gint) + (sizeof(gchar) * 3));
g_sprintf (dcstr_index, "[EMAIL PROTECTED]", display_cover_index);
gchar *fname = NULL;
- if (g_str_has_suffix(*template_items, ".jpg"))
+ if (g_str_has_suffix(filename, ".jpg"))
fname = g_strconcat(dcstr_index, filename, NULL);
else
fname = g_strconcat(dcstr_index, filename, ".jpg", NULL);
@@ -566,14 +582,24 @@
/* Assign the filename ready to rename the file */
newname = g_build_filename(displayed_cover->dir,
fname_items[1], NULL);
fetchcover_debug("New name of file is %s\n", newname);
-
- if (g_file_test (newname, G_FILE_TEST_EXISTS))
+
+ while (g_file_test (newname, G_FILE_TEST_EXISTS))
{
- /* file with the new name exists so delete the file */
- g_remove (newname);
+ newname = display_file_exist_dialog (newname);
+ if (newname == NULL)
+ break;
}
+ /* Carry the nullified value back to the original called so the
+ * entire fetchcover process can be cancelled
+ */
+ if (newname == NULL)
+ return NULL;
+
gchar *oldname = g_build_filename(displayed_cover->dir,
displayed_cover->filename, NULL);
+ /* Rename the preferred choice, ie. [EMAIL PROTECTED], to the
preferred name,
+ * ie. After_Forever.jpg
+ */
g_rename (oldname, newname);
/* Tidy up to ensure the path will not get cleaned up
@@ -590,6 +616,75 @@
}
#endif /* HAVE_CURL */
+static gchar *display_file_exist_dialog (gchar *filename)
+{
+ gint result;
+ gchar **splitarr = NULL;
+ gchar *basename = NULL;
+ gint i;
+ gchar *message;
+ GtkWidget *label;
+ GtkWidget *dialog = gtk_dialog_new_with_buttons ("Coverart file already
exists",
+ NULL,
+ GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_YES,
+ GTK_RESPONSE_YES,
+ GTK_STOCK_NO,
+ GTK_RESPONSE_NO,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_REJECT,
+ NULL);
+ message = g_strdup_printf (_("The picture file %s already exists. \
+\nThis may be associated with other music files in the directory. \
+\n\n- Clicking Yes will overwrite the existing file, possibly associating \
+\n other music files in the same directory with this coverart file. \
+\n- Clicking No will save the file with a unique file name. \
+\n- Clicking Cancel will abort the fetchcover operation."), filename);
+
+ label = gtk_label_new (message);
+
+ /* Add the label, and show everything we've added to the dialog. */
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
+
+ gtk_widget_show_all (dialog);
+ result = gtk_dialog_run (GTK_DIALOG(dialog));
+ g_free (message);
+
+ switch (result)
+ {
+ case GTK_RESPONSE_REJECT:
+ /* Cancel has been clicked so no save */
+ gtk_widget_destroy (dialog);
+ return NULL;
+ case GTK_RESPONSE_YES:
+ /* Yes clicked so overwrite the file is okay. Leave
final_filename intact
+ * and remove the original
+ */
+ g_remove (filename);
+ gtk_widget_destroy (dialog);
+ return filename;
+ case GTK_RESPONSE_NO:
+ /* User doesnt want to overwrite anything so need to do
some work on filename */
+ splitarr = g_strsplit (filename, ".", 0);
+ basename = splitarr[0];
+
+ for (i = 1; g_file_test (filename, G_FILE_TEST_EXISTS);
++i)
+ {
+ g_sprintf (filename, "%s%d.jpg", basename, i);
+ }
+
+ /* Should have found a filename that really doesnt
exist so this needs to be returned */
+ basename = NULL;
+ g_strfreev(splitarr);
+ gtk_widget_destroy (dialog);
+
+ return filename;
+ default:
+ gtk_widget_destroy (dialog);
+ return NULL;
+ }
+}
+
/**
* free_fetchcover:
*
@@ -658,9 +753,6 @@
}
#endif /* CURL */
free_fetchcover_list();
-
- /* Clear the status bar */
- gtk_statusbar_pop(GTK_STATUSBAR(fetchcover_statusbar), 1);
}
/**
@@ -798,8 +890,7 @@
gtk_widget_set_sensitive (prev_button, FALSE);
fetchcover_statusbar_update ("CURL has not been installed so
this function is not available");
#endif /* HAVE_CURL */
-
-
+
gtk_widget_show_all (fetchcover_dialog);
g_object_unref (fetchcover_xml);
@@ -828,6 +919,7 @@
}
}
+
/**
* fetchcover_statusbar_update:
*
@@ -844,6 +936,7 @@
}
}
+
/**
* on_coverart_context_menu_click:
*
@@ -867,13 +960,15 @@
g_return_if_fail (dialog);
result = gtk_dialog_run (GTK_DIALOG (dialog));
-
+ gtk_widget_hide (GTK_WIDGET(dialog));
+ gtk_widget_destroy (GTK_WIDGET(dialog));
+
#ifdef HAVE_CURL
gchar *filename = NULL;
switch (result)
{
- case GTK_RESPONSE_ACCEPT:
+ case GTK_RESPONSE_ACCEPT:
filename = fetchcover_save ();
if (filename)
{
@@ -892,7 +987,6 @@
#endif /* HAVE_CURL */
fetchcover_cleanup();
- gtk_widget_destroy (GTK_WIDGET (dialog));
}
/**
@@ -912,7 +1006,8 @@
g_return_if_fail (dialog);
result = gtk_dialog_run (GTK_DIALOG (dialog));
-
+ gtk_widget_hide (GTK_WIDGET(dialog));
+ gtk_widget_destroy (GTK_WIDGET(dialog));
#ifdef HAVE_CURL
gchar *filename = NULL;
@@ -958,5 +1053,4 @@
#endif /* HAVE_CURL */
fetchcover_cleanup();
- gtk_widget_destroy (GTK_WIDGET (dialog));
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
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