Mercurial > pidgin.yaz
annotate plugins/gevolution/new_person_dialog.c @ 9826:6f2a90c36ee2
[gaim-migrate @ 10697]
Kevin pointed out that the error message for AIM when you couldn't send
a message to someone could be better. So I made it better.
Also renamed AIM_IMCHARSET_bleh to AIM_CHARSET_bleh, since they're used
in direct connect stuff, too.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 22 Aug 2004 17:59:17 +0000 |
parents | c00def44d76a |
children | ff4be2d1401d |
rev | line source |
---|---|
8089 | 1 /* |
2 * Evolution integration plugin for Gaim | |
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., 59 Temple Place - Suite 330, Boston, MA | |
19 * 02111-1307, USA. | |
20 */ | |
9825
c00def44d76a
[gaim-migrate @ 10696]
Christian Hammond <chipx86@chipx86.com>
parents:
9824
diff
changeset
|
21 #include "internal.h" |
9824 | 22 #include "gtkgaim.h" |
8089 | 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_free(dialog); | |
58 | |
59 return 0; | |
60 } | |
61 | |
62 static void | |
63 cancel_cb(GtkWidget *w, GevoNewPersonDialog *dialog) | |
64 { | |
65 delete_win_cb(NULL, NULL, dialog); | |
66 } | |
67 | |
68 static void | |
69 screenname_changed_cb(GtkEntry *entry, GevoNewPersonDialog *dialog) | |
70 { | |
71 gtk_widget_set_sensitive(dialog->add_button, | |
72 *gtk_entry_get_text(entry) != '\0'); | |
73 } | |
74 | |
75 static void | |
76 person_info_changed_cb(GtkEntry *entry, GevoNewPersonDialog *dialog) | |
77 { | |
78 gtk_widget_set_sensitive(dialog->add_button, | |
79 (*gtk_entry_get_text(GTK_ENTRY(dialog->firstname)) != '\0' || | |
80 *gtk_entry_get_text(GTK_ENTRY(dialog->lastname)) != '\0')); | |
81 } | |
82 | |
83 static void | |
84 add_cb(GtkWidget *w, GevoNewPersonDialog *dialog) | |
85 { | |
86 EContact *contact = NULL; | |
87 EBook *book; | |
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 (!gevo_load_addressbook(&book, NULL)) | |
110 { | |
111 gaim_debug_error("evolution", | |
112 "Error retrieving default addressbook\n"); | |
113 | |
114 return; | |
115 } | |
116 | |
117 if (dialog->contact == NULL) | |
118 { | |
119 char *file_as; | |
120 | |
121 dialog->contact = e_contact_new(); | |
122 | |
123 if (lastname != NULL && firstname != NULL) | |
124 file_as = g_strdup_printf("%s, %s", lastname, firstname); | |
125 else if (lastname != NULL) | |
126 file_as = g_strdup(lastname); | |
127 else | |
128 file_as = g_strdup(firstname); | |
129 | |
8474
8b62cc40069b
[gaim-migrate @ 9207]
Christian Hammond <chipx86@chipx86.com>
parents:
8089
diff
changeset
|
130 e_contact_set(dialog->contact, E_CONTACT_FILE_AS, file_as); |
8089 | 131 |
132 g_free(file_as); | |
133 | |
134 new_contact = TRUE; | |
135 } | |
136 | |
137 contact = dialog->contact; | |
138 | |
139 name = e_contact_name_new(); | |
140 | |
141 name->given = g_strdup(firstname); | |
142 name->family = g_strdup(lastname); | |
143 | |
144 full_name = e_contact_name_to_string(name); | |
145 e_contact_set(contact, E_CONTACT_FULL_NAME, full_name); | |
146 | |
147 im_service = gaim_account_get_protocol_id(dialog->account); | |
148 | |
149 if (*email) | |
150 e_contact_set(contact, E_CONTACT_EMAIL_1, (gpointer)email); | |
151 | |
152 if (!strcmp(im_service, "prpl-oscar")) | |
153 { | |
154 if (isdigit(*screenname)) | |
155 field = E_CONTACT_IM_ICQ; | |
156 else | |
157 field = E_CONTACT_IM_AIM; | |
158 } | |
159 else if (!strcmp(im_service, "prpl-yahoo")) | |
160 field = E_CONTACT_IM_YAHOO; | |
161 else if (!strcmp(im_service, "prpl-jabber")) | |
162 field = E_CONTACT_IM_JABBER; | |
163 else if (!strcmp(im_service, "prpl-msn")) | |
164 field = E_CONTACT_IM_MSN; | |
165 | |
166 if (field > 0) | |
167 { | |
168 GList *list = g_list_append(NULL, g_strdup(screenname)); | |
169 | |
170 e_contact_set(contact, field, list); | |
171 | |
172 g_free(list->data); | |
173 g_list_free(list); | |
174 } | |
175 | |
176 if (new_contact) | |
177 { | |
178 if (!e_book_add_contact(book, contact, NULL)) | |
179 { | |
180 gaim_debug_error("evolution", "Error adding contact to book\n"); | |
181 | |
182 g_object_unref(contact); | |
183 delete_win_cb(NULL, NULL, dialog); | |
184 return; | |
185 } | |
186 } | |
187 else | |
188 { | |
189 if (!e_book_commit_contact(book, contact, NULL)) | |
190 { | |
191 gaim_debug_error("evolution", "Error adding contact to book\n"); | |
192 | |
193 g_object_unref(contact); | |
194 delete_win_cb(NULL, NULL, dialog); | |
195 return; | |
196 } | |
197 } | |
198 | |
199 g_object_unref(contact); | |
200 } | |
201 | |
202 if (!dialog->person_only) | |
203 { | |
204 GtkWidget *entry = GTK_COMBO(dialog->group_combo)->entry; | |
205 const char *group_name; | |
206 | |
207 group_name = gtk_entry_get_text(GTK_ENTRY(entry)); | |
208 | |
209 gevo_add_buddy(dialog->account, group_name, screenname, full_name); | |
210 } | |
211 | |
212 if (name != NULL) | |
213 e_contact_name_free(name); | |
214 | |
215 if (full_name != NULL) | |
216 g_free(full_name); | |
217 | |
218 delete_win_cb(NULL, NULL, dialog); | |
219 } | |
220 | |
221 static void | |
222 select_account_cb(GObject *w, GaimAccount *account, | |
223 GevoNewPersonDialog *dialog) | |
224 { | |
225 dialog->account = account; | |
226 } | |
227 | |
228 void | |
229 gevo_new_person_dialog_show(EContact *contact, GaimAccount *account, | |
230 const char *username, const char *group, | |
231 GaimBuddy *buddy, gboolean person_only) | |
232 { | |
233 GevoNewPersonDialog *dialog; | |
234 GtkWidget *vbox, *vbox2; | |
235 GtkWidget *hbox; | |
236 GtkWidget *bbox; | |
237 GtkWidget *label; | |
238 GtkWidget *button; | |
239 GtkWidget *sep; | |
240 GtkSizeGroup *sg, *sg2; | |
241 const char *str; | |
242 | |
243 g_return_if_fail(!person_only || (person_only && buddy)); | |
244 | |
245 dialog = g_new0(GevoNewPersonDialog, 1); | |
246 | |
247 dialog->account = account; | |
248 dialog->person_only = person_only; | |
249 dialog->buddy = buddy; | |
250 | |
251 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
252 gtk_window_set_role(GTK_WINDOW(dialog->win), "new_person"); | |
253 gtk_window_set_resizable(GTK_WINDOW(dialog->win), FALSE); | |
254 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
255 | |
256 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
257 G_CALLBACK(delete_win_cb), dialog); | |
258 | |
259 /* Setup the vbox */ | |
260 vbox = gtk_vbox_new(FALSE, 12); | |
261 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
262 gtk_widget_show(vbox); | |
263 | |
264 /* Label */ | |
265 if (person_only) | |
266 { | |
267 label = gtk_label_new( | |
268 _("Please enter the person's information below.")); | |
269 } | |
270 else | |
271 { | |
272 label = gtk_label_new(_("Please enter the buddy's screen name and " | |
273 "account type below.")); | |
274 } | |
275 | |
276 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
277 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
278 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
279 gtk_widget_show(label); | |
280 | |
281 /* Setup the size groups */ | |
282 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
283 sg2 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
284 | |
285 if (!person_only) | |
286 { | |
287 /* Add the account type stuff. */ | |
288 dialog->accounts_menu = | |
289 gaim_gtk_account_option_menu_new(account, FALSE, | |
290 G_CALLBACK(select_account_cb), | |
291 NULL, dialog); | |
292 add_pref_box(sg, vbox, _("Account type:"), dialog->accounts_menu); | |
293 | |
294 /* Screen Name */ | |
295 dialog->screenname = gtk_entry_new(); | |
296 add_pref_box(sg, vbox, _("Screenname:"), dialog->screenname); | |
297 | |
298 if (username != NULL) | |
299 gtk_entry_set_text(GTK_ENTRY(dialog->screenname), username); | |
300 | |
301 g_signal_connect(G_OBJECT(dialog->screenname), "changed", | |
302 G_CALLBACK(screenname_changed_cb), dialog); | |
303 | |
304 /* Group */ | |
305 dialog->group_combo = gtk_combo_new(); | |
306 gtk_combo_set_popdown_strings(GTK_COMBO(dialog->group_combo), | |
307 gevo_get_groups()); | |
308 add_pref_box(sg, vbox, _("Group:"), dialog->group_combo); | |
309 | |
310 /* Separator */ | |
311 sep = gtk_hseparator_new(); | |
312 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
313 gtk_widget_show(sep); | |
314 | |
315 /* Optional Information section */ | |
316 label = gtk_label_new(_("Optional information:")); | |
317 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
318 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
319 gtk_widget_show(label); | |
320 } | |
321 | |
322 /* Create the parent hbox for this whole thing. */ | |
323 hbox = gtk_hbox_new(FALSE, 12); | |
324 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); | |
325 gtk_widget_show(hbox); | |
326 | |
327 #if 0 | |
328 /* Now the left side of the hbox */ | |
329 vbox2 = gtk_vbox_new(FALSE, 12); | |
330 gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, FALSE, 0); | |
331 gtk_widget_show(vbox2); | |
332 | |
333 /* Buddy icon button */ | |
334 button = gtk_button_new_from_stock(GTK_STOCK_OPEN); | |
335 gtk_box_pack_start(GTK_BOX(vbox2), button, FALSE, FALSE, 0); | |
336 gtk_widget_show(button); | |
337 | |
338 /* Label */ | |
339 label = gtk_label_new(_("Buddy Icon")); | |
340 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | |
341 gtk_widget_show(label); | |
342 #endif | |
343 | |
344 /* Now the right side. */ | |
345 vbox2 = gtk_vbox_new(FALSE, 12); | |
346 gtk_box_pack_start(GTK_BOX(hbox), vbox2, TRUE, TRUE, 0); | |
347 gtk_widget_show(vbox2); | |
348 | |
349 /* First Name field */ | |
350 dialog->firstname = gtk_entry_new(); | |
9044
23bcfdcd530d
[gaim-migrate @ 9820]
Christian Hammond <chipx86@chipx86.com>
parents:
9039
diff
changeset
|
351 add_pref_box(sg2, vbox2, _("First name:"), dialog->firstname); |
8089 | 352 |
353 if (contact != NULL) | |
354 { | |
355 str = e_contact_get_const(contact, E_CONTACT_GIVEN_NAME); | |
356 | |
357 if (str != NULL) | |
358 gtk_entry_set_text(GTK_ENTRY(dialog->firstname), str); | |
359 } | |
360 | |
361 /* Last Name field */ | |
362 dialog->lastname = gtk_entry_new(); | |
363 add_pref_box(sg2, vbox2, _("Last name:"), dialog->lastname); | |
364 | |
365 if (contact != NULL) | |
366 { | |
367 str = e_contact_get_const(contact, E_CONTACT_FAMILY_NAME); | |
368 | |
369 if (str != NULL) | |
370 gtk_entry_set_text(GTK_ENTRY(dialog->lastname), str); | |
371 } | |
372 | |
373 if (person_only) | |
374 { | |
375 g_signal_connect(G_OBJECT(dialog->firstname), "changed", | |
376 G_CALLBACK(person_info_changed_cb), dialog); | |
377 g_signal_connect(G_OBJECT(dialog->lastname), "changed", | |
378 G_CALLBACK(person_info_changed_cb), dialog); | |
379 } | |
380 | |
381 /* E-Mail address field */ | |
382 dialog->email = gtk_entry_new(); | |
383 add_pref_box(sg2, vbox2, _("E-mail:"), dialog->email); | |
384 | |
385 if (contact != NULL) | |
386 { | |
387 str = e_contact_get_const(contact, E_CONTACT_EMAIL_1); | |
388 | |
389 if (str != NULL) | |
390 gtk_entry_set_text(GTK_ENTRY(dialog->email), str); | |
391 } | |
392 | |
393 /* Separator */ | |
394 sep = gtk_hseparator_new(); | |
395 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
396 gtk_widget_show(sep); | |
397 | |
398 /* Button box */ | |
399 bbox = gtk_hbutton_box_new(); | |
400 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
401 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
402 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
403 gtk_widget_show(bbox); | |
404 | |
405 /* Cancel button */ | |
406 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
407 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
408 gtk_widget_show(button); | |
409 | |
410 g_signal_connect(G_OBJECT(button), "clicked", | |
411 G_CALLBACK(cancel_cb), dialog); | |
412 | |
413 /* Add button */ | |
414 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
415 dialog->add_button = button; | |
416 gtk_widget_set_sensitive(button, FALSE); | |
417 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
418 gtk_widget_show(button); | |
419 | |
420 g_signal_connect(G_OBJECT(button), "clicked", | |
421 G_CALLBACK(add_cb), dialog); | |
422 | |
423 /* Show it. */ | |
424 gtk_widget_show(dialog->win); | |
425 } |