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
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
{
31 PurpleChatConversation
*conversation
;
32 } PidginInviteDialogPrivate
;
42 static GParamSpec
*properties
[N_PROPERTIES
] = {0, };
44 G_DEFINE_TYPE_WITH_PRIVATE(PidginInviteDialog
, pidgin_invite_dialog
, GTK_TYPE_DIALOG
);
46 /******************************************************************************
48 *****************************************************************************/
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 /******************************************************************************
66 *****************************************************************************/
68 pidgin_invite_dialog_get_property(GObject
*obj
,
73 PidginInviteDialog
*dialog
= PIDGIN_INVITE_DIALOG(obj
);
77 g_value_set_string(value
,
78 pidgin_invite_dialog_get_contact(dialog
));
81 g_value_set_string(value
,
82 pidgin_invite_dialog_get_message(dialog
));
84 case PROP_CONVERSATION
:
85 g_value_set_object(value
,
86 pidgin_invite_dialog_get_conversation(dialog
));
89 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
95 pidgin_invite_dialog_set_property(GObject
*obj
,
100 PidginInviteDialog
*dialog
= PIDGIN_INVITE_DIALOG(obj
);
104 pidgin_invite_dialog_set_contact(dialog
,
105 g_value_get_string(value
));
108 pidgin_invite_dialog_set_message(dialog
,
109 g_value_get_string(value
));
111 case PROP_CONVERSATION
:
112 pidgin_invite_dialog_set_conversation(dialog
,
113 g_value_get_object(value
));
116 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
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
);
135 pidgin_invite_dialog_init(PidginInviteDialog
*dialog
) {
136 gtk_widget_init_template(GTK_WIDGET(dialog
));
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
),
163 gtk_entry_set_completion(GTK_ENTRY(priv
->contact
), completion
);
164 g_object_unref(completion
);
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(
179 "/im/pidgin/Pidgin/Conversations/invite_dialog.ui"
182 gtk_widget_class_bind_template_child_private(
187 gtk_widget_class_bind_template_child_private(
193 properties
[PROP_CONTACT
] = g_param_spec_string(
196 "The person that is being invited",
198 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
200 properties
[PROP_MESSAGE
] = g_param_spec_string(
203 "The invite message to send",
205 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
);
207 properties
[PROP_CONVERSATION
] = g_param_spec_object(
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 /******************************************************************************
219 *****************************************************************************/
221 pidgin_invite_dialog_new(PurpleChatConversation
*conversation
) {
222 return GTK_WIDGET(g_object_new(
223 PIDGIN_TYPE_INVITE_DIALOG
,
224 "conversation", conversation
,
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
));
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
]);
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
));
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
;