revise label colouring, add filter action for label colouring, fix filtering issues
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Sat, 21 Jul 2001 11:57:56 +0000 (11:57 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Sat, 21 Jul 2001 11:57:56 +0000 (11:57 +0000)
17 files changed:
ChangeLog.claws
configure.in
po/POTFILES.in
src/Makefile.am
src/filtering.c
src/filtering.h
src/folderview.c
src/inc.c
src/labelcolors.c [new file with mode: 0644]
src/labelcolors.h [new file with mode: 0644]
src/matcher.c
src/matcher.h
src/prefs_filtering.c
src/prefs_matcher.c
src/procmsg.h
src/summaryview.c
src/summaryview.h

index 4217e91..592b925 100644 (file)
@@ -1,3 +1,39 @@
+2001-07-21 [alfons]
+
+       0.5.0claws7
+
+       * configure.in
+               change version
+
+       * src/inc.c, src/summaryview.[ch]
+               prevent update of mark file when filtering has done, by
+               using a variable; this affects two functions:
+                       inc.c::inc_finished()
+                       summaryview.c::summary_show()
+
+2001-07-20 [alfons]
+
+       * src/filtering.[ch], src/prefs_filtering.c, 
+         src/matcher.[ch]
+               add filtering action for label coloring 
+
+       * po/POTFILES.in
+               add labelcolors.c
+
+       * added src/labelcolors.c
+       * added src/labelcolors.h
+       * src/Makefile.am, src/summaryview.c
+               rearrange label coloring code
+
+       * src/procmsg.h
+               add more parentheses so label colouring works correctly
+
+       * src/filtering.c
+               don't really delete message, but move it to Trash
+
+       * src/prefs_matcher.c
+               add quote options to info dialog
+
 2001-07-20 [christoph]
 
        * src/Makefile.am
index a9a976a..d914191 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=5
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws6
+EXTRA_VERSION=claws7
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl
index f47fa32..404c1a5 100644 (file)
@@ -26,6 +26,7 @@ src/imap.c
 src/import.c
 src/inc.c
 src/inputdialog.c
+src/labelcolors.c
 src/logwindow.c
 src/main.c
 src/mainwindow.c
index 68d6655..58daec1 100644 (file)
@@ -98,6 +98,7 @@ sylpheed_SOURCES = \
        editjpilot.c editjpilot.h \
        editldap.c editldap.h \
        editldap_basedn.c editldap_basedn.h \
+       labelcolors.c labelcolors.h \
        ssl.c ssl.h
 
 EXTRA_DIST = \
index edf0d08..13d525e 100644 (file)
@@ -53,7 +53,8 @@
 GSList * prefs_filtering = NULL;
 
 FilteringAction * filteringaction_new(int type, int account_id,
-                                     gchar * destination)
+                                     gchar * destination,
+                                     gint labelcolor)
 {
        FilteringAction * action;
 
@@ -63,7 +64,7 @@ FilteringAction * filteringaction_new(int type, int account_id,
        action->account_id = account_id;
        if (destination)
                action->destination = g_strdup(destination);
-
+       action->labelcolor = labelcolor;        
        return action;
 }
 
@@ -81,6 +82,7 @@ FilteringAction * filteringaction_parse(gchar ** str)
        gchar * destination = NULL;
        gint account_id = 0;
        gint key;
+       gint labelcolor = 0;
 
        tmp = * str;
 
@@ -120,6 +122,14 @@ FilteringAction * filteringaction_parse(gchar ** str)
                        return NULL;
                }
 
+               break;
+       case MATCHING_ACTION_COLOR:
+               labelcolor = matcher_parse_number(&tmp);
+               if (tmp == NULL) {
+                       *str = NULL;
+                       return NULL;
+               }
+
                break;
        default:
                * str = NULL;
@@ -128,7 +138,7 @@ FilteringAction * filteringaction_parse(gchar ** str)
 
        * str = tmp;
 
-       action = filteringaction_new(key, account_id, destination);
+       action = filteringaction_new(key, account_id, destination, labelcolor);
 
        return action;
 }
