pidgin/pidginnotificationconnectionerror.c

Thu, 15 May 2025 23:56:42 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 15 May 2025 23:56:42 -0500
changeset 43257
934732945514
parent 42986
f535fef9f727
permissions
-rw-r--r--

Add Purple.Protocol:tags and add unit tests for protocol properties

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

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

42986
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Pidgin - Internet Messenger
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * Pidgin is the legal property of its developers, whose names are too numerous
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * source distribution.
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include <glib/gi18n-lib.h>
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #include <purple.h>
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 #include "pidgin/pidginnotificationconnectionerror.h"
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 struct _PidginNotificationConnectionError {
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 PidginNotification parent;
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 GtkWidget *reconnect;
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 GtkWidget *modify;
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 };
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 G_DEFINE_FINAL_TYPE(PidginNotificationConnectionError,
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 pidgin_notification_connection_error, PIDGIN_TYPE_NOTIFICATION)
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 /******************************************************************************
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 * Helpers
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 *****************************************************************************/
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 static void
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 pidgin_notification_connection_error_update_targets(PidginNotificationConnectionError *error)
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 {
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 PurpleAccount *account = NULL;
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 PidginNotification *pidgin_notification = PIDGIN_NOTIFICATION(error);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 PurpleNotification *purple_notification = NULL;
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 const char *id = NULL;
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 purple_notification = pidgin_notification_get_notification(pidgin_notification);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 account = purple_notification_get_account(purple_notification);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 id = purple_account_get_id(account);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 gtk_actionable_set_action_target(GTK_ACTIONABLE(error->reconnect), "s",
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 id);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 gtk_actionable_set_action_target(GTK_ACTIONABLE(error->modify), "s", id);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 }
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 /******************************************************************************
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 * Callbacks
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 *****************************************************************************/
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 static void
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 pidgin_notification_connection_error_account_notify_cb(G_GNUC_UNUSED GObject *self,
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 G_GNUC_UNUSED GParamSpec *pspec,
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 gpointer data)
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 {
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 pidgin_notification_connection_error_update_targets(data);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 }
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 /******************************************************************************
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 * GObject Implementation
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 *****************************************************************************/
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 static void
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 pidgin_notification_connection_error_init(PidginNotificationConnectionError *notification)
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 {
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 gtk_widget_init_template(GTK_WIDGET(notification));
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 }
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 static void
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 pidgin_notification_connection_error_constructed(GObject *obj) {
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 PidginNotification *pidgin_notification = PIDGIN_NOTIFICATION(obj);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 PurpleNotification *purple_notification = NULL;
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 G_OBJECT_CLASS(pidgin_notification_connection_error_parent_class)->constructed(obj);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 purple_notification = pidgin_notification_get_notification(pidgin_notification);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 g_signal_connect_object(purple_notification, "notify::account",
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 G_CALLBACK(pidgin_notification_connection_error_account_notify_cb),
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 obj, G_CONNECT_DEFAULT);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 pidgin_notification_connection_error_update_targets(PIDGIN_NOTIFICATION_CONNECTION_ERROR(obj));
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 }
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 static void
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 pidgin_notification_connection_error_class_init(PidginNotificationConnectionErrorClass *klass)
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 {
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 obj_class->constructed = pidgin_notification_connection_error_constructed;
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 gtk_widget_class_set_template_from_resource(
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 widget_class,
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 "/im/pidgin/Pidgin3/notificationconnectionerror.ui"
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 );
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 gtk_widget_class_bind_template_child(widget_class,
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 PidginNotificationConnectionError,
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 reconnect);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 gtk_widget_class_bind_template_child(widget_class,
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 PidginNotificationConnectionError,
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 modify);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 }
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 /******************************************************************************
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 * API
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 *****************************************************************************/
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 GtkWidget *
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 pidgin_notification_connection_error_new(PurpleNotificationConnectionError *notification)
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 {
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 g_return_val_if_fail(PURPLE_IS_NOTIFICATION_CONNECTION_ERROR(notification),
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 NULL);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 return g_object_new(
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 PIDGIN_TYPE_NOTIFICATION_CONNECTION_ERROR,
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 "notification", notification,
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 NULL);
f535fef9f727 Create Pidgin.NotificationConnectionError
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 }

mercurial