| 16 * along with this program; if not, write to the Free Software |
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 |
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 18 */ |
18 */ |
| 19 |
19 |
| 20 #include "pidgininvitedialog.h" |
20 #include "pidgininvitedialog.h" |
| |
21 #include "pidgincontactcompletion.h" |
| 21 |
22 |
| 22 struct _PidginInviteDialog { |
23 struct _PidginInviteDialog { |
| 23 GtkDialog parent; |
24 GtkDialog parent; |
| 24 }; |
25 }; |
| 25 |
26 |
| 26 typedef struct { |
27 typedef struct { |
| 27 GtkWidget *contact; |
28 GtkWidget *contact; |
| 28 GtkWidget *message; |
29 GtkWidget *message; |
| |
30 |
| |
31 PurpleChatConversation *conversation; |
| 29 } PidginInviteDialogPrivate; |
32 } PidginInviteDialogPrivate; |
| 30 |
33 |
| 31 enum { |
34 enum { |
| 32 PROP_ZERO, |
35 PROP_ZERO, |
| 33 PROP_CONTACT, |
36 PROP_CONTACT, |
| 34 PROP_MESSAGE, |
37 PROP_MESSAGE, |
| |
38 PROP_CONVERSATION, |
| 35 N_PROPERTIES, |
39 N_PROPERTIES, |
| 36 }; |
40 }; |
| 37 |
41 |
| 38 static GParamSpec *properties[N_PROPERTIES] = {}; |
42 static GParamSpec *properties[N_PROPERTIES] = {}; |
| 39 |
43 |
| 40 G_DEFINE_TYPE_WITH_PRIVATE(PidginInviteDialog, pidgin_invite_dialog, GTK_TYPE_DIALOG); |
44 G_DEFINE_TYPE_WITH_PRIVATE(PidginInviteDialog, pidgin_invite_dialog, GTK_TYPE_DIALOG); |
| |
45 |
| |
46 /****************************************************************************** |
| |
47 * Helpers |
| |
48 *****************************************************************************/ |
| |
49 static void |
| |
50 pidgin_invite_dialog_set_conversation(PidginInviteDialog *dialog, |
| |
51 PurpleChatConversation *conversation) |
| |
52 { |
| |
53 PidginInviteDialogPrivate *priv = NULL; |
| |
54 |
| |
55 g_return_if_fail(PIDGIN_IS_INVITE_DIALOG(dialog)); |
| |
56 |
| |
57 priv = pidgin_invite_dialog_get_instance_private(dialog); |
| |
58 |
| |
59 priv->conversation = g_object_ref(conversation); |
| |
60 |
| |
61 g_object_notify_by_pspec(G_OBJECT(dialog), properties[PROP_CONVERSATION]); |
| |
62 } |
| 41 |
63 |
| 42 /****************************************************************************** |
64 /****************************************************************************** |
| 43 * GObject Stuff |
65 * GObject Stuff |
| 44 *****************************************************************************/ |
66 *****************************************************************************/ |
| 45 static void |
67 static void |
| 57 break; |
79 break; |
| 58 case PROP_MESSAGE: |
80 case PROP_MESSAGE: |
| 59 g_value_set_string(value, |
81 g_value_set_string(value, |
| 60 pidgin_invite_dialog_get_message(dialog)); |
82 pidgin_invite_dialog_get_message(dialog)); |
| 61 break; |
83 break; |
| |
84 case PROP_CONVERSATION: |
| |
85 g_value_set_object(value, |
| |
86 pidgin_invite_dialog_get_conversation(dialog)); |
| |
87 break; |
| 62 default: |
88 default: |
| 63 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
89 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
| 64 break; |
90 break; |
| 65 } |
91 } |
| 66 } |
92 } |
| 80 break; |
106 break; |
| 81 case PROP_MESSAGE: |
107 case PROP_MESSAGE: |
| 82 pidgin_invite_dialog_set_message(dialog, |
108 pidgin_invite_dialog_set_message(dialog, |
| 83 g_value_get_string(value)); |
109 g_value_get_string(value)); |
| 84 break; |
110 break; |
| |
111 case PROP_CONVERSATION: |
| |
112 pidgin_invite_dialog_set_conversation(dialog, |
| |
113 g_value_get_object(value)); |
| |
114 break; |
| 85 default: |
115 default: |
| 86 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
116 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
| 87 break; |
117 break; |
| 88 } |
118 } |
| 89 } |
119 } |
| 101 } |
131 } |
| 102 |
132 |
| 103 static void |
133 static void |
| 104 pidgin_invite_dialog_init(PidginInviteDialog *dialog) { |
134 pidgin_invite_dialog_init(PidginInviteDialog *dialog) { |
| 105 gtk_widget_init_template(GTK_WIDGET(dialog)); |
135 gtk_widget_init_template(GTK_WIDGET(dialog)); |
| |
136 } |
| |
137 |
| |
138 static void |
| |
139 pidgin_invite_dialog_constructed(GObject *obj) { |
| |
140 PidginInviteDialog *dialog = PIDGIN_INVITE_DIALOG(obj); |
| |
141 PidginInviteDialogPrivate *priv = NULL; |
| |
142 GtkEntryCompletion *completion = NULL; |
| |
143 |
| |
144 priv = pidgin_invite_dialog_get_instance_private(dialog); |
| |
145 |
| |
146 completion = pidgin_contact_completion_new(); |
| |
147 |
| |
148 /* constructed is called after all properties are set, so we set the |
| |
149 * account for the completion from the conversation we were created with. |
| |
150 */ |
| |
151 if(priv->conversation) { |
| |
152 PurpleAccount *account = purple_conversation_get_account(PURPLE_CONVERSATION(priv->conversation)); |
| |
153 |
| |
154 if(account != NULL) { |
| |
155 pidgin_contact_completion_set_account( |
| |
156 PIDGIN_CONTACT_COMPLETION(completion), |
| |
157 account |
| |
158 ); |
| |
159 } |
| |
160 } |
| |
161 |
| |
162 gtk_entry_set_completion(GTK_ENTRY(priv->contact), completion); |
| |
163 g_object_unref(completion); |
| 106 } |
164 } |
| 107 |
165 |
| 108 static void |
166 static void |
| 109 pidgin_invite_dialog_class_init(PidginInviteDialogClass *klass) { |
167 pidgin_invite_dialog_class_init(PidginInviteDialogClass *klass) { |
| 110 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
168 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
| 111 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); |
169 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); |
| 112 |
170 |
| 113 obj_class->get_property = pidgin_invite_dialog_get_property; |
171 obj_class->get_property = pidgin_invite_dialog_get_property; |
| 114 obj_class->set_property = pidgin_invite_dialog_set_property; |
172 obj_class->set_property = pidgin_invite_dialog_set_property; |
| 115 obj_class->finalize = pidgin_invite_dialog_finalize; |
173 obj_class->finalize = pidgin_invite_dialog_finalize; |
| |
174 obj_class->constructed = pidgin_invite_dialog_constructed; |
| 116 |
175 |
| 117 gtk_widget_class_set_template_from_resource( |
176 gtk_widget_class_set_template_from_resource( |
| 118 widget_class, |
177 widget_class, |
| 119 "/im/pidgin/Pidgin/Conversations/invite_dialog.ui" |
178 "/im/pidgin/Pidgin/Conversations/invite_dialog.ui" |
| 120 ); |
179 ); |
| 142 "message", |
201 "message", |
| 143 "The invite message to send", |
202 "The invite message to send", |
| 144 NULL, |
203 NULL, |
| 145 G_PARAM_READWRITE | G_PARAM_CONSTRUCT); |
204 G_PARAM_READWRITE | G_PARAM_CONSTRUCT); |
| 146 |
205 |
| |
206 properties[PROP_CONVERSATION] = g_param_spec_object( |
| |
207 "conversation", |
| |
208 "conversation", |
| |
209 "The conversation that someone is being invited to", |
| |
210 PURPLE_TYPE_CHAT_CONVERSATION, |
| |
211 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); |
| |
212 |
| 147 g_object_class_install_properties(obj_class, N_PROPERTIES, properties); |
213 g_object_class_install_properties(obj_class, N_PROPERTIES, properties); |
| 148 } |
214 } |
| 149 |
215 |
| 150 /****************************************************************************** |
216 /****************************************************************************** |
| 151 * Public API |
217 * Public API |
| 152 *****************************************************************************/ |
218 *****************************************************************************/ |
| 153 GtkWidget * |
219 GtkWidget * |
| 154 pidgin_invite_dialog_new(void) { |
220 pidgin_invite_dialog_new(PurpleChatConversation *conversation) { |
| 155 return GTK_WIDGET(g_object_new(PIDGIN_TYPE_INVITE_DIALOG, NULL)); |
221 return GTK_WIDGET(g_object_new( |
| |
222 PIDGIN_TYPE_INVITE_DIALOG, |
| |
223 "conversation", conversation, |
| |
224 NULL)); |
| 156 } |
225 } |
| 157 |
226 |
| 158 const gchar * |
227 const gchar * |
| 159 pidgin_invite_dialog_get_contact(PidginInviteDialog *dialog) { |
228 pidgin_invite_dialog_get_contact(PidginInviteDialog *dialog) { |
| 160 PidginInviteDialogPrivate *priv = NULL; |
229 PidginInviteDialogPrivate *priv = NULL; |
| 209 |
278 |
| 210 g_object_notify_by_pspec(G_OBJECT(dialog), properties[PROP_MESSAGE]); |
279 g_object_notify_by_pspec(G_OBJECT(dialog), properties[PROP_MESSAGE]); |
| 211 } |
280 } |
| 212 } |
281 } |
| 213 |
282 |
| |
283 PurpleChatConversation * |
| |
284 pidgin_invite_dialog_get_conversation(PidginInviteDialog *dialog) { |
| |
285 PidginInviteDialogPrivate *priv = NULL; |
| |
286 |
| |
287 g_return_val_if_fail(PIDGIN_IS_INVITE_DIALOG(dialog), NULL); |
| |
288 |
| |
289 priv = pidgin_invite_dialog_get_instance_private(dialog); |
| |
290 |
| |
291 return priv->conversation; |
| |
292 } |