Code

moving trunk for module inkscape
[inkscape.git] / src / ui / dialog / messages.cpp
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         : Dialog ("dialogs.messages", SP_VERB_DIALOG_DEBUG)
50 {
51     Gtk::VBox *mainVBox = get_vbox();
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     mainVBox->pack_start(menuBar, Gtk::PACK_SHRINK);
62     
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     mainVBox->pack_start(textScroll);
70     show_all_children();
72     message(_("Ready."));
73     message(_("Enable log display by setting dialogs.debug 'redirect' attribute to 1 in preferences.xml"));
75     handlerDefault = 0;
76     handlerGlibmm  = 0;
77     handlerAtkmm   = 0;
78     handlerPangomm = 0;
79     handlerGdkmm   = 0;
80     handlerGtkmm   = 0;
81 }
83 Messages::~Messages()
84 {
85 }
88 //#########################################################################
89 //## M E T H O D S
90 //#########################################################################
92 void Messages::message(char *msg)
93 {
94     Glib::RefPtr<Gtk::TextBuffer> buffer = messageText.get_buffer();
95     Glib::ustring uMsg = msg;
96     if (uMsg[uMsg.length()-1] != '\n')
97         uMsg += '\n';
98     buffer->insert (buffer->end(), uMsg);
99 }
102 void dialogLoggingFunction(const gchar *log_domain,
103                            GLogLevelFlags log_level,
104                            const gchar *messageText,
105                            gpointer user_data)
107     Messages *dlg = (Messages *)user_data;
109     dlg->message((char *)messageText);
114 void Messages::captureLogMessages()
116     /*
117     This might likely need more code, to capture Gtkmm
118     and Glibmm warnings, or maybe just simply grab stdout/stderr
119     */
120    GLogLevelFlags flags = (GLogLevelFlags) (G_LOG_LEVEL_ERROR   | G_LOG_LEVEL_CRITICAL |
121                              G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE  |
122                              G_LOG_LEVEL_INFO    | G_LOG_LEVEL_DEBUG);
123     if ( !handlerDefault ) {
124         handlerDefault = g_log_set_handler(NULL, flags,
125               dialogLoggingFunction, (gpointer)this);
126     }
127     if ( !handlerGlibmm ) {
128         handlerGlibmm = g_log_set_handler("glibmm", flags,
129               dialogLoggingFunction, (gpointer)this);
130     }
131     if ( !handlerAtkmm ) {
132         handlerAtkmm = g_log_set_handler("atkmm", flags,
133               dialogLoggingFunction, (gpointer)this);
134     }
135     if ( !handlerPangomm ) {
136         handlerPangomm = g_log_set_handler("pangomm", flags,
137               dialogLoggingFunction, (gpointer)this);
138     }
139     if ( !handlerGdkmm ) {
140         handlerGdkmm = g_log_set_handler("gdkmm", flags,
141               dialogLoggingFunction, (gpointer)this);
142     }
143     if ( !handlerGtkmm ) {
144         handlerGtkmm = g_log_set_handler("gtkmm", flags,
145               dialogLoggingFunction, (gpointer)this);
146     }
147     message("log capture started");
150 void Messages::releaseLogMessages()
152     if ( handlerDefault ) {
153         g_log_remove_handler(NULL, handlerDefault);
154         handlerDefault = 0;
155     }
156     if ( handlerGlibmm ) {
157         g_log_remove_handler("glibmm", handlerGlibmm);
158         handlerGlibmm = 0;
159     }
160     if ( handlerAtkmm ) {
161         g_log_remove_handler("atkmm", handlerAtkmm);
162         handlerAtkmm = 0;
163     }
164     if ( handlerPangomm ) {
165         g_log_remove_handler("pangomm", handlerPangomm);
166         handlerPangomm = 0;
167     }
168     if ( handlerGdkmm ) {
169         g_log_remove_handler("gdkmm", handlerGdkmm);
170         handlerGdkmm = 0;
171     }
172     if ( handlerGtkmm ) {
173         g_log_remove_handler("gtkmm", handlerGtkmm);
174         handlerGtkmm = 0;
175     }
176     message("log capture discontinued");
179 } //namespace Dialog
180 } //namespace UI
181 } //namespace Inkscape
183 //#########################################################################
184 //## E N D    O F    F I L E
185 //#########################################################################