[gtk+/parser: 66/66] cssprovider: Make load_internal() load the contents



commit a34df3e17993855fb9aae690063b4f7e4eeb0d77
Author: Benjamin Otte <otte redhat com>
Date:   Mon Apr 11 20:08:57 2011 +0200

    cssprovider: Make load_internal() load the contents
    
    This way, we achieve two things:
    1) We can unify file loading to one location
    2) We can emit the error from file loading using the parsing-error
       signal. This is very useful for @import handling in particular.

 gtk/gtkcssprovider.c |   50 +++++++++++++++++++++++++++++---------------------
 1 files changed, 29 insertions(+), 21 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 41f54ae..944f957 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -2631,6 +2631,7 @@ gtk_css_provider_load_internal (GtkCssProvider *css_provider,
 {
   GScanner *scanner;
   gulong error_handler;
+  char *free_data;
 
   if (error)
     error_handler = g_signal_connect (css_provider,
@@ -2640,11 +2641,35 @@ gtk_css_provider_load_internal (GtkCssProvider *css_provider,
   else
     error_handler = 0; /* silence gcc */
 
-  scanner = gtk_css_scanner_new (file, data, length);
+  if (data == NULL)
+    {
+      GError *load_error = NULL;
 
-  parse_stylesheet (css_provider, scanner);
+      if (g_file_load_contents (file, NULL,
+                                &free_data, &length,
+                                NULL, &load_error))
+        {
+          data = free_data;
+        }
+      else
+        {
+          gtk_css_provider_take_error_full (css_provider,
+                                            file,
+                                            0, 0,
+                                            load_error);
+        }
+    }
+  else
+    free_data = NULL;
+
+  if (data)
+    {
+      scanner = gtk_css_scanner_new (file, data, length);
+
+      parse_stylesheet (css_provider, scanner);
 
-  gtk_css_scanner_destroy (scanner);
+      gtk_css_scanner_destroy (scanner);
+    }
 
   if (error)
     {
@@ -2706,29 +2731,12 @@ gtk_css_provider_load_from_file (GtkCssProvider  *css_provider,
                                  GFile           *file,
                                  GError         **error)
 {
-  GError *internal_error = NULL;
-  gchar *data;
-  gsize length;
-  gboolean ret;
-
   g_return_val_if_fail (GTK_IS_CSS_PROVIDER (css_provider), FALSE);
   g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
-  if (!g_file_load_contents (file, NULL,
-                             &data, &length,
-                             NULL, &internal_error))
-    {
-      g_propagate_error (error, internal_error);
-      return FALSE;
-    }
-
   gtk_css_provider_reset (css_provider);
 
-  ret = gtk_css_provider_load_internal (css_provider, file, data, length, error);
-
-  g_free (data);
-
-  return ret;
+  return gtk_css_provider_load_internal (css_provider, file, NULL, 0, error);
 }
 
 static gboolean



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