Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
messages.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
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 v2+, read the file 'COPYING' for more information.
13 */
14
15#include "messages.h"
16
17#include "ui/pack.h"
18
19namespace Inkscape::UI::Widget {
20
21//#########################################################################
22//## E V E N T S
23//#########################################################################
24
29{
30 Glib::RefPtr<Gtk::TextBuffer> buffer = messageText.get_buffer();
31 buffer->erase(buffer->begin(), buffer->end());
32}
33
34//#########################################################################
35//## C O N S T R U C T O R / D E S T R U C T O R
36//#########################################################################
41 : Box(Gtk::Orientation::VERTICAL)
42 , buttonClear(_("_Clear"), _("Clear log messages"))
43 , checkCapture(_("Capture log messages"), _("Capture log messages"))
44 , buttonBox(Gtk::Orientation::HORIZONTAL)
45{
46 messageText.set_editable(false);
47 messageText.set_size_request(400, -1);
48 textScroll.set_child(messageText);
49 textScroll.set_policy(Gtk::PolicyType::ALWAYS, Gtk::PolicyType::ALWAYS);
51
52 buttonBox.set_spacing(6);
53 buttonBox.set_margin(4);
55 UI::pack_end(buttonBox, buttonClear, false, false);
57
58 message(_("Ready."));
59
60 buttonClear.signal_clicked().connect(sigc::mem_fun(*this, &Messages::clear));
61 checkCapture.signal_toggled().connect(sigc::mem_fun(*this, &Messages::toggleCapture));
62}
63
64//#########################################################################
65//## M E T H O D S
66//#########################################################################
67
68void Messages::message(char const *msg)
69{
70 Glib::RefPtr<Gtk::TextBuffer> buffer = messageText.get_buffer();
71 Glib::ustring uMsg = msg;
72 if (uMsg[uMsg.length() - 1] != '\n') {
73 uMsg += '\n';
74 }
75 buffer->insert(buffer->end(), uMsg);
76}
77
78// dialogLoggingCallback is already used in debug.cpp
79static void dialogLoggingCallback(char const */*log_domain*/,
80 GLogLevelFlags /*log_level*/,
81 char const *messageText,
82 gpointer user_data)
83{
84 Messages *dlg = static_cast<Messages *>(user_data);
85 dlg->message(messageText);
86}
87
89{
90 if (checkCapture.get_active()) {
92 } else {
94 }
95}
96
98{
99 /*
100 This might likely need more code, to capture Gtkmm
101 and Glibmm warnings, or maybe just simply grab stdout/stderr
102 */
103 GLogLevelFlags flags = (GLogLevelFlags) (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL |
104 G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE |
105 G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG);
106 if (!handlerDefault) {
107 handlerDefault = g_log_set_handler(nullptr, flags, dialogLoggingCallback, (gpointer)this);
108 }
109 if (!handlerGlibmm) {
110 handlerGlibmm = g_log_set_handler("glibmm", flags, dialogLoggingCallback, (gpointer)this);
111 }
112 if (!handlerAtkmm) {
113 handlerAtkmm = g_log_set_handler("atkmm", flags, dialogLoggingCallback, (gpointer)this);
114 }
115 if (!handlerPangomm) {
116 handlerPangomm = g_log_set_handler("pangomm", flags, dialogLoggingCallback, (gpointer)this);
117 }
118 if (!handlerGdkmm) {
119 handlerGdkmm = g_log_set_handler("gdkmm", flags, dialogLoggingCallback, (gpointer)this);
120 }
121 if (!handlerGtkmm) {
122 handlerGtkmm = g_log_set_handler("gtkmm", flags, dialogLoggingCallback, (gpointer)this);
123 }
124 message(_("Log capture started."));
125}
126
128{
129 if (handlerDefault) {
130 g_log_remove_handler(nullptr, handlerDefault);
131 handlerDefault = 0;
132 }
133 if (handlerGlibmm) {
134 g_log_remove_handler("glibmm", handlerGlibmm);
135 handlerGlibmm = 0;
136 }
137 if (handlerAtkmm) {
138 g_log_remove_handler("atkmm", handlerAtkmm);
139 handlerAtkmm = 0;
140 }
141 if (handlerPangomm) {
142 g_log_remove_handler("pangomm", handlerPangomm);
143 handlerPangomm = 0;
144 }
145 if (handlerGdkmm) {
146 g_log_remove_handler("gdkmm", handlerGdkmm);
147 handlerGdkmm = 0;
148 }
149 if (handlerGtkmm) {
150 g_log_remove_handler("gtkmm", handlerGtkmm);
151 handlerGtkmm = 0;
152 }
153 message(_("Log capture stopped."));
154}
155
156} // namespace Inkscape::UI::Widget
157
158/*
159 Local Variables:
160 mode:c++
161 c-file-style:"stroustrup"
162 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
163 indent-tabs-mode:nil
164 fill-column:99
165 End:
166*/
167// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
void message(char const *msg)
Display a message.
Definition messages.cpp:68
void captureLogMessages()
Redirect g_log() messages to this widget.
Definition messages.cpp:97
Gtk::ScrolledWindow textScroll
Definition messages.h:57
void clear()
Clear all information from the dialog.
Definition messages.cpp:28
void releaseLogMessages()
Return g_log() messages to normal handling.
Definition messages.cpp:127
Gtk::CheckButton checkCapture
Definition messages.h:61
Glib::ustring msg
Messages dialog.
Definition desktop.h:50
Custom widgets.
Definition desktop.h:126
static void dialogLoggingCallback(char const *, GLogLevelFlags, char const *messageText, gpointer user_data)
Definition messages.cpp:79
void pack_end(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the end of box.
Definition pack.cpp:153
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
Definition pack.cpp:141
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.