summaryrefslogtreecommitdiff
path: root/libpurple
diff options
context:
space:
mode:
authorGary Kramlich <grim@reaperworld.com>2023-01-06 02:12:12 -0600
committerGary Kramlich <grim@reaperworld.com>2023-01-06 02:12:12 -0600
commit96d40245d68d7d2bc59ef09edc17f56f05035b40 (patch)
treec10ff26f9ffec810eac3fd59c36e6f555072e319 /libpurple
parente544b5412649a0823fbb933406872984141e7106 (diff)
downloadpidgin-96d40245d68d7d2bc59ef09edc17f56f05035b40.tar.gz
Replace the account-actions-changed signal with an actions-changed signal on PurpleProtocolActions
We also propagate the PurpleProtocolActions::actions-changed signal from the PurpleProtocolManager::account-actions-changed signal if the protocol implements the PurpleProtocolActions interface. Testing Done: Build the docs and ran the unit tests. I also put a temporary action in the demo protocol plugin and called `purple_protocol_actions_changed` after the demo protocol connected. I will have another pull request that makes this a permenent action, but I want to convert the demo protocol plugin to subclass PurpleConnection before doing so as that will be accounting of everything *much* easier. Reviewed at https://reviews.imfreedom.org/r/2168/
Diffstat (limited to 'libpurple')
-rw-r--r--libpurple/accounts.c4
-rw-r--r--libpurple/protocols.c11
-rw-r--r--libpurple/protocols.h14
-rw-r--r--libpurple/protocols/demo/purpledemoprotocol.c2
-rw-r--r--libpurple/protocols/jabber/adhoccommands.c8
-rw-r--r--libpurple/purpleprotocolactions.c40
-rw-r--r--libpurple/purpleprotocolactions.h13
-rw-r--r--libpurple/purpleprotocolmanager.c58
8 files changed, 116 insertions, 34 deletions
diff --git a/libpurple/accounts.c b/libpurple/accounts.c
index 331dd877f2..dbd61e05e2 100644
--- a/libpurple/accounts.c
+++ b/libpurple/accounts.c
@@ -649,10 +649,6 @@ purple_accounts_init(void)
G_TYPE_NONE, 3, PURPLE_TYPE_ACCOUNT,
PURPLE_TYPE_STATUS, PURPLE_TYPE_STATUS);
- purple_signal_register(handle, "account-actions-changed",
- purple_marshal_VOID__POINTER, G_TYPE_NONE, 1,
- PURPLE_TYPE_ACCOUNT);
-
purple_signal_register(handle, "account-signed-on",
purple_marshal_VOID__POINTER, G_TYPE_NONE, 1,
PURPLE_TYPE_ACCOUNT);
diff --git a/libpurple/protocols.c b/libpurple/protocols.c
index acb8f1de58..8193ecc372 100644
--- a/libpurple/protocols.c
+++ b/libpurple/protocols.c
@@ -42,17 +42,6 @@
/* Protocol API */
/**************************************************************************/
void
-purple_protocol_got_account_actions(PurpleAccount *account)
-{
-
- g_return_if_fail(account != NULL);
- g_return_if_fail(purple_account_is_connected(account));
-
- purple_signal_emit(purple_accounts_get_handle(), "account-actions-changed",
- account);
-}
-
-void
purple_protocol_got_user_idle(PurpleAccount *account, const char *name,
gboolean idle, time_t idle_time)
{
diff --git a/libpurple/protocols.h b/libpurple/protocols.h
index 9cd134c6ee..eb812f530f 100644
--- a/libpurple/protocols.h
+++ b/libpurple/protocols.h
@@ -41,20 +41,6 @@ G_BEGIN_DECLS
/**************************************************************************/
/**
- * purple_protocol_got_account_actions:
- * @account: The account.
- *
- * Notifies Purple that our account's actions have changed. This is only
- * called after the initial connection. Emits the account-actions-changed
- * signal.
- *
- * This is meant to be called from protocols.
- *
- * See <link linkend="accounts-account-actions-changed"><literal>"account-actions-changed"</literal></link>
- */
-void purple_protocol_got_account_actions(PurpleAccount *account);
-
-/**
* purple_protocol_got_user_idle:
* @account: The account the user is on.
* @name: The name of the buddy.
diff --git a/libpurple/protocols/demo/purpledemoprotocol.c b/libpurple/protocols/demo/purpledemoprotocol.c
index f1481e7789..47e33acca8 100644
--- a/libpurple/protocols/demo/purpledemoprotocol.c
+++ b/libpurple/protocols/demo/purpledemoprotocol.c
@@ -39,7 +39,7 @@ static PurpleConnection *
purple_demo_protocol_create_connection(PurpleProtocol *protocol,
PurpleAccount *account,
const char *password,
- GError **error)
+ G_GNUC_UNUSED GError **error)
{
g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
diff --git a/libpurple/protocols/jabber/adhoccommands.c b/libpurple/protocols/jabber/adhoccommands.c
index 320d95a79c..22d0cb35b2 100644
--- a/libpurple/protocols/jabber/adhoccommands.c
+++ b/libpurple/protocols/jabber/adhoccommands.c
@@ -266,8 +266,12 @@ jabber_adhoc_got_server_list(JabberStream *js, G_GNUC_UNUSED const char *from,
js->commands = g_list_append(js->commands,cmd);
}
- if (js->state == JABBER_STREAM_CONNECTED)
- purple_protocol_got_account_actions(purple_connection_get_account(js->gc));
+ if (js->state == JABBER_STREAM_CONNECTED) {
+ PurpleProtocol *protocol = purple_connection_get_protocol(js->gc);
+
+ purple_protocol_actions_changed(PURPLE_PROTOCOL_ACTIONS(protocol),
+ purple_connection_get_account(js->gc));
+ }
}
static void
diff --git a/libpurple/purpleprotocolactions.c b/libpurple/purpleprotocolactions.c
index d9b50bbaa9..3a52f2c98f 100644
--- a/libpurple/purpleprotocolactions.c
+++ b/libpurple/purpleprotocolactions.c
@@ -22,6 +22,12 @@
#include "purpleprotocolactions.h"
+enum {
+ SIG_ACTIONS_CHANGED,
+ N_SIGNALS,
+};
+static guint signals[N_SIGNALS] = {0, };
+
/******************************************************************************
* GObject Implementation
*****************************************************************************/
@@ -29,8 +35,28 @@ G_DEFINE_INTERFACE(PurpleProtocolActions, purple_protocol_actions,
PURPLE_TYPE_PROTOCOL)
static void
-purple_protocol_actions_default_init(G_GNUC_UNUSED PurpleProtocolActionsInterface *iface)
-{
+purple_protocol_actions_default_init(PurpleProtocolActionsInterface *iface) {
+ /**
+ * PurpleProtocolActions::actions-changed:
+ * @self: The instance.
+ * @account: The [class@Account] whose actions changed.
+ *
+ * A signal that is emitted to tell interested parties that the actions
+ * have changed.
+ *
+ * Since: 3.0.0
+ */
+ signals[SIG_ACTIONS_CHANGED] = g_signal_new_class_handler(
+ "actions-changed",
+ G_TYPE_FROM_INTERFACE(iface),
+ G_SIGNAL_RUN_LAST,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 1,
+ PURPLE_TYPE_ACCOUNT);
}
/******************************************************************************
@@ -86,3 +112,13 @@ purple_protocol_actions_get_menu(PurpleProtocolActions *actions,
return NULL;
}
+
+void
+purple_protocol_actions_changed(PurpleProtocolActions *actions,
+ PurpleAccount *account)
+{
+ g_return_if_fail(PURPLE_IS_PROTOCOL_ACTIONS(actions));
+ g_return_if_fail(PURPLE_IS_ACCOUNT(account));
+
+ g_signal_emit(actions, signals[SIG_ACTIONS_CHANGED], 0, account);
+}
diff --git a/libpurple/purpleprotocolactions.h b/libpurple/purpleprotocolactions.h
index 3c82150257..329740201e 100644
--- a/libpurple/purpleprotocolactions.h
+++ b/libpurple/purpleprotocolactions.h
@@ -119,6 +119,19 @@ GActionGroup *purple_protocol_actions_get_action_group(PurpleProtocolActions *ac
*/
GMenu *purple_protocol_actions_get_menu(PurpleProtocolActions *actions, PurpleConnection *connection);
+/**
+ * purple_protocol_actions_changed:
+ * @actions: The instance.
+ * @account: The [class@Account] whose actions changed.
+ *
+ * Emits the [signal@ProtocolActions::actions-changed] signal. This is meant to
+ * be called by [iface@ProtocolActions] implementations when actions have
+ * changed.
+ *
+ * Since: 3.0.0
+ */
+void purple_protocol_actions_changed(PurpleProtocolActions *actions, PurpleAccount *account);
+
G_END_DECLS
#endif /* PURPLE_PROTOCOL_ACTIONS_H */
diff --git a/libpurple/purpleprotocolmanager.c b/libpurple/purpleprotocolmanager.c
index f9e8cd58f6..9d74661110 100644
--- a/libpurple/purpleprotocolmanager.c
+++ b/libpurple/purpleprotocolmanager.c
@@ -21,9 +21,12 @@
#include "purpleprotocolmanager.h"
#include "purpleprivate.h"
+#include "purpleprotocolactions.h"
+
enum {
SIG_REGISTERED,
SIG_UNREGISTERED,
+ SIG_ACCOUNT_ACTIONS_CHANGED,
N_SIGNALS,
};
static guint signals[N_SIGNALS] = {0, };
@@ -38,6 +41,19 @@ struct _PurpleProtocolManager {
static PurpleProtocolManager *default_manager = NULL;
/******************************************************************************
+ * Callbacks
+ *****************************************************************************/
+static void
+purple_protocol_manager_actions_changed_cb(PurpleProtocolActions *actions,
+ PurpleAccount *account,
+ gpointer data)
+{
+ /* Propagate the actions-changed signal. */
+ g_signal_emit(data, signals[SIG_ACCOUNT_ACTIONS_CHANGED], 0, actions,
+ account);
+}
+
+/******************************************************************************
* GListModel Implementation
*****************************************************************************/
static GType
@@ -145,6 +161,31 @@ purple_protocol_manager_class_init(PurpleProtocolManagerClass *klass) {
G_TYPE_NONE,
1,
PURPLE_TYPE_PROTOCOL);
+
+ /**
+ * PurpleProtocolManager::account-actions-changed:
+ * @manager: The instance.
+ * @protocol: The [class@Protocol] whose actions changed.
+ * @account: The [class@Account] whose actions changed.
+ *
+ * This is a propagation of the [signal@ProtocolActions::actions-changed]
+ * signal and will only be emitted for protocols that implement
+ * [iface@ProtocolActions].
+ *
+ * Since: 3.0.0
+ */
+ signals[SIG_ACCOUNT_ACTIONS_CHANGED] = g_signal_new_class_handler(
+ "account-actions-changed",
+ G_OBJECT_CLASS_TYPE(klass),
+ G_SIGNAL_RUN_LAST,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 2,
+ PURPLE_TYPE_PROTOCOL,
+ PURPLE_TYPE_ACCOUNT);
}
/******************************************************************************
@@ -194,6 +235,13 @@ purple_protocol_manager_register(PurpleProtocolManager *manager,
g_signal_emit(G_OBJECT(manager), signals[SIG_REGISTERED], 0, protocol);
+ /* Connect the signals we want to propagate. */
+ if(PURPLE_IS_PROTOCOL_ACTIONS(protocol)) {
+ g_signal_connect_object(protocol, "actions-changed",
+ G_CALLBACK(purple_protocol_manager_actions_changed_cb),
+ manager, 0);
+ }
+
return TRUE;
}
@@ -218,9 +266,19 @@ purple_protocol_manager_unregister(PurpleProtocolManager *manager,
if(g_hash_table_remove(manager->protocols, id)) {
guint position;
+
if(g_ptr_array_find(manager->list, protocol, &position)) {
g_ptr_array_remove_index(manager->list, position);
g_list_model_items_changed(G_LIST_MODEL(manager), position, 1, 0);
+
+ /* Disconnect our signal handlers for tracking changes if this is a
+ * PurpleProtocolActions implementation.
+ */
+ if(PURPLE_IS_PROTOCOL_ACTIONS(protocol)) {
+ g_signal_handlers_disconnect_by_func(protocol,
+ purple_protocol_manager_actions_changed_cb,
+ manager);
+ }
}
g_signal_emit(G_OBJECT(manager), signals[SIG_UNREGISTERED], 0,