scoring / expression matcher
[claws.git] / src / prefs_folder_item.c
1 #include "folder.h"
2 #include "prefs_folder_item.h"
3 #include "summaryview.h"
4 #include "prefs.h"
5 #include "defs.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         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
25 };
26
27 void prefs_folder_item_read_config(FolderItem * item)
28 {
29         gchar * path;
30
31         path = folder_item_get_path(item);
32         prefs_read_config(param, path, FOLDERITEM_RC);
33         g_free(path);
34
35         * item->prefs = tmp_prefs;
36 }
37
38 void prefs_folder_item_save_config(FolderItem * item)
39 {       
40         gchar * path;
41
42         tmp_prefs = * item->prefs;
43
44         path = folder_item_get_path(item);
45         prefs_save_config(param, path, FOLDERITEM_RC);
46         g_free(path);
47 }
48
49 void prefs_folder_item_set_config(FolderItem * item,
50                                   int sort_type, gint sort_mode)
51 {
52         tmp_prefs = * item->prefs;
53
54         tmp_prefs.sort_by_number = FALSE;
55         tmp_prefs.sort_by_size = FALSE;
56         tmp_prefs.sort_by_date = FALSE;
57         tmp_prefs.sort_by_from = FALSE;
58         tmp_prefs.sort_by_subject = FALSE;
59         tmp_prefs.sort_by_score = FALSE;
60
61         switch (sort_mode) {
62         case SORT_BY_NUMBER:
63                 tmp_prefs.sort_by_number = TRUE;
64                 break;
65         case SORT_BY_SIZE:
66                 tmp_prefs.sort_by_size = TRUE;
67                 break;
68         case SORT_BY_DATE:
69                 tmp_prefs.sort_by_date = TRUE;
70                 break;
71         case SORT_BY_FROM:
72                 tmp_prefs.sort_by_from = TRUE;
73                 break;
74         case SORT_BY_SUBJECT:
75                 tmp_prefs.sort_by_subject = TRUE;
76                 break;
77         case SORT_BY_SCORE:
78                 tmp_prefs.sort_by_score = TRUE;
79                 break;
80         }
81         tmp_prefs.sort_descending = (sort_type == GTK_SORT_DESCENDING);
82
83         * item->prefs = tmp_prefs;
84 }
85
86 PrefsFolderItem * prefs_folder_item_new(void)
87 {
88         PrefsFolderItem * prefs;
89
90         prefs = g_new0(PrefsFolderItem, 1);
91
92         tmp_prefs.sort_by_number = FALSE;
93         tmp_prefs.sort_by_size = FALSE;
94         tmp_prefs.sort_by_date = FALSE;
95         tmp_prefs.sort_by_from = FALSE;
96         tmp_prefs.sort_by_subject = FALSE;
97         tmp_prefs.sort_by_score = FALSE;
98         tmp_prefs.sort_descending = FALSE;
99
100         * prefs = tmp_prefs;
101         
102         return prefs;
103 }
104
105 void prefs_folder_item_free(PrefsFolderItem * prefs)
106 {
107         g_free(prefs);
108 }
109
110 gint prefs_folder_item_get_sort_mode(FolderItem * item)
111 {
112         tmp_prefs = * item->prefs;
113
114         if (tmp_prefs.sort_by_number)
115                 return SORT_BY_NUMBER;
116         if (tmp_prefs.sort_by_size)
117                 return SORT_BY_SIZE;
118         if (tmp_prefs.sort_by_date)
119                 return SORT_BY_DATE;
120         if (tmp_prefs.sort_by_from)
121                 return SORT_BY_FROM;
122         if (tmp_prefs.sort_by_subject)
123                 return SORT_BY_SUBJECT;
124         if (tmp_prefs.sort_by_score)
125                 return SORT_BY_SCORE;
126         return SORT_BY_NONE;
127 }
128
129 gint prefs_folder_item_get_sort_type(FolderItem * item)
130 {
131         tmp_prefs = * item->prefs;
132
133         if (tmp_prefs.sort_descending)
134                 return GTK_SORT_DESCENDING;
135         else
136                 return GTK_SORT_ASCENDING;
137 }