@@ -869,6 +879,11 @@ static gboolean filter_incoming_perform_actions(FolderItem *default_folder,
                        MSG_SET_PERM_FLAGS(markflags, MSG_UNREAD);
                        break;
 
+               case MATCHING_ACTION_COLOR:
+                       MSG_SET_LABEL_VALUE(markflags, ma_tail->action->labelcolor);
+                       debug_print("*** label color %d\n", ma_tail->action->labelcolor);
+                       break;
+
                /* UNCONTINUABLE */
                case MATCHING_ACTION_FORWARD:
                case MATCHING_ACTION_FORWARD_AS_ATTACHMENT:
@@ -982,8 +997,18 @@ static gboolean filter_incoming_perform_actions(FolderItem *default_folder,
                else if (MATCHING_ACTION_DELETE == ACTION) {
                        debug_print("*** performing delete\n");
                        copy_to_inbox_too = FALSE;
-                       if (unlink(filename) < 0)
-                               debug_print(_("Rule failed: could not delete message\n"));
+
+                       /* drop to Trash */
+                       dest_folder = folder_get_default_trash();
+                       msgnum = folder_item_add_msg(dest_folder, filename, FALSE);
+                       if (msgnum < 0) {
+                               debug_print(_("Rule failed: could not move to trash"));
+                               copy_to_inbox_too = TRUE;           
+                       }
+                       else {
+                               flags = msginfo->flags.perm_flags | markflags.perm_flags;
+                               add_mark(dest_folder, msgnum, flags);
+                       }
                        break;                          
                }
                else if (MATCHING_ACTION_MOVE == ACTION) {
@@ -1011,6 +1036,7 @@ static gboolean filter_incoming_perform_actions(FolderItem *default_folder,
 
        /* may need to copy it to inbox too */
        if (copy_to_inbox_too) {
+               gint color;
                debug_print("*** performing inbox copy\n");
                msgnum = folder_item_add_msg(default_folder, filename, TRUE);
                if (msgnum < 0) {
@@ -1019,6 +1045,8 @@ static gboolean filter_incoming_perform_actions(FolderItem *default_folder,
                        return FALSE;                               
                }
                flags = msginfo->flags.perm_flags | markflags.perm_flags;
+               color = (flags >> 7) & 7; 
+               debug_print("*** marking label color %d\n", color);
                add_mark(default_folder, msgnum, flags);
        }
        else {
@@ -1123,6 +1151,9 @@ gchar * filteringaction_to_string(FilteringAction * action)
        gchar * command_str;
        gint i;
        gchar * account_id_str;
+       gchar * labelcolor_str;
+
+       /* FIXME: use g_sprintf() throughout */
 
        command_str = NULL;
        command_str = get_matchparser_tab_str(action->type);
@@ -1151,6 +1182,10 @@ gchar * filteringaction_to_string(FilteringAction * action)
                return g_strconcat(command_str, " ", account_id_str,
                                   " \"", action->destination, "\"", NULL);
 
+       case MATCHING_ACTION_COLOR:
+               labelcolor_str = itos(action->labelcolor);
+               return g_strconcat(command_str, " ", labelcolor_str, NULL);  
+
        default:
                return NULL;
        }
@@ -1203,6 +1238,7 @@ void prefs_filtering_write_config(void)
 
                prop = (FilteringProp *) cur->data;
                filtering_str = filteringprop_to_string(prop);
+               debug_print("*** WRITING %s\n", filtering_str);
                if (fputs(filtering_str, pfile->fp) == EOF ||
                    fputc('\n', pfile->fp) == EOF) {
                        FILE_OP_ERROR(rcpath, "fputs || fputc");
index 4748109..113e33b 100644 (file)
@@ -28,7 +28,8 @@
 struct _FilteringAction {
        gint type;
        gint account_id;
-       gchar * destination;
+       gchar *destination;
+       gint labelcolor;
 };
 
 typedef struct _FilteringAction FilteringAction;
@@ -44,7 +45,8 @@ extern GSList * prefs_filtering;
 
 
 FilteringAction * filteringaction_new(int type, int account_id,
-                                     gchar * destination);
+                                     gchar * destination,
+                                     gint labelcolor);
 void filteringaction_free(FilteringAction * action);
 FilteringAction * filteringaction_parse(gchar ** str);
 
index 4b781a7..07df785 100644 (file)
@@ -470,8 +470,10 @@ void folderview_select(FolderView *folderview, FolderItem *item)
 
        if (!item) return;
 
+       debug_print("*** select enter\n");
        node = gtk_ctree_find_by_row_data(ctree, NULL, item);
        if (node) folderview_select_node(folderview, node);
+       debug_print("*** select leave\n");
 }
 
 static void folderview_select_node(FolderView *folderview, GtkCTreeNode *node)
@@ -1319,6 +1321,8 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
 
        folderview->selected = row;
 
+       debug_print("*** selected enter\n");
+
        if (folderview->opened == row) {
                folderview->open_folder = FALSE;
                return;
@@ -1353,6 +1357,7 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
                        gdk_pointer_ungrab(GDK_CURRENT_TIME);
        }
 
+       debug_print("*** summary_show %s\n", item->name);
        opened = summary_show(folderview->summaryview, item, FALSE);
 
        if (!opened) {
@@ -1363,6 +1368,9 @@ static void folderview_selected(GtkCTree *ctree, GtkCTreeNode *row,
 
        folderview->open_folder = FALSE;
        can_select = TRUE;
+
+
+       debug_print("*** selected leave\n");
 }
 
 static void folderview_tree_expanded(GtkCTree *ctree, GtkCTreeNode *node,
index a5220f2..9e19f25 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -120,6 +120,23 @@ static void inc_finished(MainWindow *mainwin)
 {
        FolderItem *item;
 
+       /* XXX: major problems right here. if we change marks after
+        * incorporation of mail, folderview_select() rewrites it
+        * right under our nose. folderview_select() eventually
+        * calls summary_show(), which rewrites the cache twice:
+        * one for the previously selected FolderItem*, and one
+        * for the newly selected FolderItem* 
+        *
+        * since filtering also allows changing mark files, 
+        * i've solved this by using a global variable (in 
+        * SummmaryView*). a better solution is to use the folder
+        * hash table, and see whether the newly and currently 
+        * selected FolderItem* where updated by the filtering. */
+
+       mainwin->summaryview->filtering_happened = TRUE;
+
+       /* XXX: filtering_happened is reset by summary_show() */
+
        if (prefs_common.open_inbox_on_inc) {
                item = cur_account && cur_account->inbox
                        ? folder_find_item_from_path(cur_account->inbox)
@@ -584,9 +601,7 @@ static IncState inc_pop3_session_do(IncSession *session)
                if(!ssl_init_socket(sockinfo)) {
                        pop3_automaton_terminate(NULL, atm);
                        automaton_destroy(atm);
-
                        return INC_ERROR;
-               }
        } else {
                sockinfo->ssl = NULL;
        }
diff --git a/src/labelcolors.c b/src/labelcolors.c
new file mode 100644 (file)
index 0000000..18823f5
--- /dev/null
@@ -0,0 +1,332 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2001 Hiroyuki Yamamoto & 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
+ * 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) - based on a contribution by Satoshi Nagayasu; revised for colorful 
+ * menu and more Sylpheed integration. The idea to put the code in a separate
+ * file is just that it make it easier to allow "user changeable" label colors.
+ */
+
+#include "defs.h"
+#include "intl.h"
+
+#include <glib.h>
+#include <gdk/gdkx.h>
+#include <gtk/gtkwidget.h>
+#include <gtk/gtkpixmap.h>
+#include <gtk/gtkmenu.h>
+#include <gtk/gtkcheckmenuitem.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtkmenuitem.h>
+#include <gtk/gtkalignment.h>
+#include <gtk/gtkhbox.h>
+#include <gtk/gtkwindow.h>
+
+
+#include "labelcolors.h"
+#include "gtkutils.h"
+#include "utils.h"
+
+static gchar *labels[] = {
+       N_("Orange"),
+       N_("Red") ,
+       N_("Pink"),
+       N_("Sky blue"),
+       N_("Blue"),
+       N_("Green"),
+       N_("Brown")
+};
+
+typedef enum LabelColorChangeFlags_ {
+       LCCF_COLOR = 1 << 0,
+       LCCF_LABEL = 1 << 1,
+       LCCF_ALL   = LCCF_COLOR | LCCF_LABEL
+} LabelColorChangeFlags;
+
+/* XXX: if you add colors, make sure you also check the procmsg.h. color indices
+ * are stored as 3 bits; that explains the max. of 7 colors */
+static struct 
+{
+       LabelColorChangeFlags   changed; 
+       GdkColor                color;
+
+       /* XXX: note that the label member is supposed to be dynamically 
+        * allocated and fffreed */
+       gchar                   *label;
+       GtkPixmap               *pixmap;
+}
+label_colors[] = 
+{
+       { LCCF_ALL, { 0, 0xffff, (0x99 << 8), 0x0 },            NULL, NULL },
+       { LCCF_ALL, { 0, 0xffff, 0, 0 },                        NULL, NULL },
+       { LCCF_ALL, { 0, 0xffff, (0x66 << 8), 0xffff },         NULL, NULL },
+       { LCCF_ALL, { 0, 0x0, (0xcc << 8), 0xffff },            NULL, NULL },
+       { LCCF_ALL, { 0, 0x0, 0x0, 0xffff },                    NULL, NULL },
+       { LCCF_ALL, { 0, 0x0, 0x99 << 8, 0x0 },                 NULL, NULL },
+       { LCCF_ALL, { 0, 0x66 << 8, 0x33 << 8, 0x33 << 8 },     NULL, NULL }
+};
+
+#define LABEL_COLORS_ELEMS (sizeof label_colors / sizeof label_colors[0])
+
+#define G_RETURN_VAL_IF_INVALID_COLOR(color, val) \
+       g_return_val_if_fail((color) >= 0 && (color) < LABEL_COLORS_ELEMS, (val))
+
+static void labelcolors_recreate        (gint);
+static void labelcolors_recreate_label  (gint);
+
+gint labelcolors_get_color_count(void)
+{
+       return LABEL_COLORS_ELEMS;
+}
+
+GdkColor labelcolors_get_color(gint color_index)
+{
+       GdkColor invalid = { 0 };
+
+       G_RETURN_VAL_IF_INVALID_COLOR(color_index, invalid);
+
+       return label_colors[color_index].color;
+}
+
+gchar *labelcolors_get_color_text(gint color_index)
+{
+       G_RETURN_VAL_IF_INVALID_COLOR(color_index, NULL);
+
+       labelcolors_recreate_label(color_index);
+       return label_colors[color_index].label;
+}
+
+GtkPixmap *labelcolors_create_color_pixmap(GdkColor color)
+{
+       const char *FMT = "+      c #%2.2X%2.2X%2.2X";
+       char buf[40];
+       
+       /* black frame of 1 pixel */
+       char * dummy_xpm[] = {
+               "16 16 3 1",
+               "       c None",
+               ".      c #000000",
+               "+      c #000000",
+               "................",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               ".++++++++++++++.",
+               "................"
+       };
+
+       GdkBitmap *xpmmask;
+       GdkPixmap *xpm;
+       GtkPixmap *pixmap;
+
+       /* put correct color in xpm data */
+       sprintf(buf, FMT, color.red >> 8, color.green >> 8, color.blue >> 8);
+       dummy_xpm[3] = buf;                             
+
+       /* XXX: passing NULL as GdkWindow* seems to be possible */
+       xpm = gdk_pixmap_create_from_xpm_d(GDK_ROOT_PARENT(), &xpmmask, NULL, (gchar **) &dummy_xpm);
+       if (xpm == NULL)
+               debug_print("*** NO XPM\n");
+       pixmap = GTK_PIXMAP(gtk_pixmap_new(xpm, xpmmask)); 
+
+       
+       g_return_val_if_fail(pixmap, NULL);
+
+       gdk_pixmap_unref(xpm);
+       gdk_bitmap_unref(xpmmask);
+       return pixmap;
+}
+
+/* XXX: this function to check if menus with colors and labels should
+ * be recreated */
+gboolean labelcolors_changed(void)
+{
+       gint n;
+       for (n = 0; n < LABEL_COLORS_ELEMS; n++) {
+               if (label_colors[n].changed) 
+                       return TRUE;
+       }
+       return FALSE;
+}
+
+/* XXX: labelcolors_recreate_XXX are there to make sure everything
+ * is initialized ok, without having to call a global _xxx_init_
+ * function */
+static void labelcolors_recreate_color(gint color)
+{
+       GtkPixmap *pixmap;
+       
+       if (!(label_colors[color].changed & LCCF_COLOR))
+               return;
+       
+       pixmap = GTK_PIXMAP(labelcolors_create_color_pixmap(label_colors[color].color));
+       g_return_if_fail(pixmap);
+       
+       if (label_colors[color].pixmap)
+               gtk_widget_destroy(GTK_WIDGET(label_colors[color].pixmap));
+               
+       label_colors[color].pixmap = pixmap;            
+       label_colors[color].changed &= ~LCCF_COLOR;
+}
+
+static void labelcolors_recreate_label(gint color)
+{
+       if (!label_colors[color].changed & LCCF_LABEL)
+               return;
+
+       if (label_colors[color].label == NULL) 
+               label_colors[color].label = g_strdup(labels[color]);
+       
+       label_colors[color].changed &= ~LCCF_LABEL;
+}
+
+/* XXX: call this function everytime when you're doing important
+ * stuff with the label_colors[] array */
+static void labelcolors_recreate(gint color)
+{
+       labelcolors_recreate_label(color);
+       labelcolors_recreate_color(color);
+}
+
+static void labelcolors_recreate_all(void)
+{
+       gint n;
+       for ( n = 0; n < LABEL_COLORS_ELEMS; n++) 
+               labelcolors_recreate(n);
+}
+
+/* labelcolors_create_check_color_menu_item() - creates a color
+ * menu item with a check box */
+GtkWidget *labelcolors_create_check_color_menu_item(gint color_index)
+{
+       GtkWidget *label; 
+       GtkWidget *hbox; 
+       GtkWidget *align; 
+       GtkWidget *pixmap; 
+       GtkWidget *item;
+
+       G_RETURN_VAL_IF_INVALID_COLOR(color_index, NULL);
+
+       item  = gtk_check_menu_item_new();
+
+       labelcolors_recreate(color_index);
+
+       /* XXX: gnome-core::panel::menu.c is a great example of
+        * how to create pixmap menus */
+       label = gtk_label_new(label_colors[color_index].label);
+       
+       gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+       gtk_widget_show(label);
+       hbox = gtk_hbox_new(FALSE, 0);
+       gtk_widget_show(hbox);
+       gtk_container_add(GTK_CONTAINER(item), hbox);
+
+       align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
+       gtk_widget_show(align);
+       gtk_container_set_border_width(GTK_CONTAINER(align), 1);
+
+       gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(label_colors[color_index].pixmap));
+       gtk_widget_show(GTK_WIDGET(label_colors[color_index].pixmap));
+       gtk_widget_set_usize(align, 16, 16);
+
+       gtk_box_pack_start(GTK_BOX(hbox), align, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 4);
+
+       return item;
+}
+
+/* labelcolors_create_color_menu() - creates a color menu without 
+ * checkitems, probably for use in combo items */
+GtkWidget *labelcolors_create_color_menu(void)
+{
+       GtkWidget *label; 
+       GtkWidget *hbox; 
+       GtkWidget *align; 
+       GtkWidget *pixmap; 
+       GtkWidget *item;
+       GtkWidget *menu;
+       gint i;
+
+       labelcolors_recreate_all();
+
+       /* create the menu items. each item has its color code attached */
+       menu = gtk_menu_new();
+       gtk_object_set_data(GTK_OBJECT(menu), "label_color_menu", menu);
+
+       item = gtk_menu_item_new_with_label(_("None"));
+       gtk_menu_append(GTK_MENU(menu), item);
+       gtk_object_set_data(GTK_OBJECT(item), "color", GUINT_TO_POINTER(0));
+       gtk_widget_show(item);
+       
+       /* and the color items */
+       for (i = 0; i < LABEL_COLORS_ELEMS; i++) {
+               GtkPixmap *pixmap = labelcolors_create_color_pixmap(label_colors[i].color);
+
+               item  = gtk_menu_item_new();
+               gtk_object_set_data(GTK_OBJECT(item), "color", GUINT_TO_POINTER(i + 1));
+
+               label = gtk_label_new(label_colors[i].label);
+               
+               gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+               gtk_widget_show(label);
+               hbox = gtk_hbox_new(FALSE, 0);
+               gtk_widget_show(hbox);
+               gtk_container_add(GTK_CONTAINER(item), hbox);
+
+               align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
+               gtk_widget_show(align);
+               gtk_container_set_border_width(GTK_CONTAINER(align), 1);
+
+               gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(pixmap));
+               gtk_widget_show(GTK_WIDGET(pixmap));
+               gtk_widget_set_usize(align, 16, 16);
+
+               gtk_box_pack_start(GTK_BOX(hbox), align, FALSE, FALSE, 0);
+               gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 4);
+               
+               gtk_menu_append(GTK_MENU(menu), item);
+               gtk_widget_show(item);
+       }
+       
+       gtk_widget_show(menu);
+
+       return menu;
+}
+
+guint labelcolors_get_color_menu_active_item(GtkWidget *menu)
+{
+       GtkWidget *menuitem;
+       guint      color;
+       
+       g_return_val_if_fail( gtk_object_get_data(GTK_OBJECT(menu), "label_color_menu"), 0);
+       menuitem = gtk_menu_get_active(GTK_MENU(menu));
+       color = GPOINTER_TO_UINT( gtk_object_get_data(GTK_OBJECT(menuitem), "color") );
+       return color;
+}
+
+
diff --git a/src/labelcolors.h b/src/labelcolors.h
new file mode 100644 (file)
index 0000000..1891bb5
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2001 Hiroyuki Yamamoto & 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
+ * 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.
+ */
+
+#if !defined(LABELCOLORS_H__)
+#define LABELCOLORS_H__
+
+gint labelcolors_get_color_count(void);
+
+GdkColor labelcolors_get_color(gint color_index);
+
+gchar *labelcolors_get_color_text(gint color_index);
+
+GtkPixmap *labelcolors_create_color_pixmap(GdkColor color);
+
+gboolean labelcolors_changed(void);
+
+GtkWidget *labelcolors_create_check_color_menu_item(gint color_index);
+
+GtkWidget *labelcolors_create_color_menu(void);
+
+guint labelcolors_get_color_menu_active_item(GtkWidget *menu);
+
+#endif /* LABELCOLORS_H__ */
index 06b5f12..9a671c5 100644 (file)
@@ -111,6 +111,7 @@ static MatchParser matchparser_tab[] = {
        {MATCHING_ACTION_MARK_AS_UNREAD, "mark_as_unread"},
        {MATCHING_ACTION_FORWARD, "forward"},
        {MATCHING_ACTION_FORWARD_AS_ATTACHMENT, "forward_as_attachment"},
+       {MATCHING_ACTION_COLOR, "color"}
        /*      {MATCHING_EXECUTE, "execute"}, */
 };
 
index 29a3ca9..54d253e 100644 (file)
@@ -70,6 +70,7 @@ enum {
        MATCHING_ACTION_MARK_AS_UNREAD,
        MATCHING_ACTION_FORWARD,
        MATCHING_ACTION_FORWARD_AS_ATTACHMENT,
+       MATCHING_ACTION_COLOR,
        /* MATCHING_ACTION_EXECUTE, */
 
        MATCHING_MATCH,
index aa3c7da..c087934 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <glib.h>
 #include <gtk/gtk.h>
+#include <gtk/gtkoptionmenu.h>
 #include <gdk/gdkkeysyms.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -47,6 +48,7 @@
 #include "folder.h"
 #include "filtering.h"
 #include "addr_compl.h"
+#include "labelcolors.h"
 
 static struct Filtering {
        GtkWidget *window;
@@ -63,6 +65,9 @@ static struct Filtering {
        GtkWidget *exec_label;
        GtkWidget *exec_btn;
 
+       GtkWidget *color_label;
+       GtkWidget *color_optmenu;
+
        GtkWidget *cond_clist;
 
        /* need this to make address completion entry work */
@@ -122,7 +127,8 @@ enum {
        ACTION_MARK_AS_UNREAD = 6,
        ACTION_FORWARD = 7,
        ACTION_FORWARD_AS_ATTACHMENT = 8,
-       ACTION_EXECUTE = 9
+       ACTION_EXECUTE = 9,
+       ACTION_COLOR = 10
 };
 
 static gint get_sel_from_list(GtkList * list)
@@ -199,6 +205,8 @@ static gint prefs_filtering_get_matching_from_action(gint action_id)
                return MATCHING_ACTION_FORWARD_AS_ATTACHMENT;
        case ACTION_EXECUTE:
                return MATCHING_EXECUTE;
+       case ACTION_COLOR:
+               return MATCHING_ACTION_COLOR;
        default:
                return -1;
        }
@@ -207,7 +215,8 @@ static gint prefs_filtering_get_matching_from_action(gint action_id)
 gchar * action_text [] = {
        "Move", "Copy", "Delete",
        "Mark", "Unmark", "Mark as read", "Mark as unread",
-       "Forward", "Forward as attachment", "Execute"
+       "Forward", "Forward as attachment", "Execute",
+       "Color"
 };
 
 void prefs_filtering_open(void)
@@ -267,6 +276,8 @@ static void prefs_filtering_create(void)
        GtkWidget *dest_entry;
        GtkWidget *dest_btn;
        GtkWidget *exec_btn;
+       GtkWidget *color_label;
+       GtkWidget *color_optmenu;
 
        GtkWidget *reg_btn;
        GtkWidget *subst_btn;
@@ -280,6 +291,8 @@ static void prefs_filtering_create(void)
        GtkWidget *up_btn;
        GtkWidget *down_btn;
 
+       GtkWidget *dummy;
+
        GList *combo_items;
        gint i;
 
@@ -338,7 +351,7 @@ static void prefs_filtering_create(void)
 
        cond_entry = gtk_entry_new ();
        gtk_widget_show (cond_entry);
-       gtk_widget_set_usize (cond_entry, 300, -1);
+//     gtk_widget_set_usize (cond_entry, 200, -1);
        gtk_box_pack_start (GTK_BOX (hbox1), cond_entry, TRUE, TRUE, 0);
 
        cond_btn = gtk_button_new_with_label (_("Define ..."));
@@ -360,7 +373,7 @@ static void prefs_filtering_create(void)
 
        action_combo = gtk_combo_new ();
        gtk_widget_show (action_combo);
-       gtk_widget_set_usize (action_combo, 200, -1);
+//     gtk_widget_set_usize (action_combo, 200, -1);
        gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(action_combo)->entry),
                               FALSE);
 
@@ -442,11 +455,22 @@ static void prefs_filtering_create(void)
        gtk_widget_show (exec_label);
        gtk_misc_set_alignment (GTK_MISC (exec_label), 0, 0.5);
        gtk_box_pack_start (GTK_BOX (hbox1), exec_label, FALSE, FALSE, 0);
+       
+       color_label = gtk_label_new (_("Color"));
+       gtk_widget_show(color_label);
+       gtk_misc_set_alignment(GTK_MISC(color_label), 0, 0.5);
+       gtk_box_pack_start(GTK_BOX(hbox1), color_label, FALSE, FALSE, 0);
 
        dest_entry = gtk_entry_new ();
        gtk_widget_show (dest_entry);
-       gtk_widget_set_usize (dest_entry, 300, -1);
+//     gtk_widget_set_usize (dest_entry, 200, -1);
        gtk_box_pack_start (GTK_BOX (hbox1), dest_entry, TRUE, TRUE, 0);
+       
+       color_optmenu = gtk_option_menu_new();
+       gtk_option_menu_set_menu(GTK_OPTION_MENU(color_optmenu), 
+                                labelcolors_create_color_menu());
+//     gtk_widget_set_usize(color_optmenu, -1, -1);
+       gtk_box_pack_start(GTK_BOX(hbox1), color_optmenu, TRUE, TRUE, 0);
 
        dest_btn = gtk_button_new_with_label (_("Select ..."));
        gtk_widget_show (dest_btn);
@@ -462,6 +486,11 @@ static void prefs_filtering_create(void)
                            GTK_SIGNAL_FUNC (prefs_matcher_exec_info),
                            NULL);
 
+//     dummy = gtk_label_new("");
+//     gtk_widget_show (dummy);
+//     gtk_box_pack_start(GTK_BOX (hbox1), dummy, FALSE, FALSE, 0);
+       
+
        /* register / substitute / delete */
 
        reg_hbox = gtk_hbox_new (FALSE, 4);
@@ -536,6 +565,8 @@ static void prefs_filtering_create(void)
        gtk_signal_connect (GTK_OBJECT (down_btn), "clicked",
                            GTK_SIGNAL_FUNC (prefs_filtering_down), NULL);
 
+       gtk_widget_set_usize(window, 500, -1);
+
        gtk_widget_show_all(window);
 
        filtering.window    = window;
@@ -553,6 +584,9 @@ static void prefs_filtering_create(void)
        filtering.exec_btn = exec_btn;
 
        filtering.cond_clist   = cond_clist;
+
+       filtering.color_label   = color_label;
+       filtering.color_optmenu = color_optmenu;
 }
 
 static void prefs_filtering_update_hscrollbar(void)
@@ -695,6 +729,7 @@ static FilteringProp * prefs_filtering_dialog_to_filtering(void)
        gint action_type;
        gint account_id;
        gchar * destination;
+       gint labelcolor;
        
        cond_str = gtk_entry_get_text(GTK_ENTRY(filtering.cond_entry));
        if (*cond_str == '\0') {
@@ -719,12 +754,17 @@ static FilteringProp * prefs_filtering_dialog_to_filtering(void)
                        return NULL;
                }
                break;
+       case ACTION_COLOR:
+               labelcolor = labelcolors_get_color_menu_active_item(
+                       gtk_option_menu_get_menu(GTK_OPTION_MENU(filtering.color_optmenu)));
+               destination = NULL;     
+               break;
        default:
                destination = NULL;
                break;
        }
        
