Skip to content

Commit

Permalink
Cleanup and code redundancy reduction.
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Monin committed May 18, 2008
1 parent 3df95a3 commit a172604
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/logwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ static void log_window_init(LogWindow *logwin)
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);
}

Expand All @@ -168,7 +169,6 @@ static void log_window_show(LogWindow *logwin)
log_window_append("", LOG_NORMAL); // to flush memorized lines
}


void log_window_new(void)
{
if (logwindow == NULL)
Expand All @@ -190,13 +190,25 @@ struct _LogMsg {
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((gchar *)text);
gtk_text_buffer_insert_with_tags_by_name(buffer, iter, str_utf8, -1, tag, NULL);
}


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)
Expand Down Expand Up @@ -243,22 +255,15 @@ void log_window_append(const gchar *str, LogType type)
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))
{
Expand Down

0 comments on commit a172604

Please sign in to comment.