diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-01-17 11:14:06 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2005-01-17 11:14:06 +0000 |
commit | 3fec59fac205ff4588f8afe93b28943b31f9ab8d (patch) | |
tree | 0687e8a4cc948efdbcf2a480beb9381a03382e85 | |
parent | f0325b36e30c81266a5e6f750553be6bc6e8fe33 (diff) |
automatically take over older config files.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@13 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r-- | src/account.c | 34 | ||||
-rw-r--r-- | src/defs.h | 1 | ||||
-rw-r--r-- | src/folder.c | 9 | ||||
-rw-r--r-- | src/prefs.c | 43 | ||||
-rw-r--r-- | src/prefs.h | 3 | ||||
-rw-r--r-- | src/prefs_account.c | 19 | ||||
-rw-r--r-- | src/prefs_common.c | 14 | ||||
-rw-r--r-- | src/prefs_filter.c | 43 | ||||
-rw-r--r-- | src/utils.c | 11 | ||||
-rw-r--r-- | src/utils.h | 1 |
10 files changed, 120 insertions, 58 deletions
diff --git a/src/account.c b/src/account.c index 49069651..8c9fe253 100644 --- a/src/account.c +++ b/src/account.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2004 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 @@ -44,6 +44,7 @@ #include "stock_pixmap.h" #include "statusbar.h" #include "inc.h" +#include "codeconv.h" #include "gtkutils.h" #include "utils.h" #include "alertpanel.h" @@ -114,13 +115,23 @@ void account_read_config_all(void) { GSList *ac_label_list = NULL, *cur; gchar *rcpath; + const gchar *encoding = NULL; FILE *fp; gchar buf[PREFSBUFSIZE]; PrefsAccount *ac_prefs; debug_print(_("Reading all config for each account...\n")); - rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL); + rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, + NULL); + if (!is_file_exist(rcpath)) { + debug_print("reading older version of accountrc ...\n"); + g_free(rcpath); + rcpath = g_strconcat(get_old_rc_dir(), G_DIR_SEPARATOR_S, + ACCOUNT_RC, NULL); + encoding = conv_get_locale_charset_str(); + } + if ((fp = fopen(rcpath, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); g_free(rcpath); @@ -133,9 +144,22 @@ void account_read_config_all(void) strretchomp(buf); memmove(buf, buf + 1, strlen(buf)); buf[strlen(buf) - 1] = '\0'; - debug_print(_("Found label: %s\n"), buf); - ac_label_list = g_slist_append(ac_label_list, - g_strdup(buf)); + if (encoding) { + gchar *conv_str; + + conv_str = conv_codeset_strdup + (buf, encoding, + conv_get_internal_charset_str()); + if (!conv_str) + conv_str = g_strdup(buf); + debug_print("Found label: %s\n", conv_str); + ac_label_list = g_slist_append(ac_label_list, + conv_str); + } else { + debug_print("Found label: %s\n", buf); + ac_label_list = g_slist_append(ac_label_list, + g_strdup(buf)); + } } } fclose(fp); @@ -38,6 +38,7 @@ #define DRAFT_DIR "draft" #define TRASH_DIR "trash" #define RC_DIR ".sylpheed-2.0" +#define OLD_RC_DIR ".sylpheed" #define NEWS_CACHE_DIR "newscache" #define IMAP_CACHE_DIR "imapcache" #define MIME_TMP_DIR "mimetmp" diff --git a/src/folder.c b/src/folder.c index 08800e53..93e8b334 100644 --- a/src/folder.c +++ b/src/folder.c @@ -339,7 +339,14 @@ gint folder_read_list(void) gchar *path; path = folder_get_list_path(); - if (!is_file_exist(path)) return -1; + if (!is_file_exist(path)) { + debug_print("reading older version of folderlist.xml ...\n"); + path = g_strconcat(get_old_rc_dir(), G_DIR_SEPARATOR_S, + FOLDER_LIST, NULL); + AUTORELEASE_STR(path, return -1); + if (!is_file_exist(path)) + return -1; + } node = xml_parse_file(path); if (!node) return -1; diff --git a/src/prefs.c b/src/prefs.c index d9972b57..b6d2fac8 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -41,28 +41,24 @@ typedef enum } DummyEnum; void prefs_read_config(PrefParam *param, const gchar *label, - const gchar *rcfile) + const gchar *rcfile, const gchar *encoding) { FILE *fp; gchar buf[PREFSBUFSIZE]; - gchar *rcpath; gchar *block_label; g_return_if_fail(param != NULL); g_return_if_fail(label != NULL); g_return_if_fail(rcfile != NULL); - debug_print(_("Reading configuration...\n")); + debug_print("Reading configuration...\n"); prefs_set_default(param); - rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, rcfile, NULL); - if ((fp = fopen(rcpath, "rb")) == NULL) { - if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); - g_free(rcpath); + if ((fp = fopen(rcfile, "rb")) == NULL) { + if (ENOENT != errno) FILE_OP_ERROR(rcfile, "fopen"); return; } - g_free(rcpath); block_label = g_strdup_printf("[%s]", label); @@ -70,9 +66,21 @@ void prefs_read_config(PrefParam *param, const gchar *label, while (fgets(buf, sizeof(buf), fp) != NULL) { gint val; - val = strncmp(buf, block_label, strlen(block_label)); + if (encoding) { + gchar *conv_str; + + conv_str = conv_codeset_strdup + (buf, encoding, + conv_get_internal_charset_str()); + if (!conv_str) + conv_str = g_strdup(buf); + val = strncmp + (conv_str, block_label, strlen(block_label)); + g_free(conv_str); + } else + val = strncmp(buf, block_label, strlen(block_label)); if (val == 0) { - debug_print(_("Found %s\n"), block_label); + debug_print("Found %s\n", block_label); break; } } @@ -83,10 +91,21 @@ void prefs_read_config(PrefParam *param, const gchar *label, /* reached next block */ if (buf[0] == '[') break; - prefs_config_parse_one_line(param, buf); + if (encoding) { + gchar *conv_str; + + conv_str = conv_codeset_strdup + (buf, encoding, + conv_get_internal_charset_str()); + if (!conv_str) + conv_str = g_strdup(buf); + prefs_config_parse_one_line(param, conv_str); + g_free(conv_str); + } else + prefs_config_parse_one_line(param, buf); } - debug_print(_("Finished reading configuration.\n")); + debug_print("Finished reading configuration.\n"); fclose(fp); } diff --git a/src/prefs.h b/src/prefs.h index 987269b0..77ec216b 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -131,7 +131,8 @@ struct _PrefsDialog void prefs_read_config (PrefParam *param, const gchar *label, - const gchar *rcfile); + const gchar *rcfile, + const gchar *encoding); void prefs_config_parse_one_line(PrefParam *param, const gchar *buf); void prefs_write_config (PrefParam *param, diff --git a/src/prefs_account.c b/src/prefs_account.c index bcad14b9..39a5f101 100644 --- a/src/prefs_account.c +++ b/src/prefs_account.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2003 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 @@ -43,6 +43,7 @@ #include "foldersel.h" #include "inc.h" #include "menu.h" +#include "codeconv.h" #include "gtkutils.h" #include "utils.h" #include "alertpanel.h" @@ -514,13 +515,27 @@ PrefsAccount *prefs_account_new(void) void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label) { const guchar *p = label; + gchar *rcpath; + const gchar *encoding = NULL; gint id; g_return_if_fail(ac_prefs != NULL); g_return_if_fail(label != NULL); memset(&tmp_ac_prefs, 0, sizeof(PrefsAccount)); - prefs_read_config(param, label, ACCOUNT_RC); + + rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL); + if (!is_file_exist(rcpath)) { + debug_print("reading older version of accountrc ...\n"); + g_free(rcpath); + rcpath = g_strconcat(get_old_rc_dir(), G_DIR_SEPARATOR_S, + ACCOUNT_RC, NULL); + encoding = conv_get_locale_charset_str(); + } + + prefs_read_config(param, label, rcpath, encoding); + g_free(rcpath); + *ac_prefs = tmp_ac_prefs; while (*p && !isdigit(*p)) p++; id = atoi(p); diff --git a/src/prefs_common.c b/src/prefs_common.c index a448368f..1780d94c 100644 --- a/src/prefs_common.c +++ b/src/prefs_common.c @@ -754,7 +754,19 @@ void prefs_common_read_config(void) gchar *path; gchar buf[PREFSBUFSIZE]; - prefs_read_config(param, "Common", COMMON_RC); + path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL); +#if 0 + if (!is_file_exist(path)) { + debug_print("reading older version of sylpheedrc ...\n"); + g_free(path); + path = g_strconcat(get_old_rc_dir(), G_DIR_SEPARATOR_S, + COMMON_RC, NULL); + encoding = conv_get_locale_charset_str(); + } +#endif + + prefs_read_config(param, "Common", path, NULL); + g_free(path); prefs_common.online_mode = TRUE; diff --git a/src/prefs_filter.c b/src/prefs_filter.c index 1a160755..28dfcbf6 100644 --- a/src/prefs_filter.c +++ b/src/prefs_filter.c @@ -74,8 +74,6 @@ static GdkBitmap *markxpmmask; static void prefs_filter_create (void); -//static void prefs_filter_read_old_config (void); - static void prefs_filter_set_dialog (void); static void prefs_filter_set_list_row (gint row, FilterRule *rule, @@ -328,13 +326,17 @@ void prefs_filter_read_config(void) rule); } -#warning FIXME_GTK2 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, FILTER_LIST, NULL); if (!is_file_exist(rcpath)) { - //prefs_filter_read_old_config(); + debug_print("reading older version of filter.xml ...\n"); g_free(rcpath); - return; + rcpath = g_strconcat(get_old_rc_dir(), G_DIR_SEPARATOR_S, + FILTER_LIST, NULL); + if (!is_file_exist(rcpath)) { + g_free(rcpath); + return; + } } node = xml_parse_file(rcpath); @@ -350,37 +352,6 @@ void prefs_filter_read_config(void) xml_free_tree(node); } -#if 0 -static void prefs_filter_read_old_config(void) -{ - gchar *rcpath; - FILE *fp; - gchar buf[PREFSBUFSIZE]; - FilterRule *rule; - - debug_print("Reading old filter configuration...\n"); - - rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, FILTER_RC, NULL); - if ((fp = fopen(rcpath, "rb")) == NULL) { - if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen"); - g_free(rcpath); - return; - } - g_free(rcpath); - - while (fgets(buf, sizeof(buf), fp) != NULL) { - g_strchomp(buf); - rule = filter_read_str(buf); - if (rule) { - prefs_common.fltlist = - g_slist_append(prefs_common.fltlist, rule); - } - } - - fclose(fp); -} -#endif - void prefs_filter_write_config(void) { filter_write_config(prefs_common.fltlist); diff --git a/src/utils.c b/src/utils.c index 693f86ea..570f60f3 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1593,6 +1593,17 @@ const gchar *get_rc_dir(void) return rc_dir; } +const gchar *get_old_rc_dir(void) +{ + static gchar *old_rc_dir = NULL; + + if (!old_rc_dir) + old_rc_dir = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, + OLD_RC_DIR, NULL); + + return old_rc_dir; +} + const gchar *get_news_cache_dir(void) { static gchar *news_cache_dir = NULL; diff --git a/src/utils.h b/src/utils.h index b9788181..f21cd06c 100644 --- a/src/utils.h +++ b/src/utils.h @@ -331,6 +331,7 @@ gint scan_mailto_url (const gchar *mailto, /* return static strings */ const gchar *get_home_dir (void); const gchar *get_rc_dir (void); +const gchar *get_old_rc_dir (void); const gchar *get_news_cache_dir (void); const gchar *get_imap_cache_dir (void); const gchar *get_mime_tmp_dir (void); |