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