summaryrefslogtreecommitdiffstats
path: root/src/gui/MessagesWindow.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-08-01 03:43:23 -0400
committerDavid Robillard <d@drobilla.net>2016-08-01 03:44:00 -0400
commit902703efa9425a0630053c10229de911e23a2a43 (patch)
tree078b44cf205f8f7a3265142ff95b36f08f56fa05 /src/gui/MessagesWindow.cpp
parentff6d8a87f9569a42c7827428f2329280c9b633b9 (diff)
downloadingen-902703efa9425a0630053c10229de911e23a2a43.tar.gz
ingen-902703efa9425a0630053c10229de911e23a2a43.tar.bz2
ingen-902703efa9425a0630053c10229de911e23a2a43.zip
Show colorized log output in messages window
Diffstat (limited to 'src/gui/MessagesWindow.cpp')
-rw-r--r--src/gui/MessagesWindow.cpp93
1 files changed, 88 insertions, 5 deletions
diff --git a/src/gui/MessagesWindow.cpp b/src/gui/MessagesWindow.cpp
index 262cb817..fb29716c 100644
--- a/src/gui/MessagesWindow.cpp
+++ b/src/gui/MessagesWindow.cpp
@@ -1,6 +1,6 @@
/*
This file is part of Ingen.
- Copyright 2007-2015 David Robillard <http://drobilla.net/>
+ Copyright 2007-2016 David Robillard <http://drobilla.net/>
Ingen is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free
@@ -14,9 +14,13 @@
along with Ingen. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "MessagesWindow.hpp"
#include <string>
+#include "ingen/URIs.hpp"
+
+#include "App.hpp"
+#include "MessagesWindow.hpp"
+
namespace Ingen {
namespace GUI {
using std::string;
@@ -31,17 +35,96 @@ MessagesWindow::MessagesWindow(BaseObjectType* cobject,
_clear_button->signal_clicked().connect(sigc::mem_fun(this, &MessagesWindow::clear_clicked));
_close_button->signal_clicked().connect(sigc::mem_fun(this, &Window::hide));
+
+ for (int s = Gtk::STATE_NORMAL; s <= Gtk::STATE_INSENSITIVE; ++s) {
+ _textview->modify_base((Gtk::StateType)s, Gdk::Color("#000000"));
+ _textview->modify_text((Gtk::StateType)s, Gdk::Color("#EEEEEC"));
+ }
+}
+
+void
+MessagesWindow::init_window(App& app)
+{
+ Glib::RefPtr<Gtk::TextTag> tag = Gtk::TextTag::create();
+ tag->property_foreground() = "#EF2929";
+ _tags.emplace(app.uris().log_Error, tag);
+ _error_tag = tag;
+
+ tag = Gtk::TextTag::create();
+ tag->property_foreground() = "#FCAF3E";
+ _tags.emplace(app.uris().log_Warning, tag);
+
+ tag = Gtk::TextTag::create();
+ tag->property_foreground() = "#8AE234";
+ _tags.emplace(app.uris().log_Trace, tag);
+
+ for (const auto& t : _tags) {
+ _textview->get_buffer()->get_tag_table()->add(t.second);
+ }
}
void
-MessagesWindow::post(const string& msg)
+MessagesWindow::post_error(const string& msg)
{
Glib::RefPtr<Gtk::TextBuffer> text_buf = _textview->get_buffer();
- text_buf->insert(text_buf->end(), msg);
+ text_buf->insert_with_tag(text_buf->end(), msg, _error_tag);
text_buf->insert(text_buf->end(), "\n");
- if (!_clear_button->is_sensitive())
+ if (!_clear_button->is_sensitive()) {
+ _clear_button->set_sensitive(true);
+ }
+
+ set_urgency_hint(true);
+ if (!is_visible()) {
+ present();
+ }
+}
+
+int
+MessagesWindow::log(LV2_URID type, const char* fmt, va_list args)
+{
+ std::lock_guard<std::mutex> lock(_mutex);
+
+#ifdef HAVE_VASPRINTF
+ char* buf = NULL;
+ const int len = vasprintf(&buf, fmt, args);
+#else
+ char* buf = g_strdup_vprintf(fmt, args);
+ const int len = strlen(buf);
+#endif
+
+ _stream << type << ' ' << buf << '\0';
+ free(buf);
+
+ return len;
+}
+
+void
+MessagesWindow::flush()
+{
+ LV2_URID type;
+ std::string line;
+ {
+ std::lock_guard<std::mutex> lock(_mutex);
+ if (!_stream.rdbuf()->in_avail()) {
+ return;
+ }
+ _stream >> type;
+ std::getline(_stream, line, '\0');
+ }
+
+ Glib::RefPtr<Gtk::TextBuffer> text_buf = _textview->get_buffer();
+
+ auto t = _tags.find(type);
+ if (t != _tags.end()) {
+ text_buf->insert_with_tag(text_buf->end(), line, t->second);
+ } else {
+ text_buf->insert(text_buf->end(), line);
+ }
+
+ if (!_clear_button->is_sensitive()) {
_clear_button->set_sensitive(true);
+ }
}
void