gnome-utils r8299 - trunk/logview
- From: cosimoc svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-utils r8299 - trunk/logview
- Date: Tue, 23 Dec 2008 13:27:45 +0000 (UTC)
Author: cosimoc
Date: Tue Dec 23 13:27:45 2008
New Revision: 8299
URL: http://svn.gnome.org/viewvc/gnome-utils?rev=8299&view=rev
Log:
Complete days highlighting.
Modified:
trunk/logview/logview-utils.c
trunk/logview/logview-window.c
Modified: trunk/logview/logview-utils.c
==============================================================================
--- trunk/logview/logview-utils.c (original)
+++ trunk/logview/logview-utils.c Tue Dec 23 13:27:45 2008
@@ -74,13 +74,11 @@
}
static GDate *
-string_get_date (const char *line, char **time_string)
+string_get_date (const char *line, char **time_string, int *timestamp_len)
{
GDate *date = NULL;
struct tm tp;
- char *cp = NULL;
- char tmp[50];
- size_t chars_read;
+ char *cp = NULL, *timestamp = NULL;
/* it's safe to assume that if strptime returns NULL, it's
* because of an error (format unmatched). being a log file, it's very
@@ -94,14 +92,12 @@
/* this parses the "MonthName DayNo" format */
cp = strptime (line, "%b %d", &tp);
if (cp) {
- chars_read = strftime (tmp, 50, "%b %e", &tp);
goto out;
}
/* this parses the YYYY-MM-DD format */
cp = strptime (line, "%F", &tp);
if (cp) {
- chars_read = strftime (tmp, 50, "%F", &tp);
goto out;
}
@@ -109,7 +105,12 @@
if (cp) {
/* the year doesn't matter to us now */
date = g_date_new_dmy (tp.tm_mday, tp.tm_mon + 1, 1);
- *time_string = g_strndup (tmp, chars_read);
+ *time_string = g_strndup (line, cp - line);
+
+ timestamp = strptime (cp, "%X", &tp);
+ if (timestamp) {
+ *timestamp_len = timestamp - line;
+ }
}
return date;
@@ -132,7 +133,7 @@
GSList *
log_read_dates (const char **buffer_lines, time_t current)
{
- int current_year, offsetyear, i, n, rangemin, rangemax;
+ int current_year, offsetyear, i, n, rangemin, rangemax, timestamp_len = 0;
GSList *days = NULL;
GDate *date, *newdate;
struct tm *tmptm;
@@ -150,7 +151,7 @@
/* find the first line with a date we're able to parse */
for (i = 0; buffer_lines[i]; i++) {
- if ((date = string_get_date (buffer_lines[i], &date_string)) != NULL)
+ if ((date = string_get_date (buffer_lines[i], &date_string, ×tamp_len)) != NULL)
break;
}
@@ -174,7 +175,7 @@
day->date = date;
day->first_line = i;
day->last_line = -1;
- day->timestamp_len = strlen (date_string);
+ day->timestamp_len = timestamp_len;
/* now scan the logfile to get the last line of the day */
rangemin = i;
@@ -223,7 +224,7 @@
newdate = NULL;
for (i = day->last_line + 1; buffer_lines[i]; i++) {
- if ((newdate = string_get_date (buffer_lines[i], &date_string)) != NULL)
+ if ((newdate = string_get_date (buffer_lines[i], &date_string, ×tamp_len)) != NULL)
break;
}
@@ -257,7 +258,7 @@
day->date = date;
day->first_line = i;
day->last_line = -1;
- day->timestamp_len = strlen (date_string);
+ day->timestamp_len = timestamp_len;
rangemin = i;
rangemax = n - 1;
}
Modified: trunk/logview/logview-window.c
==============================================================================
--- trunk/logview/logview-window.c (original)
+++ trunk/logview/logview-window.c Tue Dec 23 13:27:45 2008
@@ -109,11 +109,9 @@
/* private helpers */
static void
-populate_tag_table (GtkStyle *style,
- GtkTextTagTable *tag_table)
+populate_tag_table (GtkTextTagTable *tag_table)
{
GtkTextTag *tag;
- GdkColor color;
tag = gtk_text_tag_new ("bold");
g_object_set (tag, "weight", PANGO_WEIGHT_BOLD,
@@ -126,6 +124,23 @@
gtk_text_tag_table_add (tag_table, tag);
+}
+
+
+static void
+populate_style_tag_table (GtkStyle *style,
+ GtkTextTagTable *tag_table)
+{
+ GtkTextTag *tag;
+ GdkColor color;
+
+ tag = gtk_text_tag_table_lookup (tag_table, "gray");
+
+ if (tag) {
+ /* FIXME: do we need a way to update the buffer/view? */
+ gtk_text_tag_table_remove (tag_table, tag);
+ }
+
tag = gtk_text_tag_new ("gray");
color = style->text[GTK_STATE_INSENSITIVE];
g_object_set (tag, "foreground-gdk", &color, "foreground-set", TRUE, NULL);
@@ -754,6 +769,22 @@
}
static void
+paint_timestamps (GtkTextBuffer *buffer, int old_line_count,
+ GSList *days)
+{
+ GSList *l;
+
+ for (l = days; l; l = l->next) {
+ Day *day = l->data;
+
+ _gtk_text_buffer_apply_tag_to_rectangle (buffer,
+ old_line_count + day->first_line - 1,
+ old_line_count + day->last_line,
+ 0, day->timestamp_len, "gray");
+ }
+}
+
+static void
read_new_lines_cb (LogviewLog *log,
const char **lines,
GSList *new_days,
@@ -766,15 +797,14 @@
int i, old_line_count;
GtkTextIter iter, start;
GtkTextMark *mark;
- GSList *l;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (window->priv->text_view));
+ old_line_count = gtk_text_buffer_get_line_count (buffer);
if (gtk_text_buffer_get_char_count (buffer) != 0) {
boldify = TRUE;
}
- old_line_count = gtk_text_buffer_get_line_count (buffer);
gtk_text_buffer_get_end_iter (buffer, &iter);
if (boldify) {
@@ -788,21 +818,14 @@
gtk_text_iter_forward_char (&iter);
}
- for (l = new_days; l; l = l->next) {
- Day *day = l->data;
-
- _gtk_text_buffer_apply_tag_to_rectangle (buffer,
- old_line_count + day->first_line - 1,
- old_line_count + day->last_line,
- 0, day->timestamp_len, "gray");
- }
-
if (boldify) {
gtk_text_buffer_get_iter_at_mark (buffer, &start, mark);
gtk_text_buffer_apply_tag_by_name (buffer, "bold", &start, &iter);
gtk_text_buffer_delete_mark (buffer, mark);
}
+ paint_timestamps (buffer, old_line_count, new_days);
+
if (window->priv->monitor_id == 0) {
window->priv->monitor_id = g_signal_connect (log, "log-changed",
G_CALLBACK (log_monitor_changed_cb), window);
@@ -846,6 +869,8 @@
gtk_text_buffer_insert (buffer, &iter, "\n", 1);
gtk_text_iter_forward_char (&iter);
}
+
+ paint_timestamps (buffer, 1, logview_log_get_days_for_cached_lines (log));
}
if (lines == NULL || logview_log_has_new_lines (log)) {
@@ -894,7 +919,7 @@
LogviewWindow *logview = user_data;
GtkStyle *style = gtk_widget_get_style (widget);
- populate_tag_table (style, logview->priv->tag_table);
+ populate_style_tag_table (style, logview->priv->tag_table);
}
static void
@@ -1001,6 +1026,7 @@
gtk_widget_show (w);
priv->tag_table = gtk_text_tag_table_new ();
+ populate_tag_table (priv->tag_table);
priv->text_view = gtk_text_view_new ();
g_object_set (priv->text_view, "editable", FALSE, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]