diff options
author | Benjamin Otte <otte@redhat.com> | 2012-09-27 15:10:52 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2012-09-28 18:27:49 +0200 |
commit | 5e1ae36b2f65ef3f2715001ba59842469ed5308a (patch) | |
tree | 7d2c579165f03164e1ae1d9e4fd6127736867bdc | |
parent | 8f96966178dd14d1d625df991d2bdf85e431dfa3 (diff) | |
download | gtk+-5e1ae36b2f65ef3f2715001ba59842469ed5308a.tar.gz |
section: Add _gtk_css_section_to_string()
Mostly for debugging pruposes, but use it for printing CSS errors in
GtkCssProvider, too.
-rw-r--r-- | gtk/gtkcssprovider.c | 64 | ||||
-rw-r--r-- | gtk/gtkcsssection.c | 42 | ||||
-rw-r--r-- | gtk/gtkcsssectionprivate.h | 4 |
3 files changed, 57 insertions, 53 deletions
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c index d6f5d2b169..9fffd6b219 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 58383c6b98..9246d2d27c 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 12c13aaba0..d59188e8db 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__ */ |