Mercurial > geeqie.yaz
annotate src/logwindow.c @ 804:e702eaa6d1df
vficon_sync speed-up
author | nadvornik |
---|---|
date | Sun, 08 Jun 2008 20:24:46 +0000 |
parents | e73d30e0c896 |
children | 9962b24b6b43 |
rev | line source |
---|---|
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
1 /* |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
2 * Geeqie |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
3 * Copyright (C) 2008 The Geeqie Team |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
4 * |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
5 * Author: Vladimir Nadvornik, Laurent Monin |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
6 * based on logwindow.[ch] from Sylpheed 2.4.7 (C) Hiroyuki Yamamoto |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
7 * |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
8 * This software is released under the GNU General Public License (GNU GPL). |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
9 * Please read the included file COPYING for more information. |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
10 * This software comes with no warranty of any kind, use at your own risk! |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
11 */ |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
12 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
13 #include "main.h" |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
14 #include "logwindow.h" |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
15 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
16 #include "window.h" |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
17 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
18 #include <gdk/gdkkeysyms.h> |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
19 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
20 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
21 typedef struct _LogWindow LogWindow; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
22 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
23 struct _LogWindow |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
24 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
25 GtkWidget *window; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
26 GtkWidget *scrolledwin; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
27 GtkWidget *text; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
28 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
29 GdkColor colors[LOG_COUNT]; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
30 |
736 | 31 guint lines; |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
32 }; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
33 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
34 typedef struct _LogDef LogDef; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
35 struct _LogDef |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
36 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
37 LogType type; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
38 const gchar *tag; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
39 const gchar *color; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
40 }; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
41 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
42 /* Keep LogType order !! */ |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
43 static LogDef logdefs[LOG_COUNT] = { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
44 { LOG_NORMAL, "normal", "black" }, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
45 { LOG_MSG, "message", "blue" }, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
46 { LOG_WARN, "warning", "orange" }, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
47 { LOG_ERROR, "error", "red" }, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
48 }; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
49 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
50 static LogWindow *logwindow = NULL; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
51 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
52 static void hide_cb(GtkWidget *widget, LogWindow *logwin) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
53 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
54 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
55 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
56 static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
57 LogWindow *logwin) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
58 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
59 if (event && event->keyval == GDK_Escape) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
60 gtk_widget_hide(logwin->window); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
61 return FALSE; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
62 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
63 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
64 static LogWindow *log_window_create(void) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
65 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
66 LogWindow *logwin; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
67 GtkWidget *window; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
68 GtkWidget *scrolledwin; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
69 GtkWidget *text; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
70 GtkTextBuffer *buffer; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
71 GtkTextIter iter; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
72 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
73 logwin = g_new0(LogWindow, 1); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
74 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
75 window = window_new(GTK_WINDOW_TOPLEVEL, "log", NULL, NULL, _("Log")); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
76 gtk_widget_set_size_request(window, 520, 400); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
77 g_signal_connect(G_OBJECT(window), "delete_event", |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
78 G_CALLBACK(gtk_widget_hide_on_delete), NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
79 g_signal_connect(G_OBJECT(window), "key_press_event", |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
80 G_CALLBACK(key_pressed), logwin); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
81 g_signal_connect(G_OBJECT(window), "hide", |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
82 G_CALLBACK(hide_cb), logwin); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
83 gtk_widget_realize(window); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
84 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
85 scrolledwin = gtk_scrolled_window_new(NULL, NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
86 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
87 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
88 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin), |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
89 GTK_SHADOW_IN); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
90 gtk_container_add(GTK_CONTAINER(window), scrolledwin); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
91 gtk_widget_show(scrolledwin); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
92 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
93 text = gtk_text_view_new(); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
94 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
95 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
96 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
97 gtk_text_buffer_get_start_iter(buffer, &iter); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
98 gtk_text_buffer_create_mark(buffer, "end", &iter, FALSE); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
99 gtk_container_add(GTK_CONTAINER(scrolledwin), text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
100 gtk_widget_show(text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
101 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
102 logwin->window = window; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
103 logwin->scrolledwin = scrolledwin; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
104 logwin->text = text; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
105 logwin->lines = 1; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
106 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
107 return logwin; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
108 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
109 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
110 static void log_window_init(LogWindow *logwin) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
111 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
112 GtkTextBuffer *buffer; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
113 GdkColormap *colormap; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
114 gboolean success[LOG_COUNT - 1]; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
115 gint i; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
116 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
117 g_assert(logwin != NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
118 g_assert(logwin->colors != NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
119 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
120 for (i = LOG_NORMAL; i < LOG_COUNT; i++) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
121 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
122 gboolean ok = gdk_color_parse(logdefs[i].color, &logwin->colors[i]); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
123 if (ok == TRUE) continue; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
124 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
125 if (i == LOG_NORMAL) return; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
126 memcpy(&logwin->colors[i], &logwin->colors[LOG_NORMAL], sizeof(GdkColor)); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
127 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
128 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
129 colormap = gdk_drawable_get_colormap(logwin->window->window); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
130 gdk_colormap_alloc_colors(colormap, logwin->colors, LOG_COUNT, FALSE, TRUE, success); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
131 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
132 for (i = LOG_NORMAL; i < LOG_COUNT; i++) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
133 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
134 if (success[i] == FALSE) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
135 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
136 GtkStyle *style; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
137 gint j; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
138 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
139 g_warning("LogWindow: color allocation failed\n"); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
140 style = gtk_widget_get_style(logwin->window); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
141 for (j = LOG_NORMAL; j < LOG_COUNT; j++) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
142 logwin->colors[j] = style->black; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
143 break; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
144 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
145 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
146 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
147 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text)); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
148 for (i = LOG_NORMAL; i < LOG_COUNT; i++) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
149 gtk_text_buffer_create_tag(buffer, logdefs[i].tag, |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
150 "foreground-gdk", &logwin->colors[i], |
683 | 151 "family", "MonoSpace", |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
152 NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
153 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
154 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
155 static void log_window_show(LogWindow *logwin) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
156 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
157 GtkTextView *text = GTK_TEXT_VIEW(logwin->text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
158 GtkTextBuffer *buffer; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
159 GtkTextMark *mark; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
160 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
161 g_assert(logwin != NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
162 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
163 buffer = gtk_text_view_get_buffer(text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
164 mark = gtk_text_buffer_get_mark(buffer, "end"); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
165 gtk_text_view_scroll_mark_onscreen(text, mark); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
166 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
167 gtk_window_present(GTK_WINDOW(logwin->window)); |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
168 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
169 log_window_append("", LOG_NORMAL); // to flush memorized lines |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
170 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
171 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
172 void log_window_new(void) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
173 { |
681 | 174 if (logwindow == NULL) |
175 { | |
176 LogWindow *logwin; | |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
177 |
681 | 178 logwin = log_window_create(); |
179 log_window_init(logwin); | |
180 logwindow = logwin; | |
181 } | |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
182 |
681 | 183 log_window_show(logwindow); |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
184 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
185 |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
186 typedef struct _LogMsg LogMsg; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
187 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
188 struct _LogMsg { |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
189 gchar *text; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
190 LogType type; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
191 }; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
192 |
683 | 193 |
194 static void log_window_insert_text(GtkTextBuffer *buffer, GtkTextIter *iter, | |
195 const gchar *text, const gchar *tag) | |
196 { | |
197 gchar *str_utf8; | |
198 | |
199 if (!text || !*text) return; | |
200 | |
767
e73d30e0c896
Make utf8_validate_or_convert() to always allocate a new string.
zas_
parents:
736
diff
changeset
|
201 str_utf8 = utf8_validate_or_convert(text); |
683 | 202 gtk_text_buffer_insert_with_tags_by_name(buffer, iter, str_utf8, -1, tag, NULL); |
767
e73d30e0c896
Make utf8_validate_or_convert() to always allocate a new string.
zas_
parents:
736
diff
changeset
|
203 g_free(str_utf8); |
683 | 204 } |
205 | |
206 | |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
207 void log_window_append(const gchar *str, LogType type) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
208 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
209 GtkTextView *text; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
210 GtkTextBuffer *buffer; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
211 GtkTextIter iter; |
736 | 212 guint line_limit = 1000; //FIXME: option |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
213 static GList *memory = NULL; |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
214 |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
215 if (logwindow == NULL) |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
216 { |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
217 if (*str) { |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
218 LogMsg *msg = g_new(LogMsg, 1); |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
219 |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
220 msg->text = g_strdup(str); |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
221 msg->type = type; |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
222 |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
223 memory = g_list_prepend(memory, msg); |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
224 |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
225 while (g_list_length(memory) >= line_limit) |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
226 { |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
227 GList *work = g_list_last(memory); |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
228 LogMsg *oldest_msg = work->data; |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
229 |
718
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
230 g_free(oldest_msg->text); |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
231 memory = g_list_delete_link(memory, work); |
7119e30971ec
Fix a segfault occuring when logging an empty message and there is no log window.
zas_
parents:
683
diff
changeset
|
232 } |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
233 } |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
234 return; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
235 } |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
236 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
237 text = GTK_TEXT_VIEW(logwindow->text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
238 buffer = gtk_text_view_get_buffer(text); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
239 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
240 if (line_limit > 0 && logwindow->lines >= line_limit) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
241 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
242 GtkTextIter start, end; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
243 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
244 gtk_text_buffer_get_start_iter(buffer, &start); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
245 end = start; |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
246 gtk_text_iter_forward_lines(&end, logwindow->lines - line_limit); |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
247 gtk_text_buffer_delete(buffer, &start, &end); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
248 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
249 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
250 gtk_text_buffer_get_end_iter(buffer, &iter); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
251 |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
252 { |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
253 GList *work = g_list_last(memory); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
254 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
255 while (work) |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
256 { |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
257 GList *prev; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
258 LogMsg *oldest_msg = work->data; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
259 |
683 | 260 log_window_insert_text(buffer, &iter, oldest_msg->text, logdefs[oldest_msg->type].tag); |
261 | |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
262 prev = work->prev; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
263 memory = g_list_delete_link(memory, work); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
264 work = prev; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
265 } |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
266 } |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
267 |
683 | 268 log_window_insert_text(buffer, &iter, str, logdefs[type].tag); |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
269 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
270 if (GTK_WIDGET_VISIBLE(text)) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
271 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
272 GtkTextMark *mark; |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
273 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
274 mark = gtk_text_buffer_get_mark(buffer, "end"); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
275 gtk_text_view_scroll_mark_onscreen(text, mark); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
276 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
277 |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
278 logwindow->lines = gtk_text_buffer_get_line_count(buffer); |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
279 } |