1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
/*
* A very simple dialog for displaying Inkscape messages. Messages
* sent to g_log(), g_warning(), g_message(), ets, are routed here,
* in order to avoid messing with the startup console.
*
* Authors:
* Bob Jamison
* Other dudes from The Inkscape Organization
*
* Copyright (C) 2004 The Inkscape Organization
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <glibmm/i18n.h>
#include <gtkmm/box.h>
#include <gtkmm/dialog.h>
#include <gtkmm/textview.h>
#include <gtkmm/button.h>
#include <gtkmm/menubar.h>
#include <gtkmm/scrolledwindow.h>
#include "debugdialog.h"
namespace Inkscape {
namespace UI {
namespace Dialogs {
//#########################################################################
//## I M P L E M E N T A T I O N
//#########################################################################
/**
* A dialog that displays log messages
*/
class DebugDialogImpl : public DebugDialog, public Gtk::Dialog
{
public:
/**
* Constructor
*/
DebugDialogImpl();
/**
* Destructor
*/
~DebugDialogImpl();
/**
* Show the dialog
*/
void show();
/**
* Do not show the dialog
*/
void hide();
/**
* Clear all information from the dialog
*/
void clear();
/**
* Display a message
*/
void message(char const *msg);
/**
* Redirect g_log() messages to this widget
*/
void captureLogMessages();
/**
* Return g_log() messages to normal handling
*/
void releaseLogMessages();
private:
Gtk::MenuBar menuBar;
Gtk::Menu fileMenu;
Gtk::ScrolledWindow textScroll;
Gtk::TextView messageText;
//Handler ID's
guint handlerDefault;
guint handlerGlibmm;
guint handlerAtkmm;
guint handlerPangomm;
guint handlerGdkmm;
guint handlerGtkmm;
};
//#########################################################################
//## E V E N T S
//#########################################################################
/**
* Also a public method. Remove all text from the dialog
*/
void DebugDialogImpl::clear()
{
Glib::RefPtr<Gtk::TextBuffer> buffer = messageText.get_buffer();
buffer->erase(buffer->begin(), buffer->end());
}
//#########################################################################
//## C O N S T R U C T O R / D E S T R U C T O R
//#########################################################################
/**
* Constructor
*/
DebugDialogImpl::DebugDialogImpl()
{
set_title(_("Messages"));
set_size_request(300, 400);
Gtk::VBox *mainVBox = get_vbox();
//## Add a menu for clear()
menuBar.items().push_back( Gtk::Menu_Helpers::MenuElem(_("_File"), fileMenu) );
fileMenu.items().push_back( Gtk::Menu_Helpers::MenuElem(_("_Clear"),
sigc::mem_fun(*this, &DebugDialogImpl::clear) ) );
fileMenu.items().push_back( Gtk::Menu_Helpers::MenuElem(_("Capture log messages"),
sigc::mem_fun(*this, &DebugDialogImpl::captureLogMessages) ) );
fileMenu.items().push_back( Gtk::Menu_Helpers::MenuElem(_("Release log messages"),
sigc::mem_fun(*this, &DebugDialogImpl::releaseLogMessages) ) );
mainVBox->pack_start(menuBar, Gtk::PACK_SHRINK);
//### Set up the text widget
messageText.set_editable(false);
textScroll.add(messageText);
textScroll.set_policy(Gtk::POLICY_ALWAYS, Gtk::POLICY_ALWAYS);
mainVBox->pack_start(textScroll);
show_all_children();
message("ready.");
message("enable log display by setting ");
message("dialogs.debug 'redirect' attribute to 1 in preferences.xml");
handlerDefault = 0;
handlerGlibmm = 0;
handlerAtkmm = 0;
handlerPangomm = 0;
handlerGdkmm = 0;
handlerGtkmm = 0;
}
/**
* Factory method. Use this to create a new DebugDialog
*/
DebugDialog *DebugDialog::create()
{
DebugDialog *dialog = new DebugDialogImpl();
return dialog;
}
/**
* Constructor
*/
DebugDialogImpl::~DebugDialogImpl()
{
}
//#########################################################################
//## M E T H O D S
//#########################################################################
void DebugDialogImpl::show()
{
//call super()
Gtk::Dialog::show();
//sp_transientize((GtkWidget *)gobj()); //Make transient
raise();
Gtk::Dialog::present();
}
void DebugDialogImpl::hide()
{
//call super()
Gtk::Dialog::hide();
}
void DebugDialogImpl::message(char const *msg)
{
Glib::RefPtr<Gtk::TextBuffer> buffer = messageText.get_buffer();
Glib::ustring uMsg = msg;
if (uMsg[uMsg.length()-1] != '\n')
uMsg += '\n';
buffer->insert (buffer->end(), uMsg);
}
/* static instance, to reduce dependencies */
static DebugDialog *debugDialogInstance = NULL;
DebugDialog *DebugDialog::getInstance()
{
if ( !debugDialogInstance )
{
debugDialogInstance = new DebugDialogImpl();
}
return debugDialogInstance;
}
void DebugDialog::showInstance()
{
DebugDialog *debugDialog = getInstance();
debugDialog->show();
}
/*##### THIS IS THE IMPORTANT PART ##### */
void dialogLoggingFunction(const gchar */*log_domain*/,
GLogLevelFlags /*log_level*/,
const gchar *messageText,
gpointer user_data)
{
DebugDialogImpl *dlg = (DebugDialogImpl *)user_data;
dlg->message(messageText);
}
void DebugDialogImpl::captureLogMessages()
{
/*
This might likely need more code, to capture Gtkmm
and Glibmm warnings, or maybe just simply grab stdout/stderr
*/
GLogLevelFlags flags = (GLogLevelFlags) (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL |
G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE |
G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG);
if ( !handlerDefault )
{
handlerDefault = g_log_set_handler(NULL, flags,
dialogLoggingFunction, (gpointer)this);
}
if ( !handlerGlibmm )
{
handlerGlibmm = g_log_set_handler("glibmm", flags,
dialogLoggingFunction, (gpointer)this);
}
if ( !handlerAtkmm )
{
handlerAtkmm = g_log_set_handler("atkmm", flags,
dialogLoggingFunction, (gpointer)this);
}
if ( !handlerPangomm )
{
handlerPangomm = g_log_set_handler("pangomm", flags,
dialogLoggingFunction, (gpointer)this);
}
if ( !handlerGdkmm )
{
handlerGdkmm = g_log_set_handler("gdkmm", flags,
dialogLoggingFunction, (gpointer)this);
}
if ( !handlerGtkmm )
{
handlerGtkmm = g_log_set_handler("gtkmm", flags,
dialogLoggingFunction, (gpointer)this);
}
message("log capture started");
}
void DebugDialogImpl::releaseLogMessages()
{
if ( handlerDefault )
{
g_log_remove_handler(NULL, handlerDefault);
handlerDefault = 0;
}
if ( handlerGlibmm )
{
g_log_remove_handler("glibmm", handlerGlibmm);
handlerGlibmm = 0;
}
if ( handlerAtkmm )
{
g_log_remove_handler("atkmm", handlerAtkmm);
handlerAtkmm = 0;
}
if ( handlerPangomm )
{
g_log_remove_handler("pangomm", handlerPangomm);
handlerPangomm = 0;
}
if ( handlerGdkmm )
{
g_log_remove_handler("gdkmm", handlerGdkmm);
handlerGdkmm = 0;
}
if ( handlerGtkmm )
{
g_log_remove_handler("gtkmm", handlerGtkmm);
handlerGtkmm = 0;
}
message("log capture discontinued");
}
} //namespace Dialogs
} //namespace UI
} //namespace Inkscape
//#########################################################################
//## E N D O F F I L E
//#########################################################################
|