-       action = filteringaction_new(action_type, account_id, destination);
+       action = filteringaction_new(action_type, account_id, destination, labelcolor);
 
        tmp = cond_str;
        cond = matcherlist_parse(&tmp);
@@ -890,6 +930,11 @@ static void prefs_filtering_select_set(FilteringProp * prop)
                gtk_list_select_item(GTK_LIST(filtering.action_list),
                                     ACTION_EXECUTE);
                break;
+       case MATCHING_ACTION_COLOR:
+               gtk_list_select_item(GTK_LIST(filtering.action_list),
+                                    ACTION_COLOR);
+               gtk_option_menu_set_history(GTK_OPTION_MENU(filtering.color_optmenu), action->labelcolor);     
+               break;
        }
 
        g_free(matcher_str);
@@ -967,83 +1012,125 @@ static void prefs_filtering_action_select(GtkList *list,
        switch (value) {
        case ACTION_MOVE:
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
                gtk_widget_show(filtering.dest_btn);
                gtk_widget_show(filtering.dest_label);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_COPY:
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
                gtk_widget_show(filtering.dest_btn);
                gtk_widget_show(filtering.dest_label);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_DELETE:
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
                gtk_widget_hide(filtering.dest_btn);
                gtk_widget_show(filtering.dest_label);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_MARK:
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
                gtk_widget_hide(filtering.dest_btn);
                gtk_widget_show(filtering.dest_label);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_UNMARK:
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
                gtk_widget_hide(filtering.dest_btn);
                gtk_widget_show(filtering.dest_label);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_MARK_AS_READ:
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
                gtk_widget_hide(filtering.dest_btn);
                gtk_widget_show(filtering.dest_label);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_MARK_AS_UNREAD:
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, FALSE);
                gtk_widget_hide(filtering.dest_btn);
                gtk_widget_show(filtering.dest_label);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_FORWARD:
                gtk_widget_set_sensitive(filtering.account_combo, TRUE);
+               gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
                gtk_widget_hide(filtering.dest_btn);
                gtk_widget_show(filtering.dest_label);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_FORWARD_AS_ATTACHMENT:
                gtk_widget_set_sensitive(filtering.account_combo, TRUE);
+               gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
                gtk_widget_hide(filtering.dest_btn);
                gtk_widget_show(filtering.dest_label);
                gtk_widget_hide(filtering.exec_label);
                gtk_widget_hide(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
                break;
        case ACTION_EXECUTE:
                gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_show(filtering.dest_entry);
                gtk_widget_set_sensitive(filtering.dest_entry, TRUE);
                gtk_widget_hide(filtering.dest_btn);
                gtk_widget_hide(filtering.dest_label);
                gtk_widget_show(filtering.exec_label);
+               gtk_widget_set_sensitive(filtering.exec_btn, FALSE);
+               gtk_widget_show(filtering.exec_btn);
+               gtk_widget_hide(filtering.color_optmenu);
+               gtk_widget_hide(filtering.color_label);
+               break;
+       case ACTION_COLOR:
+               gtk_widget_set_sensitive(filtering.account_combo, FALSE);
+               gtk_widget_hide(filtering.dest_entry);
+               gtk_widget_hide(filtering.dest_btn);
+               gtk_widget_hide(filtering.dest_label);
+               gtk_widget_hide(filtering.exec_label);
                gtk_widget_show(filtering.exec_btn);
+               gtk_widget_set_sensitive(filtering.exec_btn, FALSE);
+               gtk_widget_show(filtering.color_optmenu);
+               gtk_widget_show(filtering.color_label);
                break;
        }
 }
