Mercurial > pidgin
annotate plugins/gevolution/new_person_dialog.c @ 13836:9af607a0108f
[gaim-migrate @ 16285]
Fix a case of a file transfer "system message" notification where we were not looking up an alias like everywhere else in this file.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 19 Jun 2006 06:23:20 +0000 |
parents | d2e5a9f2c174 |
children |
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 | |
13420
d6530e0cd89f
[gaim-migrate @ 15795]
Richard Laager <rlaager@wiktel.com>
parents:
13415
diff
changeset
|
107 if (*firstname || *lastname) |
8089 | 108 { |
109 if (dialog->contact == NULL) | |
110 { | |
111 char *file_as; | |
112 | |
113 dialog->contact = e_contact_new(); | |
114 | |
13420
d6530e0cd89f
[gaim-migrate @ 15795]
Richard Laager <rlaager@wiktel.com>
parents:
13415
diff
changeset
|
115 if (*lastname && *firstname) |
8089 | 116 file_as = g_strdup_printf("%s, %s", lastname, firstname); |
13420
d6530e0cd89f
[gaim-migrate @ 15795]
Richard Laager <rlaager@wiktel.com>
parents:
13415
diff
changeset
|
117 else if (*lastname) |
8089 | 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"); | |
13703
d2e5a9f2c174
[gaim-migrate @ 16106]
Richard Laager <rlaager@wiktel.com>
parents:
13420
diff
changeset
|
251 gtk_window_set_title(GTK_WINDOW(dialog->win), _("New Person")); |
8089 | 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(); | |
12489 | 295 add_pref_box(sg, vbox, _("Screen name:"), dialog->screenname); |
8089 | 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 } |