Mercurial > pidgin
annotate src/gtkpounce.c @ 5279:36523a0d8459
[gaim-migrate @ 5651]
iso8601 tweaks for jabber
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 01 May 2003 19:40:16 +0000 |
parents | 1a53330dfd34 |
children | 3adb20b869b4 |
rev | line source |
---|---|
5032 | 1 /** |
2 * @file gtkpounce.h GTK+ buddy pounce API | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
5054 | 23 #include <unistd.h> |
5032 | 24 #include "gaim.h" |
25 #include "gtkpounce.h" | |
5228
1a53330dfd34
[gaim-migrate @ 5598]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
26 #include "gtkblist.h" |
5032 | 27 #include "prpl.h" |
28 #include "sound.h" | |
29 | |
30 struct gaim_gtkpounce_dialog | |
31 { | |
32 /* Pounce data */ | |
33 struct gaim_pounce *pounce; | |
34 struct gaim_account *account; | |
35 | |
36 /* The window */ | |
37 GtkWidget *window; | |
38 | |
39 /* Pounce Who */ | |
40 GtkWidget *account_menu; | |
41 GtkWidget *buddy_entry; | |
42 | |
43 /* Pounce When */ | |
44 GtkWidget *signon; | |
45 GtkWidget *signoff; | |
46 GtkWidget *away; | |
47 GtkWidget *away_return; | |
48 GtkWidget *idle; | |
49 GtkWidget *idle_return; | |
50 GtkWidget *typing; | |
51 GtkWidget *stop_typing; | |
52 | |
53 /* Pounce Action */ | |
54 GtkWidget *open_win; | |
55 GtkWidget *popup; | |
56 GtkWidget *send_msg; | |
57 GtkWidget *send_msg_entry; | |
58 GtkWidget *exec_cmd; | |
59 GtkWidget *exec_cmd_entry; | |
60 GtkWidget *play_sound; | |
61 GtkWidget *play_sound_entry; | |
62 | |
63 GtkWidget *save_pounce; | |
64 }; | |
65 | |
66 /************************************************************************** | |
67 * Callbacks | |
68 **************************************************************************/ | |
69 static gint | |
70 delete_win_cb(GtkWidget *w, GdkEventAny *e, | |
71 struct gaim_gtkpounce_dialog *dialog) | |
72 { | |
73 gtk_widget_destroy(dialog->window); | |
74 g_free(dialog); | |
75 | |
76 return TRUE; | |
77 } | |
78 | |
79 static void | |
5052
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
80 delete_cb(GtkWidget *w, struct gaim_gtkpounce_dialog *dialog) |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
81 { |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
82 gaim_pounce_destroy(dialog->pounce); |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
83 |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
84 delete_win_cb(NULL, NULL, dialog); |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
85 } |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
86 |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
87 static void |
5032 | 88 cancel_cb(GtkWidget *w, struct gaim_gtkpounce_dialog *dialog) |
89 { | |
90 delete_win_cb(NULL, NULL, dialog); | |
91 } | |
92 | |
93 | |
94 static void | |
95 save_pounce_cb(GtkWidget *w, struct gaim_gtkpounce_dialog *dialog) | |
96 { | |
97 const char *name; | |
98 const char *message, *command, *sound; | |
99 struct gaim_buddy_list *blist; | |
100 struct gaim_gtk_buddy_list *gtkblist; | |
101 GaimPounceEvent events = GAIM_POUNCE_NONE; | |
102 GaimGtkPounceAction actions = GAIM_GTKPOUNCE_NONE; | |
103 gboolean save; | |
104 | |
105 name = gtk_entry_get_text(GTK_ENTRY(dialog->buddy_entry)); | |
106 | |
107 if (*name == '\0') { | |
108 do_error_dialog(_("Please enter a buddy to pounce."), NULL, GAIM_ERROR); | |
109 return; | |
110 } | |
111 | |
112 /* Events */ | |
113 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->signon))) | |
114 events |= GAIM_POUNCE_SIGNON; | |
115 | |
116 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->signoff))) | |
117 events |= GAIM_POUNCE_SIGNOFF; | |
118 | |
119 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->away))) | |
120 events |= GAIM_POUNCE_AWAY; | |
121 | |
122 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->away_return))) | |
123 events |= GAIM_POUNCE_AWAY_RETURN; | |
124 | |
125 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->idle))) | |
126 events |= GAIM_POUNCE_IDLE; | |
127 | |
128 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->idle_return))) | |
129 events |= GAIM_POUNCE_IDLE_RETURN; | |
130 | |
131 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->typing))) | |
132 events |= GAIM_POUNCE_TYPING; | |
133 | |
134 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->stop_typing))) | |
135 events |= GAIM_POUNCE_TYPING_STOPPED; | |
136 | |
137 | |
138 /* Actions */ | |
139 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->open_win))) | |
140 actions |= GAIM_GTKPOUNCE_OPEN_WIN; | |
141 | |
142 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->popup))) | |
143 actions |= GAIM_GTKPOUNCE_POPUP; | |
144 | |
145 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->send_msg))) | |
146 actions |= GAIM_GTKPOUNCE_SEND_MSG; | |
147 | |
148 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->exec_cmd))) | |
149 actions |= GAIM_GTKPOUNCE_EXEC_CMD; | |
150 | |
151 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->play_sound))) | |
152 actions |= GAIM_GTKPOUNCE_PLAY_SOUND; | |
153 | |
154 save = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->save_pounce)); | |
155 | |
156 /* Data fields */ | |
157 message = gtk_entry_get_text(GTK_ENTRY(dialog->send_msg_entry)); | |
158 command = gtk_entry_get_text(GTK_ENTRY(dialog->exec_cmd_entry)); | |
159 sound = gtk_entry_get_text(GTK_ENTRY(dialog->play_sound_entry)); | |
160 | |
161 if (*message == '\0') message = NULL; | |
162 if (*command == '\0') command = NULL; | |
163 if (*sound == '\0') sound = NULL; | |
164 | |
165 if (dialog->pounce == NULL) | |
166 { | |
167 gaim_gtkpounce_new(dialog->account, name, events, actions, | |
168 message, command, sound, save); | |
169 } | |
170 else | |
171 { | |
172 struct gaim_gtkpounce_data *pounce_data; | |
173 | |
174 gaim_pounce_set_events(dialog->pounce, events); | |
175 gaim_pounce_set_pouncer(dialog->pounce, dialog->account); | |
176 gaim_pounce_set_pouncee(dialog->pounce, name); | |
177 | |
178 pounce_data = GAIM_GTKPOUNCE(dialog->pounce); | |
179 | |
180 if (pounce_data->message != NULL) g_free(pounce_data->message); | |
181 if (pounce_data->command != NULL) g_free(pounce_data->command); | |
182 if (pounce_data->sound != NULL) g_free(pounce_data->sound); | |
183 | |
184 pounce_data->message = (message == NULL ? NULL : g_strdup(message)); | |
185 pounce_data->command = (command == NULL ? NULL : g_strdup(command)); | |
186 pounce_data->sound = (sound == NULL ? NULL : g_strdup(sound)); | |
187 | |
188 pounce_data->actions = actions; | |
189 pounce_data->save = save; | |
190 } | |
191 | |
192 delete_win_cb(NULL, NULL, dialog); | |
193 | |
194 /* Rebuild the pounce menu */ | |
195 blist = gaim_get_blist(); | |
196 | |
197 if (GAIM_IS_GTK_BLIST(blist)) | |
198 { | |
199 gtkblist = GAIM_GTK_BLIST(blist); | |
200 | |
201 gaim_gtkpounce_menu_build(gtkblist->bpmenu); | |
202 } | |
203 | |
204 save_prefs(); | |
205 } | |
206 | |
5054 | 207 static void |
5032 | 208 pounce_choose_cb(GtkWidget *item, struct gaim_gtkpounce_dialog *dialog) |
209 { | |
210 dialog->account = g_object_get_data(G_OBJECT(item), "user_data"); | |
211 } | |
212 | |
213 static GtkWidget * | |
214 pounce_user_menu(struct gaim_gtkpounce_dialog *dialog) | |
215 { | |
216 struct gaim_account *account; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
217 GaimPlugin *prpl; |
5032 | 218 GtkWidget *opt_menu; |
219 GtkWidget *menu; | |
220 GtkWidget *item; | |
221 GSList *l; | |
222 char buf[2048]; | |
5054 | 223 int count, place = 0; |
5032 | 224 |
225 opt_menu = gtk_option_menu_new(); | |
226 menu = gtk_menu_new(); | |
227 | |
228 for (l = gaim_accounts, count = 0; l != NULL; l = l->next, count++) { | |
229 account = (struct gaim_account *)l->data; | |
230 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
231 prpl = gaim_find_prpl(account->protocol); |
5032 | 232 |
233 g_snprintf(buf, sizeof(buf), "%s (%s)", account->username, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
234 (prpl && prpl->info->name) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5161
diff
changeset
|
235 ? prpl->info->name : _("Unknown")); |
5032 | 236 |
237 item = gtk_menu_item_new_with_label(buf); | |
238 g_object_set_data(G_OBJECT(item), "user_data", account); | |
239 | |
240 g_signal_connect(G_OBJECT(item), "activate", | |
241 G_CALLBACK(pounce_choose_cb), dialog); | |
242 | |
243 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
244 gtk_widget_show(item); | |
245 | |
246 if (dialog->account == account) { | |
247 gtk_menu_item_activate(GTK_MENU_ITEM(item)); | |
248 place = count; | |
249 } | |
250 } | |
251 | |
252 gtk_option_menu_set_menu(GTK_OPTION_MENU(opt_menu), menu); | |
253 gtk_option_menu_set_history(GTK_OPTION_MENU(opt_menu), place); | |
254 | |
255 return opt_menu; | |
256 } | |
257 | |
258 static void | |
259 pounce_cb(struct gaim_pounce *pounce, GaimPounceEvent events, void *data) | |
260 { | |
261 struct gaim_conversation *conv; | |
262 struct gaim_account *account; | |
263 struct gaim_gtkpounce_data *pounce_data; | |
264 const char *pouncee; | |
265 | |
266 pounce_data = (struct gaim_gtkpounce_data *)data; | |
267 pouncee = gaim_pounce_get_pouncee(pounce); | |
268 account = gaim_pounce_get_pouncer(pounce); | |
269 | |
270 if (pounce_data->actions & GAIM_GTKPOUNCE_OPEN_WIN) { | |
271 conv = gaim_find_conversation(pouncee); | |
272 | |
273 if (conv == NULL) | |
274 conv = gaim_conversation_new(GAIM_CONV_IM, account, pouncee); | |
275 } | |
276 | |
277 if (pounce_data->actions & GAIM_GTKPOUNCE_POPUP) { | |
278 char tmp[1024]; | |
279 | |
280 g_snprintf(tmp, sizeof(tmp), | |
281 (events & GAIM_POUNCE_TYPING) ? _("%s has started typing to you") : | |
282 (events & GAIM_POUNCE_SIGNON) ? _("%s has signed on") : | |
283 (events & GAIM_POUNCE_IDLE_RETURN) ? _("%s has returned from being idle") : | |
284 (events & GAIM_POUNCE_AWAY_RETURN) ? _("%s has returned from being away") : | |
285 (events & GAIM_POUNCE_TYPING_STOPPED) ? _("%s has stopped typing to you") : | |
286 (events & GAIM_POUNCE_SIGNOFF) ? _("%s has signed off") : | |
287 (events & GAIM_POUNCE_IDLE) ? _("%s has become idle") : | |
288 (events & GAIM_POUNCE_AWAY) ? _("%s has gone away.") : | |
289 _("Unknown pounce event. Please report this!"), | |
290 pouncee); | |
291 | |
292 do_error_dialog(tmp, NULL, GAIM_INFO); | |
293 } | |
294 | |
295 if (pounce_data->actions & GAIM_GTKPOUNCE_SEND_MSG && | |
5051
b3d9195777bb
[gaim-migrate @ 5400]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
296 pounce_data->message != NULL) { |
5032 | 297 |
298 conv = gaim_find_conversation(pouncee); | |
299 | |
300 if (conv == NULL) | |
301 conv = gaim_conversation_new(GAIM_CONV_IM, account, pouncee); | |
302 | |
303 gaim_conversation_write(conv, NULL, pounce_data->message, -1, | |
304 WFLAG_SEND, time(NULL)); | |
305 | |
306 serv_send_im(account->gc, (char *)pouncee, pounce_data->message, -1, 0); | |
307 } | |
308 | |
309 if (pounce_data->actions & GAIM_GTKPOUNCE_EXEC_CMD && | |
5051
b3d9195777bb
[gaim-migrate @ 5400]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
310 pounce_data->command != NULL) { |
5032 | 311 #ifndef _WIN32 |
312 int pid = fork(); | |
313 | |
314 if (pid == 0) { | |
315 char *args[4]; | |
316 | |
317 args[0] = "sh"; | |
318 args[1] = "-c"; | |
319 args[2] = pounce_data->command; | |
320 args[3] = NULL; | |
321 | |
322 execvp(args[0], args); | |
323 | |
324 _exit(0); | |
325 } | |
326 #endif /* _WIN32 */ | |
327 } | |
328 | |
329 if (pounce_data->actions & GAIM_GTKPOUNCE_PLAY_SOUND) { | |
5051
b3d9195777bb
[gaim-migrate @ 5400]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
330 if (pounce_data->sound != NULL) |
5032 | 331 gaim_sound_play_file(pounce_data->sound); |
332 else | |
333 gaim_sound_play_event(GAIM_SOUND_POUNCE_DEFAULT); | |
334 } | |
335 | |
336 if (!pounce_data->save) | |
337 gaim_pounce_destroy(pounce); | |
338 } | |
339 | |
340 static void | |
341 free_pounce(void *data) | |
342 { | |
343 struct gaim_gtkpounce_data *pounce_data; | |
344 struct gaim_buddy_list *blist; | |
345 struct gaim_gtk_buddy_list *gtkblist; | |
346 | |
347 pounce_data = (struct gaim_gtkpounce_data *)data; | |
348 | |
349 if (pounce_data->message != NULL) g_free(pounce_data->message); | |
350 if (pounce_data->command != NULL) g_free(pounce_data->command); | |
351 if (pounce_data->sound != NULL) g_free(pounce_data->sound); | |
352 | |
353 g_free(data); | |
354 | |
355 /* Rebuild the pounce menu */ | |
356 blist = gaim_get_blist(); | |
357 | |
358 if (GAIM_IS_GTK_BLIST(blist)) | |
359 { | |
360 gtkblist = GAIM_GTK_BLIST(blist); | |
361 | |
362 gaim_gtkpounce_menu_build(gtkblist->bpmenu); | |
363 } | |
364 | |
365 save_prefs(); | |
366 } | |
367 | |
368 struct gaim_pounce * | |
369 gaim_gtkpounce_new(struct gaim_account *pouncer, const char *pouncee, | |
370 GaimPounceEvent events, GaimGtkPounceAction actions, | |
371 const char *message, const char *command, | |
372 const char *sound, gboolean save) | |
373 { | |
374 struct gaim_gtkpounce_data *data; | |
375 | |
376 data = g_new0(struct gaim_gtkpounce_data, 1); | |
377 | |
378 data->actions = actions; | |
379 | |
380 if (message != NULL) data->message = g_strdup(message); | |
381 if (command != NULL) data->command = g_strdup(command); | |
382 if (sound != NULL) data->sound = g_strdup(sound); | |
383 | |
384 data->save = save; | |
385 | |
386 return gaim_pounce_new(pouncer, pouncee, events, pounce_cb, data, | |
387 free_pounce); | |
388 } | |
389 | |
390 void | |
391 gaim_gtkpounce_dialog_show(struct buddy *buddy, | |
392 struct gaim_pounce *cur_pounce) | |
393 { | |
394 struct gaim_gtkpounce_dialog *dialog; | |
395 GtkWidget *window; | |
396 GtkWidget *label; | |
397 GtkWidget *bbox; | |
398 GtkWidget *vbox1, *vbox2; | |
399 GtkWidget *hbox; | |
400 GtkWidget *button; | |
401 GtkWidget *frame; | |
402 GtkWidget *table; | |
403 GtkWidget *sep; | |
404 GtkSizeGroup *sg; | |
405 | |
406 dialog = g_new0(struct gaim_gtkpounce_dialog, 1); | |
407 | |
408 if (cur_pounce != NULL) { | |
409 dialog->pounce = cur_pounce; | |
410 dialog->account = gaim_pounce_get_pouncer(cur_pounce); | |
411 } | |
412 else if (buddy != NULL) { | |
413 dialog->pounce = NULL; | |
414 dialog->account = buddy->account; | |
415 } | |
416 else { | |
417 dialog->pounce = NULL; | |
418 dialog->account = gaim_accounts->data; | |
419 } | |
420 | |
421 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
422 | |
423 /* Create the window. */ | |
424 dialog->window = window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
425 gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
426 gtk_window_set_role(GTK_WINDOW(window), "buddy_pounce"); | |
427 gtk_window_set_resizable(GTK_WINDOW(window), FALSE); | |
428 gtk_window_set_title(GTK_WINDOW(window), | |
429 (cur_pounce == NULL | |
430 ? _("New Buddy Pounce") : _("Edit Buddy Pounce"))); | |
431 | |
432 gtk_container_set_border_width(GTK_CONTAINER(window), 12); | |
433 gtk_widget_realize(window); | |
434 | |
435 g_signal_connect(G_OBJECT(window), "delete_event", | |
436 G_CALLBACK(delete_win_cb), dialog); | |
437 | |
438 /* Create the parent vbox for everything. */ | |
439 vbox1 = gtk_vbox_new(FALSE, 12); | |
440 gtk_container_add(GTK_CONTAINER(window), vbox1); | |
441 gtk_widget_show(vbox1); | |
442 | |
443 /* Create the vbox that will contain all the prefs stuff. */ | |
444 vbox2 = gtk_vbox_new(FALSE, 18); | |
445 gtk_box_pack_start(GTK_BOX(vbox1), vbox2, TRUE, TRUE, 0); | |
446 | |
447 /* Create the "Pounce Who" frame. */ | |
448 frame = make_frame(vbox2, _("Pounce Who")); | |
449 | |
450 /* Account: */ | |
451 hbox = gtk_hbox_new(FALSE, 6); | |
452 gtk_box_pack_start(GTK_BOX(frame), hbox, FALSE, FALSE, 0); | |
453 gtk_widget_show(hbox); | |
454 | |
455 label = gtk_label_new_with_mnemonic(_("_Account:")); | |
456 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
457 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
458 gtk_widget_show(label); | |
459 gtk_size_group_add_widget(sg, label); | |
460 | |
461 dialog->account_menu = pounce_user_menu(dialog); | |
462 gtk_box_pack_start(GTK_BOX(hbox), dialog->account_menu, FALSE, FALSE, 0); | |
463 gtk_widget_show(dialog->account_menu); | |
464 | |
465 /* Buddy: */ | |
466 hbox = gtk_hbox_new(FALSE, 6); | |
467 gtk_box_pack_start(GTK_BOX(frame), hbox, FALSE, FALSE, 0); | |
468 gtk_widget_show(hbox); | |
469 | |
470 label = gtk_label_new_with_mnemonic(_("_Buddy Name:")); | |
471 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
472 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
473 gtk_widget_show(label); | |
474 gtk_size_group_add_widget(sg, label); | |
475 | |
476 dialog->buddy_entry = gtk_entry_new(); | |
477 gtk_box_pack_start(GTK_BOX(hbox), dialog->buddy_entry, TRUE, TRUE, 0); | |
478 gtk_widget_show(dialog->buddy_entry); | |
479 | |
480 if (cur_pounce != NULL) { | |
481 gtk_entry_set_text(GTK_ENTRY(dialog->buddy_entry), | |
482 gaim_pounce_get_pouncee(cur_pounce)); | |
483 } | |
484 else if (buddy != NULL) { | |
485 gtk_entry_set_text(GTK_ENTRY(dialog->buddy_entry), buddy->name); | |
486 } | |
487 | |
488 /* Create the "Pounce When" frame. */ | |
489 frame = make_frame(vbox2, _("Pounce When")); | |
490 | |
491 table = gtk_table_new(2, 4, FALSE); | |
492 gtk_container_add(GTK_CONTAINER(frame), table); | |
493 gtk_table_set_col_spacings(GTK_TABLE(table), 12); | |
494 gtk_widget_show(table); | |
495 | |
496 dialog->signon = | |
497 gtk_check_button_new_with_label(_("Sign on")); | |
498 dialog->signoff = | |
499 gtk_check_button_new_with_label(_("Sign off")); | |
500 dialog->away = | |
501 gtk_check_button_new_with_label(_("Away")); | |
502 dialog->away_return = | |
503 gtk_check_button_new_with_label(_("Return from away")); | |
504 dialog->idle = | |
505 gtk_check_button_new_with_label(_("Idle")); | |
506 dialog->idle_return = | |
507 gtk_check_button_new_with_label(_("Return from idle")); | |
508 dialog->typing = | |
509 gtk_check_button_new_with_label(_("Buddy starts typing")); | |
510 dialog->stop_typing = | |
511 gtk_check_button_new_with_label(_("Buddy stops typing")); | |
512 | |
513 gtk_table_attach(GTK_TABLE(table), dialog->signon, 0, 1, 0, 1, | |
514 GTK_FILL, 0, 0, 0); | |
515 gtk_table_attach(GTK_TABLE(table), dialog->signoff, 1, 2, 0, 1, | |
516 GTK_FILL, 0, 0, 0); | |
517 gtk_table_attach(GTK_TABLE(table), dialog->away, 0, 1, 1, 2, | |
518 GTK_FILL, 0, 0, 0); | |
519 gtk_table_attach(GTK_TABLE(table), dialog->away_return, 1, 2, 1, 2, | |
520 GTK_FILL, 0, 0, 0); | |
521 gtk_table_attach(GTK_TABLE(table), dialog->idle, 0, 1, 2, 3, | |
522 GTK_FILL, 0, 0, 0); | |
523 gtk_table_attach(GTK_TABLE(table), dialog->idle_return, 1, 2, 2, 3, | |
524 GTK_FILL, 0, 0, 0); | |
525 gtk_table_attach(GTK_TABLE(table), dialog->typing, 0, 1, 3, 4, | |
526 GTK_FILL, 0, 0, 0); | |
527 gtk_table_attach(GTK_TABLE(table), dialog->stop_typing, 1, 2, 3, 4, | |
528 GTK_FILL, 0, 0, 0); | |
529 | |
530 gtk_widget_show(dialog->signon); | |
531 gtk_widget_show(dialog->signoff); | |
532 gtk_widget_show(dialog->away); | |
533 gtk_widget_show(dialog->away_return); | |
534 gtk_widget_show(dialog->idle); | |
535 gtk_widget_show(dialog->idle_return); | |
536 gtk_widget_show(dialog->typing); | |
537 gtk_widget_show(dialog->stop_typing); | |
538 | |
539 /* Create the "Pounce Action" frame. */ | |
540 frame = make_frame(vbox2, _("Pounce Action")); | |
541 | |
542 table = gtk_table_new(2, 5, FALSE); | |
543 gtk_container_add(GTK_CONTAINER(frame), table); | |
544 gtk_table_set_col_spacings(GTK_TABLE(table), 12); | |
545 gtk_widget_show(table); | |
546 | |
547 dialog->open_win = gtk_check_button_new_with_label(_("Open an IM window")); | |
548 dialog->popup = gtk_check_button_new_with_label(_("Popup notification")); | |
549 dialog->send_msg = gtk_check_button_new_with_label(_("Send a message")); | |
550 dialog->exec_cmd = gtk_check_button_new_with_label(_("Execute a command")); | |
5051
b3d9195777bb
[gaim-migrate @ 5400]
Christian Hammond <chipx86@chipx86.com>
parents:
5032
diff
changeset
|
551 dialog->play_sound = gtk_check_button_new_with_label(_("Play a sound")); |
5032 | 552 |
553 dialog->send_msg_entry = gtk_entry_new(); | |
554 dialog->exec_cmd_entry = gtk_entry_new(); | |
555 dialog->play_sound_entry = gtk_entry_new(); | |
556 | |
557 gtk_widget_set_sensitive(dialog->send_msg_entry, FALSE); | |
558 gtk_widget_set_sensitive(dialog->exec_cmd_entry, FALSE); | |
559 gtk_widget_set_sensitive(dialog->play_sound_entry, FALSE); | |
560 | |
561 gtk_table_attach(GTK_TABLE(table), dialog->open_win, 0, 1, 0, 1, | |
562 GTK_FILL, 0, 0, 0); | |
563 gtk_table_attach(GTK_TABLE(table), dialog->popup, 0, 1, 1, 2, | |
564 GTK_FILL, 0, 0, 0); | |
565 gtk_table_attach(GTK_TABLE(table), dialog->send_msg, 0, 1, 2, 3, | |
566 GTK_FILL, 0, 0, 0); | |
567 gtk_table_attach(GTK_TABLE(table), dialog->send_msg_entry, 1, 2, 2, 3, | |
568 GTK_FILL, 0, 0, 0); | |
569 gtk_table_attach(GTK_TABLE(table), dialog->exec_cmd, 0, 1, 3, 4, | |
570 GTK_FILL, 0, 0, 0); | |
571 gtk_table_attach(GTK_TABLE(table), dialog->exec_cmd_entry, 1, 2, 3, 4, | |
572 GTK_FILL, 0, 0, 0); | |
573 gtk_table_attach(GTK_TABLE(table), dialog->play_sound, 0, 1, 4, 5, | |
574 GTK_FILL, 0, 0, 0); | |
575 gtk_table_attach(GTK_TABLE(table), dialog->play_sound_entry, 1, 2, 4, 5, | |
576 GTK_FILL, 0, 0, 0); | |
577 | |
578 gtk_widget_show(dialog->open_win); | |
579 gtk_widget_show(dialog->popup); | |
580 gtk_widget_show(dialog->send_msg); | |
581 gtk_widget_show(dialog->send_msg_entry); | |
582 gtk_widget_show(dialog->exec_cmd); | |
583 gtk_widget_show(dialog->exec_cmd_entry); | |
584 gtk_widget_show(dialog->play_sound); | |
585 gtk_widget_show(dialog->play_sound_entry); | |
586 | |
587 g_signal_connect(G_OBJECT(dialog->send_msg), "clicked", | |
588 G_CALLBACK(gaim_gtk_toggle_sensitive), | |
589 dialog->send_msg_entry); | |
590 g_signal_connect(G_OBJECT(dialog->exec_cmd), "clicked", | |
591 G_CALLBACK(gaim_gtk_toggle_sensitive), | |
592 dialog->exec_cmd_entry); | |
593 g_signal_connect(G_OBJECT(dialog->play_sound), "clicked", | |
594 G_CALLBACK(gaim_gtk_toggle_sensitive), | |
595 dialog->play_sound_entry); | |
596 | |
597 g_signal_connect(G_OBJECT(dialog->send_msg_entry), "activate", | |
598 G_CALLBACK(save_pounce_cb), dialog); | |
599 g_signal_connect(G_OBJECT(dialog->exec_cmd_entry), "activate", | |
600 G_CALLBACK(save_pounce_cb), dialog); | |
601 g_signal_connect(G_OBJECT(dialog->play_sound_entry), "activate", | |
602 G_CALLBACK(save_pounce_cb), dialog); | |
603 | |
604 /* Now the last part, where we have the Save checkbox */ | |
605 dialog->save_pounce = gtk_check_button_new_with_mnemonic( | |
606 _("_Save this pounce after activation")); | |
607 | |
608 gtk_box_pack_start(GTK_BOX(vbox2), dialog->save_pounce, FALSE, FALSE, 0); | |
609 | |
610 /* Separator... */ | |
611 sep = gtk_hseparator_new(); | |
612 gtk_box_pack_start(GTK_BOX(vbox1), sep, FALSE, FALSE, 0); | |
613 gtk_widget_show(sep); | |
614 | |
615 /* Now the button box! */ | |
616 bbox = gtk_hbutton_box_new(); | |
617 gtk_box_set_spacing(GTK_BOX(bbox), 6); | |
618 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
619 gtk_box_pack_end(GTK_BOX(vbox1), bbox, FALSE, FALSE, 0); | |
620 gtk_widget_show(bbox); | |
621 | |
5052
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
622 /* Delete button */ |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
623 button = gtk_button_new_from_stock(GTK_STOCK_DELETE); |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
624 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
625 gtk_widget_show(button); |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
626 |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
627 g_signal_connect(G_OBJECT(button), "clicked", |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
628 G_CALLBACK(delete_cb), dialog); |
6a7759f63766
[gaim-migrate @ 5401]
Christian Hammond <chipx86@chipx86.com>
parents:
5051
diff
changeset
|
629 |
5032 | 630 /* Cancel button */ |
631 button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
632 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
633 gtk_widget_show(button); | |
634 | |
635 g_signal_connect(G_OBJECT(button), "clicked", | |
636 G_CALLBACK(cancel_cb), dialog); | |
637 | |
638 /* OK button */ | |
639 button = gtk_button_new_from_stock(GTK_STOCK_OK); | |
640 gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); | |
641 gtk_widget_show(button); | |
642 | |
643 g_signal_connect(G_OBJECT(button), "clicked", | |
644 G_CALLBACK(save_pounce_cb), dialog); | |
645 | |
646 /* Set the values of stuff. */ | |
647 if (cur_pounce != NULL) { | |
648 GaimPounceEvent events; | |
649 GaimGtkPounceAction actions; | |
650 struct gaim_gtkpounce_data *pounce_data; | |
651 | |
652 pounce_data = GAIM_GTKPOUNCE(cur_pounce); | |
653 events = gaim_pounce_get_events(cur_pounce); | |
654 actions = pounce_data->actions; | |
655 | |
656 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->signon), | |
657 (events & GAIM_POUNCE_SIGNON)); | |
658 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->signoff), | |
659 (events & GAIM_POUNCE_SIGNOFF)); | |
660 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->away), | |
661 (events & GAIM_POUNCE_AWAY)); | |
662 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->away_return), | |
663 (events & GAIM_POUNCE_AWAY_RETURN)); | |
664 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->idle), | |
665 (events & GAIM_POUNCE_IDLE)); | |
666 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->idle_return), | |
667 (events & GAIM_POUNCE_IDLE_RETURN)); | |
668 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->typing), | |
669 (events & GAIM_POUNCE_TYPING)); | |
670 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->stop_typing), | |
671 (events & GAIM_POUNCE_TYPING_STOPPED)); | |
672 | |
673 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->open_win), | |
674 (actions & GAIM_GTKPOUNCE_OPEN_WIN)); | |
675 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->popup), | |
676 (actions & GAIM_GTKPOUNCE_POPUP)); | |
677 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->send_msg), | |
678 (actions & GAIM_GTKPOUNCE_SEND_MSG)); | |
679 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->exec_cmd), | |
680 (actions & GAIM_GTKPOUNCE_EXEC_CMD)); | |
681 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->play_sound), | |
682 (actions & GAIM_GTKPOUNCE_PLAY_SOUND)); | |
683 | |
684 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->save_pounce), | |
685 pounce_data->save); | |
686 | |
687 gtk_entry_set_text(GTK_ENTRY(dialog->send_msg_entry), | |
688 pounce_data->message); | |
689 gtk_entry_set_text(GTK_ENTRY(dialog->exec_cmd_entry), | |
690 pounce_data->command); | |
691 gtk_entry_set_text(GTK_ENTRY(dialog->play_sound_entry), | |
692 pounce_data->sound); | |
693 } | |
694 else { | |
695 /* Set some defaults */ | |
696 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->send_msg), TRUE); | |
697 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->signon), TRUE); | |
698 } | |
699 | |
700 gtk_widget_show_all(vbox2); | |
701 gtk_widget_show(window); | |
702 } | |
703 | |
704 static void | |
705 new_pounce_cb(GtkWidget *w, struct buddy *b) | |
706 { | |
707 gaim_gtkpounce_dialog_show(b, NULL); | |
708 } | |
709 | |
710 static void | |
5153
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
711 delete_pounce_cb(GtkWidget *w, struct gaim_pounce *pounce) |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
712 { |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
713 gaim_pounce_destroy(pounce); |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
714 } |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
715 |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
716 static void |
5032 | 717 edit_pounce_cb(GtkWidget *w, struct gaim_pounce *pounce) |
718 { | |
719 struct buddy *buddy; | |
720 | |
721 buddy = gaim_find_buddy(gaim_pounce_get_pouncer(pounce), | |
722 gaim_pounce_get_pouncee(pounce)); | |
723 | |
724 gaim_gtkpounce_dialog_show(buddy, pounce); | |
725 } | |
726 | |
5153
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
727 static void |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
728 fill_menu(GtkWidget *menu, GCallback cb) |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
729 { |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
730 GtkWidget *image; |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
731 GtkWidget *item; |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
732 GdkPixbuf *pixbuf, *scale; |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
733 struct gaim_pounce *pounce; |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
734 const char *buddy; |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
735 GList *bp; |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
736 |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
737 for (bp = gaim_get_pounces(); bp != NULL; bp = bp->next) { |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
738 pounce = (struct gaim_pounce *)bp->data; |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
739 buddy = gaim_pounce_get_pouncee(pounce); |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
740 |
5161 | 741 /* Build the menu item */ |
742 item = gtk_image_menu_item_new_with_label(buddy); | |
743 | |
5153
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
744 /* Create a pixmap for the protocol icon. */ |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
745 pixbuf = create_prpl_icon(gaim_pounce_get_pouncer(pounce)); |
5161 | 746 if(pixbuf) { |
747 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, | |
748 GDK_INTERP_BILINEAR); | |
5153
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
749 |
5161 | 750 /* Now convert it to GtkImage */ |
5153
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
751 image = gtk_image_new_from_pixbuf(scale); |
5161 | 752 g_object_unref(G_OBJECT(scale)); |
753 g_object_unref(G_OBJECT(pixbuf)); | |
754 gtk_widget_show(image); | |
755 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); | |
756 } | |
5153
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
757 |
5161 | 758 /* Put the item in the menu */ |
5153
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
759 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
760 gtk_widget_show(item); |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
761 |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
762 /* Set our callbacks. */ |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
763 g_signal_connect(G_OBJECT(item), "activate", cb, pounce); |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
764 } |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
765 } |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
766 |
5032 | 767 void |
768 gaim_gtkpounce_menu_build(GtkWidget *menu) | |
769 { | |
5153
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
770 GtkWidget *remmenu; |
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
771 GtkWidget *item; |
5032 | 772 GList *l; |
773 | |
774 for (l = gtk_container_get_children(GTK_CONTAINER(menu)); | |
775 l != NULL; | |
776 l = l->next) { | |
777 | |
778 gtk_widget_destroy(GTK_WIDGET(l->data)); | |
779 } | |
780 | |
781 /* "New Buddy Pounce" */ | |
782 item = gtk_menu_item_new_with_label(_("New Buddy Pounce")); | |
783 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
784 gtk_widget_show(item); | |
785 g_signal_connect(G_OBJECT(item), "activate", | |
786 G_CALLBACK(new_pounce_cb), NULL); | |
787 | |
788 /* "Remove Buddy Pounce" */ | |
789 item = gtk_menu_item_new_with_label(_("Remove Buddy Pounce")); | |
790 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
791 | |
792 /* "Remove Buddy Pounce" menu */ | |
793 remmenu = gtk_menu_new(); | |
794 | |
5153
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
795 fill_menu(remmenu, G_CALLBACK(delete_pounce_cb)); |
5032 | 796 |
797 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), remmenu); | |
798 gtk_widget_show(remmenu); | |
799 gtk_widget_show(item); | |
800 | |
801 /* Separator */ | |
802 item = gtk_separator_menu_item_new(); | |
803 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
804 gtk_widget_show(item); | |
805 | |
5153
ab0f12de3718
[gaim-migrate @ 5517]
Christian Hammond <chipx86@chipx86.com>
parents:
5054
diff
changeset
|
806 fill_menu(menu, G_CALLBACK(edit_pounce_cb)); |
5032 | 807 } |
808 |