Updated Spanish translation
[anjuta-git-plugin.git] / plugins / debug-manager / signals.c
blobda0adf74e546924c6b61d60e69b294844af02f3a
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 signals.c
4 Copyright (C) 2000 Kh. Naba Kumar Singh
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include <string.h>
27 #include <ctype.h>
29 #include <gnome.h>
31 #include <libanjuta/resources.h>
33 #include "utilities.h"
34 #include "signals.h"
37 static GtkWidget* create_signals_set_dialog (Signals *s);
39 static void
40 signals_update_controls (Signals * ew)
42 gboolean R, Pr;
44 R = dma_debugger_queue_get_state (ew->debugger) == IANJUTA_DEBUGGER_OK;
45 Pr = dma_debugger_queue_get_state (ew->debugger) == IANJUTA_DEBUGGER_PROGRAM_RUNNING;
46 gtk_widget_set_sensitive (ew->widgets.menu_signal, Pr);
47 gtk_widget_set_sensitive (ew->widgets.menu_modify, R);
48 gtk_widget_set_sensitive (ew->widgets.menu_update, R);
51 static void
52 signals_update (const GList * lines, gpointer data)
54 Signals *sg;
55 gint j, count;
56 gchar *row[5], *str;
57 gchar sig[32], stop[10], print[10], pass[10];
58 GList *list, *node;
60 sg = (Signals *) data;
61 signals_clear (sg);
62 list = gdb_util_remove_blank_lines (lines);
63 if (g_list_length (list) < 2)
65 g_list_free (list);
66 return;
68 gtk_clist_freeze (GTK_CLIST(sg->widgets.clist));
69 node = list->next;
70 while (node)
72 count =
73 sscanf ((char *) node->data, "%s %s %s %s", sig, stop, print, pass);
74 str = node->data;
75 node = g_list_next (node);
76 if (count != 4)
77 continue;
79 /* Do not worry. This is used to avoid the last line */
80 if (node == NULL)
81 break;
82 row[0] = sig;
83 row[1] = stop;
84 row[2] = print;
85 row[3] = pass;
86 for (j = 0; j < 4; j++)
88 while (isspace (*str))
89 str++;
90 while (!isspace (*str))
91 str++;
93 while (isspace (*str))
94 str++;
95 row[4] = str;
96 gtk_clist_append (GTK_CLIST (sg->widgets.clist), row);
98 g_list_free (list);
99 gtk_clist_thaw (GTK_CLIST(sg->widgets.clist));
102 static void
103 on_signals_clist_select_row (GtkCList *clist, gint row,
104 gint column, GdkEvent *event, gpointer user_data)
106 Signals *s = (Signals*)user_data;
107 s->idx = row;
110 static gint
111 on_signals_delete_event(GtkWidget* w, GdkEvent *event, gpointer data)
113 Signals* cr = (Signals*) data;
114 signals_hide (cr);
115 return TRUE;
118 static gboolean
119 on_signals_key_press_event(GtkWidget *widget, GdkEventKey *event,
120 gpointer data)
122 if (event->keyval == GDK_Escape)
124 Signals* cr = (Signals*) data;
125 signals_hide(cr);
126 return TRUE;
128 return FALSE;
131 static void
132 on_signals_modify_activate (GtkMenuItem *menuitem, gpointer user_data)
134 GtkWidget* dialog;
135 Signals *s = (Signals*)user_data;
137 dialog = create_signals_set_dialog (s);
138 if (dialog)
139 gtk_widget_show (dialog);
142 static void
143 on_signals_send_activate (GtkMenuItem *menuitem, gpointer user_data)
145 #if 0
146 gchar* sig;
147 Signals *s = (Signals*)user_data;
149 if (debugger_program_is_running (s->debugger) == FALSE) return;
151 signals_show (s);
152 gtk_clist_get_text(GTK_CLIST (s->widgets.clist), s->idx, 0, &sig);
153 debugger_signal(sig, TRUE);
154 #endif
157 static void
158 on_signals_update_activate (GtkMenuItem *menuitem, gpointer user_data)
160 Signals *s = (Signals*)user_data;
161 dma_queue_info_signal (
162 s->debugger,
163 (IAnjutaDebuggerCallback)signals_update,
167 static gboolean
168 on_signals_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
170 GdkEventButton *bevent;
171 Signals *ew = (Signals*)user_data;
173 if (event->type != GDK_BUTTON_PRESS) return FALSE;
174 if (((GdkEventButton *)event)->button != 3) return FALSE;
176 bevent = (GdkEventButton *)event;
177 bevent->button = 1;
178 signals_update_controls(ew);
179 gtk_menu_popup (GTK_MENU(ew->widgets.menu), NULL,
180 NULL, NULL, NULL,
181 bevent->button, bevent->time);
182 return TRUE;
185 static void
186 on_signals_togglebutton1_toggled (GtkToggleButton *togglebutton,
187 gpointer user_data)
189 Signals *sig = (Signals*) user_data;
191 sig->stop = gtk_toggle_button_get_active (togglebutton);
192 if (sig->stop)
193 gtk_label_set_text (GTK_LABEL(GTK_BIN (togglebutton)->child), _("Yes"));
194 else
195 gtk_label_set_text (GTK_LABEL(GTK_BIN (togglebutton)->child), _("No"));
198 static void
199 on_signals_togglebutton2_toggled (GtkToggleButton *togglebutton,
200 gpointer user_data)
202 Signals *sig = (Signals*) user_data;
204 sig->print = gtk_toggle_button_get_active(togglebutton);
205 if (sig->print)
206 gtk_label_set_text (GTK_LABEL(GTK_BIN(togglebutton)->child), _("Yes"));
207 else
208 gtk_label_set_text (GTK_LABEL(GTK_BIN(togglebutton)->child), _("No"));
211 static void
212 on_signals_togglebutton3_toggled (GtkToggleButton *togglebutton,
213 gpointer user_data)
215 Signals *sig = (Signals*) user_data;
217 sig->pass = gtk_toggle_button_get_active (togglebutton);
218 if (sig->pass)
219 gtk_label_set_text (GTK_LABEL(GTK_BIN(togglebutton)->child), _("Yes"));
220 else
221 gtk_label_set_text (GTK_LABEL(GTK_BIN(togglebutton)->child), _("No"));
224 static void
225 on_signals_set_ok_clicked (GtkButton *button,
226 gpointer user_data)
228 Signals *s = (Signals*) user_data;
230 if(s->stop)
232 gtk_clist_set_text(GTK_CLIST(s->widgets.clist), s->idx, 1, "Yes");
234 else
236 gtk_clist_set_text(GTK_CLIST(s->widgets.clist), s->idx, 1, "No");
238 if(s->print)
240 gtk_clist_set_text(GTK_CLIST(s->widgets.clist), s->idx, 2, "Yes");
242 else
244 gtk_clist_set_text(GTK_CLIST(s->widgets.clist), s->idx, 2, "No");
246 if(s->pass)
248 gtk_clist_set_text(GTK_CLIST(s->widgets.clist), s->idx, 3, "Yes");
250 else
252 gtk_clist_set_text(GTK_CLIST(s->widgets.clist), s->idx, 3, "No");
254 dma_queue_handle_signal (s->debugger, s->signal, s->stop, s->print, s->pass);
257 static GnomeUIInfo signals_menu_uiinfo[] =
260 GNOME_APP_UI_ITEM, N_("Modify Signal"),
261 NULL,
262 on_signals_modify_activate, NULL, NULL,
263 GNOME_APP_PIXMAP_NONE, NULL,
264 0, 0, NULL
267 GNOME_APP_UI_ITEM, N_("Send to process"),
268 NULL,
269 on_signals_send_activate, NULL, NULL,
270 GNOME_APP_PIXMAP_NONE, NULL,
271 0, 0, NULL
274 GNOME_APP_UI_ITEM, N_("Update"),
275 NULL,
276 on_signals_update_activate, NULL, NULL,
277 GNOME_APP_PIXMAP_NONE, NULL,
278 0, 0, NULL
280 GNOMEUIINFO_END
283 static GtkWidget*
284 create_signals_menu (Signals *s)
286 GtkWidget *signals_menu;
288 signals_menu = gtk_menu_new ();
290 signals_menu_uiinfo[0].user_data = s;
291 signals_menu_uiinfo[1].user_data = s;
292 signals_menu_uiinfo[2].user_data = s;
294 gnome_app_fill_menu (GTK_MENU_SHELL (signals_menu), signals_menu_uiinfo,
295 NULL, FALSE, 0);
296 return signals_menu;
299 static void
300 create_signals_gui (Signals *cr)
302 GtkWidget *window3;
303 GtkWidget *scrolledwindow4;
304 GtkWidget *clist4;
305 GtkWidget *label6, *label7, *label8, *label9, *label10;
307 window3 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
308 gtk_widget_set_usize (window3, 170, -2);
309 gtk_window_set_title (GTK_WINDOW (window3), _("Kernel signals"));
310 gtk_window_set_wmclass (GTK_WINDOW (window3), "signals", "Anjuta");
311 gtk_window_set_default_size (GTK_WINDOW (window3), 240, 230);
312 gnome_window_icon_set_from_default(GTK_WINDOW(window3));
314 scrolledwindow4 = gtk_scrolled_window_new (NULL, NULL);
315 gtk_widget_show (scrolledwindow4);
316 gtk_container_add (GTK_CONTAINER (window3), scrolledwindow4);
317 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow4),
318 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
320 clist4 = gtk_clist_new (5);
321 gtk_widget_show (clist4);
322 gtk_container_add (GTK_CONTAINER (scrolledwindow4), clist4);
323 gtk_clist_set_column_width (GTK_CLIST (clist4), 0, 100);
324 gtk_clist_set_column_width (GTK_CLIST (clist4), 1, 50);
325 gtk_clist_set_column_width (GTK_CLIST (clist4), 2, 50);
326 gtk_clist_set_column_width (GTK_CLIST (clist4), 3, 50);
327 gtk_clist_set_column_width (GTK_CLIST (clist4), 4, 80);
328 gtk_clist_set_selection_mode (GTK_CLIST (clist4), GTK_SELECTION_BROWSE);
329 gtk_clist_column_titles_show (GTK_CLIST (clist4));
330 gtk_clist_set_column_auto_resize (GTK_CLIST(clist4), 4, TRUE);
332 label6 = gtk_label_new (_("Signal"));
333 gtk_widget_show (label6);
334 gtk_clist_set_column_widget (GTK_CLIST (clist4), 0, label6);
336 label7 = gtk_label_new (_("Stop"));
337 gtk_widget_show (label7);
338 gtk_clist_set_column_widget (GTK_CLIST (clist4), 1, label7);
340 label8 = gtk_label_new (_("Print"));
341 gtk_widget_show (label8);
342 gtk_clist_set_column_widget (GTK_CLIST (clist4), 2, label8);
344 label9 = gtk_label_new (_("Pass"));
345 gtk_widget_show (label9);
346 gtk_clist_set_column_widget (GTK_CLIST (clist4), 3, label9);
348 label10 = gtk_label_new (_("Description"));
349 gtk_widget_show (label10);
350 gtk_clist_set_column_widget (GTK_CLIST (clist4), 4, label10);
352 gtk_signal_connect (GTK_OBJECT (window3), "delete_event",
353 GTK_SIGNAL_FUNC (on_signals_delete_event), cr);
354 gtk_signal_connect (GTK_OBJECT (window3), "key-press-event",
355 GTK_SIGNAL_FUNC (on_signals_key_press_event), cr);
357 gtk_signal_connect (GTK_OBJECT (clist4), "event",
358 GTK_SIGNAL_FUNC (on_signals_event),
359 cr);
360 gtk_signal_connect (GTK_OBJECT (clist4), "select_row",
361 GTK_SIGNAL_FUNC (on_signals_clist_select_row),
362 cr);
364 cr->widgets.window = window3;
365 cr->widgets.clist = clist4;
366 cr->widgets.menu = create_signals_menu (cr);
367 cr->widgets.menu_modify = signals_menu_uiinfo[0].widget;
368 cr->widgets.menu_signal = signals_menu_uiinfo[1].widget;
369 cr->widgets.menu_update = signals_menu_uiinfo[2].widget;
372 static GtkWidget*
373 create_signals_set_dialog (Signals *s)
375 GtkWidget *dialog1;
376 GtkWidget *dialog_vbox1;
377 GtkWidget *hbox1;
378 GtkWidget *label1;
379 GtkWidget *label2;
380 GtkWidget *hbox2;
381 GtkWidget *label3;
382 GtkWidget *label4;
383 GtkWidget *hseparator1;
384 GtkWidget *hbox4;
385 GtkWidget *label5;
386 GtkWidget *label6;
387 GtkWidget *label7;
388 GtkWidget *hbox3;
389 GtkWidget *togglebutton1;
390 GtkWidget *togglebutton2;
391 GtkWidget *togglebutton3;
392 GtkWidget *dialog_action_area1;
393 GtkWidget *button1;
394 GtkWidget *button2;
395 GtkWidget *button3;
396 gchar *row[5];
398 if(s->idx < 0)
399 return NULL;
401 gtk_clist_get_text(GTK_CLIST(s->widgets.clist), s->idx,0, &row[0]);
402 gtk_clist_get_text(GTK_CLIST(s->widgets.clist), s->idx,1, &row[1]);
403 gtk_clist_get_text(GTK_CLIST(s->widgets.clist), s->idx,2, &row[2]);
404 gtk_clist_get_text(GTK_CLIST(s->widgets.clist), s->idx,3, &row[3]);
405 gtk_clist_get_text(GTK_CLIST(s->widgets.clist), s->idx,4, &row[4]);
406 s->signal = row[0];
408 if(strcasecmp(row[1], "Yes")==0)
409 s->stop = TRUE;
410 else
411 s->stop = FALSE;
413 if(strcasecmp(row[2], "Yes")==0)
414 s->print = TRUE;
415 else
416 s->print = FALSE;
418 if(strcasecmp(row[3], "Yes")==0)
419 s->pass = TRUE;
420 else
421 s->pass = FALSE;
423 dialog1 = gnome_dialog_new (_("Set Signal Property"), NULL);
424 gtk_window_set_transient_for (GTK_WINDOW(dialog1),
425 GTK_WINDOW(s->widgets.window));
426 GTK_WINDOW (dialog1)->type = GTK_WINDOW_TOPLEVEL;
427 gtk_window_set_position (GTK_WINDOW (dialog1), GTK_WIN_POS_MOUSE);
428 gtk_window_set_policy (GTK_WINDOW (dialog1), FALSE, FALSE, FALSE);
429 gtk_window_set_wmclass (GTK_WINDOW (dialog1), "set_signal", "Anjuta");
430 gnome_dialog_set_close (GNOME_DIALOG (dialog1), TRUE);
432 dialog_vbox1 = GNOME_DIALOG (dialog1)->vbox;
433 gtk_widget_show (dialog_vbox1);
435 hbox1 = gtk_hbox_new (FALSE, 0);
436 gtk_widget_show (hbox1);
437 gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox1, TRUE, TRUE, 0);
439 label1 = gtk_label_new ("Signal: ");
440 gtk_widget_show (label1);
441 gtk_box_pack_start (GTK_BOX (hbox1), label1, FALSE, FALSE, 0);
443 label2 = gtk_label_new (row[0]);
444 gtk_widget_show (label2);
445 gtk_box_pack_start (GTK_BOX (hbox1), label2, FALSE, FALSE, 0);
447 hbox2 = gtk_hbox_new (FALSE, 0);
448 gtk_widget_show (hbox2);
449 gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox2, TRUE, TRUE, 0);
451 label3 = gtk_label_new ("Description: ");
452 gtk_widget_show (label3);
453 gtk_box_pack_start (GTK_BOX (hbox2), label3, FALSE, FALSE, 0);
455 label4 = gtk_label_new (row[4]);
456 gtk_widget_show (label4);
457 gtk_box_pack_start (GTK_BOX (hbox2), label4, FALSE, FALSE, 0);
459 hseparator1 = gtk_hseparator_new ();
460 gtk_widget_show (hseparator1);
461 gtk_box_pack_start (GTK_BOX (dialog_vbox1), hseparator1, TRUE, TRUE, 0);
463 hbox4 = gtk_hbox_new (FALSE, 0);
464 gtk_widget_show (hbox4);
465 gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox4, TRUE, TRUE, 0);
467 label5 = gtk_label_new (_(" Stop: "));
468 gtk_widget_show (label5);
469 gtk_box_pack_start (GTK_BOX (hbox4), label5, TRUE, TRUE, 0);
471 label6 = gtk_label_new (_(" Print: "));
472 gtk_widget_show (label6);
473 gtk_box_pack_start (GTK_BOX (hbox4), label6, TRUE, TRUE, 0);
475 label7 = gtk_label_new (_("Pass:"));
476 gtk_widget_show (label7);
477 gtk_box_pack_start (GTK_BOX (hbox4), label7, TRUE, TRUE, 0);
479 hbox3 = gtk_hbox_new (FALSE, 0);
480 gtk_widget_show (hbox3);
481 gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox3, TRUE, TRUE, 0);
483 togglebutton1 = gtk_toggle_button_new_with_label (row[1]);
484 gtk_widget_show (togglebutton1);
485 gtk_box_pack_start (GTK_BOX (hbox3), togglebutton1, TRUE, TRUE, 0);
486 gtk_container_set_border_width (GTK_CONTAINER (togglebutton1), 3);
487 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togglebutton1), s->stop);
489 togglebutton2 = gtk_toggle_button_new_with_label (row[2]);
490 gtk_widget_show (togglebutton2);
491 gtk_box_pack_start (GTK_BOX (hbox3), togglebutton2, TRUE, TRUE, 0);
492 gtk_container_set_border_width (GTK_CONTAINER (togglebutton2), 3);
493 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togglebutton2), s->print);
495 togglebutton3 = gtk_toggle_button_new_with_label (row[3]);
496 gtk_widget_show (togglebutton3);
497 gtk_box_pack_start (GTK_BOX (hbox3), togglebutton3, TRUE, TRUE, 0);
498 gtk_container_set_border_width (GTK_CONTAINER (togglebutton3), 3);
499 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togglebutton3), s->pass);
501 dialog_action_area1 = GNOME_DIALOG (dialog1)->action_area;
502 gtk_widget_show (dialog_action_area1);
503 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1),
504 GTK_BUTTONBOX_SPREAD);
505 gtk_button_box_set_spacing (GTK_BUTTON_BOX (dialog_action_area1), 8);
507 gnome_dialog_append_button (GNOME_DIALOG (dialog1),
508 GNOME_STOCK_BUTTON_HELP);
509 button1 = g_list_last (GNOME_DIALOG (dialog1)->buttons)->data;
510 gtk_widget_show (button1);
511 GTK_WIDGET_SET_FLAGS (button1, GTK_CAN_DEFAULT);
513 gnome_dialog_append_button (GNOME_DIALOG (dialog1), GNOME_STOCK_BUTTON_OK);
514 button2 = g_list_last (GNOME_DIALOG (dialog1)->buttons)->data;
515 gtk_widget_show (button2);
516 GTK_WIDGET_SET_FLAGS (button2, GTK_CAN_DEFAULT);
518 gnome_dialog_append_button (GNOME_DIALOG (dialog1),
519 GNOME_STOCK_BUTTON_CANCEL);
520 button3 = g_list_last (GNOME_DIALOG (dialog1)->buttons)->data;
521 gtk_widget_show (button3);
522 GTK_WIDGET_SET_FLAGS (button3, GTK_CAN_DEFAULT);
524 gtk_signal_connect (GTK_OBJECT (togglebutton1), "toggled",
525 GTK_SIGNAL_FUNC (on_signals_togglebutton1_toggled),
527 gtk_signal_connect (GTK_OBJECT (togglebutton2), "toggled",
528 GTK_SIGNAL_FUNC (on_signals_togglebutton2_toggled),
530 gtk_signal_connect (GTK_OBJECT (togglebutton3), "toggled",
531 GTK_SIGNAL_FUNC (on_signals_togglebutton3_toggled),
533 gtk_signal_connect (GTK_OBJECT (button2), "clicked",
534 GTK_SIGNAL_FUNC (on_signals_set_ok_clicked),
536 return dialog1;
539 Signals *
540 signals_new (DebugManagerPlugin *plugin)
542 Signals *ew;
543 ew = g_malloc (sizeof (Signals));
544 if (ew)
546 ew->debugger = dma_debug_manager_get_queue (plugin);
547 ew->is_showing = FALSE;
548 ew->win_width = 460;
549 ew->win_height = 320;
550 ew->win_pos_x = 150;
551 ew->win_pos_y = 130;
552 ew->idx = -1;
553 create_signals_gui (ew);
555 return ew;
558 void
559 signals_clear (Signals * sg)
561 if (GTK_IS_CLIST (sg->widgets.clist))
562 gtk_clist_clear (GTK_CLIST (sg->widgets.clist));
563 sg->idx = -1;
566 void
567 signals_show (Signals * ew)
569 if (ew)
571 if (ew->is_showing)
573 gdk_window_raise (ew->widgets.window->window);
575 else
577 gtk_widget_set_uposition (ew->widgets.window, ew->win_pos_x,
578 ew->win_pos_y);
579 gtk_window_set_default_size (GTK_WINDOW (ew->widgets.window),
580 ew->win_width, ew->win_height);
581 gtk_widget_show (ew->widgets.window);
582 ew->is_showing = TRUE;
583 dma_queue_info_signal (
584 ew->debugger,
585 (IAnjutaDebuggerCallback)signals_update,
586 ew);
591 void
592 signals_hide (Signals * ew)
594 if (ew)
596 if (ew->is_showing == FALSE)
597 return;
598 gdk_window_get_root_origin (ew->widgets.window->window, &ew->win_pos_x,
599 &ew->win_pos_y);
600 gdk_window_get_size (ew->widgets.window->window, &ew->win_width,
601 &ew->win_height);
602 gtk_widget_hide (ew->widgets.window);
603 ew->is_showing = FALSE;
607 void
608 signals_free (Signals * sg)
610 if (sg)
612 signals_clear (sg);
613 gtk_widget_destroy (sg->widgets.window);
614 gtk_widget_destroy (sg->widgets.menu);
615 g_free (sg);