gnome-utils r8232 - trunk/logview
- From: cosimoc svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-utils r8232 - trunk/logview
- Date: Tue, 23 Dec 2008 13:25:37 +0000 (UTC)
Author: cosimoc
Date: Tue Dec 23 13:25:36 2008
New Revision: 8232
URL: http://svn.gnome.org/viewvc/gnome-utils?rev=8232&view=rev
Log:
Move some utilities to logview-utils.c.
Start refactoring log_repaint.c.
Added:
trunk/logview/logview-utils.c
trunk/logview/logview-utils.h
Modified:
trunk/logview/Makefile.am
trunk/logview/log_repaint.c
trunk/logview/logrtns.c
trunk/logview/logview-log.c
trunk/logview/logview-log.h
trunk/logview/logview-manager.c
trunk/logview/logview-manager.h
trunk/logview/logview.c
trunk/logview/misc.c
Modified: trunk/logview/Makefile.am
==============================================================================
--- trunk/logview/Makefile.am (original)
+++ trunk/logview/Makefile.am Tue Dec 23 13:25:36 2008
@@ -22,6 +22,8 @@
logview-about.h \
logview-manager.c \
logview-manager.h \
+ logview-utils.c \
+ logview-utils.h \
calendar.c \
calendar.h \
log_repaint.c \
Modified: trunk/logview/log_repaint.c
==============================================================================
--- trunk/logview/log_repaint.c (original)
+++ trunk/logview/log_repaint.c Tue Dec 23 13:25:36 2008
@@ -33,38 +33,10 @@
#include "calendar.h"
enum {
- MESSAGE = 0,
- DAY_POINTER,
- LOG_LINE_WEIGHT,
- LOG_LINE_WEIGHT_SET
+ COL_MESSAGE,
+ COL_DAY
};
-static gboolean busy_cursor = FALSE;
-
-static gboolean
-logview_show_busy_cursor (LogviewWindow *logview)
-{
- GdkCursor *cursor;
- if (GTK_WIDGET_VISIBLE (logview->view) && logview->curlog->model == NULL) {
- cursor = gdk_cursor_new (GDK_WATCH);
- gdk_window_set_cursor (GTK_WIDGET (logview)->window, cursor);
- gdk_cursor_unref (cursor);
- gdk_display_flush (gtk_widget_get_display (GTK_WIDGET (logview)));
- busy_cursor = TRUE;
- }
- return (FALSE);
-}
-
-static gboolean
-logview_show_normal_cursor (LogviewWindow *logview)
-{
- if (busy_cursor) {
- gdk_window_set_cursor (GTK_WIDGET (logview)->window, NULL);
- gdk_display_flush (gtk_widget_get_display (GTK_WIDGET (logview)));
- busy_cursor = FALSE;
- }
-}
-
void
row_toggled_cb (GtkTreeView *treeview, GtkTreeIter *iter,
GtkTreePath *path, gpointer user_data)
@@ -165,42 +137,6 @@
}
}
-static void
-logview_update_statusbar (LogviewWindow *logview)
-{
- char *statusbar_text;
- char *size, *modified, *index;
- Log *log;
-
- g_assert (LOGVIEW_IS_WINDOW (logview));
-
- log = logview->curlog;
-
- if (log == NULL) {
- gtk_statusbar_pop (GTK_STATUSBAR (logview->statusbar), 0);
- return;
- }
-
- /* ctime returned string has "\n\0" causes statusbar display a invalid char */
- modified = ctime (&(log->stats->file_time));
- index = strrchr (modified, '\n');
- if (index && *index != '\0')
- *index = '\0';
-
- modified = g_strdup_printf (_("last update: %s"), modified);
- size = gnome_vfs_format_file_size_for_display (log->stats->file_size);
- statusbar_text = g_strdup_printf (_("%d lines (%s) - %s"),
- log->total_lines, size, modified);
-
- if (statusbar_text) {
- gtk_statusbar_pop (GTK_STATUSBAR(logview->statusbar), 0);
- gtk_statusbar_push (GTK_STATUSBAR(logview->statusbar), 0, statusbar_text);
- g_free (size);
- g_free (modified);
- g_free (statusbar_text);
- }
-}
-
void
logview_update_version_bar (LogviewWindow *logview)
{
@@ -447,21 +383,7 @@
log->displayed_lines = log->total_lines;
}
-
-static void
-log_create_model (Log *log)
-{
- GtkTreeModel *model;
-
- g_assert (log != NULL);
- model = GTK_TREE_MODEL(gtk_tree_store_new (4, G_TYPE_STRING, G_TYPE_POINTER,
- G_TYPE_INT, G_TYPE_BOOLEAN));
- if (log->days != NULL)
- log_fill_model_with_date (log, model);
- else
- log_fill_model_no_date (log, model);
- log->model = model;
-}
+
static void
logview_set_log_model (LogviewWindow *window, Log *log)
@@ -488,35 +410,39 @@
}
}
-void
-logview_repaint (LogviewWindow *logview)
+
+static GtkTreeModel *
+create_and_fill_model (LogviewLog *log)
{
- Log *log;
- g_return_if_fail (LOGVIEW_IS_WINDOW (logview));
-
- log = logview->curlog;
+ GtkTreeModel *retval;
- logview_update_statusbar (logview);
- logview_set_window_title (logview);
-
- if (log == NULL) {
- gtk_tree_view_set_model (GTK_TREE_VIEW (logview->view), NULL);
- return;
- }
+ g_assert (LOGVIEW_IS_LOG (log));
- if (log->model == NULL) {
- g_timeout_add (200, (GSourceFunc) logview_show_busy_cursor, logview);
- log_create_model (log);
- logview_show_normal_cursor (logview);
- }
-
- if (log->needs_refresh) {
- log_add_new_log_lines (log);
- log->needs_refresh = FALSE;
- }
+ retval = GTK_TREE_MODEL (gtk_tree_store_new (4, G_TYPE_STRING, G_TYPE_POINTER));
+ if (log->days != NULL)
+ log_fill_model_with_date (log, model);
+ else
+ log_fill_model_no_date (log, model);
+
+ return retval;
+}
+
+void
+logview_repaint (LogviewWindow *logview, LogviewLog *log)
+{
+ g_return_if_fail (LOGVIEW_IS_WINDOW (logview));
+
+ if (logview->priv->model == NULL) {
+ log_create_model (log);
+ }
+
+ if (log->needs_refresh) {
+ log_add_new_log_lines (log);
+ log->needs_refresh = FALSE;
+ }
- if (gtk_tree_view_get_model (GTK_TREE_VIEW (logview->view)) != log->model)
- logview_set_log_model (logview, log);
+ if (gtk_tree_view_get_model (GTK_TREE_VIEW (logview->view)) != log->model)
+ logview_set_log_model (logview, log);
- logview_scroll_and_focus_path (logview, log);
+ logview_scroll_and_focus_path (logview, log);
}
Modified: trunk/logview/logrtns.c
==============================================================================
--- trunk/logview/logrtns.c (original)
+++ trunk/logview/logrtns.c Tue Dec 23 13:25:36 2008
@@ -118,189 +118,6 @@
}
}
-/* log functions */
-
-gint
-days_compare (gconstpointer a, gconstpointer b)
-{
- const Day *day1 = a, *day2 = b;
- return (g_date_compare (day1->date, day2->date));
-}
-
-gchar *
-string_get_date_string (gchar *line)
-{
- gchar **split, *date_string;
- gchar *month=NULL, *day=NULL;
- int i=0;
-
- if (line == NULL || line[0] == 0)
- return NULL;
-
- split = g_strsplit (line, " ", 4);
- if (split == NULL)
- return NULL;
-
- while ((day == NULL || month == NULL) && split[i]!=NULL && i<4) {
- if (g_str_equal (split[i], "")) {
- i++;
- continue;
- }
-
- if (month == NULL) {
- month = split[i++];
- /* If the first field begins by a number, the date
- is given in yyyy-mm-dd format */
- if (!g_ascii_isalpha (month[0]))
- break;
- continue;
- }
-
- if (day == NULL)
- day = split[i];
- i++;
- }
-
- if (i==3)
- date_string = g_strconcat (month, " ", day, NULL);
- else
- date_string = g_strconcat (month, " ", day, NULL);
- g_strfreev (split);
- return (date_string);
-}
-
-/* log_read_dates
- Read all dates which have a log entry to create calendar.
- All dates are given with respect to the 1/1/1970
- and are then corrected to the correct year once we
- reach the end.
-*/
-GSList *
-log_read_dates (gchar **buffer_lines, time_t current)
-{
- int offsetyear = 0, current_year;
- GSList *days = NULL, *days_copy;
- GDate *date, *newdate;
- struct tm *tmptm;
- gchar *date_string;
- Day *day;
- gboolean done = FALSE;
- int i, n, rangemin, rangemax;
-
- if (buffer_lines == NULL)
- return NULL;
-
- n = g_strv_length (buffer_lines);
-
- tmptm = localtime (¤t);
- current_year = tmptm->tm_year + 1900;
-
- for (i=0; buffer_lines[i]==NULL; i++);
-
- /* Start building the list */
- /* Scanning each line to see if the date changed is too slow, so we proceed
- in a recursive fashion */
-
- date = string_get_date (buffer_lines[i]);
- if ((date==NULL)|| !g_date_valid (date))
- return NULL;
-
- g_date_set_year (date, current_year);
- day = g_new (Day, 1);
- days = g_slist_append (days, day);
-
- day->date = date;
- day->first_line = i;
- day->last_line = -1;
- date_string = string_get_date_string (buffer_lines[i]);
-
- rangemin = 0;
- rangemax = n-1;
-
- while (!done) {
-
- i = n-1;
- while (day->last_line < 0) {
-
- if (g_str_has_prefix (buffer_lines[i], date_string)) {
- if (i == (n-1)) {
- day->last_line = i;
- done = TRUE;
- break;
- } else {
- if (!g_str_has_prefix (buffer_lines[i+1], date_string)) {
- day->last_line = i;
- break;
- } else {
- rangemin = i;
- i = floor ( ((float) i + (float) rangemax)/2.);
- }
- }
- } else {
- rangemax = i;
- i = floor (((float) rangemin + (float) i)/2.);
- }
-
- }
-
- g_free (date_string);
-
- if (!done) {
- /* We need to find the first line now that has a date
- Logs can have some messages without dates ... */
- newdate = NULL;
- while (newdate == NULL && !done) {
- i++;
- date_string = string_get_date_string (buffer_lines[i]);
- if (date_string == NULL)
- if (i==n-1) {
- done = TRUE;
- break;
- } else
- continue;
- newdate = string_get_date (buffer_lines[i]);
-
- if (newdate == NULL && i==n-1)
- done = TRUE;
- }
-
- day->last_line = i-1;
-
- /* Append a day to the list */
- if (newdate) {
- g_date_set_year (newdate, current_year + offsetyear);
- if (g_date_compare (newdate, date) < 1) {
- offsetyear++; /* newdate is next year */
- g_date_add_years (newdate, 1);
- }
-
- date = newdate;
- day = g_new (Day, 1);
- days = g_slist_append (days, day);
-
- day->date = date;
- day->first_line = i;
- day->last_line = -1;
- rangemin = i;
- rangemax = n;
- }
- }
- }
-
- /* Correct years now. We assume that the last date on the log
- is the date last accessed */
-
- for (days_copy = days; days_copy != NULL; days_copy = g_slist_next (days_copy)) {
- day = days_copy -> data;
- g_date_subtract_years (day->date, offsetyear);
- }
-
- /* Sort the days in chronological order */
- days = g_slist_sort (days, days_compare);
-
- return (days);
-}
-
/*
log_stats_new
Read the log and get some statistics from it.
Modified: trunk/logview/logview-log.c
==============================================================================
--- trunk/logview/logview-log.c (original)
+++ trunk/logview/logview-log.c Tue Dec 23 13:25:36 2008
@@ -349,4 +349,20 @@
g_assert (LOGVIEW_IS_LOG (log));
return log->priv->display_name;
+}
+
+gulong
+logview_log_get_timestamp (LogviewLog *log)
+{
+ g_assert (LOGVIEW_IS_LOG (log));
+
+ return log->priv->file_time.tv_sec;
+}
+
+goffset
+logview_log_get_file_size (LogviewLog *log)
+{
+ g_assert (LOGVIEW_IS_LOG (log));
+
+ return log->priv->file_size;
}
\ No newline at end of file
Modified: trunk/logview/logview-log.h
==============================================================================
--- trunk/logview/logview-log.h (original)
+++ trunk/logview/logview-log.h Tue Dec 23 13:25:36 2008
@@ -84,6 +84,8 @@
LogviewNewLinesCallback callback,
gpointer user_data);
const char * logview_log_get_display_name (LogviewLog *log);
+gulong logview_log_get_timestamp (LogviewLog *log);
+goffset logview_log_get_file_size (LogviewLog *log);
G_END_DECLS
Modified: trunk/logview/logview-manager.c
==============================================================================
--- trunk/logview/logview-manager.c (original)
+++ trunk/logview/logview-manager.c Tue Dec 23 13:25:36 2008
@@ -25,6 +25,7 @@
enum {
LOG_ADDED,
LOG_CLOSED,
+ LOG_CHANGED,
LOG_ADD_ERROR,
ACTIVE_CHANGED,
LAST_SIGNAL
@@ -46,10 +47,18 @@
struct _LogviewManagerPrivate {
GHashTable *logs;
+ GHashTable *lines_cache;
LogviewLog *active_log;
};
static void
+lines_destroy_notify (GPtrArray *array)
+{
+ char **lines = (char **) g_ptr_array_free (array, FALSE);
+ g_strfreev (lines);
+}
+
+static void
logview_manager_finalize (GObject *object)
{
LogviewManager *manager;
@@ -61,6 +70,7 @@
}
g_hash_table_destroy (manager->priv->logs);
+ g_hash_table_destroy (manager->priv->lines_cache);
G_OBJECT_CLASS (logview_manager_parent_class)->finalize (object);
}
@@ -90,6 +100,15 @@
G_TYPE_NONE, 1,
LOGVIEW_TYPE_LOG);
+ signals[LOG_CHANGED] = g_signal_new ("log-changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (LogviewManagerClass, log_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 1,
+ LOGVIEW_TYPE_LOG);
+
signals[LOG_ADD_ERROR] = g_signal_new ("log-add-error",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
@@ -119,6 +138,17 @@
priv->active_log = NULL;
priv->logs = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, (GDestroyNotify) g_object_unref);
+ priv->lines_cache = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ NULL, (GDestroyNotify) lines_destroy_notify);
+}
+
+static void
+log_changed_cb (LogviewLog *log,
+ gpointer user_data)
+{
+ LogviewManager *manager = user_data;
+
+ g_signal_emit (manager, signals[LOG_CHANGED], 0, log, NULL);
}
static void
@@ -132,6 +162,9 @@
/* creation went well, store the log and notify */
g_hash_table_insert (data->manager->priv->logs, data->filename, log);
+ g_signal_connect (log, "log-changed",
+ G_CALLBACK (log_changed_cb), data->manager);
+
g_signal_emit (data->manager, signals[LOG_ADDED], 0, log, NULL);
if (data->set_active) {
@@ -161,6 +194,44 @@
return FALSE;
}
+static void
+log_new_lines_cb (LogviewLog *log,
+ char **lines,
+ GError *error,
+ gpointer user_data)
+{
+ LogviewManager *manager = user_data;
+ LogviewManagerPrivate *priv = manager->priv;
+ GPtrArray *arr;
+ int i;
+
+ if (error) {
+ /* TODO: handle this */
+ return;
+ }
+
+ arr = g_hash_table_lookup (priv->lines_cache, log);
+ if (!arr) {
+ arr = g_ptr_array_new ();
+ g_hash_table_insert (priv->lines_cache, log, arr);
+ }
+ for (i = 0; i; i++) {
+ g_ptr_array_add (arr, lines[i]);
+ }
+
+ g_signal_emit (singleton, signals[LOG_CHANGED], 0, log, NULL);
+}
+
+static void
+active_log_changed_cb (LogviewLog *log,
+ gpointer user_data)
+{
+ LogviewManager *manager = user_data;
+ gboolean first_read = FALSE;
+
+ logview_log_read_new_lines (log, log_new_lines_cb, &first_read);
+}
+
/* public methods */
LogviewManager*
@@ -177,6 +248,8 @@
logview_manager_set_active_log (LogviewManager *manager,
LogviewLog *log)
{
+ gboolean first_read = TRUE;
+
g_assert (LOGVIEW_IS_MANAGER (manager));
if (manager->priv->active_log) {
@@ -184,7 +257,12 @@
}
manager->priv->active_log = g_object_ref (log);
+
g_signal_emit (manager, signals[ACTIVE_CHANGED], 0, log, NULL);
+
+ logview_log_read_new_lines (log, log_new_lines_cb, manager);
+
+ /* we will emit the "active-changed" signal when we have the new lines */
}
LogviewLog *
@@ -268,10 +346,40 @@
/* we own two refs to the active log; one is inside the hash table */
g_object_unref (active_log);
+ g_hash_table_remove (manager->priv->lines_cache, active_log);
+ g_signal_handlers_disconnect_by_func (active_log, active_log_changed_cb, manager);
g_hash_table_find (manager->priv->logs,
(GHRFunc) look_for_log,
active_log);
/* someone else will take care of setting the next active log to us */
+}
+
+const char **
+logview_manager_get_lines_for_active_log (LogviewManager *manager)
+{
+ const char **retval;
+ GPtrArray *arr;
+
+ g_assert (LOGVIEW_IS_MANAGER (manager));
+
+ arr = g_hash_table_lookup (manager->priv->lines_cache, manager->priv->active_log);
+ if (!arr) {
+ /* why? */
+ return NULL;
+ }
+
+ retval = (const char **) arr->pdata;
+
+ return retval;
+}
+
+gboolean
+logview_manager_log_is_active (LogviewManager *manager,
+ LogviewLog *log)
+{
+ g_assert (LOGVIEW_IS_MANAGER (manager));
+
+ return (manager->priv->active_log == log);
}
\ No newline at end of file
Modified: trunk/logview/logview-manager.h
==============================================================================
--- trunk/logview/logview-manager.h (original)
+++ trunk/logview/logview-manager.h Tue Dec 23 13:25:36 2008
@@ -57,6 +57,8 @@
LogviewLog *log);
void (* log_closed) (LogviewManager *manager,
LogviewLog *log);
+ void (* log_changed) (LogviewManager *manager,
+ LogviewLog *log);
void (* log_add_error) (LogviewManager *manager,
char *filename);
void (* active_changed) (LogviewManager *manager,
@@ -80,6 +82,7 @@
LogviewLog * logview_manager_get_if_loaded (LogviewManager *manager,
char *filename);
void logview_manager_close_active_log (LogviewManager *manager);
+const char ** logview_manager_get_lines_for_active_log (LogviewManager *manager);
G_END_DECLS
Added: trunk/logview/logview-utils.c
==============================================================================
--- (empty file)
+++ trunk/logview/logview-utils.c Tue Dec 23 13:25:36 2008
@@ -0,0 +1,230 @@
+/* logview-utils.c
+ *
+ * Copyright (C) 1998 Cesar Miquel <miquel df uba ar>
+ * Copyright (C) 2008 Cosimo Cecchi <cosimoc gnome org>
+ *
+ * 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., 551 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ */
+
+#define _XOPEN_SOURCE
+#include <time.h>
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include <glib.h>
+
+#include "logview-utils.h"
+
+static gint
+days_compare (gconstpointer a, gconstpointer b)
+{
+ const Day *day1 = a, *day2 = b;
+ return (g_date_compare (day1->date, day2->date));
+}
+
+static GDate *
+string_get_date (char *line)
+{
+ GDate *date;
+ struct tm tp;
+ char *cp;
+
+ if (line == NULL || line[0] == 0)
+ return NULL;
+
+ cp = strptime (line, "%b %d", &tp);
+ if (cp == NULL) {
+ cp = strptime (line, "%F", &tp);
+ if (cp == NULL) {
+ return NULL;
+ }
+ }
+
+ date = g_date_new_dmy (tp.tm_mday, tp.tm_mon+1, 70);
+ return date;
+}
+
+static gchar *
+string_get_date_string (gchar *line)
+{
+ gchar **split, *date_string;
+ gchar *month=NULL, *day=NULL;
+ int i=0;
+
+ if (line == NULL || line[0] == 0)
+ return NULL;
+
+ split = g_strsplit (line, " ", 4);
+ if (split == NULL)
+ return NULL;
+
+ while ((day == NULL || month == NULL) && split[i]!=NULL && i<4) {
+ if (g_str_equal (split[i], "")) {
+ i++;
+ continue;
+ }
+
+ if (month == NULL) {
+ month = split[i++];
+ /* If the first field begins by a number, the date
+ is given in yyyy-mm-dd format */
+ if (!g_ascii_isalpha (month[0]))
+ break;
+ continue;
+ }
+
+ if (day == NULL)
+ day = split[i];
+ i++;
+ }
+
+ if (i==3)
+ date_string = g_strconcat (month, " ", day, NULL);
+ else
+ date_string = g_strconcat (month, " ", day, NULL);
+ g_strfreev (split);
+ return (date_string);
+}
+
+/* log_read_dates
+ Read all dates which have a log entry to create calendar.
+ All dates are given with respect to the 1/1/1970
+ and are then corrected to the correct year once we
+ reach the end.
+*/
+
+GSList *
+log_read_dates (gchar **buffer_lines, time_t current)
+{
+ int offsetyear = 0, current_year;
+ GSList *days = NULL, *days_copy;
+ GDate *date, *newdate;
+ struct tm *tmptm;
+ gchar *date_string;
+ Day *day;
+ gboolean done = FALSE;
+ int i, n, rangemin, rangemax;
+
+ if (buffer_lines == NULL)
+ return NULL;
+
+ n = g_strv_length (buffer_lines);
+
+ tmptm = localtime (¤t);
+ current_year = tmptm->tm_year + 1900;
+
+ for (i=0; buffer_lines[i]==NULL; i++);
+
+ /* Start building the list */
+ /* Scanning each line to see if the date changed is too slow, so we proceed
+ in a recursive fashion */
+
+ date = string_get_date (buffer_lines[i]);
+ if ((date==NULL)|| !g_date_valid (date))
+ return NULL;
+
+ g_date_set_year (date, current_year);
+ day = g_new (Day, 1);
+ days = g_slist_append (days, day);
+
+ day->date = date;
+ day->first_line = i;
+ day->last_line = -1;
+ date_string = string_get_date_string (buffer_lines[i]);
+
+ rangemin = 0;
+ rangemax = n-1;
+
+ while (!done) {
+ i = n-1;
+ while (day->last_line < 0) {
+ if (g_str_has_prefix (buffer_lines[i], date_string)) {
+ if (i == (n-1)) {
+ day->last_line = i;
+ done = TRUE;
+ break;
+ } else {
+ if (!g_str_has_prefix (buffer_lines[i+1], date_string)) {
+ day->last_line = i;
+ break;
+ } else {
+ rangemin = i;
+ i = floor ( ((float) i + (float) rangemax)/2.);
+ }
+ }
+ } else {
+ rangemax = i;
+ i = floor (((float) rangemin + (float) i)/2.);
+ }
+ }
+
+ g_free (date_string);
+
+ if (!done) {
+ /* We need to find the first line now that has a date
+ Logs can have some messages without dates ... */
+ newdate = NULL;
+ while (newdate == NULL && !done) {
+ i++;
+ date_string = string_get_date_string (buffer_lines[i]);
+ if (date_string == NULL)
+ if (i==n-1) {
+ done = TRUE;
+ break;
+ } else
+ continue;
+ newdate = string_get_date (buffer_lines[i]);
+
+ if (newdate == NULL && i==n-1)
+ done = TRUE;
+ }
+
+ day->last_line = i-1;
+
+ /* Append a day to the list */
+ if (newdate) {
+ g_date_set_year (newdate, current_year + offsetyear);
+ if (g_date_compare (newdate, date) < 1) {
+ offsetyear++; /* newdate is next year */
+ g_date_add_years (newdate, 1);
+ }
+
+ date = newdate;
+ day = g_new (Day, 1);
+ days = g_slist_append (days, day);
+
+ day->date = date;
+ day->first_line = i;
+ day->last_line = -1;
+ rangemin = i;
+ rangemax = n;
+ }
+ }
+ }
+
+ /* Correct years now. We assume that the last date on the log
+ is the date last accessed */
+
+ for (days_copy = days; days_copy != NULL; days_copy = g_slist_next (days_copy)) {
+ day = days_copy -> data;
+ g_date_subtract_years (day->date, offsetyear);
+ }
+
+ /* Sort the days in chronological order */
+ days = g_slist_sort (days, days_compare);
+
+ return (days);
+}
\ No newline at end of file
Added: trunk/logview/logview-utils.h
==============================================================================
--- (empty file)
+++ trunk/logview/logview-utils.h Tue Dec 23 13:25:36 2008
@@ -0,0 +1,33 @@
+/* logview-utils.c
+ *
+ * Copyright (C) 1998 Cesar Miquel <miquel df uba ar>
+ * Copyright (C) 2008 Cosimo Cecchi <cosimoc gnome org>
+ *
+ * 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., 551 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ */
+
+#ifndef __LOGVIEW_UTILS_H__
+#define __LOGVIEW_UTILS_H__
+
+#include <glib.h>
+
+typedef struct {
+ GDate *date;
+ long first_line, last_line; /* First and last line for this day in the log */
+} Day;
+
+GSList * log_read_dates (gchar **buffer_lines, time_t current);
+
+#endif /* __LOGVIEW_UTILS_H__ */
\ No newline at end of file
Modified: trunk/logview/logview.c
==============================================================================
--- trunk/logview/logview.c (original)
+++ trunk/logview/logview.c Tue Dec 23 13:25:36 2008
@@ -63,6 +63,8 @@
GtkWidget *version_selector;
GtkWidget *hpaned;
+ GtkTreeModel *model;
+
int original_fontsize, fontsize;
LogviewPrefs *prefs;
@@ -137,10 +139,8 @@
logview_store_visible_range (logview);
- logview->curlog = log;
- logview_menus_set_state (logview);
logview_calendar_set_state (logview);
- logview_repaint (logview);
+
logview_update_findbar_visibility (logview);
logview_update_version_bar (logview);
@@ -226,6 +226,40 @@
/* private helpers */
+static void
+logview_update_statusbar (LogviewWindow *logview, LogviewLog *active)
+{
+ char *statusbar_text;
+ char *size, *modified, *index;
+
+ g_assert (LOGVIEW_IS_WINDOW (logview));
+
+ if (active == NULL) {
+ gtk_statusbar_pop (GTK_STATUSBAR (logview->priv->statusbar), 0);
+ return;
+ }
+
+ /* ctime returned string has "\n\0" causes statusbar display a invalid char */
+ modified = ctime (&(logview_log_get_timestamp (active)));
+ index = strrchr (modified, '\n');
+ if (index && *index != '\0')
+ *index = '\0';
+
+ modified = g_strdup_printf (_("last update: %s"), modified);
+
+ size = g_format_size_for_display (logview_log_get_file_size (active));
+ statusbar_text = g_strdup_printf (_("%d lines (%s) - %s"),
+ log->total_lines, size, modified);
+
+ if (statusbar_text) {
+ gtk_statusbar_pop (GTK_STATUSBAR (logview->priv->statusbar), 0);
+ gtk_statusbar_push (GTK_STATUSBAR (logview->priv->statusbar), 0, statusbar_text);
+ g_free (size);
+ g_free (modified);
+ g_free (statusbar_text);
+ }
+}
+
#define DEFAULT_LOGVIEW_FONT "Monospace 10"
static void
@@ -300,7 +334,7 @@
g_assert (LOGVIEW_IS_WINDOW (logview));
- log = logview_manager_get_current_log (logview->priv->manager);
+ log = logview_manager_get_active_log (logview->priv->manager);
if (log) {
calendar_active = (log->days != NULL);
@@ -627,9 +661,10 @@
{
LogviewWindow *window = data;
-
- /* update the tile for the new log */
- logview_set_window_title (window, logview_log_get_display_name (log));
+ /* destroy the model */
+ gtk_tree_view_set_model (window->priv->view, NULL);
+ g_object_unref (window->priv->model);
+ window->priv->model = NULL;
}
static void
@@ -644,7 +679,6 @@
static void
logview_window_init (LogviewWindow *logview)
{
- GtkTreeStore *tree_store;
GtkTreeSelection *selection;
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
Modified: trunk/logview/misc.c
==============================================================================
--- trunk/logview/misc.c (original)
+++ trunk/logview/misc.c Tue Dec 23 13:25:36 2008
@@ -132,28 +132,6 @@
return out;
}
-GDate *
-string_get_date (char *line)
-{
- GDate *date;
- struct tm tp;
- char *cp;
-
- if (line == NULL || line[0] == 0)
- return NULL;
-
- cp = strptime (line, "%b %d", &tp);
- if (cp == NULL) {
- cp = strptime (line, "%F", &tp);
- if (cp == NULL) {
- return NULL;
- }
- }
-
- date = g_date_new_dmy (tp.tm_mday, tp.tm_mon+1, 70);
- return date;
-}
-
char *
date_get_string (GDate *date)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]