1 /* ierror window
2 */
3
4 /*
5
6 Copyright (C) 1991-2003 The National Gallery
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 along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22 */
23
24 /*
25
26 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
27
28 */
29
30 /*
31 #define DEBUG
32 */
33
34 #include "ip.h"
35
36 static LogClass *parent_class = NULL;
37
38 static void *
ierror_print(Expr * expr,iError * ierror,gboolean * found)39 ierror_print( Expr *expr, iError *ierror, gboolean *found )
40 {
41 char txt[1024];
42 VipsBuf buf = VIPS_BUF_STATIC( txt );
43
44 expr_error_print( expr, &buf );
45 log_text( LOG( ierror ), vips_buf_all( &buf ) );
46 *found = TRUE;
47
48 return( NULL );
49 }
50
51 static void
ierror_show_all(iError * ierror)52 ierror_show_all( iError *ierror )
53 {
54 gboolean found;
55
56 found = FALSE;
57 slist_map2( expr_error_all,
58 (SListMap2Fn) ierror_print, ierror, &found );
59 if( !found ) {
60 log_text( LOG( ierror ), _( "No ierrors found." ) );
61 log_text( LOG( ierror ), "\n" );
62 }
63 }
64
65 static void
ierror_show_all_action_cb(GtkAction * action,iError * ierror)66 ierror_show_all_action_cb( GtkAction *action, iError *ierror )
67 {
68 ierror_show_all( ierror );
69 }
70
71 static void *
unresolved_print_tool(Tool * tool,iError * ierror,gboolean * found)72 unresolved_print_tool( Tool *tool, iError *ierror, gboolean *found )
73 {
74 char txt[MAX_STRSIZE];
75 VipsBuf buf = VIPS_BUF_STATIC( txt );
76
77 tool_linkreport_tool( tool, &buf, found );
78 log_text( LOG( ierror ), vips_buf_all( &buf ) );
79
80 return( NULL );
81 }
82
83 static void *
unresolved_print(Toolkit * kit,iError * ierror,gboolean * found)84 unresolved_print( Toolkit *kit, iError *ierror, gboolean *found )
85 {
86 toolkit_map( kit, (tool_map_fn) unresolved_print_tool, ierror, found );
87
88 return( NULL );
89 }
90
91 static void
unresolved_show_all(iError * ierror)92 unresolved_show_all( iError *ierror )
93 {
94 gboolean found;
95
96 found = FALSE;
97 (void) toolkitgroup_map( ierror->kitg,
98 (toolkit_map_fn) unresolved_print, ierror, &found );
99 if( !found ) {
100 log_text( LOG( ierror ), _( "No unresolved symbols found." ) );
101 log_text( LOG( ierror ), "\n" );
102 }
103 }
104
105 static void
unresolved_show_all_action_cb(GtkAction * action,iError * ierror)106 unresolved_show_all_action_cb( GtkAction *action, iError *ierror )
107 {
108 unresolved_show_all( ierror );
109 }
110
111 /* Our actions.
112 */
113 static GtkActionEntry ierror_actions[] = {
114 { "Clear",
115 NULL, N_( "_Clear" ), NULL,
116 N_( "Clear ierror window" ),
117 G_CALLBACK( log_clear_action_cb ) },
118
119 { "iErrors",
120 NULL, N_( "List _iErrors" ), NULL,
121 N_( "Search for all ierrors" ),
122 G_CALLBACK( ierror_show_all_action_cb ) },
123
124 { "Unresolved",
125 NULL, N_( "List _Unresolved" ), NULL,
126 N_( "Search for all unresolved references" ),
127 G_CALLBACK( unresolved_show_all_action_cb ) }
128 };
129
130 static const char *ierror_menubar_ui_description =
131 "<ui>"
132 " <menubar name='iErrorMenubar'>"
133 " <menu action='FileMenu'>"
134 " <menuitem action='Clear'/>"
135 " <separator/>"
136 " <menuitem action='Close'/>"
137 " <menuitem action='Quit'/>"
138 " </menu>"
139 " <menu action='ViewMenu'>"
140 " <menuitem action='iErrors'/>"
141 " <menuitem action='Unresolved'/>"
142 " </menu>"
143 " <menu action='HelpMenu'>"
144 " <menuitem action='Guide'/>"
145 " <menuitem action='About'/>"
146 " <separator/>"
147 " <menuitem action='Homepage'/>"
148 " </menu>"
149 " </menubar>"
150 "</ui>";
151
152 static void
ierror_class_init(iErrorClass * class)153 ierror_class_init( iErrorClass *class )
154 {
155 LogClass *log_class = (LogClass *) class;
156
157 parent_class = g_type_class_peek_parent( class );
158
159 log_class->actions = ierror_actions;
160 log_class->n_actions = IM_NUMBER( ierror_actions );
161 log_class->action_name = "iErrorActions";
162 log_class->ui_description = ierror_menubar_ui_description;
163 log_class->menu_bar_name = "/iErrorMenubar";
164 }
165
166 static void
ierror_init(iError * ierror)167 ierror_init( iError *ierror )
168 {
169 }
170
171 GtkType
ierror_get_type(void)172 ierror_get_type( void )
173 {
174 static GtkType type = 0;
175
176 if( !type ) {
177 static const GtkTypeInfo info = {
178 "iError",
179 sizeof( iError ),
180 sizeof( iErrorClass ),
181 (GtkClassInitFunc) ierror_class_init,
182 (GtkObjectInitFunc) ierror_init,
183 /* reserved_1 */ NULL,
184 /* reserved_2 */ NULL,
185 (GtkClassInitFunc) NULL,
186 };
187
188 type = gtk_type_unique( TYPE_LOG, &info );
189 }
190
191 return( type );
192 }
193
194 static void
ierror_link(iError * ierror,Toolkitgroup * kitg)195 ierror_link( iError *ierror, Toolkitgroup *kitg )
196 {
197 ierror->kitg = kitg;
198
199 destroy_if_destroyed( G_OBJECT( ierror ),
200 G_OBJECT( kitg ), (DestroyFn) gtk_widget_destroy );
201 iwindow_set_title( IWINDOW( ierror ),
202 _( "iError - %s" ), IOBJECT( kitg )->name );
203 gtk_window_set_default_size( GTK_WINDOW( ierror ), 640, 480 );
204 iwindow_set_size_prefs( IWINDOW( ierror ),
205 "IERROR_WIDTH", "IERROR_HEIGHT" );
206 iwindow_build( IWINDOW( ierror ) );
207 }
208
209 iError *
ierror_new(Toolkitgroup * kitg)210 ierror_new( Toolkitgroup *kitg )
211 {
212 iError *ierror = gtk_type_new( TYPE_IERROR );
213
214 ierror_link( ierror, kitg );
215 ierror_show_all( ierror );
216 unresolved_show_all( ierror );
217
218 return( ierror );
219 }
220