[Xfce4-commits] <xfburn:master> Ensure that paths passed in from the cli are absolute

David Mohr noreply at xfce.org
Fri Dec 4 08:50:03 CET 2009


Updating branch refs/heads/master
         to 84308bd5a8936529fb8aff21139cba66e570030c (commit)
       from 0d6d0bafe9d54d9bd237ad77fa222322d2f62db3 (commit)

commit 84308bd5a8936529fb8aff21139cba66e570030c
Author: David Mohr <squisher at xfce.org>
Date:   Fri Dec 4 00:49:21 2009 -0700

    Ensure that paths passed in from the cli are absolute

 xfburn/xfburn-audio-composition.c |   21 +++++++++++----------
 xfburn/xfburn-audio-composition.h |    2 +-
 xfburn/xfburn-data-composition.c  |   20 ++++++++++----------
 xfburn/xfburn-data-composition.h  |    2 +-
 xfburn/xfburn-main-window.c       |   10 ++++++++--
 xfburn/xfburn-utils.c             |   25 +++++++++++++++++++++++++
 xfburn/xfburn-utils.h             |    1 +
 7 files changed, 57 insertions(+), 24 deletions(-)

diff --git a/xfburn/xfburn-audio-composition.c b/xfburn/xfburn-audio-composition.c
index eb9c624..4e9ceae 100644
--- a/xfburn/xfburn-audio-composition.c
+++ b/xfburn/xfburn-audio-composition.c
@@ -45,6 +45,7 @@
 #include "xfburn-audio-composition.h"
 #include "xfburn-global.h"
 #include "xfburn-error.h"
+#include "xfburn-utils.h"
 
 #include "xfburn-adding-progress.h"
 #include "xfburn-composition.h"
@@ -92,8 +93,7 @@ typedef enum
 
 /* thread parameters */
 typedef struct {
-  char **filenames;
-  int filec;
+  GSList * filelist;
   XfburnAudioComposition *dc;
 } ThreadAddFilesCLIParams;
 
@@ -1293,19 +1293,21 @@ thread_add_files_cli (ThreadAddFilesCLIParams *params)
   GtkTreeIter iter;
 
   GtkTreeModel *model;
-  int i;
-  gchar *full_path = NULL;
+  GSList * list_iter;
 
   gdk_threads_enter ();
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->content));
   gdk_threads_leave ();
 
-  for (i=0; i<params->filec; i++) {
-    full_path = g_build_filename (params->filenames[i], NULL);
+  for (list_iter = params->filelist; list_iter != NULL; list_iter = g_slist_next (list_iter)) {
+    gchar * full_path = (gchar *) list_iter->data;
+
     g_message ("Adding %s to the audio composition... (might take a while)", full_path);
     thread_add_file_to_list (params->dc, model, full_path, &iter, NULL, GTK_TREE_VIEW_DROP_AFTER);  
+
     g_free (full_path);
   }
+  g_slist_free (params->filelist);
   xfburn_adding_progress_done (XFBURN_ADDING_PROGRESS (priv->progress));
 }
 
@@ -2145,16 +2147,15 @@ xfburn_audio_composition_new (void)
 }
 
 void 
