gnome-utils r8311 - trunk/logview



Author: cosimoc
Date: Tue Dec 23 13:28:06 2008
New Revision: 8311
URL: http://svn.gnome.org/viewvc/gnome-utils?rev=8311&view=rev

Log:
W.I.P. for a better error handling.

Modified:
   trunk/logview/Makefile.am
   trunk/logview/logview-main.c
   trunk/logview/logview-manager.c
   trunk/logview/logview-manager.h
   trunk/logview/logview-window.c

Modified: trunk/logview/Makefile.am
==============================================================================
--- trunk/logview/Makefile.am	(original)
+++ trunk/logview/Makefile.am	Tue Dec 23 13:28:06 2008
@@ -23,6 +23,7 @@
 
 gnome_system_log_SOURCES = 	\
 	logview-main.c		\
+	logview-main.h		\
 	logview-about.h		\
 	logview-manager.c	\
 	logview-manager.h	\

Modified: trunk/logview/logview-main.c
==============================================================================
--- trunk/logview/logview-main.c	(original)
+++ trunk/logview/logview-main.c	Tue Dec 23 13:28:06 2008
@@ -30,8 +30,10 @@
 #include "logview-window.h"
 #include "logview-prefs.h"
 #include "logview-manager.h"
+#include "logview-main.h"
 
 static gboolean show_version = FALSE;
+static GtkWidget *main_window = NULL;
 
 static gboolean
 main_window_delete_cb (GtkWidget *widget,
@@ -79,12 +81,31 @@
   exit (0);
 }
 
+void
+logview_show_error (const char *primary,
+                    const char *secondary)
+{
+  GtkWidget *message_dialog;
+
+  message_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
+                                           GTK_DIALOG_DESTROY_WITH_PARENT,
+                                           GTK_MESSAGE_ERROR,
+                                           GTK_BUTTONS_OK,
+                                           "%s", primary);
+  if (secondary) {
+    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message_dialog),
+                                              "%s", secondary);
+  };
+
+  gtk_dialog_run (GTK_DIALOG (message_dialog));
+  gtk_widget_destroy (message_dialog);
+}
+
 int
 main (int argc, char *argv[])
 {
   GError *error = NULL;
   GOptionContext *context;
-  GtkWidget *main_window;
   LogviewPrefs *prefs;
   LogviewManager *manager;
 

Modified: trunk/logview/logview-manager.c
==============================================================================
--- trunk/logview/logview-manager.c	(original)
+++ trunk/logview/logview-manager.c	Tue Dec 23 13:28:06 2008
@@ -22,13 +22,15 @@
 
 #include "logview-manager.h"
 
+#include <glib/gi18n.h>
+
 #include "logview-prefs.h"
 #include "logview-marshal.h"
+#include "logview-main.h"
 
 enum {
   LOG_ADDED,
   LOG_CLOSED,
-  LOG_ADD_ERROR,
   ACTIVE_CHANGED,
   LAST_SIGNAL
 };
@@ -44,6 +46,7 @@
 typedef struct {
   LogviewManager *manager;
   gboolean set_active;
+  GFile *file;
 } CreateCBData;
 
 struct _LogviewManagerPrivate {
@@ -92,15 +95,6 @@
                                       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,
-                                         G_STRUCT_OFFSET (LogviewManagerClass, log_add_error),
-                                         NULL, NULL,
-                                         g_cclosure_marshal_VOID__STRING,
-                                         G_TYPE_NONE, 1,
-                                         G_TYPE_STRING);
-
   signals[ACTIVE_CHANGED] = g_signal_new ("active-changed",
                                           G_OBJECT_CLASS_TYPE (object_class),
                                           G_SIGNAL_RUN_LAST,
@@ -154,11 +148,19 @@
       logview_manager_set_active_log (data->manager, log);
     }
   } else {
+    char *path, *primary;
+
     /* notify the error */
-    /* FIXME: this is not right! */
-    g_signal_emit (data->manager, signals[LOG_ADD_ERROR], 0, NULL, NULL);
+    path = g_file_get_path (data->file);
+    primary = g_strdup_printf (_("Impossible to open the file %s."), path);
+
+    logview_show_error (primary, error->message);
+
+    g_free (path);
+    g_free (primary);
   }
 
+  g_object_unref (data->file);
   g_slice_free (CreateCBData, data);
 }
 
@@ -233,6 +235,7 @@
     data = g_slice_new0 (CreateCBData);
     data->manager = manager;
     data->set_active = set_active;
+    data->file = g_object_ref (file);
 
     logview_log_create_from_gfile (file, create_log_cb, data);
   }

Modified: trunk/logview/logview-manager.h
==============================================================================
--- trunk/logview/logview-manager.h	(original)
+++ trunk/logview/logview-manager.h	Tue Dec 23 13:28:06 2008
@@ -57,8 +57,6 @@
                       LogviewLog *log);
   void (* log_closed) (LogviewManager *manager,
                        LogviewLog *log);
-  void (* log_add_error) (LogviewManager *manager,
-                          char *filename);
   void (* active_changed) (LogviewManager *manager,
                            LogviewLog *log,
                            LogviewLog *old_log);

Modified: trunk/logview/logview-window.c
==============================================================================
--- trunk/logview/logview-window.c	(original)
+++ trunk/logview/logview-window.c	Tue Dec 23 13:28:06 2008
@@ -31,6 +31,7 @@
 #include "logview-about.h"
 #include "logview-prefs.h"
 #include "logview-manager.h"
+#include "logview-main.h"
 
 #define APP_NAME _("System Log Viewer")
 #define SEARCH_START_MARK "lw-search-start-mark"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]