2007-11-27 [wwp] 3.1.0cvs37
[claws.git] / src / prefs_common.c
index 2122a75aedc30c0ab51e45f7d8801d540bd83368..9f586eeab90159eb5fa6e426326e6279ad11fa74 100644 (file)
@@ -59,6 +59,7 @@
 #include "stock_pixmap.h"
 #include "prefswindow.h"
 #include "colorlabel.h"
+#include "addrcustomattr.h"
 
 enum {
        DATEFMT_FMT,
@@ -187,7 +188,7 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"confirm_send_queued_messages", "FALSE", &prefs_common.confirm_send_queued_messages,
         P_BOOL, NULL, NULL, NULL},
-       {"send_dialog_mode", "0", &prefs_common.send_dialog_mode, P_BOOL,
+       {"send_dialog_mode", "0", &prefs_common.send_dialog_invisible, P_BOOL,
         NULL, NULL, NULL},
        {"sendwin_width", "460", &prefs_common.sendwin_width, P_INT,
         NULL, NULL, NULL},
@@ -738,7 +739,10 @@ static PrefParam param[] = {
         P_BOOL, NULL, NULL, NULL},
        {"select_on_entry", "3", &prefs_common.select_on_entry,
         P_ENUM, NULL, NULL, NULL},
+       {"show_tooltips", "TRUE", &prefs_common.show_tooltips,
+        P_BOOL, NULL, NULL, NULL},
 
+       /* do it SUMMARY_OPEN_ACTIONS-1 times */
        {"summary_select_prio1", "0", &prefs_common.summary_select_prio[0], P_ENUM,
         NULL, NULL, NULL},
        {"summary_select_prio2", "0", &prefs_common.summary_select_prio[1], P_ENUM,
@@ -751,6 +755,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"summary_select_prio6", "0", &prefs_common.summary_select_prio[5], P_ENUM,
         NULL, NULL, NULL},
+       {"summary_select_prio7", "0", &prefs_common.summary_select_prio[6], P_ENUM,
+        NULL, NULL, NULL},
 
        {"mark_as_read_on_new_window", "FALSE",
         &prefs_common.mark_as_read_on_new_window,
@@ -790,6 +796,8 @@ static PrefParam param[] = {
         &SPECIFIC_PREFS.print_cmd, P_STRING, NULL, NULL, NULL},
        {"ext_editor_command", DEFAULT_EDITOR_CMD,
         &SPECIFIC_PREFS.ext_editor_cmd, P_STRING, NULL, NULL, NULL},
+       {"cmds_use_system_default", "FALSE",
+        &prefs_common.cmds_use_system_default, P_BOOL, NULL, NULL, NULL},
        {"add_address_by_click", "FALSE", &prefs_common.add_address_by_click,
         P_BOOL, NULL, NULL, NULL},
        {"confirm_on_exit", "FALSE", &prefs_common.confirm_on_exit, P_BOOL,
@@ -1040,6 +1048,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"live_dangerously", "FALSE", &prefs_common.live_dangerously, P_BOOL,
         NULL, NULL, NULL},
+       {"save_parts_readwrite", "FALSE", &prefs_common.save_parts_readwrite, P_BOOL,
+        NULL, NULL, NULL},
        {"hide_quotes", "0", &prefs_common.hide_quotes, P_INT,
         NULL, NULL, NULL},
        {"unsafe_ssl_certs", "FALSE", &prefs_common.unsafe_ssl_certs, P_BOOL,
@@ -1051,30 +1061,54 @@ static PrefParam param[] = {
        {"real_time_sync", "TRUE", &prefs_common.real_time_sync, P_BOOL,
         NULL, NULL, NULL},
 #endif
+
+       {"print_paper_type", NULL, &prefs_common.print_paper_type, P_STRING,
+        NULL, NULL, NULL},
+       {"print_paper_orientation", "0", &prefs_common.print_paper_orientation, P_INT,
+        NULL, NULL, NULL},
+       {"print_use_color", "0", &prefs_common.print_use_color, P_INT,
+        NULL, NULL, NULL},
+       {"print_use_collate", "0", &prefs_common.print_use_collate, P_INT,
+        NULL, NULL, NULL},
+       {"print_use_reverse", "0", &prefs_common.print_use_reverse, P_INT,
+        NULL, NULL, NULL},
+       {"print_use_duplex", "0", &prefs_common.print_use_duplex, P_INT,
+        NULL, NULL, NULL},
+       {"print_imgs", "1", &prefs_common.print_imgs, P_INT,
+        NULL, NULL, NULL},
+       {"print_previewwin_width", "600", &prefs_common.print_previewwin_width, P_INT,
+        NULL, NULL, NULL},
+       {"print_previewwin_height", "-1", &prefs_common.print_previewwin_height, P_INT,
+        NULL, NULL, NULL},
+
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
-PrefsCommon *prefs_common_get(void)
-{
-       return &prefs_common;
-}
-
 /*
- * Read history list from the specified history file
+ * Read history list from the specified history file in the specified directory (subdir of rc_dir)
+ * Fallback to default_list if history file is not found
  */
-static GList *prefs_common_read_history(const gchar *history) 
+GList *prefs_common_read_history_from_dir_with_defaults(const gchar *dirname, const gchar *history,
+                                                                                                                         GList *default_list)
 {
        FILE *fp;
        gchar *path;
        gchar buf[PREFSBUFSIZE];
        GList *tmp = NULL;
 
+       if (dirname) {
+               path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, dirname,
+                                  G_DIR_SEPARATOR_S, history,
+                                  NULL);
+       } else {
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
                           NULL);
+       }
        if ((fp = g_fopen(path, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                g_free(path);
-               return NULL;
+               /* returns default list if set, otherwise NULL */
+               return default_list;
        }
        g_free(path);
        while (fgets(buf, sizeof(buf), fp) != NULL) {
@@ -1089,6 +1123,22 @@ static GList *prefs_common_read_history(const gchar *history)
        return tmp;
 }
 
+/*
+ * Read history list from the specified history file in the specified directory (subdir of rc_dir)
+ */
+static GList *prefs_common_read_history_from_dir(const gchar *dirname, const gchar *history) 
+{
+       return prefs_common_read_history_from_dir_with_defaults(dirname, history, NULL);
+}
+
+/*
+ * Read history list from the specified history file
+ */
+static GList *prefs_common_read_history(const gchar *history) 
+{
+       return prefs_common_read_history_from_dir(NULL, history);
+}
+
 void prefs_common_read_config(void)
 {
        gchar *rcpath;
@@ -1135,6 +1185,8 @@ void prefs_common_read_config(void)
        prefs_common.message_search_history =
                prefs_common_read_history(MESSAGE_SEARCH_HISTORY);
 
+       prefs_common.addressbook_custom_attributes = addressbook_update_custom_attr_from_prefs();
+
        colorlabel_update_colortable_from_prefs();
 }
 
@@ -1146,16 +1198,22 @@ if (!(func)) \
 } \
 
 /*
- * Save history list to the specified history file
+ * Save history list to the specified history file in the specified directory (subdir of rc_dir)
  */
-static void prefs_common_save_history(const gchar *history, GList *list)
+static void prefs_common_save_history_to_dir(const gchar *dirname, const gchar *history, GList *list)
 {
        GList *cur;
        FILE *fp;
        gchar *path, *tmp_path;
 
+       if (dirname) {
+               path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, dirname,
+                                  G_DIR_SEPARATOR_S, history,
+                                  NULL);
+       } else {
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
                           NULL);
+       }
        tmp_path = g_strconcat(path, ".tmp", NULL);
 
        if ((fp = g_fopen(tmp_path, "wb")) == NULL) {
@@ -1189,6 +1247,14 @@ out:
        g_free(path);
 }
 
+/*
+ * Save history list to the specified history file
+ */
+static void prefs_common_save_history(const gchar *history, GList *list)
+{
+       prefs_common_save_history_to_dir(NULL, history, list);
+}
+
 #undef TRY
 
 void prefs_common_write_config(void)
@@ -1214,6 +1280,10 @@ void prefs_common_write_config(void)
                prefs_common.summary_search_adv_condition_history);
        prefs_common_save_history(MESSAGE_SEARCH_HISTORY, 
                prefs_common.message_search_history);
+
+       prefs_common_save_history_to_dir(ADDRBOOK_DIR,
+               ADDRESSBOOK_CUSTOM_ATTRIBUTES, 
+               prefs_common.addressbook_custom_attributes);
 }
 
 /* make a copy of string 'in' into buffer 'out'. un-escape \ sequences.
@@ -1417,3 +1487,37 @@ const gchar *prefs_common_translated_header_name(const gchar *header_name)
 
        return prefs_common.trans_hdr ? gettext(header_name) : header_name;
 }
+
+const gchar *prefs_common_get_uri_cmd(void)
+{
+       gchar *tmp = NULL;
+       
+       if (!prefs_common.cmds_use_system_default)
+               return prefs_common.uri_cmd;
+       
+       tmp = g_find_program_in_path("xdg-open");
+       if (!tmp) 
+               return prefs_common.uri_cmd;
+       
+       g_free(tmp);
+       return "xdg-open %s";
+}
+
+const gchar *prefs_common_get_ext_editor_cmd(void)
+{
+       return prefs_common.ext_editor_cmd;
+#if 0 /* we should do that, but it detaches the editor and breaks
+        compose.c's external composition. */
+       gchar *tmp = NULL;
+       
+       if (!prefs_common.cmds_use_system_default)
+               return prefs_common.ext_editor_cmd;
+       
+       tmp = g_find_program_in_path("xdg-open");
+       if (!tmp) 
+               return prefs_common.ext_editor_cmd;
+       
+       g_free(tmp);
+       return "xdg-open %s";
+#endif 
+}