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

Modified Files:
        context_menus.c display.c display_playlists.c file_export.c 
        misc.c misc.h podcast.c podcast.h prefs.c prefs.h 
        prefs_window.c prefs_window.h 
Log Message:
         * podcasts: some code cleanup, added context menus

         * prefs.c: handle filenames somewhat more decently



Index: context_menus.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/context_menus.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- context_menus.c     24 Sep 2005 04:20:24 -0000      1.43
+++ context_menus.c     12 Nov 2005 08:54:31 -0000      1.44
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-09-24 13:17:16 jcs>
+/* Time-stamp: <2005-11-12 17:34:06 jcs>
 |
 |  Copyright (C) 2003 Corey Donohoe <atmos at atmos dot org>
 |  Copyright (C) 2003-2005 Jorg Schuler <jcsjcs at users sourceforge net>
@@ -32,13 +32,14 @@
 #  include <config.h>
 #endif
 
+#include "itdb.h"
 #include "display.h"
 #include "file.h"
 #include "misc.h"
 #include "misc_track.h"
 #include "prefs.h"
 #include "tools.h"
-#include "itdb.h"
+#include "podcast.h"
 
 static guint entry_inst = -1;
 static GList *selected_tracks = NULL;
@@ -158,8 +159,10 @@
  * @data - ignored, should be NULL
  */
 static void 
-delete_entries(GtkMenuItem *mi, DeleteAction deleteaction)
+delete_entries(GtkMenuItem *mi, gpointer data)
 {
+    DeleteAction deleteaction = GPOINTER_TO_INT (data);
+
     if (selected_playlist)
        delete_playlist_head (deleteaction);
     else if(selected_entry)
@@ -289,6 +292,9 @@
                                           * tracks)      */
     static GtkWidget *mi_db_all[CM_NUM];  /* DELETE_ACTION_DATABASE
                                           * (all tracks  */
+    static GtkWidget *mi_podcasts_sep[CM_NUM]; /* Podcasts Separator */
+    static GtkWidget *mi_podcasts_update[CM_NUM]; /* Update Podcasts */
+    static GtkWidget *mi_podcasts_prefs[CM_NUM];  /* Podcasts Prefs */
 
     Playlist *pl;
 
@@ -298,31 +304,32 @@
 #if 0
        hookup_mi (menu[type], _("Edit"), NULL, G_CALLBACK (edit_entries));
 #endif
-       hookup_mi (menu[type], _("Play Now"), "gtk-cdrom",
+       hookup_mi (menu[type], _("Play Now"), GTK_STOCK_CDROM,
                   G_CALLBACK (play_entries_now), NULL);
-       hookup_mi (menu[type], _("Enqueue"), "gtk-cdrom",
+       hookup_mi (menu[type], _("Enqueue"), GTK_STOCK_CDROM,
                   G_CALLBACK (play_entries_enqueue), NULL);
-       mi_exp[type] = hookup_mi (menu[type],
-                                 _("Export Tracks"), "gtk-floppy",
+       mi_exp[type] = hookup_mi (menu[type], 
+                                 _("Export Tracks"), GTK_STOCK_FLOPPY,
                                  G_CALLBACK (export_entries), NULL);
-       hookup_mi (menu[type], _("Create Playlist File"), "gtk-floppy",
+       hookup_mi (menu[type], _("Create Playlist File"), GTK_STOCK_FLOPPY,
                   G_CALLBACK (create_playlist_file), NULL);
-       hookup_mi (menu[type], _("Update"), "gtk-refresh",
+       hookup_mi (menu[type], _("Update"), GTK_STOCK_REFRESH,
                   G_CALLBACK (update_entries), NULL);
-       hookup_mi (menu[type], _("Sync Dirs"), "gtk-refresh",
+       hookup_mi (menu[type], _("Sync Dirs"), GTK_STOCK_REFRESH,
                   G_CALLBACK (sync_dirs_entries), NULL);
        hookup_mi (menu[type], _("Normalize"), NULL,
                   G_CALLBACK (normalize_entries), NULL);
        hookup_mi (menu[type], _("Create new Playlist"),
-                  "gtk-justify-left",
+                  GTK_STOCK_JUSTIFY_LEFT,
                   G_CALLBACK (create_playlist_from_entries), NULL);
        mi_spl[type] = hookup_mi (menu[type], _("Edit Smart Playlist"),
-                                 "gtk-properties",
+                                 GTK_STOCK_PROPERTIES,
                                  G_CALLBACK (edit_spl), NULL);
 
        if (type == CM_ST)
        {
-           hookup_mi (menu[type], _("Alphabetize"), "gtk-sort-ascending",
+           hookup_mi (menu[type], _("Alphabetize"),
+                      GTK_STOCK_SORT_ASCENDING,
                       G_CALLBACK (alphabetize), NULL);
 /* example for sub menus!
            GtkWidget *mi;
@@ -332,11 +339,11 @@
            sub = gtk_menu_new ();
            gtk_widget_show (sub);
            gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), sub);
-           hookup_mi (sub, _("Ascending"), "gtk-sort-ascending",
+           hookup_mi (sub, _("Ascending"), GTK_STOCK_SORT_ASCENDING,
                       G_CALLBACK (alphabetize_ascending), NULL);
-           hookup_mi (sub, _("Descending"), "gtk-sort-descending",
+           hookup_mi (sub, _("Descending"), GTK_STOCK_SORT_DESCENDING,
                       G_CALLBACK (alphabetize_descending), NULL);
-           hookup_mi (sub, _("Reset"), "gtk-undo",
+           hookup_mi (sub, _("Reset"), GTK_STOCK_UNDO,
                       G_CALLBACK (reset_alphabetize), NULL);
 */
        }
@@ -345,58 +352,74 @@
            mi_sep[type] = add_separator (menu[type]);
            mi_ipod[type] = hookup_mi (menu[type],
                                       _("Delete From iPod"),
-                                      "gtk-delete",
+                                      GTK_STOCK_DELETE,
                                       G_CALLBACK (delete_entries),
-                                      (gpointer)DELETE_ACTION_IPOD);
+                                      GINT_TO_POINTER (DELETE_ACTION_IPOD));
            mi_local[type] = hookup_mi (menu[type],
                                        _("Delete From Harddisk"),
-                                       "gtk-delete",
+                                       GTK_STOCK_DELETE,
                                        G_CALLBACK (delete_entries),
-                                       (gpointer)DELETE_ACTION_LOCAL);
+                                       GINT_TO_POINTER (DELETE_ACTION_LOCAL));
            mi_db[type] = hookup_mi (menu[type],
                                     _("Delete From Database"),
-                                    "gtk-delete",
+                                    GTK_STOCK_DELETE,
                                     G_CALLBACK (delete_entries),
-                                    (gpointer)DELETE_ACTION_DATABASE);
+                                    GINT_TO_POINTER (DELETE_ACTION_DATABASE));
            mi_pl[type] = hookup_mi (menu[type],
                                     _("Delete From Playlist"),
-                                    "gtk-delete",
+                                    GTK_STOCK_DELETE,
                                     G_CALLBACK (delete_entries),
-                                    (gpointer)DELETE_ACTION_PLAYLIST);
+                                    GINT_TO_POINTER (DELETE_ACTION_PLAYLIST));
        }
        if (type == CM_PM)
        {
            mi_sep[type] = add_separator (menu[type]);
            mi_ipod[type] = hookup_mi (menu[type],
                                       _("Delete Including Tracks"),
-                                      "gtk-delete",
+                                      GTK_STOCK_DELETE,
                                       G_CALLBACK (delete_entries),
-                                      (gpointer)DELETE_ACTION_IPOD);
+                                      GINT_TO_POINTER (DELETE_ACTION_IPOD));
            mi_local[type] = hookup_mi (menu[type],
                                        _("Delete Including Tracks (Harddisk)"),
-                                       "gtk-delete",
+                                       GTK_STOCK_DELETE,
                                        G_CALLBACK (delete_entries),
-                                       (gpointer)DELETE_ACTION_LOCAL);
+                                       GINT_TO_POINTER (DELETE_ACTION_LOCAL));
            mi_db[type] = hookup_mi (menu[type],
                                     _("Delete Including Tracks (Database)"),
-                                    "gtk-delete",
+                                    GTK_STOCK_DELETE,
                                     G_CALLBACK (delete_entries),
-                                    (gpointer)DELETE_ACTION_DATABASE);
+                                    GINT_TO_POINTER (DELETE_ACTION_DATABASE));
            mi_pl[type] = hookup_mi (menu[type],
                                     _("Delete But Keep Tracks"),
-                                    "gtk-delete",
+                                    GTK_STOCK_DELETE,
                                     G_CALLBACK (delete_entries),
-                                    (gpointer)DELETE_ACTION_PLAYLIST);
+                                    GINT_TO_POINTER (DELETE_ACTION_PLAYLIST));
            mi_ipod_all[type] = hookup_mi (menu[type],
                                           _("Remove All Tracks from iPod"),
-                                          "gtk-delete",
+                                          GTK_STOCK_DELETE,
                                           G_CALLBACK (delete_entries),
-                                          (gpointer)DELETE_ACTION_IPOD);
+                                          GINT_TO_POINTER 
(DELETE_ACTION_IPOD));
            mi_db_all[type] = hookup_mi (menu[type],
                                         _("Remove All Tracks from Database"),
-                                        "gtk-delete",
+                                        GTK_STOCK_DELETE,
                                         G_CALLBACK (delete_entries),
-                                        (gpointer)DELETE_ACTION_DATABASE);
+                                        GINT_TO_POINTER 
(DELETE_ACTION_DATABASE));
+
+           mi_podcasts_sep[type] = add_separator (menu[type]);
+
+           mi_podcasts_update[type] =
+               hookup_mi (menu[type],
+                          _("Update Podcasts"),
+                          GTK_STOCK_REFRESH,
+                          G_CALLBACK (podcast_fetch),
+                          GINT_TO_POINTER (DELETE_ACTION_DATABASE));
+
+           mi_podcasts_prefs[type] =
+               hookup_mi (menu[type],
+                          _("Podcasts Preferences"),
+                          GTK_STOCK_PREFERENCES,
+                          G_CALLBACK (prefs_window_podcasts),
+                          GINT_TO_POINTER (DELETE_ACTION_DATABASE));
        }
     }
     /* Make sure, only available options are displayed */
