Mercurial > pidgin.yaz
changeset 7535:f771759739c1
[gaim-migrate @ 8148]
Log viewer search.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 17 Nov 2003 03:40:17 +0000 |
parents | 5f1531ec872a |
children | 41ba5e3b2844 |
files | plugins/history.c src/gtklog.c src/gtklog.h src/log.c |
diffstat | 4 files changed, 67 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/history.c Mon Nov 17 02:40:11 2003 +0000 +++ b/plugins/history.c Mon Nov 17 03:40:17 2003 +0000 @@ -41,10 +41,14 @@ gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(gtkconv->imhtml), &end, 0, TRUE, 0, 0); g_free(history); - for (;logs;logs = logs->next) { + while (logs) { GaimLog *log = logs->data; + GList *logs2; g_free(log->name); g_free(log); + logs2 = logs->next; + g_list_free_1(logs); + logs = logs2; } }
--- a/src/gtklog.c Mon Nov 17 02:40:11 2003 +0000 +++ b/src/gtklog.c Mon Nov 17 03:40:17 2003 +0000 @@ -32,6 +32,7 @@ #include "log.h" static GHashTable *log_viewers = NULL; +static void populate_log_tree(GaimGtkLogViewer *lv); struct log_viewer_hash_t { char *screenname; @@ -61,17 +62,67 @@ return ret; } +static void search_cb(GtkWidget *button, GaimGtkLogViewer *lv) +{ + const char *search_term = gtk_entry_get_text(GTK_ENTRY(lv->entry)); + GList *logs; + GdkCursor *cursor = gdk_cursor_new(GDK_WATCH); + + if (lv->search) + g_free(lv->search); + + gtk_tree_store_clear(lv->treestore); + if (strlen(search_term) == 0) {/* reset the tree */ + populate_log_tree(lv); + lv->search = NULL; + gtk_imhtml_search_clear(lv->imhtml); + return; + } + + lv->search = g_strdup(search_term); + + gdk_window_set_cursor(lv->window->window, cursor); + while (gtk_events_pending()) + gtk_main_iteration(); + gdk_cursor_unref(cursor); + + for (logs = lv->logs; logs != NULL; logs = logs->next) { + char *read = gaim_log_read((GaimLog*)logs->data, NULL); + if (gaim_strcasestr(read, search_term)) { + GtkTreeIter iter; + GaimLog *log = logs->data; + char title[64]; + strftime(title, sizeof(title), "%c", localtime(&log->time)); + gtk_tree_store_append (lv->treestore, &iter, NULL); + gtk_tree_store_set(lv->treestore, &iter, + 0, title, + 1, log, -1); + } + } + + + cursor = gdk_cursor_new(GDK_LEFT_PTR); + gdk_window_set_cursor(lv->window->window, cursor); + gdk_cursor_unref(cursor); +} + static gboolean destroy_cb(GtkWidget *w, gint resp, struct log_viewer_hash_t *ht) { GaimGtkLogViewer *lv = g_hash_table_lookup(log_viewers, ht); g_hash_table_remove(log_viewers, ht); g_free(ht->screenname); g_free(ht); - for (;lv->logs;lv->logs = lv->logs->next) { + while (lv->logs) { GaimLog *log = lv->logs->data; + GList *logs2; g_free(log->name); g_free(log); + logs2 = lv->logs->next; + g_list_free_1(lv->logs); + lv->logs = logs2; } + if (lv->search) + g_free(lv->search); g_free(lv); gtk_widget_destroy(w); @@ -107,6 +158,10 @@ gtk_imhtml_append_text(GTK_IMHTML(viewer->imhtml), read, GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_TITLE | GTK_IMHTML_NO_SCROLL | ((flags & GAIM_LOG_READ_NO_NEWLINE) ? GTK_IMHTML_NO_NEWLINE : 0)); + + if (viewer->search) + gtk_imhtml_search_find(viewer->imhtml, viewer->search); + g_free(read); g_free(title); } @@ -235,6 +290,9 @@ lv->entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(hbox), lv->entry, TRUE, TRUE, 0); button = gtk_button_new_from_stock(GTK_STOCK_FIND); + g_signal_connect (G_OBJECT (button), "pressed", + G_CALLBACK (search_cb), + lv); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); gtk_widget_show_all(lv->window);
--- a/src/gtklog.h Mon Nov 17 02:40:11 2003 +0000 +++ b/src/gtklog.h Mon Nov 17 03:40:17 2003 +0000 @@ -42,6 +42,7 @@ GtkWidget *entry; /**< The search entry, in which search terms are * entered */ GaimLogReadFlags flags; /**< The most recently used log flags */ + char *search; /**< The string currently being searched for */ };
--- a/src/log.c Mon Nov 17 02:40:11 2003 +0000 +++ b/src/log.c Mon Nov 17 03:40:17 2003 +0000 @@ -70,9 +70,10 @@ char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags) { + int mflags; g_return_val_if_fail(log && log->logger, NULL); if (log->logger->read) { - char *ret = (log->logger->read)(log, flags); + char *ret = (log->logger->read)(log, flags ? flags : &mflags); gaim_str_strip_cr(ret); return ret; }