pidgin: 2397ba22: Add an autojoin connection signal

rlaager at pidgin.im rlaager at pidgin.im
Sun Apr 18 18:40:41 EDT 2010


-----------------------------------------------------------------
Revision: 2397ba22512c2bb9c2e3d67b9b0e38ced723db05
Ancestor: 2ea80f9dd3cbd78edd4aa3dbe3b686684e251304
Author: rlaager at pidgin.im
Date: 2010-04-18T22:39:01
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/2397ba22512c2bb9c2e3d67b9b0e38ced723db05

Modified files:
        doc/connection-signals.dox finch/gntblist.c
        libpurple/connection.c pidgin/gtkblist.c

ChangeLog: 

Add an autojoin connection signal

UIs should use this so plugins can delay autojoining by blocking this
signal and re-emitting it later.  For example, IRC Helper now delays
autojoins until after it has identified with NickServ/AuthServ/etc.

-------------- next part --------------
============================================================
--- doc/connection-signals.dox	0fc6ad225dbc7c7d1a023790c315e8a58a9fcd3f
+++ doc/connection-signals.dox	2a46e279d035eb69077efaa667447f836cb5ae3b
@@ -3,6 +3,7 @@
  @signals
   @signal signing-on
   @signal signed-on
+  @signal autojoin
   @signal signing-off
   @signal signed-off
   @signal connection-error
@@ -30,6 +31,21 @@ void (*signed_on)(PurpleConnection *gc);
   @param gc The connection that has signed on.
  @endsignaldef
 
+ @signaldef autojoin
+  @signalproto
+gboolean (*autojoin)(PurpleConnection *gc);
+  @endsignalproto
+  @signaldesc
+   Emitted when a connection has signed on, after the signed-on signal, to
+   signal UIs to autojoin chats if they wish.  UIs should connect to this
+   with @c PURPLE_SIGNAL_PRIORITY_HIGHEST to allow plugins to block this
+   signal before the UI sees it and then re-emit it later.
+  @param gc The connection that has signed on.
+  @return @c TRUE if the signal was handled or @c FALSE otherwise.  In
+          practice, the return value is irrelevant, as it really only
+          exists so plugins can block the UI's autojoin.
+ @endsignaldef
+
  @signaldef signing-off
   @signalproto
 void (*signing_off)(PurpleConnection *gc);
============================================================
--- finch/gntblist.c	4e066847490916f1e54e19797e3344f67716dfd1
+++ finch/gntblist.c	016c02d877d8f782f6ace66343f8e7fb1d77d9e7
@@ -144,7 +144,7 @@ static void update_buddy_display(PurpleB
 static void blist_show(PurpleBuddyList *list);
 static void update_node_display(PurpleBlistNode *buddy, FinchBlist *ggblist);
 static void update_buddy_display(PurpleBuddy *buddy, FinchBlist *ggblist);
-static void account_signed_on_cb(PurpleConnection *pc, gpointer null);
+static gboolean account_autojoin_cb(PurpleConnection *pc, gpointer null);
 static void finch_request_add_buddy(PurpleAccount *account, const char *username, const char *grp, const char *alias);
 static void menu_group_set_cb(GntMenuItem *item, gpointer null);
 
@@ -2213,8 +2213,10 @@ void finch_blist_init()
 	purple_prefs_connect_callback(finch_blist_get_handle(),
 			PREF_ROOT "/grouping", redraw_blist, NULL);
 
-	purple_signal_connect(purple_connections_get_handle(), "signed-on", purple_blist_get_handle(),
-			G_CALLBACK(account_signed_on_cb), NULL);
+	purple_signal_connect_priority(purple_connections_get_handle(),
+	                               "autojoin", purple_blist_get_handle(),
+			               G_CALLBACK(account_autojoin_cb), NULL,
+	                               PURPLE_SIGNAL_PRIORITY_HIGHEST);
 
 	finch_blist_install_manager(&default_manager);
 
@@ -2684,10 +2686,11 @@ auto_join_chats(gpointer data)
 	return FALSE;
 }
 
