more plumbing in Hoa's code (can't wait to have all these settings moved into folderl...
[claws.git] / src / prefs_folder_item.c
index 9297b645f948443b550b375f1b873150c059efab..038fca1e504515087a3e89faf03964d62690c58e 100644 (file)
@@ -1,11 +1,47 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* alfons - all folder item specific settings should migrate into 
+ * folderlist.xml!!! the old folderitemrc file will only serve for a few 
+ * versions (for compatibility) */
+
+#include "intl.h"
+#include "defs.h"
 #include "folder.h"
 #include "prefs_folder_item.h"
 #include "summaryview.h"
 #include "prefs.h"
-#include "defs.h"
+#include "manage_window.h"
 
 PrefsFolderItem tmp_prefs;
 
+struct PrefsFolderItemDialog
+{
+       FolderItem *item;
+       GtkWidget *window;
+       GtkWidget *checkbtn_request_return_receipt;
+       GtkWidget *checkbtn_default_to;
+       GtkWidget *entry_default_to;
+       GtkWidget *checkbtn_folder_chmod;
+       GtkWidget *entry_folder_chmod;
+};
+
 static PrefParam param[] = {
        {"sort_by_number", "FALSE", &tmp_prefs.sort_by_number, P_BOOL,
         NULL, NULL, NULL},
@@ -21,31 +57,61 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"sort_descending", "FALSE", &tmp_prefs.sort_descending, P_BOOL,
         NULL, NULL, NULL},
-       {"enable_thread", "FALSE", &tmp_prefs.enable_thread, P_BOOL,
+       /*{"enable_thread", "TRUE", &tmp_prefs.enable_thread, P_BOOL,
+        NULL, NULL, NULL},*/
+       {"kill_score", "-9999", &tmp_prefs.kill_score, P_INT,
+        NULL, NULL, NULL},
+       {"important_score", "1", &tmp_prefs.important_score, P_INT,
+        NULL, NULL, NULL},
+       /* MIGRATION */  
+       {"request_return_receipt", "", &tmp_prefs.request_return_receipt, P_BOOL,
+        NULL, NULL, NULL},
+       {"enable_default_to", "", &tmp_prefs.enable_default_to, P_BOOL,
+        NULL, NULL, NULL},
+       {"default_to", "", &tmp_prefs.default_to, P_STRING,
+        NULL, NULL, NULL},
+       {"enable_folder_chmod", "", &tmp_prefs.enable_folder_chmod, P_BOOL,
+        NULL, NULL, NULL},
+       {"folder_chmod", "", &tmp_prefs.folder_chmod, P_INT,
         NULL, NULL, NULL},
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
+void prefs_folder_item_delete_cb(GtkWidget *widget, GdkEventAny *event, struct PrefsFolderItemDialog *dialog);
+void prefs_folder_item_cancel_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
+void prefs_folder_item_ok_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
+void prefs_folder_item_default_to_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
+void prefs_folder_item_folder_chmod_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog);
+gint prefs_folder_item_chmod_mode(gchar *folder_chmod);
+
 void prefs_folder_item_read_config(FolderItem * item)
 {
-       gchar * path;
+       gchar * id;
 
-       path = folder_item_get_path(item);
-       prefs_read_config(param, path, FOLDERITEM_RC);
-       g_free(path);
+       id = folder_item_get_identifier(item);
 
-       * item->prefs = tmp_prefs;
+       prefs_read_config(param, id, FOLDERITEM_RC);
+       g_free(id);
+
+       *item->prefs = tmp_prefs;
+
+       /* MIGRATION */
+       item->ret_rcpt = tmp_prefs.request_return_receipt ? TRUE : FALSE; 
 }
 
 void prefs_folder_item_save_config(FolderItem * item)
 {      
-       gchar * path;
+       gchar * id;
 
        tmp_prefs = * item->prefs;
 
-       path = folder_item_get_path(item);
-       prefs_save_config(param, path, FOLDERITEM_RC);
-       g_free(path);
+       id = folder_item_get_identifier(item);
+
+       prefs_save_config(param, id, FOLDERITEM_RC);
+       g_free(id);
+
+       /* MIGRATION: make sure migrated items are not saved
+        */
 }
 
 void prefs_folder_item_set_config(FolderItem * item,
@@ -98,6 +164,14 @@ PrefsFolderItem * prefs_folder_item_new(void)
        tmp_prefs.sort_by_subject = FALSE;
        tmp_prefs.sort_by_score = FALSE;
        tmp_prefs.sort_descending = FALSE;
+       tmp_prefs.kill_score = -9999;
+       tmp_prefs.important_score = 9999;
+
+       tmp_prefs.request_return_receipt = FALSE;
+       tmp_prefs.enable_default_to = FALSE;
+       tmp_prefs.default_to = NULL;
+       tmp_prefs.enable_folder_chmod = FALSE;
+       tmp_prefs.folder_chmod = 0;
 
        * prefs = tmp_prefs;
        
@@ -106,6 +180,10 @@ PrefsFolderItem * prefs_folder_item_new(void)
 
 void prefs_folder_item_free(PrefsFolderItem * prefs)
 {
+       if (prefs->default_to) 
+               g_free(prefs->default_to);
+       if (prefs->scoring != NULL)
+               prefs_scoring_free(prefs->scoring);
        g_free(prefs);
 }
 
@@ -137,3 +215,176 @@ gint prefs_folder_item_get_sort_type(FolderItem * item)
        else
                return GTK_SORT_ASCENDING;
 }