@@ -459,6 +482,18 @@
                    gtk_widget_hide (mi_db_all [type]);
                }
            }
+           if (itdb->usertype & GP_ITDB_TYPE_PODCASTS)
+           {
+               gtk_widget_show (mi_podcasts_sep[type]);
+               gtk_widget_show (mi_podcasts_update[type]);
+               gtk_widget_show (mi_podcasts_prefs[type]);
+           }
+           else
+           {
+               gtk_widget_hide (mi_podcasts_sep[type]);
+               gtk_widget_hide (mi_podcasts_update[type]);
+               gtk_widget_hide (mi_podcasts_prefs[type]);
+           }
            break;
        case CM_ST:
        case CM_TM:

Index: display.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/display.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- display.c   18 Oct 2005 14:29:55 -0000      1.121
+++ display.c   12 Nov 2005 08:54:31 -0000      1.122
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-10-03 22:20:08 jcs>
+/* Time-stamp: <2005-11-12 17:41:37 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -769,12 +769,10 @@
 */
 
 
-
-void
-on_podcast_button_clicked              (GtkButton       *button,
-                                        gpointer         user_data)
+void on_update_podcasts_activate (GtkButton       *button,
+                                 gpointer         user_data)
 {
-    podcast_fetch();
+    podcast_fetch ();
 }
 
 
