diff options
-rw-r--r-- | libpurple/purpleconversationmanager.c | 17 | ||||
-rw-r--r-- | libpurple/purpleconversationmanager.h | 24 | ||||
-rw-r--r-- | libpurple/purpleprotocolmanager.c | 20 | ||||
-rw-r--r-- | libpurple/purpleprotocolmanager.h | 23 |
4 files changed, 84 insertions, 0 deletions
diff --git a/libpurple/purpleconversationmanager.c b/libpurple/purpleconversationmanager.c index bb1922d890..93c805f697 100644 --- a/libpurple/purpleconversationmanager.c +++ b/libpurple/purpleconversationmanager.c @@ -178,6 +178,23 @@ purple_conversation_manager_is_registered(PurpleConversationManager *manager, NULL, NULL); } +void +purple_conversation_manager_foreach(PurpleConversationManager *manager, + PurpleConversationManagerForeachFunc func, + gpointer data) +{ + GHashTableIter iter; + gpointer key; + + g_return_if_fail(PURPLE_IS_CONVERSATION_MANAGER(manager)); + g_return_if_fail(func != NULL); + + g_hash_table_iter_init(&iter, manager->conversations); + while(g_hash_table_iter_next(&iter, &key, NULL)) { + func(PURPLE_CONVERSATION(key), data); + } +} + GList * purple_conversation_manager_get_all(PurpleConversationManager *manager) { g_return_val_if_fail(PURPLE_IS_CONVERSATION_MANAGER(manager), NULL); diff --git a/libpurple/purpleconversationmanager.h b/libpurple/purpleconversationmanager.h index a0252aa8d2..d4183c1be9 100644 --- a/libpurple/purpleconversationmanager.h +++ b/libpurple/purpleconversationmanager.h @@ -44,6 +44,18 @@ G_DECLARE_FINAL_TYPE(PurpleConversationManager, purple_conversation_manager, PURPLE, CONVERSATION_MANAGER, GObject) /** + * PurpleConversationManagerForeachFunc: + * @conversation: The #PurpleConversation instance. + * @data: User supplied data. + * + * A function to be used as a callback with + * purple_conversation_manager_foreach(). + * + * Since: 3.0.0 + */ +typedef void (*PurpleConversationManagerForeachFunc)(PurpleConversation *conversation, gpointer data); + +/** * purple_conversation_manager_get_default: * * Gets the default instance of #PurpleConversationManager. This instance @@ -96,6 +108,18 @@ gboolean purple_conversation_manager_unregister(PurpleConversationManager *manag gboolean purple_conversation_manager_is_registered(PurpleConversationManager *manager, PurpleConversation *conversation); /** + * purple_conversation_manager_foreach: + * @manager: The #PurpleConversationManager instance. + * @func: (scope call): The #PurpleConversationManagerForeachFunc to call. + * @data: User data to pass to @func. + * + * Calls @func for each #PurpleConversation that @manager knows about. + * + * Since: 3.0.0 + */ +void purple_conversation_manager_foreach(PurpleConversationManager *manager, PurpleConversationManagerForeachFunc func, gpointer data); + +/** * purple_conversation_manager_get_all: * @manager: The #PurpleConversationManager instance. * diff --git a/libpurple/purpleprotocolmanager.c b/libpurple/purpleprotocolmanager.c index 50649ca3fb..1157fd151f 100644 --- a/libpurple/purpleprotocolmanager.c +++ b/libpurple/purpleprotocolmanager.c @@ -218,6 +218,26 @@ purple_protocol_manager_find(PurpleProtocolManager *manager, const gchar *id) { return PURPLE_PROTOCOL(value); } +void +purple_protocol_manager_foreach(PurpleProtocolManager *manager, + PurpleProtocolManagerForeachFunc func, + gpointer data) +{ + GHashTableIter iter; + PurpleProtocolManagerPrivate *priv = NULL; + gpointer value; + + g_return_if_fail(PURPLE_IS_PROTOCOL_MANAGER(manager)); + g_return_if_fail(func != NULL); + + priv = purple_protocol_manager_get_instance_private(manager); + + g_hash_table_iter_init(&iter, priv->protocols); + while(g_hash_table_iter_next(&iter, NULL, &value)) { + func(PURPLE_PROTOCOL(value), data); + } +} + GList * purple_protocol_manager_get_all(PurpleProtocolManager *manager) { PurpleProtocolManagerPrivate *priv = NULL; diff --git a/libpurple/purpleprotocolmanager.h b/libpurple/purpleprotocolmanager.h index 5180a8fa83..d7ce07538b 100644 --- a/libpurple/purpleprotocolmanager.h +++ b/libpurple/purpleprotocolmanager.h @@ -88,6 +88,17 @@ struct _PurpleProtocolManagerClass { }; /** + * PurpleProtocolManagerForeachFunc: + * @protocol: The #PurpleProtocol instance. + * @data: User supplied data. + * + * A function to be used as a callback with purple_protocol_manager_foreach(). + * + * Since: 3.0.0 + */ +typedef void (*PurpleProtocolManagerForeachFunc)(PurpleProtocol *protocol, gpointer data); + +/** * purple_protocol_manager_get_default: * * Gets the default #PurpleProtocolManager instance. @@ -142,6 +153,18 @@ gboolean purple_protocol_manager_unregister(PurpleProtocolManager *manager, Purp PurpleProtocol *purple_protocol_manager_find(PurpleProtocolManager *manager, const gchar *id); /** + * purple_protocol_manager_foreach: + * @manager: The #PurpleProtocolManager instance. + * @func: (scope call): The #PurpleProtocolManagerForeachFunc to call. + * @data: User data to pass to @func. + * + * Calls @func for each #PurpleProtocol that @manager knows about. + * + * Since: 3.0.0 + */ +void purple_protocol_manager_foreach(PurpleProtocolManager *manager, PurpleProtocolManagerForeachFunc func, gpointer data); + +/** * purple_protocol_manager_get_all: * @manager: The #PurpleProtocolManager instance. * |