From f3e001990b61a336c1f30c5bae8065c15e320aec Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Sat, 17 Dec 2005 18:59:58 +0000 Subject: Use GLib API to manipulate pathname. 2005-12-17 Tor Lillqvist * save-attachments.c (entry_changed): Use GLib API to manipulate pathname. svn path=/trunk/; revision=30848 --- plugins/save-attachments/ChangeLog | 5 +++++ plugins/save-attachments/save-attachments.c | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/save-attachments/ChangeLog b/plugins/save-attachments/ChangeLog index 3ab5a8a8a8..599381eba1 100644 --- a/plugins/save-attachments/ChangeLog +++ b/plugins/save-attachments/ChangeLog @@ -1,3 +1,8 @@ +2005-12-17 Tor Lillqvist + + * save-attachments.c (entry_changed): Use GLib API to manipulate + pathname. + 2005-05-16 Not Zed * save-attachments.c: moved e-error to e-util diff --git a/plugins/save-attachments/save-attachments.c b/plugins/save-attachments/save-attachments.c index 4ecd7e5943..bc4dc89a6c 100644 --- a/plugins/save-attachments/save-attachments.c +++ b/plugins/save-attachments/save-attachments.c @@ -30,6 +30,11 @@ #include #include +#include + +#if !GLIB_CHECK_VERSION (2, 8, 0) +#define g_access access +#endif #include #include @@ -220,7 +225,7 @@ save_part(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, void *d) * the POSIX access-call should suffice for checking the file existence. */ - if (access(save, F_OK) == 0) + if (g_access(save, F_OK) == 0) doit = e_error_run(NULL, E_ERROR_ASK_FILE_EXISTS_OVERWRITE, save, NULL) == GTK_RESPONSE_OK; if (doit) @@ -271,20 +276,22 @@ static void entry_changed(GtkWidget *entry, struct _save_data *data) { char *path; + char *basename = NULL; const char *file; - struct stat st; path = gnome_file_entry_get_full_path((GnomeFileEntry *)data->entry, FALSE); if (path == NULL - || (file = strrchr(path, '/')) == NULL - || file[1] == 0 - || (stat(path, &st) == 0 && S_ISDIR(st.st_mode))) + || G_IS_DIR_SEPARATOR (path[strlen(path)-1]) + || (basename = g_path_get_basename(path)) == NULL + || (basename[0] == '.' && basename[1] == '\0') + || (g_file_test(path, G_FILE_TEST_IS_DIR))) file = "attachment"; else - file++; + file = basename; gtk_tree_model_foreach((GtkTreeModel *)data->model, entry_changed_update, (void *)file); g_free(path); + g_free(basename); } static void -- cgit v1.2.3