commit 1968080128bbc4ded4fe8f31ae420b3b42a5e578
Author: phantomjinx <p.g.richard...@phantomjinx.co.uk>
Date:   Sun Mar 13 19:20:08 2011 +0000

    trial attempt at converting itdb

 libgtkpod/autodetection.c                   |   30 +++---
 libgtkpod/file.h                            |    3 +-
 libgtkpod/file_itunesdb.c                   |  149 +++++++++---------------
 libgtkpod/gp_itdb.c                         |  168 +++++++++++++++++++++++----
 libgtkpod/gp_itdb.h                         |    1 +
 libgtkpod/prefs.c                           |    2 +
 libgtkpod/prefs.h                           |    2 +
 plugins/repository_editor/repository_init.c |    2 +-
 8 files changed, 223 insertions(+), 134 deletions(-)
---
diff --git a/libgtkpod/autodetection.c b/libgtkpod/autodetection.c
index e0bc5b0..75c1371 100644
--- a/libgtkpod/autodetection.c
+++ b/libgtkpod/autodetection.c
@@ -73,25 +73,23 @@ static iTunesDB *ad_find_repository_with_mountpoint(const 
gchar *mountpoint) {
         iTunesDB *itdb = gl->data;
         g_return_val_if_fail (itdb, NULL);
 
-        if (itdb->usertype & GP_ITDB_TYPE_IPOD) {
-            gchar *imp = get_itdb_prefs_string(itdb, KEY_MOUNTPOINT);
-            if (imp) {
-                gint comp;
-                gint lenimp = strlen(imp);
-
-                /* eliminate trailing dir separators ('/') */
-                if ((lenimp > 0) && (imp[lenimp - 1] == G_DIR_SEPARATOR)) {
-                    imp[lenmp - 1] = 0;
-                }
+        gchar *imp = get_itdb_prefs_string(itdb, KEY_MOUNTPOINT);
+        if (imp) {
+            gint comp;
+            gint lenimp = strlen(imp);
+
+            /* eliminate trailing dir separators ('/') */
+            if ((lenimp > 0) && (imp[lenimp - 1] == G_DIR_SEPARATOR)) {
+                imp[lenmp - 1] = 0;
+            }
 
-                comp = strcmp(mp, imp);
+            comp = strcmp(mp, imp);
 
-                g_free(imp);
+            g_free(imp);
 
-                if (comp == 0) {
-                    result = itdb;
-                    break;
-                }
+            if (comp == 0) {
+                result = itdb;
+                break;
             }
         }
     }
diff --git a/libgtkpod/file.h b/libgtkpod/file.h
index 9c99785..55440e4 100644
--- a/libgtkpod/file.h
+++ b/libgtkpod/file.h
@@ -77,8 +77,7 @@ void update_tracks (GList *selected_tracks);
 void display_non_updated (Track *track, gchar *txt);
 void display_updated (Track *track, gchar *txt);
 iTunesDB *gp_import_itdb (iTunesDB *old_itdb, const gint type,
-                         const gchar *mp, const gchar *name_off,
-                         const gchar *name_loc);
+                         const gchar *mp, const gchar *name_off);
 void gp_load_ipods (void);
 iTunesDB *gp_load_ipod (iTunesDB *itdb);
 gboolean gp_eject_ipod(iTunesDB *itdb);
diff --git a/libgtkpod/file_itunesdb.c b/libgtkpod/file_itunesdb.c
index d947106..5d0ff08 100644
--- a/libgtkpod/file_itunesdb.c
+++ b/libgtkpod/file_itunesdb.c
@@ -412,9 +412,9 @@ static void load_photodb(iTunesDB *itdb, GString *errors) {
  * @type: GP_ITDB_TYPE_LOCAL/IPOD (bitwise flags!)
  * @mp: mount point of iPod (if reading an iPod iTunesDB)
  * @name_off: name of the iTunesDB in offline mode
- * @name_loc: name of iTunesDB (if reading a local file browser) */
-/* Return value: a new iTunesDB structure or NULL in case of an error */
-iTunesDB *gp_import_itdb(iTunesDB *old_itdb, const gint type, const gchar *mp, 
const gchar *name_off, const gchar *name_loc) {
+ * Return value: a new iTunesDB structure or NULL in case of an error
+ */
+iTunesDB *gp_import_itdb(iTunesDB *old_itdb, const gint type, const gchar *mp, 
const gchar *name_off) {
     gchar *cfgdir;
     GList *gl;
     Playlist *pod_pl;
@@ -425,9 +425,7 @@ iTunesDB *gp_import_itdb(iTunesDB *old_itdb, const gint 
type, const gchar *mp, c
     gint32 total, num;
     gboolean offline;
 
-    g_return_val_if_fail (!(type & GP_ITDB_TYPE_LOCAL) || name_loc, NULL);
-    g_return_val_if_fail (!(type & GP_ITDB_TYPE_IPOD) ||
-            (mp && name_off), NULL);
+    g_return_val_if_fail (mp && name_off, NULL);
 
     cfgdir = prefs_get_cfgdir();
     g_return_val_if_fail (cfgdir, NULL);
@@ -438,18 +436,11 @@ iTunesDB *gp_import_itdb(iTunesDB *old_itdb, const gint 
type, const gchar *mp, c
         offline = FALSE;
 
     block_widgets();
-    if (offline || (type & GP_ITDB_TYPE_LOCAL)) { /* offline or local database 
- requires extended info */
+    if (offline) { /* offline - requires extended info */
         gchar *name_ext;
         gchar *name_db;
-
-        if (type & GP_ITDB_TYPE_LOCAL) {
-            name_ext = g_strdup_printf("%s.ext", name_loc);
-            name_db = g_strdup(name_loc);
-        }
-        else {
-            name_ext = g_strdup_printf("%s.ext", name_off);
-            name_db = g_strdup(name_off);
-        }
+        name_ext = g_strdup_printf("%s.ext", name_off);
+        name_db = g_strdup(name_off);
 
         if (g_file_test(name_db, G_FILE_TEST_EXISTS)) {
             if (WRITE_EXTENDED_INFO) {
@@ -460,29 +451,20 @@ iTunesDB *gp_import_itdb(iTunesDB *old_itdb, const gint 
type, const gchar *mp, c
                     msg
                             = g_strconcat(msg, _("This database identifies the 
track on disk with the track data in the repository database. "), _("Any tracks 
already in the database cannot be transferred between repositories without the 
extended database. "), _("A new extended database will be created upon saving 
but existing tracks will need to be reimported to be linked to the file on 
disk.\n\n"), NULL);
                     g_string_append(errors, msg);
+                    g_free(msg);
                 }
             }
             itdb = itdb_parse_file(name_db, &error);
             if (itdb && !error) {
-                if (type & GP_ITDB_TYPE_IPOD)
-                    gtkpod_statusbar_message(_("Offline iPod database 
successfully imported"));
-                else
-                    gtkpod_statusbar_message(_("Local database successfully 
imported"));
+                gtkpod_statusbar_message(_("Offline iPod database successfully 
imported"));
             }
             else {
                 if (error) {
-                    if (type & GP_ITDB_TYPE_IPOD)
-                        g_string_append_printf(errors, _("Offline iPod 
database import failed: '%s'\n\n"), error->message);
-                    else
-                        g_string_append_printf(errors, _("Local database 
import failed: '%s'\n\n"), error->message);
-
+                    g_string_append_printf(errors, _("Offline iPod database 
import failed: '%s'\n\n"), error->message);
                     g_error_free(error);
                 }
                 else {
-                    if (type & GP_ITDB_TYPE_IPOD)
-                        g_string_append(errors, _("Offline iPod database 
import failed: \n\n"));
-                    else
-                        g_string_append(errors, _("Local database import 
failed: \n\n"));
+                    g_string_append(errors, _("Offline iPod database import 
failed: \n\n"));
                 }
             }
         }
@@ -492,7 +474,7 @@ iTunesDB *gp_import_itdb(iTunesDB *old_itdb, const gint 
type, const gchar *mp, c
         g_free(name_ext);
         g_free(name_db);
     }
-    else { /* GP_ITDB_TYPE_IPOD _and_ iPod is connected */
+    else { /* iPod is connected */
         gchar *name_ext = NULL, *name_db = NULL;
 
         name_db = itdb_get_itunesdb_path(mp);
@@ -543,14 +525,12 @@ iTunesDB *gp_import_itdb(iTunesDB *old_itdb, const gint 
type, const gchar *mp, c
 
     /* fill in additional info */
     itdb->usertype = type;
-    if (type & GP_ITDB_TYPE_IPOD) {
-        if (offline) {
-            itdb_set_mountpoint(itdb, mp);
-            g_free(itdb->filename);
-            itdb->filename = NULL;
-        }
-        eitdb->offline_filename = g_strdup(name_off);
+    if (offline) {
+        itdb_set_mountpoint(itdb, mp);
+        g_free(itdb->filename);
+        itdb->filename = NULL;
     }
+    eitdb->offline_filename = g_strdup(name_off);
 
     total = g_list_length(itdb->tracks);
     num = 1;
@@ -692,19 +672,19 @@ iTunesDB *gp_import_itdb(iTunesDB *old_itdb, const gint 
type, const gchar *mp, c
 
     if (errors && errors->len > 0) {
         gtkpod_confirmation(-1, /* gint id, */
-                TRUE, /* gboolean modal, */
-                _("Import Repository Errors"), /* title */
-                _("Errors created during repository import"), /* label */
-                errors->str, /* scrolled text */
-                NULL, 0, NULL, /* option 1 */
-                NULL, 0, NULL, /* option 2 */
-                TRUE, /* gboolean confirm_again, */
-                "show_itdb_import_errors",/* confirm_again_key,*/
-                CONF_NULL_HANDLER, /* ConfHandler ok_handler,*/
-                NULL, /* don't show "Apply" button */
-                NULL, /* cancel_handler,*/
-                NULL, /* gpointer user_data1,*/
-                NULL); /* gpointer user_data2,*/
+        TRUE, /* gboolean modal, */
+        _("Import Repository Errors"), /* title */
+        _("Errors created during repository import"), /* label */
+        errors->str, /* scrolled text */
+        NULL, 0, NULL, /* option 1 */
+        NULL, 0, NULL, /* option 2 */
+        TRUE, /* gboolean confirm_again, */
+        "show_itdb_import_errors",/* confirm_again_key,*/
+        CONF_NULL_HANDLER, /* ConfHandler ok_handler,*/
+        NULL, /* don't show "Apply" button */
+        NULL, /* cancel_handler,*/
+        NULL, /* gpointer user_data1,*/
+        NULL); /* gpointer user_data2,*/
 
         g_string_free(errors, TRUE);
     }
@@ -750,22 +730,11 @@ static iTunesDB *gp_merge_itdb(iTunesDB *old_itdb) {
     old_eitdb = old_itdb->userdata;
     g_return_val_if_fail (old_eitdb, NULL);
 
-    if (old_itdb->usertype & GP_ITDB_TYPE_LOCAL) {
-        g_return_val_if_fail (old_itdb->filename, NULL);
-
-        new_itdb = gp_import_itdb(old_itdb, old_itdb->usertype, NULL, NULL, 
old_itdb->filename);
-    }
-    else if (old_itdb->usertype & GP_ITDB_TYPE_IPOD) {
-        const gchar *mountpoint = itdb_get_mountpoint(old_itdb);
-        g_return_val_if_fail (mountpoint, NULL);
-        g_return_val_if_fail (old_eitdb->offline_filename, NULL);
-
-        new_itdb = gp_import_itdb(old_itdb, old_itdb->usertype, mountpoint, 
old_eitdb->offline_filename, NULL);
-    }
-    else {
-        g_return_val_if_reached (NULL);
-    }
+    const gchar *mountpoint = itdb_get_mountpoint(old_itdb);
+    g_return_val_if_fail (mountpoint, NULL);
+    g_return_val_if_fail (old_eitdb->offline_filename, NULL);
 
+    new_itdb = gp_import_itdb(old_itdb, old_itdb->usertype, mountpoint, 
old_eitdb->offline_filename);
     if (new_itdb) {
         gp_replace_itdb(old_itdb, new_itdb);
         /* take care of autosync... */
@@ -1244,7 +1213,6 @@ static gdouble set_progress(time_t start, gint n, gint 
count, gint init_count, g
                 = g_strdup_printf(_("%d%% (%d/%d  %d:%02d:%02d left)  %s"), 
(gint) (fraction * 100), count, n, (gint) hrs, (gint) mins, (gint) secs, msg);
     }
 
-
     gdouble ticks = fraction - old_fraction;
     gtkpod_statusbar_increment_progress_ticks(ticks * 100, progtext);
 
@@ -1510,8 +1478,8 @@ static gboolean transfer_tracks(iTunesDB *itdb, 
TransferData *td) {
             }
         }
 
-        td->current_progress = set_progress(start, to_convert_num + 
converting_num + to_transfer_num + failed_num + transferred_num, transferred_num
-                        + failed_num, transferred_init, td->current_progress, 
buf);
+        td->current_progress = set_progress(start, to_convert_num + 
converting_num + to_transfer_num + failed_num
+                + transferred_num, transferred_num + failed_num, 
transferred_init, td->current_progress, buf);
 
         if ((to_convert_num != 0) && (converting_num == 0)) { /* Force the 
conversion to continue. Not sure if this scenario
          * is likely to happen, but better be safe then sorry */
@@ -1665,7 +1633,17 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
         gp_track_cleanup_empty_strings((Itdb_Track *) it->data);
     }
 
-    if (success && !get_offline(itdb) && (itdb->usertype & GP_ITDB_TYPE_IPOD)) 
{ /* write to the iPod */
+    const Itdb_IpodInfo *info;
+    if (success && !get_offline(itdb) && gp_itdb_has_mountpoint(itdb)) { /* 
write to the iPod */
+        g_warning("Supposed modelnum %s", itdb_device_get_sysinfo 
(itdb->device, "ModelNumStr"));
+        info = itdb_device_get_ipod_info (itdb->device);
+        g_warning("device info: %d %d", info->ipod_generation, 
info->ipod_model);
+
+        if (itdb_device_supports_artwork(itdb->device))
+            g_warning("Does support artwork");
+        else
+            g_warning("Does not support artwork");
+
         GError *error = NULL;
         if (!itdb_write(itdb, &error)) { /* an error occurred */
             success = FALSE;
@@ -1677,7 +1655,11 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
             error = NULL;
         }
 
-        if (success) { /* write shuffle data */
+        /*
+         * write shuffle data but only if an ipod since the local
+         * and podcast dbs definitely are not shuffles
+         */
+        if (success && (itdb->usertype & GP_ITDB_TYPE_IPOD)) {
             if (!itdb_shuffle_write(itdb, &error)) { /* an error occurred */
                 success = FALSE;
                 if (error && error->message) {
@@ -1750,7 +1732,7 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
         }
     }
 
-    if (success && get_offline(itdb) && (itdb->usertype & GP_ITDB_TYPE_IPOD)) 
{ /* write to cfgdir */
+    if (success && get_offline(itdb) && gp_itdb_has_mountpoint(itdb)) { /* 
write to cfgdir */
         GError *error = NULL;
         if (!itdb_write_file(itdb, eitdb->offline_filename, &error)) { /* an 
error occurred */
             success = FALSE;
@@ -1766,22 +1748,6 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
         }
     }
 
-    if (success && (itdb->usertype & GP_ITDB_TYPE_LOCAL)) { /* write to cfgdir 
*/
-        GError *error = NULL;
-        if (!itdb_write_file(itdb, NULL, &error)) { /* an error occurred */
-            success = FALSE;
-            if (error && error->message)
-                gtkpod_warning("%s\n\n", error->message);
-                else
-                g_warning ("error->message == NULL!\n");
-            g_error_free(error);
-            error = NULL;
-        }
-        if (success) { /* write extended information */
-            success = write_extended_info(itdb);
-        }
-    }
-
     for (it = itdb->tracks; it != NULL; it = it->next) {
         gp_track_validate_entries((Itdb_Track *) it->data);
     }
@@ -1789,7 +1755,7 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
     /* If the ipod supports photos and the photo_data_changed
      * flag has been set to true then wrtie the photo database
      */
-    if (success && (itdb->usertype & GP_ITDB_TYPE_IPOD) && 
itdb_device_supports_photo(itdb->device) && eitdb->photodb
+    if (success && gp_itdb_has_mountpoint(itdb) && 
itdb_device_supports_photo(itdb->device) && eitdb->photodb
             != NULL && eitdb->photo_data_changed == TRUE) {
         GError *error = NULL;
         if (!itdb_photodb_write(eitdb->photodb, &error)) {
@@ -1807,12 +1773,7 @@ static gboolean gp_write_itdb(iTunesDB *itdb) {
     /* indicate that files and/or database is saved */
     if (success) {
         data_unchanged(itdb);
-        if (itdb->usertype & GP_ITDB_TYPE_IPOD) {
-            gtkpod_statusbar_message(_("%s: Database saved"), mpl->name);
-        }
-        else {
-            gtkpod_statusbar_message(_("%s: Changes saved"), mpl->name);
-        }
+        gtkpod_statusbar_message(_("%s: Changes saved"), mpl->name);
     }
 
     g_free(cfgdir);
diff --git a/libgtkpod/gp_itdb.c b/libgtkpod/gp_itdb.c
index b95847e..63ce111 100644
--- a/libgtkpod/gp_itdb.c
+++ b/libgtkpod/gp_itdb.c
@@ -48,10 +48,129 @@
 #include "clientserver.h"
 #include "gtkpod_app_iface.h"
 
+#define CONVERT_ERR_MESSAGE "Failed to convert local itunes db from file to a 
directory."
+
 /* A struct containing a list with available iTunesDBs. A pointer to
  this struct is stored in gtkpod_app as itdbs_head */
 static struct itdbs_head *itdbs_head = NULL;
 
+static gchar *gp_convert_itdb_file_to_directory (gint index, gint itdb_type, 
gchar *filename) {
+
+    g_return_val_if_fail((itdb_type & GP_ITDB_TYPE_PODCASTS) || (itdb_type & 
GP_ITDB_TYPE_LOCAL), NULL);
+
+    GError *error = NULL;
+    gboolean result;
+
+    if (!filename) {
+        gchar *local = g_strdup_printf("local%d.itdb", index);
+        filename = g_build_filename(prefs_get_cfgdir(), local, NULL);
+        g_free(local);
+    }
+
+    g_message("Filename: %s", filename);
+
+    gchar *db_name_key = get_itdb_prefs_key(index, KEY_NAME);
+    gchar *db_name = prefs_get_string(db_name_key);
+    g_free(db_name_key);
+
+    if (! db_name) {
+        if (itdb_type & GP_ITDB_TYPE_PODCASTS)
+            db_name = g_strdup(_("Podcasts"));
+        else
+            db_name = g_strdup(_("Local"));
+    }
+
+    /* Determine the new mountpoint */
+    gchar *mountpoint = g_build_filename(prefs_get_cfgdir(), 
g_strdup_printf("%s_%d", g_utf8_strdown(db_name, -1), index), NULL);
+    while (g_file_test(mountpoint, G_FILE_TEST_EXISTS)) {
+        gchar *mp = g_strdup_printf("%s1", mountpoint);
+        g_free(mountpoint);
+        mountpoint = mp;
+    }
+
+    g_message("Chosen mountpoint: %s", mountpoint);
+
+    /* initialise a blank itdb in the mountpoint */
+    const Itdb_IpodInfo *info = itdb_info_get_ipod_info_table();
+    while(info->model_number) {
+        if (info->ipod_generation == ITDB_IPOD_GENERATION_CLASSIC_3) {
+            break;
+        }
+        ++info;
+    }
+
+    result = itdb_init_ipod(mountpoint, info->model_number, db_name, &error);
+    g_free(db_name);
+
+    if (!result) {
+        if (error) {
+            gtkpod_warning(_("%s : %s\n"), CONVERT_ERR_MESSAGE, 
error->message);
+            g_error_free(error);
+            error = NULL;
+        }
+        else {
+            gtkpod_warning(_("%s, unknown error initialising directory 
structure\n"), CONVERT_ERR_MESSAGE);
+        }
+        g_free(mountpoint);
+        return NULL;
+    }
+
+    /* Copy in the itdb file to replace the blank itdb */
+    gchar *itunesdb = itdb_get_itunesdb_path(mountpoint);
+    GFile *oldfile = g_file_new_for_path(filename);
+    GFile *newfile = g_file_new_for_path(itunesdb);
+    g_free(itunesdb);
+
+    result = g_file_copy(oldfile, newfile, G_FILE_COPY_OVERWRITE, NULL, NULL, 
NULL, &error);
+    g_object_unref(oldfile);
+    g_object_unref(newfile);
+
+    if (!result) {
+        if (error) {
+            gtkpod_warning(_("%s : %s\n"), CONVERT_ERR_MESSAGE, 
error->message);
+            g_error_free(error);
+            error = NULL;
+        }
+        else {
+            gtkpod_warning(_("%s, unknown error copying in existing itdb.\n"), 
CONVERT_ERR_MESSAGE);
+        }
+        g_free(mountpoint);
+        return NULL;
+    }
+
+    /* Copy in the itdb ext */
+    gchar *oldextfilename = g_strdup_printf("%s.ext", filename);
+    gchar *newextfilename = g_strdup_printf("%s.ext", 
itdb_get_itunesdb_path(mountpoint));
+    oldfile = g_file_new_for_path(oldextfilename);
+    newfile = g_file_new_for_path(newextfilename);
+    g_free(oldextfilename);
+    g_free(newextfilename);
+
+    result = g_file_copy(oldfile, newfile, G_FILE_COPY_OVERWRITE, NULL, NULL, 
NULL, &error);
+    g_object_unref(oldfile);
+    g_object_unref(newfile);
+
+    if (!result) {
+        if (error) {
+            gtkpod_warning(_("%s : %s\n"), CONVERT_ERR_MESSAGE, 
error->message);
+            g_error_free(error);
+            error = NULL;
+        }
+        else {
+            gtkpod_warning(_("%s, unknown error copying in existing itdb ext 
file.\n"), CONVERT_ERR_MESSAGE);
+        }
+        g_free(mountpoint);
+        return NULL;
+    }
+
+    /* Successfully created new itdb */
+
+    /* Update preferences of this itdb */
+    set_itdb_index_prefs_string(index, KEY_MOUNTPOINT, mountpoint);
+
+    return mountpoint;
+}
+
 /* for convenience */
 struct itdbs_head *gp_get_itdbs_head() {
     g_return_val_if_fail(gtkpod_app, NULL);
@@ -186,6 +305,10 @@ void gp_itdb_add_extra_full(iTunesDB *itdb) {
     }
 }
 
+gboolean gp_itdb_has_mountpoint(iTunesDB *itdb) {
+    return itdb_get_mountpoint(itdb) != NULL;
+}
+
 Playlist *gp_playlist_new(const gchar *title, gboolean spl) {
     Playlist *pl = itdb_playlist_new(title, spl);
     pl->userdata = g_new0 (ExtraPlaylistData, 1);
@@ -859,7 +982,7 @@ void gp_init_itdbs() {
  system. */
 iTunesDB *setup_itdb_n(gint i) {
     iTunesDB *itdb = NULL;
-    gchar *property = get_itdb_prefs_key(i, "type");
+    gchar *property = get_itdb_prefs_key(i, KEY_TYPE);
     gint type;
     gboolean valid = prefs_get_int_value(property, &type);
     g_free(property);
@@ -868,33 +991,36 @@ iTunesDB *setup_itdb_n(gint i) {
         Playlist *pl = NULL;
         ExtraiTunesDBData *eitdb;
         gchar *filename = NULL;
-        gchar *mountpoint = NULL;
         gchar *offline_filename = NULL;
+        gchar *mountpoint = NULL;
 
-        if (type & GP_ITDB_TYPE_LOCAL) {
-            gchar *fn = get_itdb_prefs_key(i, "filename");
+        /* Read filename from preferences */
+        gchar *filename_key = get_itdb_prefs_key(i, KEY_FILENAME);
+        if (filename_key) {
+            filename = prefs_get_string(filename_key);
+        }
+        g_free(filename_key);
 
-            filename = prefs_get_string(fn);
+        /* Read mountpoint from preferences */
+        gchar *mountpoint_key = get_itdb_prefs_key(i, KEY_MOUNTPOINT);
+        if (mountpoint_key) {
+            mountpoint = prefs_get_string(mountpoint_key);
+        }
+        g_free(mountpoint_key);
 
-            if (!filename) {
-                gchar *local = g_strdup_printf("local%d.itdb", i);
-                filename = g_build_filename(cfgdir, local, NULL);
-                g_free(local);
+        if (type & GP_ITDB_TYPE_LOCAL) {
+            if (!mountpoint) {
+                /* This is the old style itdb file */
+                g_warning("Deprecated file structure ... Converting local 
itdb");
+                mountpoint = gp_convert_itdb_file_to_directory(i, type, 
filename);
             }
-            g_free(fn);
-            if (g_file_test(filename, G_FILE_TEST_EXISTS))
-                itdb = gp_import_itdb(NULL, type, NULL, NULL, filename);
+
+            if (g_file_test(mountpoint, G_FILE_TEST_EXISTS))
+                itdb = gp_import_itdb(NULL, type, mountpoint, filename);
         }
         else if (type & GP_ITDB_TYPE_IPOD) {
-            gchar *key;
-
-            key = get_itdb_prefs_key(i, KEY_MOUNTPOINT);
-            mountpoint = prefs_get_string(key);
-            g_free(key);
-
-            key = get_itdb_prefs_key(i, "filename");
-            offline_filename = prefs_get_string(key);
-            g_free(key);
+            offline_filename = filename;
+            filename = NULL;
 
             if (!offline_filename) {
                 gchar *local = g_strdup_printf("gtkpod_%d.itdb", i);
diff --git a/libgtkpod/gp_itdb.h b/libgtkpod/gp_itdb.h
index 74e6b71..a56e9cc 100644
--- a/libgtkpod/gp_itdb.h
+++ b/libgtkpod/gp_itdb.h
@@ -134,6 +134,7 @@ void gp_itdb_free (iTunesDB *itdb);
 void gp_replace_itdb (iTunesDB *old_itdb, iTunesDB *new_itdb);
 void gp_itdb_add_extra (iTunesDB *itdb);
 void gp_itdb_add_extra_full (iTunesDB *itdb);
+gboolean gp_itdb_has_mountpoint(iTunesDB *itdb);
 
 Track *gp_track_new (void);
 #define gp_track_free itdb_track_free
diff --git a/libgtkpod/prefs.c b/libgtkpod/prefs.c
index 249d71d..15c8abc 100644
--- a/libgtkpod/prefs.c
+++ b/libgtkpod/prefs.c
@@ -73,6 +73,8 @@ const gchar *KEY_MOUNTPOINT = "mountpoint";
 const gchar *KEY_BACKUP = "filename";
 const gchar *KEY_IPOD_MODEL = "ipod_model";
 const gchar *KEY_FILENAME = "filename";
+const gchar *KEY_TYPE = "type";
+const gchar *KEY_NAME = "name";
 const gchar *KEY_PATH_SYNC_CONTACTS = "path_sync_contacts";
 const gchar *KEY_PATH_SYNC_CALENDAR = "path_sync_calendar";
 const gchar *KEY_PATH_SYNC_NOTES = "path_sync_notes";
diff --git a/libgtkpod/prefs.h b/libgtkpod/prefs.h
index 585f721..212d46a 100644
--- a/libgtkpod/prefs.h
+++ b/libgtkpod/prefs.h
@@ -53,6 +53,8 @@ extern const gchar *KEY_SYNC_SHOW_SUMMARY;
 extern const gchar *KEY_MOUNTPOINT;
 extern const gchar *KEY_IPOD_MODEL;
 extern const gchar *KEY_FILENAME;
+extern const gchar *KEY_TYPE;
+extern const gchar *KEY_NAME;
 extern const gchar *KEY_PATH_SYNC_CONTACTS;
 extern const gchar *KEY_PATH_SYNC_CALENDAR;
 extern const gchar *KEY_PATH_SYNC_NOTES;
diff --git a/plugins/repository_editor/repository_init.c 
b/plugins/repository_editor/repository_init.c
index ed69c89..901d458 100644
--- a/plugins/repository_editor/repository_init.c
+++ b/plugins/repository_editor/repository_init.c
@@ -177,7 +177,7 @@ gboolean repository_ipod_init(iTunesDB *itdb) {
         model = gtk_combo_box_get_active_text(GTK_COMBO_BOX (GET_WIDGET 
(ii->builder, IID_MODEL_COMBO)));
         if ((strcmp(model, gettext(SELECT_OR_ENTER_YOUR_MODEL)) == 0) || 
(strlen(model) == 0)) { /* User didn't choose a model */
             g_free(model);
-            model = NULL;
+            model = "Unknown";
         }
 
         /* Set model in the prefs system */

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
gtkpod-cvs2 mailing list
gtkpod-cvs2@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to