Mercurial > pidgin.yaz
comparison pidgin/plugins/gevolution/new_person_dialog.c @ 20171:e172db483c07
disapproval of revision '87db1277801f9f4bb6cf456b1344a263f51f2864'
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 20 Sep 2007 12:01:33 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
20170:46f4ca8a4a27 | 20171:e172db483c07 |
---|---|
1 /* | |
2 * Evolution integration plugin for Purple | |
3 * | |
4 * Copyright (C) 2003 Christian Hammond. | |
5 * | |
6 * This program is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation; either version 2 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
19 * 02111-1301, USA. | |
20 */ | |
21 #include "internal.h" | |
22 #include "pidgin.h" | |
23 #include "gtkutils.h" | |
24 | |
25 #include "debug.h" | |
26 | |
27 #include "gevolution.h" | |
28 | |
29 static GtkWidget * | |
30 add_pref_box(GtkSizeGroup *sg, GtkWidget *parent, const char *text, | |
31 GtkWidget *widget) | |
32 { | |
33 GtkWidget *hbox; | |
34 GtkWidget *label; | |
35 | |
36 hbox = gtk_hbox_new(FALSE, 6); | |
37 gtk_box_pack_start(GTK_BOX(parent), hbox, FALSE, FALSE, 0); | |
38 gtk_widget_show(hbox); | |
39 | |
40 label = gtk_label_new_with_mnemonic(text); | |
41 gtk_size_group_add_widget(sg, label); | |
42 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
43 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
44 gtk_widget_show(label); | |
45 | |
46 gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0); | |
47 gtk_widget_show(widget); | |
48 | |
49 return hbox; | |
50 } | |
51 | |
52 static gint | |
53 delete_win_cb(GtkWidget *w, GdkEvent *event, GevoNewPersonDialog *dialog) | |
54 { | |
55 gtk_widget_destroy(dialog->win); | |
56 | |
57 g_object_unref(dialog->book); | |
58 g_free(dialog); | |
59 | |
60 return 0; | |
61 } | |
62 | |
63 static void | |
64 cancel_cb(GtkWidget *w, GevoNewPersonDialog *dialog) | |
65 { | |
66 delete_win_cb(NULL, NULL, dialog); | |
67 } | |
68 | |
69 static void | |
70 screenname_changed_cb(GtkEntry *entry, GevoNewPersonDialog *dialog) | |
71 { | |
72 gtk_widget_set_sensitive(dialog->add_button, | |
73 *gtk_entry_get_text(entry) != '\0'); | |
74 } | |
75 | |
76 static void | |
77 person_info_changed_cb(GtkEntry *entry, GevoNewPersonDialog *dialog) | |
78 { | |
79 gtk_widget_set_sensitive(dialog->add_button, | |
80 (*gtk_entry_get_text(GTK_ENTRY(dialog->firstname)) != '\0' || | |
81 *gtk_entry_get_text(GTK_ENTRY(dialog->lastname)) != '\0')); | |
82 } | |
83 | |
84 static void | |
85 add_cb(GtkWidget *w, GevoNewPersonDialog *dialog) | |
86 { | |
87 EContact *contact = NULL; | |
88 const char *screenname; | |
89 const char *firstname; | |
90 const char *lastname; | |
91 const char *email; | |
92 const char *im_service; | |
93 gboolean new_contact = FALSE; | |
94 EContactField field = 0; | |
95 EContactName *name = NULL; | |
96 char *full_name = NULL; | |
97 | |
98 if (dialog->person_only) | |
99 screenname = dialog->buddy->name; | |
100 else | |
101 screenname = gtk_entry_get_text(GTK_ENTRY(dialog->screenname)); | |
102 | |
103 firstname = gtk_entry_get_text(GTK_ENTRY(dialog->firstname)); | |
104 lastname = gtk_entry_get_text(GTK_ENTRY(dialog->lastname)); | |
105 email = gtk_entry_get_text(GTK_ENTRY(dialog->email)); | |
106 | |
107 if (*firstname || *lastname) | |
108 { | |
109 if (dialog->contact == NULL) | |
110 { | |
111 char *file_as; | |
112 | |
113 dialog->contact = e_contact_new(); | |
114 | |
115 if (*lastname && *firstname) | |
116 file_as = g_strdup_printf("%s, %s", lastname, firstname); | |
117 else if (*lastname) | |
118 file_as = g_strdup(lastname); | |
119 else | |
120 file_as = g_strdup(firstname); | |
121 | |
122 e_contact_set(dialog->contact, E_CONTACT_FILE_AS, file_as); | |
123 | |
124 g_free(file_as); | |
125 | |
126 new_contact = TRUE; | |
127 } | |
128 | |
129 contact = dialog->contact; | |
130 | |
131 name = e_contact_name_new(); | |
132 | |
133 name->given = g_strdup(firstname); | |
134 name->family = g_strdup(lastname); | |
135 | |
136 full_name = e_contact_name_to_string(name); | |
137 e_contact_set(contact, E_CONTACT_FULL_NAME, full_name); | |
138 | |
139 im_service = purple_account_get_protocol_id(dialog->account); | |
140 | |
141 if (*email) | |
142 e_contact_set(contact, E_CONTACT_EMAIL_1, (gpointer)email); | |
143 | |
144 if (!strcmp(im_service, "prpl-oscar")) | |
145 { | |
146 if (isdigit(*screenname)) | |
147 field = E_CONTACT_IM_ICQ; | |
148 else | |
149 field = E_CONTACT_IM_AIM; | |
150 } | |
151 else if (!strcmp(im_service, "prpl-yahoo")) | |
152 field = E_CONTACT_IM_YAHOO; | |
153 else if (!strcmp(im_service, "prpl-jabber")) | |
154 field = E_CONTACT_IM_JABBER; | |
155 else if (!strcmp(im_service, "prpl-msn")) | |
156 field = E_CONTACT_IM_MSN; | |
157 else if (!strcmp(im_service, "prpl-novell")) | |
158 field = E_CONTACT_IM_GROUPWISE; | |
159 | |
160 if (field > 0) | |
161 { | |
162 GList *list = g_list_append(NULL, g_strdup(screenname)); | |
163 | |
164 e_contact_set(contact, field, list); | |
165 | |
166 g_free(list->data); | |
167 g_list_free(list); | |
168 } | |
169 | |
170 if (new_contact) | |
171 { | |
172 if (!e_book_add_contact(dialog->book, contact, NULL)) | |
173 { | |
174 purple_debug_error("evolution", "Error adding contact to book\n"); | |
175 | |
176 g_object_unref(contact); | |
177 delete_win_cb(NULL, NULL, dialog); | |
178 return; | |
179 } | |
180 } | |
181 else | |
182 { | |
183 if (!e_book_commit_contact(dialog->book, contact, NULL)) | |
184 { | |
185 purple_debug_error("evolution", "Error adding contact to book\n"); | |
186 | |
187 g_object_unref(contact); | |
188 delete_win_cb(NULL, NULL, dialog); | |
189 return; | |
190 } | |
191 } | |
192 | |
193 g_object_unref(contact); | |
194 } | |
195 | |
196 if (!dialog->person_only) | |
197 { | |
198 const char *group_name; | |
199 | |
200 group_name = pidgin_text_combo_box_entry_get_text(dialog->group_combo); | |
201 | |
202 gevo_add_buddy(dialog->account, group_name, screenname, full_name); | |
203 } | |
204 | |
205 if (name != NULL) | |
206 e_contact_name_free(name); | |
207 | |
208 if (full_name != NULL) | |
209 g_free(full_name); | |
210 | |
211 delete_win_cb(NULL, NULL, dialog); | |
212 } | |
213 | |
214 static void | |
215 select_account_cb(GObject *w, PurpleAccount *account, | |
216 GevoNewPersonDialog *dialog) | |
217 { | |
218 dialog->account = account; | |
219 } | |
220 | |
221 void | |
222 gevo_new_person_dialog_show(EBook *book, EContact *contact, | |
223 PurpleAccount *account, const char *username, | |
224 const char *group, PurpleBuddy *buddy, | |
225 gboolean person_only) | |
226 { | |
227 GevoNewPersonDialog *dialog; | |
228 GtkWidget *vbox, *vbox2; | |
229 GtkWidget *hbox; | |
230 GtkWidget *bbox; | |
231 GtkWidget *label; | |
232 GtkWidget *button; | |
233 GtkWidget *sep; | |
234 GtkSizeGroup *sg, *sg2; | |
235 const char *str; | |
236 | |
237 g_return_if_fail(book); | |
238 g_return_if_fail(!person_only || (person_only && buddy)); | |
239 | |
240 dialog = g_new0(GevoNewPersonDialog, 1); | |
241 | |
242 dialog->account = account; | |
243 dialog->person_only = person_only; | |
244 dialog->buddy = buddy; | |
245 dialog->book = book; | |
246 g_object_ref(book); | |
247 | |
248 dialog->win = pidgin_create_window(_("New Person"), PIDGIN_HIG_BORDER, "new_person", FALSE); | |
249 | |
250 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
251 G_CALLBACK(delete_win_cb), dialog); | |
252 | |
253 /* Setup the vbox */ | |
254 vbox = gtk_vbox_new(FALSE, 12); | |
255 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
256 gtk_widget_show(vbox); | |
257 | |
258 /* Label */ | |
259 if (person_only) | |
260 { | |
261 label = gtk_label_new( | |
262 _("Please enter the person's information below.")); | |
263 } | |
264 else | |
265 { | |
266 label = gtk_label_new(_("Please enter the buddy's screen name and " | |
267 "account type below.")); | |
268 } | |
269 | |
270 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
271 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
272 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
273 gtk_widget_show(label); | |
274 | |
275 /* Setup the size groups */ | |
276 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
277 sg2 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
278 | |
279 if (!person_only) | |
280 { | |
281 /* Add the account type stuff. */ | |
282 dialog->accounts_menu = | |
283 pidgin_account_option_menu_new(account, FALSE, | |
284 G_CALLBACK(select_account_cb), | |
285 NULL, dialog); | |
286 add_pref_box(sg, vbox, _("Account type:"), dialog->accounts_menu); | |
287 | |
288 /* Screen Name */ | |
289 dialog->screenname = gtk_entry_new(); | |
290 add_pref_box(sg, vbox, _("Screen name:"), dialog->screenname); | |
291 | |
292 if (username != NULL) | |
293 gtk_entry_set_text(GTK_ENTRY(dialog->screenname), username); | |
294 | |
295 g_signal_connect(G_OBJECT(dialog->screenname), "changed", | |
296 G_CALLBACK(screenname_changed_cb), dialog); | |
297 | |
298 /* Group */ | |
299 dialog->group_combo = pidgin_text_combo_box_entry_new(NULL, | |
300 gevo_get_groups()); | |
301 add_pref_box(sg, vbox, _("Group:"), dialog->group_combo); | |
302 | |
303 /* Separator */ | |
304 sep = gtk_hseparator_new(); | |
305 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
306 gtk_widget_show(sep); | |
307 | |
308 /* Optional Information section */ | |
309 label = gtk_label_new(_("Optional information:")); | |
310 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
311 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
312 gtk_widget_show(label); | |
313 } | |
314 | |
315 /* Create the parent hbox for this whole thing. */ | |
316 hbox = gtk_hbox_new(FALSE, 12); | |
317 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); | |
318 gtk_widget_show(hbox); | |
319 | |
320 #if 0 | |
321 /* Now the left side of the hbox */ | |
322 vbox2 = gtk_vbox_new(FALSE, 12); | |
323 gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, FALSE, 0); | |
324 gtk_widget_show(vbox2); | |
325 | |
326 /* Buddy icon button */ | |
327 button = gtk_button_new_from_stock(GTK_STOCK_OPEN); | |
328 gtk_box_pack_start(GTK_BOX(vbox2), button, FALSE, FALSE, 0); | |
329 gtk_widget_show(button); | |
330 | |
331 /* Label */ | |
332 label = gtk_label_new(_("Buddy Icon")); | |
333 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | |
334 gtk_widget_show(label); | |
335 #endif | |
336 | |
337 /* Now the right side. */ | |
338 vbox2 = gtk_vbox_new(FALSE, 12); | |
339 gtk_box_pack_start(GTK_BOX(hbox), vbox2, TRUE, TRUE, 0); | |
340 gtk_widget_show(vbox2); | |
341 | |
342 /* First Name field */ | |
343 dialog->firstname = gtk_entry_new(); | |
344 add_pref_box(sg2, vbox2, _("First name:"), dialog->firstname); | |
345 | |
346 if (contact != NULL) | |
347 { | |
348 str = e_contact_get_const(contact, E_CONTACT_GIVEN_NAME); | |
349 | |
350 if (str != NULL) | |
351 gtk_entry_set_text(GTK_ENTRY(dialog->firstname), str); | |
352 } | |
353 | |
354 /* Last Name field */ | |
355 dialog->lastname = gtk_entry_new(); | |
356 add_pref_box(sg2, vbox2, _("Last name:"), dialog->lastname); | |
357 | |
358 if (contact != NULL) | |
359 { | |
360 str = e_contact_get_const(contact, E_CONTACT_FAMILY_NAME); | |
361 | |
362 if (str != NULL) | |
363 gtk_entry_set_text(GTK_ENTRY(dialog->lastname), str); | |
364 } | |
365 | |
366 if (person_only) | |
367 { | |
368 g_signal_connect(G_OBJECT(dialog->firstname), "changed", | |
369 G_CALLBACK(person_info_changed_cb), dialog); | |
370 g_signal_connect(G_OBJECT(dialog->lastname), "changed", | |
371 G_CALLBACK(person_info_changed_cb), dialog); | |
372 } | |
373 | |
374 /* E-Mail address field */ | |
375 dialog->email = gtk_entry_new(); | |
376 add_pref_box(sg2, vbox2, _("E-mail:"), dialog->email); | |
377 | |
378 if (contact != NULL) | |
379 { | |
380 str = e_contact_get_const(contact, E_CONTACT_EMAIL_1); | |
381 | |
382 if (str != NULL) | |
383 gtk_entry_set_text(GTK_ENTRY(dialog->email), str); | |
384 } | |
385 | |
386 /* Separator */ | |
387 sep = gtk_hseparator_new(); | |
388 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
389 gtk_widget_show(sep); | |
390 | |
391 /* Button box */ | |
392 bbox = gtk_hbutton_box_new(); | |
393 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
394 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
395 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
396 gtk_widget_show(bbox); | |
397 | |
398 /* Cancel button */ | |
399 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
400 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
401 gtk_widget_show(button); | |
402 | |
403 g_signal_connect(G_OBJECT(button), "clicked", | |
404 G_CALLBACK(cancel_cb), dialog); | |
405 | |
406 /* Add button */ | |
407 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
408 dialog->add_button = button; | |
409 if (username == NULL || *username == '\0') | |
410 gtk_widget_set_sensitive(button, FALSE); | |
411 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
412 gtk_widget_show(button); | |
413 | |
414 g_signal_connect(G_OBJECT(button), "clicked", | |
415 G_CALLBACK(add_cb), dialog); | |
416 | |
417 /* Show it. */ | |
418 gtk_widget_show(dialog->win); | |
419 } |