gobjectification: bc36b447: purple_type_connect and family.
sadrul at pidgin.im
sadrul at pidgin.im
Thu Jun 26 00:20:45 EDT 2008
-----------------------------------------------------------------
Revision: bc36b4476fa34ad71049111027423b7988510af5
Ancestor: 54a3f6c27532f476dfd8b1725f7166ba84ff2fce
Author: sadrul at pidgin.im
Date: 2008-06-26T04:08:55
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/bc36b4476fa34ad71049111027423b7988510af5
Modified files:
libpurple/pobject.c libpurple/pobject.h
ChangeLog:
purple_type_connect and family.
-------------- next part --------------
============================================================
--- libpurple/pobject.c b59936961f6309c69a306a519247081b0f4f1977
+++ libpurple/pobject.c 87f1ae3fbf40bf300b6a9658b01cd7f52fae8d30
@@ -122,3 +122,64 @@ int purple_object_get_int(PurpleObject *
return ret;
}
+/**
+ * Signal emission hooks utility function
+ */
+typedef struct
+{
+ GCallback callback;
+ gpointer user_data;
+ GConnectFlags flags;
+ GQuark detail;
+} PObjectConnectHook;
+
+static gboolean
+signal_emission_hook_fn(GSignalInvocationHint *hint, guint nparams,
+ const GValue *pvalues, gpointer data)
+{
+ PObjectConnectHook *hook = data;
+ PurpleObject *obj = PURPLE_OBJECT(g_value_get_object(pvalues + 0));
+ if (g_signal_handler_find(obj,
+ G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA | G_SIGNAL_MATCH_DETAIL,
+ hint->signal_id, hook->detail, NULL,
+ hook->callback, hook->user_data) == 0) {
+ gboolean swap = (hook->flags & G_CONNECT_SWAPPED);
+ gboolean after = (hook->flags & G_CONNECT_AFTER);
+ GClosure *closure = (swap ? g_cclosure_new_swap : g_cclosure_new)
+ (hook->callback, hook->user_data, NULL);
+ g_signal_connect_closure_by_id(obj, hint->signal_id, hook->detail, closure, after);
+ g_closure_invoke(closure, NULL, nparams, pvalues, hint);
+ }
+ return TRUE;
+}
+
+gulong
+purple_type_connect(GType type, const char *detailed_signal, GCallback callback,
+ gpointer data)
+{
+ return purple_type_connect_flags(type, detailed_signal, callback, data, 0);
+}
+
+gulong
+purple_type_connect_flags(GType type, const char *detailed_signal, GCallback callback,
+ gpointer data, GConnectFlags flags)
+{
+ PObjectConnectHook *hook;
+ guint signal_id;
+ GQuark detail;
+
+ g_type_class_unref(g_type_class_ref(type));
+
+ if (!g_signal_parse_name(detailed_signal, type, &signal_id, &detail, TRUE))
+ return 0;
+
+ hook = g_new0(PObjectConnectHook, 1);
+ hook->callback = callback;
+ hook->user_data = data;
+ hook->flags = flags;
+ hook->detail = detail;
+
+ return g_signal_add_emission_hook(signal_id, detail,
+ signal_emission_hook_fn, hook, g_free);
+}
+
============================================================
--- libpurple/pobject.h 18fe9cec069e515633b56a33dea53ecdc2b83f88
+++ libpurple/pobject.h 98224c7cc165bb6470ec000a56ef3ab2260dc9be
@@ -63,6 +63,11 @@ int purple_object_get_int(PurpleObject *
int purple_object_get_int(PurpleObject *pobj, const char *prop);
+gulong purple_type_connect(GType type, const char *signal, GCallback callback, gpointer data);
+
+gulong purple_type_connect_flags(GType type, const char *signal, GCallback callback,
+ gpointer data, GConnectFlags flags);
+
G_END_DECLS
#endif /* PURPLE_OBJECT_H */
More information about the Commits
mailing list