libpurple/purplenotificationmanager.c

Thu, 07 Aug 2025 21:40:13 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 07 Aug 2025 21:40:13 -0500
changeset 43302
e7b0bbfec5d5
parent 43128
1ce3ad90614c
permissions
-rw-r--r--

Add an avatar-for-display property to Purple.ContactInfo

Testing Done:
Ran the tests under valgrind and called in the turtles.

Reviewed at https://reviews.imfreedom.org/r/4086/

41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
7 * source distribution.
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
9 * This library is free software; you can redistribute it and/or modify it
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
10 * under the terms of the GNU General Public License as published by the Free
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
11 * Software Foundation; either version 2 of the License, or (at your option)
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
12 * any later version.
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
14 * This library is distributed in the hope that it will be useful, but WITHOUT
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
17 * more details.
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
18 *
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
19 * You should have received a copy of the GNU General Public License along with
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
20 * this library; if not, see <https://www.gnu.org/licenses/>.
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include <glib/gi18n-lib.h>
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #include "purplenotificationmanager.h"
42997
368deff13c21 Split purpleprivate.h up into individual files
Gary Kramlich <grim@reaperworld.com>
parents: 42985
diff changeset
26 #include "purplenotificationmanagerprivate.h"
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27
42985
66ad6fc11879 Create Purple.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents: 42984
diff changeset
28 #include "purplenotificationconnectionerror.h"
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 enum {
42584
687260353985 Make signal and property enums and initializers consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42576
diff changeset
31 PROP_0,
42662
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
32 PROP_ITEM_TYPE,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
33 PROP_N_ITEMS,
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 PROP_UNREAD_COUNT,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 N_PROPERTIES,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 };
42584
687260353985 Make signal and property enums and initializers consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42576
diff changeset
37 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 enum {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 SIG_ADDED,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 SIG_REMOVED,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 SIG_READ,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 SIG_UNREAD,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 N_SIGNALS,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 };
42584
687260353985 Make signal and property enums and initializers consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42576
diff changeset
46 static guint signals[N_SIGNALS] = {0, };
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 struct _PurpleNotificationManager {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 GObject parent;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
51 GPtrArray *notifications;
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 guint unread_count;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 };
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 static PurpleNotificationManager *default_manager = NULL;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 /******************************************************************************
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 * Helpers
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 *****************************************************************************/
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 purple_notification_manager_set_unread_count(PurpleNotificationManager *manager,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 guint unread_count)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 if(manager->unread_count != unread_count) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 manager->unread_count = unread_count;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 g_object_notify_by_pspec(G_OBJECT(manager),
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 properties[PROP_UNREAD_COUNT]);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 static inline void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 purple_notification_manager_increment_unread_count(PurpleNotificationManager *manager)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 if(manager->unread_count < G_MAXUINT) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 purple_notification_manager_set_unread_count(manager,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 manager->unread_count + 1);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 static inline void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 purple_notification_manager_decrement_unread_count(PurpleNotificationManager *manager)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 if(manager->unread_count > 0) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 purple_notification_manager_set_unread_count(manager,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 manager->unread_count - 1);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 /******************************************************************************
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 * Callbacks
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 *****************************************************************************/
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 purple_notification_manager_notify_cb(GObject *obj,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 G_GNUC_UNUSED GParamSpec *pspec,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 gpointer data)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 PurpleNotification *notification = PURPLE_NOTIFICATION(obj);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 PurpleNotificationManager *manager = data;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 guint signal_id = 0;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 /* This function is called after the property is changed. So we need to
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 * get the new value to determine how the state changed.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 if(purple_notification_get_read(notification)) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 purple_notification_manager_decrement_unread_count(manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 signal_id = signals[SIG_READ];
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 } else {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 purple_notification_manager_increment_unread_count(manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 signal_id = signals[SIG_UNREAD];
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 g_signal_emit(manager, signal_id, 0, notification);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119
42962
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
120 static void
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
121 purple_notification_manager_deleted_cb(PurpleNotification *notification,
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
122 gpointer data)
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
123 {
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
124 PurpleNotificationManager *manager = data;
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
125
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
126 purple_notification_manager_remove(manager, notification);
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
127 }
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
128
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 /******************************************************************************
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
130 * GListModel Implementation
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
131 *****************************************************************************/
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
132 static GType
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
133 purple_notification_manager_get_item_type(G_GNUC_UNUSED GListModel *list) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
134 return PURPLE_TYPE_NOTIFICATION;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
135 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
136
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
137 static guint
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
138 purple_notification_manager_get_n_items(GListModel *list) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
139 PurpleNotificationManager *manager = PURPLE_NOTIFICATION_MANAGER(list);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
140
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
141 return manager->notifications->len;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
142 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
143
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
144 static gpointer
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
145 purple_notification_manager_get_item(GListModel *list, guint position) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
146 PurpleNotificationManager *manager = PURPLE_NOTIFICATION_MANAGER(list);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
147 PurpleNotification *notification = NULL;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
148
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
149 if(position < manager->notifications->len) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
150 notification = g_ptr_array_index(manager->notifications, position);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
151 g_object_ref(notification);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
152 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
153
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
154 return notification;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
155 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
156
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
157 static void
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
158 purple_notification_manager_list_model_init(GListModelInterface *iface) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
159 iface->get_item_type = purple_notification_manager_get_item_type;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
160 iface->get_n_items = purple_notification_manager_get_n_items;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
161 iface->get_item = purple_notification_manager_get_item;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
162 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
163
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
164 /******************************************************************************
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 * GObject Implementation
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 *****************************************************************************/
42576
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
167 G_DEFINE_FINAL_TYPE_WITH_CODE(PurpleNotificationManager, purple_notification_manager,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
168 G_TYPE_OBJECT,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
169 G_IMPLEMENT_INTERFACE(G_TYPE_LIST_MODEL,
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
170 purple_notification_manager_list_model_init));
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
171
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
172
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 purple_notification_manager_get_property(GObject *obj, guint param_id,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 GValue *value, GParamSpec *pspec)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 PurpleNotificationManager *manager = PURPLE_NOTIFICATION_MANAGER(obj);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179 switch(param_id) {
42662
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
180 case PROP_ITEM_TYPE:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
181 g_value_set_gtype(value,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
182 purple_notification_manager_get_item_type(G_LIST_MODEL(manager)));
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
183 break;
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
184 case PROP_N_ITEMS:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
185 g_value_set_uint(value,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
186 purple_notification_manager_get_n_items(G_LIST_MODEL(manager)));
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
187 break;
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
188 case PROP_UNREAD_COUNT:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
189 g_value_set_uint(value,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
190 purple_notification_manager_get_unread_count(manager));
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
191 break;
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
192 default:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
193 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
194 break;
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199 purple_notification_manager_finalize(GObject *obj) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200 PurpleNotificationManager *manager = NULL;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202 manager = PURPLE_NOTIFICATION_MANAGER(obj);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
204 g_ptr_array_free(manager->notifications, TRUE);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
205 manager->notifications = NULL;
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207 G_OBJECT_CLASS(purple_notification_manager_parent_class)->finalize(obj);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
210 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211 purple_notification_manager_init(PurpleNotificationManager *manager) {
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
212 manager->notifications = g_ptr_array_new_full(0,
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
213 (GDestroyNotify)g_object_unref);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 purple_notification_manager_class_init(PurpleNotificationManagerClass *klass) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
220 obj_class->get_property = purple_notification_manager_get_property;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 obj_class->finalize = purple_notification_manager_finalize;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222
42662
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
223 /**
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
224 * PurpleNotificationManager:item-type:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
225 *
42984
818220289e67 Update the gi-docgen subproject and fix some new issues it found
Gary Kramlich <grim@reaperworld.com>
parents: 42962
diff changeset
226 * The type of items. See [vfunc@Gio.ListModel.get_item_type].
42662
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
227 *
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
228 * Since: 3.0
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
229 */
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
230 properties[PROP_ITEM_TYPE] = g_param_spec_gtype(
43071
071588186662 Remove nick and blurb from libpurple properties
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42997
diff changeset
231 "item-type", NULL, NULL,
42662
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
232 G_TYPE_OBJECT,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
233 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
234
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
235 /**
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
236 * PurpleNotificationManager:n-items:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
237 *
42984
818220289e67 Update the gi-docgen subproject and fix some new issues it found
Gary Kramlich <grim@reaperworld.com>
parents: 42962
diff changeset
238 * The number of items. See [vfunc@Gio.ListModel.get_n_items].
42662
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
239 *
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
240 * Since: 3.0
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
241 */
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
242 properties[PROP_N_ITEMS] = g_param_spec_uint(
43071
071588186662 Remove nick and blurb from libpurple properties
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42997
diff changeset
243 "n-items", NULL, NULL,
42662
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
244 0, G_MAXUINT, 0,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
245 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247 /**
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
248 * PurpleNotificationManager:unread-count:
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
249 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 * The number of unread notifications in the manager.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251 *
42614
b75a5bbf6c35 Remove the micro version from since tags for libpurple part 3
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
252 * Since: 3.0
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
253 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
254 properties[PROP_UNREAD_COUNT] = g_param_spec_uint(
43071
071588186662 Remove nick and blurb from libpurple properties
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42997
diff changeset
255 "unread-count", NULL, NULL,
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
256 0, G_MAXUINT, 0,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
257 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
258
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
259 g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
260
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
261 /**
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
262 * PurpleNotificationManager::added:
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
263 * @manager: The instance.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
264 * @notification: The [class@Notification] that was added.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
265 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
266 * Emitted after @notification has been added to @manager.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
267 *
42614
b75a5bbf6c35 Remove the micro version from since tags for libpurple part 3
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
268 * Since: 3.0
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
269 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
270 signals[SIG_ADDED] = g_signal_new_class_handler(
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
271 "added",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
272 G_OBJECT_CLASS_TYPE(klass),
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
273 G_SIGNAL_RUN_LAST,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
274 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
275 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
277 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
278 G_TYPE_NONE,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
279 1,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
280 PURPLE_TYPE_NOTIFICATION);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
281
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
282 /**
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283 * PurpleNotificationManager::removed:
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
284 * @manager: The instance.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285 * @notification: The [class@Notification] that was removed.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
286 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
287 * Emitted after @notification has been removed from @manager.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
288 *
42614
b75a5bbf6c35 Remove the micro version from since tags for libpurple part 3
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
289 * Since: 3.0
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
290 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
291 signals[SIG_REMOVED] = g_signal_new_class_handler(
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
292 "removed",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
293 G_OBJECT_CLASS_TYPE(klass),
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
294 G_SIGNAL_RUN_LAST,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
295 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
296 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
298 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
299 G_TYPE_NONE,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
300 1,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301 PURPLE_TYPE_NOTIFICATION);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
302
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
303 /**
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 * PurpleNotificationManager::read:
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
305 * @manager: The instance.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
306 * @notification: The [class@Notification].
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
307 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 * Emitted after @notification has been marked as read.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309 *
42614
b75a5bbf6c35 Remove the micro version from since tags for libpurple part 3
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
310 * Since: 3.0
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
312 signals[SIG_READ] = g_signal_new_class_handler(
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
313 "read",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314 G_OBJECT_CLASS_TYPE(klass),
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315 G_SIGNAL_RUN_LAST,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
317 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
320 G_TYPE_NONE,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
321 1,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
322 PURPLE_TYPE_NOTIFICATION);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
324 /**
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
325 * PurpleNotificationManager::unread:
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
326 * @manager: The instance.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327 * @notification: The [class@Notification].
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
328 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
329 * Emitted after @notification has been marked as unread.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
330 *
42614
b75a5bbf6c35 Remove the micro version from since tags for libpurple part 3
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
331 * Since: 3.0
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
333 signals[SIG_UNREAD] = g_signal_new_class_handler(
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
334 "unread",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
335 G_OBJECT_CLASS_TYPE(klass),
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
336 G_SIGNAL_RUN_LAST,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
337 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
338 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341 G_TYPE_NONE,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
342 1,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 PURPLE_TYPE_NOTIFICATION);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
346 /******************************************************************************
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
347 * Private API
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
348 *****************************************************************************/
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
349 void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
350 purple_notification_manager_startup(void) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351 if(default_manager == NULL) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
352 default_manager = g_object_new(PURPLE_TYPE_NOTIFICATION_MANAGER, NULL);
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
353 g_object_add_weak_pointer(G_OBJECT(default_manager),
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
354 (gpointer *)&default_manager);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
355 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
356 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
357
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
358 void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
359 purple_notification_manager_shutdown(void) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
360 g_clear_object(&default_manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
361 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
362
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
363 /******************************************************************************
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
364 * Public API
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
365 *****************************************************************************/
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
366 PurpleNotificationManager *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
367 purple_notification_manager_get_default(void) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
368 return default_manager;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
369 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
370
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
371 GListModel *
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
372 purple_notification_manager_get_default_as_model(void) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
373 if(PURPLE_IS_NOTIFICATION_MANAGER(default_manager)) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
374 return G_LIST_MODEL(default_manager);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
375 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
376
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
377 return NULL;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
378 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
379
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
380 void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
381 purple_notification_manager_add(PurpleNotificationManager *manager,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
382 PurpleNotification *notification)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
383 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
384 g_return_if_fail(PURPLE_IS_NOTIFICATION_MANAGER(manager));
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
385 g_return_if_fail(PURPLE_IS_NOTIFICATION(notification));
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
386
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
387 if(g_ptr_array_find(manager->notifications, notification, NULL)) {
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
388 const gchar *id = purple_notification_get_id(notification);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
389
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
390 g_warning("double add detected for notification %s", id);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
391
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
392 return;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
393 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
394
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
395 g_ptr_array_insert(manager->notifications, 0, g_object_ref(notification));
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
396
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
397 /* Connect to the notify signal for the read property only so we can
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
398 * propagate out changes for any notification.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
399 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
400 g_signal_connect_object(notification, "notify::read",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
401 G_CALLBACK(purple_notification_manager_notify_cb),
42962
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
402 manager, G_CONNECT_DEFAULT);
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
403 g_signal_connect_object(notification, "deleted",
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
404 G_CALLBACK(purple_notification_manager_deleted_cb),
a2c1926ce7b2 Update Purple.NotificationManager to remove notifications when they're deleted
Gary Kramlich <grim@reaperworld.com>
parents: 42927
diff changeset
405 manager, G_CONNECT_DEFAULT);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
406
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
407 /* If the notification is not read, we need to increment the unread count.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
408 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
409 if(!purple_notification_get_read(notification)) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
410 purple_notification_manager_increment_unread_count(manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
411 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
412
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
413 g_signal_emit(G_OBJECT(manager), signals[SIG_ADDED], 0, notification);
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
414 g_list_model_items_changed(G_LIST_MODEL(manager), 0, 0, 1);
43128
1ce3ad90614c Make sure we notify on the n-items property for all objects that have it
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
415 g_object_notify_by_pspec(G_OBJECT(manager), properties[PROP_N_ITEMS]);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
416 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
417
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
418 void
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
419 purple_notification_manager_remove(PurpleNotificationManager *manager,
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
420 PurpleNotification *notification)
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
421 {
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
422 guint index = 0;
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
423
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
424 g_return_if_fail(PURPLE_IS_NOTIFICATION_MANAGER(manager));
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
425 g_return_if_fail(PURPLE_IS_NOTIFICATION(notification));
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
426
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
427 if(g_ptr_array_find(manager->notifications, notification, &index)) {
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
428 /* Reference the notification so we can emit the signal after it's been
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
429 * removed from the hash table.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
430 */
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
431 g_object_ref(notification);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
432
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
433 g_ptr_array_remove_index(manager->notifications, index);
42565
c035e2eba80d Fix several minor typos
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42246
diff changeset
434 /* Remove the notify signal handler for the read state in case someone
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
435 * else added a reference to the notification which would then mess
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
436 * with our unread count accounting.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
437 */
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
438 g_signal_handlers_disconnect_by_func(notification,
42246
3230f1a1fb8f Remove unnecessary casting from g_signal_handlers_disconnect
Gary Kramlich <grim@reaperworld.com>
parents: 41936
diff changeset
439 purple_notification_manager_notify_cb,
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
440 manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
441
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
442 /* If the notification is not read, we need to decrement the unread
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
443 * count.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
444 */
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
445 if(!purple_notification_get_read(notification)) {
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
446 purple_notification_manager_decrement_unread_count(manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
447 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
448
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
449 g_signal_emit(G_OBJECT(manager), signals[SIG_REMOVED], 0, notification);
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
450 g_list_model_items_changed(G_LIST_MODEL(manager), index, 1, 0);
43128
1ce3ad90614c Make sure we notify on the n-items property for all objects that have it
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
451 g_object_notify_by_pspec(G_OBJECT(manager), properties[PROP_N_ITEMS]);
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
452
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
453 g_object_unref(notification);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
454 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
455 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
456
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
457 /*
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
458 This function uses the following algorithm to optimally remove items from the
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
459 g_ptr_array to minimize the number of calls to g_list_model_items_changed. See
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
460 the pseudo code below for an easier to follow version.
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
461
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
462 A
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
463 A B C
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
464 B C
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
465 A A B C
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
466 B A C
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
467 B A A C
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
468 B C A
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
469 B C A A
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
470
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
471 set len = number_of_items
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
472 set pos = 0
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
473 set have_same = false
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
474 while pos < len
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
475 check item at pos
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
476 if same
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
477 if not have_same
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
478 reset count = 0
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
479 set start = pos
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
480 set have_same = TRUE
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
481
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
482 set count = count + 1
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
483 else
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
484 if have_same
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
485 remove count items from start
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
486 set pos = pos - count
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
487 set len = len - count
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
488 set have_same = FALSE
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
489 set pos = pos + 1
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
490 if have_same
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
491 remove count items from start
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
492 */
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
493 void
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
494 purple_notification_manager_remove_with_account(PurpleNotificationManager *manager,
41817
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
495 PurpleAccount *account,
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
496 gboolean all)
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
497 {
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
498 GListModel *model = NULL;
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
499 guint pos = 0, len = 0;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
500 guint start = 0, count = 0;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
501 gboolean have_same = FALSE;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
502
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
503 g_return_if_fail(PURPLE_IS_NOTIFICATION_MANAGER(manager));
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
504 g_return_if_fail(PURPLE_IS_ACCOUNT(account));
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
505
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
506 model = G_LIST_MODEL(manager);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
507
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
508 for(pos = 0; pos < manager->notifications->len; pos++) {
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
509 PurpleAccount *account2 = NULL;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
510 PurpleNotification *notification = NULL;
41817
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
511 gboolean can_remove = TRUE;
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
512
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
513 notification = g_ptr_array_index(manager->notifications, pos);
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
514
41817
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
515 /* If the notification's type is connection error, set can_remove to
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
516 * the value of the all parameter.
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
517 */
42985
66ad6fc11879 Create Purple.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents: 42984
diff changeset
518 if(PURPLE_IS_NOTIFICATION_CONNECTION_ERROR(notification)) {
41817
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
519 can_remove = all;
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
520 }
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
521
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
522 account2 = purple_notification_get_account(notification);
41817
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
523 if(account == account2 && can_remove) {
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
524 /* If this is the first item with the right account store its
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
525 * position.
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
526 */
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
527 if(!have_same) {
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
528 count = 0;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
529 start = pos;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
530 have_same = TRUE;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
531 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
532
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
533 /* Increment the count of items starting at the start position. */
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
534 count++;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
535 } else {
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
536 if(have_same) {
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
537 /* Remove the run of items from the list. */
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
538 g_ptr_array_remove_range(manager->notifications, start, count);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
539 g_list_model_items_changed(model, start, count, 0);
43128
1ce3ad90614c Make sure we notify on the n-items property for all objects that have it
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
540 g_object_notify_by_pspec(G_OBJECT(manager),
1ce3ad90614c Make sure we notify on the n-items property for all objects that have it
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
541 properties[PROP_N_ITEMS]);
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
542
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
543 /* Adjust pos and len for the items that we removed. */
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
544 pos = pos - count;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
545 len = len - count;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
546
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
547 have_same = FALSE;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
548 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
549 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
550 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
551
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
552 /* Clean up the last bit if the last item needs to be removed. */
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
553 if(have_same) {
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
554 g_ptr_array_remove_range(manager->notifications, start, count);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
555 g_list_model_items_changed(model, start, count, 0);
43128
1ce3ad90614c Make sure we notify on the n-items property for all objects that have it
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
556 g_object_notify_by_pspec(G_OBJECT(manager), properties[PROP_N_ITEMS]);
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
557 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
558 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
559
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
560 guint
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
561 purple_notification_manager_get_unread_count(PurpleNotificationManager *manager) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
562 g_return_val_if_fail(PURPLE_IS_NOTIFICATION_MANAGER(manager), 0);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
563
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
564 return manager->unread_count;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
565 }
41441
e114ed471a1e Implement the UI for the new Notifications API.
Gary Kramlich <grim@reaperworld.com>
parents: 41438
diff changeset
566
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
567 void
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
568 purple_notification_manager_clear(PurpleNotificationManager *manager) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
569 guint count = 0;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
570
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
571 g_return_if_fail(PURPLE_IS_NOTIFICATION_MANAGER(manager));
41441
e114ed471a1e Implement the UI for the new Notifications API.
Gary Kramlich <grim@reaperworld.com>
parents: 41438
diff changeset
572
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
573 count = manager->notifications->len;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
574
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
575 for(guint pos = 0; pos < count; pos++) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
576 PurpleNotification *notification = NULL;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
577
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
578 notification = g_ptr_array_index(manager->notifications, pos);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
579
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
580 g_signal_emit(manager, signals[SIG_REMOVED], 0, notification);
41441
e114ed471a1e Implement the UI for the new Notifications API.
Gary Kramlich <grim@reaperworld.com>
parents: 41438
diff changeset
581 }
e114ed471a1e Implement the UI for the new Notifications API.
Gary Kramlich <grim@reaperworld.com>
parents: 41438
diff changeset
582
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
583 g_ptr_array_remove_range(manager->notifications, 0, count);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
584
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
585 g_list_model_items_changed(G_LIST_MODEL(manager), 0, count, 0);
43128
1ce3ad90614c Make sure we notify on the n-items property for all objects that have it
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
586 g_object_notify_by_pspec(G_OBJECT(manager), properties[PROP_N_ITEMS]);
41441
e114ed471a1e Implement the UI for the new Notifications API.
Gary Kramlich <grim@reaperworld.com>
parents: 41438
diff changeset
587 }

mercurial