Revision: 1568
          http://gtkpod.svn.sourceforge.net/gtkpod/?rev=1568&view=rev
Author:   phantom_sf
Date:     2007-06-20 15:50:11 -0700 (Wed, 20 Jun 2007)

Log Message:
-----------
2007-06-20 P.G. Richardson <phantom_sf at users.sourceforge.net>

        * details.c - details_copy_artwork
          Reintroduced if clause on whether to copy the artwork. If
          image file has been set by fetchcover then a tilde is appended
          to the filename. This method removes the tilde, renames the
          file and copies the artwork with the proper filename.
          
        * fetchcover.c
          Introduced flag USE_TILDA that is true when Details window calls
          fetchcover and false for when display coverart calls it. Tilda
          symbol added to end of filename if USE_TILDA set to true.
          Added references to dialog parents to properly control which
          windows can receive focus while dialogs are displayed.

Modified Paths:
--------------
    gtkpod/trunk/ChangeLog_detailed
    gtkpod/trunk/src/details.c
    gtkpod/trunk/src/fetchcover.c

Modified: gtkpod/trunk/ChangeLog_detailed
===================================================================
--- gtkpod/trunk/ChangeLog_detailed     2007-06-20 15:32:25 UTC (rev 1567)
+++ gtkpod/trunk/ChangeLog_detailed     2007-06-20 22:50:11 UTC (rev 1568)
@@ -1,3 +1,18 @@
+2007-06-20 P.G. Richardson <phantom_sf at users.sourceforge.net>
+
+       * details.c - details_copy_artwork
+         Reintroduced if clause on whether to copy the artwork. If
+         image file has been set by fetchcover then a tilde is appended
+         to the filename. This method removes the tilde, renames the
+         file and copies the artwork with the proper filename.
+         
+       * fetchcover.c
+         Introduced flag USE_TILDA that is true when Details window calls
+         fetchcover and false for when display coverart calls it. Tilda
+         symbol added to end of filename if USE_TILDA set to true.
+         Added references to dialog parents to properly control which
+         windows can receive focus while dialogs are displayed.
+
 2007-06-20 Jorg Schuler <jcsjcs at users.sourceforge.net>
 
        * data/gtkpod.glade

Modified: gtkpod/trunk/src/details.c
===================================================================
--- gtkpod/trunk/src/details.c  2007-06-20 15:32:25 UTC (rev 1567)
+++ gtkpod/trunk/src/details.c  2007-06-20 22:50:11 UTC (rev 1568)
@@ -38,6 +38,7 @@
 #include "misc_track.h"
 #include "prefs.h"
 #include <string.h>