index 4a00c6b..df2a165 100644 (file)
@@ -1424,6 +1424,9 @@ static void prefs_matcher_exec_info_create(void)
                 "%n:\n"
                 "%r:\n"
                 "%F:\n"
+                "\\n:\n"
+                "\\:\n"
+                "\\\":\n"
                 "%%:");
 
        gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
@@ -1440,6 +1443,9 @@ static void prefs_matcher_exec_info_create(void)
                   "Newsgroups\n"
                   "References\n"
                   "Filename - should not be modified\n"
+                  "new line\n"
+                  "escape character for quotes\n"
+                  "quote character\n"
                   "%"));
 
        gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
index b506399..60795bd 100644 (file)
@@ -43,9 +43,9 @@ typedef enum
        MSG_REALLY_DELETED = 1 << 6,            /* mbox stuff */
 
 #define MSG_LABEL_SBIT (7)             /* start bit message label */
-#define MAKE_MSG_LABEL(h, m, l) ((h) << (MSG_LABEL_SBIT+2)) | \
+#define MAKE_MSG_LABEL(h, m, l) (((h) << (MSG_LABEL_SBIT+2)) | \
                                ((m) << (MSG_LABEL_SBIT+1)) | \
-                               ((l) << (MSG_LABEL_SBIT+0))
+                               ((l) << (MSG_LABEL_SBIT+0)))
                                
        MSG_LABEL       = MAKE_MSG_LABEL(1, 1, 1),
        MSG_LABEL_NONE  = MAKE_MSG_LABEL(0, 0, 0),
