diff options
author | Richard Hughes <richard@hughsie.com> | 2014-05-27 14:32:02 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-05-27 14:36:21 +0100 |
commit | 82ff7d6e1a579d301cf9655b045b2b983bf40849 (patch) | |
tree | ee0f11c08a319cfa210a5c89134647426a8cf7e2 /libappstream-glib | |
parent | afffd46ed4f51fe41adc55d6f7688ecf2fd77118 (diff) | |
download | appstream-glib-82ff7d6e1a579d301cf9655b045b2b983bf40849.tar.gz |
Also support validating .appdata.xml.in files
Sometimes we don't want to build the entire project just to validate one file.
Resolves: https://github.com/hughsie/appdata-tools/issues/22
Diffstat (limited to 'libappstream-glib')
-rw-r--r-- | libappstream-glib/as-app.c | 47 | ||||
-rw-r--r-- | libappstream-glib/as-app.h | 6 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 38 |
3 files changed, 89 insertions, 2 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index 3c85772..b74c501 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -2660,6 +2660,39 @@ out: } /** + * as_app_parse_appdata_unintltoolize_cb: + **/ +static gboolean +as_app_parse_appdata_unintltoolize_cb (GNode *node, gpointer data) +{ + const gchar *name; + + name = as_node_get_name (node); + if (g_strcmp0 (name, "_name") == 0) { + as_node_set_name (node, "name"); + goto out; + } + if (g_strcmp0 (name, "_summary") == 0) { + as_node_set_name (node, "summary"); + goto out; + } + if (g_strcmp0 (name, "_caption") == 0) { + as_node_set_name (node, "caption"); + goto out; + } + if (g_strcmp0 (name, "_p") == 0) { + as_node_set_name (node, "p"); + goto out; + } + if (g_strcmp0 (name, "_li") == 0) { + as_node_set_name (node, "li"); + goto out; + } +out: + return FALSE; +} + +/** * as_app_parse_appdata_file: **/ static gboolean @@ -2706,6 +2739,17 @@ as_app_parse_appdata_file (AsApp *app, ret = FALSE; goto out; } + + /* make the <_summary> tags into <summary> */ + if (flags & AS_APP_PARSE_FLAG_CONVERT_TRANSLATABLE) { + g_node_traverse (root, + G_IN_ORDER, + G_TRAVERSE_ALL, + 10, + as_app_parse_appdata_unintltoolize_cb, + app); + } + node = as_node_find (root, "application"); if (node == NULL) node = as_node_find (root, "component"); @@ -2768,6 +2812,9 @@ as_app_parse_file (AsApp *app, as_app_set_source_kind (app, AS_APP_SOURCE_KIND_DESKTOP); } else if (g_str_has_suffix (filename, ".appdata.xml")) { as_app_set_source_kind (app, AS_APP_SOURCE_KIND_APPDATA); + } else if (g_str_has_suffix (filename, ".appdata.xml.in")) { + flags |= AS_APP_PARSE_FLAG_CONVERT_TRANSLATABLE; + as_app_set_source_kind (app, AS_APP_SOURCE_KIND_APPDATA); } else { g_set_error (error, AS_APP_ERROR, diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h index 934bd51..b78f89a 100644 --- a/libappstream-glib/as-app.h +++ b/libappstream-glib/as-app.h @@ -69,13 +69,15 @@ struct _AsAppClass * @AS_APP_PARSE_FLAG_NONE: No special actions to use * @AS_APP_PARSE_FLAG_USE_HEURISTICS: Use heuristic to infer properties * @AS_APP_PARSE_FLAG_KEEP_COMMENTS: Save comments from the file + * @AS_APP_PARSE_FLAG_CONVERT_TRANSLATABLE: Allow translatable flags like <_p> * * The flags to use when parsing resources. **/ typedef enum { AS_APP_PARSE_FLAG_NONE, - AS_APP_PARSE_FLAG_USE_HEURISTICS = 1, /* Since: 0.1.2 */ - AS_APP_PARSE_FLAG_KEEP_COMMENTS = 1, /* Since: 0.1.6 */ + AS_APP_PARSE_FLAG_USE_HEURISTICS = 1, /* Since: 0.1.2 */ + AS_APP_PARSE_FLAG_KEEP_COMMENTS = 2, /* Since: 0.1.6 */ + AS_APP_PARSE_FLAG_CONVERT_TRANSLATABLE = 4, /* Since: 0.1.6 */ /*< private >*/ AS_APP_PARSE_FLAG_LAST, } AsAppParseFlags; diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index 8cb5995..78fd0c7 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -509,6 +509,43 @@ ch_test_app_validate_file_good_func (void) } static void +ch_test_app_validate_intltool_func (void) +{ + AsApp *app; + AsProblem *problem; + GError *error = NULL; + GPtrArray *probs; + gboolean ret; + gchar *filename; + guint i; + + /* open file */ + app = as_app_new (); + filename = as_test_get_filename ("intltool.appdata.xml.in"); + ret = as_app_parse_file (app, filename, AS_APP_PARSE_FLAG_NONE, &error); + g_assert_no_error (error); + g_assert (ret); + + /* check success */ + g_assert_cmpint (as_app_get_id_kind (app), ==, AS_ID_KIND_DESKTOP); + g_assert_cmpstr (as_app_get_id_full (app), ==, "gnome-power-statistics.desktop"); + g_assert_cmpstr (as_app_get_name (app, "C"), ==, "0 A.D."); + g_assert_cmpstr (as_app_get_comment (app, "C"), ==, "Observe power management"); + probs = as_app_validate (app, AS_APP_VALIDATE_FLAG_NO_NETWORK, &error); + g_assert_no_error (error); + g_assert (probs != NULL); + for (i = 0; i < probs->len; i++) { + problem = g_ptr_array_index (probs, i); + g_warning ("%s", as_problem_get_message (problem)); + } + g_assert_cmpint (probs->len, ==, 0); + g_ptr_array_unref (probs); + + g_free (filename); + g_object_unref (app); +} + +static void ch_test_app_translated_func (void) { AsApp *app; @@ -1585,6 +1622,7 @@ main (int argc, char **argv) g_test_add_func ("/AppStream/app{validate-style}", ch_test_app_validate_style_func); g_test_add_func ("/AppStream/app{validate-file-good}", ch_test_app_validate_file_good_func); g_test_add_func ("/AppStream/app{validate-file-bad}", ch_test_app_validate_file_bad_func); + g_test_add_func ("/AppStream/app{validate-intltool}", ch_test_app_validate_intltool_func); g_test_add_func ("/AppStream/app{parse-file}", ch_test_app_parse_file_func); g_test_add_func ("/AppStream/app{no-markup}", ch_test_app_no_markup_func); g_test_add_func ("/AppStream/app{subsume}", ch_test_app_subsume_func); |