+#include <glib/gstdio.h>
 
 /*
 void details_close (void);
@@ -500,11 +501,11 @@
 /****** Copy artwork data if filaname has changed ****** */
 static gboolean details_copy_artwork (Track *frtrack, Track *totrack)
 {
-    gboolean changed = FALSE;
-    ExtraTrackData *fretr, *toetr;
+               gboolean changed = FALSE;
+       ExtraTrackData *fretr, *toetr;
 
-    g_return_val_if_fail (frtrack, FALSE);
-    g_return_val_if_fail (totrack, FALSE);
+       g_return_val_if_fail (frtrack, FALSE);
+       g_return_val_if_fail (totrack, FALSE);
 
     fretr = frtrack->userdata;
     toetr = totrack->userdata;
@@ -514,18 +515,30 @@
 
     g_return_val_if_fail (fretr->thumb_path_locale, FALSE);
     g_return_val_if_fail (toetr->thumb_path_locale, FALSE);
-
-       itdb_artwork_free (totrack->artwork);
-       totrack->artwork = itdb_artwork_duplicate (frtrack->artwork);
-       totrack->artwork_size = frtrack->artwork_size;
-       totrack->artwork_count = frtrack->artwork_count;
-       totrack->has_artwork = frtrack->has_artwork;
-       g_free (toetr->thumb_path_locale);
-       g_free (toetr->thumb_path_utf8);
-       toetr->thumb_path_locale = g_strdup (fretr->thumb_path_locale);
-       toetr->thumb_path_utf8 = g_strdup (fretr->thumb_path_utf8);
-       changed = TRUE;
-    
+       
+       if (strcmp (fretr->thumb_path_locale, toetr->thumb_path_locale) != 0)
+  {
+       /* If filename ends with a ~ then remove it as we are preparing to save 
*/
+       if (g_str_has_suffix(fretr->thumb_path_locale, "~"))
+       {
+               gchar **basename = g_strsplit(fretr->thumb_path_locale, "~", 0);
+               g_rename (fretr->thumb_path_locale, basename[0]);
+               
+               gp_track_set_thumbnails (frtrack, basename[0]);
+               g_strfreev(basename);
+       }
+       
+               itdb_artwork_free (totrack->artwork);
+               totrack->artwork = itdb_artwork_duplicate (frtrack->artwork);
+               totrack->artwork_size = frtrack->artwork_size;
+               totrack->artwork_count = frtrack->artwork_count;
+               totrack->has_artwork = frtrack->has_artwork;
+               g_free (toetr->thumb_path_locale);
+               g_free (toetr->thumb_path_utf8);
+               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)

Modified: gtkpod/trunk/src/fetchcover.c
===================================================================
--- gtkpod/trunk/src/fetchcover.c       2007-06-20 15:32:25 UTC (rev 1567)
+++ gtkpod/trunk/src/fetchcover.c       2007-06-20 22:50:11 UTC (rev 1568)
@@ -37,7 +37,7 @@
 #define FETCHCOVER_DEBUG 1
 
 static void fetchcover_statusbar_update (gchar *message);
-static GtkDialog *fetchcover_display_dialog (Track *track, Itdb_Device 
*device);
+static GtkDialog *fetchcover_display_dialog (Track *track, Itdb_Device 
*device, GtkWindow *parent);
 static void fetchcover_debug(const gchar *format, ...);
 
 typedef struct
@@ -67,8 +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);
+/* Flag indicating whether the tilda should be used for the naming of the new 
file */
+static gboolean USE_TILDA = FALSE;
 
 #define IMGSCALE 256
 
@@ -85,7 +85,9 @@
 static void fetchcover_next_button_clicked (GtkWidget *widget, gpointer data);
 static void fetchcover_prev_button_clicked (GtkWidget *widget, gpointer data);
 static void fetchcover_cleanup();