-static void
-account_signed_on_cb(PurpleConnection *gc, gpointer null)
+static gboolean
+account_autojoin_cb(PurpleConnection *gc, gpointer null)
 {
 	g_idle_add(auto_join_chats, gc);
+	return TRUE;
 }
 
 static void toggle_pref_cb(GntMenuItem *item, gpointer n)
============================================================
--- libpurple/connection.c	56265112fe3e22b67168eb522ffe432d60772546
+++ libpurple/connection.c	8200ea1fe0052c750f69d1b202349daeb43acd17
@@ -372,6 +372,7 @@ purple_connection_set_state(PurpleConnec
 		purple_blist_add_account(account);
 
 		purple_signal_emit(purple_connections_get_handle(), "signed-on", gc);
+		purple_signal_emit_return_1(purple_connections_get_handle(), "autojoin", gc);
 
 		serv_set_permit_deny(gc);
 
@@ -715,6 +716,11 @@ purple_connections_init(void)
 	                       purple_value_new(PURPLE_TYPE_ENUM),
 	                       purple_value_new(PURPLE_TYPE_STRING));
 
+	purple_signal_register(handle, "autojoin",
+	                       purple_marshal_BOOLEAN__POINTER, NULL, 1,
+	                       purple_value_new(PURPLE_TYPE_SUBTYPE,
+	                                        PURPLE_SUBTYPE_CONNECTION));
+
 }
 
 void
============================================================
--- pidgin/gtkblist.c	5651dfd8b7add119e80ad5a25e53b8b6616772db
+++ pidgin/gtkblist.c	59572bc5415328dec42852173febb8e6d216f911
@@ -7461,7 +7461,7 @@ PidginBuddyList *pidgin_blist_get_defaul
 	return gtkblist;
 }
 
-static void account_signon_cb(PurpleConnection *gc, gpointer z)
+static gboolean autojoin_cb(PurpleConnection *gc, gpointer data)
 {
 	PurpleAccount *account = purple_connection_get_account(gc);
 	PurpleBlistNode *gnode, *cnode;
@@ -7487,6 +7487,9 @@ static void account_signon_cb(PurpleConn
 				serv_join_chat(gc, chat->components);
 		}
 	}
+
+	/* Stop processing; we handled the autojoins. */
+	return TRUE;
 }
 
 void *
@@ -7563,10 +7566,6 @@ void pidgin_blist_init(void)
 
 	cached_emblems = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 
-	purple_signal_connect(purple_connections_get_handle(), "signed-on",
-						gtk_blist_handle, PURPLE_CALLBACK(account_signon_cb),
-						NULL);
-
 	/* Initialize prefs */
 	purple_prefs_add_none(PIDGIN_PREFS_ROOT "/blist");
 	purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/blist/show_buddy_icons", TRUE);
@@ -7625,6 +7624,9 @@ void pidgin_blist_init(void)
 	purple_signal_connect(purple_blist_get_handle(), "buddy-privacy-changed",
 			gtk_blist_handle, PURPLE_CALLBACK(pidgin_blist_update_privacy_cb), NULL);
 
+	purple_signal_connect_priority(purple_connections_get_handle(), "autojoin",
+	                               gtk_blist_handle, PURPLE_CALLBACK(autojoin_cb),
+	                               NULL, PURPLE_SIGNAL_PRIORITY_HIGHEST);
 }
 
 void
@@ -7740,7 +7742,6 @@ static void sort_method_alphabetical(Pur
 		return;
 	}
 
-
 	if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(gtkblist->treemodel), &more_z, &groupiter)) {
 		gtk_tree_store_insert(gtkblist->treemodel, iter, &groupiter, 0);
 		return;


More information about the Commits mailing list