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