[PATCH] : Search clean up (CVS)
- From: Emmanuel <e allaud wanadoo fr>
- To: balsa-list gnome org
- Subject: [PATCH] : Search clean up (CVS)
- Date: Tue, 1 Jan 2002 21:39:31 +0100
Hi all,
just a small clean-up patch for the search feature against CVS. I've just
separated the search function in a different source file for clarity.
Nothing more for now.
Bye
Manu
Common subdirectories: balsa-cvs/balsa/src/CVS and test/balsa-cvs/balsa/src/CVS
diff -uN balsa-cvs/balsa/src/Makefile.am test/balsa-cvs/balsa/src/Makefile.am
--- balsa-cvs/balsa/src/Makefile.am Tue Jan 1 21:09:53 2002
+++ test/balsa-cvs/balsa/src/Makefile.am Tue Jan 1 21:12:01 2002
@@ -2,6 +2,8 @@
if BALSA_SHOW_ALL
filter_src = \
+ balsa-search.h \
+ balsa-search.c \
filter-edit.h \
filter-edit-callbacks.c \
filter-edit-dialog.c \
diff -uN balsa-cvs/balsa/src/balsa-search.c test/balsa-cvs/balsa/src/balsa-search.c
--- balsa-cvs/balsa/src/balsa-search.c Thu Jan 1 01:00:00 1970
+++ test/balsa-cvs/balsa/src/balsa-search.c Tue Jan 1 21:32:47 2002
@@ -0,0 +1,180 @@
+/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
+/* vim:set ts=4 sw=4 ai et: */
+/* Balsa E-Mail Client
+ * Copyright (C) 1997-2001 Stuart Parmenter and others,
+ * See the file AUTHORS for a list.
+ *
+ * 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, 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.
+ */
+
+#include "config.h"
+
+#ifdef BALSA_SHOW_ALL
+
+#include "filter-funcs.h"
+#include "balsa-search.h"
+
+static GtkToggleButton*
+add_check_button(GtkWidget* table, const gchar* label, gint x, gint y)
+{
+ GtkWidget* res = gtk_check_button_new_with_label(label);
+ gtk_table_attach(GTK_TABLE(table),
+ res,
+ x, x+1, y, y+1,
+ GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
+ return GTK_TOGGLE_BUTTON(res);
+}
+
+void
+message_search(BalsaIndex * bindex,gboolean again)
+{
+ /* Condition set up for the search, it will be of type
+ CONDITION_NONE if nothing has been set up */
+ static LibBalsaCondition * cnd=NULL;
+ GSList * conditions;
+ static gboolean reverse=FALSE;
+
+ if (!cnd) {
+ cnd=libbalsa_condition_new();
+ CONDITION_SETMATCH(cnd,CONDITION_MATCH_FROM);
+ CONDITION_SETMATCH(cnd,CONDITION_MATCH_SUBJECT);
+ }
+
+
+ /* first search, so set up the match rule(s) */
+ if (!again || cnd->type==CONDITION_NONE) {
+ GnomeDialog* dia=
+ GNOME_DIALOG(gnome_dialog_new(_("Search a message"),
+ GNOME_STOCK_BUTTON_OK,
+ GNOME_STOCK_BUTTON_CANCEL,
+ NULL));
+ GtkWidget *reverse_button, *search_entry, *w, *page, *table;
+ GtkToggleButton *matching_body, *matching_from;
+ GtkToggleButton *matching_to, *matching_cc, *matching_subject;
+ gint ok;
+
+ gnome_dialog_close_hides(dia,TRUE);
+
+ reverse_button = gtk_check_button_new_with_label(_("Reverse search"));
+
+ page=gtk_table_new(2, 1, FALSE);
+ w = gtk_label_new(_("Search for:"));
+ gtk_table_attach(GTK_TABLE(page),w,0, 1, 0, 1,
+ GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
+ search_entry = gtk_entry_new_with_max_length(30);
+ gtk_table_attach(GTK_TABLE(page),search_entry,1, 2, 0, 1,
+ GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
+ gtk_box_pack_start(GTK_BOX(dia->vbox), page, FALSE, FALSE, 2);
+
+ /* builds the toggle buttons to specify fields concerned by
+ * the search. */
+ page = gtk_table_new(3, 7, FALSE);
+
+ w = gtk_frame_new(_("In:"));
+ gtk_frame_set_label_align(GTK_FRAME(w), GTK_POS_LEFT, GTK_POS_TOP);
+ gtk_frame_set_shadow_type(GTK_FRAME(w), GTK_SHADOW_ETCHED_IN);
+ gtk_table_attach(GTK_TABLE(page),
+ w,
+ 0, 3, 0, 2,
+ GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 5, 5);
+
+ table = gtk_table_new(3, 3, TRUE);
+ gtk_container_add(GTK_CONTAINER(w), table);
+
+ matching_body = add_check_button(table, _("Body"), 0, 0);
+ matching_to = add_check_button(table, _("To:"), 1, 0);
+ matching_from = add_check_button(table, _("From:"), 1, 1);
+ matching_subject = add_check_button(table, _("Subject"), 2, 0);
+ matching_cc = add_check_button(table, _("Cc:"), 2, 1);
+ gtk_box_pack_start(GTK_BOX(dia->vbox), page, FALSE, FALSE, 2);
+
+ gtk_box_pack_start(GTK_BOX(dia->vbox), gtk_hseparator_new(),
+ FALSE, FALSE, 2);
+ gtk_box_pack_start(GTK_BOX(dia->vbox), reverse_button,TRUE,TRUE,0);
+ gtk_widget_show_all(dia->vbox);
+
+ if (cnd->match.string)
+ gtk_entry_set_text(GTK_ENTRY(search_entry),cnd->match.string);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(reverse_button),reverse);
+ gtk_toggle_button_set_active(matching_body,
+ CONDITION_CHKMATCH(cnd,
+ CONDITION_MATCH_BODY));
+ gtk_toggle_button_set_active(matching_to,
+ CONDITION_CHKMATCH(cnd,
+ CONDITION_MATCH_TO));
+ gtk_toggle_button_set_active(matching_from,
+ CONDITION_CHKMATCH(cnd,CONDITION_MATCH_FROM));
+ gtk_toggle_button_set_active(matching_subject,
+ CONDITION_CHKMATCH(cnd,CONDITION_MATCH_SUBJECT));
+ gtk_toggle_button_set_active(matching_cc,
+ CONDITION_CHKMATCH(cnd,CONDITION_MATCH_CC));
+
+ gtk_widget_grab_focus(search_entry);
+ gnome_dialog_editable_enters(dia, GTK_EDITABLE(search_entry));
+ gnome_dialog_set_default(dia, 0);
+ do {
+ ok=gnome_dialog_run(dia);
+ if (ok==0) {
+ reverse=GTK_TOGGLE_BUTTON(reverse_button)->active;
+ g_free(cnd->match.string);
+ cnd->match.string =
+ g_strdup(gtk_entry_get_text(GTK_ENTRY(search_entry)));
+ cnd->match_fields=CONDITION_EMPTY;
+
+ if (gtk_toggle_button_get_active(matching_body))
+ CONDITION_SETMATCH(cnd,CONDITION_MATCH_BODY);
+ if (gtk_toggle_button_get_active(matching_to))
+ CONDITION_SETMATCH(cnd,CONDITION_MATCH_TO);
+ if (gtk_toggle_button_get_active(matching_subject))
+ CONDITION_SETMATCH(cnd,CONDITION_MATCH_SUBJECT);
+ if (gtk_toggle_button_get_active(matching_from))
+ CONDITION_SETMATCH(cnd,CONDITION_MATCH_FROM);
+ if (gtk_toggle_button_get_active(matching_cc))
+ CONDITION_SETMATCH(cnd,CONDITION_MATCH_CC);
+ if (cnd->match_fields!=CONDITION_EMPTY && cnd->match.string[0])
+
+ /* FIXME : We should print error messages, but for
+ * that we should first make find dialog non-modal
+ * balsa_information(LIBBALSA_INFORMATION_ERROR,_("You
+ * must specify at least one field to look in"));
+ * *balsa_information(LIBBALSA_INFORMATION_ERROR,_("You
+ * must provide a non-empty string")); */
+
+ ok=1;
+ else ok=-1;
+ }
+ else ok=-1;
+ }
+ while (ok==0);
+ gtk_widget_destroy(GTK_WIDGET(dia));
+ /* Here ok==1 means OK button was pressed, search is valid so let's go
+ * else cancel was pressed return */
+ if (ok!=1) return;
+ cnd->type=CONDITION_SIMPLE;
+ }
+
+ conditions=g_slist_append(NULL,cnd);
+
+ balsa_index_find(bindex,
+ FILTER_OP_OR,
+ conditions, reverse);
+
+ /* FIXME : See if this does not lead to a segfault because of
+ balsa_index_scan_info */
+ if (!f) g_slist_free(conditions);
+}
+
+#endif
diff -uN balsa-cvs/balsa/src/balsa-search.h test/balsa-cvs/balsa/src/balsa-search.h
--- balsa-cvs/balsa/src/balsa-search.h Thu Jan 1 01:00:00 1970
+++ test/balsa-cvs/balsa/src/balsa-search.h Tue Jan 1 21:08:12 2002
@@ -0,0 +1,41 @@
+/* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
+/* vim:set ts=4 sw=4 ai et: */
+/* Balsa E-Mail Client
+ * Copyright (C) 1997-2001 Stuart Parmenter and others,
+ * See the file AUTHORS for a list.
+ *
+ * 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, 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.
+ */
+
+#ifndef __BALSA_SEARCH_H__
+#define __BALSA_SEARCH_H__
+
+#include "balsa-index.h"
+
+/* This function implements the "in-place" search
+ * ie it moves the selection to the next message
+ * matching the rule the user has specified
+ * Parameters :
+ * bindex is the BalsaIndex of the message list
+ * to search in
+ * again is FALSE for the first search, TRUE for
+ * the following searches (ie it uses the rules that
+ * have already been set up)
+ */
+
+void message_search(BalsaIndex * bindex,gboolean again);
+
+#endif /* __BALSA_SEARCH_H__ */
Binary files balsa-cvs/balsa/src/balsa-search.o and test/balsa-cvs/balsa/src/balsa-search.o differ
diff -uN balsa-cvs/balsa/src/main-window.c test/balsa-cvs/balsa/src/main-window.c
--- balsa-cvs/balsa/src/main-window.c Sun Dec 16 10:29:22 2001
+++ test/balsa-cvs/balsa/src/main-window.c Tue Jan 1 21:24:42 2002
@@ -59,6 +59,7 @@
#ifdef BALSA_SHOW_ALL
#include "filter.h"
#include "filter-funcs.h"
+#include "balsa-search.h"
#endif
#include "libinit_balsa/init_balsa.h"
@@ -203,9 +204,8 @@
static void select_part_cb(BalsaMessage * bm, gpointer data);
#ifdef BALSA_SHOW_ALL
-static void find_real(BalsaIndex * bindex,gboolean again);
-static void find_cb(GtkWidget * widget, gpointer data);
-static void find_again_cb(GtkWidget * widget, gpointer data);
+static void search_cb(GtkWidget * widget, gpointer data);
+static void search_again_cb(GtkWidget * widget, gpointer data);
static void filter_dlg_cb(GtkWidget * widget, gpointer data);
static void filter_export_cb(GtkWidget * widget, gpointer data);
#endif
@@ -360,12 +360,16 @@
GNOMEUIINFO_MENU_SELECT_ALL_ITEM(select_all_cb, NULL),
#ifdef BALSA_SHOW_ALL
GNOMEUIINFO_SEPARATOR,
- GNOMEUIINFO_MENU_FIND_ITEM(find_cb, NULL),
- GNOMEUIINFO_MENU_FIND_AGAIN_ITEM(find_again_cb, NULL),
+ GNOMEUIINFO_ITEM_STOCK(N_("_Search a message..."),
+ N_("Search a message matching your criterium"),
+ search_cb, GNOME_STOCK_MENU_PROP),
+ GNOMEUIINFO_ITEM_STOCK(N_("_Search again"),
+ N_("Search a message matching the same criterium"),
+ search_again_cb, GNOME_STOCK_MENU_PROP),
/* GNOMEUIINFO_MENU_REPLACE_ITEM(NULL, NULL); */
-/* GNOMEUIINFO_SEPARATOR, */
-/* #define MENU_EDIT_PREFERENCES_POS 3 */
-/* GNOMEUIINFO_MENU_PREFERENCES_ITEM(open_preferences_manager, NULL), */
+ /* GNOMEUIINFO_SEPARATOR, */
+ /* #define MENU_EDIT_PREFERENCES_POS 3 */
+ /* GNOMEUIINFO_MENU_PREFERENCES_ITEM(open_preferences_manager, NULL), */
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_ITEM_STOCK(N_("_Filters..."), N_("Manage filters"),
filter_dlg_cb, GNOME_STOCK_MENU_PROP),
@@ -2547,183 +2551,20 @@
#ifdef BALSA_SHOW_ALL
-static GtkToggleButton*
-add_check_button(GtkWidget* table, const gchar* label, gint x, gint y)
-{
- GtkWidget* res = gtk_check_button_new_with_label(label);
- gtk_table_attach(GTK_TABLE(table),
- res,
- x, x+1, y, y+1,
- GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
- return GTK_TOGGLE_BUTTON(res);
-}
-
-static void
-find_real(BalsaIndex * bindex,gboolean again)
-{
- /* FIXME : later we could do a search based on a complete filter */
- static LibBalsaFilter * f=NULL;
- /* Condition set up for the search, it will be of type
- CONDITION_NONE if nothing has been set up */
- static LibBalsaCondition * cnd=NULL;
- GSList * conditions;
- static gboolean reverse=FALSE;
-
- if (!cnd) {
- cnd=libbalsa_condition_new();
- CONDITION_SETMATCH(cnd,CONDITION_MATCH_FROM);
- CONDITION_SETMATCH(cnd,CONDITION_MATCH_SUBJECT);
- }
-
-
- /* first search, so set up the match rule(s) */
- if (!again || (!f && cnd->type==CONDITION_NONE)) {
- GnomeDialog* dia=
- GNOME_DIALOG(gnome_dialog_new(_("Search a message"),
- GNOME_STOCK_BUTTON_OK,
- GNOME_STOCK_BUTTON_CANCEL,
- NULL));
- GtkWidget *reverse_button, *search_entry, *w, *page, *table;
- GtkToggleButton *matching_body, *matching_from;
- GtkToggleButton *matching_to, *matching_cc, *matching_subject;
- gint ok;
-
- gnome_dialog_close_hides(dia,TRUE);
-
- /* FIXME : we'll set up this callback later when selecting
- filters has been enabled
- gtk_signal_connect(GTK_OBJECT(dia),"clicked",
- find_dialog_button_cb,&f);
- */
- reverse_button = gtk_check_button_new_with_label(_("Reverse search"));
-
- page=gtk_table_new(2, 1, FALSE);
- w = gtk_label_new(_("Search for:"));
- gtk_table_attach(GTK_TABLE(page),w,0, 1, 0, 1,
- GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
- search_entry = gtk_entry_new_with_max_length(30);
- gtk_table_attach(GTK_TABLE(page),search_entry,1, 2, 0, 1,
- GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 2, 2);
- gtk_box_pack_start(GTK_BOX(dia->vbox), page, FALSE, FALSE, 2);
-
- /* builds the toggle buttons to specify fields concerned by
- * the search. */
- page = gtk_table_new(3, 7, FALSE);
-
- w = gtk_frame_new(_("In:"));
- gtk_frame_set_label_align(GTK_FRAME(w), GTK_POS_LEFT, GTK_POS_TOP);
- gtk_frame_set_shadow_type(GTK_FRAME(w), GTK_SHADOW_ETCHED_IN);
- gtk_table_attach(GTK_TABLE(page),
- w,
- 0, 3, 0, 2,
- GTK_FILL | GTK_SHRINK | GTK_EXPAND, GTK_SHRINK, 5, 5);
-
- table = gtk_table_new(3, 3, TRUE);
- gtk_container_add(GTK_CONTAINER(w), table);
-
- matching_body = add_check_button(table, _("Body"), 0, 0);
- matching_to = add_check_button(table, _("To:"), 1, 0);
- matching_from = add_check_button(table, _("From:"), 1, 1);
- matching_subject = add_check_button(table, _("Subject"), 2, 0);
- matching_cc = add_check_button(table, _("Cc:"), 2, 1);
- gtk_box_pack_start(GTK_BOX(dia->vbox), page, FALSE, FALSE, 2);
-
- gtk_box_pack_start(GTK_BOX(dia->vbox), gtk_hseparator_new(),
- FALSE, FALSE, 2);
- gtk_box_pack_start(GTK_BOX(dia->vbox), reverse_button,TRUE,TRUE,0);
- gtk_widget_show_all(dia->vbox);
-
- if (cnd->match.string)
- gtk_entry_set_text(GTK_ENTRY(search_entry),cnd->match.string);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(reverse_button),reverse);
- gtk_toggle_button_set_active(matching_body,
- CONDITION_CHKMATCH(cnd,
- CONDITION_MATCH_BODY));
- gtk_toggle_button_set_active(matching_to,
- CONDITION_CHKMATCH(cnd,
- CONDITION_MATCH_TO));
- gtk_toggle_button_set_active(matching_from,
- CONDITION_CHKMATCH(cnd,CONDITION_MATCH_FROM));
- gtk_toggle_button_set_active(matching_subject,
- CONDITION_CHKMATCH(cnd,CONDITION_MATCH_SUBJECT));
- gtk_toggle_button_set_active(matching_cc,
- CONDITION_CHKMATCH(cnd,CONDITION_MATCH_CC));
-
- gtk_widget_grab_focus(search_entry);
- gnome_dialog_editable_enters(dia, GTK_EDITABLE(search_entry));
- gnome_dialog_set_default(dia, 0);
- do {
- ok=gnome_dialog_run(dia);
- if (ok==0) {
- reverse=GTK_TOGGLE_BUTTON(reverse_button)->active;
- g_free(cnd->match.string);
- cnd->match.string =
- g_strdup(gtk_entry_get_text(GTK_ENTRY(search_entry)));
- cnd->match_fields=CONDITION_EMPTY;
-
- if (gtk_toggle_button_get_active(matching_body))
- CONDITION_SETMATCH(cnd,CONDITION_MATCH_BODY);
- if (gtk_toggle_button_get_active(matching_to))
- CONDITION_SETMATCH(cnd,CONDITION_MATCH_TO);
- if (gtk_toggle_button_get_active(matching_subject))
- CONDITION_SETMATCH(cnd,CONDITION_MATCH_SUBJECT);
- if (gtk_toggle_button_get_active(matching_from))
- CONDITION_SETMATCH(cnd,CONDITION_MATCH_FROM);
- if (gtk_toggle_button_get_active(matching_cc))
- CONDITION_SETMATCH(cnd,CONDITION_MATCH_CC);
- if (cnd->match_fields!=CONDITION_EMPTY && cnd->match.string[0])
-
- /* FIXME : We should print error messages, but for
- * that we should first make find dialog non-modal
- * balsa_information(LIBBALSA_INFORMATION_ERROR,_("You
- * must specify at least one field to look in"));
- * *balsa_information(LIBBALSA_INFORMATION_ERROR,_("You
- * must provide a non-empty string")); */
-
- ok=1;
- else ok=-1;
- }
- else ok=-1;
- }
- while (ok==0);
- gtk_widget_destroy(GTK_WIDGET(dia));
- /* Here ok==1 means OK button was pressed, search is valid so let's go
- * else cancel was pressed return */
- if (ok!=1) return;
- cnd->type=CONDITION_SIMPLE;
- }
-
- if (f) {
- GSList * lst=g_slist_append(NULL,f);
- if (!filters_prepare_to_run(lst)) return;
- g_slist_free(lst);
- conditions=f->conditions;
- }
- else conditions=g_slist_append(NULL,cnd);
-
- balsa_index_find(bindex,
- f ? f->conditions_op : FILTER_OP_OR,
- conditions, reverse);
-
- /* FIXME : See if this does not lead to a segfault because of
- balsa_index_scan_info */
- if (!f) g_slist_free(conditions);
-}
-
static void
-find_cb(GtkWidget * widget,gpointer data)
+search_cb(GtkWidget * widget,gpointer data)
{
GtkWidget * bindex;
if ((bindex=balsa_window_find_current_index(BALSA_WINDOW(data))))
- find_real(BALSA_INDEX(bindex),FALSE);
+ message_search(BALSA_INDEX(bindex),FALSE);
}
static void
-find_again_cb(GtkWidget * widget,gpointer data)
+search_again_cb(GtkWidget * widget,gpointer data)
{
GtkWidget * bindex;
if ((bindex=balsa_window_find_current_index(BALSA_WINDOW(data))))
- find_real(BALSA_INDEX(bindex),TRUE);
+ message_search(BALSA_INDEX(bindex),TRUE);
}
static void
Common subdirectories: balsa-cvs/balsa/src/pixmaps and test/balsa-cvs/balsa/src/pixmaps
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]