1 /*
2 * A very simple dialog for displaying Inkscape messages. Messages
3 * sent to g_log(), g_warning(), g_message(), ets, are routed here,
4 * in order to avoid messing with the startup console.
5 *
6 * Authors:
7 * Bob Jamison
8 * Other dudes from The Inkscape Organization
9 *
10 * Copyright (C) 2004, 2005 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
14 #ifdef HAVE_CONFIG_H
15 # include <config.h>
16 #endif
18 #include "messages.h"
21 #include "verbs.h"
23 namespace Inkscape {
24 namespace UI {
25 namespace Dialog {
28 //#########################################################################
29 //## E V E N T S
30 //#########################################################################
32 /**
33 * Also a public method. Remove all text from the dialog
34 */
35 void Messages::clear()
36 {
37 Glib::RefPtr<Gtk::TextBuffer> buffer = messageText.get_buffer();
38 buffer->erase(buffer->begin(), buffer->end());
39 }
42 //#########################################################################
43 //## C O N S T R U C T O R / D E S T R U C T O R
44 //#########################################################################
45 /**
46 * Constructor
47 */
48 Messages::Messages()
49 : UI::Widget::Panel("", "dialogs.messages", SP_VERB_DIALOG_DEBUG)
50 {
51 Gtk::Box *contents = _getContents();
53 //## Add a menu for clear()
54 menuBar.items().push_back( Gtk::Menu_Helpers::MenuElem(_("_File"), fileMenu) );
55 fileMenu.items().push_back( Gtk::Menu_Helpers::MenuElem(_("_Clear"),
56 sigc::mem_fun(*this, &Messages::clear) ) );
57 fileMenu.items().push_back( Gtk::Menu_Helpers::MenuElem(_("Capture log messages"),
58 sigc::mem_fun(*this, &Messages::captureLogMessages) ) );
59 fileMenu.items().push_back( Gtk::Menu_Helpers::MenuElem(_("Release log messages"),
60 sigc::mem_fun(*this, &Messages::releaseLogMessages) ) );
61 contents->pack_start(menuBar, Gtk::PACK_SHRINK);
64 //### Set up the text widget
65 messageText.set_editable(false);
66 textScroll.add(messageText);
67 textScroll.set_policy(Gtk::POLICY_ALWAYS, Gtk::POLICY_ALWAYS);
68 contents->pack_start(textScroll);
70 // sick of this thing shrinking too much
71 set_size_request(400, 300);
73 show_all_children();
75 message(_("Ready."));
76 message(_("Enable log display by setting dialogs.debug 'redirect' attribute to 1 in preferences.xml"));
78 handlerDefault = 0;
79 handlerGlibmm = 0;
80 handlerAtkmm = 0;
81 handlerPangomm = 0;
82 handlerGdkmm = 0;
83 handlerGtkmm = 0;
84 }
86 Messages::~Messages()
87 {
88 }
91 //#########################################################################
92 //## M E T H O D S
93 //#########################################################################
95 void Messages::message(char *msg)
96 {
97 Glib::RefPtr<Gtk::TextBuffer> buffer = messageText.get_buffer();
98 Glib::ustring uMsg = msg;
99 if (uMsg[uMsg.length()-1] != '\n')
100 uMsg += '\n';
101 buffer->insert (buffer->end(), uMsg);
102 }
105 void dialogLoggingFunction(const gchar */*log_domain*/,
106 GLogLevelFlags /*log_level*/,
107 const gchar *messageText,
108 gpointer user_data)
109 {
110 Messages *dlg = (Messages *)user_data;
112 dlg->message((char *)messageText);
114 }
117 void Messages::captureLogMessages()
118 {
119 /*
120 This might likely need more code, to capture Gtkmm
121 and Glibmm warnings, or maybe just simply grab stdout/stderr
122 */
123 GLogLevelFlags flags = (GLogLevelFlags) (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL |
124 G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE |
125 G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG);
126 if ( !handlerDefault ) {
127 handlerDefault = g_log_set_handler(NULL, flags,
128 dialogLoggingFunction, (gpointer)this);
129 }
130 if ( !handlerGlibmm ) {
131 handlerGlibmm = g_log_set_handler("glibmm", flags,
132 dialogLoggingFunction, (gpointer)this);
133 }
134 if ( !handlerAtkmm ) {
135 handlerAtkmm = g_log_set_handler("atkmm", flags,
136 dialogLoggingFunction, (gpointer)this);
137 }
138 if ( !handlerPangomm ) {
139 handlerPangomm = g_log_set_handler("pangomm", flags,
140 dialogLoggingFunction, (gpointer)this);
141 }
142 if ( !handlerGdkmm ) {
143 handlerGdkmm = g_log_set_handler("gdkmm", flags,
144 dialogLoggingFunction, (gpointer)this);
145 }
146 if ( !handlerGtkmm ) {
147 handlerGtkmm = g_log_set_handler("gtkmm", flags,
148 dialogLoggingFunction, (gpointer)this);
149 }
150 message((char*)"log capture started");
151 }
153 void Messages::releaseLogMessages()
154 {
155 if ( handlerDefault ) {
156 g_log_remove_handler(NULL, handlerDefault);
157 handlerDefault = 0;
158 }
159 if ( handlerGlibmm ) {
160 g_log_remove_handler("glibmm", handlerGlibmm);
161 handlerGlibmm = 0;
162 }
163 if ( handlerAtkmm ) {
164 g_log_remove_handler("atkmm", handlerAtkmm);
165 handlerAtkmm = 0;
166 }
167 if ( handlerPangomm ) {
168 g_log_remove_handler("pangomm", handlerPangomm);
169 handlerPangomm = 0;
170 }
171 if ( handlerGdkmm ) {
172 g_log_remove_handler("gdkmm", handlerGdkmm);
173 handlerGdkmm = 0;
174 }
175 if ( handlerGtkmm ) {
176 g_log_remove_handler("gtkmm", handlerGtkmm);
177 handlerGtkmm = 0;
178 }
179 message((char*)"log capture discontinued");
180 }
182 } //namespace Dialog
183 } //namespace UI
184 } //namespace Inkscape
186 //#########################################################################
187 //## E N D O F F I L E
188 //#########################################################################