Commit 287cb066 authored by Noah Levitt's avatar Noah Levitt

2004-02-01 Noah Levitt

	* gucharmap/gucharmap-search-dialog.c:
	* gucharmap/gucharmap-search-dialog.h:
	* gucharmap/gucharmap-unicode-info.c:
	* gucharmap/gucharmap-unicode-info.h:
	* gucharmap/gucharmap-window.c: Progress bar for searching.
parent 0eca8234
2004-02-01 Noah Levitt
* gucharmap/gucharmap-search-dialog.c:
* gucharmap/gucharmap-search-dialog.h:
* gucharmap/gucharmap-unicode-info.c:
* gucharmap/gucharmap-unicode-info.h:
* gucharmap/gucharmap-window.c: Progress bar for searching.
2004-01-31 Noah Levitt
* gucharmap/gucharmap-charmap.c: PAGE_SIZE not used anymore.
......
......@@ -62,6 +62,8 @@ struct _GucharmapSearchState
gboolean dont_search;
gpointer saved_data; /* holds some data to pass back to the caller */
gint list_num_chars; /* last_index + 1 */
gboolean searching;
gint strings_checked;
};
struct _GucharmapSearchDialogPrivate
......@@ -100,16 +102,20 @@ utf8_strcasestr (const gchar *haystack,
}
static gboolean
matches (gunichar wc,
const gchar *search_string_nfd)
matches (GucharmapSearchDialog *search_dialog,
gunichar wc,
const gchar *search_string_nfd)
{
GucharmapSearchDialogPrivate *priv = GUCHARMAP_SEARCH_DIALOG_GET_PRIVATE (search_dialog);
const gchar *haystack;
gchar *haystack_nfd;
gboolean matches;
haystack = gucharmap_get_unicode_name (wc);
haystack = gucharmap_get_unicode_data_name (wc);
if (haystack)
{
priv->search_state->strings_checked++;
/* character names are ascii, so are nfd */
haystack_nfd = (gchar *) haystack;
matches = utf8_strcasestr (haystack_nfd, search_string_nfd) != NULL;
......@@ -121,6 +127,8 @@ matches (gunichar wc,
haystack = gucharmap_get_unicode_kDefinition (wc);
if (haystack)
{
priv->search_state->strings_checked++;
haystack_nfd = g_utf8_normalize (haystack, -1, G_NORMALIZE_NFD);
matches = utf8_strcasestr (haystack_nfd, search_string_nfd) != NULL;
g_free (haystack_nfd);
......@@ -247,7 +255,7 @@ idle_search (GucharmapSearchDialog *search_dialog)
continue;
/* no leading spaces */
if (matches (wc, priv->search_state->no_leading_space))
if (matches (search_dialog, wc, priv->search_state->no_leading_space))
{
if (priv->search_state->found_index == priv->search_state->curr_index)
priv->search_state->dont_search = TRUE; /* this is the only match */
......@@ -347,6 +355,8 @@ gucharmap_search_state_new (const GucharmapCodepointList *list,
g_unichar_isspace (g_utf8_get_char (search_state->no_leading_space));
search_state->no_leading_space = g_utf8_next_char (search_state->no_leading_space));
search_state->searching = FALSE;
return search_state;
}
......@@ -400,6 +410,8 @@ search_completed (GucharmapSearchDialog *search_dialog)
GucharmapSearchDialogPrivate *priv = GUCHARMAP_SEARCH_DIALOG_GET_PRIVATE (search_dialog);
gunichar found_char = gucharmap_search_state_get_found_char (priv->search_state);
priv->search_state->searching = FALSE;
g_signal_emit (search_dialog, gucharmap_search_dialog_signals[SEARCH_FINISH], 0, found_char);
if (found_char == (gunichar)(-1))
......@@ -435,9 +447,11 @@ gucharmap_search_dialog_start_search (GucharmapSearchDialog *search_dialog,
gtk_widget_set_sensitive (priv->prev_button, FALSE);
gtk_widget_set_sensitive (priv->next_button, FALSE);
g_signal_emit (search_dialog, gucharmap_search_dialog_signals[SEARCH_START], 0);
priv->search_state->searching = TRUE;
priv->search_state->strings_checked = 0;
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, (GSourceFunc) idle_search, search_dialog, (GDestroyNotify) search_completed);
g_signal_emit (search_dialog, gucharmap_search_dialog_signals[SEARCH_START], 0);
}
static void
......@@ -602,3 +616,17 @@ gucharmap_search_dialog_new (GucharmapWindow *guw)
return GTK_WIDGET (search_dialog);
}
gdouble
gucharmap_search_dialog_get_completed (GucharmapSearchDialog *search_dialog)
{
GucharmapSearchDialogPrivate *priv = GUCHARMAP_SEARCH_DIALOG_GET_PRIVATE (search_dialog);
if (priv->search_state == NULL || !priv->search_state->searching)
return -1.0;
else
{
gdouble total = gucharmap_get_unicode_data_name_count () + gucharmap_get_unihan_count ();
return (gdouble) priv->search_state->strings_checked / total;
}
}
......@@ -53,10 +53,11 @@ struct _GucharmapSearchDialogClass
void (* search_finish) (gunichar found_char);
};
GType gucharmap_search_dialog_get_type ();
GtkWidget * gucharmap_search_dialog_new (GucharmapWindow *parent);
void gucharmap_search_dialog_start_search (GucharmapSearchDialog *search_dialog,
GucharmapDirection direction);
GType gucharmap_search_dialog_get_type ();
GtkWidget * gucharmap_search_dialog_new (GucharmapWindow *parent);
void gucharmap_search_dialog_start_search (GucharmapSearchDialog *search_dialog,
GucharmapDirection direction);
gdouble gucharmap_search_dialog_get_completed (GucharmapSearchDialog *search_dialog);
G_END_DECLS
......
......@@ -235,6 +235,18 @@ gucharmap_get_unicode_data_name (gunichar uc)
return NULL;
}
gint
gucharmap_get_unicode_data_name_count ()
{
return G_N_ELEMENTS (unicode_names);
}
gint
gucharmap_get_unihan_count ()
{
return G_N_ELEMENTS (unihan);
}
#if ENABLE_UNIHAN
/* does a binary search; also caches most recent, since it will often be
......
......@@ -27,7 +27,9 @@ G_BEGIN_DECLS
/* return values are read-only */
G_CONST_RETURN gchar * gucharmap_get_unicode_name (gunichar uc);
G_CONST_RETURN gchar * gucharmap_get_unicode_data_name (gunichar uc);
gint gucharmap_get_unicode_data_name_count ();
G_CONST_RETURN gchar * gucharmap_get_unicode_category_name (gunichar uc);
gint gucharmap_get_unihan_count ();
G_CONST_RETURN gchar * gucharmap_get_unicode_kDefinition (gunichar uc);
G_CONST_RETURN gchar * gucharmap_get_unicode_kCantonese (gunichar uc);
G_CONST_RETURN gchar * gucharmap_get_unicode_kMandarin (gunichar uc);
......
......@@ -38,15 +38,6 @@
# define ICON_PATH ""
#endif
typedef struct _EntryDialog EntryDialog;
struct _EntryDialog
{
GucharmapWindow *guw;
GtkWidget *dialog;
GtkEntry *entry;
};
#define GUCHARMAP_WINDOW_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), gucharmap_window_get_type (), GucharmapWindowPrivate))
......@@ -72,6 +63,8 @@ struct _GucharmapWindowPrivate
GtkWidget *search_dialog; /* takes care of all aspects of searching */
GtkWidget *progress;
/* menu items to disable while searching */
GtkWidget *find_menu_item;
GtkWidget *find_next_menu_item;
......@@ -95,6 +88,27 @@ status_message (GtkWidget *widget,
gtk_statusbar_push (GTK_STATUSBAR (priv->status), 0, message);
}
static gboolean
update_progress_bar (GucharmapWindow *guw)
{
GucharmapWindowPrivate *priv = GUCHARMAP_WINDOW_GET_PRIVATE (guw);
gdouble fraction_completed;
fraction_completed = gucharmap_search_dialog_get_completed (GUCHARMAP_SEARCH_DIALOG (priv->search_dialog));
if (fraction_completed < 0 || fraction_completed > 1)
{
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress), 0);
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (priv->progress), NULL);
return FALSE;
}
else
{
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress), fraction_completed);
return TRUE;
}
}
static void
search_start (GucharmapSearchDialog *search_dialog,
GucharmapWindow *guw)
......@@ -109,6 +123,9 @@ search_start (GucharmapSearchDialog *search_dialog,
gtk_widget_set_sensitive (priv->find_menu_item, FALSE);
gtk_widget_set_sensitive (priv->find_next_menu_item, FALSE);
gtk_widget_set_sensitive (priv->find_prev_menu_item, FALSE);
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (priv->progress), _("Searching..."));
g_timeout_add (100, (GSourceFunc) update_progress_bar, guw);
}
static void
......@@ -118,6 +135,9 @@ search_finish (GucharmapSearchDialog *search_dialog,
{
GucharmapWindowPrivate *priv = GUCHARMAP_WINDOW_GET_PRIVATE (guw);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress), 0);
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (priv->progress), NULL);
if (found_char != (gunichar)(-1))
gucharmap_charmap_go_to_character (guw->charmap, found_char);
/* not-found dialog handled by GucharmapSearchDialog */
......@@ -638,7 +658,7 @@ status_realize (GtkWidget *status,
GucharmapWindowPrivate *priv = GUCHARMAP_WINDOW_GET_PRIVATE (guw);
/* increase the height a bit so it doesn't resize itself */
gtk_widget_set_size_request (priv->status, -1, priv->status->allocation.height + 3);
gtk_widget_set_size_request (priv->status, -1, priv->status->allocation.height + 9);
}
static void
......@@ -671,11 +691,26 @@ pack_stuff_in_window (GucharmapWindow *guw)
gtk_box_pack_start (GTK_BOX (big_vbox), priv->text_to_copy_container, FALSE, FALSE, 0);
g_signal_connect (guw->charmap->chartable, "activate", G_CALLBACK (insert_character_in_text_to_copy), guw);
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (big_vbox), hbox, FALSE, FALSE, 0);
priv->status = gtk_statusbar_new ();
gtk_box_pack_start (GTK_BOX (big_vbox), priv->status, FALSE, FALSE, 0);
gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (priv->status), FALSE);
gtk_box_pack_start (GTK_BOX (hbox), priv->status, TRUE, TRUE, 0);
gtk_widget_show (priv->status);
g_signal_connect (priv->status, "realize", G_CALLBACK (status_realize), guw);
priv->progress = gtk_progress_bar_new ();
gtk_box_pack_start (GTK_BOX (hbox), priv->progress, FALSE, FALSE, 0);;
#if 0
grip = gtk_statusbar_new ();
gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (grip), TRUE);
gtk_box_pack_start (GTK_BOX (hbox), grip, FALSE, FALSE, 0);;
#endif
gtk_widget_show_all (hbox);
g_signal_connect (guw->charmap, "status-message", G_CALLBACK (status_message), guw);
gtk_widget_show (big_vbox);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment