summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-03-25 16:20:33 +0000
committerRichard Hughes <richard@hughsie.com>2015-04-07 08:47:02 +0100
commitc5a8e1cda057e78b26505a43fba88273bfa2ef09 (patch)
tree94da136d179714c6e2fe857530ca98fbcee2fe21
parentff7df39b02f64688a653c536949eb7d5d51fcce0 (diff)
downloadappstream-glib-c5a8e1cda057e78b26505a43fba88273bfa2ef09.tar.gz
Remove all networking support when building metadata
Distros currently relying on '--screenshot-uri' should start using the 'appstream-util mirror-screenshots' command after the builder has completed.
-rw-r--r--client/as-builder.c20
-rw-r--r--libappstream-builder/Makefile.am1
-rw-r--r--libappstream-builder/asb-app.c160
-rw-r--r--libappstream-builder/asb-context.c109
-rw-r--r--libappstream-builder/asb-context.h3
-rw-r--r--libappstream-builder/asb-self-test.c9
-rw-r--r--libappstream-builder/plugins/asb-plugin-appdata.c114
-rw-r--r--libappstream-builder/plugins/asb-plugin-font.c29
8 files changed, 58 insertions, 387 deletions
diff --git a/client/as-builder.c b/client/as-builder.c
index a46cf68..af6c414 100644
--- a/client/as-builder.c
+++ b/client/as-builder.c
@@ -133,7 +133,6 @@ main (int argc, char **argv)
gboolean embedded_icons = FALSE;
gboolean hidpi_enabled = FALSE;
gboolean include_failed = FALSE;
- gboolean no_net = FALSE;
gboolean ret;
gboolean uncompressed_icons = FALSE;
gboolean verbose = FALSE;
@@ -154,8 +153,6 @@ main (int argc, char **argv)
_cleanup_free_ gchar *origin = NULL;
_cleanup_free_ gchar *ostree_repo = NULL;
_cleanup_free_ gchar *output_dir = NULL;
- _cleanup_free_ gchar *screenshot_dir = NULL;
- _cleanup_free_ gchar *screenshot_uri = NULL;
_cleanup_free_ gchar *temp_dir = NULL;
_cleanup_free_ gchar **veto_ignore = NULL;
_cleanup_ptrarray_unref_ GPtrArray *packages = NULL;
@@ -165,9 +162,6 @@ main (int argc, char **argv)
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
/* TRANSLATORS: command line option */
_("Show extra debugging information"), NULL },
- { "no-net", '\0', 0, G_OPTION_ARG_NONE, &no_net,
- /* TRANSLATORS: command line option */
- _("Do not use the network to download screenshots"), NULL },
{ "add-cache-id", '\0', 0, G_OPTION_ARG_NONE, &add_cache_id,
/* TRANSLATORS: command line option */
_("Add a cache ID to each component"), NULL },
@@ -189,9 +183,6 @@ main (int argc, char **argv)
{ "log-dir", '\0', 0, G_OPTION_ARG_FILENAME, &log_dir,
/* TRANSLATORS: command line option */
_("Set the logging directory"), "DIR" },
- { "screenshot-dir", '\0', 0, G_OPTION_ARG_FILENAME, &screenshot_dir,
- /* TRANSLATORS: command line option */
- _("Set the screenshots directory"), "DIR" },
{ "packages-dir", '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &packages_dirs,
/* TRANSLATORS: command line option */
_("Set the packages directory"), "DIR" },
@@ -228,9 +219,6 @@ main (int argc, char **argv)
{ "api-version", '\0', 0, G_OPTION_ARG_DOUBLE, &api_version,
/* TRANSLATORS: command line option */
_("Set the AppStream version"), "API_VERSION" },
- { "screenshot-uri", '\0', 0, G_OPTION_ARG_STRING, &screenshot_uri,
- /* TRANSLATORS: command line option */
- _("Set the screenshot base URL"), "URI" },
{ "ostree-repo", '\0', 0, G_OPTION_ARG_STRING, &ostree_repo,
/* TRANSLATORS: command line option */
_("Set the ostree repo name"), "REPO" },
@@ -275,8 +263,6 @@ main (int argc, char **argv)
temp_dir = g_strdup ("./tmp");
if (log_dir == NULL)
log_dir = g_strdup ("./logs");
- if (screenshot_dir == NULL)
- screenshot_dir = g_build_filename (temp_dir, "screenshots", NULL);
if (output_dir == NULL)
output_dir = g_strdup (".");
if (icons_dir == NULL)
@@ -287,8 +273,6 @@ main (int argc, char **argv)
basename = g_strdup ("appstream");
if (origin == NULL)
origin = g_strdup ("example");
- if (screenshot_uri == NULL)
- screenshot_uri = g_strdup ("http://www.example.com/screenshots/");
if (extra_appdata == NULL)
extra_appdata = g_strdup ("./appdata-extra");
if (extra_screenshots == NULL)
@@ -300,9 +284,7 @@ main (int argc, char **argv)
asb_context_set_old_metadata (ctx, old_metadata);
asb_context_set_extra_appdata (ctx, extra_appdata);
asb_context_set_extra_screenshots (ctx, extra_screenshots);
- asb_context_set_screenshot_uri (ctx, screenshot_uri);
asb_context_set_log_dir (ctx, log_dir);
- asb_context_set_screenshot_dir (ctx, screenshot_dir);
asb_context_set_temp_dir (ctx, temp_dir);
asb_context_set_output_dir (ctx, output_dir);
asb_context_set_icons_dir (ctx, icons_dir);
@@ -334,8 +316,6 @@ main (int argc, char **argv)
flags |= ASB_CONTEXT_FLAG_HIDPI_ICONS;
if (add_cache_id)
flags |= ASB_CONTEXT_FLAG_ADD_CACHE_ID;
- if (no_net)
- flags |= ASB_CONTEXT_FLAG_NO_NETWORK;
if (embedded_icons)
flags |= ASB_CONTEXT_FLAG_EMBEDDED_ICONS;
if (include_failed)
diff --git a/libappstream-builder/Makefile.am b/libappstream-builder/Makefile.am
index e31351d..f8ec8ab 100644
--- a/libappstream-builder/Makefile.am
+++ b/libappstream-builder/Makefile.am
@@ -109,7 +109,6 @@ asb_self_test_LDADD = \
$(AS_GLIB_LIBS) \
$(GLIB_LIBS) \
$(GDKPIXBUF_LIBS) \
- $(SOUP_LIBS) \
$(lib_LTLIBRARIES)
asb_self_test_CFLAGS = $(WARNINGFLAGS_C)
diff --git a/libappstream-builder/asb-app.c b/libappstream-builder/asb-app.c
index b91b1f9..8cc33de 100644
--- a/libappstream-builder/asb-app.c
+++ b/libappstream-builder/asb-app.c
@@ -171,84 +171,6 @@ asb_app_get_package (AsbApp *app)
}
/**
- * asb_app_save_resources_image:
- **/
-static gboolean
-asb_app_save_resources_image (AsbApp *app,
- AsImage *image,
- GError **error)
-{
- const gchar *output_dir;
- gboolean ret = TRUE;
- _cleanup_free_ gchar *filename = NULL;
- _cleanup_free_ gchar *size_str = NULL;
-
- /* treat source images differently */
- if (as_image_get_kind (image) == AS_IMAGE_KIND_SOURCE) {
- size_str = g_strdup ("source");
- } else {
- size_str = g_strdup_printf ("%ix%i",
- as_image_get_width (image),
- as_image_get_height (image));
- }
-
- /* does screenshot already exist */
- output_dir = asb_package_get_config (asb_app_get_package (app), "ScreenshotDir");
- if (output_dir == NULL)
- return TRUE;
- filename = g_build_filename (output_dir,
- size_str,
- as_image_get_basename (image),
- NULL);
- if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
- asb_package_log (asb_app_get_package (app),
- ASB_PACKAGE_LOG_LEVEL_DEBUG,
- "%s screenshot already exists", size_str);
- return TRUE;
- }
-
- /* thumbnails will already be 16:9 */
- ret = as_image_save_filename (image,
- filename,
- 0, 0,
- AS_IMAGE_SAVE_FLAG_NONE,
- error);
- if (!ret)
- return FALSE;
-
- /* set new AppStream compatible screenshot name */
- asb_package_log (asb_app_get_package (app),
- ASB_PACKAGE_LOG_LEVEL_DEBUG,
- "saved %s screenshot", size_str);
- return TRUE;
-
-}
-
-/**
- * asb_app_save_resources_screenshot:
- **/
-static gboolean
-asb_app_save_resources_screenshot (AsbApp *app,
- AsScreenshot *screenshot,
- GError **error)
-{
- AsImage *im;
- GPtrArray *images;
- guint i;
-
- images = as_screenshot_get_images (screenshot);
- for (i = 0; i < images->len; i++) {
- im = g_ptr_array_index (images, i);
- if (!asb_app_save_resources_image (app, im, error))
- return FALSE;
-
- /* clear the image data to reduce memory usage */
- as_image_set_pixbuf (im, NULL);
- }
- return TRUE;
-}
-
-/**
* asb_app_set_hidpi_enabled:
* @app: A #AsbApp
* @hidpi_enabled: if HiDPI mode should be enabled
@@ -281,10 +203,8 @@ asb_app_save_resources (AsbApp *app, AsbAppSaveFlags save_flags, GError **error)
{
AsbAppPrivate *priv = GET_PRIVATE (app);
AsIcon *icon;
- AsScreenshot *ss;
GdkPixbuf *pixbuf;
GPtrArray *icons = NULL;
- GPtrArray *screenshots = NULL;
guint i;
/* any non-stock icon set */
@@ -325,56 +245,6 @@ asb_app_save_resources (AsbApp *app, AsbAppSaveFlags save_flags, GError **error)
ASB_PACKAGE_LOG_LEVEL_DEBUG,
"Saved icon %s", filename);
}
-
- /* save any screenshots */
- if (save_flags & ASB_APP_SAVE_FLAG_SCREENSHOTS)
- screenshots = as_app_get_screenshots (AS_APP (app));
- for (i = 0; screenshots != NULL && i < screenshots->len; i++) {
- ss = g_ptr_array_index (screenshots, i);
- if (!asb_app_save_resources_screenshot (app, ss, error))
- return FALSE;
- }
- return TRUE;
-}
-
-/**
- * asb_app_save_thumbnail:
- **/
-static gboolean
-asb_app_save_thumbnail (AsScreenshot *ss, AsImage *im_src,
- guint width, guint height, guint scale,
- const gchar *mirror_uri,
- GError **error)
-{
- _cleanup_free_ gchar *size_str = NULL;
- _cleanup_free_ gchar *url_tmp = NULL;
- _cleanup_object_unref_ AsImage *im_tmp = NULL;
- _cleanup_object_unref_ GdkPixbuf *pixbuf = NULL;
-
- /* only save the HiDPI screenshot if it's not padded */
- if (scale > 1) {
- if (width * scale > as_image_get_width (im_src) ||
- height * scale > as_image_get_height (im_src))
- return TRUE;
- }
- size_str = g_strdup_printf ("%ix%i", width * scale, height * scale);
- url_tmp = g_build_filename (mirror_uri,
- size_str,
- as_image_get_basename (im_src),
- NULL);
- pixbuf = as_image_save_pixbuf (im_src,
- width * scale,
- height * scale,
- AS_IMAGE_SAVE_FLAG_PAD_16_9 |
- AS_IMAGE_SAVE_FLAG_SHARPEN);
- im_tmp = as_image_new ();
- as_image_set_width (im_tmp, width * scale);
- as_image_set_height (im_tmp, height * scale);
- as_image_set_url (im_tmp, url_tmp, -1);
- as_image_set_pixbuf (im_tmp, pixbuf);
- as_image_set_kind (im_tmp, AS_IMAGE_KIND_THUMBNAIL);
- as_image_set_basename (im_tmp, as_image_get_basename (im_src));
- as_screenshot_add_image (ss, im_tmp);
return TRUE;
}
@@ -393,20 +263,13 @@ asb_app_save_thumbnail (AsScreenshot *ss, AsImage *im_src,
gboolean
asb_app_add_screenshot_source (AsbApp *app, const gchar *filename, GError **error)
{
- AsbAppPrivate *priv = GET_PRIVATE (app);
AsImageAlphaFlags alpha_flags;
gboolean is_default;
- const gchar *mirror_uri;
- guint i;
_cleanup_free_ gchar *basename = NULL;
_cleanup_free_ gchar *filename_no_path = NULL;
_cleanup_free_ gchar *url_src = NULL;
_cleanup_object_unref_ AsImage *im_src = NULL;
_cleanup_object_unref_ AsScreenshot *ss = NULL;
- guint sizes[] = { AS_IMAGE_NORMAL_WIDTH, AS_IMAGE_NORMAL_HEIGHT,
- AS_IMAGE_THUMBNAIL_WIDTH, AS_IMAGE_THUMBNAIL_HEIGHT,
- AS_IMAGE_LARGE_WIDTH, AS_IMAGE_LARGE_HEIGHT,
- 0 };
im_src = as_image_new ();
if (!as_image_load_filename (im_src, filename, error))
@@ -467,31 +330,10 @@ asb_app_add_screenshot_source (AsbApp *app, const gchar *filename, GError **erro
as_image_set_basename (im_src, basename);
/* fonts only have full sized screenshots */
- mirror_uri = asb_package_get_config (asb_app_get_package (app), "MirrorURI");
- url_src = g_build_filename (mirror_uri, "source", basename, NULL);
+ url_src = g_build_filename ("file://", basename, NULL);
as_image_set_url (im_src, url_src, -1);
as_image_set_kind (im_src, AS_IMAGE_KIND_SOURCE);
as_screenshot_add_image (ss, im_src);
- if (as_app_get_id_kind (AS_APP (app)) != AS_ID_KIND_FONT) {
- for (i = 0; sizes[i] != 0; i += 2) {
-
- /* save LoDPI */
- if (!asb_app_save_thumbnail (ss, im_src,
- sizes[i], sizes[i+1],
- 1, mirror_uri, error))
- return FALSE;
-
- /* save HiDPI version */
- if (priv->hidpi_enabled) {
- if (!asb_app_save_thumbnail (ss, im_src,
- sizes[i],
- sizes[i+1],
- 2, mirror_uri,
- error))
- return FALSE;
- }
- }
- }
as_app_add_screenshot (AS_APP (app), ss);
return TRUE;
}
diff --git a/libappstream-builder/asb-context.c b/libappstream-builder/asb-context.c
index f904bca..d9ccd03 100644
--- a/libappstream-builder/asb-context.c
+++ b/libappstream-builder/asb-context.c
@@ -70,9 +70,7 @@ struct _AsbContextPrivate
gchar *old_metadata;
gchar *extra_appdata;
gchar *extra_screenshots;
- gchar *screenshot_uri;
gchar *log_dir;
- gchar *screenshot_dir;
gchar *cache_dir;
gchar *temp_dir;
gchar *output_dir;
@@ -249,22 +247,6 @@ asb_context_set_extra_screenshots (AsbContext *ctx, const gchar *extra_screensho
}
/**
- * asb_context_set_screenshot_uri:
- * @ctx: A #AsbContext
- * @screenshot_uri: Remote URI root, e.g. "http://www.mysite.com/screenshots/"
- *
- * Sets the remote screenshot URI for screenshots.
- *
- * Since: 0.1.0
- **/
-void
-asb_context_set_screenshot_uri (AsbContext *ctx, const gchar *screenshot_uri)
-{
- AsbContextPrivate *priv = GET_PRIVATE (ctx);
- priv->screenshot_uri = g_strdup (screenshot_uri);
-}
-
-/**
* asb_context_set_log_dir:
* @ctx: A #AsbContext
* @log_dir: directory
@@ -281,22 +263,6 @@ asb_context_set_log_dir (AsbContext *ctx, const gchar *log_dir)
}
/**
- * asb_context_set_screenshot_dir:
- * @ctx: A #AsbContext
- * @screenshot_dir: directory
- *
- * Sets the screenshot directory to use when building metadata.
- *
- * Since: 0.2.2
- **/
-void
-asb_context_set_screenshot_dir (AsbContext *ctx, const gchar *screenshot_dir)
-{
- AsbContextPrivate *priv = GET_PRIVATE (ctx);
- priv->screenshot_dir = g_strdup (screenshot_dir);
-}
-
-/**
* asb_context_set_cache_dir:
* @ctx: A #AsbContext
* @cache_dir: directory
@@ -462,6 +428,23 @@ asb_context_get_temp_dir (AsbContext *ctx)
}
/**
+ * asb_context_get_cache_dir:
+ * @ctx: A #AsbContext
+ *
+ * Gets the screenshot directory to use
+ *
+ * Returns: directory
+ *
+ * Since: 0.3.6
+ **/
+const gchar *
+asb_context_get_cache_dir (AsbContext *ctx)
+{
+ AsbContextPrivate *priv = GET_PRIVATE (ctx);
+ return priv->cache_dir;
+}
+
+/**
* asb_context_get_plugin_loader:
* @ctx: A #AsbContext
*
@@ -601,12 +584,9 @@ gboolean
asb_context_setup (AsbContext *ctx, GError **error)
{
AsbContextPrivate *priv = GET_PRIVATE (ctx);
- guint i;
- guint sizes[] = { AS_IMAGE_NORMAL_WIDTH, AS_IMAGE_NORMAL_HEIGHT,
- AS_IMAGE_THUMBNAIL_WIDTH, AS_IMAGE_THUMBNAIL_HEIGHT,
- AS_IMAGE_LARGE_WIDTH, AS_IMAGE_LARGE_HEIGHT,
- 0 };
_cleanup_free_ gchar *icons_dir = NULL;
+ _cleanup_free_ gchar *screenshot_dir1 = NULL;
+ _cleanup_free_ gchar *screenshot_dir2 = NULL;
/* required stuff set */
if (priv->origin == NULL) {
@@ -646,11 +626,13 @@ asb_context_setup (AsbContext *ctx, GError **error)
}
/* create temp space */
- if (!asb_utils_ensure_exists_and_empty (priv->temp_dir, error))
- return FALSE;
if (!asb_utils_ensure_exists (priv->output_dir, error))
return FALSE;
- if (!asb_utils_ensure_exists (priv->cache_dir, error))
+ screenshot_dir1 = g_build_filename (priv->temp_dir, "screenshots", NULL);
+ if (!asb_utils_ensure_exists_and_empty (screenshot_dir1, error))
+ return FALSE;
+ screenshot_dir2 = g_build_filename (priv->cache_dir, "screenshots", NULL);
+ if (!asb_utils_ensure_exists (screenshot_dir2, error))
return FALSE;
if (priv->log_dir != NULL) {
if (!asb_utils_ensure_exists (priv->log_dir, error))
@@ -671,38 +653,6 @@ asb_context_setup (AsbContext *ctx, GError **error)
return FALSE;
}
- /* create all the screenshot sizes */
- if (priv->screenshot_dir != NULL) {
- gboolean hidpi_enabled = (priv->flags & ASB_CONTEXT_FLAG_HIDPI_ICONS) > 0;
- _cleanup_free_ gchar *ss_src = NULL;
- ss_src = g_build_filename (priv->screenshot_dir,
- "source", NULL);
- if (!asb_utils_ensure_exists (ss_src, error))
- return FALSE;
- for (i = 0; sizes[i] != 0; i += 2) {
- _cleanup_free_ gchar *size_str = NULL;
- _cleanup_free_ gchar *ss_dir = NULL;
- size_str = g_strdup_printf ("%ix%i",
- sizes[i],
- sizes[i+1]);
- ss_dir = g_build_filename (priv->screenshot_dir,
- size_str, NULL);
- if (!asb_utils_ensure_exists (ss_dir, error))
- return FALSE;
- }
- for (i = 0; sizes[i] != 0 && hidpi_enabled; i += 2) {
- _cleanup_free_ gchar *size_str = NULL;
- _cleanup_free_ gchar *ss_dir = NULL;
- size_str = g_strdup_printf ("%ix%i",
- sizes[i] * 2,
- sizes[i+1] * 2);
- ss_dir = g_build_filename (priv->screenshot_dir,
- size_str, NULL);
- if (!asb_utils_ensure_exists (ss_dir, error))
- return FALSE;
- }
- }
-
/* decompress the icons */
if (priv->old_metadata != NULL) {
_cleanup_free_ gchar *icons_fn = NULL;
@@ -839,17 +789,19 @@ asb_context_write_screenshots (AsbContext *ctx,
{
AsbContextPrivate *priv = GET_PRIVATE (ctx);
_cleanup_free_ gchar *filename = NULL;
+ _cleanup_free_ gchar *screenshot_dir = NULL;
/* not enabled */
if (priv->flags & ASB_CONTEXT_FLAG_UNCOMPRESSED_ICONS)
return TRUE;
- if (!g_file_test (priv->screenshot_dir, G_FILE_TEST_EXISTS))
+ screenshot_dir = g_build_filename (temp_dir, "screenshots", NULL);
+ if (!g_file_test (screenshot_dir, G_FILE_TEST_EXISTS))
return TRUE;
filename = g_strdup_printf ("%s/%s-screenshots.tar",
priv->output_dir, priv->basename);
g_print ("Writing %s...\n", filename);
- return asb_utils_write_archive_dir (filename, priv->screenshot_dir, error);
+ return asb_utils_write_archive_dir (filename, screenshot_dir, error);
}
/**
@@ -1332,10 +1284,7 @@ asb_context_process (AsbContext *ctx, GError **error)
/* set locations of external resources */
asb_package_set_config (pkg, "AppDataExtra", priv->extra_appdata);
asb_package_set_config (pkg, "ScreenshotsExtra", priv->extra_screenshots);
- asb_package_set_config (pkg, "MirrorURI", priv->screenshot_uri);
asb_package_set_config (pkg, "LogDir", priv->log_dir);
- asb_package_set_config (pkg, "ScreenshotDir", priv->screenshot_dir);
- asb_package_set_config (pkg, "CacheDir", priv->cache_dir);
asb_package_set_config (pkg, "TempDir", priv->temp_dir);
asb_package_set_config (pkg, "IconsDir", priv->icons_dir);
asb_package_set_config (pkg, "OutputDir", priv->output_dir);
@@ -1579,9 +1528,7 @@ asb_context_finalize (GObject *object)
g_free (priv->old_metadata);
g_free (priv->extra_appdata);
g_free (priv->extra_screenshots);
- g_free (priv->screenshot_uri);
g_free (priv->log_dir);
- g_free (priv->screenshot_dir);
g_free (priv->cache_dir);
g_free (priv->temp_dir);
g_free (priv->output_dir);
diff --git a/libappstream-builder/asb-context.h b/libappstream-builder/asb-context.h
index 68ad40d..2f41517 100644
--- a/libappstream-builder/asb-context.h
+++ b/libappstream-builder/asb-context.h
@@ -111,8 +111,6 @@ void asb_context_set_extra_appdata (AsbContext *ctx,
const gchar *extra_appdata);
void asb_context_set_extra_screenshots (AsbContext *ctx,
const gchar *extra_screenshots);
-void asb_context_set_screenshot_uri (AsbContext *ctx,
- const gchar *screenshot_uri);
void asb_context_set_log_dir (AsbContext *ctx,
const gchar *log_dir);
void asb_context_set_screenshot_dir (AsbContext *ctx,
@@ -130,6 +128,7 @@ void asb_context_set_basename (AsbContext *ctx,
void asb_context_set_origin (AsbContext *ctx,
const gchar *origin);
const gchar *asb_context_get_temp_dir (AsbContext *ctx);
+const gchar *asb_context_get_cache_dir (AsbContext *ctx);
AsbContextFlags asb_context_get_flags (AsbContext *ctx);
gboolean asb_context_get_flag (AsbContext *ctx,
AsbContextFlags flag);
diff --git a/libappstream-builder/asb-self-test.c b/libappstream-builder/asb-self-test.c
index 2f2a037..0881a5c 100644
--- a/libappstream-builder/asb-self-test.c
+++ b/libappstream-builder/asb-self-test.c
@@ -341,7 +341,6 @@ asb_test_context_test_func (AsbTestContextMode mode)
asb_context_set_output_dir (ctx, "/tmp/asbuilder/output");
asb_context_set_temp_dir (ctx, "/tmp/asbuilder/temp");
asb_context_set_icons_dir (ctx, "/tmp/asbuilder/temp/icons");
- asb_context_set_screenshot_dir (ctx, "/tmp/asbuilder/temp/screenshots");
switch (mode) {
case ASB_TEST_CONTEXT_MODE_WITH_CACHE:
asb_context_set_old_metadata (ctx, "/tmp/asbuilder/output");
@@ -453,11 +452,11 @@ asb_test_context_test_func (AsbTestContextMode mode)
"<screenshots>\n"
"<screenshot type=\"default\">\n"
"<caption>Liberation Serif – Regular</caption>\n"
- "<image type=\"source\" height=\"48\" width=\"640\"/>\n"
+ "<image type=\"source\" height=\"48\" width=\"640\">file:/LiberationSerif-660e7a5a60fdeb133d3e8b24e2766f2e.png</image>\n"
"</screenshot>\n"
"<screenshot priority=\"-32\">\n"
"<caption>Liberation Serif – Bold</caption>\n"
- "<image type=\"source\" height=\"48\" width=\"640\"/>\n"
+ "<image type=\"source\" height=\"48\" width=\"640\">file:/LiberationSerif-660e7a5a60fdeb133d3e8b24e2766f2e.png</image>\n"
"</screenshot>\n"
"</screenshots>\n"
"<releases>\n"
@@ -619,11 +618,11 @@ asb_test_context_test_func (AsbTestContextMode mode)
"<screenshots>\n"
"<screenshot type=\"default\">\n"
"<caption>Liberation Serif – Regular</caption>\n"
- "<image type=\"source\" height=\"48\" width=\"640\"/>\n"
+ "<image type=\"source\" height=\"48\" width=\"640\">file:/LiberationSerif-660e7a5a60fdeb133d3e8b24e2766f2e.png</image>\n"
"</screenshot>\n"
"<screenshot priority=\"-32\">\n"
"<caption>Liberation Serif – Bold</caption>\n"
- "<image type=\"source\" height=\"48\" width=\"640\"/>\n"
+ "<image type=\"source\" height=\"48\" width=\"640\">file:/LiberationSerif-660e7a5a60fdeb133d3e8b24e2766f2e.png</image>\n"
"</screenshot>\n"
"</screenshots>\n"
"<releases>\n"
diff --git a/libappstream-builder/plugins/asb-plugin-appdata.c b/libappstream-builder/plugins/asb-plugin-appdata.c
index 56d296f..cb2f253 100644
--- a/libappstream-builder/plugins/asb-plugin-appdata.c
+++ b/libappstream-builder/plugins/asb-plugin-appdata.c
@@ -176,80 +176,6 @@ asb_plugin_appdata_log_overwrite (AsbApp *app,
}
/**
- * asb_plugin_appdata_load_url:
- **/
-static gboolean
-asb_plugin_appdata_load_url (AsbPlugin *plugin,
- AsbApp *app,
- const gchar *url,
- GError **error)
-{
- const gchar *cache_dir;
- gboolean ret = TRUE;
- SoupStatus status;
- SoupURI *uri = NULL;
- _cleanup_free_ gchar *basename = NULL;
- _cleanup_free_ gchar *cache_filename = NULL;
- _cleanup_object_unref_ SoupMessage *msg = NULL;
-
- /* download to cache if not already added */
- basename = g_path_get_basename (url);
- cache_dir = asb_package_get_config (asb_app_get_package (app), "CacheDir");
- cache_filename = g_strdup_printf ("%s/%s-%s",
- cache_dir,
- as_app_get_id_filename (AS_APP (app)),
- basename);
- if (!g_file_test (cache_filename, G_FILE_TEST_EXISTS)) {
- if (asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_NO_NETWORK)) {
- asb_package_log (asb_app_get_package (app),
- ASB_PACKAGE_LOG_LEVEL_WARNING,
- "Could not download %s as no network", url);
- goto out;
- }
- uri = soup_uri_new (url);
- if (uri == NULL) {
- ret = FALSE;
- g_set_error (error,
- ASB_PLUGIN_ERROR,
- ASB_PLUGIN_ERROR_FAILED,
- "Could not parse '%s' as a URL", url);
- goto out;
- }
- asb_package_log (asb_app_get_package (app),
- ASB_PACKAGE_LOG_LEVEL_DEBUG,
- "Downloading %s", url);
- msg = soup_message_new_from_uri (SOUP_METHOD_GET, uri);
- status = soup_session_send_message (plugin->priv->session, msg);
- if (status != SOUP_STATUS_OK) {
- ret = FALSE;
- g_set_error (error,
- ASB_PLUGIN_ERROR,
- ASB_PLUGIN_ERROR_FAILED,
- "Downloading failed: %s",
- soup_status_get_phrase (status));
- goto out;
- }
-
- /* save new file */
- ret = g_file_set_contents (cache_filename,
- msg->response_body->data,
- msg->response_body->length,
- error);
- if (!ret)
- goto out;
- }
-
- /* load the pixbuf */
- ret = asb_app_add_screenshot_source (app, cache_filename, error);
- if (!ret)
- goto out;
-out:
- if (uri != NULL)
- soup_uri_free (uri);
- return ret;
-}
-
-/**
* asb_plugin_process_filename:
*/
static gboolean
@@ -415,44 +341,12 @@ asb_plugin_process_filename (AsbPlugin *plugin,
/* add screenshots if not already added */
array = as_app_get_screenshots (AS_APP (app));
if (array->len == 0) {
+ /* just use the upstream locations */
array = as_app_get_screenshots (appdata);
for (i = 0; i < array->len; i++) {
- GError *error_local = NULL;
- AsScreenshot *ass;
- AsImage *image;
-
- ass = g_ptr_array_index (array, i);
- image = as_screenshot_get_source (ass);
- if (image == NULL)
- continue;
-
- /* if no network just use the upstream location */
- if (asb_context_get_flag (plugin->ctx,
- ASB_CONTEXT_FLAG_NO_NETWORK)) {
- asb_package_log (asb_app_get_package (app),
- ASB_PACKAGE_LOG_LEVEL_DEBUG,
- "Using upstream screenshot");
- as_app_add_screenshot (AS_APP (app), ass);
- continue;
- }
-
- /* load the URI or get from a cache */
- tmp = as_image_get_url (image);
- ret = asb_plugin_appdata_load_url (plugin,
- app,
- as_image_get_url (image),
- &error_local);
- if (ret) {
- asb_package_log (asb_app_get_package (app),
- ASB_PACKAGE_LOG_LEVEL_DEBUG,
- "Added screenshot %s", tmp);
- } else {
- asb_package_log (asb_app_get_package (app),
- ASB_PACKAGE_LOG_LEVEL_WARNING,
- "Failed to load screenshot %s: %s",
- tmp, error_local->message);
- g_clear_error (&error_local);
- }
+ AsScreenshot *ss;
+ ss = g_ptr_array_index (array, i);
+ as_app_add_screenshot (AS_APP (app), ss);
}
} else {
array = as_app_get_screenshots (appdata);
diff --git a/libappstream-builder/plugins/asb-plugin-font.c b/libappstream-builder/plugins/asb-plugin-font.c
index 5699734..56af067 100644
--- a/libappstream-builder/plugins/asb-plugin-font.c
+++ b/libappstream-builder/plugins/asb-plugin-font.c
@@ -387,13 +387,14 @@ asb_font_get_caption (AsbApp *app)
* asb_font_add_screenshot:
*/
static gboolean
-asb_font_add_screenshot (AsbApp *app, FT_Face ft_face, GError **error)
+asb_font_add_screenshot (AsbPlugin *plugin, AsbApp *app, FT_Face ft_face, GError **error)
{
const gchar *cache_dir;
- const gchar *mirror_uri;
+ const gchar *temp_dir;
const gchar *tmp;
_cleanup_free_ gchar *basename = NULL;
_cleanup_free_ gchar *cache_fn = NULL;
+ _cleanup_free_ gchar *output_fn = NULL;
_cleanup_free_ gchar *caption = NULL;
_cleanup_free_ gchar *url_tmp = NULL;
_cleanup_object_unref_ AsImage *im = NULL;
@@ -405,8 +406,8 @@ asb_font_add_screenshot (AsbApp *app, FT_Face ft_face, GError **error)
return TRUE;
/* is in the cache */
- cache_dir = asb_package_get_config (asb_app_get_package (app), "CacheDir");
- cache_fn = g_strdup_printf ("%s/%s.png",
+ cache_dir = asb_context_get_cache_dir (plugin->ctx);
+ cache_fn = g_strdup_printf ("%s/screenshots/%s.png",
cache_dir,
as_app_get_id_filename (AS_APP (app)));
if (g_file_test (cache_fn, G_FILE_TEST_EXISTS)) {
@@ -428,8 +429,13 @@ asb_font_add_screenshot (AsbApp *app, FT_Face ft_face, GError **error)
return FALSE;
}
- mirror_uri = asb_package_get_config (asb_app_get_package (app),
- "MirrorURI");
+ /* save to the cache for next time */
+ if (!g_file_test (cache_fn, G_FILE_TEST_EXISTS)) {
+ if (!gdk_pixbuf_save (pixbuf, cache_fn, "png", error, NULL))
+ return FALSE;
+ }
+
+ /* copy it to the screenshot directory */
im = as_image_new ();
as_image_set_pixbuf (im, pixbuf);
as_image_set_kind (im, AS_IMAGE_KIND_SOURCE);
@@ -437,12 +443,17 @@ asb_font_add_screenshot (AsbApp *app, FT_Face ft_face, GError **error)
as_app_get_id_filename (AS_APP (app)),
as_image_get_md5 (im));
as_image_set_basename (im, basename);
- url_tmp = g_build_filename (mirror_uri,
- "source",
+ url_tmp = g_build_filename ("file://",
basename,
NULL);
as_image_set_url (im, url_tmp, -1);
+ /* put this in a special place so it gets packaged up */
+ temp_dir = asb_context_get_temp_dir (plugin->ctx);
+ output_fn = g_build_filename (temp_dir, "screenshots", basename, NULL);
+ if (!gdk_pixbuf_save (pixbuf, output_fn, "png", error, NULL))
+ return FALSE;
+
ss = as_screenshot_new ();
as_screenshot_set_kind (ss, AS_SCREENSHOT_KIND_DEFAULT);
as_screenshot_add_image (ss, im);
@@ -621,7 +632,7 @@ asb_plugin_font_app (AsbPlugin *plugin, AsbApp *app,
asb_font_add_languages (app, pattern);
asb_font_add_metadata (app, ft_face);
asb_font_fix_metadata (app);
- ret = asb_font_add_screenshot (app, ft_face, error);
+ ret = asb_font_add_screenshot (plugin, app, ft_face, error);
if (!ret)
goto out;