pidgin/pidgin

8378ac3ef0f1
Parents c36543f2ec67
Children b069ea54b906
Convert PidginNotificationList to GtkListView

This conversion was done because apparently GtkListBox starts getting slow
around 100 items and this could grow fast if someone has a bunch of accounts.

We'll need to convert the rest of the widgets, but those can come later.

Testing Done:
Compiled with the turtles. Also manually added weak refs to the widgets to make sure they were getting cleaned up properly.

Reviewed at https://reviews.imfreedom.org/r/3011/
--- a/pidgin/pidginnotificationlist.c Thu Mar 07 22:36:47 2024 -0600
+++ b/pidgin/pidginnotificationlist.c Thu Mar 07 22:59:26 2024 -0600
@@ -33,7 +33,8 @@
struct _PidginNotificationList {
GtkBox parent;
- GtkWidget *list_box;
+ GtkWidget *list_view;
+ GtkSingleSelection *selection_model;
};
G_DEFINE_FINAL_TYPE(PidginNotificationList, pidgin_notification_list,
@@ -101,13 +102,20 @@
return row;
}
-static GtkWidget *
-pidgin_notification_list_create_widget_func(gpointer item,
- G_GNUC_UNUSED gpointer data)
+/******************************************************************************
+ * Callbacks
+ *****************************************************************************/
+static void
+pidgin_notification_list_bind_cb(G_GNUC_UNUSED GtkSignalListItemFactory *self,
+ GObject *object,
+ G_GNUC_UNUSED gpointer data)
{
- PurpleNotification *notification = item;
+ PurpleNotification *notification = NULL;
+ GtkListItem *item = GTK_LIST_ITEM(object);
GtkWidget *widget = NULL;
+ notification = gtk_list_item_get_item(item);
+
switch(purple_notification_get_notification_type(notification)) {
case PURPLE_NOTIFICATION_TYPE_GENERIC:
widget = pidgin_notification_generic_new(notification);
@@ -130,7 +138,7 @@
widget = pidgin_notification_list_unknown_notification(notification);
}
- return widget;
+ gtk_list_item_set_child(item, widget);
}
/******************************************************************************
@@ -138,12 +146,12 @@
*****************************************************************************/
static void
pidgin_notification_list_init(PidginNotificationList *list) {
+ GListModel *model = NULL;
+
gtk_widget_init_template(GTK_WIDGET(list));
- gtk_list_box_bind_model(GTK_LIST_BOX(list->list_box),
- purple_notification_manager_get_default_as_model(),
- pidgin_notification_list_create_widget_func,
- list, NULL);
+ model = purple_notification_manager_get_default_as_model();
+ gtk_single_selection_set_model(list->selection_model, model);
}
static void
@@ -152,11 +160,16 @@
gtk_widget_class_set_template_from_resource(
widget_class,
- "/im/pidgin/Pidgin3/Notifications/list.ui"
+ "/im/pidgin/Pidgin3/notificationlist.ui"
);
gtk_widget_class_bind_template_child(widget_class, PidginNotificationList,
- list_box);
+ list_view);
+ gtk_widget_class_bind_template_child(widget_class, PidginNotificationList,
+ selection_model);
+
+ gtk_widget_class_bind_template_callback(widget_class,
+ pidgin_notification_list_bind_cb);
}
/******************************************************************************
--- a/pidgin/resources/Notifications/list.ui Thu Mar 07 22:36:47 2024 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-<?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>
- <requires lib="gtk" version="4.0"/>
- <requires lib="Adw" version="1.0"/>
- <!-- interface-license-type gplv2 -->
- <!-- interface-name Pidgin -->
- <!-- interface-description Internet Messenger -->
- <!-- interface-copyright Pidgin Developers <devel@pidgin.im> -->
- <template class="PidginNotificationList" parent="GtkBox">
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkListBox" id="list_box">
- <property name="vexpand">1</property>
- <child type="placeholder">
- <object class="AdwStatusPage">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="icon-name">mail-read-symbolic</property>
- <property name="title" translatable="1">Notifications</property>
- <property name="description" translatable="1">You&apos;re all caught up!</property>
- <child>
- <placeholder/>
- </child>
- </object>
- </child>
- </object>
- </child>
- </template>
-</interface>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/resources/notificationlist.ui Thu Mar 07 22:59:26 2024 -0600
@@ -0,0 +1,54 @@
+<?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>
+ <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="PidginNotificationList" parent="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkListView" id="list_view">
+ <property name="model">
+ <object class="GtkSingleSelection" id="selection_model"/>
+ </property>
+ <property name="factory">
+ <object class="GtkSignalListItemFactory">
+ <signal name="bind" handler="pidgin_notification_list_bind_cb"/>
+ </object>
+ </property>
+<!--
+ <child type="placeholder">
+ <object class="AdwStatusPage">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="icon-name">mail-read-symbolic</property>
+ <property name="title" translatable="1">Notifications</property>
+ <property name="description" translatable="1">You&apos;re all caught up!</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ </child>
+-->
+ </object>
+ </child>
+ </template>
+</interface>
--- a/pidgin/resources/pidgin.gresource.xml Thu Mar 07 22:36:47 2024 -0600
+++ b/pidgin/resources/pidgin.gresource.xml Thu Mar 07 22:59:26 2024 -0600
@@ -19,7 +19,6 @@
<file compressed="true" preprocess="xml-stripblanks">Notifications/addcontact.ui</file>
<file compressed="true" preprocess="xml-stripblanks">Notifications/authorizationrequest.ui</file>
<file compressed="true" preprocess="xml-stripblanks">Notifications/connectionerror.ui</file>
- <file compressed="true" preprocess="xml-stripblanks">Notifications/list.ui</file>
<file compressed="true" preprocess="xml-stripblanks">Plugins/dialog.ui</file>
<file compressed="true" preprocess="xml-stripblanks">Prefs/away.ui</file>
<file compressed="true" preprocess="xml-stripblanks">Prefs/conversation.ui</file>
@@ -43,6 +42,7 @@
<file compressed="true" preprocess="xml-stripblanks">conversationmemberlistitem.ui</file>
<file compressed="true" preprocess="xml-stripblanks">imwindow.ui</file>
<file compressed="true" preprocess="xml-stripblanks">infopane.ui</file>
+ <file compressed="true" preprocess="xml-stripblanks">notificationlist.ui</file>
<file compressed="true" preprocess="xml-stripblanks">presenceicon.ui</file>
<file>icons/16x16/status/pidgin-user-available.png</file>
<file>icons/16x16/status/pidgin-user-away.png</file>