@@ -799,7 +797,7 @@
 on_edit_preferences1_activate          (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
 {
-    if(!widgets_blocked)  prefs_window_create();
+    if(!widgets_blocked)  prefs_window_create (-1);
 }
 
 

Index: display_playlists.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/display_playlists.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- display_playlists.c 18 Oct 2005 14:29:55 -0000      1.65
+++ display_playlists.c 12 Nov 2005 08:54:31 -0000      1.66
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-09-24 15:30:36 jcs>
+/* Time-stamp: <2005-11-12 17:31:33 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -1792,12 +1792,12 @@
        if (playlist->is_spl)
        {
            g_object_set (G_OBJECT (renderer),
-                         "stock-id", "gtk-properties", NULL);
+                         "stock-id", GTK_STOCK_PROPERTIES, NULL);
        }
        else if (!itdb_playlist_is_mpl (playlist))
        {
            g_object_set (G_OBJECT (renderer),
-                         "stock-id", "gtk-justify-left", NULL);
+                         "stock-id", GTK_STOCK_JUSTIFY_LEFT, NULL);
        }
        else
        {

Index: file_export.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/file_export.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- file_export.c       18 Oct 2005 14:29:55 -0000      1.52
+++ file_export.c       12 Nov 2005 08:54:31 -0000      1.53
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-09-12 18:57:24 jcs>
+/* Time-stamp: <2005-11-12 01:31:58 jcs>
 |
 |  Copyright (C) 2002 Corey Donohoe <atmos at atmos.org>
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
@@ -91,29 +91,6 @@
 
 
 /**
- * Recursively make directories in the given filename.
- * @return FALSE is this is not possible.
- */
-gboolean
-mkdirhier(char* filename)
-{
-       char* p = filename;
-       if (*p == G_DIR_SEPARATOR) p++;
-       while ((p = index(p, G_DIR_SEPARATOR)) != NULL) {
-               *p = '\0';
-               if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
-                       if (mkdir(filename, 0755) == -1) {
-                               gtkpod_warning (_("Error creating %s: %s\n"), 
filename, g_strerror(errno));
-                               return FALSE;
-                       }
-               }
-               *p = G_DIR_SEPARATOR;
-               p++;
-       }
-       return TRUE;
-}
-
-/**
  * copy_file_fd_sync - given two open file descriptors, read from one
  *     and write the data to the other, fsync() before returning.
  * @from - the file descriptor we're reading from
@@ -324,7 +301,7 @@
            prefs_get_string_value (EXPORT_FILES_PATH, &dest_dir);
            filename = g_build_filename (dest_dir, dest_file, NULL);
 
-           if (mkdirhier(filename))
+           if (mkdirhierfile(filename))
            {
                if(copy_file(from_file, filename))
                {

Index: misc.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc.c,v
retrieving revision 1.185
retrieving revision 1.186
diff -u -d -r1.185 -r1.186
--- misc.c      20 Sep 2005 09:50:13 -0000      1.185
+++ misc.c      12 Nov 2005 08:54:31 -0000      1.186
@@ -1,5 +1,5 @@
 /* -*- coding: utf-8; -*-
-|  Time-stamp: <2005-09-20 18:44:43 jcs>
+|  Time-stamp: <2005-11-12 15:54:12 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -1302,3 +1302,69 @@
     g_free(which_exec);
     return(result);
 }
+
+/**
+ * Recursively make directories.
+ * @return FALSE is this is not possible.
+ */
+gboolean mkdirhier(const gchar *dirname)
+{
+    gchar *dn, *p;
+
+    g_return_val_if_fail (dirname && *dirname, FALSE);
+
+    if (strncmp ("~/", dirname, 2) == 0)
+        dn = g_build_filename (g_get_home_dir(), dirname+2, NULL);
+    else dn = g_strdup (dirname);
+
+    p = dn;
+
+    do
+    {
+       ++p;
+       p = index (p, G_DIR_SEPARATOR);
+
+       if (p)   *p = '\0';
+
+       if (!g_file_test(dn, G_FILE_TEST_EXISTS))
+       {
+           if (mkdir(dn, 0755) == -1)
+           {
+               gtkpod_warning (_("Error creating %s: %s\n"),
+                               dn, g_strerror(errno));
+               g_free (dn);
+               return FALSE;
+           }
+       }
+       if (p)   *p = G_DIR_SEPARATOR;
+    } while (p);
+
+    g_free (dn);
+    return TRUE;
+}
+
+/**
+ * Recursively make directories in the given filename.
+ * @return FALSE is this is not possible.
+ */
+gboolean mkdirhierfile(const gchar *filename)
+{
+    gboolean result;
+    gchar *dirname = g_path_get_dirname (filename);
+    result = mkdirhier (filename);
+    g_free (dirname);
+    return result;
+}
+
+
+/**
+ * Convert "~/" to "/home/.../"
+ *
+ * g_free() return value when no longer needed.
+ */
+gchar *convert_filename (const gchar *filename)
+{
+    if (strncmp ("~/", filename, 2) == 0)
+        return g_build_filename (g_get_home_dir(), filename+2, NULL);
+    else return g_strdup (filename);
+}

Index: misc.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/misc.h,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -d -r1.102 -r1.103
--- misc.h      20 Sep 2005 09:50:13 -0000      1.102
+++ misc.h      12 Nov 2005 08:54:31 -0000      1.103
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-09-20 18:42:26 jcs>
+/* Time-stamp: <2005-11-12 15:53:06 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -163,6 +163,10 @@
 
 void check_db (iTunesDB *db);
 
+gboolean mkdirhier(const gchar *dirname);
+gboolean mkdirhierfile(const gchar *filename);
+gchar *convert_filename (const gchar *filename);
+
 guint32 replaygain_to_soundcheck (gdouble gain);
 gdouble soundcheck_to_replaygain (guint32 soundcheck);
 

Index: podcast.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/podcast.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- podcast.c   16 Oct 2005 23:36:03 -0000      1.5
+++ podcast.c   12 Nov 2005 08:54:31 -0000      1.6
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-07-01 23:16:54 asd>
+/* Time-stamp: <2005-11-12 16:08:34 jcs>
 |
 |  Copyright (C) 2002-2005 Alexander Dutton <alexdutton at f2s dot com>
 |  Part of the gtkpod project.
@@ -53,16 +53,53 @@
 #include <curl/curl.h>
 #include <curl/multi.h>
 #include <curl/types.h>
-GList *podcasts = NULL;
-GList *podcast_files = NULL;
-GList *abort_urls = NULL;
-GList *abort_urls_to_add = NULL;
 
-GladeXML *podcast_window_xml;
+struct podcast
+{
+    gchar *name;                 /* of the podcast */
+    gchar *url;                  /* of XML file */
+};
+
+struct podcast_file
+{
+    gchar *title;                 /* of each individual audio file */
+    gchar *url;                  /* where the audio file is to be found */
+    gchar *desc;                 /* description of audio file (from XML) */
+    gchar *artist;               /* itunes:author in actuality */
+    gchar pubdate[14];           /* "YYYYMMDDHHMMSS" in UTC/GMT*/
+    gchar fetchdate[14];         /* same as above */
+    glong size;                  /* filesize */
+    gchar *local;                /* where the file is kept on the local system 
*/
+    gboolean fetched;            /* whether or not this podcast has been 
fetched */
+    gboolean tofetch;            /* whether we should fetch this podcast */
+};
+
+enum
+{
+  PCL_TITLE = 0,
+  PCL_URL,
+  PCL_SIZE,
+  PCL_PROGRESS,
+  PCL_NUM_COLS
+};
+
+enum
+{
+  ABORT_SELECTED = 0,
+  ABORT_CURRENT,
+  ABORT_ALL
+};
+
+static GList *podcasts = NULL;
+static GList *podcast_files = NULL;
+static GList *abort_urls = NULL;
+static GList *abort_urls_to_add = NULL;
+
+static GladeXML *podcast_window_xml;
 static GtkWidget *podcast_window = NULL;
 static GtkTreeView *podcast_list = NULL;
 
-gchar *url_being_fetched = NULL;
+static gchar *url_being_fetched = NULL;
 
 static long transfer_total, transfer_done;
 static gint retrieve_url_to_path (gchar *url, gchar *path);
@@ -70,21 +107,26 @@
 static void podcast_log (gchar *msg);
 static void create_podcast_list ();
 static gchar *choose_filename(gchar *url);
-static iTunesDB *get_itdb_local();
 
 static void podcast_window_create(void);
 
 static void abort_fetch_response(GtkDialog *dialog, gint arg1, gpointer 
user_data);
 static void abort_fetch (gint what);
 
+int update_progress(gpointer *data,
+                    double t, /* dltotal */
+                    double d, /* dlnow */
+                    double ultotal,
+                    double ulnow);
+
 void podcast_add (gchar *name, gchar *url)
 {
-    // assign some memory to hold data for new podcast
+    /* assign some memory to hold data for new podcast */
     struct podcast *podcast = malloc(sizeof(struct podcast));
     podcast->name = g_strdup(name);
     podcast->url = g_strdup(url);
-    //g_free(name);
-    //g_free(url);
+    /* g_free(name); */
+    /* g_free(url); */
     podcasts = g_list_insert(podcasts, podcast, -1);
 }
 