@@ -126,7 +126,7 @@ typedef enum
 #define MSG_GET_LABEL(msg)             (((msg).perm_flags & MSG_LABEL))
 #define MSG_GET_LABEL_VALUE(msg)       (MSG_GET_LABEL(msg) >> MSG_LABEL_SBIT)
 /* 7 == nr. of colors excl. none */
-#define MSG_SET_LABEL_VALUE(msg, val)  MSG_SET_PERM_FLAGS(msg, ((((int)(val)) & 7) << MSG_LABEL_SBIT))
+#define MSG_SET_LABEL_VALUE(msg, val)  MSG_SET_PERM_FLAGS(msg, ((((unsigned)(val)) & 7) << MSG_LABEL_SBIT))
 #define MSG_IS_FILTERING(msg)          (((msg).tmp_flags  & MSG_FILTERING) != 0)
 
 
index 7faf77b..0f3df2f 100644 (file)
@@ -75,6 +75,7 @@
 #include "scoring.h"
 #include "prefs_folder_item.h"
 #include "filtering.h"
+#include "labelcolors.h"
 
 #include "pixmaps/dir-open.xpm"
 #include "pixmaps/mark.xpm"
@@ -356,29 +357,7 @@ static GtkItemFactoryEntry summary_popup_entries[] =
        {N_("/Select _all"),            NULL, summary_select_all, 0, NULL}
 };
 
