cpw.nader.asynclogging-3: 071c2dfd: Fixed the webkit code
morshed.nader at gmail.com
morshed.nader at gmail.com
Tue Dec 20 21:25:52 EST 2011
----------------------------------------------------------------------
Revision: 071c2dfd3ee996f70e19680dfc8384d95ecd7c70
Parent: c4aecf4d21bcf82a66ee81640b4d41cc1aca36d9
Author: morshed.nader at gmail.com
Date: 12/15/11 18:03:37
Branch: im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/071c2dfd3ee996f70e19680dfc8384d95ecd7c70
Changelog:
Fixed the webkit code
Got rid of the unnecessary locks on global variables
Changes against parent c4aecf4d21bcf82a66ee81640b4d41cc1aca36d9
patched pidgin/gtklog.c
-------------- next part --------------
============================================================
--- pidgin/gtklog.c 21765abc53efcea325655429ab6061ade45455a6
+++ pidgin/gtklog.c 32e9b991f41f55d5f5d499f874dbcf1b4a3a7da5
@@ -39,7 +39,24 @@
#include "gtkutils.h"
#include "gtkwebview.h"
+/* Helpful macros */
+#define G_OBJECT_CHECK_UNREF(obj) \
+ { \
+ if ((obj) != NULL) { \
+ g_object_unref(obj); \
+ (obj) = NULL; \
+ } \
+ }
+#define G_HASH_TABLE_CHECK_DESTROY(obj) \
+ { \
+ if ((obj) != NULL) { \
+ g_hash_table_destroy(obj); \
+ (obj) = NULL; \
+ } \
+ }
+
+
#if ! GLIB_CHECK_VERSION(2, 19, 8)
/* Fixes strict-aliasing warning */
#undef g_static_mutex_get_mutex_impl_shortcut
@@ -51,6 +68,7 @@
#endif
+/* Structures */
G_DEFINE_TYPE (PidginLogViewer, pidgin_log_viewer, GTK_TYPE_DIALOG)
enum {
@@ -82,7 +100,7 @@ struct _PidginLogViewerPrivate {
GList *logs; /**< The list of logs viewed in this viewer */
GtkTreeStore *treestore; /**< The treestore containing said logs */
GtkWidget *treeview; /**< The treeview representing said treestore */
- GtkWidget *imhtml; /**< The imhtml to display said logs */
+ GtkWidget *web_view; /**< The webkit web view to display said logs */
GtkWidget *entry; /**< The search entry, in which search terms are entered */
gchar *search; /**< The string currently being searched for */
GtkWidget *label; /**< The label at the top of the log viewer */
@@ -106,7 +124,6 @@ struct _PidginLogViewerPrivate {
#endif
};
-
typedef struct {
PidginLogViewer *log_viewer;
PurpleLog *log;
@@ -139,6 +156,7 @@ typedef struct {
} log_viewer_hash_t;
+/* Function prototypes */
static void pidgin_log_data_free(_pidgin_log_data *);
static void pidgin_window_destroy_cb(_pidgin_log_data *);
static guint log_viewer_hash(gconstpointer);
@@ -180,16 +198,12 @@ static void pidgin_log_viewer_set_select
static void pidgin_log_viewer_set_selected(PidginLogViewer *,
gboolean);
-
-
-G_LOCK_DEFINE(log_viewers);
-G_LOCK_DEFINE(syslog_viewer);
-
-
+/* Globals */
static GHashTable *log_viewers = NULL;
static PidginLogViewer *syslog_viewer = NULL;
+/* Main functions */
static void
pidgin_log_data_free(_pidgin_log_data *data)
{
@@ -345,8 +359,7 @@ search_cb(GtkWidget *button, PidginLogVi
{
_pidgin_log_data *pidgin_log_data;
PidginLogViewerPrivate *priv = PIDGIN_LOG_VIEWER_GET_PRIVATE(lv);
- GtkIMHtml *imhtml = GTK_IMHTML(pidgin_log_viewer_get_text_area(lv));
- GtkTreeStore *treestore = pidgin_log_viewer_get_tree_store(lv);
+ WebKitWebView *wv = WEBKIT_WEB_VIEW(pidgin_log_viewer_get_text_area(lv));
GtkWidget *bar;
GCancellable *cancel;
GList *logs;
@@ -362,7 +375,7 @@ search_cb(GtkWidget *button, PidginLogVi
populate_log_tree(lv);
- webkit_web_view_unmark_text_matches(WEBKIT_WEB_VIEW(lv->web_view));
+ webkit_web_view_unmark_text_matches(wv);
select_first_log(lv);
return;
@@ -372,7 +385,7 @@ search_cb(GtkWidget *button, PidginLogVi
if (old_search != NULL && !strcmp(old_search, search_term)) {
/* Searching for the same term acts as "Find Next" */
- webkit_web_view_search_text(WEBKIT_WEB_VIEW(lv->web_view), search_term, FALSE, TRUE, TRUE);
+ webkit_web_view_search_text(wv, search_term, FALSE, TRUE, TRUE);
return;
}
@@ -384,8 +397,7 @@ search_cb(GtkWidget *button, PidginLogVi
return;
pidgin_log_viewer_set_search_string(lv, search_term);
- webkit_web_view_open(WEBKIT_WEB_VIEW(lv->web_view), "about:blank"); /* clear the view */
- gtk_imhtml_clear(imhtml);
+ webkit_web_view_open(wv, "about:blank"); /* clear the view */
pidgin_log_viewer_set_selected(lv, FALSE);
pidgin_log_data = g_new0(_pidgin_log_data, 1);
@@ -442,16 +454,12 @@ destroy_cb(PidginLogViewer *lv, gint res
#endif
if (ht != NULL) {
- G_LOCK(log_viewers);
g_hash_table_remove(log_viewers, ht);
- G_UNLOCK(log_viewers);
g_free(ht->buddyname);
g_free(ht);
} else {
- G_LOCK(syslog_viewer);
syslog_viewer = NULL;
- G_UNLOCK(syslog_viewer);
}
gtk_widget_destroy(GTK_WIDGET(lv));
@@ -729,16 +737,14 @@ search_find_cb(gpointer userdata)
search_find_cb(gpointer userdata)
{
_pidgin_log_data *pidgin_log_data = userdata;
- webkit_web_view_mark_text_matches(WEBKIT_WEB_VIEW(viewer->web_view), viewer->search, FALSE, 0);
- webkit_web_view_set_highlight_text_matches(WEBKIT_WEB_VIEW(viewer->web_view), TRUE);
- webkit_web_view_search_text(WEBKIT_WEB_VIEW(viewer->web_view), viewer->search, FALSE, TRUE, TRUE);
-
if (pidgin_log_data->is_window_open) {
PidginLogViewer *lv = pidgin_log_data->log_viewer;
- GtkIMHtml *imhtml = GTK_IMHTML(pidgin_log_viewer_get_text_area(lv));
+ WebKitWebView *wv = WEBKIT_WEB_VIEW(pidgin_log_viewer_get_text_area(lv));
const gchar *search = pidgin_log_viewer_get_search_string(lv);
- gtk_imhtml_search_find(imhtml, search);
+ webkit_web_view_mark_text_matches(wv, search, FALSE, 0);
+ webkit_web_view_set_highlight_text_matches(wv, TRUE);
+ webkit_web_view_search_text(wv, search, FALSE, TRUE, TRUE);
}
pidgin_log_data_free(pidgin_log_data);
@@ -755,9 +761,8 @@ pidgin_log_read_cb(GObject *object, GAsy
PurpleLog *log = pidgin_log_data->log;
PurpleLogReadFlags flags;
PidginLogViewer *lv = pidgin_log_data->log_viewer;
- GtkIMHtml *imhtml = GTK_IMHTML(pidgin_log_viewer_get_text_area(lv));
+ WebKitWebView *wv = WEBKIT_WEB_VIEW(pidgin_log_viewer_get_text_area(lv));
GError *error = NULL;
- const gchar *search = pidgin_log_viewer_get_search_string(lv);
gchar *text;
text = purple_log_read_finish(log, res, &flags, &error);
@@ -776,28 +781,28 @@ pidgin_log_read_cb(GObject *object, GAsy
#if GTK_CHECK_VERSION(2, 20, 0)
{
PidginLogViewerPrivate *priv = PIDGIN_LOG_VIEWER_GET_PRIVATE(lv);
- gtk_widget_show(priv->imhtml);
+ gtk_widget_show(GTK_WIDGET(wv));
gtk_widget_hide(priv->spinner);
}
#endif
- gtk_imhtml_clear(imhtml);
- gtk_imhtml_set_protocol_name(imhtml,
- purple_account_get_protocol_name(purple_log_get_account(log)));
+ webkit_web_view_open(wv, "about:blank");
+ /* XXX: Not sure what to do with this just yet */
+ // gtk_imhtml_set_protocol_name(imhtml,
+ // purple_account_get_protocol_name(purple_log_get_account(log)));
+
purple_signal_emit(pidgin_log_get_handle(), "log-displaying", lv, log);
- /* gtk_imhtml_append_text is a time killer in loading logs, annoyingly */
- gtk_imhtml_append_text(imhtml, text,
- GTK_IMHTML_NO_COMMENTS | GTK_IMHTML_NO_TITLE | GTK_IMHTML_NO_SCROLL |
- (flags & PURPLE_LOG_READ_NO_NEWLINE ? GTK_IMHTML_NO_NEWLINE : 0));
+ webkit_web_view_load_html_string(wv, text, "");
+ g_free(text);
/**
* If we have something in the search bar, scroll to it in the
* current log.
*/
- if (search != NULL) {
- gtk_imhtml_search_clear(imhtml);
+ if (pidgin_log_viewer_get_search_string(lv) != NULL) {
+ webkit_web_view_unmark_text_matches(wv);
g_idle_add(search_find_cb, pidgin_log_data);
} else
pidgin_log_data_free(pidgin_log_data);
@@ -816,6 +821,7 @@ log_select_cb(GtkTreeSelection *sel, Pid
GtkTreeModel *model = GTK_TREE_MODEL(pidgin_log_viewer_get_tree_store(lv));
GtkTreeIter iter;
GCancellable *cancel;
+ WebKitWebView *wv;
if (!gtk_tree_selection_get_selected(sel, &model, &iter))
return;
@@ -848,10 +854,11 @@ log_select_cb(GtkTreeSelection *sel, Pid
g_free(bold_text);
}
+ wv = WEBKIT_WEB_VIEW(pidgin_log_viewer_get_text_area(lv));
pidgin_log_data = g_new0(_pidgin_log_data, 1);
pidgin_log_data->is_window_open = TRUE;
pidgin_log_data->total = pidgin_log_data->count = 1;
- webkit_web_view_open(WEBKIT_WEB_VIEW(viewer->web_view), "about:blank");
+ webkit_web_view_open(wv, "about:blank");
pidgin_log_data->log_viewer = lv;
pidgin_log_data->log = log;
pidgin_log_data->destroy_handler_id = g_signal_connect_swapped(lv,
@@ -859,16 +866,13 @@ log_select_cb(GtkTreeSelection *sel, Pid
cancel = g_cancellable_new();
pidgin_log_viewer_set_read_cancel(lv, cancel);
- webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(viewer->web_view), read, "");
#if GTK_CHECK_VERSION(2, 20, 0)
- webkit_web_view_unmark_text_matches(WEBKIT_WEB_VIEW(viewer->web_view));
- g_idle_add(search_find_cb, viewer);
- {
- PidginLogViewerPrivate *priv = PIDGIN_LOG_VIEWER_GET_PRIVATE(lv);
- gtk_widget_hide(priv->imhtml);
- gtk_widget_show(priv->spinner);
- }
+ {
+ PidginLogViewerPrivate *priv = PIDGIN_LOG_VIEWER_GET_PRIVATE(lv);
+ gtk_widget_hide(priv->web_view);
+ gtk_widget_show(priv->spinner);
+ }
#endif
purple_log_read_async(log, G_PRIORITY_DEFAULT, cancel,
@@ -943,9 +947,7 @@ pidgin_log_viewer_new(log_viewer_hash_t
* Store the information to later prevent duplicate windows from popping up.
*/
if (ht != NULL) {
- G_LOCK(log_viewers);
g_hash_table_insert(log_viewers, ht, g_object_ref(lv));
- G_UNLOCK(log_viewers);
}
g_signal_connect(lv, "response", G_CALLBACK(destroy_cb), ht);
@@ -1155,7 +1157,7 @@ pidgin_log_list_cb(GObject *object, GAsy
GError *error = NULL;
GList *list;
- list = purple_logs_get_logs_finish(res, &error);
+ list = purple_logs_list_logs_finish(res, &error);
pidgin_log_data->count--;
if (list == NULL) {
@@ -1181,7 +1183,7 @@ pidgin_log_system_list_cb(GObject *objec
GError *error = NULL;
GList *list;
- list = purple_logs_get_system_logs_finish(res, &error);
+ list = purple_logs_list_system_logs_finish(res, &error);
pidgin_log_data->count--;
if (list == NULL) {
@@ -1223,9 +1225,7 @@ pidgin_log_show(PurpleLogChatType chat_t
ht->buddyname = g_strdup(buddyname);
ht->account = account;
- G_LOCK(log_viewers);
lv = g_hash_table_lookup(log_viewers, ht);
- G_UNLOCK(log_viewers);
if (lv != NULL) {
gtk_window_present(GTK_WINDOW(lv));
@@ -1272,7 +1272,7 @@ pidgin_log_show(PurpleLogChatType chat_t
cancel = g_cancellable_new();
pidgin_log_viewer_set_list_cancel(lv, cancel);
- purple_logs_get_logs_async(chat_type, buddyname, account,
+ purple_logs_list_logs_async(chat_type, buddyname, account,
G_PRIORITY_DEFAULT, cancel, pidgin_log_list_cb, pidgin_log_data);
purple_logs_get_total_size_async(chat_type, buddyname, account,
G_PRIORITY_DEFAULT, cancel, pidgin_log_size_cb, pidgin_log_data);
@@ -1300,9 +1300,7 @@ pidgin_log_show_contact(PurpleContact *c
ht->chat_type = PURPLE_LOG_IM;
ht->contact = contact;
- G_LOCK(log_viewers);
lv = g_hash_table_lookup(log_viewers, ht);
- G_UNLOCK(log_viewers);
if (lv != NULL) {
gtk_window_present(GTK_WINDOW(lv));
@@ -1374,7 +1372,7 @@ pidgin_log_show_contact(PurpleContact *c
name = purple_buddy_get_name(PURPLE_BUDDY(child));
account = purple_buddy_get_account(PURPLE_BUDDY(child));
- purple_logs_get_logs_async(PURPLE_LOG_IM, name, account,
+ purple_logs_list_logs_async(PURPLE_LOG_IM, name, account,
G_PRIORITY_DEFAULT, cancel, pidgin_log_list_cb, pidgin_log_data);
purple_logs_get_total_size_async(PURPLE_LOG_IM, name, account,
G_PRIORITY_DEFAULT, cancel, pidgin_log_size_cb, pidgin_log_data);
@@ -1395,9 +1393,7 @@ pidgin_syslog_show(void)
GList *accounts;
gboolean found_account = FALSE;
- G_LOCK(syslog_viewer);
lv = syslog_viewer;
- G_UNLOCK(syslog_viewer);
if (lv != NULL) {
gtk_window_present(GTK_WINDOW(lv));
@@ -1430,16 +1426,14 @@ pidgin_syslog_show(void)
pidgin_log_data->count++;
pidgin_log_data->total++;
- purple_logs_get_system_logs_async(account, G_PRIORITY_DEFAULT,
+ purple_logs_list_system_logs_async(account, G_PRIORITY_DEFAULT,
cancel, pidgin_log_system_list_cb, pidgin_log_data);
}
g_object_unref(cancel);
if (found_account) {
- G_LOCK(syslog_viewer);
syslog_viewer = lv;
- G_UNLOCK(syslog_viewer);
} else
pidgin_log_done_cb(pidgin_log_data);
}
@@ -1473,7 +1467,7 @@ pidgin_log_viewer_get_text_area(PidginLo
{
g_return_val_if_fail(PIDGIN_IS_LOG_VIEWER(lv), NULL);
- return PIDGIN_LOG_VIEWER_GET_PRIVATE(lv)->imhtml;
+ return PIDGIN_LOG_VIEWER_GET_PRIVATE(lv)->web_view;
}
G_CONST_RETURN gchar *
@@ -1599,7 +1593,7 @@ pidgin_log_viewer_set_logs(PidginLogView
priv->logs = logs;
populate_log_tree(lv);
- gtk_imhtml_clear(GTK_IMHTML(priv->imhtml));
+ webkit_web_view_open(WEBKIT_WEB_VIEW(priv->web_view), "about:blank");
select_first_log(lv);
g_object_notify(G_OBJECT(lv), "logs");
@@ -2213,19 +2207,19 @@ pidgin_log_viewer_init(PidginLogViewer *
/* Viewer */
- frame = pidgin_create_imhtml(FALSE, &priv->imhtml, NULL, NULL);
- gtk_widget_set_name(priv->imhtml, "pidgin_log_imhtml");
- gtk_widget_set_size_request(priv->imhtml, 320, 200);
+ frame = pidgin_create_webview(FALSE, &priv->web_view, NULL, NULL);
+ gtk_widget_set_name(priv->web_view, "pidgin_log_web_view");
+ gtk_widget_set_size_request(priv->web_view, 320, 200);
gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
gtk_widget_show(frame);
+ /* Spinner */
#if GTK_CHECK_VERSION(2, 20, 0)
priv->spinner = gtk_spinner_new();
gtk_spinner_start(GTK_SPINNER(priv->spinner));
gtk_box_pack_start(GTK_BOX(vbox), priv->spinner, TRUE, FALSE, 0);
#endif
-
/* Search box */
hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
@@ -2287,15 +2281,11 @@ pidgin_log_init(void)
{
void *handle = pidgin_log_get_handle();
- G_LOCK(log_viewers);
/* XXX: Is the ht stuff leaking? */
log_viewers = g_hash_table_new_full(log_viewer_hash, log_viewer_equal,
NULL, g_object_unref);
- G_UNLOCK(log_viewers);
- G_LOCK(syslog_viewer);
syslog_viewer = NULL;
- G_UNLOCK(syslog_viewer);
purple_signal_register(handle, "log-displaying",
purple_marshal_VOID__POINTER_POINTER,
@@ -2309,17 +2299,6 @@ pidgin_log_uninit(void)
{
purple_signals_unregister_by_instance(pidgin_log_get_handle());
- G_LOCK(log_viewers);
- if (log_viewers != NULL) {
- g_hash_table_destroy(log_viewers);
- log_viewers = NULL;
- }
- G_UNLOCK(log_viewers);
-
- G_LOCK(syslog_viewer);
- if (syslog_viewer != NULL) {
- g_object_unref(syslog_viewer);
- syslog_viewer = NULL;
- }
- G_UNLOCK(syslog_viewer);
+ G_HASH_TABLE_CHECK_DESTROY(log_viewers);
+ G_OBJECT_CHECK_UNREF(syslog_viewer);
}
More information about the Commits
mailing list