@@ -111,6 +153,7 @@
 {
     int i = 0;
     struct podcast *podcast = NULL;
+
     while(i < g_list_length(podcasts))
     {
         podcast = g_list_nth_data(podcasts, i);
@@ -130,7 +173,6 @@
 void podcast_write_from_store (GtkListStore *store)
 {
     gchar *cfgdir = NULL;
-    gchar filename[PATH_MAX+1];
     FILE *fp = NULL;
     gboolean have_prefs = FALSE;
 
@@ -138,8 +180,7 @@
 
     if (cfgdir)
     {
-        snprintf(filename, PATH_MAX, "%s/podcast.list", cfgdir);
-        filename[PATH_MAX] = 0;
+       gchar *filename = g_build_filename (cfgdir, "podcast.list", NULL);
 
         if((fp = fopen(filename, "w")))
         {
@@ -176,6 +217,8 @@
         {
             gtkpod_warning(_("Unable to open podcast file '%s' for 
writing\n"), filename);
         }
+       g_free (filename);
+       g_free (cfgdir);
     }
 }
 
@@ -202,7 +245,6 @@
 void podcast_read_from_file ()
 {
     gchar *cfgdir = NULL, *name = NULL, *url = NULL;
-    gchar filename[PATH_MAX+1];
     gchar buf[PATH_MAX];
     gchar *line, *arg, *bufp;
     gint len;
@@ -213,8 +255,7 @@
 
     if (cfgdir)
     {
-        snprintf(filename, PATH_MAX, "%s/podcast.list", cfgdir);
-        filename[PATH_MAX] = 0;
+       gchar *filename = g_build_filename (cfgdir, "podcast.list", NULL);
 
         if((fp = fopen(filename, "r")))
         {
@@ -258,6 +299,8 @@
             }
             fclose(fp);
         }
+       g_free (filename);
+       g_free (cfgdir);
     }
 }
 
@@ -267,15 +310,15 @@
                        glong size, gchar *local,
                        gboolean fetched, gboolean tofetch)
 {
-    // assign some memory to hold data for new podcast
+    /* assign some memory to hold data for new podcast */
     struct podcast_file *podcast_file = malloc(sizeof(struct podcast_file));
     podcast_file->title = g_strdup(title);
     podcast_file->url = g_strdup(url);
     podcast_file->desc = g_strdup(desc);
     podcast_file->artist = g_strdup(artist);
     podcast_file->local = g_strdup(local);
-//    podcast_file->pubdate = pubdate;
-//    podcast_file->fetchdate = fetchdate;
+/*    podcast_file->pubdate = pubdate; */
+/*    podcast_file->fetchdate = fetchdate; */
     podcast_file->size = size;
     podcast_file->fetched = fetched;
     podcast_file->tofetch = tofetch;
@@ -306,15 +349,20 @@
 gint podcast_file_read_from_file()
 {
     gchar *cfgdir = prefs_get_cfgdir ();
+
     if (cfgdir)
     {
-        gchar *filename = g_strdup_printf("%s/podcast.xml", cfgdir);
+        gchar *filename = g_build_filename(cfgdir, "podcast.xml", NULL);
+
         parse_file_for_podcast_files(filename);
+
         g_free(filename);
         g_free(cfgdir);
         return 0;
-    } else {
-        g_free(cfgdir);
+
+    }
+    else
+    {
         return 1;
     }
 }
@@ -356,29 +404,34 @@
         fprintf(fp, "</channel>\n</rss>\n");
 
         fclose(fp);
+
+       g_free (cfgdir);
+
         return 0;
-    } else {
-        return 1;
     }
-    
+    return 1;
 }
 
 void podcast_fetch ()
 {
-    //pthread_create(&podcast_fetch_tid, NULL, &podcast_fetch_thread, NULL);
+    /*pthread_create(&podcast_fetch_tid, NULL, &podcast_fetch_thread,
+      NULL); */
     podcast_fetch_thread();
-    //g_thread_create(podcast_fetch_thread, NULL, FALSE, NULL);
+    /* g_thread_create(podcast_fetch_thread, NULL, FALSE, NULL);*/
 }
 
 void podcast_fetch_thread(gpointer data)
 {
-    podcast_fetch_in_progress = TRUE;
-
     struct podcast *podcast;
     struct podcast_file *podcast_file;
     guint i = 0;
     gint found = 0;
-    gchar *status_msg = NULL, *cfgdir = NULL, *filename = NULL;
+    gchar *status_msg = NULL, *cfgdir = NULL;
+
+    podcast_fetch_in_progress = TRUE;
+
+    iTunesDB *itdb = gp_itdb_get_podcast ();
+
 
     gdk_threads_enter();
     podcast_window_create();
@@ -415,7 +468,10 @@
 
     if (cfgdir)
     {
-        filename = g_strdup_printf("%s/tmp.xml", cfgdir);
+       GtkListStore *model;
+       GtkTreeIter iter;
+       GtkTreePath *path;
+       gchar *filename = g_strdup_printf("%s/tmp.xml", cfgdir);
 
         while(i < g_list_length(podcasts))
         {
@@ -445,9 +501,8 @@
 
         gdk_threads_enter();
 
-        GtkListStore *model = 
GTK_LIST_STORE(gtk_tree_view_get_model(podcast_list));
-        GtkTreeIter iter;
-        GtkTreePath *path;
+       model = GTK_LIST_STORE(gtk_tree_view_get_model(podcast_list));
+
         gtk_list_store_clear (model);
 
         transfer_total = 0;
@@ -473,9 +528,6 @@
         gdk_threads_leave();
         while (gtk_events_pending())  gtk_main_iteration();
 
-        iTunesDB *itdb = get_itdb_local ();
-        Playlist *pl = itdb_playlist_by_name(itdb, "Podcasts");
-
         i = 0;
         while(i < g_list_length(podcast_files))
         {
@@ -486,7 +538,7 @@
                 gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path);
                 gtk_tree_path_free(path);
 
-                //gtk_list_store_set(model, &iter, PCL_PROGRESS, "Fetching");
+                /* gtk_list_store_set(model, &iter, PCL_PROGRESS, 
"Fetching");*/
 
                 filename = choose_filename(podcast_file->url);
                 status_msg = g_strdup_printf("Starting download of '%s' to 
'%s' (%ld bytes)", podcast_file->url, filename, podcast_file->size);
@@ -494,13 +546,13 @@
                 g_free(status_msg);
                 if (retrieve_url_to_path(podcast_file->url, filename))
                 {
-        //            gtk_list_store_set(model, &iter, PCL_PROGRESS, "Failed");
+                   /*           gtk_list_store_set(model, &iter, PCL_PROGRESS, 
"Failed");*/
                     status_msg = g_strdup_printf("Could not fetch '%s'", 
podcast_file->title);
                     podcast_log(_(status_msg));
                     podcast_set_status(_(status_msg));
                     g_free(status_msg);
                 } else {
-        //            gtk_list_store_set(model, &iter, PCL_PROGRESS, "Done");
+                   /*            gtk_list_store_set(model, &iter, 
PCL_PROGRESS, "Done");*/
                     transfer_done += podcast_file->size;
                     podcast_file->tofetch = FALSE;
                     podcast_file->fetched = TRUE;
@@ -511,13 +563,13 @@
                     podcast_set_status(_(status_msg));
                     g_free(status_msg);
 
-                    add_track_by_filename (itdb, filename, pl, FALSE, NULL, 
NULL);
+                    add_track_by_filename (itdb, filename, NULL, FALSE, NULL, 
NULL);
                     
                 }
                 g_free(filename);
             }
-    //        gtk_tree_model_iter_next (GTK_TREE_MODEL(model), &iter);
-    podcast_file_write_to_file();
+           /*        gtk_tree_model_iter_next (GTK_TREE_MODEL(model), &iter);*/
+           podcast_file_write_to_file();
             ++i;
         }
 
@@ -530,57 +582,83 @@
 
 static gchar *choose_filename(gchar *url)
 {
-    gchar *working = g_strdup_printf("%s/%s", prefs_get_pc_dir(), 
g_strrstr(url, "/")+1);
+    gchar *pc_dir;
+    gchar *working;
+
+    g_return_val_if_fail (g_strrstr (url, G_DIR_SEPARATOR_S), NULL);
+
+    pc_dir = prefs_get_pc_dir();
+
+    working = g_build_filename (pc_dir, g_strrstr(url, "/")+1,
+                               NULL);
+
+    /* Make sure pc_dir exists */
+    if (!g_file_test (pc_dir, G_FILE_TEST_IS_DIR))
+    {
+       if (!mkdirhier (pc_dir))
+       {
+           gtkpod_warning (_("Could not create podcast download directory 
'%s'\n"), pc_dir);
+       }
+    }
+    g_free (pc_dir);
     return working;
 }
 
 static gint retrieve_url_to_path (gchar *url, gchar *path)
 {
-gdk_threads_enter();
-podcast_set_cur_file_name(url);
-gdk_threads_leave();
-int ret = 0;
-
-CURL *curl = curl_easy_init();
-CURLM *curlm = curl_multi_init();
+    int ret = 0;
 
-url_being_fetched = g_strdup(url);
+    CURL *curl;
+    CURLM *curlm;
 
-if (curl)
-{
-  FILE *fp = fopen(path, "w");
+    gdk_threads_enter();
+    podcast_set_cur_file_name(url);
+    gdk_threads_leave();
 
-  if (fp != NULL) {
-    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, update_progress);
-    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
-    curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
-    curl_easy_setopt(curl, CURLOPT_URL, url);
-    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-    curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
-    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15);
+    curl = curl_easy_init();
+    curlm = curl_multi_init();
 
-    curl_multi_add_handle(curlm, curl);
+    url_being_fetched = g_strdup(url);
 
-    int running_handles = 1;
-    while (running_handles > 0)
+    if (curl)
     {
-      curl_multi_perform(curlm, &running_handles);
-      while (gtk_events_pending())  gtk_main_iteration();
-    }
+       FILE *fp = fopen(path, "w");
 
-    fclose(fp);
-  } else {
-    gtkpod_warning (_("Could not open \"%s\" for writing podcast 
download.\n"), path);
-    ret = -1;
-  }
+       if (fp != NULL)
+       {
+           int running_handles = 1;
 
-  g_free(url_being_fetched);
-  url_being_fetched = NULL;
+           curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, update_progress);
+           curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE);
+           curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
+           curl_easy_setopt(curl, CURLOPT_URL, url);
+           curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
+           curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
+           curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15);
 
-  curl_easy_cleanup(curl);
-  curl_global_cleanup();
-}
-return ret;
+           curl_multi_add_handle(curlm, curl);
+
+           while (running_handles > 0)
+           {
+               curl_multi_perform(curlm, &running_handles);
+               while (gtk_events_pending())  gtk_main_iteration();
+           }
+
+           fclose(fp);
+       }
+       else
+       {
+           gtkpod_warning (_("Could not open '%s' for writing podcast 
download.\n"), path);
+           ret = -1;
+       }
+
+       g_free(url_being_fetched);
+       url_being_fetched = NULL;
+
+       curl_easy_cleanup(curl);
+       curl_global_cleanup();
+    }
+    return ret;
 }
 
 int update_progress(gpointer *data,
@@ -589,6 +667,8 @@
                     double ultotal,
                     double ulnow)
 {
+    gchar *tmp;
+
 /*  printf("%d / %d (%g %%)\n", d, t, d*100.0/t);*/
 
 /*if (t == 0)
@@ -597,18 +677,18 @@
     while (gtk_events_pending())  gtk_main_iteration();
 }*/
 
-if (t == 0 || transfer_total == 0) return 0;
-if (d/t > 1 || (d+transfer_done)/transfer_total > 1) return 0;
-  gdk_threads_enter();
-  gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (glade_xml_get_widget 
(podcast_window_xml, "file_progressbar")), d/t);
-  gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (glade_xml_get_widget 
(podcast_window_xml, "total_progressbar")), (d+transfer_done)/transfer_total);
-  gchar *tmp = g_strdup_printf("%.2fMb of %.2fMb (%.0f%%), 12:32 remaining", 
(double) (d+transfer_done)/1024/1024, (double) transfer_total/1024/1024, 
100*(d+transfer_done)/transfer_total);
-  gtk_progress_bar_set_text(GTK_PROGRESS_BAR (glade_xml_get_widget 
(podcast_window_xml, "total_progressbar")), tmp);
-  g_free(tmp);
+    if (t == 0 || transfer_total == 0) return 0;
+    if (d/t > 1 || (d+transfer_done)/transfer_total > 1) return 0;
+    gdk_threads_enter();
+    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (glade_xml_get_widget 
(podcast_window_xml, "file_progressbar")), d/t);
+    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (glade_xml_get_widget 
(podcast_window_xml, "total_progressbar")), (d+transfer_done)/transfer_total);
+    tmp = g_strdup_printf("%.2fMb of %.2fMb (%.0f%%), 12:32 remaining", 
(double) (d+transfer_done)/1024/1024, (double) transfer_total/1024/1024, 
100*(d+transfer_done)/transfer_total);
+    gtk_progress_bar_set_text(GTK_PROGRESS_BAR (glade_xml_get_widget 
(podcast_window_xml, "total_progressbar")), tmp);
+    g_free(tmp);
 
-  gdk_threads_leave();
+    gdk_threads_leave();
     while (gtk_events_pending())  gtk_main_iteration();
-  return 0;
+    return 0;
 }
 
 static gint parse_file_for_podcast_files(gchar *file)
