/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
*
* 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
#include "folder.h"
#include "prefs_folder_item.h"
#include "folderview.h"
+#include "folder.h"
#include "summaryview.h"
#include "menu.h"
#include "account.h"
#include "filtering.h"
#include "folder_item_prefs.h"
#include "gtk/colorsel.h"
+#include "string_match.h"
#if USE_ASPELL
#include "gtkaspell.h"
FolderItem *item;
GtkWidget *table;
+ GtkWidget *folder_type;
GtkWidget *checkbtn_simplify_subject;
GtkWidget *entry_simplify_subject;
+ GtkWidget *entry_regexp_test_string;
+ GtkWidget *entry_regexp_test_result;
GtkWidget *checkbtn_folder_chmod;
GtkWidget *entry_folder_chmod;
GtkWidget *folder_color_btn;
GtkWidget *checkbtn_newmailcheck;
GtkWidget *checkbtn_offlinesync;
- /* appy to sub folders */
+ /* apply to sub folders */
GtkWidget *simplify_subject_rec_checkbtn;
GtkWidget *folder_chmod_rec_checkbtn;
GtkWidget *folder_color_rec_checkbtn;
#if USE_ASPELL
GtkWidget *default_dictionary_rec_checkbtn;
#endif
-
};
gint prefs_folder_item_chmod_mode (gchar *folder_chmod);
static void folder_color_set_dialog(GtkWidget *widget, gpointer data);
+static void folder_regexp_test_cb(GtkWidget *widget, gpointer data);
+static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data);
#define SAFE_STRING(str) \
(str) ? (str) : ""
FolderItem *item = (FolderItem *) data;
guint rowcount;
+
GtkWidget *table;
GtkWidget *hbox;
GtkWidget *label;
+ GtkWidget *folder_type_menu;
+ GtkWidget *folder_type;
+ GtkWidget *dummy_chkbtn;
+ GtkWidget *menuitem;
+ SpecialFolderItemType type;
+
GtkWidget *checkbtn_simplify_subject;
GtkWidget *entry_simplify_subject;
+ GtkWidget *hbox_regexp;
+ GtkWidget *label_regexp_test;
+ GtkWidget *entry_regexp_test_string;
+ GtkWidget *left_arrow;
+ GtkWidget *entry_regexp_test_result;
+
GtkWidget *checkbtn_folder_chmod;
GtkWidget *entry_folder_chmod;
GtkWidget *folder_color;
GtkWidget *enable_processing_rec_checkbtn;
GtkWidget *newmailcheck_rec_checkbtn;
GtkWidget *offlinesync_rec_checkbtn;
+ GtkTooltips *tooltips;
page->item = item;
/* Apply to subfolders */
label = gtk_label_new(_("Apply to\nsubfolders"));
gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
- gtk_table_attach(GTK_TABLE(table), label, 2, 3,
+ gtk_table_attach(GTK_TABLE(table), label, 3, 4,
rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
rowcount++;
+ /* folder_type */
+ folder_type = gtk_option_menu_new ();
+ gtk_widget_show (folder_type);
+
+ type = F_NORMAL;
+ if (item->stype == F_INBOX)
+ type = F_INBOX;
+ else if (folder_has_parent_of_type(item, F_OUTBOX))
+ type = F_OUTBOX;
+ else if (folder_has_parent_of_type(item, F_DRAFT))
+ type = F_DRAFT;
+ else if (folder_has_parent_of_type(item, F_QUEUE))
+ type = F_QUEUE;
+ else if (folder_has_parent_of_type(item, F_TRASH))
+ type = F_TRASH;
+
+ folder_type_menu = gtk_menu_new ();
+
+ MENUITEM_ADD (folder_type_menu, menuitem, _("Normal"), F_NORMAL);
+ MENUITEM_ADD (folder_type_menu, menuitem, _("Inbox"), F_INBOX);
+ MENUITEM_ADD (folder_type_menu, menuitem, _("Outbox"), F_OUTBOX);
+ MENUITEM_ADD (folder_type_menu, menuitem, _("Drafts"), F_DRAFT);
+ MENUITEM_ADD (folder_type_menu, menuitem, _("Queue"), F_QUEUE);
+ MENUITEM_ADD (folder_type_menu, menuitem, _("Trash"), F_TRASH);
+ gtk_option_menu_set_menu (GTK_OPTION_MENU (folder_type), folder_type_menu);
+
+ gtk_option_menu_set_history(GTK_OPTION_MENU(folder_type), type);
+
+ dummy_chkbtn = gtk_check_button_new();
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy_chkbtn), type != F_INBOX);
+ gtk_widget_set_sensitive(dummy_chkbtn, FALSE);
+
+ if (type == item->stype && type == F_NORMAL)
+ gtk_widget_set_sensitive(folder_type, TRUE);
+ else
+ gtk_widget_set_sensitive(folder_type, FALSE);
+
+ label = gtk_label_new(_("Folder type"));
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+ gtk_table_attach(GTK_TABLE(table), label, 0, 1,
+ rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), folder_type, 1, 2,
+ rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), dummy_chkbtn, 3, 4,
+ rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
+
+ rowcount++;
+
/* Simplify Subject */
- checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp: "));
+ checkbtn_simplify_subject = gtk_check_button_new_with_label(_("Simplify Subject RegExp"));
gtk_table_attach(GTK_TABLE(table), checkbtn_simplify_subject, 0, 1,
rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_simplify_subject),
item->prefs->enable_simplify_subject);
+ g_signal_connect(G_OBJECT(checkbtn_simplify_subject), "toggled",
+ G_CALLBACK(folder_regexp_set_subject_example_cb), page);
+
entry_simplify_subject = gtk_entry_new();
- gtk_table_attach(GTK_TABLE(table), entry_simplify_subject, 1, 2,
+ gtk_table_attach(GTK_TABLE(table), entry_simplify_subject, 1, 3,
rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_simplify_subject);
gtk_entry_set_text(GTK_ENTRY(entry_simplify_subject),
SAFE_STRING(item->prefs->simplify_subject_regexp));
+ g_signal_connect(G_OBJECT(entry_simplify_subject), "changed",
+ G_CALLBACK(folder_regexp_test_cb), page);
+
simplify_subject_rec_checkbtn = gtk_check_button_new();
- gtk_table_attach(GTK_TABLE(table), simplify_subject_rec_checkbtn, 2, 3,
+ gtk_table_attach(GTK_TABLE(table), simplify_subject_rec_checkbtn, 3, 4,
rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
rowcount++;
+ /* Test RegExp */
+ label_regexp_test = gtk_label_new(_("Test RegExp"));
+ gtk_misc_set_alignment(GTK_MISC(label_regexp_test), 0, 0.5);
+ gtk_table_attach(GTK_TABLE(table), label_regexp_test, 0, 1,
+ rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
+ SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, label_regexp_test);
+
+ entry_regexp_test_string = gtk_entry_new();
+ gtk_table_attach(GTK_TABLE(table), entry_regexp_test_string, 1, 2,
+ rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+ SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_string);
+
+ g_signal_connect(G_OBJECT(entry_regexp_test_string), "changed",
+ G_CALLBACK(folder_regexp_test_cb), page);
+
+ hbox_regexp = gtk_hbox_new (FALSE, 4);
+ gtk_widget_show (hbox_regexp);
+ gtk_table_attach(GTK_TABLE(table), hbox_regexp, 2, 3,
+ rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+
+ left_arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
+ gtk_widget_show(left_arrow);
+ gtk_box_pack_start (GTK_BOX(hbox_regexp), left_arrow, FALSE, FALSE, 0);
+ SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, left_arrow);
+
+ entry_regexp_test_result = gtk_entry_new();
+ gtk_box_pack_end (GTK_BOX(hbox_regexp), entry_regexp_test_result, TRUE, TRUE, 0);
+ SET_TOGGLE_SENSITIVITY(checkbtn_simplify_subject, entry_regexp_test_result);
+ gtk_entry_set_editable(GTK_ENTRY(entry_regexp_test_result), FALSE);
+
+ rowcount++;
+
/* Folder chmod */
- checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod: "));
+ checkbtn_folder_chmod = gtk_check_button_new_with_label(_("Folder chmod"));
gtk_table_attach(GTK_TABLE(table), checkbtn_folder_chmod, 0, 1,
rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
}
folder_chmod_rec_checkbtn = gtk_check_button_new();
- gtk_table_attach(GTK_TABLE(table), folder_chmod_rec_checkbtn, 2, 3,
+ gtk_table_attach(GTK_TABLE(table), folder_chmod_rec_checkbtn, 3, 4,
rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
rowcount++;
/* Folder color */
- folder_color = gtk_label_new(_("Folder color: "));
+ folder_color = gtk_label_new(_("Folder color"));
gtk_misc_set_alignment(GTK_MISC(folder_color), 0, 0.5);
gtk_table_attach(GTK_TABLE(table), folder_color, 0, 1,
rowcount, rowcount + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
folder_color_btn = gtk_button_new_with_label("");
gtk_widget_set_size_request(folder_color_btn, 36, 26);
gtk_box_pack_start (GTK_BOX(hbox), folder_color_btn, FALSE, FALSE, 0);
+ tooltips = gtk_tooltips_new();
+ gtk_tooltips_set_tip(tooltips, folder_color_btn,
+ _("Pick color for folder"), NULL);
page->folder_color = item->prefs->color;
gtkut_set_widget_bgcolor_rgb(folder_color_btn, item->prefs->color);
folder_color_rec_checkbtn = gtk_check_button_new();
- gtk_table_attach(GTK_TABLE(table), folder_color_rec_checkbtn, 2, 3,
+ gtk_table_attach(GTK_TABLE(table), folder_color_rec_checkbtn, 3, 4,
rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
rowcount++;
item->prefs->enable_processing);
enable_processing_rec_checkbtn = gtk_check_button_new();
- gtk_table_attach(GTK_TABLE(table), enable_processing_rec_checkbtn, 2, 3,
+ gtk_table_attach(GTK_TABLE(table), enable_processing_rec_checkbtn, 3, 4,
rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
rowcount++;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_newmailcheck),
item->prefs->newmailcheck);
newmailcheck_rec_checkbtn = gtk_check_button_new();
- gtk_table_attach(GTK_TABLE(table), newmailcheck_rec_checkbtn, 2, 3,
+ gtk_table_attach(GTK_TABLE(table), newmailcheck_rec_checkbtn, 3, 4,
rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
rowcount++;
rowcount, rowcount+1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
offlinesync_rec_checkbtn = gtk_check_button_new();
- gtk_table_attach(GTK_TABLE(table), offlinesync_rec_checkbtn, 2, 3,
+ gtk_table_attach(GTK_TABLE(table), offlinesync_rec_checkbtn, 3, 4,
rowcount, rowcount + 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
if (item->folder && (item->folder->klass->type != F_IMAP &&
gtk_widget_show_all(table);
page->table = table;
+ page->folder_type = folder_type;
page->checkbtn_simplify_subject = checkbtn_simplify_subject;
page->entry_simplify_subject = entry_simplify_subject;
+ page->entry_regexp_test_string = entry_regexp_test_string;
+ page->entry_regexp_test_result = entry_regexp_test_result;
page->checkbtn_folder_chmod = checkbtn_folder_chmod;
page->entry_folder_chmod = entry_folder_chmod;
page->folder_color_btn = folder_color_btn;
page->offlinesync_rec_checkbtn = offlinesync_rec_checkbtn;
page->page.widget = table;
+
+ folder_regexp_set_subject_example_cb(NULL, page);
}
void prefs_folder_item_general_destroy_widget_func(PrefsPage *page_)
/** \brief Save the prefs in page to folder.
*
* If the folder is not the one specified in page->item, then only those properties
- * that have the relevant 'appy to sub folders' button checked are saved
+ * that have the relevant 'apply to sub folders' button checked are saved
*/
static void general_save_folder_prefs(FolderItem *folder, FolderItemGeneralPage *page)
{
FolderItemPrefs *prefs = folder->prefs;
gchar *buf;
gboolean all = FALSE;
+ SpecialFolderItemType type = F_NORMAL;
+ GtkWidget *menu;
+ GtkWidget *menuitem;
+
+ if (folder->path == NULL)
+ return;
g_return_if_fail(prefs != NULL);
if (page->item == folder)
all = TRUE;
+ menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(page->folder_type));
+ menuitem = gtk_menu_get_active(GTK_MENU(menu));
+ type = GPOINTER_TO_INT
+ (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
+ if (all && folder->stype != type) {
+ folder_item_change_type(folder, type);
+ }
+
if (all || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->simplify_subject_rec_checkbtn))) {
prefs->enable_simplify_subject =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject));
rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
SET_TOGGLE_SENSITIVITY(checkbtn_default_to, entry_default_to);
gtk_entry_set_text(GTK_ENTRY(entry_default_to), SAFE_STRING(item->prefs->default_to));
- address_completion_register_entry(GTK_ENTRY(entry_default_to));
+ address_completion_register_entry(GTK_ENTRY(entry_default_to),
+ TRUE);
default_to_rec_checkbtn = gtk_check_button_new();
gtk_table_attach(GTK_TABLE(table), default_to_rec_checkbtn, 2, 3,
rowcount, rowcount + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
SET_TOGGLE_SENSITIVITY(checkbtn_default_reply_to, entry_default_reply_to);
gtk_entry_set_text(GTK_ENTRY(entry_default_reply_to), SAFE_STRING(item->prefs->default_reply_to));
- address_completion_register_entry(GTK_ENTRY(entry_default_reply_to));
+ address_completion_register_entry(
+ GTK_ENTRY(entry_default_reply_to), TRUE);
default_reply_to_rec_checkbtn = gtk_check_button_new();
gtk_table_attach(GTK_TABLE(table), default_reply_to_rec_checkbtn, 2, 3,
/** \brief Save the prefs in page to folder.
*
* If the folder is not the one specified in page->item, then only those properties
- * that have the relevant 'appy to sub folders' button checked are saved
+ * that have the relevant 'apply to sub folders' button checked are saved
*/
static void compose_save_folder_prefs(FolderItem *folder, FolderItemComposePage *page)
{
GtkWidget *menuitem;
gboolean all = FALSE;
+ if (folder->path == NULL)
+ return;
+
if (page->item == folder)
all = TRUE;
page->folder_color = rgbcolor;
}
+static regex_t *summary_compile_simplify_regexp(gchar *simplify_subject_regexp)
+{
+ int err;
+ gchar buf[BUFFSIZE];
+ regex_t *preg = NULL;
+
+ preg = g_new0(regex_t, 1);
+
+ err = string_match_precompile(simplify_subject_regexp,
+ preg, REG_EXTENDED);
+ if (err) {
+ regerror(err, preg, buf, BUFFSIZE);
+ g_free(preg);
+ preg = NULL;
+ }
+
+ return preg;
+}
+
+static void folder_regexp_test_cb(GtkWidget *widget, gpointer data)
+{
+ static GdkColor red;
+ static gboolean colors_initialised = FALSE;
+ static gchar buf[BUFFSIZE];
+ FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
+ gchar *test_string, *regexp;
+ regex_t *preg;
+
+ regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_simplify_subject)));
+ test_string = g_strdup(gtk_entry_get_text(GTK_ENTRY(page->entry_regexp_test_string)));
+
+ if (!regexp || !regexp[0]) {
+ if (test_string) {
+ gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), test_string);
+ g_free(test_string);
+ }
+ return;
+ }
+
+ if (!test_string || !test_string[0]) {
+ g_free(regexp);
+ return;
+ }
+
+ if (!colors_initialised) {
+ gdk_color_parse("#ff7070", &red);
+ colors_initialised = gdk_colormap_alloc_color(
+ gdk_colormap_get_system(), &red, FALSE, TRUE);
+ }
+
+ preg = summary_compile_simplify_regexp(regexp);
+ if (colors_initialised) {
+ gtk_widget_modify_base(page->entry_simplify_subject,
+ GTK_STATE_NORMAL, preg ? NULL : &red);
+ }
+
+ if (preg != NULL) {
+ string_remove_match(buf, BUFFSIZE, test_string, preg);
+
+ gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_result), buf);
+
+ regfree(preg);
+ g_free(preg);
+ }
+
+ g_free(test_string);
+ g_free(regexp);
+}
+
+static gchar *folder_regexp_get_subject_example(void)
+{
+ MsgInfo *msginfo_selected;
+ SummaryView *summaryview = NULL;
+
+ if (!mainwindow_get_mainwindow())
+ return NULL;
+ summaryview = mainwindow_get_mainwindow()->summaryview;
+
+ msginfo_selected = summary_get_selected_msg(summaryview);
+ return msginfo_selected ? g_strdup(msginfo_selected->subject) : NULL;
+}
+
+static void folder_regexp_set_subject_example_cb(GtkWidget *widget, gpointer data)
+{
+ FolderItemGeneralPage *page = (FolderItemGeneralPage *)data;
+
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_simplify_subject))) {
+ gchar *subject = folder_regexp_get_subject_example();
+ if (subject) {
+ gtk_entry_set_text(GTK_ENTRY(page->entry_regexp_test_string), subject);
+ g_free(subject);
+ }
+ }
+}
static void register_general_page()
{
register_compose_page();
}
- id = folder_item_get_identifier (item);
+ if (item->path)
+ id = folder_item_get_identifier (item);
+ else
+ id = g_strdup(item->name);
title = g_strdup_printf (_("Properties for folder %s"), id);
g_free (id);
prefswindow_open(title, prefs_pages, item,