/*
- * Geeqie
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2008 - 2016 The Geeqie Team
*
- * Author: Vladimir Nadvornik, Laurent Monin
- * based on logwindow.[ch] from Sylpheed 2.4.7 (C) Hiroyuki Yamamoto
+ * Authors: Vladimir Nadvornik, Laurent Monin
*
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "main.h"
#include "logwindow.h"
+#include "misc.h"
#include "window.h"
#include <gdk/gdkkeysyms.h>
GtkWidget *window;
GtkWidget *scrolledwin;
GtkWidget *text;
-
+
GdkColor colors[LOG_COUNT];
- gint lines;
+ guint lines;
};
typedef struct _LogDef LogDef;
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
LogWindow *logwin)
{
- if (event && event->keyval == GDK_Escape)
+ if (event && event->keyval == GDK_KEY_Escape)
gtk_widget_hide(logwin->window);
return FALSE;
}
static void log_window_init(LogWindow *logwin)
{
GtkTextBuffer *buffer;
+#if !GTK_CHECK_VERSION(3,0,0)
GdkColormap *colormap;
- gboolean success[LOG_COUNT - 1];
+ gboolean success[LOG_COUNT];
+#endif
gint i;
g_assert(logwin != NULL);
g_assert(logwin->colors != NULL);
-
+#if !GTK_CHECK_VERSION(3,0,0)
for (i = LOG_NORMAL; i < LOG_COUNT; i++)
{
gboolean ok = gdk_color_parse(logdefs[i].color, &logwin->colors[i]);
memcpy(&logwin->colors[i], &logwin->colors[LOG_NORMAL], sizeof(GdkColor));
}
- colormap = gdk_drawable_get_colormap(logwin->window->window);
+ colormap = gdk_drawable_get_colormap(gtk_widget_get_window(logwin->window));
gdk_colormap_alloc_colors(colormap, logwin->colors, LOG_COUNT, FALSE, TRUE, success);
for (i = LOG_NORMAL; i < LOG_COUNT; i++)
break;
}
}
-
+#endif
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text));
for (i = LOG_NORMAL; i < LOG_COUNT; i++)
gtk_text_buffer_create_tag(buffer, logdefs[i].tag,
"foreground-gdk", &logwin->colors[i],
+ "family", "MonoSpace",
NULL);
}
GtkTextView *text = GTK_TEXT_VIEW(logwin->text);
GtkTextBuffer *buffer;
GtkTextMark *mark;
-
+
g_assert(logwin != NULL);
buffer = gtk_text_view_get_buffer(text);
log_window_append("", LOG_NORMAL); // to flush memorized lines
}
-
void log_window_new(void)
{
if (logwindow == NULL)
LogType type;
};
+
+static void log_window_insert_text(GtkTextBuffer *buffer, GtkTextIter *iter,
+ const gchar *text, const gchar *tag)
+{
+ gchar *str_utf8;
+
+ if (!text || !*text) return;
+
+ str_utf8 = utf8_validate_or_convert(text);
+ gtk_text_buffer_insert_with_tags_by_name(buffer, iter, str_utf8, -1, tag, NULL);
+ g_free(str_utf8);
+}
+
+
void log_window_append(const gchar *str, LogType type)
{
GtkTextView *text;
GtkTextBuffer *buffer;
GtkTextIter iter;
- gint line_limit = 1000; //FIXME: option
- gchar *str_utf8;
static GList *memory = NULL;
- if (logwindow == NULL && *str)
+ if (logwindow == NULL)
{
- LogMsg *msg = g_new(LogMsg, 1);
+ if (*str) {
+ LogMsg *msg = g_new(LogMsg, 1);
- msg->text = g_strdup(str);
- msg->type = type;
+ msg->text = g_strdup(str);
+ msg->type = type;
- memory = g_list_prepend(memory, msg);
+ memory = g_list_prepend(memory, msg);
- while (g_list_length(memory) >= line_limit)
- {
- GList *work = g_list_last(memory);
- LogMsg *oldest_msg = work->data;
-
- g_free(oldest_msg->text);
- memory = g_list_delete_link(memory, work);
- }
+ while (g_list_length(memory) >= options->log_window_lines)
+ {
+ GList *work = g_list_last(memory);
+ LogMsg *oldest_msg = work->data;
+ g_free(oldest_msg->text);
+ memory = g_list_delete_link(memory, work);
+ }
+ }
return;
}
text = GTK_TEXT_VIEW(logwindow->text);
buffer = gtk_text_view_get_buffer(text);
- if (line_limit > 0 && logwindow->lines >= line_limit)
+ if (options->log_window_lines > 0 && logwindow->lines >= options->log_window_lines)
{
GtkTextIter start, end;
gtk_text_buffer_get_start_iter(buffer, &start);
end = start;
- gtk_text_iter_forward_lines(&end, logwindow->lines - line_limit);
+ gtk_text_iter_forward_lines(&end, logwindow->lines - options->log_window_lines);
gtk_text_buffer_delete(buffer, &start, &end);
}
{
GList *prev;
LogMsg *oldest_msg = work->data;
-
- str_utf8 = utf8_validate_or_convert((gchar *)oldest_msg->text);
- gtk_text_buffer_insert_with_tags_by_name
- (buffer, &iter, str_utf8, -1, logdefs[oldest_msg->type].tag, NULL);
-
+
+ log_window_insert_text(buffer, &iter, oldest_msg->text, logdefs[oldest_msg->type].tag);
+
prev = work->prev;
memory = g_list_delete_link(memory, work);
work = prev;
}
}
- if (*str)
- {
- str_utf8 = utf8_validate_or_convert((gchar *)str);
- gtk_text_buffer_insert_with_tags_by_name
- (buffer, &iter, str_utf8, -1, logdefs[type].tag, NULL);
- }
+ log_window_insert_text(buffer, &iter, str, logdefs[type].tag);
- if (GTK_WIDGET_VISIBLE(text))
+ if (gtk_widget_get_visible(GTK_WIDGET(text)))
{
GtkTextMark *mark;
-
+
mark = gtk_text_buffer_get_mark(buffer, "end");
gtk_text_view_scroll_mark_onscreen(text, mark);
}
logwindow->lines = gtk_text_buffer_get_line_count(buffer);
}
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */