Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=gfpm.git;a=commitdiff;h=f583761a904c9350980075709bd381249f29e080

commit f583761a904c9350980075709bd381249f29e080
Author: Priyank <[EMAIL PROTECTED]>
Date:   Sun Jan 27 16:28:36 2008 +0530

gfpm-logviewer: good! we have a partially working pacman-g2 log viewer

diff --git a/src/gfpm-interface.c b/src/gfpm-interface.c
index a697ffe..7748e55 100644
--- a/src/gfpm-interface.c
+++ b/src/gfpm-interface.c
@@ -42,6 +42,7 @@
#include "gfpm-quickpane.h"
#include "gfpm-icmonitor.h"
#include "gfpm-repomanager.h"
+#include "gfpm-logviewer.h"
#include "gfpm-util.h"
#include "gfpm-about.h"
#include "gfpm-db.h"
@@ -268,6 +269,9 @@ gfpm_interface_init (void)
/* about */
g_signal_connect (G_OBJECT(glade_xml_get_widget(xml, "about_gfpm1")), 
"activate", G_CALLBACK(gfpm_about), NULL);

+       /* syslog */
+       g_signal_connect (G_OBJECT(glade_xml_get_widget(xml, "syslog1")), 
"activate", G_CALLBACK(gfpm_logviewer_show), NULL);
+
/* repository manager */
g_signal_connect (G_OBJECT(glade_xml_get_widget(xml, "repos")), "activate", 
G_CALLBACK(gfpm_repomanager_show), NULL);

@@ -300,7 +304,8 @@ gfpm_interface_init (void)
gfpm_quickpane_init ();
gfpm_icmonitor_init ();
gfpm_repomanager_init ();
-
+       gfpm_logviewer_init ();
+
gtk_widget_hide (gfpm_splash);
title = g_strdup_printf ("%s (%s)", PACKAGE_STRING, GFPM_RELEASE_NAME);
gtk_window_set_title (GTK_WINDOW(gfpm_mw), title);
diff --git a/src/gfpm-logviewer.c b/src/gfpm-logviewer.c
index 6d25925..ee5e170 100644
--- a/src/gfpm-logviewer.c
+++ b/src/gfpm-logviewer.c
@@ -22,22 +22,162 @@
#include "gfpm-messages.h"
#include <glib.h>

+typedef struct _LogViewItem
+{
+       gchar           *label;
+       GList           *children;
+} LogViewItem;
+
#define LOG_FILE "/var/log/pacman-g2.log"

extern GladeXML *xml;

+int getdate_err;

/* Log viewer widgets */
+static GtkWidget *gfpm_logviewer_dlg;
+static GtkWidget *gfpm_logviewer_tvw;
+static GtkWidget *gfpm_logviewer_txtvw;
+
+static void _gfpm_logviewer_populate (void);

void
gfpm_logviewer_init (void)
{
+        gint col_offset;
+        GtkCellRenderer *renderer;
+        GtkTreeViewColumn *column;
+
+        gfpm_logviewer_dlg = glade_xml_get_widget (xml, "syslog_window");
+        gfpm_logviewer_tvw = glade_xml_get_widget (xml, "log_tvw");
+        gfpm_logviewer_txtvw = glade_xml_get_widget (xml, "log_txtvw");
+
+        renderer = gtk_cell_renderer_text_new ();
+        g_object_set (renderer, "xalign", 0.0, NULL);
+        col_offset = gtk_tree_view_insert_column_with_attributes 
(GTK_TREE_VIEW (gfpm_logviewer_tvw),
+                                                           -1, "Month / Year",
+                                                           renderer, "text",
+                                                           0,
+                                                           NULL);
+       column = gtk_tree_view_get_column (GTK_TREE_VIEW (gfpm_logviewer_tvw), 
col_offset - 1);
+       gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), 
TRUE);
+
return;
}

