Mercurial > geeqie
annotate src/logwindow.c @ 682:54980ddfe1ce
Memorize text to display in the log window when the window is
not yet created. On log window display, the memorized text
is then recalled and displayed.
author | zas_ |
---|---|
date | Sun, 18 May 2008 11:39:58 +0000 |
parents | ac0ede6a53cf |
children | fece9ff5c624 |
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 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
31 gint lines; |
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], |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
151 NULL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
152 } |
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 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
|
155 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
160 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
|
161 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
162 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
|
163 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
|
164 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
|
165 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
166 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
|
167 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
168 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
|
169 } |
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 |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
193 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
|
194 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
195 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
|
196 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
|
197 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
|
198 gint line_limit = 1000; //FIXME: option |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
199 gchar *str_utf8; |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
200 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
|
201 |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
202 if (logwindow == NULL && *str) |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
203 { |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
204 LogMsg *msg = g_new(LogMsg, 1); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
205 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
206 msg->text = g_strdup(str); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
207 msg->type = type; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
208 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
209 memory = g_list_prepend(memory, msg); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
210 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
211 while (g_list_length(memory) >= line_limit) |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
212 { |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
213 GList *work = g_list_last(memory); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
214 LogMsg *oldest_msg = work->data; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
215 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
216 g_free(oldest_msg->text); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
217 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
|
218 } |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
219 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
220 return; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
221 } |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
222 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
223 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
|
224 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
|
225 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
226 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
|
227 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
228 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
|
229 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
230 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
|
231 end = start; |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
232 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
|
233 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
|
234 } |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
235 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
236 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
|
237 |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
238 { |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
239 GList *work = g_list_last(memory); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
240 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
241 while (work) |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
242 { |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
243 GList *prev; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
244 LogMsg *oldest_msg = work->data; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
245 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
246 str_utf8 = utf8_validate_or_convert((gchar *)oldest_msg->text); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
247 gtk_text_buffer_insert_with_tags_by_name |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
248 (buffer, &iter, str_utf8, -1, logdefs[oldest_msg->type].tag, NULL); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
249 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
250 prev = work->prev; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
251 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
|
252 work = prev; |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
253 } |
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 |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
256 if (*str) |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
257 { |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
258 str_utf8 = utf8_validate_or_convert((gchar *)str); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
259 gtk_text_buffer_insert_with_tags_by_name |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
260 (buffer, &iter, str_utf8, -1, logdefs[type].tag, NULL); |
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
261 } |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
262 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
263 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
|
264 { |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
265 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
|
266 |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
diff
changeset
|
267 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
|
268 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
|
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 |
682
54980ddfe1ce
Memorize text to display in the log window when the window is
zas_
parents:
681
diff
changeset
|
271 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
|
272 } |