finch/finchnotifications.c

Mon, 05 Sep 2022 20:51:04 -0500

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Mon, 05 Sep 2022 20:51:04 -0500
changeset 41647
63c65c9fbb34
parent 41619
f19b4c13bc90
child 41936
c4a96b5eecba
permissions
-rw-r--r--

Small cleanups to xmlnode

Mostly just wanted to remove ending newlines from the debug messages, but also added braces and a couple simplifications.

Testing Done:
Compiled only.

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

41510
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Finch - Universal Text Chat Client
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * Finch is the legal property of its developers, whose names are too numerous
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * source distribution.
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include <config.h>
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #include <glib.h>
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 #include <glib/gi18n-lib.h>
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 #include <glib/gstdio.h>
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 #include <purple.h>
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 #include <gnt.h>
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 #include "finchnotifications.h"
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 #include "gntaccount.h"
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 static struct {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 GntWidget *window;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 GntWidget *list;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 } notifications;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 /*******************************************************************************
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 * Helpers
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 ******************************************************************************/
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 static void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 finch_notifications_update(GntTree *list, GListModel *model) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 guint index = 0;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 gnt_tree_remove_all(GNT_TREE(list));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 for(index = 0; index < g_list_model_get_n_items(model); index++) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 PurpleNotification *notification = g_list_model_get_item(model, index);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 GntTreeRow *row = NULL;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 row = gnt_tree_create_row(list,
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 purple_notification_get_title(notification));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 gnt_tree_add_row_last(list, notification, row, NULL);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 static void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 finch_notification_delete_notification(PurpleNotification *notification) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 if(PURPLE_IS_NOTIFICATION(notification)) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 PurpleNotificationManager *manager = NULL;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65
41514
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
66 purple_notification_delete(notification);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
67
41510
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 manager = purple_notification_manager_get_default();
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 purple_notification_manager_remove(manager, notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 /*******************************************************************************
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 * Finch Notification Callbacks
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 ******************************************************************************/
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 static void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 finch_notification_delete(G_GNUC_UNUSED GntWidget *widget, gpointer data) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 PurpleNotification *notification = g_object_get_data(data, "notification");
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 finch_notification_delete_notification(notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 gnt_widget_destroy(GNT_WIDGET(data));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 static void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 finch_notification_reconnect_account(G_GNUC_UNUSED GntWidget *widget,
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 gpointer data)
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 PurpleNotification *notification = g_object_get_data(data, "notification");
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 PurpleAccount *account = purple_notification_get_account(notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 if(PURPLE_IS_ACCOUNT(account)) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 purple_account_connect(account);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 gnt_widget_destroy(GNT_WIDGET(data));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 static void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 finch_notification_reenable_account(G_GNUC_UNUSED GntWidget *widget,
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 gpointer data)
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 PurpleNotification *notification = g_object_get_data(data, "notification");
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 PurpleAccount *account = purple_notification_get_account(notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 if(PURPLE_IS_ACCOUNT(account)) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 purple_account_set_enabled(account, TRUE);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 gnt_widget_destroy(GNT_WIDGET(data));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 static void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 finch_notification_modify_account(G_GNUC_UNUSED GntWidget *widget,
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 gpointer data)
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 PurpleNotification *notification = g_object_get_data(data, "notification");
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 PurpleAccount *account = purple_notification_get_account(notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 if(PURPLE_IS_ACCOUNT(account)) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 finch_account_dialog_show(account);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 gnt_widget_destroy(GNT_WIDGET(data));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126
41514
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
127 static void
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
128 finch_notification_contact_authorize(G_GNUC_UNUSED GntWidget *widget,
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
129 gpointer data)
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
130 {
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
131 PurpleAccount *account = NULL;
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
132 PurpleNotification *notification = NULL;
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
133 PurpleNotificationManager *manager = NULL;
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
134 PurpleAuthorizationRequest *auth_request = NULL;
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
135 const gchar *alias = NULL, *username = NULL;
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
136
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
137 /* Get the notification and authorization request from the data. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
138 notification = g_object_get_data(data, "notification");
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
139 auth_request = purple_notification_get_data(notification);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
140
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
141 /* Accept the authorization request. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
142 purple_authorization_request_accept(auth_request);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
143
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
144 /* Remove the notification from the manager. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
145 manager = purple_notification_manager_get_default();
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
146 purple_notification_manager_remove(manager, notification);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
147
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
148 /* Request the user to add the person they just authorized. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
149 account = purple_authorization_request_get_account(auth_request);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
150 alias = purple_authorization_request_get_alias(auth_request);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
151 username = purple_authorization_request_get_username(auth_request);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
152 purple_blist_request_add_buddy(account, username, NULL, alias);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
153
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
154 /* Destroy the dialog. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
155 gnt_widget_destroy(GNT_WIDGET(data));
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
156 }
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
157
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
158 static void
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
159 finch_notification_contact_deny(G_GNUC_UNUSED GntWidget *widget, gpointer data)
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
160 {
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
161 PurpleNotification *notification = NULL;
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
162 PurpleNotificationManager *manager = NULL;
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
163 PurpleAuthorizationRequest *auth_request = NULL;
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
164
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
165 /* Get the notification and authorization request from the data. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
166 notification = g_object_get_data(data, "notification");
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
167 auth_request = purple_notification_get_data(notification);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
168
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
169 /* Deny the request. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
170 purple_authorization_request_deny(auth_request, NULL);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
171
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
172 /* Remove the notification from the manager. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
173 manager = purple_notification_manager_get_default();
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
174 purple_notification_manager_remove(manager, notification);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
175
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
176 /* Destroy the dialog. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
177 gnt_widget_destroy(GNT_WIDGET(data));
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
178 }
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
179
41510
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180 /*******************************************************************************
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181 * Finch Notification API
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 ******************************************************************************/
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 static void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184 finch_notification_show(PurpleNotification *notification) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 GntWidget *dialog = NULL, *label = NULL, *hbox = NULL, *button = NULL;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 PurpleAccount *account = NULL;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187 PurpleNotificationType type;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 gpointer data = NULL;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190 account = purple_notification_get_account(notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192 dialog = gnt_box_new(FALSE, TRUE);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193 gnt_box_set_toplevel(GNT_BOX(dialog), TRUE);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
194 gnt_box_set_alignment(GNT_BOX(dialog), GNT_ALIGN_MID);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195 g_object_set_data(G_OBJECT(dialog), "notification", notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197 label = gnt_label_new(purple_notification_get_title(notification));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 gnt_box_add_widget(GNT_BOX(dialog), label);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200 hbox = gnt_box_new(FALSE, FALSE);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202 type = purple_notification_get_notification_type(notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203 data = purple_notification_get_data(notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205 if(type == PURPLE_NOTIFICATION_TYPE_GENERIC) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206 gnt_box_set_title(GNT_BOX(dialog),
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207 purple_notification_get_title(notification));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 label = gnt_label_new(purple_notification_get_data(notification));
41619
f19b4c13bc90 Make sure we pack the label for generic notifications
Gary Kramlich <grim@reaperworld.com>
parents: 41514
diff changeset
209 gnt_box_add_widget(GNT_BOX(dialog), label);
41510
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
210 } else if(type == PURPLE_NOTIFICATION_TYPE_CONNECTION_ERROR) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211 PurpleConnectionErrorInfo *info = data;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212
41514
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
213 /* Set the title. */
41510
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214 gnt_box_set_title(GNT_BOX(dialog), _("Connection Error"));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 /* Add the connection error reason. */
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 label = gnt_label_new(info->description);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218 gnt_box_add_widget(GNT_BOX(dialog), label);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
220 /* Add the buttons. */
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 if(purple_account_get_enabled(account)) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222 button = gnt_button_new(_("Reconnect"));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
223 g_signal_connect(button, "activate",
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
224 G_CALLBACK(finch_notification_reconnect_account),
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225 dialog);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
226 } else {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
227 button = gnt_button_new(_("Re-enable"));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
228 g_signal_connect(button, "activate",
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
229 G_CALLBACK(finch_notification_reenable_account),
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230 dialog);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
232 gnt_box_add_widget(GNT_BOX(hbox), button);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234 button = gnt_button_new(_("Modify Account"));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235 g_signal_connect(button, "activate",
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 G_CALLBACK(finch_notification_modify_account),
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237 dialog);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238 gnt_box_add_widget(GNT_BOX(hbox), button);
41514
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
239 } else if(type == PURPLE_NOTIFICATION_TYPE_AUTHORIZATION_REQUEST) {
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
240 PurpleAuthorizationRequest *auth_request = NULL;
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
241 const gchar *message = NULL;
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
242
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
243 /* Set the title. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
244 gnt_box_set_title(GNT_BOX(dialog), _("Authorization Request"));
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
245
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
246 auth_request = purple_notification_get_data(notification);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
247 message = purple_authorization_request_get_message(auth_request);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
248
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
249 /* Add the message if we have one. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
250 if(message != NULL && *message != '\0') {
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
251 label = gnt_label_new(message);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
252 gnt_box_add_widget(GNT_BOX(dialog), label);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
253 }
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
254
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
255 /* Add the buttons. */
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
256 button = gnt_button_new(_("Authorize"));
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
257 g_signal_connect(button, "activate",
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
258 G_CALLBACK(finch_notification_contact_authorize),
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
259 dialog);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
260 gnt_box_add_widget(GNT_BOX(hbox), button);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
261
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
262 button = gnt_button_new(_("Deny"));
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
263 g_signal_connect(button, "activate",
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
264 G_CALLBACK(finch_notification_contact_deny), dialog);
a96768bacb59 Create PurpleAuthorizationRequest and use it for notifications.
Gary Kramlich <grim@reaperworld.com>
parents: 41510
diff changeset
265 gnt_box_add_widget(GNT_BOX(hbox), button);
41510
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
266 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
267
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
268 gnt_box_add_widget(GNT_BOX(dialog), hbox);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
269
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
270 button = gnt_button_new(_("Delete"));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
271 g_signal_connect(button, "activate",
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
272 G_CALLBACK(finch_notification_delete), dialog);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
273 gnt_box_add_widget(GNT_BOX(hbox), button);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
274
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
275 gnt_widget_show(dialog);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
277
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
278 /*******************************************************************************
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
279 * Callbacks
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
280 ******************************************************************************/
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
281 static void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
282 finch_notifications_changed_cb(GListModel *model,
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283 G_GNUC_UNUSED guint position,
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
284 G_GNUC_UNUSED guint removed,
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285 guint added,
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
286 gpointer data)
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
287 {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
288 finch_notifications_update(data, model);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
289
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
290 if(added > 0) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
291 gnt_widget_set_urgent(notifications.window);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
292 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
293 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
294
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
295 static void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
296 finch_notifications_open_cb(G_GNUC_UNUSED GntWidget *w, gpointer data) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297 PurpleNotification *notification = NULL;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
298
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
299 notification = gnt_tree_get_selection_data(GNT_TREE(notifications.list));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
300 if(!PURPLE_IS_NOTIFICATION(notification)) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301 return;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
302 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
303
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 finch_notification_show(notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
305 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
306
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
307 static void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 finch_notifications_delete_cb(G_GNUC_UNUSED GntWidget *widget, gpointer data) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309 PurpleNotification *notification = NULL;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311 notification = gnt_tree_get_selection_data(GNT_TREE(notifications.list));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
312
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
313 finch_notification_delete_notification(notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
317 static void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318 finch_notifications_activate_cb(G_GNUC_UNUSED GntWidget *w,
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319 G_GNUC_UNUSED gpointer data)
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
320 {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
321 PurpleNotification *notification = NULL;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
322
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323 notification = gnt_tree_get_selection_data(GNT_TREE(notifications.list));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
324
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
325 finch_notification_show(notification);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
326 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
328 /*******************************************************************************
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
329 * Public API
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
330 ******************************************************************************/
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
331 void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332 finch_notifications_window_show(void) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
333 PurpleNotificationManager *manager = NULL;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
334 GntWidget *wid, *box;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
335 GListModel *model = NULL;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
336
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
337 if(notifications.window) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
338 gnt_window_present(notifications.window);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340 return;
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
342
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 notifications.window = gnt_vbox_new(FALSE);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 gnt_box_set_toplevel(GNT_BOX(notifications.window), TRUE);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345 gnt_box_set_fill(GNT_BOX(notifications.window), TRUE);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
346 gnt_box_set_title(GNT_BOX(notifications.window), _("Notifications"));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
347 gnt_box_set_alignment(GNT_BOX(notifications.window), GNT_ALIGN_MID);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
348 gnt_box_set_pad(GNT_BOX(notifications.window), 0);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
349 gnt_widget_set_name(notifications.window, "notifications");
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
350
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351 /* Create the box that lists all of the notifications. */
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
352 notifications.list = gnt_tree_new_with_columns(1);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
353 gnt_tree_set_compare_func(GNT_TREE(notifications.list),
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
354 purple_notification_compare);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
355 gnt_widget_set_has_border(notifications.list, FALSE);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
356 gnt_box_add_widget(GNT_BOX(notifications.window), notifications.list);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
357 g_signal_connect(notifications.list, "activate",
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
358 G_CALLBACK(finch_notifications_activate_cb), NULL);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
359
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
360 /* Get the notification manager to get the model and populate the list. */
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
361 manager = purple_notification_manager_get_default();
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
362 model = purple_notification_manager_get_model(manager);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
363 finch_notifications_update(GNT_TREE(notifications.list), model);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
364 g_signal_connect_object(model, "items-changed",
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
365 G_CALLBACK(finch_notifications_changed_cb),
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
366 notifications.list, 0);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
367
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
368 gnt_box_add_widget(GNT_BOX(notifications.window), gnt_line_new(FALSE));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
369
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
370 box = gnt_hbox_new(FALSE);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
371 gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_MID);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
372 gnt_box_set_fill(GNT_BOX(box), FALSE);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
373
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
374 wid = gnt_button_new(_("Open"));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
375 g_signal_connect(wid, "activate", G_CALLBACK(finch_notifications_open_cb),
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
376 NULL);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
377 gnt_box_add_widget(GNT_BOX(box), wid);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
378
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
379 wid = gnt_button_new(_("Delete"));
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
380 g_signal_connect(wid, "activate", G_CALLBACK(finch_notifications_delete_cb),
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
381 NULL);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
382 gnt_box_add_widget(GNT_BOX(box), wid);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
383
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
384 gnt_box_add_widget(GNT_BOX(notifications.window), box);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
385
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
386 gnt_widget_show(notifications.window);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
387 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
388
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
389 void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
390 finch_notifications_init(void) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
391 }
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
392
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
393 void
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
394 finch_notifications_uninit(void) {
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
395 g_clear_pointer(&notifications.window, gnt_widget_destroy);
630da93b9984 Implement notifications in Finch
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
396 }

mercurial