Update of /cvsroot/gtkpod/gtkpod/src
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv8724/src

Modified Files:
        file_itunesdb.c misc_track.c misc_track.h 
Log Message:
        * misc_track.c (add_tracks_to_playlist):
          - when dragging tracks from one iPod to another: remove
            original iPod path on copied track.
          - set DND origin data when dragging from a local repository
            to the iPod.

        * misc_track.[ch]: added
          gp_itdb_find_same_tracks_in_local_itdbs()

        * files_itunesdb.c: adjust rating and playcount in local
          databases when loading ipod.



Index: file_itunesdb.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file_itunesdb.c,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -d -r1.116 -r1.117
--- file_itunesdb.c     7 Apr 2007 14:55:49 -0000       1.116
+++ file_itunesdb.c     8 Apr 2007 10:12:15 -0000       1.117
@@ -866,6 +866,10 @@
  * gp_load_ipod: loads the contents of an iPod into @itdb. If data
  * already exists in @itdb, data is merged.
  *
+ * If new countrate and rating information is available, this
+ * information is adjusted within the local databases as well if the
+ * track can be identified in the local databases.
+ *
  * @itdb: repository to load iPod contents into. mountpoint must be
  * set, and the iPod must not be loaded already
  * (eitdb->itdb_imported).
@@ -878,7 +882,7 @@
     iTunesDB *new_itdb = NULL;
     gchar *mountpoint;
     gchar *itunesdb;
-    gboolean load = TRUE;
+    gboolean ok_to_load = TRUE;
 
     g_return_val_if_fail (itdb, NULL);
     g_return_val_if_fail (itdb->usertype & GP_ITDB_TYPE_IPOD, NULL);
@@ -907,21 +911,22 @@
 
        if (result == GTK_RESPONSE_YES)
        {
-           load = gp_ipod_init (itdb);
+           ok_to_load = gp_ipod_init (itdb);
        }
        else
        {
-           load = FALSE;
+           ok_to_load = FALSE;
        }
     }
     g_free (itunesdb);
     g_free (mountpoint);
 
-    if (load)
+    if (ok_to_load)
     {
        new_itdb = gp_merge_itdb (itdb);
        if (new_itdb)
        {
+           GList *gl;
            gchar *old_model = get_itdb_prefs_string (new_itdb,
                                                      KEY_IPOD_MODEL);
            gchar *new_model = itdb_device_get_sysinfo (new_itdb->device,
@@ -953,6 +958,37 @@
 #endif         
                set_itdb_prefs_string (new_itdb, KEY_IPOD_MODEL, new_model);
            }
+           /* adjust rating and playcount in local databases */
+           for (gl=new_itdb->tracks; gl; gl=gl->next)
+           {
+               Track *itr = gl->data;
+               g_return_val_if_fail (itr, new_itdb);
+               if ((itr->recent_playcount != 0) ||
+                   (itr->app_rating != itr->rating))
+               {
+                   GList *gl;
+                   GList *tracks = gp_itdb_find_same_tracks_in_local_itdbs 
(itr);
+                   for (gl=tracks; gl; gl=gl->next)
+                   {
+                       Track *ltr = gl->data;
+                       g_return_val_if_fail (ltr, new_itdb);
+
+                       if (itr->recent_playcount != 0)
+                       {
+                           ltr->playcount += itr->recent_playcount;
+                           ltr->recent_playcount += itr->recent_playcount;
+                       }
+                       if (itr->rating != itr->app_rating)
+                       {
+                           ltr->app_rating = ltr->rating;
+                           ltr->rating = itr->rating;
+                       }
+                       pm_track_changed (ltr);
+                       data_changed (ltr->itdb);
+                   }
+                   g_list_free (tracks);
+               }
+           }
        }
     }
     return new_itdb;

Index: misc_track.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc_track.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- misc_track.c        7 Apr 2007 14:55:49 -0000       1.62
+++ misc_track.c        8 Apr 2007 10:12:16 -0000       1.63
@@ -514,6 +514,36 @@
 }
 
 
+/* Find @track in all local repositories and return a list.
+
+   This function calls gp_itdb_find_same_tracks() for each local
+   repository and concatenates the results into one list.
+
+   Return value: a GList with matching tracks. You must call
+   g_list_free() on the list when it is no longer neede.
+*/
+GList *gp_itdb_find_same_tracks_in_local_itdbs (Track *track)
+{
+    GList *gl, *tracks=NULL;
+    struct itdbs_head *ih = gp_get_itdbs_head (gtkpod_window);
+
+    g_return_val_if_fail (ih, NULL);
+    g_return_val_if_fail (track, NULL);
+
+    for (gl=ih->itdbs; gl; gl=gl->next)
+    {
+       iTunesDB *itdb = gl->data;
+       g_return_val_if_fail (itdb, tracks);
+       if (itdb->usertype & GP_ITDB_TYPE_LOCAL)
+       {
+           GList *addtracks = gp_itdb_find_same_tracks (itdb, track);
+           tracks = g_list_concat (tracks, addtracks);
+       }
+    }
+    return tracks;
+}
+
+
 
 /* ------------------------------------------------------------ *\
 |                                                                |
@@ -1665,10 +1695,10 @@
                        g_free (eduptr->pc_path_utf8);
                        eduptr->pc_path_locale = itdb_filename_on_ipod (track);
                        eduptr->pc_path_utf8 = charset_to_utf8 
(eduptr->pc_path_locale);
-                       /* Remove old reference to iPod path */
-                       g_free (duptr->ipod_path);
-                       duptr->ipod_path = g_strdup ("");
                    }
+                   /* Remove old reference to iPod path */
+                   g_free (duptr->ipod_path);
+                   duptr->ipod_path = g_strdup ("");
                }
 
                if (!eduptr->pc_path_locale)
@@ -1681,6 +1711,13 @@
                    return;
                }
 
+               if ((from_itdb->usertype & GP_ITDB_TYPE_LOCAL) &&
+                   (to_itdb->usertype & GP_ITDB_TYPE_IPOD))
+               {   /* make sure the DND origin data is set correctly */
+                   eduptr->local_itdb_id = from_itdb->id;
+                   eduptr->local_track_dbid = track->dbid;
+               }
+
                /* add to database -- if duplicate detection is on and the
                   same track already exists in the database, the already
                   existing track is returned and @duptr is freed */

Index: misc_track.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc_track.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- misc_track.h        7 Apr 2007 14:55:49 -0000       1.17
+++ misc_track.h        8 Apr 2007 10:12:16 -0000       1.18
@@ -47,6 +47,7 @@
 void gp_itdb_pc_path_hash_remove_track (Track *track);
 GList *gp_itdb_pc_path_hash_find_tracks (iTunesDB *itdb, const gchar 
*filename);
 GList *gp_itdb_find_same_tracks (iTunesDB *itdb, Track *track);
+GList *gp_itdb_find_same_tracks_in_local_itdbs (Track *track);
 
 gchar **track_get_item_pointer (Track *track, T_item t_item);
 const gchar *track_get_item (Track *track, T_item t_item);


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to