pidgin/pidginimwindow.c

changeset 42562
f02878f30f91
child 42575
580339aa47cc
equal deleted inserted replaced
42561:998b44b2c5f1 42562:f02878f30f91
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 <purple.h>
24
25 #include "pidginimwindow.h"
26
27 #include "pidginaccountrow.h"
28
29 struct _PidginIMWindow {
30 AdwMessageDialog parent;
31
32 GtkCustomFilter *filter;
33
34 GtkWidget *account;
35 GtkWidget *username;
36 };
37
38 /******************************************************************************
39 * Helpers
40 *****************************************************************************/
41 static gboolean
42 pidgin_im_window_filter_accounts(gpointer item, G_GNUC_UNUSED gpointer data) {
43 if(PURPLE_IS_ACCOUNT(item)) {
44 PurpleAccount *account = PURPLE_ACCOUNT(item);
45 PurpleProtocol *protocol = purple_account_get_protocol(account);
46
47 if(PURPLE_IS_PROTOCOL(protocol)) {
48 return PURPLE_PROTOCOL_IMPLEMENTS(protocol, CONVERSATION,
49 send_message_async);
50 }
51 }
52
53 return FALSE;
54
55 }
56
57 /******************************************************************************
58 * Callbacks
59 *****************************************************************************/
60 static void
61 pidgin_im_window_username_changed_cb(GtkEditable *self, gpointer data) {
62 const char *text = NULL;
63 gboolean enabled = FALSE;
64
65 text = gtk_editable_get_text(self);
66 enabled = !purple_strempty(text);
67
68 adw_message_dialog_set_response_enabled(data, "okay", enabled);
69 }
70
71 static void
72 pidgin_im_window_response_cb(AdwMessageDialog *self,
73 const char *response,
74 G_GNUC_UNUSED gpointer data)
75 {
76 PidginIMWindow *window = PIDGIN_IM_WINDOW(self);
77 PurpleAccount *account = NULL;
78 PurpleConversation *im = NULL;
79 PurpleConversationManager *manager = NULL;
80 const char *username = NULL;
81
82 if(!purple_strequal(response, "okay")) {
83 return;
84 }
85
86 account = pidgin_account_row_get_account(PIDGIN_ACCOUNT_ROW(window->account)) ;
87 username = gtk_editable_get_text(GTK_EDITABLE(window->username));
88
89 manager = purple_conversation_manager_get_default();
90 im = purple_conversation_manager_find_im(manager, account, username);
91
92 if(!PURPLE_IS_IM_CONVERSATION(im)) {
93 /* This constructor automagically registers the conversation with the
94 * manager.
95 */
96 purple_im_conversation_new(account, username);
97 }
98 }
99
100 /******************************************************************************
101 * GObject Implementation
102 *****************************************************************************/
103 G_DEFINE_TYPE(PidginIMWindow, pidgin_im_window, ADW_TYPE_MESSAGE_DIALOG)
104
105 static void
106 pidgin_im_window_init(PidginIMWindow *window) {
107 gtk_widget_init_template(GTK_WIDGET(window));
108
109 gtk_custom_filter_set_filter_func(window->filter,
110 pidgin_im_window_filter_accounts,
111 NULL, NULL);
112 }
113
114 static void
115 pidgin_im_window_class_init(PidginIMWindowClass *klass) {
116 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
117
118 gtk_widget_class_set_template_from_resource(
119 widget_class,
120 "/im/pidgin/Pidgin3/imwindow.ui"
121 );
122
123 gtk_widget_class_bind_template_child(widget_class, PidginIMWindow,
124 filter);
125
126 gtk_widget_class_bind_template_child(widget_class, PidginIMWindow,
127 account);
128 gtk_widget_class_bind_template_child(widget_class, PidginIMWindow,
129 username);
130
131 gtk_widget_class_bind_template_callback(widget_class,
132 pidgin_im_window_username_changed_cb);
133 gtk_widget_class_bind_template_callback(widget_class,
134 pidgin_im_window_response_cb);
135 }
136
137 /******************************************************************************
138 * Public API
139 *****************************************************************************/
140 GtkWidget *
141 pidgin_im_window_new(void) {
142 return g_object_new(PIDGIN_TYPE_IM_WINDOW, NULL);
143 }

mercurial