diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-09-01 05:40:14 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-09-01 05:40:14 +0000 |
commit | c7f311faa65a86d9751d536cb0ea6f755133471c (patch) | |
tree | 084a3079f7d949aa55022751257d0d1ca027b8e1 /src | |
parent | 61988f3a30a6a8e76530c36482b1227571721fd4 (diff) |
more code cleanups.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@534 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src')
-rw-r--r-- | src/customheader.c | 133 | ||||
-rw-r--r-- | src/customheader.h | 9 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/prefs_account.c | 7 | ||||
-rw-r--r-- | src/prefs_common.c | 1 | ||||
-rw-r--r-- | src/prefs_customheader.c | 135 | ||||
-rw-r--r-- | src/prefs_customheader.h | 2 |
7 files changed, 146 insertions, 143 deletions
diff --git a/src/customheader.c b/src/customheader.c index 535c7407..c145484d 100644 --- a/src/customheader.c +++ b/src/customheader.c @@ -21,14 +21,147 @@ # include "config.h" #endif +#include "defs.h" + #include <glib.h> +#include <stdio.h> #include <string.h> #include <stdlib.h> +#include <errno.h> #include "customheader.h" +#include "prefs.h" +#include "prefs_account.h" #include "utils.h" +void custom_header_read_config(PrefsAccount *ac) +{ + gchar *rcpath; + FILE *fp; + gchar buf[PREFSBUFSIZE]; + CustomHeader *ch; + + debug_print("Reading custom header configuration...\n"); + + rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, + CUSTOM_HEADER_RC, NULL); + if ((fp = g_fopen(rcpath, "rb")) == NULL) { + if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); + g_free(rcpath); + ac->customhdr_list = NULL; + return; + } + g_free(rcpath); + + /* remove all previous headers list */ + while (ac->customhdr_list != NULL) { + ch = (CustomHeader *)ac->customhdr_list->data; + custom_header_free(ch); + ac->customhdr_list = g_slist_remove(ac->customhdr_list, ch); + } + + while (fgets(buf, sizeof(buf), fp) != NULL) { + ch = custom_header_read_str(buf); + if (ch) { + if (ch->account_id == ac->account_id) { + ac->customhdr_list = + g_slist_append(ac->customhdr_list, ch); + } else + custom_header_free(ch); + } + } + + fclose(fp); +} + +void custom_header_write_config(PrefsAccount *ac) +{ + gchar *rcpath; + PrefFile *pfile; + GSList *cur; + gchar buf[PREFSBUFSIZE]; + FILE * fp; + CustomHeader *ch; + + GSList *all_hdrs = NULL; + + debug_print("Writing custom header configuration...\n"); + + rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, + CUSTOM_HEADER_RC, NULL); + + if ((fp = g_fopen(rcpath, "rb")) == NULL) { + if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); + } else { + all_hdrs = NULL; + + while (fgets(buf, sizeof(buf), fp) != NULL) { + ch = custom_header_read_str(buf); + if (ch) { + if (ch->account_id != ac->account_id) + all_hdrs = + g_slist_append(all_hdrs, ch); + else + custom_header_free(ch); + } + } + + fclose(fp); + } + + if ((pfile = prefs_file_open(rcpath)) == NULL) { + g_warning("failed to write configuration to file\n"); + g_free(rcpath); + return; + } + + for (cur = all_hdrs; cur != NULL; cur = cur->next) { + CustomHeader *hdr = (CustomHeader *)cur->data; + gchar *chstr; + + chstr = custom_header_get_str(hdr); + if (fputs(chstr, pfile->fp) == EOF || + fputc('\n', pfile->fp) == EOF) { + FILE_OP_ERROR(rcpath, "fputs || fputc"); + prefs_file_close_revert(pfile); + g_free(rcpath); + g_free(chstr); + return; + } + g_free(chstr); + } + + for (cur = ac->customhdr_list; cur != NULL; cur = cur->next) { + CustomHeader *hdr = (CustomHeader *)cur->data; + gchar *chstr; + + chstr = custom_header_get_str(hdr); + if (fputs(chstr, pfile->fp) == EOF || + fputc('\n', pfile->fp) == EOF) { + FILE_OP_ERROR(rcpath, "fputs || fputc"); + prefs_file_close_revert(pfile); + g_free(rcpath); + g_free(chstr); + return; + } + g_free(chstr); + } + + g_free(rcpath); + + while (all_hdrs != NULL) { + ch = (CustomHeader *)all_hdrs->data; + custom_header_free(ch); + all_hdrs = g_slist_remove(all_hdrs, ch); + } + + if (prefs_file_close(pfile) < 0) { + g_warning("failed to write configuration to file\n"); + return; + } +} + gchar *custom_header_get_str(CustomHeader *ch) { return g_strdup_printf("%i:%s: %s", diff --git a/src/customheader.h b/src/customheader.h index 8554ea7f..27ae9373 100644 --- a/src/customheader.h +++ b/src/customheader.h @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2001 Hiroyuki Yamamoto + * Copyright (C) 1999-2005 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,6 +22,10 @@ #include <glib.h> +typedef struct _CustomHeader CustomHeader; + +#include "prefs_account.h" + struct _CustomHeader { gint account_id; @@ -29,7 +33,8 @@ struct _CustomHeader gchar *value; }; -typedef struct _CustomHeader CustomHeader; +void custom_header_read_config (PrefsAccount *ac); +void custom_header_write_config (PrefsAccount *ac); gchar *custom_header_get_str (CustomHeader *ch); CustomHeader *custom_header_read_str (const gchar *buf); @@ -199,6 +199,8 @@ int main(int argc, char *argv[]) prefs_actions_read_config(); prefs_display_header_read_config(); + gtkut_stock_button_set_set_reverse(!prefs_common.comply_gnome_hig); + check_gpg(); sock_set_io_timeout(prefs_common.io_timeout_secs); diff --git a/src/prefs_account.c b/src/prefs_account.c index 825f85df..9f80a811 100644 --- a/src/prefs_account.c +++ b/src/prefs_account.c @@ -34,12 +34,9 @@ #include "prefs.h" #include "prefs_account.h" -#include "prefs_customheader.h" -#include "prefs_common.h" +#include "customheader.h" #include "account.h" #include "utils.h" -#include "smtp.h" -#include "imap.h" static PrefsAccount tmp_ac_prefs; @@ -197,7 +194,7 @@ void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label) ac_prefs->use_apop_auth = TRUE; } - prefs_custom_header_read_config(ac_prefs); + custom_header_read_config(ac_prefs); } void prefs_account_write_config_all(GList *account_list) diff --git a/src/prefs_common.c b/src/prefs_common.c index f7ebddaa..85589377 100644 --- a/src/prefs_common.c +++ b/src/prefs_common.c @@ -359,7 +359,6 @@ void prefs_common_read_config(void) prefs_common.online_mode = TRUE; - //gtkut_stock_button_set_set_reverse(!prefs_common.comply_gnome_hig); prefs_common_junk_filter_list_set(); path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMAND_HISTORY, diff --git a/src/prefs_customheader.c b/src/prefs_customheader.c index eee8696b..f2a296c3 100644 --- a/src/prefs_customheader.c +++ b/src/prefs_customheader.c @@ -27,10 +27,6 @@ #include <glib/gi18n.h> #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> #include "main.h" #include "prefs.h" @@ -304,133 +300,6 @@ static void prefs_custom_header_create(void) customhdr.customhdr_clist = customhdr_clist; } -void prefs_custom_header_read_config(PrefsAccount *ac) -{ - gchar *rcpath; - FILE *fp; - gchar buf[PREFSBUFSIZE]; - CustomHeader *ch; - - debug_print("Reading custom header configuration...\n"); - - rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, - CUSTOM_HEADER_RC, NULL); - if ((fp = g_fopen(rcpath, "rb")) == NULL) { - if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); - g_free(rcpath); - ac->customhdr_list = NULL; - return; - } - g_free(rcpath); - - /* remove all previous headers list */ - while (ac->customhdr_list != NULL) { - ch = (CustomHeader *)ac->customhdr_list->data; - custom_header_free(ch); - ac->customhdr_list = g_slist_remove(ac->customhdr_list, ch); - } - - while (fgets(buf, sizeof(buf), fp) != NULL) { - ch = custom_header_read_str(buf); - if (ch) { - if (ch->account_id == ac->account_id) { - ac->customhdr_list = - g_slist_append(ac->customhdr_list, ch); - } else - custom_header_free(ch); - } - } - - fclose(fp); -} - -void prefs_custom_header_write_config(PrefsAccount *ac) -{ - gchar *rcpath; - PrefFile *pfile; - GSList *cur; - gchar buf[PREFSBUFSIZE]; - FILE * fp; - CustomHeader *ch; - - GSList *all_hdrs = NULL; - - debug_print("Writing custom header configuration...\n"); - - rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, - CUSTOM_HEADER_RC, NULL); - - if ((fp = g_fopen(rcpath, "rb")) == NULL) { - if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); - } else { - all_hdrs = NULL; - - while (fgets(buf, sizeof(buf), fp) != NULL) { - ch = custom_header_read_str(buf); - if (ch) { - if (ch->account_id != ac->account_id) - all_hdrs = - g_slist_append(all_hdrs, ch); - else - custom_header_free(ch); - } - } - - fclose(fp); - } - - if ((pfile = prefs_file_open(rcpath)) == NULL) { - g_warning(_("failed to write configuration to file\n")); - g_free(rcpath); - return; - } - - for (cur = all_hdrs; cur != NULL; cur = cur->next) { - CustomHeader *hdr = (CustomHeader *)cur->data; - gchar *chstr; - - chstr = custom_header_get_str(hdr); - if (fputs(chstr, pfile->fp) == EOF || - fputc('\n', pfile->fp) == EOF) { - FILE_OP_ERROR(rcpath, "fputs || fputc"); - prefs_file_close_revert(pfile); - g_free(rcpath); - g_free(chstr); - return; - } - g_free(chstr); - } - - for (cur = ac->customhdr_list; cur != NULL; cur = cur->next) { - CustomHeader *hdr = (CustomHeader *)cur->data; - gchar *chstr; - - chstr = custom_header_get_str(hdr); - if (fputs(chstr, pfile->fp) == EOF || - fputc('\n', pfile->fp) == EOF) { - FILE_OP_ERROR(rcpath, "fputs || fputc"); - prefs_file_close_revert(pfile); - g_free(rcpath); - g_free(chstr); - return; - } - g_free(chstr); - } - - g_free(rcpath); - - while (all_hdrs != NULL) { - ch = (CustomHeader *)all_hdrs->data; - custom_header_free(ch); - all_hdrs = g_slist_remove(all_hdrs, ch); - } - - if (prefs_file_close(pfile) < 0) { - g_warning(_("failed to write configuration to file\n")); - return; - } -} - static void prefs_custom_header_set_dialog(PrefsAccount *ac) { GtkCList *clist = GTK_CLIST(customhdr.customhdr_clist); @@ -607,13 +476,13 @@ static gboolean prefs_custom_header_key_pressed(GtkWidget *widget, static void prefs_custom_header_ok(void) { - prefs_custom_header_write_config(cur_ac); + custom_header_write_config(cur_ac); gtk_widget_hide(customhdr.window); } static void prefs_custom_header_cancel(void) { - prefs_custom_header_read_config(cur_ac); + custom_header_read_config(cur_ac); gtk_widget_hide(customhdr.window); } diff --git a/src/prefs_customheader.h b/src/prefs_customheader.h index c72e29d2..18690eea 100644 --- a/src/prefs_customheader.h +++ b/src/prefs_customheader.h @@ -22,8 +22,6 @@ #include "prefs_account.h" -void prefs_custom_header_read_config (PrefsAccount *ac); -void prefs_custom_header_write_config (PrefsAccount *ac); void prefs_custom_header_open (PrefsAccount *ac); #endif /* __PREFS_CUSTOMHEADER_H__ */ |