2008-02-18 [colin] 3.3.0cvs16
[claws.git] / src / prefs_common.c
index 94b3fa1481bf7ea95b55626eecb7dea83e75519b..70749b77e1da27da2722ce799e07a839dbf22e74 100644 (file)
@@ -59,6 +59,7 @@
 #include "stock_pixmap.h"
 #include "prefswindow.h"
 #include "colorlabel.h"
+#include "addrcustomattr.h"
 
 enum {
        DATEFMT_FMT,
@@ -101,6 +102,8 @@ static PrefParam param_os_specific[] = {
          &prefs_common.smallfont,              P_STRING, NULL, NULL, NULL},
        {"normal_font_gtk2",    "Sans 9",
          &prefs_common.normalfont,             P_STRING, NULL, NULL, NULL},
+       {"bold_font_gtk2",      "Sans 9 Bold",
+         &prefs_common.boldfont,               P_STRING, NULL, NULL, NULL},
        /* Message */
        {"attach_save_directory", NULL,
         &prefs_common.attach_save_dir, P_STRING, NULL, NULL, NULL},
@@ -139,6 +142,10 @@ static PrefParam param_os_specific[] = {
  */
 
 static PrefParam param[] = {
+#ifdef MAEMO
+       {"data_root", "", &prefs_common.data_root, P_STRING,
+        NULL, NULL, NULL},
+#endif
        /* Receive */
        {"use_ext_inc", "FALSE", &prefs_common.use_extinc, P_BOOL,
         NULL, NULL, NULL},
@@ -161,6 +168,14 @@ static PrefParam param[] = {
        P_BOOL, NULL, NULL, NULL},
        {"newmail_notify_cmd", "", &SPECIFIC_PREFS.newmail_notify_cmd, P_STRING,
         NULL, NULL, NULL},
+#ifdef MAEMO
+       {"maemo_show_led", "TRUE", &prefs_common.maemo_show_led, P_BOOL,
+        NULL, NULL, NULL},
+       {"maemo_play_sound", "FALSE", &prefs_common.maemo_play_sound, P_BOOL,
+        NULL, NULL, NULL},
+       {"maemo_show_banner", "FALSE", &prefs_common.maemo_show_banner, P_BOOL,
+        NULL, NULL, NULL},
+#endif
        {"receive_dialog_mode", "2", &prefs_common.recv_dialog_mode, P_ENUM,
         NULL, NULL, NULL},
        {"receivewin_width", "460", &prefs_common.receivewin_width, P_INT,
@@ -177,8 +192,13 @@ 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", "1", &prefs_common.send_dialog_mode, P_ENUM,
+#ifndef MAEMO
+       {"send_dialog_mode", "0", &prefs_common.send_dialog_invisible, P_BOOL,
+        NULL, NULL, NULL},
+#else
+       {"send_dialog_mode", "1", &prefs_common.send_dialog_invisible, P_BOOL,
         NULL, NULL, NULL},
+#endif
        {"sendwin_width", "460", &prefs_common.sendwin_width, P_INT,
         NULL, NULL, NULL},
        {"sendwin_height", "-1", &prefs_common.sendwin_height, P_INT,
@@ -311,6 +331,8 @@ static PrefParam param[] = {
          &SPECIFIC_PREFS.smallfont,            P_STRING, NULL, NULL, NULL},
        {"normal_font_gtk2",    "Sans 9",
          &SPECIFIC_PREFS.normalfont,           P_STRING, NULL, NULL, NULL},
+       {"bold_font_gtk2",      "Sans Bold 9",
+         &SPECIFIC_PREFS.boldfont,             P_STRING, NULL, NULL, NULL},
 #else
        {"widget_font_gtk2",    NULL,
          &SPECIFIC_PREFS.widgetfont,           P_STRING, NULL, NULL, NULL},
@@ -322,7 +344,15 @@ static PrefParam param[] = {
          &SPECIFIC_PREFS.smallfont,            P_STRING, NULL, NULL, NULL},
        {"normal_font_gtk2",    "Sans 8",
          &SPECIFIC_PREFS.normalfont,           P_STRING, NULL, NULL, NULL},
+       {"bold_font_gtk2",      "Sans Bold 8",
+         &SPECIFIC_PREFS.boldfont,             P_STRING, NULL, NULL, NULL},
 #endif
+
+       {"use_different_print_font", "FALSE", &prefs_common.use_different_print_font, P_BOOL,
+        NULL, NULL, NULL},
+       {"derive_from_normal_font", "TRUE", &prefs_common.derive_from_normal_font, P_BOOL,
+        NULL, NULL, NULL},
+
        /* custom colors */
        {"custom_color1", "#ff9900", &prefs_common.custom_colorlabel[0].color, P_COLOR,
         NULL, NULL, NULL},
@@ -425,6 +455,8 @@ static PrefParam param[] = {
 #endif
        {"toolbar_detachable", "FALSE", &prefs_common.toolbar_detachable, P_BOOL,
         NULL, NULL, NULL},
+       {"show_col_headers", "TRUE", &prefs_common.show_col_headers, P_BOOL,
+        NULL, NULL, NULL},
 #ifndef MAEMO
        {"show_statusbar", "TRUE", &prefs_common.show_statusbar, P_BOOL,
         NULL, NULL, NULL},
@@ -599,6 +631,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"mainwin_y", "64", &prefs_common.mainwin_y, P_INT,
         NULL, NULL, NULL},
+       {"mainwin_maximised", "FALSE", &prefs_common.mainwin_maximised, P_BOOL,
+        NULL, NULL, NULL},
 #ifndef MAEMO
        {"mainwin_width", "800", &prefs_common.mainwin_width, P_INT,
         NULL, NULL, NULL},
@@ -658,6 +692,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"uri_color", "32512", &prefs_common.uri_col, P_COLOR,
         NULL, NULL, NULL},
+       {"emphasis_color", "207", &prefs_common.emphasis_col, P_COLOR,
+        NULL, NULL, NULL},
        {"target_folder_color", "14294218", &prefs_common.tgt_folder_col, P_COLOR,
         NULL, NULL, NULL},
        {"signature_color", "7960953", &prefs_common.signature_col, P_COLOR,
@@ -693,9 +729,6 @@ static PrefParam param[] = {
        {"show_other_header", "FALSE", &prefs_common.show_other_header, P_BOOL,
         NULL, NULL, NULL},
 
-       {"use_different_print_font", "FALSE", &prefs_common.use_different_print_font, P_BOOL,
-        NULL, NULL, NULL},
-
        {"attach_desc", "TRUE", &prefs_common.attach_desc, P_BOOL,
         NULL, NULL, NULL},
        {"attach_save_directory", NULL,
@@ -724,7 +757,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,
@@ -737,6 +773,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,
@@ -776,6 +814,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,
@@ -1026,6 +1066,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,
@@ -1037,30 +1079,56 @@ 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},
+       {"use_networkmanager", "TRUE", &prefs_common.use_networkmanager, P_BOOL,
+        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) {
@@ -1075,6 +1143,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;
@@ -1121,6 +1205,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();
 }
 
@@ -1132,16 +1218,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) {
@@ -1175,6 +1267,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)
@@ -1200,6 +1300,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.
@@ -1377,6 +1481,16 @@ gboolean prefs_common_enable_log_status(void)
 {
        return prefs_common.enable_log_status;
 }
+
+#ifdef MAEMO
+const gchar *prefs_common_get_data_root(void)
+{
+       if (prefs_common.data_root && *prefs_common.data_root)
+               return prefs_common.data_root;
+       else
+               return NULL;
+}
+#endif
 /**
    return the translated name of a header, if the translate_header option is
    set, otherwise return the untranslated header name (header_name itself).
@@ -1393,3 +1507,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 
+}