2007-08-04 [colin] 2.10.0cvs89
[claws.git] / src / summary_search.c
index bd2554d180037fc3263e6fd912373c17662fe6d2..48f927b2922fde12f21b2a7cb4b80ef0e8d69262 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail 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
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -194,8 +194,8 @@ static void summary_search_create(void)
        GtkWidget *vbox1;
        GtkWidget *bool_hbox;
        GtkWidget *bool_optmenu;
-       GtkWidget *bool_menu;
-       GtkWidget *menuitem;
+       GtkListStore *menu;
+       GtkTreeIter iter;
        GtkWidget *clear_btn;
 
        GtkWidget *table1;
@@ -226,14 +226,18 @@ static void summary_search_create(void)
 
        gboolean is_searching = FALSE;
 
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "summary_search");
        gtk_window_set_title(GTK_WINDOW (window), _("Search messages"));
        gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
        gtk_container_set_border_width(GTK_CONTAINER (window), 8);
        g_signal_connect(G_OBJECT(window), "delete_event",
                         G_CALLBACK(gtk_widget_hide_on_delete), NULL);
+#ifdef MAEMO
+       maemo_connect_key_press_to_mainwindow(GTK_WINDOW(window));
+#else
        g_signal_connect(G_OBJECT(window), "key_press_event",
                         G_CALLBACK(key_pressed), NULL);
+#endif
        MANAGE_WINDOW_SIGNALS_CONNECT(window);
 
        vbox1 = gtk_vbox_new (FALSE, 0);
@@ -244,14 +248,14 @@ static void summary_search_create(void)
        gtk_widget_show(bool_hbox);
        gtk_box_pack_start(GTK_BOX(vbox1), bool_hbox, FALSE, FALSE, 0);
 
-       bool_optmenu = gtk_option_menu_new();
+       bool_optmenu = gtkut_sc_combobox_create(NULL, FALSE);
+       menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(bool_optmenu)));
        gtk_widget_show(bool_optmenu);
        gtk_box_pack_start(GTK_BOX(bool_hbox), bool_optmenu, FALSE, FALSE, 0);
 
-       bool_menu = gtk_menu_new();
-       MENUITEM_ADD(bool_menu, menuitem, _("Match any of the following"), 0);
-       MENUITEM_ADD(bool_menu, menuitem, _("Match all of the following"), 1);
-       gtk_option_menu_set_menu(GTK_OPTION_MENU(bool_optmenu), bool_menu);
+       COMBOBOX_ADD(menu, _("Match any of the following"), 0);
+       gtk_combo_box_set_active_iter(GTK_COMBO_BOX(bool_optmenu), &iter);
+       COMBOBOX_ADD(menu, _("Match all of the following"), 1);
 
        clear_btn = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
        gtk_widget_show(clear_btn);
@@ -435,7 +439,7 @@ static void summary_search_create(void)
        gtk_box_pack_start (GTK_BOX (vbox1), confirm_area, FALSE, FALSE, 0);
        gtk_widget_grab_default(next_btn);
 
-       SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, bool_menu)
+       SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, bool_optmenu)
        SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, from_entry)
        SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, to_entry)
        SET_TOGGLE_SENSITIVITY_REVERSE(adv_search_checkbtn, subject_entry)
@@ -482,6 +486,9 @@ static void summary_search_create(void)
        search_window.stop_btn = stop_btn;
        search_window.matcher_list = NULL;
        search_window.is_searching = is_searching;
+#ifdef MAEMO
+       maemo_window_full_screen_if_needed(GTK_WINDOW(search_window.window));
+#endif
 }
 
 static void summary_search_execute(gboolean backward, gboolean search_all)
@@ -496,8 +503,9 @@ static void summary_search_execute(gboolean backward, gboolean search_all)
        gboolean all_searched = FALSE;
        gboolean matched = FALSE;
        gboolean body_matched = FALSE;
-       const gchar *from_str = NULL, *to_str = NULL, *subject_str = NULL;
-       const gchar *body_str = NULL, *adv_condition = NULL;
+       gchar *from_str = NULL, *to_str = NULL, *subject_str = NULL;
+       gchar *body_str = NULL;
+       gchar *adv_condition = NULL;
        StrFindFunc str_find_func = NULL;
        gboolean is_fast = TRUE;
        gint interval = 1000;
