diff options
author | Vincent Untz <vuntz@gnome.org> | 2012-10-03 07:41:14 +0200 |
---|---|---|
committer | Vincent Untz <vuntz@gnome.org> | 2012-10-03 11:42:46 +0200 |
commit | a97707811e2669b6a52a861c41cf46838fab8eb5 (patch) | |
tree | 96e9f1d26136a3f19153e2070e01c67318467c35 | |
parent | fadbee1bdceffa3c6ffdbaa67563dbcb0ce059f7 (diff) |
validate: Add function to print hints, and --no-hints option
This is useful to suggest improvements to the user.
-rw-r--r-- | src/install.c | 2 | ||||
-rw-r--r-- | src/validate.c | 25 | ||||
-rw-r--r-- | src/validate.h | 3 | ||||
-rw-r--r-- | src/validator.c | 4 |
4 files changed, 30 insertions, 4 deletions
diff --git a/src/install.c b/src/install.c index 19a7aec..fba3a7c 100644 --- a/src/install.c +++ b/src/install.c @@ -248,7 +248,7 @@ process_one_file (const char *filename, g_key_file_free (kf); /* Load and validate the file we just wrote */ - if (!desktop_file_validate (new_filename, FALSE, TRUE)) + if (!desktop_file_validate (new_filename, FALSE, TRUE, TRUE)) { g_set_error (err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE, _("Failed to validate the created desktop file")); diff --git a/src/validate.c b/src/validate.c index 8e0d869..cde12a2 100644 --- a/src/validate.c +++ b/src/validate.c @@ -112,6 +112,7 @@ struct _kf_validator { gboolean kde_reserved_warnings; gboolean no_deprecated_warnings; + gboolean no_hints; char *main_group; DesktopType type; @@ -566,6 +567,26 @@ print_warning (kf_validator *kf, const char *format, ...) g_free (str); } +static void +print_hint (kf_validator *kf, const char *format, ...) +{ + va_list args; + gchar *str; + + g_return_if_fail (kf != NULL && format != NULL); + + if (kf->no_hints) + return; + + va_start (args, format); + str = g_strdup_vprintf (format, args); + va_end (args); + + g_print ("%s: hint: %s", kf->filename, str); + + g_free (str); +} + /* + Key names must contain only the characters A-Za-z0-9-. * Checked. */ @@ -2779,7 +2800,8 @@ groups_hashtable_free (gpointer key, gboolean desktop_file_validate (const char *filename, gboolean warn_kde, - gboolean no_warn_deprecated) + gboolean no_warn_deprecated, + gboolean no_hints) { kf_validator kf; @@ -2796,6 +2818,7 @@ desktop_file_validate (const char *filename, kf.current_keys = NULL; kf.kde_reserved_warnings = warn_kde; kf.no_deprecated_warnings = no_warn_deprecated; + kf.no_hints = no_hints; kf.main_group = NULL; kf.type = INVALID_TYPE; diff --git a/src/validate.h b/src/validate.h index 7910083..3bd5a72 100644 --- a/src/validate.h +++ b/src/validate.h @@ -34,7 +34,8 @@ gboolean desktop_file_validate (const char *filename, gboolean warn_kde, - gboolean no_warn_deprecated); + gboolean no_warn_deprecated, + gboolean no_hints); gboolean desktop_file_fixup (GKeyFile *keyfile, const char *filename); diff --git a/src/validator.c b/src/validator.c index c50157e..20512a6 100644 --- a/src/validator.c +++ b/src/validator.c @@ -29,10 +29,12 @@ #include "validate.h" static gboolean warn_kde = FALSE; +static gboolean no_hints = FALSE; static gboolean no_warn_deprecated = FALSE; static char **filename = NULL; static GOptionEntry option_entries[] = { + { "no-hints", 0, 0, G_OPTION_ARG_NONE, &no_hints, "Do not output hints to improve desktop file", NULL }, { "no-warn-deprecated", 0, 0, G_OPTION_ARG_NONE, &no_warn_deprecated, "Do not warn about usage of deprecated items", NULL }, { "warn-kde", 0, 0, G_OPTION_ARG_NONE, &warn_kde, "Warn about usage of KDE extensions to the specification", NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filename, NULL, "<desktop-file>" }, @@ -75,7 +77,7 @@ main (int argc, char *argv[]) return 1; } - if (desktop_file_validate (filename[0], warn_kde, no_warn_deprecated)) + if (desktop_file_validate (filename[0], warn_kde, no_warn_deprecated, no_hints)) return 0; else return 1; |