pidgin/pidgin

fccbea158b51
Parents 53a9d24d5be2
Children 893ae9164a8e
Add a get_prefix method to the PurpleProtocolActions interface

This make it much easier for protocol authors to keep track of things, but we
do fall back to using the id of the protocol for the prefix if get_prefix is
not implemented.

Testing Done:
Verified the fallback works, then changed the prefix in the demo protocol plugin and verified everything still functioned.

Reviewed at https://reviews.imfreedom.org/r/1547/
--- a/libpurple/protocols/demo/purpledemoprotocolactions.c Fri Jul 29 00:47:59 2022 -0500
+++ b/libpurple/protocols/demo/purpledemoprotocolactions.c Fri Jul 29 01:13:51 2022 -0500
@@ -153,6 +153,11 @@
/******************************************************************************
* PurpleProtocolActions Implementation
*****************************************************************************/
+static const gchar *
+purple_demo_protocol_get_prefix(G_GNUC_UNUSED PurpleProtocolActions *actions) {
+ return "prpl-demo";
+}
+
static GActionGroup *
purple_demo_protocol_get_action_group(PurpleProtocolActions *actions,
PurpleConnection *connection)
@@ -206,6 +211,7 @@
void
purple_demo_protocol_actions_init(PurpleProtocolActionsInterface *iface) {
+ iface->get_prefix = purple_demo_protocol_get_prefix;
iface->get_action_group = purple_demo_protocol_get_action_group;
iface->get_menu = purple_demo_protocol_get_menu;
}
--- a/libpurple/purpleprotocolactions.c Fri Jul 29 00:47:59 2022 -0500
+++ b/libpurple/purpleprotocolactions.c Fri Jul 29 01:13:51 2022 -0500
@@ -35,6 +35,24 @@
/******************************************************************************
* Public API
*****************************************************************************/
+const gchar *
+purple_protocol_actions_get_prefix(PurpleProtocolActions *actions) {
+ PurpleProtocolActionsInterface *iface = NULL;
+
+ g_return_val_if_fail(PURPLE_IS_PROTOCOL_ACTIONS(actions), NULL);
+
+ iface = PURPLE_PROTOCOL_ACTIONS_GET_IFACE(actions);
+ if(iface != NULL) {
+ if(iface->get_prefix != NULL) {
+ return iface->get_prefix(actions);
+ } else {
+ return purple_protocol_get_id(PURPLE_PROTOCOL(actions));
+ }
+ }
+
+ return NULL;
+}
+
GActionGroup *
purple_protocol_actions_get_action_group(PurpleProtocolActions *actions,
PurpleConnection *connection)
--- a/libpurple/purpleprotocolactions.h Fri Jul 29 00:47:59 2022 -0500
+++ b/libpurple/purpleprotocolactions.h Fri Jul 29 01:13:51 2022 -0500
@@ -48,6 +48,8 @@
/**
* PurpleProtocolActionsInterface:
+ * @get_prefix: The prefix used for the actions in the group. If this isn't
+ * implemented, the id of the protocol will be used instead.
* @get_action_group: Returns the actions the protocol can perform. If actions
* depend on connectivity, connect to the relevant signals
* on the @connection and signal the action has changed with
@@ -67,6 +69,8 @@
GTypeInterface parent;
/*< public >*/
+ const gchar *(*get_prefix)(PurpleProtocolActions *actions);
+
GActionGroup *(*get_action_group)(PurpleProtocolActions *actions, PurpleConnection *connection);
GMenu *(*get_menu)(PurpleProtocolActions *actions);
@@ -78,6 +82,18 @@
G_BEGIN_DECLS
/**
+ * purple_protocol_actions_get_prefix:
+ * @actions: The PurpleProtocolActions instance.
+ *
+ * The prefix that should be used when inserting the action group into widgets.
+ *
+ * Returns: Gets the prefix for the name of the actions in @actions.
+ *
+ * Since: 3.0.0
+ */
+const gchar *purple_protocol_actions_get_prefix(PurpleProtocolActions *actions);
+
+/**
* purple_protocol_actions_get_action_group:
* @actions: The PurpleProtocolActions instance.
* @connection: The [class@Connection] instance.
--- a/pidgin/pidginaccountsenabledmenu.c Fri Jul 29 00:47:59 2022 -0500
+++ b/pidgin/pidginaccountsenabledmenu.c Fri Jul 29 01:13:51 2022 -0500
@@ -93,7 +93,7 @@
connection);
if(G_IS_ACTION_GROUP(action_group)) {
GApplication *application = g_application_get_default();
- const gchar *prefix = purple_protocol_get_id(protocol);
+ const gchar *prefix = purple_protocol_actions_get_prefix(actions);
pidgin_application_add_action_group(PIDGIN_APPLICATION(application),
prefix, action_group);
@@ -122,6 +122,7 @@
protocol = purple_account_get_protocol(account);
if(PURPLE_IS_PROTOCOL_ACTIONS(protocol)) {
PurpleAccountManager *manager = NULL;
+ PurpleProtocolActions *actions = PURPLE_PROTOCOL_ACTIONS(protocol);
GList *enabled_accounts = NULL;
gboolean found = FALSE;
@@ -142,7 +143,7 @@
if(!found) {
GApplication *application = g_application_get_default();
- const gchar *prefix = purple_protocol_get_id(protocol);
+ const gchar *prefix = purple_protocol_actions_get_prefix(actions);
pidgin_application_add_action_group(PIDGIN_APPLICATION(application),
prefix, NULL);