kill score / folder scoring / buf fixed for local account prefs
[claws.git] / src / prefs_folder_item.c
1 #include "defs.h"
2 #include "folder.h"
3 #include "prefs_folder_item.h"
4 #include "summaryview.h"
5 #include "prefs.h"
6
7 PrefsFolderItem tmp_prefs;
8
9 static PrefParam param[] = {
10         {"sort_by_number", "FALSE", &tmp_prefs.sort_by_number, P_BOOL,
11          NULL, NULL, NULL},
12         {"sort_by_size", "FALSE", &tmp_prefs.sort_by_size, P_BOOL,
13          NULL, NULL, NULL},
14         {"sort_by_date", "FALSE", &tmp_prefs.sort_by_date, P_BOOL,
15          NULL, NULL, NULL},
16         {"sort_by_from", "FALSE", &tmp_prefs.sort_by_from, P_BOOL,
17          NULL, NULL, NULL},
18         {"sort_by_subject", "FALSE", &tmp_prefs.sort_by_subject, P_BOOL,
19          NULL, NULL, NULL},
20         {"sort_by_score", "FALSE", &tmp_prefs.sort_by_score, P_BOOL,
21          NULL, NULL, NULL},
22         {"sort_descending", "FALSE", &tmp_prefs.sort_descending, P_BOOL,
23          NULL, NULL, NULL},
24         {"enable_thread", "TRUE", &tmp_prefs.enable_thread, P_BOOL,
25          NULL, NULL, NULL},
26         {"kill_score", "-9999", &tmp_prefs.kill_score, P_INT,
27          NULL, NULL, NULL},
28         {"important_score", "9999", &tmp_prefs.important_score, P_INT,
29          NULL, NULL, NULL},
30         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
31 };
32
33 void prefs_folder_item_read_config(FolderItem * item)
34 {
35         gchar * id;
36
37         id = folder_item_get_identifier(item);
38
39         prefs_read_config(param, id, FOLDERITEM_RC);
40         g_free(id);
41
42         * item->prefs = tmp_prefs;
43 }
44
45 void prefs_folder_item_save_config(FolderItem * item)
46 {       
47         gchar * id;
48
49         tmp_prefs = * item->prefs;
50
51         id = folder_item_get_identifier(item);
52
53         prefs_save_config(param, id, FOLDERITEM_RC);
54         g_free(id);
55 }
56
57 void prefs_folder_item_set_config(FolderItem * item,
58                                   int sort_type, gint sort_mode)
59 {
60         tmp_prefs = * item->prefs;
61
62         tmp_prefs.sort_by_number = FALSE;
63         tmp_prefs.sort_by_size = FALSE;
64         tmp_prefs.sort_by_date = FALSE;
65         tmp_prefs.sort_by_from = FALSE;
66         tmp_prefs.sort_by_subject = FALSE;
67         tmp_prefs.sort_by_score = FALSE;
68
69         switch (sort_mode) {
70         case SORT_BY_NUMBER:
71                 tmp_prefs.sort_by_number = TRUE;
72                 break;
73         case SORT_BY_SIZE:
74                 tmp_prefs.sort_by_size = TRUE;
75                 break;
76         case SORT_BY_DATE:
77                 tmp_prefs.sort_by_date = TRUE;
78                 break;
79         case SORT_BY_FROM:
80                 tmp_prefs.sort_by_from = TRUE;
81                 break;
82         case SORT_BY_SUBJECT:
83                 tmp_prefs.sort_by_subject = TRUE;
84                 break;
85         case SORT_BY_SCORE:
86                 tmp_prefs.sort_by_score = TRUE;
87                 break;
88         }
89         tmp_prefs.sort_descending = (sort_type == GTK_SORT_DESCENDING);
90
91         * item->prefs = tmp_prefs;
92 }
93
94 PrefsFolderItem * prefs_folder_item_new(void)
95 {
96         PrefsFolderItem * prefs;
97
98         prefs = g_new0(PrefsFolderItem, 1);
99
100         tmp_prefs.sort_by_number = FALSE;
101         tmp_prefs.sort_by_size = FALSE;
102         tmp_prefs.sort_by_date = FALSE;
103         tmp_prefs.sort_by_from = FALSE;
104         tmp_prefs.sort_by_subject = FALSE;
105         tmp_prefs.sort_by_score = FALSE;
106         tmp_prefs.sort_descending = FALSE;
107         tmp_prefs.kill_score = -9999;
108         tmp_prefs.important_score = 9999;
109
110         * prefs = tmp_prefs;
111         
112         return prefs;
113 }
114
115 void prefs_folder_item_free(PrefsFolderItem * prefs)
116 {
117         if (prefs->scoring != NULL)
118                 prefs_scoring_free(prefs->scoring);
119         g_free(prefs);
120 }
121
122 gint prefs_folder_item_get_sort_mode(FolderItem * item)
123 {
124         tmp_prefs = * item->prefs;
125
126         if (tmp_prefs.sort_by_number)
127                 return SORT_BY_NUMBER;
128         if (tmp_prefs.sort_by_size)
129                 return SORT_BY_SIZE;
130         if (tmp_prefs.sort_by_date)
131                 return SORT_BY_DATE;
132         if (tmp_prefs.sort_by_from)
133                 return SORT_BY_FROM;
134         if (tmp_prefs.sort_by_subject)
135                 return SORT_BY_SUBJECT;
136         if (tmp_prefs.sort_by_score)
137                 return SORT_BY_SCORE;
138         return SORT_BY_NONE;
139 }
140
141 gint prefs_folder_item_get_sort_type(FolderItem * item)
142 {
143         tmp_prefs = * item->prefs;
144
145         if (tmp_prefs.sort_descending)
146                 return GTK_SORT_DESCENDING;
147         else
148                 return GTK_SORT_ASCENDING;
149 }