]> sigrok.org Git - sigrok-gtk.git/blame - log.c
Split README, add appropriate ones per-project.
[sigrok-gtk.git] / log.c
CommitLineData
3f63165c
UH
1/*
2 * This file is part of the sigrok project.
3 *
4 * Copyright (C) 2011 Gareth McMullin <gareth@blacksphere.co.nz>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <gtk/gtk.h>
21#include "sigrok-gtk.h"
22
23static void logger(const gchar *log_domain, GLogLevelFlags log_level,
24 const gchar *message, gpointer user_data)
25{
26 GtkTextView *tv = user_data;
27 g_return_if_fail(GTK_IS_TEXT_VIEW(tv));
28 GtkTextBuffer *tb = gtk_text_view_get_buffer(tv);
29 GtkTextIter iter;
30
31 /* Avoid compiler warnings. */
32 (void)log_domain;
33 (void)log_level;
34
35 gtk_text_buffer_get_end_iter(tb, &iter);
36 gtk_text_buffer_insert(tb, &iter, message, -1);
37 gtk_text_buffer_insert(tb, &iter, "\n", -1);
38 gtk_text_view_scroll_mark_onscreen(tv, gtk_text_buffer_get_insert(tb));
39}
40
41GtkWidget *log_init(void)
42{
43 GtkWidget *sw, *tv;
44
45 sw = gtk_scrolled_window_new(NULL, NULL);
46 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
47 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
48 tv = gtk_text_view_new();
49 gtk_widget_modify_font(tv,
50 pango_font_description_from_string("Monospace"));
51 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(tv), GTK_WRAP_CHAR);
52 gtk_text_view_set_editable(GTK_TEXT_VIEW(tv), FALSE);
53
54 gtk_container_add(GTK_CONTAINER(sw), tv);
55
56 g_log_set_default_handler(logger, tv);
57 gtk_widget_show_all(tv);
58
59 return sw;
60}
61