pidgin/pidginimwindow.c

Sun, 14 Jan 2024 20:08:13 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Sun, 14 Jan 2024 20:08:13 -0600
changeset 42568
31e8c7c92e2f
parent 42562
f02878f30f91
child 42575
580339aa47cc
permissions
-rw-r--r--

Make sure all of the license headers for IRCv3 are GPLv2

Testing Done:
Ran `licensecheck` from debian in the following way.

```
$ licensecheck *.[ch] | cut -d: -f 2 | sort | uniq -c
27 GNU General Public License v2.0 or later
```

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

42562
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Pidgin - Internet Messenger
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * Pidgin is the legal property of its developers, whose names are too numerous
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * source distribution.
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include <purple.h>
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #include "pidginimwindow.h"
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 #include "pidginaccountrow.h"
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 struct _PidginIMWindow {
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 AdwMessageDialog parent;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 GtkCustomFilter *filter;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 GtkWidget *account;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 GtkWidget *username;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 };
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 /******************************************************************************
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 * Helpers
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 *****************************************************************************/
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 static gboolean
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 pidgin_im_window_filter_accounts(gpointer item, G_GNUC_UNUSED gpointer data) {
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 if(PURPLE_IS_ACCOUNT(item)) {
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 PurpleAccount *account = PURPLE_ACCOUNT(item);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 PurpleProtocol *protocol = purple_account_get_protocol(account);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 if(PURPLE_IS_PROTOCOL(protocol)) {
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 return PURPLE_PROTOCOL_IMPLEMENTS(protocol, CONVERSATION,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 send_message_async);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 }
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 }
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 return FALSE;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 }
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 /******************************************************************************
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 * Callbacks
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 *****************************************************************************/
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 static void
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 pidgin_im_window_username_changed_cb(GtkEditable *self, gpointer data) {
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 const char *text = NULL;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 gboolean enabled = FALSE;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 text = gtk_editable_get_text(self);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 enabled = !purple_strempty(text);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 adw_message_dialog_set_response_enabled(data, "okay", enabled);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 }
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 static void
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 pidgin_im_window_response_cb(AdwMessageDialog *self,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 const char *response,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 G_GNUC_UNUSED gpointer data)
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 {
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 PidginIMWindow *window = PIDGIN_IM_WINDOW(self);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 PurpleAccount *account = NULL;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 PurpleConversation *im = NULL;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 PurpleConversationManager *manager = NULL;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 const char *username = NULL;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 if(!purple_strequal(response, "okay")) {
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 return;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 }
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 account = pidgin_account_row_get_account(PIDGIN_ACCOUNT_ROW(window->account)) ;
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 username = gtk_editable_get_text(GTK_EDITABLE(window->username));
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 manager = purple_conversation_manager_get_default();
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 im = purple_conversation_manager_find_im(manager, account, username);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 if(!PURPLE_IS_IM_CONVERSATION(im)) {
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 /* This constructor automagically registers the conversation with the
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 * manager.
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 */
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 purple_im_conversation_new(account, username);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 }
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 }
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 /******************************************************************************
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 * GObject Implementation
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 *****************************************************************************/
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 G_DEFINE_TYPE(PidginIMWindow, pidgin_im_window, ADW_TYPE_MESSAGE_DIALOG)
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 static void
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 pidgin_im_window_init(PidginIMWindow *window) {
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 gtk_widget_init_template(GTK_WIDGET(window));
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 gtk_custom_filter_set_filter_func(window->filter,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 pidgin_im_window_filter_accounts,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 NULL, NULL);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 }
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 static void
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 pidgin_im_window_class_init(PidginIMWindowClass *klass) {
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 gtk_widget_class_set_template_from_resource(
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 widget_class,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 "/im/pidgin/Pidgin3/imwindow.ui"
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 );
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 gtk_widget_class_bind_template_child(widget_class, PidginIMWindow,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 filter);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 gtk_widget_class_bind_template_child(widget_class, PidginIMWindow,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 account);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 gtk_widget_class_bind_template_child(widget_class, PidginIMWindow,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 username);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131 gtk_widget_class_bind_template_callback(widget_class,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132 pidgin_im_window_username_changed_cb);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 gtk_widget_class_bind_template_callback(widget_class,
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 pidgin_im_window_response_cb);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 }
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 /******************************************************************************
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 * Public API
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 *****************************************************************************/
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 GtkWidget *
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 pidgin_im_window_new(void) {
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 return g_object_new(PIDGIN_TYPE_IM_WINDOW, NULL);
f02878f30f91 Create a full widget for the new instant message window
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 }

mercurial