void
gfpm_logviewer_show ()
{
+       gtk_widget_show (gfpm_logviewer_dlg);
+       _gfpm_logviewer_populate ();
+
+       return;
+}
+
+static void
+_gfpm_logviewer_populate (void)
+{
+       FILE                    *fp = NULL;
+       char                    line[PATH_MAX+1] = "";
+       int                             prev_day = -1;
+       int                             prev_month = -1;
+       int                             prev_year = -1;
+       GtkTreeStore    *store;
+       GtkTreeIter             iter;
+       GList                   *master = NULL;
+       GList                   *child = NULL;
+       LogViewItem     *li = NULL;
+
+       if ((fp=fopen(LOG_FILE,"r"))==NULL)
+       {
+               gfpm_error (_("Error"), _("Error opening log file."));
+               return;
+       }
+       while (fgets(line,PATH_MAX,fp))
+       {
+               char *ptr = NULL;
+
+               fwutil_trim (line);
+               if (!strlen(line))
+                       continue;
+               if (line[0] == '[' && line[15] == ']')
+               {
+                       int i;
+                       struct tm *t;
+
+                       ptr = line;
+                       ptr++;
+                       ptr[14] = 0;
+                       t = getdate (ptr);
+                       if (t!=NULL)
+                       {
+                               if (prev_year != (t->tm_year+1900))
+                               {
+                                       prev_year = (t->tm_year+1900);
+                                       if (prev_month != (t->tm_mon+1))
+                                       {
+                                               char day[64] = "";
+                                               strftime (day, 64, "%B %Y", t);
+                                               prev_month = t->tm_mon+1;
+                                               li = (LogViewItem*) 
malloc(sizeof(LogViewItem));
+
+                                               prev_month = t->tm_mon+1;
+                                               li->label = g_strdup (day);
+                                               li->children = NULL;
+                                               master = g_list_append (master, 
(gpointer)li);
+                                       }
+                               }
+                               if (prev_month != (t->tm_mon+1))
+                               {
+                                       char day[64] = "";
+                                       strftime (day, 64, "%B %Y", t);
+                                       li = (LogViewItem*) 
malloc(sizeof(LogViewItem));
+                                       prev_month = t->tm_mon+1;
+                                       li->label = g_strdup (day);
+                                       li->children = NULL;
+                                       master = g_list_append (master, 
(gpointer)li);
+                               }
+                               if (prev_day != t->tm_mday)
+                               {
+                                       char    day[64] = "";
+                                       strftime (day, 64, "%a %d %b %Y", t);
+                                       li->children = g_list_append 
(li->children, (gpointer)(g_strdup(day)));
+                                       prev_day = t->tm_mday;
+                               }
+                               while (gtk_events_pending())
+                                       gtk_main_iteration ();
+                       }
+                       else
+                       {
+                               printf ("ERROR: getdate() failed with error 
code: %d\n", getdate_err);
+                       }
+               }
+       }
+       fclose (fp);
+
+       /* add the master list */
+       store = gtk_tree_store_new (1, G_TYPE_STRING);
+
+       while (master != NULL)
+       {
+               LogViewItem *m = master->data;
+               //printf ("SECTION : %s\n", m->label);
+               gtk_tree_store_append (store, &iter, NULL);
+               gtk_tree_store_set (store, &iter, 0, m->label, -1);
+               /* add children */
+               GList *child = m->children;
+               while (child != NULL)
+               {
+                       GtkTreeIter     child_iter;
+                       //printf ("\tSUB: %s\n", child->data);
+                       gtk_tree_store_append (store, &child_iter, &iter);
+                       gtk_tree_store_set (store, &child_iter, 0, child->data, 
-1);
+                       child = g_list_next (child);
+               }
+               master = g_list_next (master);
+       }
+       gtk_tree_view_set_model (GTK_TREE_VIEW(gfpm_logviewer_tvw), 
GTK_TREE_MODEL(store));
+
return;
}

diff --git a/src/gfpm-logviewer.h b/src/gfpm-logviewer.h
index 0f16751..50c45a1 100644
--- a/src/gfpm-logviewer.h
+++ b/src/gfpm-logviewer.h
@@ -8,8 +8,6 @@
#include <locale.h>
#include <libintl.h>
#include <gtk/gtk.h>
-#include <libfwutil.h>
-#include "gfpm.h"

void gfpm_logviewer_init (void);
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to