Simplify handling of GG xfer auth queue.
[pidgin-git.git] / pidgin / pidgininvitedialog.c
blobec319a56b5e60d467b1cf6a7eb5c2a734a003904
1 /* Purple is the legal property of its developers, whose names are too numerous
2 * to list here. Please refer to the COPYRIGHT file distributed with this
3 * source distribution.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
20 #include "pidgininvitedialog.h"
21 #include "pidgincontactcompletion.h"
23 struct _PidginInviteDialog {
24 GtkDialog parent;
27 typedef struct {
28 GtkWidget *contact;
29 GtkWidget *message;
31 PurpleChatConversation *conversation;
32 } PidginInviteDialogPrivate;
34 enum {
35 PROP_ZERO,
36 PROP_CONTACT,
37 PROP_MESSAGE,
38 PROP_CONVERSATION,
39 N_PROPERTIES,
42 static GParamSpec *properties[N_PROPERTIES] = {0, };
44 G_DEFINE_TYPE_WITH_PRIVATE(PidginInviteDialog, pidgin_invite_dialog, GTK_TYPE_DIALOG);
46 /******************************************************************************
47 * Helpers
48 *****************************************************************************/
49 static void
50 pidgin_invite_dialog_set_conversation(PidginInviteDialog *dialog,
51 PurpleChatConversation *conversation)
53 PidginInviteDialogPrivate *priv = NULL;
55 g_return_if_fail(PIDGIN_IS_INVITE_DIALOG(dialog));
57 priv = pidgin_invite_dialog_get_instance_private(dialog);
59 priv->conversation = g_object_ref(conversation);
61 g_object_notify_by_pspec(G_OBJECT(dialog), properties[PROP_CONVERSATION]);
64 /******************************************************************************
65 * GObject Stuff
66 *****************************************************************************/
67 static void
68 pidgin_invite_dialog_get_property(GObject *obj,
69 guint param_id,
70 GValue *value,
71 GParamSpec *pspec)
73 PidginInviteDialog *dialog = PIDGIN_INVITE_DIALOG(obj);
75 switch(param_id) {
76 case PROP_CONTACT:
77 g_value_set_string(value,
78 pidgin_invite_dialog_get_contact(dialog));
79 break;
80 case PROP_MESSAGE:
81 g_value_set_string(value,
82 pidgin_invite_dialog_get_message(dialog));
83 break;
84 case PROP_CONVERSATION:
85 g_value_set_object(value,
86 pidgin_invite_dialog_get_conversation(dialog));
87 break;
88 default:
89 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
90 break;
94 static void
95 pidgin_invite_dialog_set_property(GObject *obj,
96 guint param_id,
97 const GValue *value,
98 GParamSpec *pspec)
100 PidginInviteDialog *dialog = PIDGIN_INVITE_DIALOG(obj);
102 switch(param_id) {
103 case PROP_CONTACT:
104 pidgin_invite_dialog_set_contact(dialog,
105 g_value_get_string(value));
106 break;
107 case PROP_MESSAGE:
108 pidgin_invite_dialog_set_message(dialog,
109 g_value_get_string(value));
110 break;
111 case PROP_CONVERSATION:
112 pidgin_invite_dialog_set_conversation(dialog,
113 g_value_get_object(value));
114 break;
115 default:
116 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
117 break;
121 static void
122 pidgin_invite_dialog_finalize(GObject *obj) {
123 PidginInviteDialogPrivate *priv = NULL;
125 priv = pidgin_invite_dialog_get_instance_private(PIDGIN_INVITE_DIALOG(obj));
127 g_clear_pointer(&priv->contact, g_free);
128 g_clear_pointer(&priv->message, g_free);
129 g_clear_object(&priv->conversation);
131 G_OBJECT_CLASS(pidgin_invite_dialog_parent_class)->finalize(obj);
134 static void
135 pidgin_invite_dialog_init(PidginInviteDialog *dialog) {
136 gtk_widget_init_template(GTK_WIDGET(dialog));
139 static void
140 pidgin_invite_dialog_constructed(GObject *obj) {
141 PidginInviteDialog *dialog = PIDGIN_INVITE_DIALOG(obj);
142 PidginInviteDialogPrivate *priv = NULL;
143 GtkEntryCompletion *completion = NULL;
145 priv = pidgin_invite_dialog_get_instance_private(dialog);
147 completion = pidgin_contact_completion_new();
149 /* constructed is called after all properties are set, so we set the
150 * account for the completion from the conversation we were created with.
152 if(priv->conversation) {
153 PurpleAccount *account = purple_conversation_get_account(PURPLE_CONVERSATION(priv->conversation));
155 if(account != NULL) {
156 pidgin_contact_completion_set_account(
157 PIDGIN_CONTACT_COMPLETION(completion),
158 account
163 gtk_entry_set_completion(GTK_ENTRY(priv->contact), completion);
164 g_object_unref(completion);
167 static void
168 pidgin_invite_dialog_class_init(PidginInviteDialogClass *klass) {
169 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
170 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
172 obj_class->get_property = pidgin_invite_dialog_get_property;
173 obj_class->set_property = pidgin_invite_dialog_set_property;
174 obj_class->finalize = pidgin_invite_dialog_finalize;
175 obj_class->constructed = pidgin_invite_dialog_constructed;
177 gtk_widget_class_set_template_from_resource(
178 widget_class,
179 "/im/pidgin/Pidgin/Conversations/invite_dialog.ui"
182 gtk_widget_class_bind_template_child_private(
183 widget_class,
184 PidginInviteDialog,
185 contact
187 gtk_widget_class_bind_template_child_private(
188 widget_class,
189 PidginInviteDialog,
190 message
193 properties[PROP_CONTACT] = g_param_spec_string(
194 "contact",
195 "contact",
196 "The person that is being invited",
197 NULL,
198 G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
200 properties[PROP_MESSAGE] = g_param_spec_string(
201 "message",
202 "message",
203 "The invite message to send",
204 NULL,
205 G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
207 properties[PROP_CONVERSATION] = g_param_spec_object(
208 "conversation",
209 "conversation",
210 "The conversation that someone is being invited to",
211 PURPLE_TYPE_CHAT_CONVERSATION,
212 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
214 g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
217 /******************************************************************************
218 * Public API
219 *****************************************************************************/
220 GtkWidget *
221 pidgin_invite_dialog_new(PurpleChatConversation *conversation) {
222 return GTK_WIDGET(g_object_new(
223 PIDGIN_TYPE_INVITE_DIALOG,
224 "conversation", conversation,
225 NULL));
228 const gchar *
229 pidgin_invite_dialog_get_contact(PidginInviteDialog *dialog) {
230 PidginInviteDialogPrivate *priv = NULL;
232 g_return_val_if_fail(PIDGIN_IS_INVITE_DIALOG(dialog), NULL);
234 priv = pidgin_invite_dialog_get_instance_private(dialog);
236 return gtk_entry_get_text(GTK_ENTRY(priv->contact));
239 void
240 pidgin_invite_dialog_set_contact(PidginInviteDialog *dialog,
241 const gchar *contact)
243 PidginInviteDialogPrivate *priv = NULL;
245 g_return_if_fail(PIDGIN_IS_INVITE_DIALOG(dialog));
247 priv = pidgin_invite_dialog_get_instance_private(dialog);
249 if(contact != NULL) {
250 gtk_entry_set_text(GTK_ENTRY(priv->contact), contact);
252 g_object_notify_by_pspec(G_OBJECT(dialog), properties[PROP_CONTACT]);
256 const gchar *
257 pidgin_invite_dialog_get_message(PidginInviteDialog *dialog) {
258 PidginInviteDialogPrivate *priv = NULL;
260 g_return_val_if_fail(PIDGIN_IS_INVITE_DIALOG(dialog), NULL);
262 priv = pidgin_invite_dialog_get_instance_private(dialog);
264 return gtk_entry_get_text(GTK_ENTRY(priv->message));
267 void
268 pidgin_invite_dialog_set_message(PidginInviteDialog *dialog,
269 const gchar *message)
271 PidginInviteDialogPrivate *priv = NULL;
273 g_return_if_fail(PIDGIN_IS_INVITE_DIALOG(dialog));
275 priv = pidgin_invite_dialog_get_instance_private(dialog);
277 if(message != NULL) {
278 gtk_entry_set_text(GTK_ENTRY(priv->message), message);
280 g_object_notify_by_pspec(G_OBJECT(dialog), properties[PROP_MESSAGE]);
284 PurpleChatConversation *
285 pidgin_invite_dialog_get_conversation(PidginInviteDialog *dialog) {
286 PidginInviteDialogPrivate *priv = NULL;
288 g_return_val_if_fail(PIDGIN_IS_INVITE_DIALOG(dialog), NULL);
290 priv = pidgin_invite_dialog_get_instance_private(dialog);
292 return priv->conversation;