-/* L A B E L   C O L O R   S T U F F */
-
-static struct 
-{
-       GdkColor         color;
-       gchar           *label;
-       
-       GdkPixmap       *xpm;
-       GdkBitmap       *xbm;
-       GtkPixmap       *pixmap;
-}
-label_colors[] = 
-{
-       { { 0, 0xffff, (0x99 << 8), 0x0 },              N_("Orange"),   NULL, NULL, NULL },
-       { { 0, 0xffff, 0, 0 },                          N_("Red"),      NULL, NULL, NULL },
-       { { 0, 0xffff, (0x66 << 8), 0xffff },           N_("Pink"),     NULL, NULL, NULL },
-       { { 0, 0x0, (0xcc << 8), 0xffff },              N_("Sky blue"), NULL, NULL, NULL },
-       { { 0, 0x0, 0x0, 0xffff },                      N_("Blue"),     NULL, NULL, NULL },
-       { { 0, 0x0, 0x99 << 8, 0x0 },                   N_("Green"),    NULL, NULL, NULL },
-       { { 0, 0x66 << 8, 0x33 << 8, 0x33 << 8 },       N_("Brown"),    NULL, NULL, NULL }
-};
-
-#define LABEL_COLORS_ELEMS (sizeof label_colors / sizeof label_colors[0])
+#define LABEL_COLORS_ELEMS labelcolors_get_color_count() 
 
 static void label_menu_item_activate_cb(GtkWidget *widget, gpointer data)
 {
@@ -390,7 +369,7 @@ static void label_menu_item_activate_cb(GtkWidget *widget, gpointer data)
        /* "dont_toggle" state set? */
        if (gtk_object_get_data(GTK_OBJECT(view->label_menu), "dont_toggle"))
                return;
-               
+
        summary_set_label(view, color, NULL);
 }
 