-xfburn_audio_composition_add_files (XfburnAudioComposition *dc, int filec, char **filenames)
+xfburn_audio_composition_add_files (XfburnAudioComposition *dc, GSList * filelist)
 {
   XfburnAudioCompositionPrivate *priv = XFBURN_AUDIO_COMPOSITION_GET_PRIVATE (dc);
   ThreadAddFilesCLIParams *params;
   
-  if (filec > 0) {
+  if (filelist != NULL) {
     params = g_new (ThreadAddFilesCLIParams, 1);
 
-    params->filenames = filenames;
-    params->filec = filec;
+    params->filelist = filelist;
     params->dc = dc;
 
     xfburn_adding_progress_show (XFBURN_ADDING_PROGRESS (priv->progress));
diff --git a/xfburn/xfburn-audio-composition.h b/xfburn/xfburn-audio-composition.h
index e459536..f7772aa 100644
--- a/xfburn/xfburn-audio-composition.h
+++ b/xfburn/xfburn-audio-composition.h
@@ -56,7 +56,7 @@ enum
 GType xfburn_audio_composition_get_type (void);
 
 GtkWidget *xfburn_audio_composition_new (void);
-void xfburn_audio_composition_add_files (XfburnAudioComposition *content, int filec, char **filenames);
+void xfburn_audio_composition_add_files (XfburnAudioComposition *content, GSList * filelist);
 void xfburn_audio_composition_hide_toolbar (XfburnAudioComposition *content);
 void xfburn_audio_composition_show_toolbar (XfburnAudioComposition *content);
 
diff --git a/xfburn/xfburn-data-composition.c b/xfburn/xfburn-data-composition.c
index 143e58a..ef73f78 100644
--- a/xfburn/xfburn-data-composition.c
+++ b/xfburn/xfburn-data-composition.c
@@ -79,8 +79,7 @@ typedef enum
 
 /* thread parameters */
 typedef struct {
-  char **filenames;
-  int filec;
+  GSList * filelist;
   XfburnDataComposition *dc;
 } ThreadAddFilesCLIParams;
 
@@ -1267,19 +1266,21 @@ thread_add_files_cli (ThreadAddFilesCLIParams *params)
   GtkTreeIter iter;
 
   GtkTreeModel *model;
-  int i;
-  gchar *full_path = NULL;
+  GSList * list_iter;
 
   gdk_threads_enter ();
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->content));
   gdk_threads_leave ();
 
-  for (i=0; i<params->filec; i++) {
-    full_path = g_build_filename (params->filenames[i], NULL);
+  for (list_iter = params->filelist; list_iter != NULL; list_iter = g_slist_next (list_iter)) {
+    gchar * full_path = (gchar *) list_iter->data;
+
     g_message ("Adding %s to the data composition... (might take a while)", full_path);
     thread_add_file_to_list (params->dc, model, full_path, &iter, NULL, GTK_TREE_VIEW_DROP_AFTER);  
+
     g_free (full_path);
   }
+  g_slist_free (params->filelist);
   xfburn_adding_progress_done (XFBURN_ADDING_PROGRESS (priv->progress));
 }
 
@@ -2190,16 +2191,15 @@ xfburn_data_composition_new (void)
 }
 
 void 