@@ -657,7 +737,7 @@
                 tag = strdup(buf);                          /* retrieve the 
tag name from the buffer */
                 i = 0;
 
-                while (cur != 0x3E)                           // make our way 
to the end of the tag
+                while (cur != 0x3E)                         /* make our way to 
the end of the tag */
                 {
                     cur = fgetc(fp);
                     buf[i++] = cur;
@@ -715,6 +795,10 @@
                 info = podcast_get_tag_attr(info, "length=");
                 size = atoi(info);
             }
+           else
+           {
+               size = 0;
+           }
 
             if (g_ascii_strcasecmp (tag, "/item") == 0)
             {
@@ -737,15 +821,15 @@
                 }
             }
 
-//            g_free(value);
-//            g_free(tag);
-//            g_free(info);
+/*            g_free(value);
+             g_free(tag);
+             g_free(info);*/
         }
         fclose(fp);
     } else {
-    //    gtkpod_warning(_("Failed to open '%s' to read podcast list."), file);
-    //        gchar *status_msg = g_strdup_printf("Error number is: %d", 
errno);
-    //        gtkpod_statusbar_message(_(status_msg));
+       /*    gtkpod_warning(_("Failed to open '%s' to read podcast list."), 
file);
+            gchar *status_msg = g_strdup_printf("Error number is: %d", errno);
+            gtkpod_statusbar_message(_(status_msg));*/
 
     }
 