@@ -402,9 +381,9 @@ void summary_set_label_color(GtkCTree *ctree, GtkCTreeNode *node,
        GdkColor  color;
        GtkStyle *style, *prev_style, *ctree_style;
        MsgInfo  *msginfo;
-       gint     color_index; 
+       gint     color_index;
 
-       color_index = (gint) labelcolor - 1;
+       color_index = labelcolor == 0 ? -1 :  (gint) labelcolor - 1;
 
        ctree_style = gtk_widget_get_style(GTK_WIDGET(ctree));
 
@@ -429,7 +408,7 @@ void summary_set_label_color(GtkCTree *ctree, GtkCTreeNode *node,
                gtk_ctree_node_set_row_style(ctree, node, style);
        }
        else {
-               color = label_colors[color_index].color;
+               color = labelcolors_get_color(color_index);
        }               
 
        msginfo = gtk_ctree_node_get_row_data(ctree, node);
@@ -454,60 +433,6 @@ void summary_set_label(SummaryView *summaryview, guint labelcolor, GtkWidget *wi
                summary_set_label_color(ctree, GTK_CTREE_NODE(cur->data), labelcolor);
 }
 
-/* summary_create_label_pixmaps() - creates label pixmaps. perhaps a little 
- * bit contrived. */
-static void summary_create_label_pixmaps(SummaryView *summaryview)
-{
-       const char *FMT = "+      c #%2.2X%2.2X%2.2X";
-       char buf[40];
-       char * dummy_xpm[] = {
-               "16 16 3 1",
-               "       c None",
-               ".      c #000000",
-               "+      c #000000",
-               "................",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               ".++++++++++++++.",
-               "................"
-       };
-
-       gint n;
-
-       for (n = 0; n < LABEL_COLORS_ELEMS; n++) {
-               GdkBitmap *xpmmask;
-               GdkPixmap *xpm;
-               GtkPixmap *pixmap;
-
-               /* put correct color in xpm data */
-               sprintf(buf, FMT, label_colors[n].color.red >> 8,
-                       label_colors[n].color.green >> 8, 
-                       label_colors[n].color.blue >> 8);
-               dummy_xpm[3] = buf;                             
-
-               /* create pixmaps */
-               xpm = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(summaryview->scrolledwin)->window, &xpmmask, NULL, 
-                                                  (gchar **) &dummy_xpm);
-               pixmap = GTK_PIXMAP(gtk_pixmap_new(xpm, xpmmask)); 
-
-               /* store it somewhere */
-               label_colors[n].xpm = xpm;
-               label_colors[n].xbm = xpmmask;
-               label_colors[n].pixmap = pixmap;
-       }
-}
-
 static void label_menu_item_activate_item_cb(GtkMenuItem *label_menu_item, gpointer data)
 {
        SummaryView  *summaryview;
@@ -568,8 +493,6 @@ static void summary_create_label_menu(SummaryView *summaryview)
        GtkWidget *item;
        gint       i;
 
-       summary_create_label_pixmaps(summaryview);
-       
        label_menu_item = gtk_menu_item_new_with_label(_("Label"));
        gtk_menu_insert(GTK_MENU(summaryview->popupmenu), label_menu_item, LABEL_MENU_POS);
        gtk_signal_connect(GTK_OBJECT(label_menu_item), "activate",
@@ -584,11 +507,12 @@ static void summary_create_label_menu(SummaryView *summaryview)
         * index of label_colors[] as data parameter. for the None color we pass
         * an invalid (high) value. also we attach a data pointer so we can
         * always get back the SummaryView pointer. */
+        
        item = gtk_check_menu_item_new_with_label(_("None"));
        gtk_menu_append(GTK_MENU(label_menu), item);
        gtk_signal_connect(GTK_OBJECT(item), "activate",  
                GTK_SIGNAL_FUNC(label_menu_item_activate_cb),
-               GUINT_TO_POINTER(-1));
+               GUINT_TO_POINTER(0));
        gtk_object_set_data(GTK_OBJECT(item), "view", summaryview);     
        gtk_widget_show(item);
        
@@ -598,36 +522,13 @@ static void summary_create_label_menu(SummaryView *summaryview)
 
        /* create pixmap/label menu items */
        for (i = 0; i < LABEL_COLORS_ELEMS; i++) {
-               GtkWidget *label, *hbox, *align, *pixmap;
-               item = gtk_check_menu_item_new();
-               
-               label = gtk_label_new(label_colors[i].label);
-               gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
-               gtk_widget_show(label);
-               hbox = gtk_hbox_new(FALSE, 0);
-               gtk_widget_show(hbox);
-               gtk_container_add(GTK_CONTAINER(item), hbox);
-
-               align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
-               gtk_widget_show(align);
-               gtk_container_set_border_width (GTK_CONTAINER(align), 1);
-
-               pixmap = GTK_WIDGET(label_colors[i].pixmap);
-               
-               gtk_container_add (GTK_CONTAINER (align), pixmap);
-                gtk_widget_set_usize (align, 16, 16);
-               gtk_widget_show(pixmap);
-
-               gtk_box_pack_start(GTK_BOX (hbox), align, FALSE, FALSE, 0);
-               gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
-
+               item = labelcolors_create_check_color_menu_item(i);
                gtk_menu_append(GTK_MENU(label_menu), item);
                gtk_signal_connect(GTK_OBJECT(item), "activate", 
                                   GTK_SIGNAL_FUNC(label_menu_item_activate_cb),
-                                  GUINT_TO_POINTER(i + 1)); /* color index + 1 */
+                                  GUINT_TO_POINTER(i + 1));
                gtk_object_set_data(GTK_OBJECT(item), "view", summaryview);
                gtk_widget_show(item);
-
        }
        
        gtk_widget_show(label_menu);
