1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) Naba Kumar <naba@gnome.org>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sys/types.h>
33 #include <libanjuta/resources.h>
34 #include <libgnome/gnome-i18n.h>
36 #include "utilities.h"
40 create_dialog_with_textview (GtkWindow
*parent
, gint width
, gint height
)
44 GtkWidget
*scrolledwindow
;
52 dialog
= gtk_dialog_new_with_buttons (_("Information"), parent
,
53 GTK_DIALOG_DESTROY_WITH_PARENT
,
54 GTK_STOCK_CLOSE
, GTK_RESPONSE_NONE
,
56 gtk_window_set_policy (GTK_WINDOW (dialog
), FALSE
, TRUE
, FALSE
);
57 gtk_window_set_default_size (GTK_WINDOW (dialog
), 400, 250);
58 gtk_window_set_wmclass (GTK_WINDOW (dialog
), "infoless", "Anjuta");
59 gtk_widget_show (dialog
);
61 g_signal_connect (G_OBJECT (dialog
), "response",
62 G_CALLBACK (gtk_widget_destroy
), NULL
);
64 scrolledwindow
= gtk_scrolled_window_new (NULL
, NULL
);
65 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog
)->vbox
),
67 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow
),
69 GTK_POLICY_AUTOMATIC
);
70 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow
),
72 gtk_widget_show (scrolledwindow
);
74 textview
= gtk_text_view_new ();
75 gtk_text_view_set_editable (GTK_TEXT_VIEW (textview
), FALSE
);
76 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview
), GTK_WRAP_WORD
);
77 gtk_container_add (GTK_CONTAINER (scrolledwindow
), textview
);
78 gtk_widget_show (textview
);
80 gtk_widget_show (dialog
);
86 create_dialog_with_treeview (GtkWindow
*parent
, gint width
, gint height
)
89 GtkWidget
*scrolledwindow
;
91 GtkCellRenderer
*renderer
;
92 GtkTreeViewColumn
*column
;
101 dialog
= gtk_dialog_new_with_buttons (_("Information"), parent
,
102 GTK_DIALOG_DESTROY_WITH_PARENT
,
103 GTK_STOCK_CLOSE
, GTK_RESPONSE_NONE
,
105 gtk_window_set_policy (GTK_WINDOW (dialog
), FALSE
, TRUE
, FALSE
);
106 gtk_window_set_default_size (GTK_WINDOW (dialog
), 400, 250);
107 gtk_window_set_wmclass (GTK_WINDOW (dialog
), "infoless", "Anjuta");
108 gtk_widget_show (dialog
);
110 g_signal_connect (G_OBJECT (dialog
), "response",
111 G_CALLBACK (gtk_widget_destroy
), NULL
);
113 scrolledwindow
= gtk_scrolled_window_new (NULL
, NULL
);
114 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog
)->vbox
),
116 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow
),
117 GTK_POLICY_AUTOMATIC
,
118 GTK_POLICY_AUTOMATIC
);
119 gtk_widget_show (scrolledwindow
);
120 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow
),
123 model
= GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING
));
125 treeview
= gtk_tree_view_new_with_model (model
);
126 renderer
= gtk_cell_renderer_text_new ();
127 column
= gtk_tree_view_column_new_with_attributes (_("Lines"), renderer
,
129 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview
), column
);
130 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(treeview
), FALSE
);
131 gtk_container_add (GTK_CONTAINER (scrolledwindow
), treeview
);
132 gtk_widget_show (treeview
);
133 g_object_unref (G_OBJECT (model
));
139 gdb_info_show_file (GtkWindow
*parent
, const gchar
*path
,
140 gint width
, gint height
)
144 g_return_val_if_fail (path
!= NULL
, FALSE
);
146 if (!g_file_test (path
, G_FILE_TEST_EXISTS
| G_FILE_TEST_IS_DIR
))
149 if ((f
= fopen (path
, "r")) == NULL
)
152 if (!gdb_info_show_filestream (parent
, f
, width
, height
))
154 int errno_bak
= errno
;
163 return (fclose (f
) != 0) ? FALSE
: TRUE
;
167 gdb_info_show_command (GtkWindow
*parent
, const gchar
*command_line
,
168 gint width
, gint height
)
171 gchar
*std_output
= NULL
;
174 g_return_val_if_fail (command_line
!= NULL
, FALSE
);
176 /* Note: we could use popen like gdb_info_show_file,
177 * but g_spawn is safier
179 if (!g_spawn_command_line_sync (command_line
, &std_output
,
182 g_warning (err
->message
);
188 if (!g_utf8_validate (std_output
, strlen (std_output
), NULL
))
189 g_warning ("Invalid UTF-8 data encountered reading output of command '%s'",
192 ret
= gdb_info_show_string (parent
, std_output
, width
, height
);
200 gdb_info_show_string (GtkWindow
*parent
, const gchar
*s
,
201 gint width
, gint height
)
204 GtkTextBuffer
*buffer
;
206 g_return_val_if_fail (s
!= NULL
, FALSE
);
208 textview
= create_dialog_with_textview (parent
,
210 buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview
));
211 gtk_text_buffer_set_text (buffer
, s
, strlen (s
));
216 #define ANJUTA_INFO_TEXTVIEW_BUFSIZE 1024
219 gdb_info_show_filestream (GtkWindow
*parent
, FILE *f
,
220 gint width
, gint height
)
223 GtkTextBuffer
*buffer
;
224 gchar buf
[ANJUTA_INFO_TEXTVIEW_BUFSIZE
];
226 g_return_val_if_fail (f
!= NULL
, FALSE
);
228 textview
= create_dialog_with_textview (parent
, width
, height
);
229 buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview
));
231 errno
= 0; /* Reset it to detect errors */
237 if ((s
= fgets (buf
, ANJUTA_INFO_TEXTVIEW_BUFSIZE
, f
)) == NULL
)
240 gtk_text_buffer_get_end_iter (buffer
, &iter
);
241 gtk_text_buffer_insert (buffer
, &iter
, buf
, strlen (buf
));
243 return errno
? FALSE
: TRUE
;
247 gdb_info_show_fd (GtkWindow
*parent
, int file_descriptor
,
248 gint width
, gint height
)
252 if ((f
= fdopen (file_descriptor
, "r")) == NULL
)
255 if (!gdb_info_show_filestream (parent
, f
, width
, height
))
257 int errno_bak
= errno
;
266 return (fclose (f
) != 0) ? FALSE
: TRUE
;
270 gdb_info_show_list (GtkWindow
*parent
, const GList
* list
,
271 gint width
, gint height
)
276 g_return_if_fail (list
!= NULL
);
278 treeview
= create_dialog_with_treeview (parent
, width
, height
);
279 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (treeview
));
281 for (; list
; list
= g_list_next (list
))
286 tmp
= gdb_util_remove_white_spaces (list
->data
);
288 gtk_list_store_append (GTK_LIST_STORE (model
), &iter
);
289 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
, 0, tmp
, -1);