1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright 2003 Ximian, Inc. (www.ximian.com)
6 * Copyright (C) Massimo Cora' 2005 <maxcvs@gmail.com>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
36 #include "vgtoolview.h"
39 static void vg_tool_view_class_init (VgToolViewClass
*klass
);
40 static void vg_tool_view_init (VgToolView
*view
);
41 static void vg_tool_view_destroy (GtkObject
*obj
);
42 static void vg_tool_view_finalize (GObject
*obj
);
44 static void tool_view_clear (VgToolView
*view
);
45 static void tool_view_reset (VgToolView
*view
);
46 static void tool_view_connect (VgToolView
*view
, int sockfd
);
47 static int tool_view_step (VgToolView
*view
);
48 static void tool_view_disconnect (VgToolView
*view
);
49 static int tool_view_save_log (VgToolView
*view
, gchar
* uri
);
50 static int tool_view_load_log (VgToolView
*view
, VgActions
*actions
, gchar
* uri
);
51 static void tool_view_cut (VgToolView
*view
);
52 static void tool_view_copy (VgToolView
*view
);
53 static void tool_view_paste (VgToolView
*view
);
54 static void tool_view_show_rules (VgToolView
*view
);
57 static GtkVBoxClass
*parent_class
= NULL
;
60 destroy_array_and_content (GPtrArray
**array
)
62 g_return_if_fail (array
!= NULL
);
65 g_ptr_array_foreach (*array
, (GFunc
)g_free
, NULL
);
66 g_ptr_array_free (*array
, TRUE
);
72 allocate_array_and_content (GPtrArray
**array
, va_list va_args
)
76 g_return_if_fail (array
!= NULL
);
77 g_return_if_fail (*array
== NULL
);
79 *array
= g_ptr_array_new ();
80 for (item
= va_arg (va_args
, gchar
*); item
; item
= va_arg (va_args
, gchar
*))
81 g_ptr_array_add (*array
, g_strdup (item
));
86 vg_tool_view_get_type (void)
88 static GType type
= 0;
91 static const GTypeInfo info
= {
92 sizeof (VgToolViewClass
),
93 NULL
, /* base_class_init */
94 NULL
, /* base_class_finalize */
95 (GClassInitFunc
) vg_tool_view_class_init
,
96 NULL
, /* class_finalize */
97 NULL
, /* class_data */
100 (GInstanceInitFunc
) vg_tool_view_init
,
103 type
= g_type_register_static (GTK_TYPE_VBOX
, "VgToolView", &info
, 0);
110 vg_tool_view_class_init (VgToolViewClass
*klass
)
112 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
113 GtkObjectClass
*gtk_object_class
= GTK_OBJECT_CLASS (klass
);
115 parent_class
= g_type_class_ref (GTK_TYPE_VBOX
);
117 object_class
->finalize
= vg_tool_view_finalize
;
118 gtk_object_class
->destroy
= vg_tool_view_destroy
;
120 /* virtual methods */
121 klass
->clear
= tool_view_clear
;
122 klass
->reset
= tool_view_reset
;
123 klass
->connect
= tool_view_connect
;
124 klass
->step
= tool_view_step
;
125 klass
->disconnect
= tool_view_disconnect
;
126 klass
->save_log
= tool_view_save_log
;
127 klass
->load_log
= tool_view_load_log
;
128 klass
->cut
= tool_view_cut
;
129 klass
->copy
= tool_view_copy
;
130 klass
->paste
= tool_view_paste
;
131 klass
->show_rules
= tool_view_show_rules
;
135 vg_tool_view_init (VgToolView
*view
)
142 view
->argv_array
= NULL
;
143 view
->srcdir_array
= NULL
;
147 vg_tool_view_finalize (GObject
*obj
)
149 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
153 vg_tool_view_destroy (GtkObject
*obj
)
155 VgToolView
*view
= VG_TOOL_VIEW (obj
);
156 destroy_array_and_content (&view
->srcdir_array
);
157 destroy_array_and_content (&view
->argv_array
);
159 GTK_OBJECT_CLASS (parent_class
)->destroy (obj
);
164 vg_tool_view_set_argv (VgToolView
*view
, char *arg0
, ...)
167 g_return_if_fail (VG_IS_TOOL_VIEW (view
));
168 destroy_array_and_content (&view
->argv_array
);
170 va_start (va_args
, arg0
);
171 allocate_array_and_content (&view
->argv_array
, va_args
);
174 view
->argv
= (const char**)view
->argv_array
->pdata
;
178 vg_tool_view_set_srcdir (VgToolView
*view
, char *srcdir0
, ...)
181 g_return_if_fail (VG_IS_TOOL_VIEW (view
));
182 destroy_array_and_content (&view
->srcdir_array
);
184 va_start (va_args
, srcdir0
);
185 allocate_array_and_content (&view
->srcdir_array
, va_args
);
188 view
->srcdir
= (const char**)view
->srcdir_array
->pdata
;
193 vg_tool_view_set_symtab (VgToolView
*view
, SymTab
*symtab
)
195 g_return_if_fail (VG_IS_TOOL_VIEW (view
));
197 view
->symtab
= symtab
;
202 tool_view_clear (VgToolView
*view
)
209 vg_tool_view_clear (VgToolView
*view
)
211 g_return_if_fail (VG_IS_TOOL_VIEW (view
));
213 VG_TOOL_VIEW_GET_CLASS (view
)->clear (view
);
218 tool_view_reset (VgToolView
*view
)
225 vg_tool_view_reset (VgToolView
*view
)
227 g_return_if_fail (VG_IS_TOOL_VIEW (view
));
229 VG_TOOL_VIEW_GET_CLASS (view
)->reset (view
);
234 tool_view_connect (VgToolView
*view
, int sockfd
)
241 vg_tool_view_connect (VgToolView
*view
, int sockfd
)
243 g_return_if_fail (VG_IS_TOOL_VIEW (view
));
245 VG_TOOL_VIEW_GET_CLASS (view
)->connect (view
, sockfd
);
250 tool_view_step (VgToolView
*view
)
257 vg_tool_view_step (VgToolView
*view
)
259 g_return_val_if_fail (VG_IS_TOOL_VIEW (view
), -1);
261 return VG_TOOL_VIEW_GET_CLASS (view
)->step (view
);
266 tool_view_disconnect (VgToolView
*view
)
273 vg_tool_view_disconnect (VgToolView
*view
)
275 g_return_if_fail (VG_IS_TOOL_VIEW (view
));
277 VG_TOOL_VIEW_GET_CLASS (view
)->disconnect (view
);
282 tool_view_save_log (VgToolView
*view
, gchar
* uri
)
290 vg_tool_view_save_log (VgToolView
*view
, gchar
*uri
)
292 g_return_val_if_fail (VG_IS_TOOL_VIEW (view
), -1);
294 return VG_TOOL_VIEW_GET_CLASS (view
)->save_log (view
, uri
);
299 tool_view_load_log (VgToolView
*view
, VgActions
*actions
, gchar
* uri
)
307 vg_tool_view_load_log (VgToolView
*view
, VgActions
*actions
, gchar
*uri
)
309 g_return_val_if_fail (VG_IS_TOOL_VIEW (view
), -1);
311 return VG_TOOL_VIEW_GET_CLASS (view
)->load_log (view
, actions
, uri
);
316 tool_view_cut (VgToolView
*view
)
323 vg_tool_view_cut (VgToolView
*view
)
325 g_return_if_fail (VG_IS_TOOL_VIEW (view
));
327 VG_TOOL_VIEW_GET_CLASS (view
)->cut (view
);
332 tool_view_copy (VgToolView
*view
)
339 vg_tool_view_copy (VgToolView
*view
)
341 g_return_if_fail (VG_IS_TOOL_VIEW (view
));
343 VG_TOOL_VIEW_GET_CLASS (view
)->copy (view
);
348 tool_view_paste (VgToolView
*view
)
355 vg_tool_view_paste (VgToolView
*view
)
357 g_return_if_fail (VG_IS_TOOL_VIEW (view
));
359 VG_TOOL_VIEW_GET_CLASS (view
)->paste (view
);
364 tool_view_show_rules (VgToolView
*view
)
366 if (view
->rules
== NULL
)
369 if (GTK_WIDGET_MAPPED (view
->rules
))
370 gdk_window_raise (view
->rules
->window
);
372 gtk_widget_show (view
->rules
);
377 vg_tool_view_show_rules (VgToolView
*view
)
379 g_return_if_fail (VG_IS_TOOL_VIEW (view
));
381 VG_TOOL_VIEW_GET_CLASS (view
)->show_rules (view
);
387 path_concat (const char *dirname
, int dirlen
, const char *basename
, int baselen
)
391 p
= path
= g_malloc (dirlen
+ baselen
+ 2);
392 memcpy (path
, dirname
, dirlen
);
395 memcpy (p
, basename
, baselen
);
402 path_is_rx (const char *path
)
406 if (stat (path
, &st
) != -1 && S_ISREG (st
.st_mode
)) {
407 if (access (path
, R_OK
| X_OK
) != -1)
416 vg_tool_view_scan_path (const char *program
)
418 const char *pathenv
, *path
, *p
;
422 if (program
[0] == '/') {
423 if (path_is_rx (program
))
424 return g_strdup (program
);
429 if (!(pathenv
= getenv ("PATH")))
433 len
= strlen (program
);
434 while ((p
= strchr (path
, ':'))) {
436 filename
= path_concat (path
, (p
- path
), program
, len
);
437 if (path_is_rx (filename
))
446 if (path
[0] != '\0') {
447 filename
= g_strdup_printf ("%s/%s", path
, program
);
448 if (path_is_rx (filename
))