-xfburn_data_composition_add_files (XfburnDataComposition *dc, int filec, char **filenames)
+xfburn_data_composition_add_files (XfburnDataComposition *dc, GSList * filelist)
 {
   XfburnDataCompositionPrivate *priv = XFBURN_DATA_COMPOSITION_GET_PRIVATE (dc);
   ThreadAddFilesCLIParams *params;
   
-  if (filec > 0) {
+  if (filelist != NULL) {
     params = g_new (ThreadAddFilesCLIParams, 1);
 
-    params->filenames = filenames;
-    params->filec = filec;
+    params->filelist = filelist;
     params->dc = dc;
 
     xfburn_adding_progress_show (XFBURN_ADDING_PROGRESS (priv->progress));
diff --git a/xfburn/xfburn-data-composition.h b/xfburn/xfburn-data-composition.h
index 578f5b2..463ac8a 100644
--- a/xfburn/xfburn-data-composition.h
+++ b/xfburn/xfburn-data-composition.h
@@ -54,7 +54,7 @@ enum
 GType xfburn_data_composition_get_type (void);
 
 GtkWidget *xfburn_data_composition_new (void);
-void xfburn_data_composition_add_files (XfburnDataComposition *content, int filec, char **filenames);
+void xfburn_data_composition_add_files (XfburnDataComposition *content, GSList * filelist);
 void xfburn_data_composition_hide_toolbar (XfburnDataComposition *content);
 void xfburn_data_composition_show_toolbar (XfburnDataComposition *content);
 
diff --git a/xfburn/xfburn-main-window.c b/xfburn/xfburn-main-window.c
index 3dfcf1a..3451ac0 100644
--- a/xfburn/xfburn-main-window.c
+++ b/xfburn/xfburn-main-window.c
@@ -40,6 +40,7 @@
 #include "xfburn-settings.h"
 #include "xfburn-main.h"
 #include "xfburn-stock.h"
+#include "xfburn-utils.h"
 
 #define XFBURN_MAIN_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XFBURN_TYPE_MAIN_WINDOW, XfburnMainWindowPrivate))
 
@@ -709,9 +710,12 @@ xfburn_main_window_add_data_composition_with_files (XfburnMainWindow *window, in
 {
   XfburnMainWindowPrivate *priv = XFBURN_MAIN_WINDOW_GET_PRIVATE (window);
   XfburnComposition *comp;
+  GSList * filelist;
  
   comp = xfburn_compositions_notebook_add_composition (XFBURN_COMPOSITIONS_NOTEBOOK (priv->compositions_notebook), XFBURN_DATA_COMPOSITION);
-  xfburn_data_composition_add_files (XFBURN_DATA_COMPOSITION (comp), filec, filenames);
+
+  filelist = xfburn_make_abosulet_file_list (filec, filenames);
+  xfburn_data_composition_add_files (XFBURN_DATA_COMPOSITION (comp), filelist);
 }
 
 void 
@@ -719,9 +723,11 @@ xfburn_main_window_add_audio_composition_with_files (XfburnMainWindow *window, i
 {
   XfburnMainWindowPrivate *priv = XFBURN_MAIN_WINDOW_GET_PRIVATE (window);
   XfburnComposition *comp;
+  GSList * filelist;
  
   comp = xfburn_compositions_notebook_add_composition (XFBURN_COMPOSITIONS_NOTEBOOK (priv->compositions_notebook), XFBURN_AUDIO_COMPOSITION);
-  xfburn_audio_composition_add_files (XFBURN_AUDIO_COMPOSITION (comp), filec, filenames);
+  filelist = xfburn_make_abosulet_file_list (filec, filenames);
+  xfburn_audio_composition_add_files (XFBURN_AUDIO_COMPOSITION (comp), filelist);
 }
 
 gboolean
diff --git a/xfburn/xfburn-utils.c b/xfburn/xfburn-utils.c
index 9cf052b..17689f2 100644
--- a/xfburn/xfburn-utils.c
+++ b/xfburn/xfburn-utils.c
@@ -211,3 +211,28 @@ xfburn_console_libburn_messages (void)
  
 }
 
+
+GSList *
+xfburn_make_abosulet_file_list (gint count, gchar *filenames[])
+{
+  gint i;
+  GSList * list = NULL;
+  gchar *file, *abs, *pwd;
+
+  pwd = g_get_current_dir ();
+
+  for (i=0; i<count; i++) {
+    file = filenames[i];
+
+    if (!g_path_is_absolute (file))
+      abs = g_build_filename (pwd, file, NULL);
+    else
+      abs = g_build_filename (file, NULL);
+
+    list = g_slist_prepend (list, abs);
+  }
+
+  g_free (pwd);
+
+  return list;
+}
diff --git a/xfburn/xfburn-utils.h b/xfburn/xfburn-utils.h
index fbf465d..27dc679 100644
--- a/xfburn/xfburn-utils.h
+++ b/xfburn/xfburn-utils.h
@@ -32,6 +32,7 @@ void xfburn_default_cursor (GtkWidget *);
 
 gchar *xfburn_humanreadable_filesize (guint64);
 guint64 xfburn_calc_dirsize (const gchar *);
+GSList * xfburn_make_abosulet_file_list (gint count, gchar *filenames[]);
 
 void xfburn_browse_for_file (GtkEntry *entry, GtkWindow *parent);
 



More information about the Xfce4-commits mailing list