folder_item_prefs.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
  3. * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Claws Mail team
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. /* alfons - all folder item specific settings should migrate into
  20. * folderlist.xml!!! the old folderitemrc file will only serve for a few
  21. * versions (for compatibility) */
  22. #ifdef HAVE_CONFIG_H
  23. # include "config.h"
  24. #endif
  25. #include <glib.h>
  26. #include <glib/gi18n.h>
  27. #include "defs.h"
  28. #include "folder.h"
  29. #include "utils.h"
  30. #include "prefs_gtk.h"
  31. #include "filtering.h"
  32. #include "folder_item_prefs.h"
  33. FolderItemPrefs tmp_prefs;
  34. static PrefParam param[] = {
  35. {"sort_by_number", "FALSE", &tmp_prefs.sort_by_number, P_BOOL,
  36. NULL, NULL, NULL},
  37. {"sort_by_size", "FALSE", &tmp_prefs.sort_by_size, P_BOOL,
  38. NULL, NULL, NULL},
  39. {"sort_by_date", "FALSE", &tmp_prefs.sort_by_date, P_BOOL,
  40. NULL, NULL, NULL},
  41. {"sort_by_from", "FALSE", &tmp_prefs.sort_by_from, P_BOOL,
  42. NULL, NULL, NULL},
  43. {"sort_by_subject", "FALSE", &tmp_prefs.sort_by_subject, P_BOOL,
  44. NULL, NULL, NULL},
  45. {"sort_by_score", "FALSE", &tmp_prefs.sort_by_score, P_BOOL,
  46. NULL, NULL, NULL},
  47. {"sort_descending", "FALSE", &tmp_prefs.sort_descending, P_BOOL,
  48. NULL, NULL, NULL},
  49. /* MIGRATION */
  50. {"request_return_receipt", "", &tmp_prefs.request_return_receipt, P_BOOL,
  51. NULL, NULL, NULL},
  52. {"enable_default_to", "", &tmp_prefs.enable_default_to, P_BOOL,
  53. NULL, NULL, NULL},
  54. {"default_to", "", &tmp_prefs.default_to, P_STRING,
  55. NULL, NULL, NULL},
  56. {"enable_default_reply_to", "", &tmp_prefs.enable_default_reply_to, P_BOOL,
  57. NULL, NULL, NULL},
  58. {"default_reply_to", "", &tmp_prefs.default_reply_to, P_STRING,
  59. NULL, NULL, NULL},
  60. {"enable_simplify_subject", "", &tmp_prefs.enable_simplify_subject, P_BOOL,
  61. NULL, NULL, NULL},
  62. {"simplify_subject_regexp", "", &tmp_prefs.simplify_subject_regexp, P_STRING,
  63. NULL, NULL, NULL},
  64. {"enable_folder_chmod", "", &tmp_prefs.enable_folder_chmod, P_BOOL,
  65. NULL, NULL, NULL},
  66. {"folder_chmod", "", &tmp_prefs.folder_chmod, P_INT,
  67. NULL, NULL, NULL},
  68. {"enable_default_account", "", &tmp_prefs.enable_default_account, P_BOOL,
  69. NULL, NULL, NULL},
  70. {"default_account", NULL, &tmp_prefs.default_account, P_INT,
  71. NULL, NULL, NULL},
  72. #if USE_ASPELL
  73. {"enable_default_dictionary", "", &tmp_prefs.enable_default_dictionary, P_BOOL,
  74. NULL, NULL, NULL},
  75. {"default_dictionary", NULL, &tmp_prefs.default_dictionary, P_STRING,
  76. NULL, NULL, NULL},
  77. #endif
  78. {"save_copy_to_folder", NULL, &tmp_prefs.save_copy_to_folder, P_BOOL,
  79. NULL, NULL, NULL},
  80. {"folder_color", "", &tmp_prefs.color, P_INT,
  81. NULL, NULL, NULL},
  82. {"enable_processing", "FALSE", &tmp_prefs.enable_processing, P_BOOL,
  83. NULL, NULL, NULL},
  84. {"newmailcheck", "TRUE", &tmp_prefs.newmailcheck, P_BOOL,
  85. NULL, NULL, NULL},
  86. {"offlinesync", "FALSE", &tmp_prefs.offlinesync, P_BOOL,
  87. NULL, NULL, NULL},
  88. {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
  89. };
  90. static FolderItemPrefs *folder_item_prefs_clear(FolderItemPrefs *prefs);
  91. void folder_item_prefs_read_config(FolderItem * item)
  92. {
  93. gchar * id;
  94. gchar *rcpath;
  95. id = folder_item_get_identifier(item);
  96. folder_item_prefs_clear(&tmp_prefs);
  97. rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, FOLDERITEM_RC, NULL);
  98. prefs_read_config(param, id, rcpath, NULL);
  99. g_free(id);
  100. g_free(rcpath);
  101. *item->prefs = tmp_prefs;
  102. /*
  103. * MIGRATION: next lines are migration code. the idea is that
  104. * if used regularly, claws folder config ends up
  105. * in the same file as sylpheed-main
  106. */
  107. item->ret_rcpt = tmp_prefs.request_return_receipt ? TRUE : FALSE;
  108. /* MIGRATION: 0.7.8main+ has persistent sort order. claws had the sort
  109. * order in different members, which is ofcourse a little
  110. * bit phoney. */
  111. if (item->sort_key == SORT_BY_NONE) {
  112. item->sort_key = (tmp_prefs.sort_by_number ? SORT_BY_NUMBER :
  113. tmp_prefs.sort_by_size ? SORT_BY_SIZE :
  114. tmp_prefs.sort_by_date ? SORT_BY_DATE :
  115. tmp_prefs.sort_by_from ? SORT_BY_FROM :
  116. tmp_prefs.sort_by_subject ? SORT_BY_SUBJECT :
  117. tmp_prefs.sort_by_score ? SORT_BY_SCORE :
  118. SORT_BY_NONE);
  119. item->sort_type = tmp_prefs.sort_descending ? SORT_DESCENDING : SORT_ASCENDING;
  120. }
  121. }
  122. void folder_item_prefs_save_config(FolderItem * item)
  123. {
  124. gchar * id;
  125. tmp_prefs = * item->prefs;
  126. id = folder_item_get_identifier(item);
  127. prefs_write_config(param, id, FOLDERITEM_RC);
  128. g_free(id);
  129. /* MIGRATION: make sure migrated items are not saved
  130. */
  131. }
  132. void folder_item_prefs_set_config(FolderItem * item,
  133. int sort_type, gint sort_mode)
  134. {
  135. g_assert(item);
  136. g_warning("folder_item_prefs_set_config() should never be called\n");
  137. item->sort_key = sort_type;
  138. item->sort_type = sort_mode;
  139. }
  140. static FolderItemPrefs *folder_item_prefs_clear(FolderItemPrefs *prefs)
  141. {
  142. prefs->sort_by_number = FALSE;
  143. prefs->sort_by_size = FALSE;
  144. prefs->sort_by_date = FALSE;
  145. prefs->sort_by_from = FALSE;
  146. prefs->sort_by_subject = FALSE;
  147. prefs->sort_by_score = FALSE;
  148. prefs->sort_descending = FALSE;
  149. prefs->request_return_receipt = FALSE;
  150. prefs->enable_default_to = FALSE;
  151. prefs->default_to = NULL;
  152. prefs->enable_default_reply_to = FALSE;
  153. prefs->default_reply_to = NULL;
  154. prefs->enable_simplify_subject = FALSE;
  155. prefs->simplify_subject_regexp = NULL;
  156. prefs->enable_folder_chmod = FALSE;
  157. prefs->folder_chmod = 0;
  158. prefs->enable_default_account = FALSE;
  159. prefs->default_account = 0;
  160. #if USE_ASPELL
  161. prefs->enable_default_dictionary = FALSE;
  162. prefs->default_dictionary = NULL;
  163. #endif
  164. prefs->save_copy_to_folder = FALSE;
  165. prefs->color = 0;
  166. prefs->enable_processing = TRUE;
  167. prefs->processing = NULL;
  168. prefs->newmailcheck = TRUE;
  169. prefs->offlinesync = FALSE;
  170. return prefs;
  171. }
  172. FolderItemPrefs * folder_item_prefs_new(void)
  173. {
  174. FolderItemPrefs * prefs;
  175. prefs = g_new0(FolderItemPrefs, 1);
  176. return folder_item_prefs_clear(prefs);
  177. }
  178. void folder_item_prefs_free(FolderItemPrefs * prefs)
  179. {
  180. g_free(prefs->default_to);
  181. g_free(prefs->default_reply_to);
  182. g_free(prefs);
  183. }
  184. gint folder_item_prefs_get_sort_mode(FolderItem * item)
  185. {
  186. g_assert(item != NULL);
  187. g_warning("folder_item_prefs_get_sort_mode() should never be called\n");
  188. return item->sort_key;
  189. }
  190. gint folder_item_prefs_get_sort_type(FolderItem * item)
  191. {
  192. g_assert(item != NULL);
  193. g_warning("folder_item_prefs_get_sort_type() should never be called\n");
  194. return item->sort_type;
  195. }
  196. #define SAFE_STRING(str) \
  197. (str) ? (str) : ""
  198. void folder_item_prefs_copy_prefs(FolderItem * src, FolderItem * dest)
  199. {
  200. GSList *tmp_prop_list = NULL, *tmp;
  201. folder_item_prefs_read_config(src);
  202. tmp_prefs.directory = g_strdup(src->prefs->directory);
  203. tmp_prefs.sort_by_number = src->prefs->sort_by_number;
  204. tmp_prefs.sort_by_size = src->prefs->sort_by_size;
  205. tmp_prefs.sort_by_date = src->prefs->sort_by_date;
  206. tmp_prefs.sort_by_from = src->prefs->sort_by_from;
  207. tmp_prefs.sort_by_subject = src->prefs->sort_by_subject;
  208. tmp_prefs.sort_by_score = src->prefs->sort_by_score;
  209. tmp_prefs.sort_descending = src->prefs->sort_descending;
  210. tmp_prefs.enable_thread = src->prefs->enable_thread;
  211. tmp_prefs.enable_processing = src->prefs->enable_processing;
  212. tmp_prefs.newmailcheck = src->prefs->newmailcheck;
  213. tmp_prefs.offlinesync = src->prefs->offlinesync;
  214. prefs_matcher_read_config();
  215. for (tmp = src->prefs->processing; tmp != NULL && tmp->data != NULL;) {
  216. FilteringProp *prop = (FilteringProp *)tmp->data;
  217. tmp_prop_list = g_slist_append(tmp_prop_list,
  218. filteringprop_copy(prop));
  219. tmp = tmp->next;
  220. }
  221. tmp_prefs.processing = tmp_prop_list;
  222. tmp_prefs.request_return_receipt = src->prefs->request_return_receipt;
  223. tmp_prefs.enable_default_to = src->prefs->enable_default_to;
  224. tmp_prefs.default_to = g_strdup(src->prefs->default_to);
  225. tmp_prefs.enable_default_reply_to = src->prefs->enable_default_reply_to;
  226. tmp_prefs.default_reply_to = g_strdup(src->prefs->default_reply_to);
  227. tmp_prefs.enable_simplify_subject = src->prefs->enable_simplify_subject;
  228. tmp_prefs.simplify_subject_regexp = g_strdup(src->prefs->simplify_subject_regexp);
  229. tmp_prefs.enable_folder_chmod = src->prefs->enable_folder_chmod;
  230. tmp_prefs.folder_chmod = src->prefs->folder_chmod;
  231. tmp_prefs.enable_default_account = src->prefs->enable_default_account;
  232. tmp_prefs.default_account = src->prefs->default_account;
  233. #if USE_ASPELL
  234. tmp_prefs.enable_default_dictionary = src->prefs->enable_default_dictionary;
  235. tmp_prefs.default_dictionary = g_strdup(src->prefs->default_dictionary);
  236. #endif
  237. tmp_prefs.save_copy_to_folder = src->prefs->save_copy_to_folder;
  238. tmp_prefs.color = src->prefs->color;
  239. *dest->prefs = tmp_prefs;
  240. folder_item_prefs_save_config(dest);
  241. }