summaryrefslogtreecommitdiff
path: root/libappstream-glib
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-07-29 15:22:51 +0100
committerRichard Hughes <richard@hughsie.com>2014-07-29 15:22:51 +0100
commit53965c8a671627ce9132f99bee45e51d38b0bc83 (patch)
tree2bbca4445cb62984af5b645f89a1333e904fea42 /libappstream-glib
parent361ac14eb59c891c46db4e343454ee0b4113fb8a (diff)
downloadappstream-glib-53965c8a671627ce9132f99bee45e51d38b0bc83.tar.gz
Only add registered projects and categories to the metadata
Diffstat (limited to 'libappstream-glib')
-rw-r--r--libappstream-glib/Makefile.am16
-rw-r--r--libappstream-glib/appstream-glib.gresource.xml2
-rw-r--r--libappstream-glib/as-app.c10
-rw-r--r--libappstream-glib/as-category-ids.txt140
-rw-r--r--libappstream-glib/as-environment-ids.txt12
-rw-r--r--libappstream-glib/as-self-test.c8
-rw-r--r--libappstream-glib/as-utils.c54
-rw-r--r--libappstream-glib/as-utils.h2
8 files changed, 240 insertions, 4 deletions
diff --git a/libappstream-glib/Makefile.am b/libappstream-glib/Makefile.am
index 43f0981..eeb0ca0 100644
--- a/libappstream-glib/Makefile.am
+++ b/libappstream-glib/Makefile.am
@@ -26,7 +26,12 @@ as-tag-private.h: as-tag.gperf
$(AM_V_GEN) gperf < $< > $@
endif
-as-resources.c: appstream-glib.gresource.xml as-stock-icons.txt as-license-ids.txt as-blacklist-ids.txt
+as-resources.c: appstream-glib.gresource.xml \
+ as-stock-icons.txt \
+ as-license-ids.txt \
+ as-blacklist-ids.txt \
+ as-category-ids.txt \
+ as-environment-ids.txt
$(AM_V_GEN) \
glib-compile-resources \
--sourcedir=$(srcdir) \
@@ -35,7 +40,12 @@ as-resources.c: appstream-glib.gresource.xml as-stock-icons.txt as-license-ids.t
--generate-source \
--c-name as \
$(srcdir)/appstream-glib.gresource.xml
-as-resources.h: appstream-glib.gresource.xml as-stock-icons.txt as-license-ids.txt as-blacklist-ids.txt
+as-resources.h: appstream-glib.gresource.xml \
+ as-stock-icons.txt \
+ as-license-ids.txt \
+ as-blacklist-ids.txt \
+ as-category-ids.txt \
+ as-environment-ids.txt
$(AM_V_GEN) \
glib-compile-resources \
--sourcedir=$(srcdir) \
@@ -184,6 +194,8 @@ EXTRA_DIST = \
appstream-glib.gresource.xml \
appstream-glib.pc.in \
as-blacklist-ids.txt \
+ as-category-ids.txt \
+ as-environment-ids.txt \
as-license-ids.txt \
as-stock-icons.txt \
as-tag.gperf \
diff --git a/libappstream-glib/appstream-glib.gresource.xml b/libappstream-glib/appstream-glib.gresource.xml
index e36a79a..b0c31d8 100644
--- a/libappstream-glib/appstream-glib.gresource.xml
+++ b/libappstream-glib/appstream-glib.gresource.xml
@@ -4,5 +4,7 @@
<file>as-stock-icons.txt</file>
<file>as-blacklist-ids.txt</file>
<file>as-license-ids.txt</file>
+ <file>as-category-ids.txt</file>
+ <file>as-environment-ids.txt</file>
</gresource>
</gresources>
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index e7ab906..e58b544 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -3433,6 +3433,14 @@ as_app_parse_file_key (AsApp *app,
return FALSE;
}
+ /* not a standard category */
+ if (g_str_has_prefix (list[i], "X-"))
+ continue;
+
+ /* check the category is valid */
+ if (!as_utils_is_category_id (list[i]))
+ continue;
+
/* ignore some useless keys */
if (g_strcmp0 (list[i], "GTK") == 0)
continue;
@@ -3442,8 +3450,6 @@ as_app_parse_file_key (AsApp *app,
continue;
if (g_strcmp0 (list[i], "GNOME") == 0)
continue;
- if (g_str_has_prefix (list[i], "X-"))
- continue;
as_app_add_category (app, list[i], -1);
}
diff --git a/libappstream-glib/as-category-ids.txt b/libappstream-glib/as-category-ids.txt
new file mode 100644
index 0000000..03d1583
--- /dev/null
+++ b/libappstream-glib/as-category-ids.txt
@@ -0,0 +1,140 @@
+# these are desktop categories
+2DGraphics
+3DGraphics
+Accessibility
+ActionGame
+Adult
+AdventureGame
+Amusement
+ArcadeGame
+Archiving
+Art
+ArtificialIntelligence
+Astronomy
+Audio
+AudioVideo
+AudioVideoEditing
+Biology
+BlocksGame
+BoardGame
+Building
+Calculator
+Calendar
+CardGame
+Chart
+Chat
+Chemistry
+Clock
+Compression
+ComputerScience
+ConsoleOnly
+Construction
+ContactManagement
+Core
+Database
+DataVisualization
+Debugger
+DesktopSettings
+Development
+Dialup
+Dictionary
+DiscBurning
+Documentation
+Economy
+Education
+Electricity
+Electronics
+Email
+Emulator
+Engineering
+Feed
+FileManager
+Filesystem
+FileTools
+FileTransfer
+Finance
+FlowChart
+Game
+Geography
+Geology
+Geoscience
+GNOME
+Graphics
+GTK
+GUIDesigner
+HamRadio
+HardwareSettings
+History
+Humanities
+IDE
+ImageProcessing
+InstantMessaging
+IRCClient
+Java
+KDE
+KidsGame
+Languages
+Literature
+LogicGame
+Maps
+Math
+MedicalSoftware
+Midi
+Mixer
+Monitor
+Motif
+Music
+Network
+News
+NumericalAnalysis
+OCR
+Office
+P2P
+PackageManager
+ParallelComputing
+PDA
+Photography
+Physics
+Player
+Presentation
+Printing
+Profiling
+ProjectManagement
+Publishing
+Qt
+RasterGraphics
+Recorder
+RemoteAccess
+RevisionControl
+Robotics
+RolePlaying
+Scanning
+Science
+Security
+Sequencer
+Settings
+Shooter
+Simulation
+Spirituality
+Sports
+SportsGame
+Spreadsheet
+StrategyGame
+System
+Telephony
+TelephonyTools
+TerminalEmulator
+TextEditor
+TextTools
+Translation
+Tuner
+TV
+Utility
+VectorGraphics
+Video
+VideoConference
+Viewer
+WebBrowser
+WebDevelopment
+WordProcessor
+XFCE
diff --git a/libappstream-glib/as-environment-ids.txt b/libappstream-glib/as-environment-ids.txt
new file mode 100644
index 0000000..4a5c0dd
--- /dev/null
+++ b/libappstream-glib/as-environment-ids.txt
@@ -0,0 +1,12 @@
+# these are registered desktop environments
+GNOME
+KDE
+LXDE
+MATE
+Razor
+ROX
+TDE
+Unity
+XFCE
+EDE
+Cinnamon
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 32d191c..77ae2ba 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -1997,6 +1997,14 @@ as_test_utils_func (void)
g_assert (as_utils_is_stock_icon_name ("insert-image"));
g_assert (as_utils_is_stock_icon_name ("zoom-out"));
+ /* environments */
+ g_assert (as_utils_is_environment_id ("GNOME"));
+ g_assert (!as_utils_is_environment_id ("RandomDE"));
+
+ /* categories */
+ g_assert (as_utils_is_category_id ("AudioVideoEditing"));
+ g_assert (!as_utils_is_category_id ("SpellEditing"));
+
/* blacklist */
g_assert (as_utils_is_blacklisted_id ("gnome-system-monitor-kde.desktop"));
g_assert (as_utils_is_blacklisted_id ("doom-*-demo.desktop"));
diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c
index 9bc92c9..66896da 100644
--- a/libappstream-glib/as-utils.c
+++ b/libappstream-glib/as-utils.c
@@ -270,6 +270,60 @@ as_utils_is_blacklisted_id (const gchar *desktop_id)
}
/**
+ * as_utils_is_environment_id:
+ * @environment_id: a desktop ID, e.g. "GNOME"
+ *
+ * Searches the known list of registered environment IDs.
+ *
+ * Returns: %TRUE if the environment ID is valid
+ *
+ * Since: 0.2.4
+ **/
+gboolean
+as_utils_is_environment_id (const gchar *environment_id)
+{
+ _cleanup_bytes_unref_ GBytes *data;
+ _cleanup_free_ gchar *key = NULL;
+
+ /* load the readonly data section and look for the icon name */
+ data = g_resource_lookup_data (as_get_resource (),
+ "/org/freedesktop/appstream-glib/as-environment-ids.txt",
+ G_RESOURCE_LOOKUP_FLAGS_NONE,
+ NULL);
+ if (data == NULL)
+ return FALSE;
+ key = g_strdup_printf ("\n%s\n", environment_id);
+ return g_strstr_len (g_bytes_get_data (data, NULL), -1, key) != NULL;
+}
+
+/**
+ * as_utils_is_category_id:
+ * @category_id: a desktop ID, e.g. "AudioVideoEditing"
+ *
+ * Searches the known list of registered category IDs.
+ *
+ * Returns: %TRUE if the category ID is valid
+ *
+ * Since: 0.2.4
+ **/
+gboolean
+as_utils_is_category_id (const gchar *category_id)
+{
+ _cleanup_bytes_unref_ GBytes *data;
+ _cleanup_free_ gchar *key = NULL;
+
+ /* load the readonly data section and look for the icon name */
+ data = g_resource_lookup_data (as_get_resource (),
+ "/org/freedesktop/appstream-glib/as-category-ids.txt",
+ G_RESOURCE_LOOKUP_FLAGS_NONE,
+ NULL);
+ if (data == NULL)
+ return FALSE;
+ key = g_strdup_printf ("\n%s\n", category_id);
+ return g_strstr_len (g_bytes_get_data (data, NULL), -1, key) != NULL;
+}
+
+/**
* as_utils_spdx_license_tokenize:
* @license: a license string, e.g. "LGPLv2+ and (QPL or GPLv2) and MIT"
*
diff --git a/libappstream-glib/as-utils.h b/libappstream-glib/as-utils.h
index 3fe76fe..2e9b094 100644
--- a/libappstream-glib/as-utils.h
+++ b/libappstream-glib/as-utils.h
@@ -35,6 +35,8 @@ gchar *as_markup_convert_simple (const gchar *markup,
GError **error);
gboolean as_utils_is_stock_icon_name (const gchar *name);
gboolean as_utils_is_spdx_license_id (const gchar *license_id);
+gboolean as_utils_is_environment_id (const gchar *environment_id);
+gboolean as_utils_is_category_id (const gchar *category_id);
gboolean as_utils_is_blacklisted_id (const gchar *desktop_id);
gchar **as_utils_spdx_license_tokenize (const gchar *license);
gboolean as_utils_check_url_exists (const gchar *url,