Fri, 22 Nov 2024 03:51:12 -0600
Implement the Pidgin.Badges widget and use it in conversation member list
Testing Done:
Opened a conversation with a developer on the demo protocol plugin.
Bugs closed: PIDGIN-17933
Reviewed at https://reviews.imfreedom.org/r/3672/
--- a/pidgin/meson.build Fri Nov 22 03:37:06 2024 -0600 +++ b/pidgin/meson.build Fri Nov 22 03:51:12 2024 -0600 @@ -20,6 +20,7 @@ 'pidginapplication.c', 'pidginautoadjustment.c', 'pidginavatar.c', + 'pidginbadges.c', 'pidginchanneljoindialog.c', 'pidgincolor.c', 'pidgincontactinfomenu.c', @@ -69,6 +70,7 @@ 'pidginapplication.h', 'pidginautoadjustment.h', 'pidginavatar.h', + 'pidginbadges.h', 'pidginchanneljoindialog.h', 'pidgincolor.h', 'pidgincontactinfomenu.h',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/pidginbadges.c Fri Nov 22 03:51:12 2024 -0600 @@ -0,0 +1,156 @@ +/* + * Pidgin - Internet Messenger + * Copyright (C) Pidgin Developers <devel@pidgin.im> + * + * Pidgin is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses/>. + */ +#include <glib/gi18n-lib.h> + +#include <gtk/gtk.h> + +#include "pidginbadges.h" + +struct _PidginBadges { + AdwBin parent; + + PurpleBadges *badges; + + GtkSliceListModel *model; +}; + +enum { + PROP_0, + PROP_BADGES, + N_PROPERTIES, +}; +static GParamSpec *properties[N_PROPERTIES] = {NULL, }; + +/****************************************************************************** + * GObject implementation + *****************************************************************************/ +G_DEFINE_FINAL_TYPE(PidginBadges, pidgin_badges, ADW_TYPE_BIN) + +static void +pidgin_badges_get_property(GObject *object, guint prop_id, GValue *value, + GParamSpec *pspec) +{ + PidginBadges *badges = PIDGIN_BADGES(object); + + switch (prop_id) { + case PROP_BADGES: + g_value_set_object(value, pidgin_badges_get_badges(badges)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +pidgin_badges_set_property(GObject *object, guint prop_id, const GValue *value, + GParamSpec *pspec) +{ + PidginBadges *badges = PIDGIN_BADGES(object); + + switch (prop_id) { + case PROP_BADGES: + pidgin_badges_set_badges(badges, g_value_get_object(value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +pidgin_badges_finalize(GObject *obj) { + PidginBadges *badges = PIDGIN_BADGES(obj); + + g_clear_object(&badges->badges); + + G_OBJECT_CLASS(pidgin_badges_parent_class)->finalize(obj); +} + +static void +pidgin_badges_class_init(PidginBadgesClass *klass) { + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + + /* Properties */ + obj_class->get_property = pidgin_badges_get_property; + obj_class->set_property = pidgin_badges_set_property; + obj_class->finalize = pidgin_badges_finalize; + + /** + * PidginBadges:badges: + * + * The badges that are being displayed. + * + * Since: 3.0 + */ + properties[PROP_BADGES] = g_param_spec_object( + "badges", NULL, NULL, + PURPLE_TYPE_BADGES, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties(obj_class, N_PROPERTIES, properties); + + /* Widget template */ + gtk_widget_class_set_template_from_resource(widget_class, + "/im/pidgin/Pidgin3/badges.ui"); + + gtk_widget_class_bind_template_child(widget_class, PidginBadges, + model); +} + +static void +pidgin_badges_init(PidginBadges *badges) { + gtk_widget_init_template(GTK_WIDGET(badges)); +} + +/****************************************************************************** + * Public API + *****************************************************************************/ +GtkWidget * +pidgin_badges_new(PurpleBadges *badges) { + return g_object_new(PIDGIN_TYPE_BADGES, + "badges", badges, + NULL); +} + +PurpleBadges * +pidgin_badges_get_badges(PidginBadges *badges) { + g_return_val_if_fail(PIDGIN_IS_BADGES(badges), NULL); + + return badges->badges; +} + +void +pidgin_badges_set_badges(PidginBadges *pidgin_badges, + PurpleBadges *purple_badges) +{ + g_return_if_fail(PIDGIN_IS_BADGES(pidgin_badges)); + + if(g_set_object(&pidgin_badges->badges, purple_badges)) { + gtk_slice_list_model_set_model(pidgin_badges->model, + G_LIST_MODEL(purple_badges)); + + g_object_notify_by_pspec(G_OBJECT(pidgin_badges), + properties[PROP_BADGES]); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/pidginbadges.h Fri Nov 22 03:51:12 2024 -0600 @@ -0,0 +1,93 @@ +/* + * Pidgin - Internet Messenger + * Copyright (C) Pidgin Developers <devel@pidgin.im> + * + * Pidgin is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses/>. + */ + +#if !defined(PIDGIN_GLOBAL_HEADER_INSIDE) && !defined(PIDGIN_COMPILATION) +# error "only <pidgin.h> may be included directly" +#endif + +#ifndef PIDGIN_BADGES_H +#define PIDGIN_BADGES_H + +#include <gtk/gtk.h> + +#include <adwaita.h> + +#include <purple.h> + +#include "pidginversion.h" + +G_BEGIN_DECLS + +/** + * PidginBadges: + * + * A widget that is used to display a [class@Purple.Badges]. + * + * Since: 3.0 + */ + +#define PIDGIN_TYPE_BADGES (pidgin_badges_get_type()) + +PIDGIN_AVAILABLE_IN_3_0 +G_DECLARE_FINAL_TYPE(PidginBadges, pidgin_badges, PIDGIN, BADGES, AdwBin) + +/** + * pidgin_badges_new: + * @badges: The badges to display. + * + * Displays badges. + * + * Returns: (transfer full): The new widget. + * + * Since: 3.0 + */ +PIDGIN_AVAILABLE_IN_3_0 +GtkWidget *pidgin_badges_new(PurpleBadges *badges); + +/** + * pidgin_badges_get_badges: + * @badges: The instance. + * + * Gets the badges that are being displayed. + * + * Returns: (transfer none) (nullable): The badges. + * + * Since: 3.0 + */ +PIDGIN_AVAILABLE_IN_3_0 +PurpleBadges *pidgin_badges_get_badges(PidginBadges *badges); + +/** + * pidgin_badges_set_badges: + * @pidgin_badges: The instance. + * @purple_badges: (nullable) (transfer none): The new badges. + * + * Sets the badges to be displayed. + * + * Since: 3.0 + */ +PIDGIN_AVAILABLE_IN_3_0 +void pidgin_badges_set_badges(PidginBadges *pidgin_badges, PurpleBadges *purple_badges); + +G_END_DECLS + +#endif /* PIDGIN_BADGES_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/resources/badge-item.ui Fri Nov 22 03:51:12 2024 -0600 @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Pidgin - Internet Messenger +Copyright (C) Pidgin Developers <devel@pidgin.im> + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this library; if not, see <https://www.gnu.org/licenses/>. +--> +<interface domain="pidgin"> + <requires lib="gtk" version="4.0"/> + <!-- interface-license-type gplv2 --> + <!-- interface-name Pidgin --> + <!-- interface-description Internet Messenger --> + <!-- interface-copyright Pidgin Developers <devel@pidgin.im> --> + <template class="GtkListItem"> + <property name="child"> + <object class="GtkImage"> + <property name="icon-size">large</property> + <binding name="icon-name"> + <lookup name="icon-name" type="PurpleBadge"> + <lookup name="item">GtkListItem</lookup> + </lookup> + </binding> + </object> + </property> + </template> +</interface>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pidgin/resources/badges.ui Fri Nov 22 03:51:12 2024 -0600 @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +Pidgin - Internet Messenger +Copyright (C) Pidgin Developers <devel@pidgin.im> + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this library; if not, see <https://www.gnu.org/licenses/>. +--> +<interface domain="pidgin"> + <requires lib="gtk" version="4.0"/> + <!-- interface-license-type gplv2 --> + <!-- interface-name Pidgin --> + <!-- interface-description Internet Messenger --> + <!-- interface-copyright Pidgin Developers <devel@pidgin.im> --> + <template class="PidginBadges" parent="AdwBin"> + <child> + <object class="GtkListView"> + <property name="orientation">horizontal</property> + <property name="model"> + <object class="GtkNoSelection"> + <property name="model"> + <object class="GtkSliceListModel" id="model"> + <property name="offset">0</property> + <property name="size">3</property> + </object> + </property> + </object> + </property> + <property name="factory"> + <object class="GtkBuilderListItemFactory"> + <property name="resource">/im/pidgin/Pidgin3/badge-item.ui</property> + </object> + </property> + </object> + </child> + </template> +</interface>
--- a/pidgin/resources/conversationmemberlistitem.ui Fri Nov 22 03:37:06 2024 -0600 +++ b/pidgin/resources/conversationmemberlistitem.ui Fri Nov 22 03:51:12 2024 -0600 @@ -32,6 +32,15 @@ <object class="GtkBox"> <property name="orientation">horizontal</property> <child> + <object class="PidginBadges"> + <binding name="badges"> + <lookup name="badges" type="PurpleConversationMember"> + <lookup name="item">GtkListItem</lookup> + </lookup> + </binding> + </object> + </child> + <child> <object class="GtkLabel"> <property name="xalign">0</property> <property name="use-markup">1</property>
--- a/pidgin/resources/pidgin.gresource.xml Fri Nov 22 03:37:06 2024 -0600 +++ b/pidgin/resources/pidgin.gresource.xml Fri Nov 22 03:51:12 2024 -0600 @@ -28,6 +28,8 @@ <file compressed="true" preprocess="xml-stripblanks">gtk/help-overlay.ui</file> <file compressed="true" preprocess="xml-stripblanks">gtk/menus.ui</file> <file compressed="true" preprocess="xml-stripblanks">account-row.ui</file> + <file compressed="true" preprocess="xml-stripblanks">badge-item.ui</file> + <file compressed="true" preprocess="xml-stripblanks">badges.ui</file> <file compressed="true" preprocess="xml-stripblanks">channeljoindialog.ui</file> <file compressed="true" preprocess="xml-stripblanks">contactlist.ui</file> <file compressed="true" preprocess="xml-stripblanks">contactlistitem.ui</file>