initial message templates support
[claws.git] / src / logwindow.c
blob3226267d1f6531eefb06faa652b85074a10e7478
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999,2000 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
24 #include <glib.h>
25 #include <gdk/gdkkeysyms.h>
26 #include <gtk/gtkwidget.h>
27 #include <gtk/gtkwindow.h>
28 #include <gtk/gtksignal.h>
29 #include <gtk/gtkscrolledwindow.h>
30 #include <gtk/gtktext.h>
31 #include <gtk/gtkstyle.h>
33 #include "intl.h"
34 #include "logwindow.h"
35 #include "utils.h"
36 #include "gtkutils.h"
38 static LogWindow *logwindow;
40 static void key_pressed(GtkWidget *widget, GdkEventKey *event,
41 LogWindow *logwin);
43 LogWindow *log_window_create(void)
45 LogWindow *logwin;
46 GtkWidget *window;
47 GtkWidget *scrolledwin;
48 GtkWidget *text;
50 debug_print(_("Creating log window...\n"));
51 logwin = g_new0(LogWindow, 1);
53 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
54 gtk_window_set_title(GTK_WINDOW(window), _("Protocol log"));
55 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
56 gtk_widget_set_usize(window, 520, 400);
57 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
58 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete), NULL);
59 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
60 GTK_SIGNAL_FUNC(key_pressed), logwin);
61 gtk_widget_realize(window);
63 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
64 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
65 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
66 gtk_container_add(GTK_CONTAINER(window), scrolledwin);
67 gtk_widget_show(scrolledwin);
69 text = gtk_text_new(gtk_scrolled_window_get_hadjustment
70 (GTK_SCROLLED_WINDOW(scrolledwin)),
71 gtk_scrolled_window_get_vadjustment
72 (GTK_SCROLLED_WINDOW(scrolledwin)));
73 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
74 gtk_widget_show(text);
76 logwin->window = window;
77 logwin->scrolledwin = scrolledwin;
78 logwin->text = text;
80 logwindow = logwin;
82 return logwin;
85 void log_window_init(LogWindow *logwin)
87 GdkColormap *colormap;
88 GdkColor color[3] =
89 {{0, 0, 0xafff, 0}, {0, 0xefff, 0, 0}, {0, 0xefff, 0, 0}};
90 gboolean success[3];
91 gint i;
93 gtkut_widget_disable_theme_engine(logwin->text);
95 logwin->msg_color = color[0];
96 logwin->warn_color = color[1];
97 logwin->error_color = color[2];
99 colormap = gdk_window_get_colormap(logwin->window->window);
100 gdk_colormap_alloc_colors(colormap, color, 3, FALSE, TRUE, success);
102 for (i = 0; i < 3; i++) {
103 if (success[i] == FALSE) {
104 GtkStyle *style;
106 g_warning("LogWindow: color allocation failed\n");
107 style = gtk_widget_get_style(logwin->window);
108 logwin->msg_color = logwin->warn_color =
109 logwin->error_color = style->black;
110 break;
115 void log_window_show(LogWindow *logwin)
117 gtk_widget_hide(logwin->window);
118 gtk_widget_show(logwin->window);
121 void log_window_append(const gchar *str, LogType type)
123 GtkText *text;
124 GdkColor *color = NULL;
125 gchar *head = NULL;
127 g_return_if_fail(logwindow != NULL);
129 text = GTK_TEXT(logwindow->text);
131 /*gtk_text_freeze(text);*/
133 switch (type) {
134 case LOG_WARN:
135 color = &logwindow->warn_color;
136 head = "*** ";
137 break;
138 case LOG_ERROR:
139 color = &logwindow->error_color;
140 head = "*** ";
141 break;
142 case LOG_MSG:
143 color = &logwindow->msg_color;
144 break;
145 default:
148 if (head) gtk_text_insert(text, NULL, color, NULL, head, -1);
149 gtk_text_insert(text, NULL, color, NULL, str, -1);
151 /*gtk_text_thaw(text);*/
154 static void key_pressed(GtkWidget *widget, GdkEventKey *event,
155 LogWindow *logwin)
157 if (event && event->keyval == GDK_Escape)
158 gtk_widget_hide(logwin->window);