[yelp/yelp-3-0] [yelp-error] Adding error domain and codes for Yelp errors



commit 37b053e1430329e539b170ec13b342d794768abf
Author: Shaun McCance <shaunm gnome org>
Date:   Sun Sep 27 13:24:54 2009 -0500

    [yelp-error] Adding error domain and codes for Yelp errors

 libyelp/yelp-document.h        |    3 ++
 libyelp/yelp-error.h           |   39 ++++++++++++++++++++++++++++++++++++++
 libyelp/yelp-location-entry.h  |   15 +++++++++----
 libyelp/yelp-simple-document.h |    4 +++
 libyelp/yelp-uri.h             |    3 ++
 libyelp/yelp-view.c            |   41 +++++++++++++++++++++++++++++++--------
 libyelp/yelp-view.h            |    4 +++
 7 files changed, 95 insertions(+), 14 deletions(-)
---
diff --git a/libyelp/yelp-document.h b/libyelp/yelp-document.h
index 64aee49..6ffecff 100644
--- a/libyelp/yelp-document.h
+++ b/libyelp/yelp-document.h
@@ -28,6 +28,8 @@
 
 #include "yelp-uri.h"
 
+G_BEGIN_DECLS
+
 #define YELP_TYPE_DOCUMENT         (yelp_document_get_type ())
 #define YELP_DOCUMENT(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), YELP_TYPE_DOCUMENT, YelpDocument))
 #define YELP_DOCUMENT_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), YELP_TYPE_DOCUMENT, YelpDocumentClass))
@@ -151,5 +153,6 @@ void              yelp_document_final_pending  (YelpDocument        *document,
 						YelpError           *error);
 */
 
+G_END_DECLS
 
 #endif /* __YELP_DOCUMENT_H__ */
diff --git a/libyelp/yelp-error.h b/libyelp/yelp-error.h
new file mode 100644
index 0000000..78fbf3d
--- /dev/null
+++ b/libyelp/yelp-error.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2009 Shaun McCance <shaunm 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Shaun McCance <shaunm gnome org>
+ */
+
+#ifndef __YELP_ERROR_H__
+#define __YELP_ERROR_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define YELP_ERROR g_quark_from_static_string ("yelp-error")
+
+typedef enum {
+    YELP_ERROR_NOT_FOUND,
+    YELP_ERROR_CANT_READ
+} YelpError;
+
+G_END_DECLS
+
+#endif /* __YELP_ERROR_H__ */
diff --git a/libyelp/yelp-location-entry.h b/libyelp/yelp-location-entry.h
index 11af99f..db7617a 100644
--- a/libyelp/yelp-location-entry.h
+++ b/libyelp/yelp-location-entry.h
@@ -20,12 +20,13 @@
  * Author: Shaun McCance <shaunm gnome org>
  */
 
-typedef struct _YelpLocationEntry         YelpLocationEntry;
-typedef struct _YelpLocationEntryClass    YelpLocationEntryClass;
-typedef struct _YelpLocationEntryPrivate  YelpLocationEntryPrivate;
+#ifndef __YELP_LOCATION_ENTRY_H__
+#define __YELP_LOCATION_ENTRY_H__
 
 #include <gtk/gtk.h>
 
