Revision: 1755
http://gtkpod.svn.sourceforge.net/gtkpod/?rev=1755&view=rev
Author: phantom_sf
Date: 2007-11-04 17:16:19 -0800 (Sun, 04 Nov 2007)
Log Message:
-----------
2007-11-04 P.G. Richardson <phantom_sf at users.sourceforge.net>
* src/fetchcover.c
Opened up filename handling functions to rest of gtkpod.
Reduced number of functions hidden if curl is not available.
Fetch_Cover object used as vehicle for handling the filename
even if image is not being downloaded.
* src/fetchcover.h: parent_window added to Fetch_Cover object.
* src/display.h
Support for IMAGE_JPEG target type.
* src/details.c
* src/display_coverart.c
Support for image/jpeg target in drag and drop operations on
cover art. This target is provided by konqueror (not by firefox
at the moment but supposedly at some point) and carries the
displayed jpeg image as its data so redownloading is not required.
Downloading option used as fallback if this target is not provided.
Modified Paths:
--------------
gtkpod/trunk/src/details.c
gtkpod/trunk/src/display.h
gtkpod/trunk/src/display_coverart.c
gtkpod/trunk/src/fetchcover.c
gtkpod/trunk/src/fetchcover.h
Modified: gtkpod/trunk/src/details.c
===================================================================
--- gtkpod/trunk/src/details.c 2007-11-04 00:53:06 UTC (rev 1754)
+++ gtkpod/trunk/src/details.c 2007-11-05 01:16:19 UTC (rev 1755)
@@ -37,6 +37,7 @@
#include "display_coverart.h"
#include "misc_track.h"
#include "prefs.h"
+#include "info.h"
#include <string.h>
#include <glib/gstdio.h>
@@ -92,6 +93,7 @@
/* Detail image drag types for dnd */
GtkTargetEntry cover_image_drag_types [] = {
+ { "image/jpeg", 0, DND_IMAGE_JPEG },
{ "text/uri-list", 0, DND_TEXT_URI_LIST },
{ "text/plain", 0, DND_TEXT_PLAIN },
{ "STRING", 0, DND_TEXT_PLAIN }
@@ -1662,23 +1664,23 @@
gtk_drag_dest_set (
GTK_WIDGET(img),
- GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT,
+ 0,
cover_image_drag_types,
TGNR (cover_image_drag_types),
- GDK_ACTION_COPY);
+ GDK_ACTION_COPY|GDK_ACTION_MOVE);
g_signal_connect ((gpointer) img, "drag-drop",
G_CALLBACK (dnd_details_art_drag_drop),
NULL);
-
- g_signal_connect ((gpointer) img, "drag-motion",
- G_CALLBACK (dnd_details_art_drag_motion),
- NULL);
-
+
g_signal_connect ((gpointer) img, "drag-data-received",
G_CALLBACK (dnd_details_art_drag_data_received),
NULL);
+ g_signal_connect ((gpointer) img, "drag-motion",
+ G_CALLBACK (dnd_details_art_drag_motion),
+ NULL);
+
details_set_tracks (detail, selected_tracks);
/* set notebook page */
@@ -1734,9 +1736,6 @@
{
GdkAtom target;
target = gtk_drag_dest_find_target (widget, drag_context, NULL);
-
- gchar *typeName = 0;
- typeName = gdk_atom_name(target);
if (target != GDK_NONE)
{
@@ -1757,7 +1756,7 @@
GdkAtom target;
iTunesDB *itdb;
ExtraiTunesDBData *eitdb;
-
+
itdb = gp_get_selected_itdb ();
/* no drop is possible if no playlist/repository is selected */
if (itdb == NULL)
@@ -1794,85 +1793,163 @@
g_return_if_fail (dc);
g_return_if_fail (data);
g_return_if_fail (data->data);
-
- #ifdef HAVE_CURL
-
- /* Deal with what we are given from source */
- if((data != NULL) && (data-> length >= 0))
- {
+ g_return_if_fail (data->length > 0);
+
+#if DEBUG
+ printf ("data length = %d\n", data->length);
+ printf ("data->data = %s\n", data->data);
+#endif
- #if DEBUG
- printf ("data length = %d\n", data->length);
- printf ("data->data = %s\n", data->data);
- #endif
-
- Detail *detail;
- GList *tracks;
- gchar *url = NULL;
- Fetch_Cover *fcover;
- gchar *filename;
-
- /* Find the selected detail item for the coverart image
*/
- detail = details_get_selected_detail ();
- tracks = detail->tracks;
-
- /* initialise the url string with the data from the dnd
*/
- url = (gchar *) data->data;
- /* Initialise a fetchcover object */
- fcover = fetchcover_new (url, tracks);
- coverart_block_change (TRUE);
-
- if (net_retrieve_image (fcover,
GTK_WINDOW(detail->window)))
+ Detail *detail;
+ GList *tracks;
+ gchar *url = NULL;
+ Fetch_Cover *fcover;
+ gchar *filename = NULL;
+ gboolean image_status = FALSE;
+ gchar *image_error = NULL;
+ /* For use with DND_IMAGE_JPEG */
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
+
+ /* Find the selected detail item for the coverart image */
+ detail = details_get_selected_detail ();
+ tracks = detail->tracks;
+
+ switch (info)
+ {
+ case DND_IMAGE_JPEG:
+#if DEBUG
+ printf ("Using DND_IMAGE_JPEG\n");
+#endif
+ pixbuf = gtk_selection_data_get_pixbuf (data);
+ if (pixbuf != NULL)
{
- #if DEBUG
- printf ("Successfully retrieved\n");
- printf ("Url of fetch cover: %s\n",
fcover->url->str);
- printf ("filename of fetch cover: %s\n",
fcover->filename);
- #endif
- filename = g_build_filename(fcover->dir,
fcover->filename, NULL);
-
- coverart_block_change (FALSE);
-
- if (details_writethrough(detail))
+ /* initialise the url string with a safe value
as not used if already have image */
+ url = "local image";
+ /* Initialise a fetchcover object */
+ fcover = fetchcover_new (url, tracks);
+ fcover->parent_window =
GTK_WINDOW(detail->window);
+ coverart_block_change (TRUE);
+
+ /* find the filename with which to save the
pixbuf to */
+ if (fetchcover_select_filename (fcover))
{
- GList *list;
- for (list = detail->tracks; list; list
= list->next)
+ filename =
g_build_filename(fcover->dir, fcover->filename, NULL);
+ if (! gdk_pixbuf_save (pixbuf,
filename, "jpeg", &error, NULL))
{
- ExtraTrackData *etd;
- Track *track = list->data;
-
- if (!track)
- break;
-
- etd = track->userdata;
- gp_track_set_thumbnails(track,
filename);
- etd->tchanged = TRUE;
- etd->tartwork_changed = TRUE;
+ /* Save failed for some reason
*/
+ fcover->err_msg = g_strdup
(error->message);
+ g_error_free (error);
}
- }
- else
- {
- ExtraTrackData *etd =
detail->track->userdata;
- if (etd)
+ else
{
-
gp_track_set_thumbnails(detail->track, filename);
- etd->tchanged = TRUE;
- etd->tartwork_changed = TRUE;
+ /* Image successfully saved */
+ image_status = TRUE;
}
}
- detail->changed = TRUE;
- details_update_thumbnail(detail);
- details_update_buttons(detail);
+ /* record any errors and free the fetchcover */
+ if (fcover->err_msg != NULL)
+ image_error = g_strdup(fcover->err_msg);
+
+ free_fetchcover (fcover);
+ gdk_pixbuf_unref (pixbuf);
+ coverart_block_change (FALSE);
}
else
{
- gtkpod_warning (_("%s\n"), fcover->err_msg);
+ /* despite the data being of type image/jpeg,
the pixbuf is NULL */
+ image_error = "jpeg data flavour was used but
the data did not contain a GdkPixbuf object";
+ }
+ break;
+ case DND_TEXT_PLAIN:
+#if DEBUG
+ printf ("Defaulting to using DND_TEXT_PLAIN\n");
+#endif
+
+#ifdef HAVE_CURL
+ /* initialise the url string with the data from
the dnd */
+ url = g_strdup ((gchar *) data->data);
+ /* Initialise a fetchcover object */
+ fcover = fetchcover_new (url, tracks);
+ /* assign details window as the parent window
so the file exists dialog is
+ * properly centred and visible if a file has
to be overwritten
+ */
+ fcover->parent_window =
GTK_WINDOW(detail->window);
+ coverart_block_change (TRUE);
+
+ if (fetchcover_net_retrieve_image (fcover))
+ {
+#if DEBUG
+ printf ("Successfully retrieved\n");
+ printf ("Url of fetch cover: %s\n",
fcover->url->str);
+ printf ("filename of fetch cover:
%s\n", fcover->filename);
+#endif
+
+ filename =
g_build_filename(fcover->dir, fcover->filename, NULL);
+ image_status = TRUE;
+ }
+
+ /* record any errors and free the fetchcover */
+ if (fcover->err_msg != NULL)
+ image_error = g_strdup(fcover->err_msg);
+
+ free_fetchcover (fcover);
coverart_block_change (FALSE);
- }
- free_fetchcover (fcover);
+#else
+ image_error = "Item had to be downloaded but gtkpod was
not compiled with curl.";
+ image_status = FALSE;
+#endif
+ }
+
+ if (!image_status || filename == NULL)
+ {
+ gtkpod_warning (_("Error occurred dropping an image onto the
details window: %s\n"), image_error);
+
+ if (image_error)
+ g_free (image_error);
+ if (filename)
+ g_free (filename);
+
+ gtk_drag_finish (dc, FALSE, FALSE, time);
+ return;
+ }
+
+ if (details_writethrough(detail))
+ {
+ GList *list;
+ for (list = detail->tracks; list; list = list->next)
+ {
+ ExtraTrackData *etd;
+ Track *track = list->data;
+
+ if (!track)
+ break;
+
+ etd = track->userdata;
+ gp_track_set_thumbnails(track, filename);
+ etd->tchanged = TRUE;
+ etd->tartwork_changed = TRUE;
}
- #endif /* only if we have curl */
+ }
+ else
+ {
+ ExtraTrackData *etd = detail->track->userdata;
+ if (etd)
+ {
+ gp_track_set_thumbnails(detail->track, filename);
+ etd->tchanged = TRUE;
+ etd->tartwork_changed = TRUE;
+ }
+ }
+ detail->changed = TRUE;
+ details_update_thumbnail(detail);
+ details_update_buttons(detail);
- gtk_drag_finish (dc, FALSE, FALSE, time);
- return;
+ if (image_error)
+ g_free (image_error);
+
+ g_free (filename);
+ gtkpod_statusbar_message (_("Successfully set new coverart for selected
tracks"));
+ gtk_drag_finish (dc, FALSE, FALSE, time);
+ return;
}
Modified: gtkpod/trunk/src/display.h
===================================================================
--- gtkpod/trunk/src/display.h 2007-11-04 00:53:06 UTC (rev 1754)
+++ gtkpod/trunk/src/display.h 2007-11-05 01:16:19 UTC (rev 1755)
@@ -277,7 +277,8 @@
DND_GTKPOD_TM_PATHLIST,
DND_GTKPOD_PLAYLISTLIST,
DND_TEXT_URI_LIST,
- DND_TEXT_PLAIN
+ DND_TEXT_PLAIN,
+ DND_IMAGE_JPEG
};
/* used for the ST_CAT_SPECIAL user_data (see st_create_special and
Modified: gtkpod/trunk/src/display_coverart.c
===================================================================
--- gtkpod/trunk/src/display_coverart.c 2007-11-04 00:53:06 UTC (rev 1754)
+++ gtkpod/trunk/src/display_coverart.c 2007-11-05 01:16:19 UTC (rev 1755)
@@ -40,6 +40,7 @@
#include "fileselection.h"
#include <glib/gprintf.h>
#include "fetchcover.h"
+#include "info.h"
#define DEBUG 0
@@ -91,8 +92,10 @@
static gulong contentpanel_signal_id;
static GtkTargetEntry coverart_drop_types [] = {
-/* { DND_TEXT_UNICODE_TYPE, 0, DND_TEXT_UNICODE_TYPE_ID }, */
-/* { DND_FETCHCOVER_TEXT_PLAIN_TYPE, 0,
DND_FETCHCOVER_TEXT_PLAIN_TYPE_ID }, */
+ /* Konqueror supported flavours */
+ { "image/jpeg", 0, DND_IMAGE_JPEG },
+
+ /* Fallback flavours */
{ "text/plain", 0, DND_TEXT_PLAIN },
{ "STRING", 0, DND_TEXT_PLAIN }
};
@@ -1992,23 +1995,23 @@
GdkAtom target;
target = gtk_drag_dest_find_target (widget, drag_context, NULL);
- gchar *typeName = 0;
- typeName = gdk_atom_name(target);
-
if (target != GDK_NONE)
{
gtk_drag_get_data (widget, drag_context, target, time);
return TRUE;
}
+ /*
printf ("drop item\n");
gint i = 0;
for (i = 0; i < g_list_length(drag_context->targets); ++i)
{
target = g_list_nth_data (drag_context->targets, i);
printf ("Atom: %s\n", gdk_atom_name(target));
+ gtk_drag_get_data (widget, drag_context, target, time);
+ return TRUE;
}
-
- return TRUE;
+ */
+ return FALSE;
}
static gboolean dnd_coverart_drag_motion (GtkWidget *widget,
@@ -2059,70 +2062,149 @@
g_return_if_fail (dc);
g_return_if_fail (data);
g_return_if_fail (data->data);
+ g_return_if_fail (data->length > 0);
-#ifdef HAVE_CURL
-
- /* Deal with what we are given from source */
- if((data != NULL) && (data-> length >= 0))
- {
-
+ /* mozilla bug 402394 */
+
#if DEBUG
printf ("data length = %d\n", data->length);
printf ("data->data = %s\n", data->data);
#endif
- Cover_Item *cover;
- GList *tracks;
- gchar *url = NULL;
- Fetch_Cover *fcover;
- Track *track;
- gchar *filename;
+ Cover_Item *cover;
+ GList *tracks;
+ gchar *url = NULL;
+ Fetch_Cover *fcover;
+ Track *track;
+ gchar *filename = NULL;
+ gboolean image_status = FALSE;
+ gchar *image_error = NULL;
+ /* For use with DND_IMAGE_JPEG */
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
+
+ /* Find the display cover item in the cover display */
+ cover = g_ptr_array_index(cdwidget->cdcovers, IMG_MAIN);
+ tracks = cover->album->tracks;
- /* Find the display cover item in the cover display */
- cover = g_ptr_array_index(cdwidget->cdcovers, IMG_MAIN);
- tracks = cover->album->tracks;
-
- /* initialise the url string with the data from the dnd */
- url = (gchar *) data->data;
- /* Initialise a fetchcover object */
- fcover = fetchcover_new (url, tracks);
- coverart_block_change (TRUE);
-
- if (net_retrieve_image (fcover, NULL))
- {
+ switch (info)
+ {
+ case DND_IMAGE_JPEG:
#if DEBUG
- printf ("Successfully retrieved\n");
- printf ("Url of fetch cover: %s\n", fcover->url->str);
- printf ("filename of fetch cover: %s\n",
fcover->filename);
+ printf ("Using DND_IMAGE_JPEG\n");
#endif
- filename = g_build_filename(fcover->dir,
fcover->filename, NULL);
+ pixbuf = gtk_selection_data_get_pixbuf (data);
+ if (pixbuf != NULL)
+ {
+ /* initialise the url string with a safe value
as not used if already have image */
+ url = "local image";
+ /* Initialise a fetchcover object */
+ fcover = fetchcover_new (url, tracks);
+ coverart_block_change (TRUE);
+
+ /* find the filename with which to save the
pixbuf to */
+ if (fetchcover_select_filename (fcover))
+ {
+ filename =
g_build_filename(fcover->dir, fcover->filename, NULL);
+ if (! gdk_pixbuf_save (pixbuf,
filename, "jpeg", &error, NULL))
+ {
+ /* Save failed for some reason
*/
+ if (error->message)
+ fcover->err_msg =
g_strdup (error->message);
+ else
+ fcover->err_msg =
"Saving image to file failed. No internal error message was returned.";
+
+ g_error_free (error);
+ }
+ else
+ {
+ /* Image successfully saved */
+ image_status = TRUE;
+ }
+ }
+ /* record any errors and free the fetchcover */
+ if (fcover->err_msg != NULL)
+ image_error = g_strdup(fcover->err_msg);
+
+ free_fetchcover (fcover);
+ gdk_pixbuf_unref (pixbuf);
+ coverart_block_change (FALSE);
+ }
+ else
+ {
+ /* despite the data being of type image/jpeg,
the pixbuf is NULL */
+ image_error = "jpeg data flavour was used but
the data did not contain a GdkPixbuf object";
+ }
+ break;
+ case DND_TEXT_PLAIN:
+#if DEBUG
+ printf ("Defaulting to using DND_TEXT_PLAIN\n");
+#endif
- coverart_block_change (FALSE);
+#ifdef HAVE_CURL
+ /* initialise the url string with the data from the dnd
*/
+ url = g_strdup ((gchar *) data->data);
+ /* Initialise a fetchcover object */
+ fcover = fetchcover_new (url, tracks);
+ coverart_block_change (TRUE);
+
+ if (fetchcover_net_retrieve_image (fcover))
+ {
+ #if DEBUG
+ printf ("Successfully retrieved\n");
+ printf ("Url of fetch cover: %s\n",
fcover->url->str);
+ printf ("filename of fetch cover: %s\n",
fcover->filename);
+ #endif
- while (tracks)
- {
- track = tracks->data;
+ filename = g_build_filename(fcover->dir,
fcover->filename, NULL);
+ image_status = TRUE;
+ }
+
+ /* record any errors and free the fetchcover */
+ if (fcover->err_msg != NULL)
+ image_error = g_strdup(fcover->err_msg);
+
+ free_fetchcover (fcover);
+ coverart_block_change (FALSE);
+#else
+ image_error = g_strdup ("Item had to be downloaded but
gtkpod was not compiled with curl.");
+ image_status = FALSE;
+#endif
+ }
+
+ if (!image_status || filename == NULL)
+ {
+ gtkpod_warning (_("Error occurred dropping an image onto the
coverart display: %s\n"), image_error);
+
+ if (image_error)
+ g_free (image_error);
+ if (filename)
+ g_free (filename);
+
+ gtk_drag_finish (dc, FALSE, FALSE, time);
+ return;
+ }
+
+ while (tracks)
+ {
+ track = tracks->data;
- if (gp_track_set_thumbnails (track, filename))
- data_changed (track->itdb);
+ if (gp_track_set_thumbnails (track, filename))
+ data_changed (track->itdb);
- tracks = tracks->next;
- }
- /* Nullify so that the album art is picked up from the
tracks again */
- cover->album->albumart = NULL;
+ tracks = tracks->next;
+ }
+ /* Nullify so that the album art is picked up from the tracks again */
+ cover->album->albumart = NULL;
- set_covers (FALSE);
- }
- else
- {
- gtkpod_warning (_("%s\n"), fcover->err_msg);
- coverart_block_change (FALSE);
- }
-
- free_fetchcover (fcover);
- }
-#endif /* only if we have curl */
+ set_covers (FALSE);
+ if (image_error)
+ g_free (image_error);
+
+ g_free (filename);
+
+ gtkpod_statusbar_message (_("Successfully set new coverart for selected
tracks"));
gtk_drag_finish (dc, FALSE, FALSE, time);
return;
}
Modified: gtkpod/trunk/src/fetchcover.c
===================================================================
--- gtkpod/trunk/src/fetchcover.c 2007-11-04 00:53:06 UTC (rev 1754)
+++ gtkpod/trunk/src/fetchcover.c 2007-11-05 01:16:19 UTC (rev 1755)
@@ -40,6 +40,10 @@
#define IMGSCALE 256
+/* Display a dialog explaining the options if a file with the proposed name
already exists */
+static gchar *display_file_exist_dialog (Fetch_Cover *fetch_cover);
+static gchar *fetchcover_check_file_exists (Fetch_Cover *fetch_cover);
+
#ifdef HAVE_CURL
#include <curl/curl.h>
@@ -47,10 +51,7 @@
/* Declarations */
static void *safe_realloc(void *ptr, size_t size);
static size_t curl_write_fetchcover_func(void *ptr, size_t itemsize,
size_t numitems, void *data);
- /* Display a dialog explaining the options if a file with the proposed name
already exists */
- static gchar *display_file_exist_dialog (Fetch_Cover *fetch_cover,
GtkWindow *parent);
- static gchar *fetchcover_check_file_exists (Fetch_Cover *fetch_cover,
GtkWindow *window);
-
+
struct chunk
{
gchar *memory;
@@ -103,11 +104,13 @@
}
return size;
}
+#endif
/*****
- * net_retrieve_image:
+ * fetchcover_new:
*
* @GString: url
+ * @GList: trks
*
* Initialise a new fetch cover object for use with the fetchcover
functions
**/
@@ -120,10 +123,13 @@
fcover->url = g_string_new ((gchar*) url_path);
fcover->image = NULL;
fcover->tracks = trks;
-
+ fcover->err_msg = NULL;
+ fcover->parent_window = NULL;
+
return fcover;
}
+#ifdef HAVE_CURL
/*****
* net_retrieve_image:
*
@@ -133,17 +139,18 @@
* save it to a file inside the track's parent directory then display
* it as a pixbuf
**/
- gboolean net_retrieve_image (Fetch_Cover *fetch_cover, GtkWindow
*window)
+ gboolean fetchcover_net_retrieve_image (Fetch_Cover *fetch_cover)
{
g_return_val_if_fail (fetch_cover, FALSE);
if (! g_str_has_suffix(fetch_cover->url->str, ".jpg") && !
g_str_has_suffix(fetch_cover->url->str, ".JPG"))
{
- fetch_cover->err_msg = "Only jpg images are currently
supported at this time\n";
+ fetch_cover->err_msg = g_strdup("Only jpg images are
currently supported at this time\n");
return FALSE;
}
- gchar *path = NULL;
+ gchar *path = NULL;
+ FILE *tmpf = NULL;
fetchcover_curl_data.size = 0;
fetchcover_curl_data.memory = NULL;
@@ -161,64 +168,20 @@
if (fetchcover_curl_data.memory == NULL)
{
- fetch_cover->err_msg = "fetchcover curl data memory is
null so failed to download anything!\n";
+ fetch_cover->err_msg = g_strdup("fetchcover curl data
memory is null so failed to download anything!\n");
return FALSE;
}
/* Check that the page returned is a valid web page */
if (strstr(fetchcover_curl_data.memory, "<html>") != NULL)
{
- fetch_cover->err_msg = "fetchcover memory contains
<html> tag so not a valid jpg image\n";
+ fetch_cover->err_msg = g_strdup("fetchcover memory
contains <html> tag so not a valid jpg image\n");
return FALSE;
}
- FILE *tmpf = NULL;
- GList *tracks = fetch_cover->tracks;
-
- if (tracks == NULL || g_list_length (tracks) <= 0)
- {
- fetch_cover->err_msg = "fetchcover object's tracks list
either NULL or no tracks were selected\n";
+ if (! fetchcover_select_filename (fetch_cover))
return FALSE;
- }
- Track *track = g_list_nth_data (tracks, 0);
- ExtraTrackData *etd = track->userdata;
-
- fetch_cover->dir = g_path_get_dirname(etd->pc_path_utf8);
- gchar *template = prefs_get_string("coverart_template");
- gchar **template_items = g_strsplit(template, ";", 0);
-
- gint i;
- for (i = 0; fetch_cover->filename == NULL && i < g_strv_length
(template_items); ++i)
- {
- fetch_cover->filename = get_string_from_template(track,
template_items[i], FALSE, FALSE);
- if (strlen(fetch_cover->filename) == 0)
- fetch_cover->filename = NULL;
- }
-
- /* Check filename still equals null then take a default stance
- * to ensure the file has a name. Default stance applies if the
- * extra track data has been left as NULL
- */
- if (fetch_cover->filename == NULL)
- fetch_cover->filename = "folder.jpg";
- else
- {
- if (! g_str_has_suffix(fetch_cover->filename, ".jpg"))
- {
- gchar *oldname;
- oldname = fetch_cover->filename;
- fetch_cover->filename = g_strconcat(oldname,
".jpg", NULL);
- g_free (oldname);
- }
- }
-
- if (fetchcover_check_file_exists (fetch_cover, window) == NULL)
- {
- fetch_cover->err_msg = "operation cancelled\n";
- return FALSE;
- }
-
path = g_build_filename(fetch_cover->dir,
fetch_cover->filename, NULL);
#if DEBUG
printf ("path of download file is %s\n", path);
@@ -231,10 +194,8 @@
fetchcover_curl_data.memory = NULL;
fetchcover_curl_data.size = 0;
}
- g_strfreev(template_items);
- g_free(template);
g_free (path);
- fetch_cover->err_msg = "Failed to create a file with
the filename\n";
+ fetch_cover->err_msg = g_strdup ("Failed to create a
file with the filename\n");
return FALSE;
}
@@ -247,10 +208,8 @@
fetchcover_curl_data.size = 0;
}
fclose(tmpf);
- g_strfreev(template_items);
- g_free(template);
g_free (path);
- fetch_cover->err_msg = "fetchcover failed to write the
data to the new file\n";
+ fetch_cover->err_msg = g_strdup("fetchcover failed to
write the data to the new file\n");
return FALSE;
}
@@ -261,7 +220,7 @@
fileformat = gdk_pixbuf_get_file_info (path, NULL, NULL);
if (fileformat == NULL)
{
- fetch_cover->err_msg = "fetchcover downloaded file is
not a valid image file\n";
+ fetch_cover->err_msg = g_strdup("fetchcover downloaded
file is not a valid image file\n");
return FALSE;
}
@@ -276,8 +235,6 @@
fetchcover_curl_data.memory = NULL;
fetchcover_curl_data.size = 0;
}
- g_strfreev(template_items);
- g_free(template);
g_free(path);
fetch_cover->err_msg = g_strconcat ("fetchcover error
occurred while creating a pixbuf from the file\n", error->message, NULL);
return FALSE;
@@ -288,12 +245,65 @@
fetchcover_curl_data.memory = NULL;
fetchcover_curl_data.size = 0;
+ g_free(path);
+ return TRUE;
+ }
+#endif
+
+ gboolean fetchcover_select_filename (Fetch_Cover *fetch_cover)
+ {
+ GList *tracks = fetch_cover->tracks;
+
+ if (tracks == NULL || g_list_length (tracks) <= 0)
+ {
+ fetch_cover->err_msg = g_strdup("fetchcover object's
tracks list either NULL or no tracks were selected\n");
+ return FALSE;
+ }
+
+ Track *track = g_list_nth_data (tracks, 0);
+ ExtraTrackData *etd = track->userdata;
+
+ fetch_cover->dir = g_path_get_dirname(etd->pc_path_utf8);
+ gchar *template = prefs_get_string("coverart_template");
+ gchar **template_items = g_strsplit(template, ";", 0);
+
+ gint i;
+ for (i = 0; fetch_cover->filename == NULL && i < g_strv_length
(template_items); ++i)
+ {
+ fetch_cover->filename = get_string_from_template(track,
template_items[i], FALSE, FALSE);
+ if (strlen(fetch_cover->filename) == 0)
+ fetch_cover->filename = NULL;
+ }
+
g_strfreev(template_items);
g_free(template);
- g_free(path);
+
+ /* Check filename still equals null then take a default stance
+ * to ensure the file has a name. Default stance applies if the
+ * extra track data has been left as NULL
+ */
+ if (fetch_cover->filename == NULL)
+ fetch_cover->filename = "folder.jpg";
+ else
+ {
+ if (! g_str_has_suffix(fetch_cover->filename, ".jpg"))
+ {
+ gchar *oldname;
+ oldname = fetch_cover->filename;
+ fetch_cover->filename = g_strconcat(oldname,
".jpg", NULL);
+ g_free (oldname);
+ }
+ }
+
+ if (fetchcover_check_file_exists (fetch_cover) == NULL)
+ {
+ fetch_cover->err_msg = g_strdup("operation
cancelled\n");
+ return FALSE;
+ }
+
return TRUE;
}
-
+
/*****
* fetchcover_check_file_exists:
*
@@ -306,7 +316,7 @@
* Returns:
* Filename of chosen cover image file
***/
- static gchar *fetchcover_check_file_exists (Fetch_Cover *fetch_cover,
GtkWindow *window)
+ static gchar *fetchcover_check_file_exists (Fetch_Cover *fetch_cover)
{
gchar *newname = NULL;
/* The default cover image will have both dir and filename set
@@ -326,13 +336,13 @@
if (g_file_test (newname, G_FILE_TEST_EXISTS))
{
- newname = display_file_exist_dialog
(fetch_cover, window);
+ newname = display_file_exist_dialog
(fetch_cover);
}
}
return newname;
}
- static gchar *display_file_exist_dialog (Fetch_Cover *fetch_cover,
GtkWindow *parent)
+ static gchar *display_file_exist_dialog (Fetch_Cover *fetch_cover)
{
gchar *filepath;
gint result;
@@ -342,11 +352,11 @@
gchar *message;
GtkWidget *label;
- if (parent == NULL)
- parent = GTK_WINDOW(gtkpod_window);
+ if (fetch_cover->parent_window == NULL)
+ fetch_cover->parent_window = GTK_WINDOW(gtkpod_window);
GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Coverart
file already exists"),
-
parent,
+
fetch_cover->parent_window,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_YES,
GTK_RESPONSE_YES,
@@ -423,8 +433,6 @@
}
}
-#endif /* HAVE_CURL */
-
/****
* free_fetchcover:
*
@@ -451,4 +459,9 @@
if (fcover->err_msg)
g_free (fcover->err_msg);
+
+ if (fcover->parent_window)
+ fcover->parent_window = NULL;
+
+ g_free (fcover);
}
Modified: gtkpod/trunk/src/fetchcover.h
===================================================================
--- gtkpod/trunk/src/fetchcover.h 2007-11-04 00:53:06 UTC (rev 1754)
+++ gtkpod/trunk/src/fetchcover.h 2007-11-05 01:16:19 UTC (rev 1755)
@@ -49,10 +49,12 @@
gchar *filename;
GList *tracks;
gchar *err_msg;
+ GtkWindow *parent_window;
} Fetch_Cover;
Fetch_Cover *fetchcover_new (gchar *url_path, GList *trks);
-gboolean net_retrieve_image (Fetch_Cover *fetch_cover, GtkWindow *window);
+gboolean fetchcover_net_retrieve_image (Fetch_Cover *fetch_cover);
+gboolean fetchcover_select_filename (Fetch_Cover *fetch_cover);
void free_fetchcover (Fetch_Cover *fcover);
#endif
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: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2