diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2013-06-03 07:25:28 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2013-06-03 07:25:28 +0000 |
commit | 1345b496dbb687ef5de04066ddbf4affee4b4cd1 (patch) | |
tree | 80e70d0469243c857b9d5bc0cfe2fcebde31fd32 /src | |
parent | 383459d4f43e54551a329c5c6a91fd2055afcfb7 (diff) |
stabilize the order of templates.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3269 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src')
-rw-r--r-- | src/prefs_template.c | 1 | ||||
-rw-r--r-- | src/template.c | 30 | ||||
-rw-r--r-- | src/template.h | 2 |
3 files changed, 26 insertions, 7 deletions
diff --git a/src/prefs_template.c b/src/prefs_template.c index fb535744..9e9d0c01 100644 --- a/src/prefs_template.c +++ b/src/prefs_template.c @@ -512,6 +512,7 @@ static GSList *prefs_template_get_list(void) while ((tmpl = gtk_clist_get_row_data (GTK_CLIST(templates.clist_tmpls), row)) != NULL) { + tmpl->tmplid = row; tmpl_list = g_slist_append(tmpl_list, tmpl); row++; } diff --git a/src/template.c b/src/template.c index 074c6080..15b30efa 100644 --- a/src/template.c +++ b/src/template.c @@ -32,7 +32,7 @@ static GSList *template_list; -static Template *template_load(gchar *filename) +static Template *template_load(gchar *filename, guint tmplid) { Template *tmpl; FILE *fp; @@ -44,6 +44,7 @@ static Template *template_load(gchar *filename) } tmpl = g_new(Template, 1); + tmpl->tmplid = tmplid; tmpl->name = NULL; tmpl->to = NULL; tmpl->cc = NULL; @@ -108,6 +109,15 @@ void template_clear_config(GSList *tmpl_list) g_slist_free(tmpl_list); } +static gint template_compare_id(gconstpointer a, gconstpointer b) +{ + Template *ta, *tb; + + ta = a; + tb = b; + return (ta->tmplid - tb->tmplid); +} + GSList *template_read_config(void) { const gchar *path; @@ -116,6 +126,7 @@ GSList *template_read_config(void) const gchar *dir_name; struct stat s; Template *tmpl; + guint tmplid; GSList *tmpl_list = NULL; path = get_template_dir(); @@ -133,18 +144,25 @@ GSList *template_read_config(void) } while ((dir_name = g_dir_read_name(dir)) != NULL) { + tmplid = atoi(dir_name); + if (tmplid <= 0) { + continue; + } + filename = g_strconcat(path, G_DIR_SEPARATOR_S, dir_name, NULL); if (g_stat(filename, &s) != 0 || !S_ISREG(s.st_mode) ) { debug_print("%s:%d %s is not an ordinary file\n", __FILE__, __LINE__, filename); + g_free(filename); continue; } - tmpl = template_load(filename); + tmpl = template_load(filename, tmplid); if (tmpl) - tmpl_list = g_slist_append(tmpl_list, tmpl); + tmpl_list = g_slist_insert_sorted(tmpl_list, tmpl, + template_compare_id); g_free(filename); } @@ -160,7 +178,6 @@ void template_write_config(GSList *tmpl_list) GSList *cur; Template *tmpl; FILE *fp; - gint tmpl_num; debug_print("%s:%d writing templates\n", __FILE__, __LINE__); @@ -177,14 +194,13 @@ void template_write_config(GSList *tmpl_list) remove_all_files(path); - for (cur = tmpl_list, tmpl_num = 1; cur != NULL; - cur = cur->next, tmpl_num++) { + for (cur = tmpl_list; cur != NULL; cur = cur->next) { gchar *filename; tmpl = cur->data; filename = g_strconcat(path, G_DIR_SEPARATOR_S, - itos(tmpl_num), NULL); + itos(tmpl->tmplid), NULL); if ((fp = g_fopen(filename, "wb")) == NULL) { FILE_OP_ERROR(filename, "fopen"); diff --git a/src/template.h b/src/template.h index 485e4380..a1a416bc 100644 --- a/src/template.h +++ b/src/template.h @@ -26,6 +26,8 @@ typedef struct _Template Template; struct _Template { + guint tmplid; + gchar *name; gchar *to; gchar *cc; |