| |
1 /* |
| |
2 * Pidgin - Internet Messenger |
| |
3 * Copyright (C) Pidgin Developers <devel@pidgin.im> |
| |
4 * |
| |
5 * Pidgin is the legal property of its developers, whose names are too numerous |
| |
6 * to list here. Please refer to the COPYRIGHT file distributed with this |
| |
7 * source distribution. |
| |
8 * |
| |
9 * This program is free software; you can redistribute it and/or modify |
| |
10 * it under the terms of the GNU General Public License as published by |
| |
11 * the Free Software Foundation; either version 2 of the License, or |
| |
12 * (at your option) any later version. |
| |
13 * |
| |
14 * This program is distributed in the hope that it will be useful, |
| |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| |
17 * GNU General Public License for more details. |
| |
18 * |
| |
19 * You should have received a copy of the GNU General Public License |
| |
20 * along with this program; if not, see <https://www.gnu.org/licenses/>. |
| |
21 */ |
| |
22 |
| |
23 #include <glib/gi18n-lib.h> |
| |
24 |
| |
25 #include <purple.h> |
| |
26 |
| |
27 #include "pidgin/pidginnotificationauthorizationrequest.h" |
| |
28 |
| |
29 struct _PidginNotificationAuthorizationRequest { |
| |
30 PidginNotification parent; |
| |
31 }; |
| |
32 |
| |
33 G_DEFINE_FINAL_TYPE(PidginNotificationAuthorizationRequest, |
| |
34 pidgin_notification_authorization_request, |
| |
35 PIDGIN_TYPE_NOTIFICATION) |
| |
36 |
| |
37 /****************************************************************************** |
| |
38 * Callbacks |
| |
39 *****************************************************************************/ |
| |
40 static void |
| |
41 pidgin_notification_authorization_request_create_dm_cb(GObject *self, |
| |
42 GAsyncResult *result, |
| |
43 G_GNUC_UNUSED gpointer data) |
| |
44 { |
| |
45 PurpleContact *contact = PURPLE_CONTACT(self); |
| |
46 PurpleConversation *conversation = NULL; |
| |
47 GError *error = NULL; |
| |
48 |
| |
49 conversation = purple_contact_create_dm_finish(contact, result, &error); |
| |
50 if(error != NULL) { |
| |
51 g_warning("failed to create dm for %s: %s", |
| |
52 purple_contact_info_get_name_for_display(PURPLE_CONTACT_INFO(contact)), |
| |
53 error->message); |
| |
54 |
| |
55 g_clear_error(&error); |
| |
56 g_clear_object(&conversation); |
| |
57 |
| |
58 return; |
| |
59 } |
| |
60 |
| |
61 if(PURPLE_IS_CONVERSATION(conversation)) { |
| |
62 purple_conversation_present(conversation); |
| |
63 } |
| |
64 |
| |
65 g_clear_object(&conversation); |
| |
66 } |
| |
67 |
| |
68 /****************************************************************************** |
| |
69 * Actions |
| |
70 *****************************************************************************/ |
| |
71 static void |
| |
72 pidgin_notification_authorization_request_accept(GtkWidget *self, |
| |
73 G_GNUC_UNUSED const char *action_name, |
| |
74 G_GNUC_UNUSED GVariant *parameter) |
| |
75 { |
| |
76 PidginNotification *pidgin_notification = PIDGIN_NOTIFICATION(self); |
| |
77 PurpleAuthorizationRequest *request = NULL; |
| |
78 PurpleNotification *purple_notification = NULL; |
| |
79 PurpleNotificationAuthorizationRequest *notification_authorization_request = NULL; |
| |
80 |
| |
81 purple_notification = pidgin_notification_get_notification(pidgin_notification); |
| |
82 notification_authorization_request = PURPLE_NOTIFICATION_AUTHORIZATION_REQUEST(purple_notification); |
| |
83 request = purple_notification_authorization_request_get_request(notification_authorization_request); |
| |
84 |
| |
85 purple_authorization_request_accept(request); |
| |
86 |
| |
87 purple_notification_delete(purple_notification); |
| |
88 } |
| |
89 |
| |
90 static void |
| |
91 pidgin_notification_authorization_request_message(GtkWidget *self, |
| |
92 G_GNUC_UNUSED const char *action_name, |
| |
93 G_GNUC_UNUSED GVariant *parameter) |
| |
94 { |
| |
95 PidginNotification *pidgin_notification = PIDGIN_NOTIFICATION(self); |
| |
96 PurpleNotification *purple_notification = NULL; |
| |
97 PurpleNotificationAuthorizationRequest *notification_authorization_request = NULL; |
| |
98 PurpleAuthorizationRequest *request = NULL; |
| |
99 PurpleContact *contact = NULL; |
| |
100 PurpleConversation *conversation = NULL; |
| |
101 |
| |
102 purple_notification = pidgin_notification_get_notification(pidgin_notification); |
| |
103 notification_authorization_request = PURPLE_NOTIFICATION_AUTHORIZATION_REQUEST(purple_notification); |
| |
104 request = purple_notification_authorization_request_get_request(notification_authorization_request); |
| |
105 contact = purple_authorization_request_get_contact(request); |
| |
106 |
| |
107 conversation = purple_contact_find_dm(contact); |
| |
108 if(PURPLE_IS_CONVERSATION(conversation)) { |
| |
109 purple_conversation_present(conversation); |
| |
110 } else { |
| |
111 purple_contact_create_dm_async(contact, NULL, |
| |
112 pidgin_notification_authorization_request_create_dm_cb, |
| |
113 NULL); |
| |
114 } |
| |
115 } |
| |
116 |
| |
117 static void |
| |
118 pidgin_notification_authorization_request_deny(GtkWidget *self, |
| |
119 G_GNUC_UNUSED const char *action_name, |
| |
120 G_GNUC_UNUSED GVariant *parameter) |
| |
121 { |
| |
122 PidginNotification *pidgin_notification = PIDGIN_NOTIFICATION(self); |
| |
123 PurpleAuthorizationRequest *request = NULL; |
| |
124 PurpleNotification *purple_notification = NULL; |
| |
125 PurpleNotificationAuthorizationRequest *notification_authorization_request = NULL; |
| |
126 |
| |
127 purple_notification = pidgin_notification_get_notification(pidgin_notification); |
| |
128 notification_authorization_request = PURPLE_NOTIFICATION_AUTHORIZATION_REQUEST(purple_notification); |
| |
129 request = purple_notification_authorization_request_get_request(notification_authorization_request); |
| |
130 |
| |
131 purple_authorization_request_deny(request, NULL); |
| |
132 |
| |
133 purple_notification_delete(purple_notification); |
| |
134 } |
| |
135 |
| |
136 /****************************************************************************** |
| |
137 * GObject Implementation |
| |
138 *****************************************************************************/ |
| |
139 static void |
| |
140 pidgin_notification_authorization_request_init(PidginNotificationAuthorizationRequest *notification) |
| |
141 { |
| |
142 gtk_widget_init_template(GTK_WIDGET(notification)); |
| |
143 } |
| |
144 |
| |
145 static void |
| |
146 pidgin_notification_authorization_request_class_init(PidginNotificationAuthorizationRequestClass *klass) |
| |
147 { |
| |
148 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); |
| |
149 |
| |
150 gtk_widget_class_set_template_from_resource( |
| |
151 widget_class, |
| |
152 "/im/pidgin/Pidgin3/notificationauthorizationrequest.ui" |
| |
153 ); |
| |
154 |
| |
155 gtk_widget_class_install_action(widget_class, "notification.accept", |
| |
156 NULL, |
| |
157 pidgin_notification_authorization_request_accept); |
| |
158 gtk_widget_class_install_action(widget_class, "notification.message", |
| |
159 NULL, |
| |
160 pidgin_notification_authorization_request_message); |
| |
161 gtk_widget_class_install_action(widget_class, "notification.deny", |
| |
162 NULL, |
| |
163 pidgin_notification_authorization_request_deny); |
| |
164 } |
| |
165 |
| |
166 /****************************************************************************** |
| |
167 * API |
| |
168 *****************************************************************************/ |
| |
169 GtkWidget * |
| |
170 pidgin_notification_authorization_request_new(PurpleNotificationAuthorizationRequest *notification) |
| |
171 { |
| |
172 g_return_val_if_fail(PURPLE_IS_NOTIFICATION_AUTHORIZATION_REQUEST(notification), |
| |
173 NULL); |
| |
174 |
| |
175 return g_object_new( |
| |
176 PIDGIN_TYPE_NOTIFICATION_AUTHORIZATION_REQUEST, |
| |
177 "notification", notification, |
| |
178 NULL); |
| |
179 } |