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