diff options
author | Richard Hughes <richard@hughsie.com> | 2014-03-26 19:28:59 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-03-26 19:29:59 +0000 |
commit | ce8c928eb97e62f9d38778e5d39be6c12cbbc79f (patch) | |
tree | 9b703cf5d9e235f14dcc58830254ca0484b9efde | |
parent | 721128cbb2c7c5f361cc71b551890e104b670e5a (diff) | |
download | appstream-glib-ce8c928eb97e62f9d38778e5d39be6c12cbbc79f.tar.gz |
Add as_utils_is_stock_icon_name()
This means we add 8k to the library size as we use an embedded GResource.
-rw-r--r-- | libappstream-glib/Makefile.am | 33 | ||||
-rw-r--r-- | libappstream-glib/appstream-glib.gresource.xml | 6 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 8 | ||||
-rw-r--r-- | libappstream-glib/as-stock-icons.txt | 305 | ||||
-rw-r--r-- | libappstream-glib/as-utils.c | 35 | ||||
-rw-r--r-- | libappstream-glib/as-utils.h | 1 |
6 files changed, 385 insertions, 3 deletions
diff --git a/libappstream-glib/Makefile.am b/libappstream-glib/Makefile.am index 1a806e4..dd4d96d 100644 --- a/libappstream-glib/Makefile.am +++ b/libappstream-glib/Makefile.am @@ -24,6 +24,29 @@ as-tag-private.h: as-tag.gperf $(AM_V_GEN) gperf < $< > $@ endif +as-resources.c: appstream-glib.gresource.xml as-stock-icons.txt + $(AM_V_GEN) \ + glib-compile-resources \ + --sourcedir=$(srcdir) \ + --sourcedir=$(top_builddir)/data \ + --target=$@ \ + --generate-source \ + --c-name as \ + $(srcdir)/appstream-glib.gresource.xml +as-resources.h: appstream-glib.gresource.xml as-stock-icons.txt + $(AM_V_GEN) \ + glib-compile-resources \ + --sourcedir=$(srcdir) \ + --sourcedir=$(top_builddir)/data \ + --target=$@ \ + --generate-header \ + --c-name as \ + $(srcdir)/appstream-glib.gresource.xml + +BUILT_SOURCES = \ + as-resources.c \ + as-resources.h + lib_LTLIBRARIES = \ libappstream-glib.la @@ -51,6 +74,8 @@ libappstream_glib_la_SOURCES = \ as-node-private.h \ as-release.c \ as-release-private.h \ + as-resources.c \ + as-resources.h \ as-screenshot.c \ as-screenshot-private.h \ as-store.c \ @@ -61,7 +86,7 @@ libappstream_glib_la_SOURCES = \ if HAVE_GPERF libappstream_glib_la_SOURCES += as-tag-private.h -BUILT_SOURCES = as-tag-private.h +BUILT_SOURCES += as-tag-private.h endif CLEANFILES = $(BUILT_SOURCES) @@ -137,9 +162,11 @@ DISTCLEANFILES = \ *.trs EXTRA_DIST = \ + appstream-glib.gresource.xml \ + appstream-glib.pc.in \ + as-stock-icons.txt \ as-tag.gperf \ - as-version.h.in \ - appstream-glib.pc.in + as-version.h.in clean-local: rm -f *~ diff --git a/libappstream-glib/appstream-glib.gresource.xml b/libappstream-glib/appstream-glib.gresource.xml new file mode 100644 index 0000000..8c6302d --- /dev/null +++ b/libappstream-glib/appstream-glib.gresource.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/freedesktop/appstream-glib"> + <file>as-stock-icons.txt</file> + </gresource> +</gresources> diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index ab71cb0..ea5ee6e 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -897,6 +897,14 @@ ch_test_utils_func (void) g_assert_cmpstr (tmp, ==, "dave"); g_free (tmp); + /* as_utils_is_stock_icon_name */ + g_assert (!as_utils_is_stock_icon_name (NULL)); + g_assert (!as_utils_is_stock_icon_name ("")); + g_assert (!as_utils_is_stock_icon_name ("indigo-blue")); + g_assert (as_utils_is_stock_icon_name ("accessories-calculator")); + g_assert (as_utils_is_stock_icon_name ("insert-image")); + g_assert (as_utils_is_stock_icon_name ("zoom-out")); + /* valid description markup */ tmp = as_markup_convert_simple ("<p>Hello world!</p>", -1, &error); g_assert_no_error (error); diff --git a/libappstream-glib/as-stock-icons.txt b/libappstream-glib/as-stock-icons.txt new file mode 100644 index 0000000..7b3beef --- /dev/null +++ b/libappstream-glib/as-stock-icons.txt @@ -0,0 +1,305 @@ +# this file contains the icon set of gnome-icon-theme +accessories-calculator +accessories-character-map +accessories-dictionary +accessories-text-editor +address-book-new +application-exit +applications-accessories +applications-development +applications-engineering +applications-games +applications-graphics +applications-internet +applications-multimedia +applications-office +applications-other +applications-science +applications-system +applications-utilities +application-x-executable +appointment-missed +appointment-new +appointment-soon +audio-card +audio-input-microphone +audio-volume-high +audio-volume-low +audio-volume-medium +audio-volume-muted +audio-x-generic +battery +battery-caution +battery-low +call-start +call-stop +camera-photo +camera-video +camera-web +computer +computer +contact-new +dialog-error +dialog-information +dialog-password +dialog-question +dialog-warning +document-new +document-open +document-open-recent +document-page-setup +document-print +document-print-preview +document-properties +document-revert +document-save +document-save-as +document-send +drive-harddisk +drive-optical +drive-removable-media +drive-removable-media +edit-clear +edit-copy +edit-cut +edit-delete +edit-find +edit-find-replace +edit-paste +edit-redo +edit-select-all +edit-undo +emblem-default +emblem-documents +emblem-downloads +emblem-favorite +emblem-important +emblem-mail +emblem-photos +emblem-readonly +emblem-shared +emblem-symbolic-link +emblem-synchronized +emblem-system +emblem-unreadable +face-angel +face-angry +face-cool +face-crying +face-devilish +face-embarrassed +face-glasses +face-kiss +face-laugh +face-monkey +face-plain +face-raspberry +face-sad +face-sick +face-smile +face-smile-big +face-smirk +face-surprise +face-tired +face-uncertain +face-wink +face-worried +flag-aa +folder +folder-drag-accept +folder-new +folder-open +folder-remote +folder-visiting +font-x-generic +format-indent-less +format-indent-more +format-justify-center +format-justify-fill +format-justify-left +format-justify-right +format-text-bold +format-text-direction-ltr +format-text-direction-rtl +format-text-italic +format-text-strikethrough +format-text-underline +go-bottom +go-down +go-first +go-home +go-jump +go-last +go-next +go-previous +go-top +go-up +help-about +help-browser +help-browser +help-contents +help-faq +image-loading +image-missing +image-x-generic +input-gaming +input-keyboard +input-mouse +input-tablet +insert-image +insert-link +insert-object +insert-text +list-add +list-remove +mail-attachment +mail-forward +mail-mark-important +mail-mark-junk +mail-mark-notjunk +mail-mark-read +mail-mark-unread +mail-message-new +mail-read +mail-replied +mail-reply-all +mail-reply-sender +mail-send +mail-send-receive +mail-signed +mail-signed-verified +mail-unread +media-cdrom +media-eject +media-flash +media-floppy +media-optical +media-playback-pause +media-playback-start +media-playback-stop +media-playlist-repeat +media-playlist-shuffle +media-record +media-seek-backward +media-seek-forward +media-skip-backward +media-skip-forward +media-tape +modem +multimedia-player +multimedia-volume-control +network-error +network-idle +network-offline +network-receive +network-server +network-transmit +network-transmit-receive +network-wired +network-wireless +network-workgroup +object-flip-horizontal +object-flip-vertical +object-rotate-left +object-rotate-right +package-x-generic +pda +phone +preferences-desktop +preferences-desktop +preferences-desktop-accessibility +preferences-desktop-display +preferences-desktop-font +preferences-desktop-keyboard +preferences-desktop-keyboard-shortcuts +preferences-desktop-locale +preferences-desktop-multimedia +preferences-desktop-peripherals +preferences-desktop-personal +preferences-desktop-remote-desktop +preferences-desktop-screensaver +preferences-desktop-theme +preferences-desktop-wallpaper +preferences-other +preferences-system +preferences-system-network +preferences-system-notifications +preferences-system-privacy +preferences-system-search +preferences-system-sharing +preferences-system-windows +printer +printer +printer-error +printer-printing +process-stop +scanner +security-high +security-low +security-medium +software-update-available +software-update-urgent +start-here +sync-error +sync-synchronizing +system-file-manager +system-file-manager +system-help +system-lock-screen +system-log-out +system-reboot +system-run +system-search +system-shutdown +system-software-install +system-software-update +system-users +task-due +task-past-due +text-html +text-x-generic +text-x-generic-template +text-x-script +tools-check-spelling +user-available +user-away +user-bookmarks +user-desktop +user-home +user-idle +user-offline +user-trash +user-trash-full +utilities-system-monitor +utilities-terminal +video-display +video-display +video-x-generic +view-fullscreen +view-refresh +view-restore +view-sort-ascending +view-sort-descending +weather-clear +weather-clear-night +weather-few-clouds +weather-few-clouds-night +weather-fog +weather-overcast +weather-severe-alert +weather-showers +weather-showers-scattered +weather-snow +weather-storm +web-browser +window-close +window-new +x-office-address-book +x-office-calendar +x-office-document +x-office-presentation +x-office-spreadsheet +zoom-fit-best +zoom-in +zoom-original +zoom-out diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c index 37dcc0b..9ef2e90 100644 --- a/libappstream-glib/as-utils.c +++ b/libappstream-glib/as-utils.c @@ -32,6 +32,7 @@ #include "config.h" #include "as-node.h" +#include "as-resources.h" #include "as-utils.h" #include "as-utils-private.h" @@ -192,3 +193,37 @@ as_hash_lookup_by_locale (GHashTable *hash, const gchar *locale) out: return tmp; } + +/** + * as_utils_is_stock_icon_name: + * @name: an icon name + * + * Searches the known list of stock icons. + * + * Returns: %TRUE if the icon is a "stock icon name" and does not need to be + * included in the AppStream icon tarball + * + * Since: 0.1.3 + **/ +gboolean +as_utils_is_stock_icon_name (const gchar *name) +{ + GBytes *data; + gboolean ret = FALSE; + 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-stock-icons.txt", + G_RESOURCE_LOOKUP_FLAGS_NONE, + NULL); + if (data == NULL) + goto out; + key = g_strdup_printf ("\n%s\n", name); + ret = g_strstr_len (g_bytes_get_data (data, NULL), -1, key) != NULL; +out: + if (data != NULL) + g_bytes_unref (data); + g_free (key); + return ret; +} diff --git a/libappstream-glib/as-utils.h b/libappstream-glib/as-utils.h index 22d6e19..991b49d 100644 --- a/libappstream-glib/as-utils.h +++ b/libappstream-glib/as-utils.h @@ -33,6 +33,7 @@ G_BEGIN_DECLS gchar *as_markup_convert_simple (const gchar *markup, gssize markup_len, GError **error); +gboolean as_utils_is_stock_icon_name (const gchar *name); G_END_DECLS |