@@ -767,7 +851,6 @@
         ++ret2;
         *(ret2 + strlen(ret2) - 1) = 0x00;
     }
-    //free(ret);
     return g_strdup(ret2);
 }
 
@@ -776,8 +859,7 @@
     if (prefs_get_pc_log())
     {
         FILE *fp = NULL;
-        gchar *filename = g_strdup(prefs_get_pc_log_file());
-
+        gchar *filename = prefs_get_pc_log_file();
         time_t rawtime;
         struct tm * timeinfo;
 
@@ -847,20 +929,19 @@
 
 static void abort_fetch (gint what)
 {
+    GtkWidget *dialog, *label;
     struct podcast_file *podcast_file = NULL;
+
     switch (what)
     {
         case ABORT_SELECTED :
-            break;
-            GtkTreeModel *model;
-            GtkTreeIter   iter;
-            gchar *url;
+/*            GtkTreeModel *model;
+             GtkTreeIter   iter;
+             gchar *url;
 
-            model = gtk_tree_view_get_model(podcast_list);
-        //    gtk_tree_model_get_iter(model, &iter);
-        //    gtk_tree_model_get (model, &iter,
-        //                        PCL_TITLE, &url,
-        //                        -1);
+             model = gtk_tree_view_get_model(podcast_list);
+             gtk_tree_model_get_iter(model, &iter);
+             gtk_tree_model_get (model, &iter, PCL_TITLE, &url, -1);*/
             break;
 
         case ABORT_CURRENT :
@@ -880,8 +961,6 @@
 
     if (g_list_length(abort_urls_to_add) == 0) return;
 
-    GtkWidget *dialog, *label;
-
     dialog = gtk_dialog_new_with_buttons ("Aborting podcast fetching",
                                           GTK_WINDOW(podcast_window),
                                           GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -900,6 +979,7 @@
     gtk_widget_show_all(dialog);
 }
 
+
 static void abort_fetch_response           (GtkDialog *dialog,
                                             gint arg1,
                                             gpointer user_data)
@@ -945,9 +1025,10 @@
 {
     GtkCellRenderer     *renderer;
     GtkTreeModel        *model;
+    GtkWidget *podcast_list_window;
 
     podcast_list = GTK_TREE_VIEW(gtk_tree_view_new ());
-//    gtk_widget_set_size_request(GTK_WIDGET (podcast_list), 270, 105);
+/*    gtk_widget_set_size_request(GTK_WIDGET (podcast_list), 270, 105);*/
 
     renderer = gtk_cell_renderer_text_new ();
     gtk_tree_view_insert_column_with_attributes (podcast_list,
@@ -990,7 +1071,7 @@
 
     g_object_unref (model);
 
-    GtkWidget *podcast_list_window = glade_xml_get_widget (podcast_window_xml, 
"podcast_list_window");
+    podcast_list_window = glade_xml_get_widget (podcast_window_xml, 
"podcast_list_window");
 
     gtk_container_add (GTK_CONTAINER (podcast_list_window), 
GTK_WIDGET(podcast_list));
 if(podcast_list_window)
@@ -1018,24 +1099,3 @@
         g_free(working);
     }
 }
-
-/* Get the local itdb */
-static iTunesDB *get_itdb_local (void)
-{
-    struct itdbs_head *itdbs_head;
-    GList *gl;
-
-    g_return_val_if_fail (gtkpod_window, NULL);
-    itdbs_head = g_object_get_data (G_OBJECT (gtkpod_window),
-                                    "itdbs_head");
-    if (!itdbs_head) return NULL;
-    for (gl=itdbs_head->itdbs; gl; gl=gl->next)
-    {
-        iTunesDB *itdb = gl->data;
-        g_return_val_if_fail (itdb, NULL);
-        if (itdb->usertype & GP_ITDB_TYPE_LOCAL)
-            return itdb;
-    }
-    return NULL;
-}
-

Index: podcast.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/podcast.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- podcast.h   18 Oct 2005 14:29:55 -0000      1.4
+++ podcast.h   12 Nov 2005 08:54:31 -0000      1.5
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-07-01 23:16:54 asd>
+/* Time-stamp: <2005-11-12 15:31:44 jcs>
 |
 |  Copyright (C) 2002-2005 Alexander Dutton <alexdutton at f2s dot com>
 |  Part of the gtkpod project.
@@ -30,26 +30,6 @@
 #ifndef __PODCAST_H__
 #define __PODCAST_H__
 
-struct podcast
-{
-    gchar *name;                 /* of the podcast */
-    gchar *url;                  /* of XML file */
-};
-
-struct podcast_file
-{
-    gchar *title;                 /* of each individual audio file */
-    gchar *url;                  /* where the audio file is to be found */
-    gchar *desc;                 /* description of audio file (from XML) */
-    gchar *artist;               /* itunes:author in actuality */
-    gchar pubdate[14];           /* "YYYYMMDDHHMMSS" in UTC/GMT*/
-    gchar fetchdate[14];         /* same as above */
-    glong size;                  /* filesize */
-    gchar *local;                /* where the file is kept on the local system 
*/
-    gboolean fetched;            /* whether or not this podcast has been 
fetched */
-    gboolean tofetch;            /* whether we should fetch this podcast */
-};
-
 enum
 {
   PC_SUBS_NAME = 0,
@@ -57,21 +37,6 @@
   PC_SUBS_NUM_COLS
 };
 
-enum
-{
-  PCL_TITLE = 0,
-  PCL_URL,
-  PCL_SIZE,
-  PCL_PROGRESS,
-  PCL_NUM_COLS
-};
-
-enum
-{
-  ABORT_SELECTED = 0,
-  ABORT_CURRENT,
-  ABORT_ALL
-};
 
 gboolean podcast_fetch_in_progress;
 
@@ -97,10 +62,4 @@
 void podcast_set_status(gchar *status);
 void podcast_set_cur_file_name(gchar *text);
 
-int update_progress(gpointer *data,
-                    double t, /* dltotal */
-                    double d, /* dlnow */
-                    double ultotal,
-                    double ulnow);
-
 #endif

Index: prefs.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/prefs.c,v
retrieving revision 1.150
retrieving revision 1.151
diff -u -d -r1.150 -r1.151
--- prefs.c     29 Sep 2005 00:28:08 -0000      1.150
+++ prefs.c     12 Nov 2005 08:54:31 -0000      1.151
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-07-16 16:11:00 jcs>
+/* Time-stamp: <2005-11-12 17:49:22 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -141,23 +141,23 @@
 {
     struct cfg *mycfg = NULL;
     gchar curdir[PATH_MAX], *str;
+    gchar *cfgdir;
     gint i;
 
+    cfgdir = prefs_get_cfgdir ();
+
     mycfg = g_malloc0 (sizeof (struct cfg));
     if(getcwd(curdir, PATH_MAX))
     {
-       mycfg->last_dir.browse = g_strdup_printf ("%s/", curdir);
+       mycfg->last_dir.browse = g_strdup (curdir);
     }
     else
     {
-       mycfg->last_dir.browse = g_strdup ("~/");
+       mycfg->last_dir.browse = convert_filename ("~/");
     }
     if((str = getenv("IPOD_MOUNTPOINT")))
     {
-       if (strncmp ("~/", str, 2) == 0)
-           mycfg->ipod_mount = g_build_filename (g_get_home_dir(),
-                                                 str+2, NULL);
-       else mycfg->ipod_mount = g_strdup(str);
+       mycfg->ipod_mount = convert_filename (str);
     }
     else
     {
@@ -293,13 +293,13 @@
     mycfg->mserv_report_probs = TRUE;
     mycfg->mserv_username = g_strdup ("");
 
-    mycfg->pc_dir = g_strdup_printf ("%s/podcasts", prefs_get_cfgdir());
+    mycfg->pc_dir = g_build_filename (cfgdir, "podcasts", NULL);
     mycfg->pc_del_age = FALSE;
     mycfg->pc_del_age_val = 1;
     mycfg->pc_del_copied = FALSE;
     mycfg->pc_auto_fetch = FALSE;
     mycfg->pc_log = TRUE;
-    mycfg->pc_log_file = g_strdup ("~/.gtkpod/podcast.log");
+    mycfg->pc_log_file = g_build_filename (cfgdir, "podcast.log", NULL);
     mycfg->pc_auto_sync = FALSE;
     mycfg->pc_ipod_del_age = FALSE;
     mycfg->pc_ipod_del_age_val = 1;
@@ -307,6 +307,8 @@
     mycfg->pc_ipod_inc_date = FALSE;
     mycfg->pc_change_genre = FALSE;
 
+    g_free (cfgdir);
+
     return(mycfg);
 }
 
@@ -994,33 +996,32 @@
 read_prefs_defaults(void)
 {
   gchar *cfgdir = NULL;
-  gchar filename[PATH_MAX+1];
+  gchar *filename;
   FILE *fp = NULL;
   gboolean have_prefs = FALSE;
 
   cfgdir = prefs_get_cfgdir ();
-  if (cfgdir)
+
+  filename = g_build_filename (cfgdir, "prefs", NULL);
+  if(g_file_test(filename, G_FILE_TEST_EXISTS))
   {
-      snprintf(filename, PATH_MAX, "%s/prefs", cfgdir);
-      filename[PATH_MAX] = 0;
-      if(g_file_test(filename, G_FILE_TEST_EXISTS))
+      if((fp = fopen(filename, "r")))
       {
-         if((fp = fopen(filename, "r")))
-         {
-             read_prefs_from_file_desc(fp);
-             fclose(fp);
-             have_prefs = TRUE; /* read prefs */
-         }
-         else
-         {
-             gtkpod_warning(_("Unable to open config file '%s' for 
reading\n"), filename);
-         }
+         read_prefs_from_file_desc(fp);
+         fclose(fp);
+         have_prefs = TRUE; /* read prefs */
       }
-
+      else
+      {
+         gtkpod_warning(_("Unable to open config file '%s' for reading\n"), 
filename);
+         }
   }
+  g_free (filename);
+
   if (!have_prefs)
   {
-      snprintf (filename, PATH_MAX, "/etc/gtkpod/prefs");
+      filename = g_build_filename ("/etc", "gtkpod", "prefs", NULL);
+
       if (g_file_test (filename, G_FILE_TEST_EXISTS))
       {
          if((fp = fopen(filename, "r")))
@@ -1030,8 +1031,9 @@
              have_prefs = TRUE; /* read prefs */
          }
       }
+      g_free (filename);
   }
