new filtering action : forward - some fixes
[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         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
27 };
28
29 void prefs_folder_item_read_config(FolderItem * item)
30 {
31         gchar * path;
32
33         path = folder_item_get_path(item);
34         if (!is_dir_exist(path))
35                 make_dir_hier(path);
36
37         prefs_read_config(param, path, FOLDERITEM_RC);
38         g_free(path);
39
40         * item->prefs = tmp_prefs;
41 }
42
43 void prefs_folder_item_save_config(FolderItem * item)
44 {       
45         gchar * path;
46
47         tmp_prefs = * item->prefs;
48
49         path = folder_item_get_path(item);
50         if (!is_dir_exist(path))
51                 make_dir_hier(path);
52
53         prefs_save_config(param, path, FOLDERITEM_RC);
54         g_free(path);
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
108         * prefs = tmp_prefs;
109         
110         return prefs;
111 }
112
113 void prefs_folder_item_free(PrefsFolderItem * prefs)
114 {
115         g_free(prefs);
116 }
117
118 gint prefs_folder_item_get_sort_mode(FolderItem * item)
119 {
120         tmp_prefs = * item->prefs;
121
122         if (tmp_prefs.sort_by_number)
123                 return SORT_BY_NUMBER;
124         if (tmp_prefs.sort_by_size)
125                 return SORT_BY_SIZE;
126         if (tmp_prefs.sort_by_date)
127                 return SORT_BY_DATE;
128         if (tmp_prefs.sort_by_from)
129                 return SORT_BY_FROM;
130         if (tmp_prefs.sort_by_subject)
131                 return SORT_BY_SUBJECT;
132         if (tmp_prefs.sort_by_score)
133                 return SORT_BY_SCORE;
134         return SORT_BY_NONE;
135 }
136
137 gint prefs_folder_item_get_sort_type(FolderItem * item)
138 {
139         tmp_prefs = * item->prefs;
140
141         if (tmp_prefs.sort_descending)
142                 return GTK_SORT_DESCENDING;
143         else
144                 return GTK_SORT_ASCENDING;
145 }