@@ -517,7 +525,10 @@ static void summary_search_execute(gboolean backward, gboolean search_all)
                        search_window.matcher_list = NULL;
                }
                adv_condition = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.adv_condition_entry));
-               if (adv_condition[0] != '\0') {
+               if (!adv_condition)
+                       adv_condition = gtk_editable_get_chars(
+                                       GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(search_window.adv_condition_entry))),0,-1);
+               if (adv_condition && adv_condition[0] != '\0') {
 
                        /* add to history */
                        combobox_unset_popdown_strings(GTK_COMBO_BOX(search_window.adv_condition_entry));
@@ -530,6 +541,7 @@ static void summary_search_execute(gboolean backward, gboolean search_all)
                        if (!is_fast)
                                interval = 100;
                        /* TODO: check for condition parsing error and show an error dialog */
+                       g_free(adv_condition);
                } else {
                        /* TODO: warn if no search condition? (or make buttons enabled only when
                                at least one search condition has been set */
@@ -537,9 +549,8 @@ static void summary_search_execute(gboolean backward, gboolean search_all)
                        return;
                }
        } else {
-               bool_and = GPOINTER_TO_INT
-                       (menu_get_option_menu_active_user_data
-                               (GTK_OPTION_MENU(search_window.bool_optmenu)));
+               bool_and = combobox_get_active_data(
+                               GTK_COMBO_BOX(search_window.bool_optmenu));
                case_sens = gtk_toggle_button_get_active
                        (GTK_TOGGLE_BUTTON(search_window.case_checkbtn));
 
@@ -554,6 +565,25 @@ static void summary_search_execute(gboolean backward, gboolean search_all)
                subject_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.subject_entry));
                body_str    = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.body_entry));
 
+               if (!from_str)
+                       from_str = gtk_editable_get_chars(
+                                       GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(search_window.from_entry))),0,-1);
+               if (!to_str)
+                       to_str = gtk_editable_get_chars(
+                                       GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(search_window.to_entry))),0,-1);
+               if (!subject_str)
+                       subject_str = gtk_editable_get_chars(
+                                       GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(search_window.subject_entry))),0,-1);
+               if (!body_str)
+                       body_str = gtk_editable_get_chars(
+                                       GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(search_window.body_entry))),0,-1);
+
+               if (!from_str || !to_str || !subject_str || !body_str) {
+                       /* TODO: warn if no search criteria? (or make buttons enabled only when
+                        * at least one search criteria has been set */
+                       summary_unlock(summaryview);
+                       return;
+               }
                if (    (from_str[0] == '\0') &&
                                (to_str[0] == '\0') &&
                                (subject_str[0] == '\0') &&
@@ -759,6 +789,11 @@ static void summary_search_execute(gboolean backward, gboolean search_all)
                        GTK_EVENTS_FLUSH();
        }
 
+       g_free(from_str);
+       g_free(to_str);
+       g_free(subject_str);
+       g_free(body_str);
+
        search_window.is_searching = FALSE;
        summary_hide_stop_button();
        main_window_cursor_normal(summaryview->mainwin);
@@ -834,7 +869,7 @@ static void adv_condition_btn_clicked(GtkButton *button, gpointer data)
        /* re-use the current search value if it's a condition expression,
           otherwise ignore it silently */
        cond_str = gtk_combo_box_get_active_text(GTK_COMBO_BOX(search_window.adv_condition_entry));
-       if (*cond_str != '\0') {
+       if (cond_str && *cond_str != '\0') {
                matchers = matcher_parser_get_cond((gchar*)cond_str, NULL);
        }
 
@@ -960,6 +995,12 @@ static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
                }
        }
 
+       if (event && (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter)) {
+               if (!search_window.is_searching) {
+                       summary_search_execute(FALSE, FALSE);
+               }
+       }
+
        if (event && (event->keyval == GDK_Down || event->keyval == GDK_Up)) {
                if (search_window.from_entry_has_focus) {
                        combobox_set_value_from_arrow_key(