aboutsummaryrefslogtreecommitdiffstats
path: root/mail/mail-search.c
diff options
context:
space:
mode:
Diffstat (limited to 'mail/mail-search.c')
-rw-r--r--mail/mail-search.c209
1 files changed, 84 insertions, 125 deletions
diff --git a/mail/mail-search.c b/mail/mail-search.c
index 4d7a4c4ed6..c1d42e6f4c 100644
--- a/mail/mail-search.c
+++ b/mail/mail-search.c
@@ -30,7 +30,6 @@
#include "mail-search.h"
#include "e-searching-tokenizer.h"
-#include <gal/widgets/e-unicode.h>
#include <gtkhtml/gtkhtml-search.h>
#include <gtkhtml/htmlengine.h>
#include <libgnomeui/gnome-window-icon.h>
@@ -106,43 +105,31 @@ mail_search_redisplay_message (MailSearch *ms)
}
static void
-mail_search_set_subject (MailSearch *ms, const gchar *subject)
+mail_search_set_subject (MailSearch *ms, const char *subject)
{
- gchar *utf8_subject = NULL;
- gchar *gtk_subject = NULL;
-
+ char *utf8_subject = NULL;
+
if (subject && *subject) {
-
utf8_subject = g_strdup (subject);
-
+
if (g_utf8_validate (utf8_subject, -1, NULL)) {
-
- const gint ARBITRARY_CUTOFF = 40;
-
- if (g_utf8_strlen (utf8_subject, -1) > ARBITRARY_CUTOFF) {
- gchar *p = g_utf8_offset_to_pointer (utf8_subject, ARBITRARY_CUTOFF);
+#define ARBITRARY_CUTOFF 40
+ if (g_utf8_strlen (utf8_subject, -1) > ARBITRARY_CUTOFF + 3) {
+ char *p = g_utf8_offset_to_pointer (utf8_subject, ARBITRARY_CUTOFF);
+
strcpy (p, "...");
}
-
} else {
/* If the subject contains bad utf8, don't show anything in the frame label. */
g_free (utf8_subject);
utf8_subject = NULL;
}
-
- if (utf8_subject) {
- gtk_subject = utf8_subject;
- utf8_subject = NULL;
- }
} else {
-
- gtk_subject = g_strdup (_("(Untitled Message)"));
-
+ utf8_subject = g_strdup (_("(Untitled Message)"));
}
-
- gtk_frame_set_label (GTK_FRAME (ms->msg_frame), gtk_subject);
-
- g_free (gtk_subject);
+
+ gtk_frame_set_label (GTK_FRAME (ms->msg_frame), utf8_subject);
+
g_free (utf8_subject);
}
@@ -154,7 +141,7 @@ static void
toggled_case_cb (GtkToggleButton *b, MailSearch *ms)
{
ms->case_sensitive = gtk_toggle_button_get_active (b);
-
+
e_searching_tokenizer_set_primary_case_sensitivity (mail_search_tokenizer (ms),
ms->case_sensitive);
mail_search_redisplay_message (ms);
@@ -174,45 +161,38 @@ static void
dialog_destroy_cb (GtkWidget *w, MailSearch *ms)
{
ESearchingTokenizer *st = mail_search_tokenizer (ms);
-
+
e_searching_tokenizer_set_primary_search_string (st, NULL);
mail_search_redisplay_message (ms);
}
static void
-dialog_clicked_cb (GtkWidget *w, gint button_number, MailSearch *ms)
+dialog_clicked_cb (GtkWidget *widget, gint button_number, MailSearch *ms)
{
ESearchingTokenizer *st = mail_search_tokenizer (ms);
if (button_number == 0) { /* "Search" */
-
- char *search_text, *tmp;
-
- tmp = gtk_editable_get_chars (GTK_EDITABLE (ms->entry), 0, -1);
-
- g_strstrip (tmp);
- search_text = e_utf8_from_gtk_string ((GtkWidget *) ms->entry, tmp);
- g_free (tmp);
-
- if (search_text && *search_text) {
+ char *search_text;
+ search_text = gtk_editable_get_chars (GTK_EDITABLE (ms->entry), 0, -1);
+ g_strstrip (search_text);
+
+ if (search_text && *search_text) {
if (ms->last_search && !strcmp (ms->last_search, search_text)) {
if (! gtk_html_engine_search_next (ms->mail->html)) {
g_free (ms->last_search);
ms->last_search = NULL;
}
-
} else {
-
g_free (ms->last_search);
ms->last_search = NULL;
-
+
e_searching_tokenizer_set_primary_search_string (st, search_text);
e_searching_tokenizer_set_primary_case_sensitivity (st, ms->case_sensitive);
-
+
mail_search_redisplay_message (ms);
-
+
if (gtk_html_engine_search (ms->mail->html, search_text,
ms->case_sensitive, ms->search_forward,
FALSE)) {
@@ -220,33 +200,27 @@ dialog_clicked_cb (GtkWidget *w, gint button_number, MailSearch *ms)
}
}
}
-
-
+
g_free (search_text);
-
} else if (button_number == 1) { /* "Close" */
- gtk_widget_destroy (w);
+ gtk_widget_destroy (widget);
}
}
static void
-begin_cb (ESearchingTokenizer *st, gchar *foo, MailSearch *ms)
+begin_cb (ESearchingTokenizer *st, char *foo, MailSearch *ms)
{
- const gchar *subject;
-
+ const char *subject;
+
if (ms && ms->mail && ms->mail->current_message) {
-
subject = ms->mail->current_message->subject;
-
+
if (subject == NULL)
subject = _("Untitled Message");
-
} else {
-
subject = _("Empty Message");
-
}
-
+
gtk_label_set_text (GTK_LABEL (ms->count_label), "0");
mail_search_set_subject (ms, subject);
}
@@ -254,7 +228,8 @@ begin_cb (ESearchingTokenizer *st, gchar *foo, MailSearch *ms)
static void
match_cb (ESearchingTokenizer *st, MailSearch *ms)
{
- gchar buf[16];
+ char buf[16];
+
g_snprintf (buf, 16, "%d", e_searching_tokenizer_match_count (st));
gtk_label_set_text (GTK_LABEL (ms->count_label), buf);
}
@@ -263,7 +238,7 @@ static void
entry_run_search(GtkWidget *w, MailSearch *ms)
{
/* run search when enter pressed on widget */
- gtk_dialog_response((GtkDialog *)ms, GTK_RESPONSE_ACCEPT);
+ gtk_dialog_response ((GtkDialog *) ms, GTK_RESPONSE_ACCEPT);
}
void
@@ -273,7 +248,6 @@ mail_search_construct (MailSearch *ms, MailDisplay *mail)
GtkWidget *matches_hbox;
GtkWidget *toggles_hbox;
GtkWidget *frame_vbox;
-
GtkWidget *entry;
GtkWidget *count_label;
GtkWidget *case_check;
@@ -283,35 +257,31 @@ mail_search_construct (MailSearch *ms, MailDisplay *mail)
GtkWidget *button;
GtkWidget *msg_hbox;
GtkWidget *msg_frame;
-
+
g_return_if_fail (ms != NULL && IS_MAIL_SEARCH (ms));
g_return_if_fail (mail != NULL && IS_MAIL_DISPLAY (mail));
-
+
/* Basic set-up */
-
+
ms->mail = mail;
- g_object_ref((mail));
-
- gtk_window_set_title((GtkWindow *)ms, _("Find in Message"));
-
- button = gtk_button_new_from_stock(GTK_STOCK_FIND);
- gtk_button_set_label((GtkButton *)button, _("Search"));
- gtk_dialog_add_action_widget((GtkDialog*)ms, button, GTK_RESPONSE_ACCEPT);
- gtk_dialog_add_button((GtkDialog *)ms, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
- gtk_dialog_set_default_response((GtkDialog *)ms, GTK_RESPONSE_ACCEPT);
-
+ g_object_ref (mail);
+
+ gtk_window_set_title ((GtkWindow *) ms, _("Find in Message"));
+
+ button = gtk_button_new_from_stock (GTK_STOCK_FIND);
+ gtk_button_set_label ((GtkButton *) button, _("Search"));
+ gtk_dialog_add_action_widget ((GtkDialog*) ms, button, GTK_RESPONSE_ACCEPT);
+ gtk_dialog_add_button ((GtkDialog *) ms, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+ gtk_dialog_set_default_response ((GtkDialog *) ms, GTK_RESPONSE_ACCEPT);
+
ms->search_forward = TRUE;
ms->case_sensitive = FALSE;
-
- ms->begin_handler = g_signal_connect((ms->mail->html->engine->ht),
- "begin",
- G_CALLBACK (begin_cb),
- ms);
- ms->match_handler = g_signal_connect((ms->mail->html->engine->ht),
- "match",
- G_CALLBACK (match_cb),
- ms);
-
+
+ ms->begin_handler = g_signal_connect (ms->mail->html->engine->ht, "begin",
+ G_CALLBACK (begin_cb), ms);
+ ms->match_handler = g_signal_connect (ms->mail->html->engine->ht, "match",
+ G_CALLBACK (match_cb), ms);
+
/* Construct the dialog contents. */
msg_hbox = gtk_hbox_new (FALSE, 0);
@@ -319,43 +289,43 @@ mail_search_construct (MailSearch *ms, MailDisplay *mail)
matches_hbox = gtk_hbox_new (FALSE, 0);
toggles_hbox = gtk_hbox_new (FALSE, 0);
frame_vbox = gtk_vbox_new (FALSE, 0);
-
+
entry = gtk_entry_new ();
count_label = gtk_label_new ("0");
-
+
msg_frame = gtk_frame_new (NULL);
-
+
case_check = gtk_check_button_new_with_label (_("Case Sensitive"));
#if 0
fwd_check = gtk_check_button_new_with_label (_("Search Forward"));
#endif
-
+
ms->entry = entry;
ms->count_label = count_label;
-
+
ms->msg_frame = msg_frame;
-
+
if (mail->current_message->subject && *mail->current_message->subject)
mail_search_set_subject (ms, mail->current_message->subject);
else
mail_search_set_subject (ms, NULL);
-
+
#if 0
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fwd_check), ms->search_forward);
#endif
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (case_check), ms->case_sensitive);
-
+
gtk_box_pack_start (GTK_BOX (msg_hbox), GTK_WIDGET (msg_frame), FALSE, FALSE, 3);
-
+
gtk_box_pack_start (GTK_BOX (find_hbox), gtk_label_new (_("Find:")), FALSE, FALSE, 3);
gtk_box_pack_start (GTK_BOX (find_hbox), entry, TRUE, TRUE, 3);
gtk_box_pack_start (GTK_BOX (matches_hbox), gtk_hbox_new (FALSE, 0), TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (matches_hbox), gtk_label_new (_("Matches:")), FALSE, FALSE, 3);
gtk_box_pack_start (GTK_BOX (matches_hbox), count_label, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (matches_hbox), gtk_hbox_new (FALSE, 0), TRUE, TRUE, 0);
-
+
gtk_box_pack_start (GTK_BOX (toggles_hbox), case_check, FALSE, FALSE, 4);
-
+
/*
* Disabling the forward/backward search button because there are problems with it
* (related to how gtkhtml handles searches), the GUI freeze is upon us, and I
@@ -366,48 +336,37 @@ mail_search_construct (MailSearch *ms, MailDisplay *mail)
#if 0
gtk_box_pack_start (GTK_BOX (toggles_hbox), fwd_check, FALSE, FALSE, 4);
#endif
-
+
gtk_box_pack_start (GTK_BOX (frame_vbox), find_hbox, TRUE, TRUE, 8);
gtk_box_pack_start (GTK_BOX (frame_vbox), matches_hbox, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (frame_vbox), toggles_hbox, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (msg_frame), GTK_WIDGET (frame_vbox));
-
+
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (ms)->vbox), msg_hbox, TRUE, TRUE, 0);
-
+
gtk_widget_grab_focus (entry); /* Give focus to entry by default */
- g_signal_connect(entry, "activate", G_CALLBACK(entry_run_search), ms);
+ g_signal_connect (entry, "activate", G_CALLBACK (entry_run_search), ms);
gnome_window_icon_set_from_file (GTK_WINDOW (ms), EVOLUTION_ICONSDIR "/find-message.xpm");
-
+
gtk_widget_show_all (msg_hbox);
gtk_widget_show_all (find_hbox);
gtk_widget_show_all (matches_hbox);
gtk_widget_show_all (toggles_hbox);
-
+
/* Hook up signals */
-
- g_signal_connect((case_check),
- "toggled",
- G_CALLBACK (toggled_case_cb),
- ms);
+
+ g_signal_connect (case_check, "toggled", G_CALLBACK (toggled_case_cb), ms);
#if 0
- g_signal_connect((fwd_check),
- "toggled",
- G_CALLBACK (toggled_fwd_cb),
- ms);
+ g_signal_connect (fwd_check, "toggled", G_CALLBACK (toggled_fwd_cb), ms);
#endif
- g_signal_connect((ms),
- "clicked",
- G_CALLBACK (dialog_clicked_cb),
- ms);
-
- gtk_signal_connect_object (GTK_OBJECT (ms),
- "destroy",
+ g_signal_connect (ms, "clicked", G_CALLBACK (dialog_clicked_cb), ms);
+
+ gtk_signal_connect_object (GTK_OBJECT (ms), "destroy",
G_CALLBACK (dialog_destroy_cb),
GTK_OBJECT (ms));
-
- gtk_signal_connect_object (GTK_OBJECT (ms->mail),
- "destroy",
+
+ gtk_signal_connect_object (GTK_OBJECT (ms->mail), "destroy",
G_CALLBACK (gtk_widget_destroy),
GTK_OBJECT (ms));
}
@@ -415,13 +374,13 @@ mail_search_construct (MailSearch *ms, MailDisplay *mail)
GtkWidget *
mail_search_new (MailDisplay *mail)
{
- gpointer ptr;
-
+ GtkWidget *widget;
+
g_return_val_if_fail (mail && IS_MAIL_DISPLAY (mail), NULL);
-
- ptr = g_object_new(mail_search_get_type (), NULL);
- mail_search_construct (MAIL_SEARCH (ptr), mail);
-
- return GTK_WIDGET (ptr);
+
+ widget = g_object_new (mail_search_get_type (), NULL);
+ mail_search_construct (MAIL_SEARCH (widget), mail);
+
+ return widget;
}