Tue, 24 Sep 2024 21:28:06 -0500
Add a tags property to Purple.Command
Testing Done:
Ran the tests under valgrind and called in the turtles for good measure.
Bugs closed: PIDGIN-17973
Reviewed at https://reviews.imfreedom.org/r/3523/
--- a/libpurple/purplecommand.c Tue Sep 24 21:26:59 2024 -0500 +++ b/libpurple/purplecommand.c Tue Sep 24 21:28:06 2024 -0500 @@ -35,6 +35,7 @@ int priority; char *source; char *summary; + PurpleTags *tags; guint use_count; }; @@ -46,6 +47,7 @@ PROP_PRIORITY, PROP_SOURCE, PROP_SUMMARY, + PROP_TAGS, PROP_USE_COUNT, N_PROPERTIES, }; @@ -134,6 +136,7 @@ g_clear_pointer(&command->name, g_free); g_clear_pointer(&command->source, g_free); g_clear_pointer(&command->summary, g_free); + g_clear_object(&command->tags); G_OBJECT_CLASS(purple_command_parent_class)->finalize(obj); } @@ -163,6 +166,9 @@ case PROP_SUMMARY: g_value_set_string(value, purple_command_get_summary(command)); break; + case PROP_TAGS: + g_value_set_object(value, purple_command_get_tags(command)); + break; case PROP_USE_COUNT: g_value_set_uint(value, purple_command_get_use_count(command)); break; @@ -207,7 +213,8 @@ } static void -purple_command_init(G_GNUC_UNUSED PurpleCommand *command) { +purple_command_init(PurpleCommand *command) { + command->tags = purple_tags_new(); } static void @@ -306,6 +313,18 @@ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); /** + * PurpleCommand:tags: + * + * The [class@Tags] for the command. + * + * Since: 3.0 + */ + properties[PROP_TAGS] = g_param_spec_object( + "tags", NULL, NULL, + PURPLE_TYPE_TAGS, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + + /** * PurpleCommand:use-count: * * The count of how many times the command has been used. @@ -415,6 +434,13 @@ return command->summary; } +PurpleTags * +purple_command_get_tags(PurpleCommand *command) { + g_return_val_if_fail(PURPLE_IS_COMMAND(command), NULL); + + return command->tags; +} + guint purple_command_get_use_count(PurpleCommand *command) { g_return_val_if_fail(PURPLE_IS_COMMAND(command), 0);
--- a/libpurple/purplecommand.h Tue Sep 24 21:26:59 2024 -0500 +++ b/libpurple/purplecommand.h Tue Sep 24 21:28:06 2024 -0500 @@ -31,6 +31,7 @@ #include <glib-object.h> #include "purpleconversation.h" +#include "purpletags.h" #include "purpleversion.h" G_BEGIN_DECLS @@ -165,6 +166,23 @@ const char *purple_command_get_summary(PurpleCommand *command); /** + * purple_command_get_tags: + * @command: The instance. + * + * Gets the [class@Tags] from @command. + * + * These tags will be matched against [property@Conversation:tags] using + * [method@Tags.contains] to determine if command is available for a + * [class@Conversation]. + * + * Returns: (transfer none): The tags object. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +PurpleTags *purple_command_get_tags(PurpleCommand *command); + +/** * purple_command_get_use_count: * @command: The instance. *
--- a/libpurple/tests/test_command.c Tue Sep 24 21:26:59 2024 -0500 +++ b/libpurple/tests/test_command.c Tue Sep 24 21:28:06 2024 -0500 @@ -36,6 +36,7 @@ static void test_purple_command_properties(void) { PurpleCommand *command = NULL; + PurpleTags *tags = NULL; GDateTime *last_used = NULL; GDateTime *last_used1 = NULL; char *icon_name = NULL; @@ -68,6 +69,7 @@ "priority", &priority, "source", &source, "summary", &summary, + "tags", &tags, "use-count", &use_count, NULL); @@ -88,6 +90,9 @@ g_assert_cmpstr(summary, ==, "summary"); g_clear_pointer(&summary, g_free); + g_assert_true(PURPLE_IS_TAGS(tags)); + g_clear_object(&tags); + g_assert_cmpuint(use_count, ==, 1337); g_assert_finalize_object(command);