Mercurial > pidgin
annotate plugins/gevolution/new_person_dialog.c @ 10234:d672afd04dcd
[gaim-migrate @ 11369]
"text replacement cosmetic change," patch 705648 from
Craig Slusher. This was submitted on 2003-03-18 and
it still basically applies. Neat.
"This just changes the way that the plugin reacts to the
'Add' button being clicked. After the replacement is
placed into the list, the text boxes are cleared and
the 'You type:' box gains focus"
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 22 Nov 2004 05:36:09 +0000 |
parents | ff4be2d1401d |
children | bc700cc98b82 |
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; | |
157 | |
158 if (field > 0) | |
159 { | |
160 GList *list = g_list_append(NULL, g_strdup(screenname)); | |
161 | |
162 e_contact_set(contact, field, list); | |
163 | |
164 g_free(list->data); | |
165 g_list_free(list); | |
166 } | |
167 | |
168 if (new_contact) | |
169 { | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
170 if (!e_book_add_contact(dialog->book, contact, NULL)) |
8089 | 171 { |
172 gaim_debug_error("evolution", "Error adding contact to book\n"); | |
173 | |
174 g_object_unref(contact); | |
175 delete_win_cb(NULL, NULL, dialog); | |
176 return; | |
177 } | |
178 } | |
179 else | |
180 { | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
181 if (!e_book_commit_contact(dialog->book, contact, NULL)) |
8089 | 182 { |
183 gaim_debug_error("evolution", "Error adding contact to book\n"); | |
184 | |
185 g_object_unref(contact); | |
186 delete_win_cb(NULL, NULL, dialog); | |
187 return; | |
188 } | |
189 } | |
190 | |
191 g_object_unref(contact); | |
192 } | |
193 | |
194 if (!dialog->person_only) | |
195 { | |
196 GtkWidget *entry = GTK_COMBO(dialog->group_combo)->entry; | |
197 const char *group_name; | |
198 | |
199 group_name = gtk_entry_get_text(GTK_ENTRY(entry)); | |
200 | |
201 gevo_add_buddy(dialog->account, group_name, screenname, full_name); | |
202 } | |
203 | |
204 if (name != NULL) | |
205 e_contact_name_free(name); | |
206 | |
207 if (full_name != NULL) | |
208 g_free(full_name); | |
209 | |
210 delete_win_cb(NULL, NULL, dialog); | |
211 } | |
212 | |
213 static void | |
214 select_account_cb(GObject *w, GaimAccount *account, | |
215 GevoNewPersonDialog *dialog) | |
216 { | |
217 dialog->account = account; | |
218 } | |
219 | |
220 void | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
221 gevo_new_person_dialog_show(EBook *book, EContact *contact, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
222 GaimAccount *account, const char *username, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
223 const char *group, GaimBuddy *buddy, |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
224 gboolean person_only) |
8089 | 225 { |
226 GevoNewPersonDialog *dialog; | |
227 GtkWidget *vbox, *vbox2; | |
228 GtkWidget *hbox; | |
229 GtkWidget *bbox; | |
230 GtkWidget *label; | |
231 GtkWidget *button; | |
232 GtkWidget *sep; | |
233 GtkSizeGroup *sg, *sg2; | |
234 const char *str; | |
235 | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
236 g_return_if_fail(book); |
8089 | 237 g_return_if_fail(!person_only || (person_only && buddy)); |
238 | |
239 dialog = g_new0(GevoNewPersonDialog, 1); | |
240 | |
241 dialog->account = account; | |
242 dialog->person_only = person_only; | |
243 dialog->buddy = buddy; | |
10081
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
244 dialog->book = book; |
ff4be2d1401d
[gaim-migrate @ 11071]
Christian Hammond <chipx86@chipx86.com>
parents:
9825
diff
changeset
|
245 g_object_ref(book); |
8089 | 246 |
247 dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
248 gtk_window_set_role(GTK_WINDOW(dialog->win), "new_person"); | |
249 gtk_window_set_resizable(GTK_WINDOW(dialog->win), FALSE); | |
250 gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12); | |
251 | |
252 g_signal_connect(G_OBJECT(dialog->win), "delete_event", | |
253 G_CALLBACK(delete_win_cb), dialog); | |
254 | |
255 /* Setup the vbox */ | |
256 vbox = gtk_vbox_new(FALSE, 12); | |
257 gtk_container_add(GTK_CONTAINER(dialog->win), vbox); | |
258 gtk_widget_show(vbox); | |
259 | |
260 /* Label */ | |
261 if (person_only) | |
262 { | |
263 label = gtk_label_new( | |
264 _("Please enter the person's information below.")); | |
265 } | |
266 else | |
267 { | |
268 label = gtk_label_new(_("Please enter the buddy's screen name and " | |
269 "account type below.")); | |
270 } | |
271 | |
272 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
273 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
274 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 0); | |
275 gtk_widget_show(label); | |
276 | |
277 /* Setup the size groups */ | |
278 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
279 sg2 = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
280 | |
281 if (!person_only) | |
282 { | |
283 /* Add the account type stuff. */ | |
284 dialog->accounts_menu = | |
285 gaim_gtk_account_option_menu_new(account, FALSE, | |
286 G_CALLBACK(select_account_cb), | |
287 NULL, dialog); | |
288 add_pref_box(sg, vbox, _("Account type:"), dialog->accounts_menu); | |
289 | |
290 /* Screen Name */ | |
291 dialog->screenname = gtk_entry_new(); | |
292 add_pref_box(sg, vbox, _("Screenname:"), dialog->screenname); | |
293 | |
294 if (username != NULL) | |
295 gtk_entry_set_text(GTK_ENTRY(dialog->screenname), username); | |
296 | |
297 g_signal_connect(G_OBJECT(dialog->screenname), "changed", | |
298 G_CALLBACK(screenname_changed_cb), dialog); | |
299 | |
300 /* Group */ | |
301 dialog->group_combo = gtk_combo_new(); | |
302 gtk_combo_set_popdown_strings(GTK_COMBO(dialog->group_combo), | |
303 gevo_get_groups()); | |
304 add_pref_box(sg, vbox, _("Group:"), dialog->group_combo); | |
305 | |
306 /* Separator */ | |
307 sep = gtk_hseparator_new(); | |
308 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
309 gtk_widget_show(sep); | |
310 | |
311 /* Optional Information section */ | |
312 label = gtk_label_new(_("Optional information:")); | |
313 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
314 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
315 gtk_widget_show(label); | |
316 } | |
317 | |
318 /* Create the parent hbox for this whole thing. */ | |
319 hbox = gtk_hbox_new(FALSE, 12); | |
320 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); | |
321 gtk_widget_show(hbox); | |
322 | |
323 #if 0 | |
324 /* Now the left side of the hbox */ | |
325 vbox2 = gtk_vbox_new(FALSE, 12); | |
326 gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, FALSE, 0); | |
327 gtk_widget_show(vbox2); | |
328 | |
329 /* Buddy icon button */ | |
330 button = gtk_button_new_from_stock(GTK_STOCK_OPEN); | |
331 gtk_box_pack_start(GTK_BOX(vbox2), button, FALSE, FALSE, 0); | |
332 gtk_widget_show(button); | |
333 | |
334 /* Label */ | |
335 label = gtk_label_new(_("Buddy Icon")); | |
336 gtk_box_pack_start(GTK_BOX(vbox2), label, FALSE, FALSE, 0); | |
337 gtk_widget_show(label); | |
338 #endif | |
339 | |
340 /* Now the right side. */ | |
341 vbox2 = gtk_vbox_new(FALSE, 12); | |
342 gtk_box_pack_start(GTK_BOX(hbox), vbox2, TRUE, TRUE, 0); | |
343 gtk_widget_show(vbox2); | |
344 | |
345 /* First Name field */ | |
346 dialog->firstname = gtk_entry_new(); | |
9044
23bcfdcd530d
[gaim-migrate @ 9820]
Christian Hammond <chipx86@chipx86.com>
parents:
9039
diff
changeset
|
347 add_pref_box(sg2, vbox2, _("First name:"), dialog->firstname); |
8089 | 348 |
349 if (contact != NULL) | |
350 { | |
351 str = e_contact_get_const(contact, E_CONTACT_GIVEN_NAME); | |
352 | |
353 if (str != NULL) | |
354 gtk_entry_set_text(GTK_ENTRY(dialog->firstname), str); | |
355 } | |
356 | |
357 /* Last Name field */ | |
358 dialog->lastname = gtk_entry_new(); | |
359 add_pref_box(sg2, vbox2, _("Last name:"), dialog->lastname); | |
360 | |
361 if (contact != NULL) | |
362 { | |
363 str = e_contact_get_const(contact, E_CONTACT_FAMILY_NAME); | |
364 | |
365 if (str != NULL) | |
366 gtk_entry_set_text(GTK_ENTRY(dialog->lastname), str); | |
367 } | |
368 | |
369 if (person_only) | |
370 { | |
371 g_signal_connect(G_OBJECT(dialog->firstname), "changed", | |
372 G_CALLBACK(person_info_changed_cb), dialog); | |
373 g_signal_connect(G_OBJECT(dialog->lastname), "changed", | |
374 G_CALLBACK(person_info_changed_cb), dialog); | |
375 } | |
376 | |
377 /* E-Mail address field */ | |
378 dialog->email = gtk_entry_new(); | |
379 add_pref_box(sg2, vbox2, _("E-mail:"), dialog->email); | |
380 | |
381 if (contact != NULL) | |
382 { | |
383 str = e_contact_get_const(contact, E_CONTACT_EMAIL_1); | |
384 | |
385 if (str != NULL) | |
386 gtk_entry_set_text(GTK_ENTRY(dialog->email), str); | |
387 } | |
388 | |
389 /* Separator */ | |
390 sep = gtk_hseparator_new(); | |
391 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
392 gtk_widget_show(sep); | |
393 | |
394 /* Button box */ | |
395 bbox = gtk_hbutton_box_new(); | |
396 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
397 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
398 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0); | |
399 gtk_widget_show(bbox); | |
400 | |
401 /* Cancel button */ | |
402 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
403 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
404 gtk_widget_show(button); | |
405 | |
406 g_signal_connect(G_OBJECT(button), "clicked", | |
407 G_CALLBACK(cancel_cb), dialog); | |
408 | |
409 /* Add button */ | |
410 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
411 dialog->add_button = button; | |
412 gtk_widget_set_sensitive(button, FALSE); | |
413 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
414 gtk_widget_show(button); | |
415 | |
416 g_signal_connect(G_OBJECT(button), "clicked", | |
417 G_CALLBACK(add_cb), dialog); | |
418 | |
419 /* Show it. */ | |
420 gtk_widget_show(dialog->win); | |
421 } |