commit dab376b8b67c043a8a5e937abc4452cdd533eaac
parent 36067e24da07e071cb6ca722029a484ac9d48fed
Author: Oliver Lowe <o@olowe.co>
Date: Sat, 29 Nov 2025 11:51:21 +1100
Start removing address book pictures
Diffstat:
10 files changed, 53 insertions(+), 255 deletions(-)
diff --git a/src/addritem.c b/src/addritem.c
@@ -270,42 +270,24 @@ void addritem_person_set_picture( ItemPerson *person, const gchar *value ) {
}
}
-/**
- * Get picture filename for person object.
- * \param person Person object.
- * \return copy of picture file path string (to be freed by caller - and there is
- * no guarantee that path does exist, or NULL.
- */
-gchar *addritem_person_get_picture( ItemPerson *person) {
- if (person->picture)
- return g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S,
- ADDRBOOK_DIR, G_DIR_SEPARATOR_S, person->picture,
- ".png", NULL );
- return NULL;
+size_t addritem_person_get_picture(char *dst, ItemPerson *person) {
+ if (!person->picture)
+ return 0;
+ char buf[PATH_MAX];
+ snprintf(buf, sizeof(buf), "%s/%s/%s.png", get_rc_dir(), ADDRBOOK_DIR, person->picture);
+ return strlcpy(dst, buf, sizeof(dst));
}
-/**
- * Delete picture for person object.
- * \param person Person object.
- */
-void addritem_person_remove_picture( ItemPerson *person) {
- if (person->picture) {
- gchar *filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S,
- ADDRBOOK_DIR, G_DIR_SEPARATOR_S, person->picture,
- ".png", NULL );
- if (is_file_exist(filename)) {
- debug_print("removing addressbook picture %s\n",
- filename);
- if (unlink(filename) < 0) {
- FILE_OP_ERROR(filename, "remove");
- g_free(filename);
- return;
- }
- }
- g_free(person->picture);
- person->picture = NULL;
- g_free(filename);
- }
+int addritem_person_remove_picture(ItemPerson *person) {
+ if (!person->picture)
+ return 0;
+
+ char path[PATH_MAX];
+ snprintf(path, sizeof(path), "%s/%s/%s", get_rc_dir(), ADDRBOOK_DIR, person->picture);
+ int ret = unlink(path);
+ free(person->picture);
+ person->picture = NULL;
+ return ret;
}
/**
diff --git a/src/addritem.h b/src/addritem.h
@@ -136,8 +136,8 @@ void addritem_free_attribute ( UserAttribute *item );
ItemPerson *addritem_create_item_person ( void );
ItemPerson *addritem_copy_item_person ( ItemPerson *item );
void addritem_person_set_picture ( ItemPerson *person, const gchar *value );
-gchar *addritem_person_get_picture ( ItemPerson *person);
-void addritem_person_remove_picture ( ItemPerson *person);
+size_t addritem_person_get_picture (char *dst, ItemPerson *person);
+int addritem_person_remove_picture ( ItemPerson *person);
void addritem_person_set_first_name ( ItemPerson *person, const gchar *value );
void addritem_person_set_last_name ( ItemPerson *person, const gchar *value );
void addritem_person_set_nick_name ( ItemPerson *person, const gchar *value );
diff --git a/src/addrmerge.c b/src/addrmerge.c
@@ -121,14 +121,10 @@ static void addrmerge_do_merge(struct AddrMergePage *page)
addritem_folder_remove_person(ADAPTER_FOLDER(page->pobj)->itemFolder, person);
person = addrbook_remove_person( page->abf, person );
- if( person ) {
- gchar *filename = addritem_person_get_picture(person);
- if ((g_strcmp0(person->picture, target->picture) &&
- filename && is_file_exist(filename)))
- unlink(filename);
- if (filename)
- g_free(filename);
- addritem_free_item_person( person );
+ if (person) {
+ char filename[PATH_MAX];
+ if (addritem_person_get_picture(filename, person))
+ remove(filename);
}
}
@@ -201,10 +197,8 @@ static void addrmerge_prompt( struct AddrMergePage *page )
GtkWidget *namesList = NULL;
MainWindow *mainwin = mainwindow_get_mainwindow();
GtkListStore *store = NULL;
- GtkTreeIter iter;
GList *node;
ItemPerson *person;
- GError *error = NULL;
gchar *msg, *label_msg;
dialog = page->dialog = gtk_dialog_new_with_buttons (
@@ -241,66 +235,6 @@ static void addrmerge_prompt( struct AddrMergePage *page )
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
g_free(label_msg);
- if (page->pickPicture) {
- GtkWidget *scrollwinPictures;
-
- store = gtk_list_store_new(N_SET_COLUMNS,
- GDK_TYPE_PIXBUF,
- G_TYPE_POINTER,
- -1);
- gtk_list_store_clear(store);
-
- vbox = gtkut_get_options_frame(mvbox, &frame,
- _("Keep which picture?"));
- gtk_container_set_border_width(GTK_CONTAINER(frame), 4);
-
- scrollwinPictures = gtk_scrolled_window_new(NULL, NULL);
- gtk_container_set_border_width(GTK_CONTAINER(scrollwinPictures), 1);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwinPictures),
- GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrollwinPictures),
- GTK_SHADOW_IN);
- gtk_box_pack_start (GTK_BOX (vbox), scrollwinPictures, FALSE, FALSE, 0);
- gtk_widget_set_size_request(scrollwinPictures, 464, 192);
-
- iconView = gtk_icon_view_new_with_model(GTK_TREE_MODEL(store));
- gtk_icon_view_set_selection_mode(GTK_ICON_VIEW(iconView), GTK_SELECTION_SINGLE);
- gtk_icon_view_set_pixbuf_column(GTK_ICON_VIEW(iconView), SET_ICON);
- gtk_container_add(GTK_CONTAINER(scrollwinPictures), GTK_WIDGET(iconView));
- g_signal_connect(G_OBJECT(iconView), "selection-changed",
- G_CALLBACK(addrmerge_picture_selected), page);
-
- /* Add pictures from persons */
- for (node = page->persons; node; node = node->next) {
- gchar *filename;
- person = node->data;
- filename = addritem_person_get_picture(person);
- if (filename && is_file_exist(filename)) {
- GdkPixbuf *pixbuf;
- GtkWidget *image;
-
- pixbuf = gdk_pixbuf_new_from_file(filename, &error);
- if (error) {
- debug_print("Failed to read image: \n%s",
- error->message);
- g_error_free(error);
- continue;
- }
-
- image = gtk_image_new();
- gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
-
- gtk_list_store_append(store, &iter);
- gtk_list_store_set(store, &iter,
- SET_ICON, pixbuf,
- SET_PERSON, person,
- -1);
- }
- if (filename)
- g_free(filename);
- }
- }
-
if (page->pickName) {
GtkWidget *scrollwinNames;
gchar *name_titles[N_NAME_COLS];
@@ -374,11 +308,10 @@ void addrmerge_merge(
AddrItemObject *aio;
ItemPerson *person, *target = NULL, *nameTarget = NULL;
GList *persons = NULL, *emails = NULL;
- gboolean pickPicture = FALSE, pickName = FALSE;
+ gboolean pickName = FALSE;
- /* Test for read only */
if( ds->interface->readOnly ) {
- alertpanel_warning(_("This address data is read-only and cannot be deleted."));
+ alertpanel_warning("This address data is read-only and cannot be deleted.");
return;
}
@@ -409,28 +342,7 @@ void addrmerge_merge(
}
}
- /* Check if more than one person has a picture */
- for (node = persons; node; node = node->next) {
- gchar *filename;
- person = node->data;
- filename = addritem_person_get_picture(person);
- if (filename && is_file_exist(filename)) {
- if (target == NULL) {
- target = person;
- } else {
- pickPicture = TRUE;
- target = NULL;
- g_free(filename);
- break;
- }
- }
- if (filename)
- g_free(filename);
- }
- if (pickPicture || target) {
- /* At least one person had a picture */
- } else if (persons && persons->data) {
- /* No person had a picture. Use the first person as target */
+ if (persons && persons->data) {
target = persons->data;
} else {
/* No persons in list. Abort */
@@ -459,7 +371,7 @@ void addrmerge_merge(
/* Create object */
page = g_new0(struct AddrMergePage, 1);
- page->pickPicture = pickPicture;
+ page->pickPicture = FALSE;
page->pickName = pickName;
page->target = target;
page->nameTarget = nameTarget;
diff --git a/src/common/utils.h b/src/common/utils.h
@@ -36,14 +36,6 @@
#endif
#include <wchar.h>
-/* The Hurd doesn't have these limits */
-#ifndef PATH_MAX
- #define PATH_MAX 4196
-#endif
-#ifndef HOST_NAME_MAX
- #define HOST_NAME_MAX 256
-#endif
-
/* Handling Base64 content in procmime and prefs_customheader */
#define B64_LINE_SIZE 57
diff --git a/src/compose.c b/src/compose.c
@@ -43,6 +43,7 @@
#include <wchar.h>
#include <wctype.h>
#include <signal.h>
+#include <err.h>
#include <errno.h>
#include <libgen.h>
@@ -7855,8 +7856,8 @@ static void compose_ext_editor_closed_cb(GPid pid, gint exit_status, gpointer da
if (compose_can_autosave(compose))
compose_draft((gpointer)compose, COMPOSE_AUTO_SAVE);
- if (unlink(compose->exteditor_file) < 0)
- FILE_OP_ERROR(compose->exteditor_file, "unlink");
+ if (remove(compose->exteditor_file) < 0)
+ warn("remove %s", compose->exteditor_file);
gtk_text_buffer_get_start_iter(buffer, &iter);
diff --git a/src/editaddress.c b/src/editaddress.c
@@ -1243,37 +1243,6 @@ static gboolean addressbook_edit_person_close( gboolean cancelled )
addritem_person_set_common_name( current_person, cn );
g_free( cn );
- if (personeditdlg.picture_set) {
- GdkPixbuf * pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(personeditdlg.image));
-
- if (!current_person->picture)
- name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S,
- ADDRITEM_ID(current_person), ".png", NULL );
- else
- name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S,
- current_person->picture, ".png", NULL );
-
- gdk_pixbuf_save(pixbuf, name, "png", &error, NULL);
- if (error) {
- alertpanel_error(_("Failed to save image: \n%s"),
- error->message);
- g_error_free(error);
- } else {
- debug_print("saved picture to %s\n", name);
- }
- if (!current_person->picture)
- addritem_person_set_picture( current_person, ADDRITEM_ID(current_person) ) ;
- g_free( name );
- } else {
- if (!current_person->picture)
- name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S,
- ADDRITEM_ID(current_person), ".png", NULL );
- else
- name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S,
- current_person->picture, ".png", NULL );
- unlink(name);
- g_free(name);
- }
name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_first), 0, -1 );
addritem_person_set_first_name( current_person, name );
g_free( name );
@@ -1360,35 +1329,6 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent_fo
if( ADDRITEM_NAME(current_person) )
gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_name), ADDRITEM_NAME(person) );
-
- if( current_person->picture ) {
- filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S,
- current_person->picture, ".png", NULL );
- if (is_file_exist(filename)) {
- pixbuf = gdk_pixbuf_new_from_file(filename, &error);
- if (error) {
- debug_print("Failed to import image: %s\n",
- error->message);
- g_error_free(error);
- goto no_img;
- }
- personeditdlg.picture_set = TRUE;
- cm_menu_set_sensitive("EditAddressPopup/UnsetPicture", personeditdlg.picture_set);
- } else {
- goto no_img;
- }
- gtk_image_set_from_pixbuf(GTK_IMAGE(personeditdlg.image), pixbuf);
- } else {
-no_img:
- addressbook_edit_person_clear_picture();
- }
-
- g_free(filename);
- if (pixbuf) {
- g_object_unref(pixbuf);
- pixbuf = NULL;
- }
-
if( current_person->firstName )
gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_first), current_person->firstName );
if( current_person->lastName )
diff --git a/src/folder.c b/src/folder.c
@@ -804,7 +804,6 @@ gint folder_read_list(void)
gint config_version = -1;
path = folder_get_list_path();
- if (!is_file_exist(path)) return -1;
node = xml_parse_file(path);
if (!node) return -1;
@@ -3781,8 +3780,7 @@ void folder_item_discard_cache(FolderItem *item)
g_free(dir);
cache = folder_item_get_cache_file(item);
- if (is_file_exist(cache))
- unlink(cache);
+ unlink(cache);
g_free(cache);
}
diff --git a/src/imap.c b/src/imap.c
@@ -1369,16 +1369,14 @@ static gchar *imap_get_cached_filename(FolderItem *item, guint msgnum)
static void imap_remove_cached_msg(Folder *folder, FolderItem *item, MsgInfo *msginfo)
{
- gchar *filename;
-
- filename = imap_get_cached_filename(item, msginfo->msgnum);
-
- cm_return_if_fail(filename != NULL);
-
- if (is_file_exist(filename)) {
- unlink(filename);
+ char *name = imap_get_cached_filename(item, msginfo->msgnum);
+ if (!name) {
+ warn("cannot get filename for message number %d", msginfo->msgnum);
+ return;
}
- g_free(filename);
+ if (remove(name) < 0)
+ warn("remove %s", name);
+ free(name);
}
static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
diff --git a/src/main.c b/src/main.c
@@ -149,21 +149,6 @@ static void quit_signal_handler (int sig);
static void install_basic_sighandlers (void);
static void exit_claws (MainWindow *mainwin);
-#define MAKE_DIR_IF_NOT_EXIST(dir) \
-{ \
- if (!is_dir_exist(dir)) { \
- if (is_file_exist(dir)) { \
- alertpanel_warning \
- (_("File '%s' already exists.\n" \
- "Can't create folder."), \
- dir); \
- return 1; \
- } \
- if (make_dir(dir) < 0) \
- return 1; \
- } \
-}
-
#define STRNCMP(S1, S2) (strncmp((S1), (S2), sizeof((S2)) - 1))
#define CM_FD_WRITE(S) fd_write(sock, (S), strlen((S)))
@@ -381,23 +366,17 @@ int main(int argc, char *argv[])
g_free(userrc);
CHDIR_RETURN_VAL_IF_FAIL(get_rc_dir(), 1);
- MAKE_DIR_IF_NOT_EXIST(get_mail_base_dir());
- MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
- MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
+ if (mkdir(get_mail_base_dir(), 0755) < 0 && errno != EEXIST)
+ err(1, "make %s", get_mail_base_dir());
+ if (mkdir(get_mime_tmp_dir(), 0755) < 0 && errno != EEXIST)
+ err(1, "make %s", get_mime_tmp_dir());
+ if (mkdir(get_tmp_dir(), 0755) < 0 && errno != EEXIST)
+ err(1, "make %s", get_tmp_dir());
remove_all_files(get_tmp_dir());
remove_all_files(get_mime_tmp_dir());
- if (is_file_exist("claws.log")) {
- if (rename_force("claws.log", "claws.log.bak") < 0)
- FILE_OP_ERROR("claws.log", "rename");
- }
set_log_file(LOG_PROTOCOL, "claws.log");
-
- if (is_file_exist("filtering.log")) {
- if (rename_force("filtering.log", "filtering.log.bak") < 0)
- FILE_OP_ERROR("filtering.log", "rename");
- }
set_log_file(LOG_DEBUG_FILTERING, "filtering.log");
CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
diff --git a/src/mh.c b/src/mh.c
@@ -301,23 +301,19 @@ gint mh_get_num_list(Folder *folder, FolderItem *item, GSList **list, gboolean *
return nummsgs;
}
-static gchar *mh_fetch_msg(Folder *folder, FolderItem *item, gint num)
+static gchar *mh_fetch_msg(Folder *folder, FolderItem *item, int num)
{
- gchar *path;
- gchar *file;
-
- cm_return_val_if_fail(item != NULL, NULL);
- cm_return_val_if_fail(num > 0, NULL);
-
- path = folder_item_get_path(item);
- file = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
-
- if (!is_file_exist(file)) {
- g_free(file);
- g_free(path);
+ if (item == NULL) {
+ warn("fetch message %d: NULL folder item", num);
+ return NULL;
+ } else if (num <= 0) {
+ warn("fetch message %d: message number must be positive");
return NULL;
}
- g_free(path);
+
+ char *path = folder_item_get_path(item);
+ char *file = malloc(PATH_MAX);
+ snprintf(file, sizeof(file), "%s/%d", path, num);
return file;
}