libpurple/purplenotificationmanager.c

Tue, 20 Feb 2024 01:23:04 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 20 Feb 2024 01:23:04 -0600
changeset 42594
eddde70cedd8
parent 42584
687260353985
child 42614
b75a5bbf6c35
permissions
-rw-r--r--

Create a test for verifying license headers and correct the ones that were wrong

We might want to move check_license_header.py script out to somewhere else,
but this is fine for now as we're just getting things going.

Testing Done:
Compiled with the Turtles.

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

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

mercurial