-  C_FREE (cfgdir);
+  g_free (cfgdir);
   /* set version of the prefs file to "current" if none was read */
   if (!have_prefs)   cfg->version = g_ascii_strtod (VERSION, NULL);
 
@@ -1287,35 +1289,30 @@
 /*     fprintf (fp, "unused_gboolean3=%d\n", cfg->unused_gboolean3); */
 }
 
+
 void
 write_prefs (void)
 {
-    gchar filename[PATH_MAX+1];
+    gchar *filename;
     gchar *cfgdir;
     FILE *fp = NULL;
 
     cfgdir = prefs_get_cfgdir ();
-    if(!cfgdir)
-      {
-       gtkpod_warning (_("Settings are not saved.\n"));
-      }
+
+    filename = g_build_filename (cfgdir, "prefs", NULL);
+    if((fp = fopen(filename, "w")))
+    {
+       write_prefs_to_file_desc(fp);
+       fclose(fp);
+    }
     else
-      {
-       snprintf(filename, PATH_MAX, "%s/prefs", cfgdir);
-       filename[PATH_MAX] = 0;
-       if((fp = fopen(filename, "w")))
-         {
-           write_prefs_to_file_desc(fp);
-           fclose(fp);
-         }
-       else
-         {
-           gtkpod_warning (_("Unable to open '%s' for writing\n"),
-                           filename);
-         }
+    {
+       gtkpod_warning (_("Unable to open '%s' for writing\n"),
+                       filename);
+    }
 
-      }
-    C_FREE (cfgdir);
+    g_free (filename);
+    g_free (cfgdir);
 }
 
 
@@ -1355,24 +1352,12 @@
 static gchar *
 get_dirname_of_filename(const gchar *file)
 {
-    gint len;
-    gchar *buf, *result = NULL;
-
     if (!file) return NULL;
 
     if (g_file_test(file, G_FILE_TEST_IS_DIR))
-       buf = g_strdup (file);
-    else
-       buf = g_path_get_dirname (file);
-
-    len = strlen (buf);
-    if (len && (buf[len-1] == '/'))    result = buf;
+       return g_strdup (file);
     else
-    {
-       result = g_strdup_printf ("%s/", buf);
-       g_free (buf);
-    }
-    return result;
+       return g_path_get_dirname (file);
 }
 
 
@@ -1405,9 +1390,7 @@
     if(cfg->ipod_mount) g_free(cfg->ipod_mount);
     /* if new mount point starts with "~/", we replace it with the
        home directory */
-    if (strncmp ("~/", mp, 2) == 0)
-      cfg->ipod_mount = g_build_filename (g_get_home_dir (), mp+2, NULL);
-    else cfg->ipod_mount = g_strdup(mp);
+    cfg->ipod_mount = convert_filename (mp);
     /* need to notify the info thread of new mount point */
     space_set_ipod_mount (cfg->ipod_mount);
     gp_itdb_set_mountpoint (cfg->ipod_mount);