+
+#define SAFE_STRING(str) \
+       (str) ? (str) : ""
+
+void prefs_folder_item_create(FolderItem *item) {
+       struct PrefsFolderItemDialog *dialog;
+       GtkWidget *window;
+       GtkWidget *vbox;
+       GtkWidget *ok_btn;
+       GtkWidget *cancel_btn;
+       GtkWidget *confirm_area;
+       GtkWidget *hbox;
+       
+       GtkWidget *checkbtn_request_return_receipt;
+       GtkWidget *checkbtn_default_to;
+       GtkWidget *entry_default_to;
+       GtkWidget *checkbtn_folder_chmod;
+       GtkWidget *entry_folder_chmod;
+
+       dialog = g_new0(struct PrefsFolderItemDialog, 1);
+       dialog->item = item;
+
+       /* Window */
+       window = gtk_window_new (GTK_WINDOW_DIALOG);
+       gtk_window_set_title (GTK_WINDOW(window),
+                             _("Folder Property"));
+       gtk_container_set_border_width (GTK_CONTAINER (window), 8);
+       gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
+       gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE);
+       gtk_signal_connect (GTK_OBJECT(window), "delete_event",
+                           GTK_SIGNAL_FUNC(prefs_folder_item_delete_cb), dialog);
+       gtk_signal_connect (GTK_OBJECT(window), "focus_in_event",
+                           GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
+       gtk_signal_connect (GTK_OBJECT(window), "focus_out_event",
+                           GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
+
+       vbox = gtk_vbox_new (FALSE, 6);
+       gtk_widget_show(vbox);
+       gtk_container_add(GTK_CONTAINER (window), vbox);
+
+       /* Ok and Cancle Buttons */
+       gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
+                               &cancel_btn, _("Cancel"), NULL, NULL);
+       gtk_widget_show(confirm_area);
+       gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
+       gtk_widget_grab_default(ok_btn);
+       gtk_signal_connect (GTK_OBJECT(ok_btn), "clicked",
+                           GTK_SIGNAL_FUNC(prefs_folder_item_ok_cb), dialog);
+       gtk_signal_connect (GTK_OBJECT(cancel_btn), "clicked",
+                           GTK_SIGNAL_FUNC(prefs_folder_item_cancel_cb), dialog);
+
+       /* Request Return Receipt */
+       PACK_CHECK_BUTTON(vbox, checkbtn_request_return_receipt,
+                          _("Request Return Receipt"));
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_request_return_receipt),
+                                    item->ret_rcpt ? TRUE : FALSE);
+
+       /* Default To */
+       hbox = gtk_hbox_new(FALSE, 8);
+       gtk_widget_show(hbox);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
+       PACK_CHECK_BUTTON(hbox, checkbtn_default_to,
+                          _("Default To: "));
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_default_to), item->prefs->enable_default_to);
+       gtk_signal_connect(GTK_OBJECT(checkbtn_default_to), "toggled",
+                           GTK_SIGNAL_FUNC(prefs_folder_item_default_to_cb), dialog);
+
+       entry_default_to = gtk_entry_new();
+       gtk_widget_show(entry_default_to);
+       gtk_box_pack_start(GTK_BOX(hbox), entry_default_to, FALSE, FALSE, 0);
+       gtk_editable_set_editable(GTK_EDITABLE(entry_default_to), item->prefs->enable_default_to);
+       gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
+
+       /* Folder chmod */
+       hbox = gtk_hbox_new(FALSE, 8);
+       gtk_widget_show(hbox);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+
+       PACK_CHECK_BUTTON(hbox, checkbtn_folder_chmod,
+                          _("Folder chmod: "));
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_folder_chmod), item->prefs->enable_folder_chmod);
+       gtk_signal_connect(GTK_OBJECT(checkbtn_folder_chmod), "toggled",
+                           GTK_SIGNAL_FUNC(prefs_folder_item_folder_chmod_cb), dialog);
+
+       entry_folder_chmod = gtk_entry_new();
+       gtk_widget_show(entry_folder_chmod);
+       gtk_box_pack_start(GTK_BOX(hbox), entry_folder_chmod, FALSE, FALSE, 0);
+       gtk_editable_set_editable(GTK_EDITABLE(entry_folder_chmod), item->prefs->enable_folder_chmod);
+       if (item->prefs->folder_chmod) {
+               gint tmp;
+               gint mult;
+               gint count = 0;
+               char buf[64]; /* plenty enough for an integer */
+
+               tmp = item->prefs->folder_chmod;
+               while (tmp && (count < sizeof(buf) - 1)) {
+                       mult = tmp / 8;
+                       buf[count++] = '0' + (tmp - mult * 8);
+                       tmp /= 8;
+               }
+               buf[count] = '\0';
+               gtk_entry_set_text(GTK_ENTRY(entry_folder_chmod), buf);
+       }
+
+       dialog->window = window;
+       dialog->checkbtn_request_return_receipt = checkbtn_request_return_receipt;
+       dialog->checkbtn_default_to = checkbtn_default_to;
+       dialog->entry_default_to = entry_default_to;
+       dialog->checkbtn_folder_chmod = checkbtn_folder_chmod;
+       dialog->entry_folder_chmod = entry_folder_chmod;
+
+       gtk_widget_show(window);
+}
+
+void prefs_folder_item_destroy(struct PrefsFolderItemDialog *dialog) {
+       gtk_widget_destroy(dialog->window);
+       g_free(dialog);
+}
+
+void prefs_folder_item_cancel_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) {
+       prefs_folder_item_destroy(dialog);
+}
+
+void prefs_folder_item_delete_cb(GtkWidget *widget, GdkEventAny *event, struct PrefsFolderItemDialog *dialog) {
+       prefs_folder_item_destroy(dialog);
+}
+
+void prefs_folder_item_ok_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) {
+       PrefsFolderItem *prefs = dialog->item->prefs;
+
+       prefs->request_return_receipt = 
+           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_request_return_receipt));
+       /* MIGRATION */    
+       dialog->item->ret_rcpt = prefs->request_return_receipt;
+           
+       prefs->enable_default_to = 
+           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_default_to));
+       g_free(prefs->default_to);
+       prefs->default_to = 
+           gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_default_to), 0, -1);
+       prefs->enable_folder_chmod = 
+           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_folder_chmod));
+       prefs->folder_chmod = prefs_folder_item_chmod_mode(
+               gtk_editable_get_chars(GTK_EDITABLE(dialog->entry_folder_chmod),
+                                      0, -1));
+
+       prefs_folder_item_save_config(dialog->item);
+       prefs_folder_item_destroy(dialog);
+}
+
+void prefs_folder_item_default_to_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) {
+       gtk_editable_set_editable(GTK_EDITABLE(dialog->entry_default_to),
+           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_default_to)));
+}
+
+void prefs_folder_item_folder_chmod_cb(GtkWidget *widget, struct PrefsFolderItemDialog *dialog) {
+       gtk_editable_set_editable(GTK_EDITABLE(dialog->entry_folder_chmod),
+           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbtn_folder_chmod)));
+}
+
+gint prefs_folder_item_chmod_mode(gchar *folder_chmod) {
+       gint newmode = 0;
+       gchar *tmp;
+
+       if (folder_chmod) {
+               newmode = strtol(folder_chmod, &tmp, 8);
+               if (!(*(folder_chmod) && !(*tmp)))
+                       newmode = 0;
+       }
+
+       return newmode;
+}