libpurple/purplenotificationmanager.c

Tue, 09 Apr 2024 22:37:57 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 09 Apr 2024 22:37:57 -0500
changeset 42662
f1f61c62fea6
parent 42614
b75a5bbf6c35
child 42927
51bee36eb6cb
permissions
-rw-r--r--

Add item-type and n-items properties to PurpleNotificationManager

Testing Done:
Compiled

Bugs closed: PIDGIN-17856

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

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"
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 #include "purpleprivate.h"
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 enum {
42584
687260353985 Make signal and property enums and initializers consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42576
diff changeset
30 PROP_0,
42662
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
31 PROP_ITEM_TYPE,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
32 PROP_N_ITEMS,
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 PROP_UNREAD_COUNT,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 N_PROPERTIES,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 };
42584
687260353985 Make signal and property enums and initializers consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42576
diff changeset
36 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 enum {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 SIG_ADDED,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 SIG_REMOVED,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 SIG_READ,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 SIG_UNREAD,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 N_SIGNALS,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 };
42584
687260353985 Make signal and property enums and initializers consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42576
diff changeset
45 static guint signals[N_SIGNALS] = {0, };
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 struct _PurpleNotificationManager {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 GObject parent;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
50 GPtrArray *notifications;
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 guint unread_count;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 };
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 static PurpleNotificationManager *default_manager = NULL;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56
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 * Helpers
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 *****************************************************************************/
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 purple_notification_manager_set_unread_count(PurpleNotificationManager *manager,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 guint unread_count)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 if(manager->unread_count != unread_count) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 manager->unread_count = unread_count;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 g_object_notify_by_pspec(G_OBJECT(manager),
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 properties[PROP_UNREAD_COUNT]);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 }
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 static inline void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 purple_notification_manager_increment_unread_count(PurpleNotificationManager *manager)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 if(manager->unread_count < G_MAXUINT) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 purple_notification_manager_set_unread_count(manager,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 manager->unread_count + 1);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 }
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 static inline void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 purple_notification_manager_decrement_unread_count(PurpleNotificationManager *manager)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 if(manager->unread_count > 0) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 purple_notification_manager_set_unread_count(manager,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 manager->unread_count - 1);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 }
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 * Callbacks
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 *****************************************************************************/
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 purple_notification_manager_notify_cb(GObject *obj,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 G_GNUC_UNUSED GParamSpec *pspec,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 gpointer data)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 PurpleNotification *notification = PURPLE_NOTIFICATION(obj);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 PurpleNotificationManager *manager = data;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 guint signal_id = 0;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 /* 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
103 * 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
104 */
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 if(purple_notification_get_read(notification)) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 purple_notification_manager_decrement_unread_count(manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 signal_id = signals[SIG_READ];
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 } else {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 purple_notification_manager_increment_unread_count(manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 signal_id = signals[SIG_UNREAD];
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 }
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 g_signal_emit(manager, signal_id, 0, notification);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 }
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 /******************************************************************************
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
120 * GListModel Implementation
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
121 *****************************************************************************/
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
122 static GType
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
123 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
124 return PURPLE_TYPE_NOTIFICATION;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
125 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
126
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
127 static guint
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
128 purple_notification_manager_get_n_items(GListModel *list) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
129 PurpleNotificationManager *manager = PURPLE_NOTIFICATION_MANAGER(list);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
130
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
131 return manager->notifications->len;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
132 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
133
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
134 static gpointer
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
135 purple_notification_manager_get_item(GListModel *list, guint position) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
136 PurpleNotificationManager *manager = PURPLE_NOTIFICATION_MANAGER(list);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
137 PurpleNotification *notification = NULL;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
138
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
139 if(position < manager->notifications->len) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
140 notification = g_ptr_array_index(manager->notifications, position);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
141 g_object_ref(notification);
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 return notification;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
145 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
146
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
147 static void
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
148 purple_notification_manager_list_model_init(GListModelInterface *iface) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
149 iface->get_item_type = purple_notification_manager_get_item_type;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
150 iface->get_n_items = purple_notification_manager_get_n_items;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
151 iface->get_item = purple_notification_manager_get_item;
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 /******************************************************************************
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 * GObject Implementation
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 *****************************************************************************/
42576
ab1ca778ddb2 Make sure all of the final types in libpurple are defined as such
Gary Kramlich <grim@reaperworld.com>
parents: 42565
diff changeset
157 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
158 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
159 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
160 purple_notification_manager_list_model_init));
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
161
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
162
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 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
165 GValue *value, GParamSpec *pspec)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 PurpleNotificationManager *manager = PURPLE_NOTIFICATION_MANAGER(obj);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 switch(param_id) {
42662
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
170 case PROP_ITEM_TYPE:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
171 g_value_set_gtype(value,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
172 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
173 break;
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
174 case PROP_N_ITEMS:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
175 g_value_set_uint(value,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
176 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
177 break;
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
178 case PROP_UNREAD_COUNT:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
179 g_value_set_uint(value,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
180 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
181 break;
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
182 default:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
183 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
184 break;
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 purple_notification_manager_finalize(GObject *obj) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190 PurpleNotificationManager *manager = NULL;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192 manager = PURPLE_NOTIFICATION_MANAGER(obj);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
194 g_ptr_array_free(manager->notifications, TRUE);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
195 manager->notifications = NULL;
41433
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 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
198 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201 purple_notification_manager_init(PurpleNotificationManager *manager) {
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
202 manager->notifications = g_ptr_array_new_full(0,
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
203 (GDestroyNotify)g_object_unref);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206 static void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207 purple_notification_manager_class_init(PurpleNotificationManagerClass *klass) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
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 obj_class->get_property = purple_notification_manager_get_property;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211 obj_class->finalize = purple_notification_manager_finalize;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212
42662
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
213 /**
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
214 * PurpleNotificationManager:item-type:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
215 *
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
216 * The type of items. See [iface@Gio.ListModel.get_item_type].
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
217 *
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
218 * Since: 3.0
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
219 */
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
220 properties[PROP_ITEM_TYPE] = g_param_spec_gtype(
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
221 "item-type", "item-type",
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
222 "The type of the contained items.",
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
223 G_TYPE_OBJECT,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
224 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
225
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
226 /**
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
227 * PurpleNotificationManager:n-items:
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
228 *
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
229 * The number of items. See [iface@Gio.ListModel.get_n_items].
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
230 *
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
231 * Since: 3.0
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
232 */
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
233 properties[PROP_N_ITEMS] = g_param_spec_uint(
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
234 "n-items", "n-items",
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
235 "The number of contained items.",
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
236 0, G_MAXUINT, 0,
f1f61c62fea6 Add item-type and n-items properties to PurpleNotificationManager
Gary Kramlich <grim@reaperworld.com>
parents: 42614
diff changeset
237 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239 /**
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240 * PurpleNotificationManager:unread-count:
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242 * The number of unread notifications in the manager.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
243 *
42614
b75a5bbf6c35 Remove the micro version from since tags for libpurple part 3
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
244 * Since: 3.0
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
245 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 properties[PROP_UNREAD_COUNT] = g_param_spec_uint(
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247 "unread-count", "unread-count",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
248 "The number of unread messages in the manager.",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
249 0, G_MAXUINT, 0,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
252 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
253
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
254 /**
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
255 * PurpleNotificationManager::added:
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
256 * @manager: The instance.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
257 * @notification: The [class@Notification] that was added.
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 * Emitted after @notification has been added to @manager.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
260 *
42614
b75a5bbf6c35 Remove the micro version from since tags for libpurple part 3
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
261 * Since: 3.0
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
262 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
263 signals[SIG_ADDED] = g_signal_new_class_handler(
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
264 "added",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
265 G_OBJECT_CLASS_TYPE(klass),
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
266 G_SIGNAL_RUN_LAST,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
267 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
268 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
269 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
270 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
271 G_TYPE_NONE,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
272 1,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
273 PURPLE_TYPE_NOTIFICATION);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
274
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
275 /**
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276 * PurpleNotificationManager::removed:
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
277 * @manager: The instance.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
278 * @notification: The [class@Notification] that was removed.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
279 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
280 * Emitted after @notification has been removed from @manager.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
281 *
42614
b75a5bbf6c35 Remove the micro version from since tags for libpurple part 3
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
282 * Since: 3.0
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
284 signals[SIG_REMOVED] = g_signal_new_class_handler(
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285 "removed",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
286 G_OBJECT_CLASS_TYPE(klass),
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
287 G_SIGNAL_RUN_LAST,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
288 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
289 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
290 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
291 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
292 G_TYPE_NONE,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
293 1,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
294 PURPLE_TYPE_NOTIFICATION);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
295
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
296 /**
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297 * PurpleNotificationManager::read:
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
298 * @manager: The instance.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
299 * @notification: The [class@Notification].
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
300 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301 * Emitted after @notification has been marked as read.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
302 *
42614
b75a5bbf6c35 Remove the micro version from since tags for libpurple part 3
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
303 * Since: 3.0
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
305 signals[SIG_READ] = g_signal_new_class_handler(
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
306 "read",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
307 G_OBJECT_CLASS_TYPE(klass),
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 G_SIGNAL_RUN_LAST,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
312 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
313 G_TYPE_NONE,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314 1,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315 PURPLE_TYPE_NOTIFICATION);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
317 /**
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318 * PurpleNotificationManager::unread:
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319 * @manager: The instance.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
320 * @notification: The [class@Notification].
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
321 *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
322 * Emitted after @notification has been marked as unread.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323 *
42614
b75a5bbf6c35 Remove the micro version from since tags for libpurple part 3
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
324 * Since: 3.0
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
325 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
326 signals[SIG_UNREAD] = g_signal_new_class_handler(
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327 "unread",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
328 G_OBJECT_CLASS_TYPE(klass),
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
329 G_SIGNAL_RUN_LAST,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
330 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
331 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
333 NULL,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
334 G_TYPE_NONE,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
335 1,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
336 PURPLE_TYPE_NOTIFICATION);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
337 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
338
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339 /******************************************************************************
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340 * Private API
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341 *****************************************************************************/
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
342 void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 purple_notification_manager_startup(void) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 if(default_manager == NULL) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345 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
346 g_object_add_weak_pointer(G_OBJECT(default_manager),
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
347 (gpointer *)&default_manager);
41433
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 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
350
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351 void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
352 purple_notification_manager_shutdown(void) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
353 g_clear_object(&default_manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
354 }
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 * Public API
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
358 *****************************************************************************/
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
359 PurpleNotificationManager *
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
360 purple_notification_manager_get_default(void) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
361 return default_manager;
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
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
364 GListModel *
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
365 purple_notification_manager_get_default_as_model(void) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
366 if(PURPLE_IS_NOTIFICATION_MANAGER(default_manager)) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
367 return G_LIST_MODEL(default_manager);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
368 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
369
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
370 return NULL;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
371 }
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
372
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
373 void
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
374 purple_notification_manager_add(PurpleNotificationManager *manager,
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
375 PurpleNotification *notification)
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
376 {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
377 g_return_if_fail(PURPLE_IS_NOTIFICATION_MANAGER(manager));
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
378 g_return_if_fail(PURPLE_IS_NOTIFICATION(notification));
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
379
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
380 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
381 const gchar *id = purple_notification_get_id(notification);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
382
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
383 g_warning("double add detected for notification %s", id);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
384
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
385 return;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
386 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
387
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
388 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
389
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
390 /* 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
391 * propagate out changes for any notification.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
392 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
393 g_signal_connect_object(notification, "notify::read",
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
394 G_CALLBACK(purple_notification_manager_notify_cb),
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
395 manager, 0);
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 /* 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
398 */
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
399 if(!purple_notification_get_read(notification)) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
400 purple_notification_manager_increment_unread_count(manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
401 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
402
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
403 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
404 g_list_model_items_changed(G_LIST_MODEL(manager), 0, 0, 1);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
405 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
406
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
407 void
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
408 purple_notification_manager_remove(PurpleNotificationManager *manager,
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
409 PurpleNotification *notification)
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
410 {
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
411 guint index = 0;
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
412
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
413 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
414 g_return_if_fail(PURPLE_IS_NOTIFICATION(notification));
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
415
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
416 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
417 /* 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
418 * removed from the hash table.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
419 */
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
420 g_object_ref(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 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
423 /* 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
424 * 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
425 * with our unread count accounting.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
426 */
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
427 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
428 purple_notification_manager_notify_cb,
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
429 manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
430
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
431 /* 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
432 * count.
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
433 */
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
434 if(!purple_notification_get_read(notification)) {
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
435 purple_notification_manager_decrement_unread_count(manager);
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
436 }
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_emit(G_OBJECT(manager), signals[SIG_REMOVED], 0, notification);
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
439 g_list_model_items_changed(G_LIST_MODEL(manager), index, 1, 0);
41438
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
440
86beaec0fa35 Create and add notifications for account errors.
Gary Kramlich <grim@reaperworld.com>
parents: 41433
diff changeset
441 g_object_unref(notification);
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
442 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
443 }
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
444
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
445 /*
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
446 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
447 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
448 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
449
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
450 A
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
451 A B C
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
452 B C
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
453 A A B C
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
454 B A C
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
455 B A A C
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
456 B C A
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
457 B C A A
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
458
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
459 set len = number_of_items
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
460 set pos = 0
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
461 set have_same = false
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
462 while pos < len
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
463 check item at pos
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
464 if same
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
465 if not have_same
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
466 reset count = 0
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
467 set start = pos
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
468 set have_same = TRUE
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
469
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
470 set count = count + 1
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
471 else
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
472 if have_same
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
473 remove count items from start
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
474 set pos = pos - count
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
475 set len = len - count
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
476 set have_same = FALSE
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
477 set pos = pos + 1
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
478 if have_same
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
479 remove count items from start
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
480 */
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
481 void
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
482 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
483 PurpleAccount *account,
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
484 gboolean all)
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
485 {
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
486 GListModel *model = NULL;
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
487 guint pos = 0, len = 0;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
488 guint start = 0, count = 0;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
489 gboolean have_same = FALSE;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
490
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
491 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
492 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
493
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
494 model = G_LIST_MODEL(manager);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
495
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
496 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
497 PurpleAccount *account2 = NULL;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
498 PurpleNotification *notification = NULL;
41817
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
499 PurpleNotificationType type;
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
500 gboolean can_remove = TRUE;
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
501
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
502 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
503
41817
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
504 /* 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
505 * 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
506 */
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
507 type = purple_notification_get_notification_type(notification);
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
508 if(type == PURPLE_NOTIFICATION_TYPE_CONNECTION_ERROR) {
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
509 can_remove = all;
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
510 }
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
511
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
512 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
513 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
514 /* 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
515 * position.
91f9ce89468b Fix connection errors getting deleted when an account is disconnected
Gary Kramlich <grim@reaperworld.com>
parents: 41511
diff changeset
516 */
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
517 if(!have_same) {
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
518 count = 0;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
519 start = pos;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
520 have_same = TRUE;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
521 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
522
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
523 /* 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
524 count++;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
525 } else {
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
526 if(have_same) {
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
527 /* Remove the run of items from the list. */
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
528 g_ptr_array_remove_range(manager->notifications, start, count);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
529 g_list_model_items_changed(model, start, count, 0);
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
530
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
531 /* 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
532 pos = pos - count;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
533 len = len - count;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
534
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
535 have_same = FALSE;
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
536 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
537 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
538 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
539
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
540 /* 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
541 if(have_same) {
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
542 g_ptr_array_remove_range(manager->notifications, start, count);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
543 g_list_model_items_changed(model, start, count, 0);
41511
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
544 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
545 }
2036d450fd18 Add purple_notification_manager_remove_with_account.
Gary Kramlich <grim@reaperworld.com>
parents: 41441
diff changeset
546
41433
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
547 guint
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
548 purple_notification_manager_get_unread_count(PurpleNotificationManager *manager) {
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
549 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
550
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
551 return manager->unread_count;
d563b345a096 Phase 1 of the Notifications API
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
552 }
41441
e114ed471a1e Implement the UI for the new Notifications API.
Gary Kramlich <grim@reaperworld.com>
parents: 41438
diff changeset
553
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
554 void
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
555 purple_notification_manager_clear(PurpleNotificationManager *manager) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
556 guint count = 0;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
557
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
558 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
559
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
560 count = manager->notifications->len;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
561
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
562 for(guint pos = 0; pos < count; pos++) {
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
563 PurpleNotification *notification = NULL;
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
564
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
565 notification = g_ptr_array_index(manager->notifications, pos);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
566
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
567 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
568 }
e114ed471a1e Implement the UI for the new Notifications API.
Gary Kramlich <grim@reaperworld.com>
parents: 41438
diff changeset
569
41936
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
570 g_ptr_array_remove_range(manager->notifications, 0, count);
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
571
c4a96b5eecba Make PurpleNotificationManager implement GListModel
Gary Kramlich <grim@reaperworld.com>
parents: 41817
diff changeset
572 g_list_model_items_changed(G_LIST_MODEL(manager), 0, count, 0);
41441
e114ed471a1e Implement the UI for the new Notifications API.
Gary Kramlich <grim@reaperworld.com>
parents: 41438
diff changeset
573 }

mercurial