@@ -950,8 +851,7 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item,
 {
        GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
        GtkCTreeNode *node;
-       GSList *mlist = NULL;
-       gchar *buf;
+       GSList *mlist = NULL; gchar *buf;
        gboolean is_refresh;
        guint prev_msgnum = 0;
        GtkCTreeNode *selected_node = summaryview->folderview->selected;
@@ -963,6 +863,7 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item,
 
        is_refresh = (!prefs_common.open_inbox_on_inc &&
                      item == summaryview->folder_item) ? TRUE : FALSE;
+
        if (is_refresh) {
                prev_msgnum = summary_get_current_msgnum(summaryview);
                if (prev_msgnum < 1)
@@ -982,8 +883,12 @@ gboolean summary_show(SummaryView *summaryview, FolderItem *item,
                        summary_write_cache(summaryview);
                else
                        return FALSE;
-       } else
+       }
+       else if (!summaryview->filtering_happened) {
                summary_write_cache(summaryview);
+       }
+
+       summaryview->filtering_happened = FALSE;
 
        summaryview->folderview->opened = selected_node;
 
@@ -1918,8 +1823,8 @@ static void summary_set_ctree_from_list(SummaryView *summaryview,
 
                        summary_set_marks_func(ctree, node, summaryview);
                        
-                       if ( MSG_GET_LABEL(msginfo->flags) )
-                         summary_set_label_color(ctree, node, MSG_GET_LABEL_VALUE(msginfo->flags));
+                       if (MSG_GET_LABEL(msginfo->flags))
+                               summary_set_label_color(ctree, node, MSG_GET_LABEL_VALUE(msginfo->flags));
 
                        /* preserve previous node if the message is
                           duplicated */
index 75360f8..2d9d27f 100644 (file)
@@ -144,14 +144,21 @@ private:
        /* current sorting state */
        SummarySortType sort_mode;
        GtkSortType sort_type;
+
+       /* tell filtering happened recently */
+       gboolean filtering_happened;
+
 };
 
 SummaryView    *summary_create(void);
 
 void summary_init                (SummaryView          *summaryview);
+
 gboolean summary_show            (SummaryView          *summaryview,
                                   FolderItem           *fitem,
                                   gboolean              update_cache);
+
+                                  
 void summary_clear_list                  (SummaryView          *summaryview);
 void summary_clear_all           (SummaryView          *summaryview);