[gtk+] section: Add _gtk_css_section_to_string()



commit 5e1ae36b2f65ef3f2715001ba59842469ed5308a
Author: Benjamin Otte <otte redhat com>
Date:   Thu Sep 27 15:10:52 2012 +0200

    section: Add _gtk_css_section_to_string()
    
    Mostly for debugging pruposes, but use it for printing CSS errors in
    GtkCssProvider, too.

 gtk/gtkcssprovider.c       |   64 +++++++------------------------------------
 gtk/gtkcsssection.c        |   42 ++++++++++++++++++++++++++++
 gtk/gtkcsssectionprivate.h |    4 +++
 3 files changed, 57 insertions(+), 53 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index d6f5d2b..9fffd6b 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1063,34 +1063,13 @@ gtk_css_provider_parsing_error (GtkCssProvider  *provider,
                                      0,
                                      TRUE))
     {
-      GFileInfo *info;
-      GFile *file;
-      const char *path;
+      char *s = _gtk_css_section_to_string (section);
 
-      file = gtk_css_section_get_file (section);
-      if (file)
-        {
-          info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
-
-          if (info)
-            path = g_file_info_get_display_name (info);
-          else
-            path = "<broken file>";
-        }
-      else
-        {
-          info = NULL;
-          path = "<data>";
-        }
-
-      g_warning ("Theme parsing error: %s:%u:%u: %s",
-                 path,
-                 gtk_css_section_get_end_line (section) + 1,
-                 gtk_css_section_get_end_position (section),
+      g_warning ("Theme parsing error: %s: %s",
+                 s,
                  error->message);
 
-      if (info)
-        g_object_unref (info);
+      g_free (s);
     }
 }
 
@@ -1826,32 +1805,14 @@ gtk_css_provider_propagate_error (GtkCssProvider  *provider,
                                   GError         **propagate_to)
 {
 
-  GFileInfo *info;
-  GFile *file;
-  const char *path;
-
-  file = gtk_css_section_get_file (section);
-  if (file)
-    {
-      info = g_file_query_info (file,G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
-
-      if (info)
-        path = g_file_info_get_display_name (info);
-      else
-        path = "<broken file>";
-    }
-  else
-    {
-      info = NULL;
-      path = "<unknown>";
-    }
+  char *s;
 
   /* don't fail for deprecations */
   if (g_error_matches (error, GTK_CSS_PROVIDER_ERROR, GTK_CSS_PROVIDER_ERROR_DEPRECATED))
     {
-      g_warning ("Theme parsing error: %s:%u:%u: %s", path,
-                 gtk_css_section_get_end_line (section) + 1,
-                 gtk_css_section_get_end_position (section), error->message);
+      s = _gtk_css_section_to_string (section);
+      g_warning ("Theme parsing error: %s: %s", s, error->message);
+      g_free (s);
       return;
     }
 
@@ -1860,12 +1821,9 @@ gtk_css_provider_propagate_error (GtkCssProvider  *provider,
     return;
 
   *propagate_to = g_error_copy (error);
-  g_prefix_error (propagate_to, "%s:%u:%u: ", path,
-                  gtk_css_section_get_end_line (section) + 1,
-                  gtk_css_section_get_end_position (section));
-
-  if (info)
-    g_object_unref (info);
+  s = _gtk_css_section_to_string (section);
+  g_prefix_error (propagate_to, "%s", s);
+  g_free (s);
 }
 
 static gboolean
diff --git a/gtk/gtkcsssection.c b/gtk/gtkcsssection.c
index 58383c6..9246d2d 100644
--- a/gtk/gtkcsssection.c
+++ b/gtk/gtkcsssection.c
@@ -303,3 +303,45 @@ gtk_css_section_get_end_position (const GtkCssSection *section)
     return section->end_position;
 }
 
+void
+_gtk_css_section_print (const GtkCssSection  *section,
+                        GString              *string)
+{
+  if (section->file)
+    {
+      GFileInfo *info;
+
+      info = g_file_query_info (section->file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
+
+      if (info)
+        {
+          g_string_append (string, g_file_info_get_display_name (info));
+          g_object_unref (info);
+        }
+      else
+        {
+          g_string_append (string, "<broken file>");
+        }
+    }
+  else
+    {
+      g_string_append (string, "<data>");
+    }
+
+  g_string_append_printf (string, ":%u:%u", 
+                          gtk_css_section_get_end_line (section) + 1,
+                          gtk_css_section_get_end_position (section));
+}
+
+char *
+_gtk_css_section_to_string (const GtkCssSection *section)
+{
+  GString *string;
+
+  g_return_val_if_fail (section != NULL, NULL);
+
+  string = g_string_new (NULL);
+  _gtk_css_section_print (section, string);
+
+  return g_string_free (string, FALSE);
+}
diff --git a/gtk/gtkcsssectionprivate.h b/gtk/gtkcsssectionprivate.h
index 12c13aa..d59188e 100644
--- a/gtk/gtkcsssectionprivate.h
+++ b/gtk/gtkcsssectionprivate.h
@@ -32,6 +32,10 @@ GtkCssSection *    _gtk_css_section_new_for_file       (GtkCssSectionType     ty
 
 void               _gtk_css_section_end                (GtkCssSection        *section);
 
+void               _gtk_css_section_print              (const GtkCssSection  *section,
+                                                        GString              *string);
+char *             _gtk_css_section_to_string          (const GtkCssSection  *section);
+
 G_END_DECLS
 
 #endif /* __GTK_CSS_SECTION_PRIVATE_H__ */



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