Mercurial > pidgin
annotate plugins/gevolution/new_person_dialog.c @ 12898:e3b4e6787dff
[gaim-migrate @ 15251]
SF Patch #1406080 from Sadrul. This fixes the prototype on the drawing-tooltip callback.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Tue, 17 Jan 2006 00:20:13 +0000 |
parents | 12db50600de5 |
children | 3038ab2eff72 |
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 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
57 g_object_unref(dialog->book); |
8089 | 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 != NULL && firstname != NULL) | |
116 file_as = g_strdup_printf("%s, %s", lastname, firstname); | |
117 else if (lastname != NULL) | |
118 file_as = g_strdup(lastname); | |
119 else | |
120 file_as = g_strdup(firstname); | |
121 | |
8474
8b62cc40069b
[gaim-migrate @ 9207]
Christian Hammond <chipx86@chipx86.com>
parents:
8089
diff
changeset
|
122 e_contact_set(dialog->contact, E_CONTACT_FILE_AS, file_as); |
8089 | 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 = gaim_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; | |
11054
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10081
diff
changeset
|
157 else if (!strcmp(im_service, "prpl-novell")) |
bc700cc98b82
[gaim-migrate @ 12992]
Richard Laager <rlaager@wiktel.com>
parents:
10081
diff
changeset
|
158 field = E_CONTACT_IM_GROUPWISE; |
8089 | 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 { | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
172 if (!e_book_add_contact(dialog->book, contact, NULL)) |
8089 | 173 { |
174 gaim_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 { | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
183 if (!e_book_commit_contact(dialog->book, contact, NULL)) |
8089 | 184 { |
185 gaim_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 GtkWidget *entry = GTK_COMBO(dialog->group_combo)->entry; | |
199 const char *group_name; | |
200 | |
201 group_name = gtk_entry_get_text(GTK_ENTRY(entry)); | |
202 | |
203 gevo_add_buddy(dialog->account, group_name, screenname, full_name); | |
204 } | |
205 | |
206 if (name != NULL) | |
207 e_contact_name_free(name); | |
208 | |
209 if (full_name != NULL) | |
210 g_free(full_name); | |
211 | |
212 delete_win_cb(NULL, NULL, dialog); | |
213 } | |
214 | |
215 static void | |
216 select_account_cb(GObject *w, GaimAccount *account, | |
217 GevoNewPersonDialog *dialog) | |
218 { | |
219 dialog->account = account; | |
220 } | |
221 | |
222 void | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
223 gevo_new_person_dialog_show(EBook *book, EContact *contact, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
224 GaimAccount *account, const char *username, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
225 const char *group, GaimBuddy *buddy, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
226 gboolean person_only) |
8089 | 227 { |
228 GevoNewPersonDialog *dialog; | |
229 GtkWidget *vbox, *vbox2; | |
230 GtkWidget *hbox; | |
231 GtkWidget *bbox; | |
232 GtkWidget *label; | |
233 GtkWidget *button; | |
234 GtkWidget *sep; | |
235 GtkSizeGroup *sg, *sg2; | |
236 const char *str; | |
237 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
238 g_return_if_fail(book); |
8089 | 239 g_return_if_fail(!person_only || (person_only && buddy)); |
240 | |
241 dialog = g_new0(GevoNewPersonDialog, 1); | |
242 | |
243 dialog->account = account; | |
244 dialog->person_only = person_only; | |
245 dialog->buddy = buddy; | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
246 dialog->book = book; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
247 g_object_ref(book); |
8089 | 248 |
249 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
250 gtk_window_set_role(GTK_WINDOW(dialog->win), "new_person"); | |
251 gtk_window_set_resizable(GTK_WINDOW(dialog->win), FALSE); | |
252 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
253 | |
254 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
255 G_CALLBACK(delete_win_cb), dialog); | |
256 | |
257 /* Setup the vbox */ | |
258 vbox = gtk_vbox_new(FALSE, 12); | |
259 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
260 gtk_widget_show(vbox); | |
261 | |
262 /* Label */ | |
263 if (person_only) | |
264 { | |
265 label = gtk_label_new( | |
266 _("Please enter the person's information below.")); | |
267 } | |
268 else | |
269 { | |
270 label = gtk_label_new(_("Please enter the buddy's screen name and " | |
271 "account type below.")); | |
272 } | |
273 | |
274 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
275 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
276 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
277 gtk_widget_show(label); | |
278 | |
279 /* Setup the size groups */ | |
280 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
281 sg2 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
282 | |
283 if (!person_only) | |
284 { | |
285 /* Add the account type stuff. */ | |
286 dialog->accounts_menu = | |
287 gaim_gtk_account_option_menu_new(account, FALSE, | |
288 G_CALLBACK(select_account_cb), | |
289 NULL, dialog); | |
290 add_pref_box(sg, vbox, _("Account type:"), dialog->accounts_menu); | |
291 | |
292 /* Screen Name */ | |
293 dialog->screenname = gtk_entry_new(); | |
12489 | 294 add_pref_box(sg, vbox, _("Screen name:"), dialog->screenname); |
8089 | 295 |
296 if (username != NULL) | |
297 gtk_entry_set_text(GTK_ENTRY(dialog->screenname), username); | |
298 | |
299 g_signal_connect(G_OBJECT(dialog->screenname), "changed", | |
300 G_CALLBACK(screenname_changed_cb), dialog); | |
301 | |
302 /* Group */ | |
303 dialog->group_combo = gtk_combo_new(); | |
304 gtk_combo_set_popdown_strings(GTK_COMBO(dialog->group_combo), | |
305 gevo_get_groups()); | |
306 add_pref_box(sg, vbox, _("Group:"), dialog->group_combo); | |
307 | |
308 /* Separator */ | |
309 sep = gtk_hseparator_new(); | |
310 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
311 gtk_widget_show(sep); | |
312 | |
313 /* Optional Information section */ | |
314 label = gtk_label_new(_("Optional information:")); | |
315 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
316 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
317 gtk_widget_show(label); | |
318 } | |
319 | |
320 /* Create the parent hbox for this whole thing. */ | |
321 hbox = gtk_hbox_new(FALSE, 12); | |
322 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); | |
323 gtk_widget_show(hbox); | |
324 | |
325 #if 0 | |
326 /* Now the left side of the hbox */ | |
327 vbox2 = gtk_vbox_new(FALSE, 12); | |
328 gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, FALSE, 0); | |
329 gtk_widget_show(vbox2); | |
330 | |
331 /* Buddy icon button */ | |
332 button = gtk_button_new_from_stock(GTK_STOCK_OPEN); | |
333 gtk_box_pack_start(GTK_BOX(vbox2), button, FALSE, FALSE, 0); | |
334 gtk_widget_show(button); | |
335 | |
336 /* Label */ | |
337 label = gtk_label_new(_("Buddy Icon")); | |
338 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | |
339 gtk_widget_show(label); | |
340 #endif | |
341 | |
342 /* Now the right side. */ | |
343 vbox2 = gtk_vbox_new(FALSE, 12); | |
344 gtk_box_pack_start(GTK_BOX(hbox), vbox2, TRUE, TRUE, 0); | |
345 gtk_widget_show(vbox2); | |
346 | |
347 /* First Name field */ | |
348 dialog->firstname = gtk_entry_new(); | |
9044
23bcfdcd530d
[gaim-migrate @ 9820]
Christian Hammond <chipx86@chipx86.com>
parents:
9039
diff
changeset
|
349 add_pref_box(sg2, vbox2, _("First name:"), dialog->firstname); |
8089 | 350 |
351 if (contact != NULL) | |
352 { | |
353 str = e_contact_get_const(contact, E_CONTACT_GIVEN_NAME); | |
354 | |
355 if (str != NULL) | |
356 gtk_entry_set_text(GTK_ENTRY(dialog->firstname), str); | |
357 } | |
358 | |
359 /* Last Name field */ | |
360 dialog->lastname = gtk_entry_new(); | |
361 add_pref_box(sg2, vbox2, _("Last name:"), dialog->lastname); | |
362 | |
363 if (contact != NULL) | |
364 { | |
365 str = e_contact_get_const(contact, E_CONTACT_FAMILY_NAME); | |
366 | |
367 if (str != NULL) | |
368 gtk_entry_set_text(GTK_ENTRY(dialog->lastname), str); | |
369 } | |
370 | |
371 if (person_only) | |
372 { | |
373 g_signal_connect(G_OBJECT(dialog->firstname), "changed", | |
374 G_CALLBACK(person_info_changed_cb), dialog); | |
375 g_signal_connect(G_OBJECT(dialog->lastname), "changed", | |
376 G_CALLBACK(person_info_changed_cb), dialog); | |
377 } | |
378 | |
379 /* E-Mail address field */ | |
380 dialog->email = gtk_entry_new(); | |
381 add_pref_box(sg2, vbox2, _("E-mail:"), dialog->email); | |
382 | |
383 if (contact != NULL) | |
384 { | |
385 str = e_contact_get_const(contact, E_CONTACT_EMAIL_1); | |
386 | |
387 if (str != NULL) | |
388 gtk_entry_set_text(GTK_ENTRY(dialog->email), str); | |
389 } | |
390 | |
391 /* Separator */ | |
392 sep = gtk_hseparator_new(); | |
393 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
394 gtk_widget_show(sep); | |
395 | |
396 /* Button box */ | |
397 bbox = gtk_hbutton_box_new(); | |
398 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
399 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
400 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
401 gtk_widget_show(bbox); | |
402 | |
403 /* Cancel button */ | |
404 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
405 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
406 gtk_widget_show(button); | |
407 | |
408 g_signal_connect(G_OBJECT(button), "clicked", | |
409 G_CALLBACK(cancel_cb), dialog); | |
410 | |
411 /* Add button */ | |
412 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
413 dialog->add_button = button; | |
414 gtk_widget_set_sensitive(button, FALSE); | |
415 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
416 gtk_widget_show(button); | |
417 | |
418 g_signal_connect(G_OBJECT(button), "clicked", | |
419 G_CALLBACK(add_cb), dialog); | |
420 | |
421 /* Show it. */ | |
422 gtk_widget_show(dialog->win); | |
423 } |