From 1345b496dbb687ef5de04066ddbf4affee4b4cd1 Mon Sep 17 00:00:00 2001 From: hiro Date: Mon, 3 Jun 2013 07:25:28 +0000 Subject: stabilize the order of templates. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3269 ee746299-78ed-0310-b773-934348b2243d --- ChangeLog | 5 +++++ src/prefs_template.c | 1 + src/template.c | 30 +++++++++++++++++++++++------- src/template.h | 2 ++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22aaf11d..c420184f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-06-03 + + * src/prefs_template.c + src/template.[ch]: stabilize the order of templates. + 2013-05-24 * version 3.4.0beta4 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; -- cgit v1.2.3