+G_BEGIN_DECLS
+
 #define YELP_TYPE_LOCATION_ENTRY (yelp_location_entry_get_type ())
 #define YELP_LOCATION_ENTRY(obj) \
   (G_TYPE_CHECK_INSTANCE_CAST((obj), YELP_TYPE_LOCATION_ENTRY, \
@@ -41,6 +42,10 @@ typedef struct _YelpLocationEntryPrivate  YelpLocationEntryPrivate;
   (G_TYPE_INSTANCE_GET_CLASS((obj), YELP_TYPE_LOCATION_ENTRY, \
 			     YelpLocationEntryClass))
 
+typedef struct _YelpLocationEntry         YelpLocationEntry;
+typedef struct _YelpLocationEntryClass    YelpLocationEntryClass;
+typedef struct _YelpLocationEntryPrivate  YelpLocationEntryPrivate;
+
 struct _YelpLocationEntry
 {
   GtkComboBoxEntry          parent;
@@ -59,8 +64,6 @@ typedef enum {
     YELP_LOCATION_ENTRY_IS_SEARCH    = 1 << 3
 } YelpLocationEntryFlags;
 
-G_BEGIN_DECLS
-
 GType           yelp_location_entry_get_type        (void);
 GtkWidget*      yelp_location_entry_new_with_model  (GtkTreeModel *model,
                                                      gint          text_column,
@@ -70,3 +73,5 @@ GtkWidget*      yelp_location_entry_new_with_model  (GtkTreeModel *model,
 void            yelp_location_entry_start_search    (YelpLocationEntry *entry);
 
 G_END_DECLS
+
+#endif /* __YELP_DOCUMENT_H__ */
diff --git a/libyelp/yelp-simple-document.h b/libyelp/yelp-simple-document.h
index aec9182..5c091ab 100644
--- a/libyelp/yelp-simple-document.h
+++ b/libyelp/yelp-simple-document.h
@@ -29,6 +29,8 @@
 #include "yelp-document.h"
 #include "yelp-uri.h"
 
+G_BEGIN_DECLS
+
 #define YELP_TYPE_SIMPLE_DOCUMENT         (yelp_simple_document_get_type ())
 #define YELP_SIMPLE_DOCUMENT(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), YELP_TYPE_SIMPLE_DOCUMENT, YelpSimpleDocument))
 #define YELP_SIMPLE_DOCUMENT_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), YELP_TYPE_SIMPLE_DOCUMENT, YelpSimpleDocumentClass))
@@ -52,4 +54,6 @@ struct _YelpSimpleDocumentClass {
 GType             yelp_simple_document_get_type       (void);
 YelpDocument *    yelp_simple_document_new            (YelpUri  *uri);
 
+G_END_DECLS
+
 #endif /* __YELP_SIMPLE_DOCUMENT_H__ */
diff --git a/libyelp/yelp-uri.h b/libyelp/yelp-uri.h
index fc180a4..e16f3c2 100644
--- a/libyelp/yelp-uri.h
+++ b/libyelp/yelp-uri.h
@@ -25,6 +25,8 @@
 
 #include <glib-object.h>
 
+G_BEGIN_DECLS
+
 #define YELP_TYPE_URI         (yelp_uri_get_type ())
 #define YELP_URI(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), YELP_TYPE_URI, YelpUri))
 #define YELP_URI_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), YELP_TYPE_URI, YelpUriClass))
@@ -74,5 +76,6 @@ gchar **             yelp_uri_get_search_path    (YelpUri   *uri);
 gchar *              yelp_uri_get_page_id        (YelpUri   *uri);
 gchar *              yelp_uri_get_frag_id        (YelpUri   *uri);
 
+G_END_DECLS
 
 #endif /* __YELP_URI_H__ */
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index 213621c..096602b 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -29,6 +29,7 @@
 #include <gtk/gtk.h>
 #include <webkit/webkit.h>
 
+#include "yelp-error.h"
 #include "yelp-view.h"
 
 static void        yelp_view_init                 (YelpView           *view);
@@ -45,7 +46,7 @@ static void        yelp_view_set_property         (GObject            *object,
                                                    GParamSpec         *pspec);
 
 static void        view_show_error_page           (YelpView           *view,
-                                                   gchar              *message);
+                                                   GError             *error);
 
 static void        document_callback              (YelpDocument       *document,
                                                    YelpDocumentSignal  signal,
@@ -245,10 +246,15 @@ yelp_view_load_document (YelpView     *view,
     g_object_set (view, "state", YELP_VIEW_STATE_LOADING, NULL);
 
     if (!document) {
-        gchar *base_uri, *msg;
+        GError *error;
+        gchar *base_uri;
         base_uri = yelp_uri_get_base_uri (uri);
-        msg = g_strdup_printf (_("Could not load a document for %s"), base_uri);
-        view_show_error_page (view, msg);
+        /* FIXME: CANT_READ isn't right */
+        error = g_error_new (YELP_ERROR, YELP_ERROR_CANT_READ,
+                             _("Could not load a document for â??%sâ??"),
+                             base_uri);
+        g_free (base_uri);
+        view_show_error_page (view, error);
         return;
     }
 
@@ -267,9 +273,9 @@ yelp_view_load_document (YelpView     *view,
 
 static void
 view_show_error_page (YelpView *view,
-                      gchar    *message)
+                      GError   *error)
 {
-    static const gchar *error =
+    static const gchar *errorpage =
         "<html><head>"
         "<style type='text/css'>"
         "body { margin: 1em; }"
@@ -286,16 +292,33 @@ view_show_error_page (YelpView *view,
         "</style>"
         "</head><body>"
         "<div class='outer'><div class='inner'>"
-        "%s"
+        "<div class='title'>%s</div>"
+        "<div class='contents'>%s</div>"
         "</div></div>"
         "</body></html>";
-    gchar *page = g_strdup_printf (error, message);
+    gchar *page, *title = NULL;
+    if (error->domain == YELP_ERROR)
+        switch (error->code) {
+        case YELP_ERROR_NOT_FOUND:
+            title = _("Document or Page Not Found");
+            break;
+        case YELP_ERROR_CANT_READ:
+            title = _("Cannot Read the Document or Page");
+            break;
+        default:
+            break;
+        }
+    if (title == NULL)
+        title = _("Unknown Error");
+    page = g_strdup_printf (errorpage, title, error->message);
     g_object_set (view, "state", YELP_VIEW_STATE_ERROR, NULL);
     webkit_web_view_load_string (WEBKIT_WEB_VIEW (view),
                                  page,
                                  "text/html",
                                  "UTF-8",
                                  "about:error");
+    g_error_free (error);
+    g_free (page);
 }
 
 static void
@@ -324,6 +347,6 @@ document_callback (YelpDocument       *document,
 	yelp_document_finish_read (document, contents);
     }
     else if (signal == YELP_DOCUMENT_SIGNAL_ERROR) {
-        view_show_error_page (view, error->message);
+        view_show_error_page (view, error);
     }
 }
diff --git a/libyelp/yelp-view.h b/libyelp/yelp-view.h
index 2d2e960..d427e7e 100644
--- a/libyelp/yelp-view.h
+++ b/libyelp/yelp-view.h
@@ -29,6 +29,8 @@
 #include "yelp-document.h"
 #include "yelp-uri.h"
 
+G_BEGIN_DECLS
+
 #define YELP_TYPE_VIEW            (yelp_view_get_type ())
 #define YELP_VIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), YELP_TYPE_VIEW, YelpView))
 #define YELP_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), YELP_TYPE_VIEW, YelpViewClass))
@@ -72,4 +74,6 @@ void             yelp_view_load_document   (YelpView     *view,
 					    YelpUri      *uri,
 					    YelpDocument *document);
 
+G_END_DECLS
+
 #endif /* __YELP_VIEW_H__ */



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