source: trunk/third/gnome-utils/logview/logview.c @ 18641

Revision 18641, 25.3 KB checked in by ghudson, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18640, which included commits to RCS files with non-trunk default branches.
Line 
1#ifndef GNOMELOCALEDIR
2#define GNOMELOCALEDIR "/usr/share/locale"
3#endif
4/*  ----------------------------------------------------------------------
5
6    Copyright (C) 1998  Cesar Miquel  (miquel@df.uba.ar)
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22    ---------------------------------------------------------------------- */
23
24
25#include <config.h>
26#include <gnome.h>
27#include <gconf/gconf-client.h>
28#include <unistd.h>
29#include <time.h>
30#include <sys/stat.h>
31#include "logview.h"
32#include <libgnomeui/gnome-window-icon.h>
33
34/*
35 *    -------------------
36 *    Function Prototypes
37 *    -------------------
38 */
39
40void CreateMainWin (void);
41gboolean log_repaint (void);
42gboolean handle_log_mouse_button (GtkWidget *view, GdkEventButton *event);
43void ExitProg (GtkWidget * widget, gpointer user_data);
44void LoadLogMenu (GtkWidget * widget, gpointer user_data);
45void CloseLogMenu (GtkWidget * widget, gpointer user_data);
46void change_log_menu (GtkWidget * widget, gpointer user_data);
47void CalendarMenu (GtkWidget * widget, gpointer user_data);
48void MonitorMenu (GtkWidget* widget, gpointer user_data);
49void create_zoom_view (void);
50void AboutShowWindow (GtkWidget* widget, gpointer user_data);
51void CloseApp (void);
52void CloseLog (Log *);
53void FileSelectCancel (GtkWidget * w, GtkFileSelection * fs);
54void FileSelectOk (GtkWidget * w, GtkFileSelection * fs);
55void LogInfo (GtkWidget * widget, gpointer user_data);
56void UpdateStatusArea (void);
57void change_log (int dir);
58void open_databases (void);
59void destroy (void);
60void InitApp (void);
61int InitPages (void);
62int RepaintLogInfo (void);
63int read_regexp_db (char *filename, GList **db);
64int read_actions_db (char *filename, GList **db);
65void print_db (GList *gb);
66Log *OpenLogFile (char *);
67GtkWidget *new_pixmap_from_data (char  **, GdkWindow *, GdkColor *);
68void SaveUserPrefs(UserPrefsStruct *prefs);
69void close_zoom_view (GtkWidget *widget, gpointer client_data);
70void handle_selection_changed_cb (GtkTreeSelection *selection, gpointer data);
71void handle_row_activation_cb (GtkTreeView *treeview, GtkTreePath *path,
72     GtkTreeViewColumn *arg2, gpointer user_data);
73void save_rows_to_expand (Log *log);
74void CloseAllLogs (void);
75
76static void toggle_calendar (void);
77static void toggle_zoom (void);
78static void toggle_collapse_rows (void);
79
80/*
81 *    ,-------.
82 *    | Menus |
83 *    `-------'
84 */
85
86enum {
87        MENU_FILE_OPEN = 0,
88        MENU_SWITCH_LOG = 2,
89        MENU_MONITOR = 3,
90        MENU_PROPERTIES = 5,
91        MENU_CLOSE = 7,
92        MENU_CLOSE_ALL = 8,
93        MENU_QUIT = 9
94};
95
96GnomeUIInfo log_menu[] = {
97        GNOMEUIINFO_MENU_OPEN_ITEM(LoadLogMenu, NULL),
98        GNOMEUIINFO_SEPARATOR,
99    { GNOME_APP_UI_ITEM, N_("S_witch Log"),
100                         N_("Switch between already opened logs"),
101                         change_log_menu,
102                         NULL, NULL,
103                         GNOME_APP_PIXMAP_NONE, NULL,
104                         'N', GDK_CONTROL_MASK, NULL },
105
106    { GNOME_APP_UI_ITEM, N_("_Monitor..."),
107                         N_("Monitor Logs"),
108                         MonitorMenu,
109                         NULL,
110                         NULL,
111                         GNOME_APP_PIXMAP_NONE, NULL,
112                         'M', GDK_CONTROL_MASK, NULL },
113 
114        GNOMEUIINFO_SEPARATOR,
115    { GNOME_APP_UI_ITEM, N_("_Properties"),
116                                N_("Show Log Properties"),
117                                LogInfo,
118                                NULL,
119                                NULL,
120                                GNOME_APP_PIXMAP_NONE, NULL,
121                                'I', GDK_CONTROL_MASK, NULL },
122        GNOMEUIINFO_SEPARATOR,
123        GNOMEUIINFO_MENU_CLOSE_ITEM (CloseLogMenu, NULL),
124    { GNOME_APP_UI_ITEM, N_("Clos_e All"),
125                                N_("Close all Log files"),
126                                CloseAllLogs,
127                                NULL,
128                                NULL,
129                                GNOME_APP_PIXMAP_STOCK,
130                                GNOME_STOCK_MENU_CLOSE,
131                                'W', GDK_CONTROL_MASK | GDK_SHIFT_MASK, NULL },
132        GNOMEUIINFO_MENU_QUIT_ITEM (ExitProg, NULL),
133    GNOMEUIINFO_END
134};
135
136GnomeUIInfo view_menu[] = {
137        { GNOME_APP_UI_TOGGLEITEM, N_("_Calendar"),
138                                N_("Show Calendar Log"),
139                                toggle_calendar,
140                                NULL,
141                                NULL,
142                                GNOME_APP_PIXMAP_NONE, NULL,
143                                'L', GDK_CONTROL_MASK, NULL },
144        { GNOME_APP_UI_TOGGLEITEM, N_("_Entry Detail"),
145                                N_("Show Entry Detail"),
146                                toggle_zoom,
147                                NULL,
148                                NULL,
149                                GNOME_APP_PIXMAP_NONE, NULL,
150                                'D', GDK_CONTROL_MASK, NULL },
151        { GNOME_APP_UI_ITEM, N_("_Collapse All"),
152                                N_("Collapse all the rows"),
153                                toggle_collapse_rows,
154                                NULL,
155                                NULL,
156                                GNOME_APP_PIXMAP_NONE, NULL,
157                                'C', GDK_CONTROL_MASK, NULL },
158        GNOMEUIINFO_END
159};
160
161GnomeUIInfo help_menu[] = {
162      GNOMEUIINFO_HELP ("gnome-system-log"),
163      GNOMEUIINFO_MENU_ABOUT_ITEM (AboutShowWindow, NULL),
164      GNOMEUIINFO_END
165};
166
167GnomeUIInfo main_menu[] = {
168        GNOMEUIINFO_MENU_FILE_TREE (log_menu),
169        GNOMEUIINFO_MENU_VIEW_TREE (view_menu),
170        GNOMEUIINFO_MENU_HELP_TREE (help_menu),
171        GNOMEUIINFO_END
172};
173                 
174
175/*
176 *       ----------------
177 *       Global variables
178 *       ----------------
179 */
180       
181GtkWidget *app = NULL;
182static GtkWidget *viewport;
183GtkLabel *date_label = NULL;
184
185GList *regexp_db = NULL, *descript_db = NULL, *actions_db = NULL;
186UserPrefsStruct *user_prefs = NULL;
187UserPrefsStruct user_prefs_struct = {0};
188ConfigData *cfg = NULL;
189GtkWidget *open_file_dialog = NULL;
190GtkWidget *view = NULL;
191
192GConfClient *client;
193poptContext poptCon;
194gint next_opt;
195
196struct poptOption options[] = { {
197        "file",
198        'f',
199        POPT_ARG_STRING,
200        NULL,
201        1,
202        NULL,
203        NULL,
204} };
205
206extern GtkWidget *CalendarDialog;
207extern GtkWidget *zoom_dialog;
208extern Log *curlog, *loglist[];
209extern int numlogs, curlognum;
210extern int loginfovisible, calendarvisible;
211extern int cursor_visible;
212extern int zoom_visible;
213
214/* ----------------------------------------------------------------------
215   NAME:          destroy
216   DESCRIPTION:   Exit program.
217   ---------------------------------------------------------------------- */
218
219void
220destroy (void)
221{
222   CloseApp ();
223}
224
225static gint
226save_session (GnomeClient *gclient, gint phase,
227              GnomeRestartStyle save_style, gint shutdown,
228              GnomeInteractStyle interact_style, gint fast,
229              gpointer client_data)
230{
231   gchar **argv;
232   gint i;
233
234   argv = g_malloc0 (sizeof (gchar *) * (numlogs+1));
235   argv[0] = (gchar *) client_data;
236   for ( i = 1; i <= numlogs; i++)
237       argv[i] = g_strconcat ("--file=", loglist[i-1]->name, NULL);
238   
239   gnome_client_set_clone_command (gclient, numlogs+1, argv);
240   gnome_client_set_restart_command (gclient, numlogs+1, argv);
241
242   g_free (argv);
243
244   return TRUE;
245
246}
247
248static gboolean
249restore_session (void)
250{
251   Log *tl;
252   gint i, logcnt = 0;
253
254   /* closing the log file opened by default */
255   CloseLog (loglist[0]);
256   curlog = NULL;
257   loglist[0] = NULL;
258   curlognum = 0;
259   log_repaint ();
260   if (loginfovisible)
261       RepaintLogInfo ();
262   numlogs = 0;
263
264   next_opt = poptGetNextOpt (poptCon);
265
266   do {
267      if ( next_opt == 1) {
268         gchar *f = (gchar *) poptGetOptArg (poptCon);
269         if (f != NULL) {
270            if ((tl = OpenLogFile (f)) != NULL) {
271               curlog = tl;
272               loglist[numlogs] = tl;
273               numlogs++;
274               curlognum = numlogs - 1;
275            }
276         }
277         if (f)
278            g_free (f);
279      }
280   } while ((next_opt = poptGetNextOpt (poptCon)) != -1);
281}
282
283static gint
284die (GnomeClient *gclient, gpointer client_data)
285{
286    gtk_main_quit ();
287}
288
289/* ----------------------------------------------------------------------
290   NAME:          main
291   DESCRIPTION:   Program entry point.
292   ---------------------------------------------------------------------- */
293
294int
295main (int argc, char *argv[])
296{
297   GnomeClient *gclient;
298
299   bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
300   bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
301   textdomain(GETTEXT_PACKAGE);
302
303   QueueErrMessages (TRUE);
304
305   /*  Initialize gnome & gtk */
306   gnome_program_init ("gnome-system-log",VERSION, LIBGNOMEUI_MODULE, argc, argv,
307                           GNOME_PARAM_APP_DATADIR, DATADIR, NULL);
308
309   gnome_window_icon_set_default_from_file (GNOME_ICONDIR"/gnome-log.png");
310   
311   poptCon = poptGetContext ("gnome-system-log", argc, (const gchar **) argv,
312                                                         options, 0); 
313   gclient = gnome_master_client ();
314   g_signal_connect (gclient, "save_yourself",
315                                         G_CALLBACK (save_session), (gpointer)argv[0]);
316   g_signal_connect (gclient, "die", G_CALLBACK (die), NULL);
317
318   gconf_init (argc, argv, NULL);
319   client = gconf_client_get_default ();
320   
321   /*  Load graphics config */
322   cfg = CreateConfig();
323   
324   InitApp ();
325
326   log_repaint ();
327
328   QueueErrMessages (FALSE);
329   ShowQueuedErrMessages ();
330   
331   if (gnome_client_get_flags (gclient) & GNOME_CLIENT_RESTORED) {
332          restore_session ();
333   }
334
335   /*  Loop application */
336   gtk_main ();
337   
338   SaveUserPrefs(user_prefs);
339
340   return 0;
341
342}
343
344/* ----------------------------------------------------------------------
345   NAME:        InitApp
346   DESCRIPTION: Main initialization routine.
347   ---------------------------------------------------------------------- */
348
349void
350InitApp ()
351{
352   loginfovisible = FALSE;
353   regexp_db = NULL;
354   user_prefs = &user_prefs_struct;
355   SetDefaultUserPrefs(user_prefs);
356
357   /*  Display main window */
358   CreateMainWin ();
359
360   /* Read databases */
361   open_databases ();
362
363   /*  Read files and init data. */
364   if (InitPages () < 0)
365         ShowErrMessage (_("No log files to open"));
366
367}
368
369/* ----------------------------------------------------------------------
370   NAME:        CreateMainWin
371   DESCRIPTION: Creates the main window.
372   ---------------------------------------------------------------------- */
373
374void
375CreateMainWin ()
376{
377   GtkWidget *w, *vbox, *table, *hbox, *hbox_date;
378   GtkWidget *padding;
379   GtkLabel *label;
380   GtkObject *adj;
381   GtkAllocation req_size;
382   GtkTreeStore *tree_store;
383   GtkTreeSelection *selection;
384   GtkTreeViewColumn *column;
385   GtkCellRenderer *renderer;
386   GtkWidget *scrolled_window = NULL;
387   gint i;
388   gchar *window_title;
389   const gchar *column_titles[] = { N_("Date"), N_("Host Name"),
390                                    N_("Process"), N_("Message"), NULL };
391
392   /* Create App */
393
394   if ((curlog != NULL) && (numlogs))
395       window_title = g_strdup_printf ("%s - %s", curlog->name, APP_NAME);
396   else
397       window_title = g_strdup_printf (APP_NAME);
398   app = gnome_app_new ("gnome-system-log", window_title);
399   g_free (window_title);
400
401   gtk_container_set_border_width ( GTK_CONTAINER (app), 0);
402   gtk_window_set_default_size ( GTK_WINDOW (app), LOG_CANVAS_W, LOG_CANVAS_H);
403   req_size.x = req_size.y = 0;
404   req_size.width = 400;
405   req_size.height = 400;
406   gtk_widget_size_allocate ( GTK_WIDGET (app), &req_size );
407   gtk_signal_connect (GTK_OBJECT (app), "destroy",
408                       GTK_SIGNAL_FUNC (destroy), NULL);
409
410   /* Create menus */
411   gnome_app_create_menus (GNOME_APP (app), main_menu);
412
413   vbox = gtk_vbox_new (FALSE, 0);
414   gnome_app_set_contents (GNOME_APP (app), vbox);
415
416   if (numlogs < 2)
417     gtk_widget_set_state (log_menu[MENU_SWITCH_LOG].widget, GTK_STATE_INSENSITIVE);
418
419   /* Create scrolled window and tree view */
420   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
421   gtk_widget_set_sensitive (scrolled_window, TRUE);
422   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
423               GTK_POLICY_AUTOMATIC,
424               GTK_POLICY_AUTOMATIC);
425   gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
426
427   /* Create Tree View */
428   tree_store = gtk_tree_store_new (4,
429                G_TYPE_STRING, G_TYPE_STRING,
430                G_TYPE_STRING, G_TYPE_STRING);
431
432   view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (tree_store));
433   gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
434   g_object_unref (G_OBJECT (tree_store));
435   
436   /* Add Tree View Columns */
437   for (i = 0; column_titles[i]; i++) {
438        renderer = gtk_cell_renderer_text_new ();
439        column = gtk_tree_view_column_new_with_attributes (column_titles[i],
440                    renderer, "text", i, NULL);
441        gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
442        gtk_tree_view_column_set_resizable (column, TRUE);
443        gtk_tree_view_column_set_spacing (column, GNOME_PAD_SMALL);
444        gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
445   }
446
447   gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (view));
448   gtk_widget_show_all (scrolled_window);
449
450   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
451   gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
452
453   /* Add signal handlers */
454   g_signal_connect (G_OBJECT (selection), "changed",
455                     G_CALLBACK (handle_selection_changed_cb), NULL);
456
457   g_signal_connect (G_OBJECT (view), "row_activated",
458                     G_CALLBACK (handle_row_activation_cb), NULL);
459
460   /* Create status area at bottom */
461   hbox = gtk_hbox_new (FALSE, 2);
462   gtk_container_set_border_width ( GTK_CONTAINER (hbox), 3);
463
464   hbox_date = gtk_hbox_new (FALSE, 2);
465   gtk_container_set_border_width ( GTK_CONTAINER (hbox_date), 3);
466
467   date_label = (GtkLabel *)gtk_label_new ("");
468   gtk_widget_show (GTK_WIDGET (date_label));
469   /* gtk_widget_set_size_request (GTK_WIDGET (label), 60, -1); */
470   gtk_box_pack_end (GTK_BOX (hbox_date), GTK_WIDGET (date_label),
471                     TRUE, TRUE, 0);
472
473
474   label = (GtkLabel *)gtk_label_new (_("Last Modified: "));
475   gtk_label_set_justify (label, GTK_JUSTIFY_RIGHT);
476   gtk_box_pack_end (GTK_BOX (hbox_date), GTK_WIDGET (label),
477                     FALSE, FALSE, 0);
478   gtk_widget_show (GTK_WIDGET (label)); 
479
480
481   gtk_widget_show (hbox_date);
482   gtk_box_pack_end (GTK_BOX (hbox), hbox_date, FALSE, FALSE, 0);
483   gtk_widget_show (hbox);
484   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
485
486   gtk_widget_show (vbox);
487   gtk_widget_show_now (app);
488
489}
490
491/* ----------------------------------------------------------------------
492   NAME:          CloseLogMenu
493   DESCRIPTION:   Close the current log.
494   ---------------------------------------------------------------------- */
495
496void
497CloseLogMenu (GtkWidget *widget, gpointer user_data)
498{
499   int i;
500
501   if (numlogs == 0)
502      return;
503
504   CloseLog (curlog);
505
506   numlogs--;
507   if (numlogs == 0)
508   {
509      curlog = NULL;
510      loglist[0] = NULL;
511      curlognum = 0;
512      log_repaint ();
513      if (loginfovisible)
514              RepaintLogInfo ();
515      gtk_widget_set_sensitive (log_menu[MENU_PROPERTIES].widget, FALSE);
516      gtk_widget_set_sensitive (log_menu[MENU_CLOSE].widget, FALSE);
517      gtk_widget_set_sensitive (log_menu[MENU_CLOSE_ALL].widget, FALSE);
518      gtk_widget_set_sensitive (log_menu[MENU_MONITOR].widget, FALSE);
519      for ( i = 0; i < 3; i++)
520         gtk_widget_set_sensitive (view_menu[i].widget, FALSE);
521      return;
522   }
523   for (i = curlognum; i < numlogs; i++)
524      loglist[i] = loglist[i + 1];
525   loglist[i] = NULL;
526
527   if (curlognum > 0)
528      curlognum--;
529   curlog = loglist[curlognum];
530   log_repaint ();
531
532   if (loginfovisible)
533      RepaintLogInfo ();
534
535   /* Change menu entry if there is only one log */
536   if (numlogs < 2)
537     gtk_widget_set_state (log_menu[MENU_SWITCH_LOG].widget, GTK_STATE_INSENSITIVE);
538
539}
540
541/* ----------------------------------------------------------------------
542   NAME:          change_log_menu
543   DESCRIPTION:   Switch log
544   ---------------------------------------------------------------------- */
545
546void
547change_log_menu (GtkWidget * widget, gpointer user_data)
548{
549  change_log (1);
550
551}
552
553/* ----------------------------------------------------------------------
554   NAME:          FileSelectOk
555   DESCRIPTION:   User selected a file.
556   ---------------------------------------------------------------------- */
557
558void
559FileSelectOk (GtkWidget * w, GtkFileSelection * fs)
560{
561   char *f;
562   Log *tl;
563   gint i;
564
565   /* Check that we haven't opened all logfiles allowed    */
566   if (numlogs >= MAX_NUM_LOGS)
567     {
568       ShowErrMessage (_("Too many open logs. Close one and try again"));
569       return;
570     }
571
572   f = g_strdup (gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
573   gtk_widget_destroy (GTK_WIDGET (fs));
574
575   /* Check whether we are opening the already opened log file */
576   for ( i = 0; i < numlogs; i++)
577   {
578      if (strcmp (f, loglist[i]->name) == 0)
579      {
580         ShowErrMessage (_("File already opened"));
581         g_free (f);
582         return;
583      }
584   }     
585
586   if (f != NULL) {
587       if ((tl = OpenLogFile (f)) != NULL) {
588           if (numlogs > 0) {
589               memset (curlog->expand_paths, 0,
590                       sizeof(curlog->expand_paths));
591               save_rows_to_expand (curlog);
592           }
593           if (!numlogs)
594               gtk_widget_set_sensitive (log_menu[MENU_CLOSE].widget, TRUE);
595           
596               curlog = tl;
597               curlog->first_time = TRUE;
598               curlog->mon_on = FALSE;
599                   loglist[numlogs] = tl;
600                   numlogs++;
601                   curlognum = numlogs - 1;
602
603                   /* Clear window */
604                   log_repaint ();
605                   if (loginfovisible)
606                           RepaintLogInfo ();
607                   if (calendarvisible)
608                           init_calendar_data();
609
610               UpdateStatusArea();
611
612                   if (numlogs) {
613                           int i;
614                           if (numlogs >= 2)
615                               gtk_widget_set_sensitive (log_menu[MENU_SWITCH_LOG].widget, TRUE);
616
617                           gtk_widget_set_sensitive (log_menu[MENU_CLOSE_ALL].widget, TRUE);
618                           gtk_widget_set_sensitive (log_menu[MENU_PROPERTIES].widget, TRUE);
619                           gtk_widget_set_sensitive (log_menu[MENU_MONITOR].widget, TRUE);
620                           for (i = 0; i < 3; ++i)
621                               gtk_widget_set_sensitive (view_menu[i].widget, TRUE);
622                   }
623       }
624   }
625
626   g_free (f);
627
628}
629
630/* ----------------------------------------------------------------------
631   NAME:          LoadLogMenu
632   DESCRIPTION:   Open a new log defined by the user.
633   ---------------------------------------------------------------------- */
634
635void
636LoadLogMenu (GtkWidget * widget, gpointer user_data)
637{
638   GtkWidget *filesel = NULL;
639
640   /*  Cannot open more than MAX_NUM_LOGS */
641   if (numlogs == MAX_NUM_LOGS)
642     {
643       ShowErrMessage (_("Too many open logs. Close one and try again"));
644       return;
645     }
646   
647   /*  Cannot have more than one fileselect window */
648   /*  at one time. */
649   if (open_file_dialog != NULL) {
650           gtk_widget_show_now (open_file_dialog);
651           gdk_window_raise (open_file_dialog->window);
652           return;
653   }
654
655
656   filesel = gtk_file_selection_new (_("Open new logfile"));
657   gtk_window_set_transient_for (GTK_WINDOW (filesel), GTK_WINDOW (app));
658   gnome_window_icon_set_from_default (GTK_WINDOW (filesel));
659
660   /* Make window modal */
661   gtk_window_set_modal (GTK_WINDOW (filesel), TRUE);
662
663   gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel),
664                                    user_prefs->logfile);
665
666   gtk_window_set_position (GTK_WINDOW (filesel), GTK_WIN_POS_MOUSE);
667   gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button),
668                       "clicked", (GtkSignalFunc) FileSelectOk,
669                       filesel);
670   gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filesel)->cancel_button),
671                              "clicked", (GtkSignalFunc) gtk_widget_destroy,
672                              GTK_OBJECT (filesel));
673
674   gtk_signal_connect (GTK_OBJECT (filesel),
675                       "destroy", (GtkSignalFunc) gtk_widget_destroyed,
676                       &open_file_dialog);
677
678   gtk_widget_show (filesel);
679
680   open_file_dialog = filesel;
681
682}
683
684/* ----------------------------------------------------------------------
685   NAME:          ExitProg
686   DESCRIPTION:   Callback to call when program exits.
687   ---------------------------------------------------------------------- */
688
689void
690ExitProg (GtkWidget * widget, gpointer user_data)
691{
692   CloseApp ();
693
694}
695
696/* ----------------------------------------------------------------------
697   NAME:          CloseAllLogs
698   DESCRIPTION:   Close all log files
699   ---------------------------------------------------------------------- */
700
701void
702CloseAllLogs (void)
703{
704   int i;
705   
706   if (numlogs == 0)
707      return;
708
709   for (i = 0; i < numlogs; ++i)
710       CloseLog (loglist[i]);
711
712   numlogs = 0;
713   curlognum = 0;
714   curlog = NULL;
715   loglist[0] = NULL;
716
717   log_repaint ();
718   if (loginfovisible)
719          RepaintLogInfo ();
720
721   gtk_widget_set_sensitive (log_menu[MENU_MONITOR].widget, FALSE);
722   gtk_widget_set_sensitive (log_menu[MENU_PROPERTIES].widget, FALSE);
723   gtk_widget_set_sensitive (log_menu[MENU_CLOSE].widget, FALSE);
724   gtk_widget_set_sensitive (log_menu[MENU_CLOSE_ALL].widget, FALSE);
725   for ( i = 0; i < 3; i++)
726       gtk_widget_set_sensitive (view_menu[i].widget, FALSE);
727
728   gtk_widget_set_state (log_menu[MENU_SWITCH_LOG].widget, GTK_STATE_INSENSITIVE);
729
730}
731
732/* ----------------------------------------------------------------------
733   NAME:          CloseApp
734   DESCRIPTION:   Close everything and exit.
735   ---------------------------------------------------------------------- */
736
737void
738CloseApp (void)
739{
740   int i;
741
742   for (i = 0; i < numlogs; i++)
743      CloseLog (loglist[i]);
744
745   numlogs = 0;
746
747   gtk_main_quit ();   
748
749}
750
751/* ----------------------------------------------------------------------
752   NAME:          open_databases
753   DESCRIPTION:   Try to locate regexp and descript databases and load
754                  them.
755   ---------------------------------------------------------------------- */
756
757void
758open_databases (void)
759{
760        char full_name[1024];
761        gboolean found;
762
763        /* Find regexp DB -----------------------------------------------------  */
764        found = FALSE;
765        if (cfg->regexp_db_path != NULL) {
766                g_snprintf (full_name, sizeof (full_name),
767                            "%s/gnome-system-log-regexp.db", cfg->regexp_db_path);
768                DB (fprintf (stderr, "Looking for database in [%s]\n", cfg->regexp_db_path));
769                if (access (full_name, R_OK) == 0)  {
770                        found = TRUE;
771                        read_regexp_db (full_name, &regexp_db);
772                }
773        }
774
775        if ( ! found) {
776                g_snprintf (full_name, sizeof (full_name),
777                            "%s/share/gnome-system-log/gnome-system-log-regexp.db", LOGVIEWINSTALLPREFIX);
778                if (access (full_name, R_OK) == 0) {
779                        found = TRUE;
780                        g_free (cfg->regexp_db_path);
781                        cfg->regexp_db_path = g_strdup (full_name);
782                        read_regexp_db (full_name, &regexp_db);
783                }
784        }
785
786        /* Find description DB ------------------------------------------------  */
787        found = FALSE;
788        if (cfg->descript_db_path != NULL) {
789                g_snprintf (full_name, sizeof (full_name),
790                            "%s/gnome-system-log-descript.db", cfg->descript_db_path);
791                DB (fprintf (stderr, "Looking for database in [%s]\n", cfg->descript_db_path));
792                if (access (full_name, R_OK) == 0) {
793                        read_descript_db (full_name, &descript_db);
794                        found = TRUE;
795                }
796        }
797
798        if ( ! found) {
799                g_snprintf (full_name, sizeof (full_name),
800                            "%s/share/gnome-system-log/gnome-system-log-descript.db", LOGVIEWINSTALLPREFIX);
801                if (access (full_name, R_OK) == 0) {
802                        found = TRUE;
803                        g_free (cfg->descript_db_path);
804                        cfg->descript_db_path = g_strdup (full_name);
805                        read_descript_db (full_name, &descript_db);
806                }
807        }
808
809
810        /* Find action DB ------------------------------------------------  */
811        found = FALSE;
812        g_snprintf (full_name, sizeof (full_name),
813                    "%s/.gnome/gnome-system-log-actions.db", g_get_home_dir ());
814        DB (fprintf (stderr, "Looking for database in [%s/.gnome]\n",
815                     g_get_home_dir ()));
816        if (access (full_name, R_OK) == 0) {
817                found = TRUE;
818                read_actions_db (full_name, &actions_db);
819        }
820
821        if ( ! found && cfg->action_db_path != NULL) {
822                g_snprintf (full_name, sizeof (full_name),
823                            "%s/gnome-system-log-actions.db", cfg->action_db_path);
824                DB (fprintf (stderr, "Looking for database in [%s]\n", cfg->action_db_path));
825                if (access (full_name, R_OK) == 0) {
826                        found = TRUE;
827                        read_actions_db (full_name, &actions_db);
828                }
829        }
830
831
832        if ( ! found) {
833                g_snprintf (full_name, sizeof (full_name),
834                            "%s/share/gnome-system-log/gnome-system-log-actions.db", LOGVIEWINSTALLPREFIX);
835                if (access (full_name, R_OK) == 0) {
836                        found = TRUE;
837                        g_free (cfg->action_db_path);
838                        cfg->action_db_path = g_strdup (full_name);
839                        read_actions_db (full_name, &actions_db);
840                }
841        }
842
843        /* If debugging then print DB */
844        DB (print_db (regexp_db));
845
846}
847
848/* ----------------------------------------------------------------------
849   NAME:          IsLeapYear
850   DESCRIPTION:   Return TRUE if year is a leap year.
851   ---------------------------------------------------------------------- */
852int
853IsLeapYear (int year)
854{
855   if ((1900 + year) % 4 == 0)
856      return TRUE;
857   else
858      return FALSE;
859
860}
861
862void SetDefaultUserPrefs(UserPrefsStruct *prefs)
863{
864        /* Make defaults configurable later */
865        /* Will have to save prefs. eventually too*/
866        gchar *logfile = NULL;
867        struct stat filestat;
868       
869        logfile = gconf_client_get_string (client, "/apps/logview/logfile", NULL);
870        if (logfile != NULL && strcmp (logfile, "")) {
871                prefs->logfile = g_strdup (logfile);
872                g_free (logfile);
873        }
874        else {
875                /* First time running logview. Try to find the logfile */
876                if (lstat("/var/adm/messages", &filestat) == 0)
877                        prefs->logfile = g_strdup ("/var/adm/messages");
878                else if (lstat("/var/log/messages", &filestat) == 0)
879                        prefs->logfile = g_strdup ("/var/log/messages");
880                else if (lstat("/var/log/sys.log", &filestat) == 0)
881                        prefs->logfile = g_strdup ("/var/log/sys.log");
882                else
883                        prefs->logfile = NULL;
884        }
885       
886}
887
888void SaveUserPrefs(UserPrefsStruct *prefs)
889{
890    gconf_client_set_string (client, "/apps/logview/logfile", prefs->logfile, NULL);
891}
892
893static void
894toggle_calendar (void)
895{
896    if (calendarvisible) {
897        calendarvisible = FALSE;
898        gtk_widget_hide (CalendarDialog);
899    }
900    else
901        CalendarMenu (app, NULL);
902}
903
904static void
905toggle_zoom (void)
906{
907    if (zoom_visible) {
908        close_zoom_view (app, NULL);
909    }
910    else
911        create_zoom_view ();
912
913}
914
915static void
916toggle_collapse_rows (void)
917{
918    gtk_tree_view_collapse_all (GTK_TREE_VIEW (view));
919}
Note: See TracBrowser for help on using the repository browser.