-static gchar *fetchcover_save ();
+static gchar *fetchcover_save (GtkWindow *parent);
+/* Display a dialog explaining the options if a file with the proposed name 
already exists */
+static gchar *display_file_exist_dialog (gchar *filename, GtkWindow *parent);
 
 struct chunk
 {
@@ -561,10 +563,10 @@
  * Returns:
  * Filename of chosen cover image file
  */
-gchar *fetchcover_save ()
+gchar *fetchcover_save (GtkWindow *parent)
 {
        gchar *newname = NULL;
-       
+       gchar *tildaname = NULL;        
        /* The default cover image will have both dir and filename set
         * to null because no need to save because it is already saved (!!)
         * Thus, this whole process is avoided. Added bonus that pressing
@@ -585,7 +587,7 @@
 
                while (g_file_test (newname, G_FILE_TEST_EXISTS))
                {
-                       newname = display_file_exist_dialog (newname);
+                       newname = display_file_exist_dialog (newname, parent);
                        if (newname == NULL)
                                break;
                }
@@ -598,9 +600,19 @@
                
                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
+                * ie. After_Forever.jpg~. The tilda denotes that the file has 
changed so provides a
+                * signal for the details window to call copy_artwork
                 */
-               g_rename (oldname, newname);
+                
+                if (USE_TILDA)
+                {
+                       tildaname = g_strconcat (newname, "~", NULL);
+                       g_rename (oldname, tildaname);
+                }
+                else
+                {
+                       g_rename (oldname, newname);
+                }
                
                /* Tidy up to ensure the path will not get cleaned up
                 * by fetchcover_clean_up
@@ -612,11 +624,18 @@
                displayed_cover->dir = NULL;
                displayed_cover->filename = NULL;
        }
-       return newname; 
+       
+       if (USE_TILDA)
+       {
+               g_free (newname);
+               return tildaname;
+       }
+       
+       return newname;
 }
 #endif /* HAVE_CURL */
 
-static gchar *display_file_exist_dialog (gchar *filename)
+static gchar *display_file_exist_dialog (gchar *filename, GtkWindow *parent)
 {
        gint result;
        gchar **splitarr = NULL;
@@ -625,7 +644,7 @@
        gchar *message; 
        GtkWidget *label;
        GtkWidget *dialog = gtk_dialog_new_with_buttons ("Coverart file already 
exists",
-                                            NULL,
+                                            parent,
                                             GTK_DIALOG_MODAL | 
GTK_DIALOG_DESTROY_WITH_PARENT,
                                             GTK_STOCK_YES,
                                             GTK_RESPONSE_YES,
@@ -762,7 +781,7 @@
  *
  * @track: track to look up images for
  */
-static GtkDialog *fetchcover_display_dialog (Track *track, Itdb_Device *device)
+static GtkDialog *fetchcover_display_dialog (Track *track, Itdb_Device 
*device, GtkWindow *parent)
 {
        GnomeCanvasItem *art_border;
        GtkBox *canvasbutton_hbox;
@@ -778,6 +797,7 @@
        
        fetchcover_xml = glade_xml_new (xml_file, "fetchcover_dialog", NULL);
        fetchcover_dialog = gtkpod_xml_get_widget (fetchcover_xml, 
"fetchcover_dialog");
+       gtk_window_set_transient_for (GTK_WINDOW(fetchcover_dialog), parent);
        
        ExtraTrackData *etd;
        etd = track->userdata;
@@ -956,7 +976,9 @@
                return;
        }
        
-  GtkDialog *dialog = fetchcover_display_dialog (track, track->itdb->device);
+       USE_TILDA = FALSE;
+       GtkWindow *parent = GTK_WINDOW (gtkpod_xml_get_widget (main_window_xml, 
"gtkpod"));
+  GtkDialog *dialog = fetchcover_display_dialog (track, track->itdb->device, 
parent);
   g_return_if_fail (dialog);
 
   result = gtk_dialog_run (GTK_DIALOG (dialog));
@@ -969,7 +991,7 @@
  switch (result)
  {
        case GTK_RESPONSE_ACCEPT:
-      filename = fetchcover_save ();
+      filename = fetchcover_save (parent);
       if (filename)
       {
          while (tracks)
@@ -1002,9 +1024,12 @@
 {
     gint result;
     Detail *detail = details_get_selected_detail ();
-    GtkDialog *dialog = fetchcover_display_dialog (detail->track, 
detail->itdb->device);
+    GtkWindow *parent = GTK_WINDOW(detail->window);
+    GtkDialog *dialog = fetchcover_display_dialog (detail->track, 
detail->itdb->device, parent);
     g_return_if_fail (dialog);
-       
+               
+               /* Set the tilda flag for the naming of the new artwork file */
+               USE_TILDA = TRUE;
     result = gtk_dialog_run (GTK_DIALOG (dialog));
                gtk_widget_hide (GTK_WIDGET(dialog));
                gtk_widget_destroy (GTK_WIDGET(dialog));
@@ -1014,7 +1039,7 @@
     switch (result)
     {
     case GTK_RESPONSE_ACCEPT:          
-       filename = fetchcover_save ();
+       filename = fetchcover_save (parent);
        if (filename)
        {
            if (details_writethrough(detail))


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

Reply via email to