@@ -1712,25 +1695,24 @@
 }
 
 
-/* Returns "$HOME/.gtkpod" or NULL if dir does not exist and cannot be
-   created. You must g_free the string after use */
+/* Returns "$HOME/.gtkpod" and tries to create it if it does not
+   exist. */
 gchar *prefs_get_cfgdir (void)
 {
   G_CONST_RETURN gchar *str;
   gchar *cfgdir=NULL;
 
   if((str = g_get_home_dir ()))
-    {
+  {
       cfgdir = g_build_filename (str, ".gtkpod", NULL);
       if(!g_file_test(cfgdir, G_FILE_TEST_IS_DIR))
-       {
+      {
          if(mkdir(cfgdir, 0755) == -1)
-           {
+         {
              gtkpod_warning(_("Unable to 'mkdir %s'\n"), cfgdir);
-             C_FREE (cfgdir); /*defined in misc.h*/
-           }
-       }
-    }
+         }
+      }
+  }
   return cfgdir;
 }
 
@@ -2748,21 +2730,16 @@
 
 void prefs_set_pc_dir (const gchar *str)
 {
-    if (str)
-    {
-        g_free (cfg->pc_dir);
-        if (*(str + strlen(str) - 1) == 0x2F)
-        {
-            cfg->pc_dir = g_strndup (str, strlen(str) - 1);
-        } else {
-            cfg->pc_dir = g_strdup (str);
-        }
-    }
+    g_return_if_fail (str);
+
+    g_free (cfg->pc_dir);
+    cfg->pc_dir = convert_filename (str);
 }
 
-const gchar *prefs_get_pc_dir (void)
+/* g_free() after use */
+gchar *prefs_get_pc_dir (void)
 {
-    return cfg->pc_dir;
+    return g_strdup (cfg->pc_dir);
 }
 
 void prefs_set_pc_del_age(gboolean val)
@@ -2820,13 +2797,14 @@
     if (str)
     {
         g_free (cfg->pc_log_file);
-        cfg->pc_log_file = g_strdup (str);
+        cfg->pc_log_file = convert_filename (str);
     }
 }
 
-const gchar *prefs_get_pc_log_file(void)
+/* g_free() after use */
+gchar *prefs_get_pc_log_file(void)
 {
-    return cfg->pc_log_file;
+    return g_strdup (cfg->pc_log_file);
 }
 
 void prefs_set_pc_auto_sync(gboolean val)

Index: prefs.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/prefs.h,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -d -r1.99 -r1.100
--- prefs.h     27 Sep 2005 11:29:24 -0000      1.99
+++ prefs.h     12 Nov 2005 08:54:31 -0000      1.100
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-07-01 23:16:54 jcs>
+/* Time-stamp: <2005-11-12 16:05:19 jcs>
 |
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
 |  Part of the gtkpod project.
@@ -367,7 +367,7 @@
 
 /* Podcast preferences */
 void prefs_set_pc_dir(const gchar *str);
-const gchar *prefs_get_pc_dir(void);
+gchar *prefs_get_pc_dir(void);
 void prefs_set_pc_del_age(gboolean val);
 gboolean prefs_get_pc_del_age(void);
 void prefs_set_pc_del_age_val(gint val);
@@ -379,7 +379,7 @@
 void prefs_set_pc_log(gboolean val);
 gboolean prefs_get_pc_log(void);
 void prefs_set_pc_log_file(const gchar *str);
-const gchar *prefs_get_pc_log_file(void);
+gchar *prefs_get_pc_log_file(void);
 void prefs_set_pc_auto_sync(gboolean val);
 gboolean prefs_get_pc_auto_sync(void);
 void prefs_set_pc_ipod_del_age(gboolean val);

Index: prefs_window.c
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/prefs_window.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -d -r1.108 -r1.109
--- prefs_window.c      18 Oct 2005 14:29:55 -0000      1.108
+++ prefs_window.c      12 Nov 2005 08:54:31 -0000      1.109
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-10-18 08:57:40 jcs>
+/* Time-stamp: <2005-11-12 17:18:55 jcs>
 |
 |  Copyright (C) 2002 Corey Donohoe <atmos at atmos.org>
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
@@ -122,7 +122,6 @@
     -1
 };
 
-static GtkListStore *subs_store;
 
 /* pointers to fileselectors */
 static GtkWidget *path_filechooser[PATH_NUM];
@@ -335,13 +334,26 @@
 }
 
 
+/* Opens the podcasts options */
+void prefs_window_podcasts ()
+{
+    prefs_window_create (5);
+}
+
+
+
 /**
  * create_gtk_prefs_window
  * Create, Initialize, and Show the preferences window
  * allocate a static cfg struct for temporary variables
+ *
+ * If the window is already open, it is raised to the front and @page
+ * is selected (unless it's -1).
+ *
+ * @page: -1 for 'last page'.
  */
 void
-prefs_window_create(void)
+prefs_window_create (gint page)
 {
     gint i;
     gint defx, defy;
@@ -352,6 +364,14 @@
     if (prefs_window)
     {   /* prefs window already open -- raise to the top */
        gdk_window_raise (prefs_window->window);
+       if (page != -1)
+       {
+           g_return_if_fail (prefs_window_xml);
+           if ((w = glade_xml_get_widget (prefs_window_xml, "notebook")))
+           {
+               gtk_notebook_set_current_page (GTK_NOTEBOOK (w), page);
+           }
+       }
        return;
     }
 
@@ -702,8 +722,15 @@
     
     if ((w = glade_xml_get_widget (prefs_window_xml, "notebook")))
     {
-       gtk_notebook_set_current_page (GTK_NOTEBOOK (w),
-                                      prefs_get_last_prefs_page ());
+       if (page == -1)
+       {
+           gtk_notebook_set_current_page (GTK_NOTEBOOK (w),
+                                          prefs_get_last_prefs_page ());
+       }
+       else
+       {
+           gtk_notebook_set_current_page (GTK_NOTEBOOK (w), page);
+       }
     }
     if ((w = glade_xml_get_widget (prefs_window_xml, "cfg_automount_ipod")))
     {

Index: prefs_window.h
===================================================================
RCS file: /cvsroot/gtkpod/gtkpod/src/prefs_window.h,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- prefs_window.h      27 Sep 2005 11:29:24 -0000      1.67
+++ prefs_window.h      12 Nov 2005 08:54:31 -0000      1.68
@@ -1,4 +1,4 @@
-/* Time-stamp: <2005-06-17 21:01:39 jcs>
+/* Time-stamp: <2005-11-12 17:16:12 jcs>
 |
 |  Copyright (C) 2002 Corey Donohoe <atmos at atmos.org>
 |  Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
@@ -41,8 +41,9 @@
 void prefs_window_ok (void);
 void prefs_window_apply (void);
 void prefs_window_cancel (void);
-void prefs_window_create (void);
+void prefs_window_create (gint page);
 void prefs_window_delete (void);
+void prefs_window_podcasts (void);
 
 void prefs_window_set_unused_gboolean3 (gboolean val);
 



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
gtkpod-cvs2 mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to