static void enum_files_cb (GObject *obj, GAsyncResult *result, gpointer data) { RBAndroidSource *source = RB_ANDROID_SOURCE (data); RBAndroidSourcePrivate *priv = GET_PRIVATE(source); GFileEnumerator *e = G_FILE_ENUMERATOR (obj); GError *error = NULL; GFileInfo *info; GList *files; GList *l; files = g_file_enumerator_next_files_finish (e, result, &error); if (error != NULL) { rb_debug ("error listing files: %s", error->message); music_dirs_done (source); return; } if (files == NULL) { priv->scanned++; g_object_unref (e); find_music_dirs (source); return; } for (l = files; l != NULL; l = l->next) { guint32 filetype; info = (GFileInfo *)l->data; filetype = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE); if (filetype == G_FILE_TYPE_DIRECTORY) { GFile *dir; if (priv->scanned == 0) { rb_debug ("got storage container %s", g_file_info_get_name (info)); dir = g_file_get_child (g_file_enumerator_get_container (e), g_file_info_get_name (info)); g_queue_push_tail (&priv->to_scan, dir); } else if (g_ascii_strcasecmp (g_file_info_get_name (info), "music") == 0) { GFile *storage; char *uri; storage = g_file_enumerator_get_container (e); dir = g_file_get_child (storage, g_file_info_get_name (info)); uri = g_file_get_uri (dir); rb_debug ("music dir found at %s", uri); /* keep the container around for space/capacity calculation */ priv->storage = g_list_append (priv->storage, dir); rhythmdb_import_job_add_uri (priv->import_job, uri); g_free (uri); } } g_object_unref (info); } g_list_free (files); g_file_enumerator_next_files_async (G_FILE_ENUMERATOR (obj), 64, G_PRIORITY_DEFAULT, priv->cancel, enum_files_cb, source); }
/** * as_icon_set_height: * @icon: a #AsIcon instance. * @height: the height in pixels. * * Sets the icon height. * * Since: 0.3.1 **/ void as_icon_set_height (AsIcon *icon, guint height) { AsIconPrivate *priv = GET_PRIVATE (icon); priv->height = height; }
/** * as_icon_node_parse: * @icon: a #AsIcon instance. * @node: a #GNode. * @ctx: a #AsNodeContext. * @error: A #GError or %NULL. * * Populates the object from a DOM node. * * Returns: %TRUE for success * * Since: 0.3.1 **/ gboolean as_icon_node_parse (AsIcon *icon, GNode *node, AsNodeContext *ctx, GError **error) { AsIconPrivate *priv = GET_PRIVATE (icon); const gchar *tmp; guint size; gboolean prepend_size = TRUE; tmp = as_node_get_attribute (node, "type"); as_icon_set_kind (icon, as_icon_kind_from_string (tmp)); switch (priv->kind) { case AS_ICON_KIND_EMBEDDED: if (!as_icon_node_parse_embedded (icon, node, error)) return FALSE; break; default: /* preserve the URL for remote icons */ tmp = as_node_get_data (node); if (tmp == NULL) { g_set_error (error, AS_ICON_ERROR, AS_ICON_ERROR_FAILED, "no data for icon of type %s", as_icon_kind_to_string (priv->kind)); return FALSE; } if (priv->kind == AS_ICON_KIND_REMOTE) as_icon_set_url (icon, tmp); else if (priv->kind == AS_ICON_KIND_LOCAL) as_icon_set_filename (icon, tmp); /* store the name without any prefix */ if (g_strstr_len (tmp, -1, "/") == NULL) { as_icon_set_name (icon, tmp); } else { g_autofree gchar *basename = NULL; basename = g_path_get_basename (tmp); as_icon_set_name (icon, basename); } /* width is optional, assume 64px if missing */ size = as_node_get_attribute_as_uint (node, "width"); if (size == G_MAXUINT) { size = 64; prepend_size = FALSE; } priv->width = size; /* height is optional, assume 64px if missing */ size = as_node_get_attribute_as_uint (node, "height"); if (size == G_MAXUINT) { size = 64; prepend_size = FALSE; } priv->height = size; /* only use the size if the metadata has width and height */ if (prepend_size) { g_free (priv->prefix_private); priv->prefix_private = g_strdup_printf ("%s/%ux%u", priv->prefix, priv->width, priv->height); } break; } return TRUE; }
/** * as_icon_get_kind: * @icon: a #AsIcon instance. * * Gets the icon kind. * * Returns: the #AsIconKind * * Since: 0.3.1 **/ AsIconKind as_icon_get_kind (AsIcon *icon) { AsIconPrivate *priv = GET_PRIVATE (icon); return priv->kind; }
/** * as_icon_get_data: * @icon: a #AsIcon instance. * * Gets the icon data if set. * * Returns: (transfer none): the #GBytes, or %NULL * * Since: 0.3.1 **/ GBytes * as_icon_get_data (AsIcon *icon) { AsIconPrivate *priv = GET_PRIVATE (icon); return priv->data; }
/** * as_icon_get_url: * @icon: a #AsIcon instance. * * Gets the full qualified URL for the icon, usually pointing at some mirror. * NOTE: This is only set for icons of type %AS_ICON_KIND_REMOTE * * Returns: the fully qualified URL * * Since: 0.3.2 **/ const gchar * as_icon_get_url (AsIcon *icon) { AsIconPrivate *priv = GET_PRIVATE (icon); return priv->url; }
/** * as_icon_get_width: * @icon: a #AsIcon instance. * * Gets the icon width. * * Returns: width in pixels * * Since: 0.3.1 **/ guint as_icon_get_width (AsIcon *icon) { AsIconPrivate *priv = GET_PRIVATE (icon); return priv->width; }
/** * as_require_get_kind: * @require: a #AsRequire instance. * * Gets the require kind. * * Returns: the #AsRequireKind * * Since: 0.6.7 **/ AsRequireKind as_require_get_kind (AsRequire *require) { AsRequirePrivate *priv = GET_PRIVATE (require); return priv->kind; }
/** * as_require_set_kind: * @require: a #AsRequire instance. * @kind: the #AsRequireKind, e.g. %AS_REQUIRE_KIND_ID. * * Sets the require kind. * * Since: 0.6.7 **/ void as_require_set_kind (AsRequire *require, AsRequireKind kind) { AsRequirePrivate *priv = GET_PRIVATE (require); priv->kind = kind; }
/** * as_require_get_version: * @require: a #AsRequire instance. * * Gets the require version if set. * * Returns: the version, e.g. "0.1.2" * * Since: 0.6.7 **/ const gchar * as_require_get_version (AsRequire *require) { AsRequirePrivate *priv = GET_PRIVATE (require); return priv->version; }
/** * as_require_get_value: * @require: a #AsRequire instance. * * Gets the require value if set. * * Returns: the value, e.g. "bootloader" * * Since: 0.6.7 **/ const gchar * as_require_get_value (AsRequire *require) { AsRequirePrivate *priv = GET_PRIVATE (require); return priv->value; }
static char * impl_build_dest_uri (RBTransferTarget *target, RhythmDBEntry *entry, const char *media_type, const char *extension) { RBAndroidSourcePrivate *priv = GET_PRIVATE (target); const char *in_artist; char *artist, *album, *title; gulong track_number, disc_number; char *number; char *file = NULL; char *storage_uri; char *uri; char *ext; GFile *storage = NULL; if (extension != NULL) { ext = g_strconcat (".", extension, NULL); } else { ext = g_strdup (""); } in_artist = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM_ARTIST); if (in_artist[0] == '\0') { in_artist = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST); } artist = sanitize_path (in_artist); album = sanitize_path (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM)); title = sanitize_path (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE)); /* we really do need to fix this so untagged entries actually have NULL rather than * a translated string. */ if (strcmp (artist, _("Unknown")) == 0 && strcmp (album, _("Unknown")) == 0 && g_str_has_suffix (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION), title)) { /* file isn't tagged, so just use the filename as-is, replacing the extension */ char *p; p = g_utf8_strrchr (title, -1, '.'); if (p != NULL) { *p = '\0'; } file = g_strdup_printf ("%s%s", title, ext); } if (file == NULL) { track_number = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_TRACK_NUMBER); disc_number = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DISC_NUMBER); if (disc_number > 0) number = g_strdup_printf ("%.02u.%.02u", (guint)disc_number, (guint)track_number); else number = g_strdup_printf ("%.02u", (guint)track_number); /* artist/album/number - title */ file = g_strdup_printf (G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s%%20-%%20%s%s", artist, album, number, title, ext); g_free (number); } g_free (artist); g_free (album); g_free (title); g_free (ext); /* pick storage container to use somehow for (l = priv->storage; l != NULL; l = l->next) { } */ if (priv->storage) storage = priv->storage->data; if (storage == NULL) { rb_debug ("couldn't find a container to store anything in"); g_free (file); return NULL; } storage_uri = g_file_get_uri (storage); uri = g_strconcat (storage_uri, file, NULL); g_free (file); g_free (storage_uri); return uri; }
static guint64 impl_get_free_space (RBMediaPlayerSource *source) { RBAndroidSourcePrivate *priv = GET_PRIVATE(source); return priv->storage_free_space; }
static guint64 impl_get_capacity (RBMediaPlayerSource *source) { RBAndroidSourcePrivate *priv = GET_PRIVATE(source); return priv->storage_capacity; }
static void fwupd_remote_set_report_uri (FwupdRemote *self, const gchar *report_uri) { FwupdRemotePrivate *priv = GET_PRIVATE (self); priv->report_uri = g_strdup (report_uri); }
/** * as_require_get_compare: * @require: a #AsRequire instance. * * Gets the require version comparison type. * * Returns: the #AsRequireKind * * Since: 0.6.7 **/ AsRequireCompare as_require_get_compare (AsRequire *require) { AsRequirePrivate *priv = GET_PRIVATE (require); return priv->compare; }
/** * fwupd_remote_load_from_filename: * @self: A #FwupdRemote * @filename: A filename * @cancellable: the #GCancellable, or %NULL * @error: the #GError, or %NULL * * Sets up the remote ready for use. Most other methods call this * for you, and do you only need to call this if you are just watching * the self. * * Returns: %TRUE for success * * Since: 0.9.3 **/ gboolean fwupd_remote_load_from_filename (FwupdRemote *self, const gchar *filename, GCancellable *cancellable, GError **error) { FwupdRemotePrivate *priv = GET_PRIVATE (self); const gchar *group = "fwupd Remote"; g_autofree gchar *firmware_base_uri = NULL; g_autofree gchar *id = NULL; g_autofree gchar *keyring_kind = NULL; g_autofree gchar *metadata_uri = NULL; g_autofree gchar *order_after = NULL; g_autofree gchar *order_before = NULL; g_autofree gchar *report_uri = NULL; g_autoptr(GKeyFile) kf = NULL; g_return_val_if_fail (FWUPD_IS_REMOTE (self), FALSE); g_return_val_if_fail (filename != NULL, FALSE); g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); /* set ID */ id = g_path_get_basename (filename); fwupd_remote_set_id (self, id); /* load file */ kf = g_key_file_new (); if (!g_key_file_load_from_file (kf, filename, G_KEY_FILE_NONE, error)) return FALSE; /* get verification type, falling back to GPG */ keyring_kind = g_key_file_get_string (kf, group, "Keyring", NULL); if (keyring_kind == NULL) { priv->keyring_kind = FWUPD_KEYRING_KIND_GPG; } else { priv->keyring_kind = fwupd_keyring_kind_from_string (keyring_kind); if (priv->keyring_kind == FWUPD_KEYRING_KIND_UNKNOWN) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INVALID_FILE, "Failed to parse type '%s'", keyring_kind); return FALSE; } } /* all remotes need a URI, even if it's file:// to the cache */ metadata_uri = g_key_file_get_string (kf, group, "MetadataURI", error); if (metadata_uri == NULL) return FALSE; if (g_str_has_prefix (metadata_uri, "file://")) { const gchar *filename_cache = metadata_uri; if (g_str_has_prefix (filename_cache, "file://")) filename_cache += 7; fwupd_remote_set_filename_cache (self, filename_cache); if (g_file_test (filename_cache, G_FILE_TEST_IS_DIR)) priv->kind = FWUPD_REMOTE_KIND_DIRECTORY; else priv->kind = FWUPD_REMOTE_KIND_LOCAL; } else if (g_str_has_prefix (metadata_uri, "http://") || g_str_has_prefix (metadata_uri, "https://")) { priv->kind = FWUPD_REMOTE_KIND_DOWNLOAD; } else { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INVALID_FILE, "Failed to parse MetadataURI type '%s'", metadata_uri); return FALSE; } /* extract data */ priv->enabled = g_key_file_get_boolean (kf, group, "Enabled", NULL); priv->approval_required = g_key_file_get_boolean (kf, group, "ApprovalRequired", NULL); priv->title = g_key_file_get_string (kf, group, "Title", NULL); /* reporting is optional */ report_uri = g_key_file_get_string (kf, group, "ReportURI", NULL); if (report_uri != NULL && report_uri[0] != '\0') fwupd_remote_set_report_uri (self, report_uri); /* DOWNLOAD-type remotes */ if (priv->kind == FWUPD_REMOTE_KIND_DOWNLOAD) { g_autofree gchar *filename_cache = NULL; g_autofree gchar *username = NULL; g_autofree gchar *password = NULL; /* the client has to download this and the signature */ fwupd_remote_set_metadata_uri (self, metadata_uri); /* check the URI was valid */ if (priv->metadata_uri == NULL) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INVALID_FILE, "Failed to parse URI '%s' in %s", metadata_uri, filename); return FALSE; } /* username and password are optional */ username = g_key_file_get_string (kf, group, "Username", NULL); if (username != NULL) fwupd_remote_set_username (self, username); password = g_key_file_get_string (kf, group, "Password", NULL); if (password != NULL) fwupd_remote_set_password (self, password); /* set cache to /var/lib... */ filename_cache = g_build_filename (LOCALSTATEDIR, "lib", "fwupd", "remotes.d", priv->id, "metadata.xml.gz", NULL); fwupd_remote_set_filename_cache (self, filename_cache); } /* load the checksum */ if (priv->filename_cache_sig != NULL && g_file_test (priv->filename_cache_sig, G_FILE_TEST_EXISTS)) { gsize sz = 0; g_autofree gchar *buf = NULL; g_autoptr(GChecksum) checksum = g_checksum_new (G_CHECKSUM_SHA256); if (!g_file_get_contents (priv->filename_cache_sig, &buf, &sz, error)) { g_prefix_error (error, "failed to get checksum: "); return FALSE; } g_checksum_update (checksum, (guchar *) buf, (gssize) sz); fwupd_remote_set_checksum (self, g_checksum_get_string (checksum)); } else { fwupd_remote_set_checksum (self, NULL); } /* the base URI is optional */ firmware_base_uri = g_key_file_get_string (kf, group, "FirmwareBaseURI", NULL); if (firmware_base_uri != NULL) fwupd_remote_set_firmware_base_uri (self, firmware_base_uri); /* some validation around DIRECTORY types */ if (priv->kind == FWUPD_REMOTE_KIND_DIRECTORY) { if (priv->keyring_kind != FWUPD_KEYRING_KIND_NONE) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INVALID_FILE, "Keyring kind %s is not supported with directory remote", fwupd_keyring_kind_to_string (priv->keyring_kind)); return FALSE; } if (firmware_base_uri != NULL) { g_set_error_literal (error, FWUPD_ERROR, FWUPD_ERROR_INVALID_FILE, "Directory remotes don't support firmware base URI"); return FALSE; } } /* dep logic */ order_before = g_key_file_get_string (kf, group, "OrderBefore", NULL); if (order_before != NULL) priv->order_before = g_strsplit_set (order_before, ",:;", -1); order_after = g_key_file_get_string (kf, group, "OrderAfter", NULL); if (order_after != NULL) priv->order_after = g_strsplit_set (order_after, ",:;", -1); /* success */ fwupd_remote_set_filename_source (self, filename); return TRUE; }
/** * as_require_set_compare: * @require: a #AsRequire instance. * @compare: the #AsRequireKind, e.g. %AS_REQUIRE_KIND_ID. * * Sets the require version comparison type. * * Since: 0.6.7 **/ void as_require_set_compare (AsRequire *require, AsRequireCompare compare) { AsRequirePrivate *priv = GET_PRIVATE (require); priv->compare = compare; }
/** * as_icon_get_filename: * @icon: a #AsIcon instance. * * Gets the absolute path on disk of the icon. * NOTE: This is only set for icons of type %AS_ICON_KIND_LOCAL * * Returns: the absolute filename on disk * * Since: 0.3.2 **/ const gchar * as_icon_get_filename (AsIcon *icon) { AsIconPrivate *priv = GET_PRIVATE (icon); return priv->filename; }
/** * as_require_version_compare: * @require: a #AsRequire instance. * @version: a version number, e.g. `0.1.3` * @error: A #GError or %NULL * * Compares the version number of the requirement with a predicate. * * Returns: %TRUE if the predicate was true * * Since: 0.6.7 **/ gboolean as_require_version_compare (AsRequire *require, const gchar *version, GError **error) { AsRequirePrivate *priv = GET_PRIVATE (require); gboolean ret = FALSE; gint rc = 0; switch (priv->compare) { case AS_REQUIRE_COMPARE_EQ: rc = as_utils_vercmp (version, priv->version); ret = rc == 0; break; case AS_REQUIRE_COMPARE_NE: rc = as_utils_vercmp (version, priv->version); ret = rc != 0; break; case AS_REQUIRE_COMPARE_LT: rc = as_utils_vercmp (version, priv->version); ret = rc < 0; break; case AS_REQUIRE_COMPARE_GT: rc = as_utils_vercmp (version, priv->version); ret = rc > 0; break; case AS_REQUIRE_COMPARE_LE: rc = as_utils_vercmp (version, priv->version); ret = rc <= 0; break; case AS_REQUIRE_COMPARE_GE: rc = as_utils_vercmp (version, priv->version); ret = rc >= 0; break; case AS_REQUIRE_COMPARE_GLOB: ret = fnmatch (priv->version, version, 0) == 0; break; case AS_REQUIRE_COMPARE_REGEX: ret = g_regex_match_simple (priv->version, version, 0, 0); break; default: break; } /* could not compare */ if (rc == G_MAXINT) { g_set_error (error, AS_UTILS_ERROR, AS_UTILS_ERROR_FAILED, "failed to compare [%s] and [%s]", priv->version, version); return FALSE; } /* set error */ if (!ret && error != NULL) { g_set_error (error, AS_UTILS_ERROR, AS_UTILS_ERROR_FAILED, "failed predicate [%s %s %s]", priv->version, as_require_compare_to_string (priv->compare), version); } return ret; }
/** * as_icon_get_height: * @icon: a #AsIcon instance. * * Gets the icon height. * * Returns: height in pixels * * Since: 0.3.1 **/ guint as_icon_get_height (AsIcon *icon) { AsIconPrivate *priv = GET_PRIVATE (icon); return priv->height; }
/** * fwupd_remote_to_variant: * @self: A #FwupdRemote * * Creates a GVariant from the remote data. * * Returns: the GVariant, or %NULL for error * * Since: 1.0.0 **/ GVariant * fwupd_remote_to_variant (FwupdRemote *self) { FwupdRemotePrivate *priv = GET_PRIVATE (self); GVariantBuilder builder; g_return_val_if_fail (FWUPD_IS_REMOTE (self), NULL); /* create an array with all the metadata in */ g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); if (priv->id != NULL) { g_variant_builder_add (&builder, "{sv}", FWUPD_RESULT_KEY_REMOTE_ID, g_variant_new_string (priv->id)); } if (priv->username != NULL) { g_variant_builder_add (&builder, "{sv}", "Username", g_variant_new_string (priv->username)); } if (priv->password != NULL) { g_variant_builder_add (&builder, "{sv}", "Password", g_variant_new_string (priv->password)); } if (priv->title != NULL) { g_variant_builder_add (&builder, "{sv}", "Title", g_variant_new_string (priv->title)); } if (priv->agreement != NULL) { g_variant_builder_add (&builder, "{sv}", "Agreement", g_variant_new_string (priv->agreement)); } if (priv->checksum != NULL) { g_variant_builder_add (&builder, "{sv}", FWUPD_RESULT_KEY_CHECKSUM, g_variant_new_string (priv->checksum)); } if (priv->metadata_uri != NULL) { g_variant_builder_add (&builder, "{sv}", FWUPD_RESULT_KEY_URI, g_variant_new_string (priv->metadata_uri)); } if (priv->report_uri != NULL) { g_variant_builder_add (&builder, "{sv}", "ReportUri", g_variant_new_string (priv->report_uri)); } if (priv->firmware_base_uri != NULL) { g_variant_builder_add (&builder, "{sv}", "FirmwareBaseUri", g_variant_new_string (priv->firmware_base_uri)); } if (priv->priority != 0) { g_variant_builder_add (&builder, "{sv}", "Priority", g_variant_new_int32 (priv->priority)); } if (priv->kind != FWUPD_REMOTE_KIND_UNKNOWN) { g_variant_builder_add (&builder, "{sv}", "Type", g_variant_new_uint32 (priv->kind)); } if (priv->keyring_kind != FWUPD_KEYRING_KIND_UNKNOWN) { g_variant_builder_add (&builder, "{sv}", "Keyring", g_variant_new_uint32 (priv->keyring_kind)); } if (priv->mtime != 0) { g_variant_builder_add (&builder, "{sv}", "ModificationTime", g_variant_new_uint64 (priv->mtime)); } if (priv->filename_cache != NULL) { g_variant_builder_add (&builder, "{sv}", "FilenameCache", g_variant_new_string (priv->filename_cache)); } if (priv->filename_source != NULL) { g_variant_builder_add (&builder, "{sv}", "FilenameSource", g_variant_new_string (priv->filename_source)); } g_variant_builder_add (&builder, "{sv}", "Enabled", g_variant_new_boolean (priv->enabled)); g_variant_builder_add (&builder, "{sv}", "ApprovalRequired", g_variant_new_boolean (priv->approval_required)); return g_variant_new ("a{sv}", &builder); }
/** * as_icon_get_pixbuf: * @icon: a #AsIcon instance. * * Gets the icon pixbuf if set. * * Returns: (transfer none): the #GdkPixbuf, or %NULL * * Since: 0.3.1 **/ GdkPixbuf * as_icon_get_pixbuf (AsIcon *icon) { AsIconPrivate *priv = GET_PRIVATE (icon); return priv->pixbuf; }
static void fwupd_remote_set_keyring_kind (FwupdRemote *self, FwupdKeyringKind keyring_kind) { FwupdRemotePrivate *priv = GET_PRIVATE (self); priv->keyring_kind = keyring_kind; }
/** * as_icon_set_width: * @icon: a #AsIcon instance. * @width: the width in pixels. * * Sets the icon width. * * Since: 0.3.1 **/ void as_icon_set_width (AsIcon *icon, guint width) { AsIconPrivate *priv = GET_PRIVATE (icon); priv->width = width; }
static SoupURI * fwupd_remote_build_uri (FwupdRemote *self, const gchar *url, GError **error) { FwupdRemotePrivate *priv = GET_PRIVATE (self); SoupURI *uri; g_return_val_if_fail (FWUPD_IS_REMOTE (self), NULL); g_return_val_if_fail (url != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); /* create URI, substituting if required */ if (priv->firmware_base_uri != NULL) { g_autoptr(SoupURI) uri_tmp = NULL; g_autofree gchar *basename = NULL; g_autofree gchar *url2 = NULL; uri_tmp = soup_uri_new (url); if (uri_tmp == NULL) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INVALID_FILE, "Failed to parse URI '%s'", url); return NULL; } basename = g_path_get_basename (soup_uri_get_path (uri_tmp)); url2 = g_build_filename (priv->firmware_base_uri, basename, NULL); uri = soup_uri_new (url2); if (uri == NULL) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INVALID_FILE, "Failed to parse URI '%s'", url2); return NULL; } /* use the base URI of the metadata to build the full path */ } else if (g_strstr_len (url, -1, "/") == NULL) { g_autofree gchar *basename = NULL; g_autofree gchar *path = NULL; uri = soup_uri_new (priv->metadata_uri); if (uri == NULL) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INVALID_FILE, "Failed to parse metadata URI '%s'", url); return NULL; } basename = g_path_get_dirname (soup_uri_get_path (uri)); path = g_build_filename (basename, url, NULL); soup_uri_set_path (uri, path); /* a normal URI */ } else { uri = soup_uri_new (url); if (uri == NULL) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_INVALID_FILE, "Failed to parse URI '%s'", url); return NULL; } } /* set the username and password */ if (priv->username != NULL) soup_uri_set_user (uri, priv->username); if (priv->password != NULL) soup_uri_set_password (uri, priv->password); return uri; }
/** * as_icon_set_kind: * @icon: a #AsIcon instance. * @kind: the #AsIconKind, e.g. %AS_ICON_KIND_STOCK. * * Sets the icon kind. * * Since: 0.3.1 **/ void as_icon_set_kind (AsIcon *icon, AsIconKind kind) { AsIconPrivate *priv = GET_PRIVATE (icon); priv->kind = kind; }
/* note, this has to be set after MetadataURI */ static void fwupd_remote_set_firmware_base_uri (FwupdRemote *self, const gchar *firmware_base_uri) { FwupdRemotePrivate *priv = GET_PRIVATE (self); priv->firmware_base_uri = g_strdup (firmware_base_uri); }
/** * as_icon_load: * @icon: a #AsIcon instance. * @flags: a #AsIconLoadFlags, e.g. %AS_ICON_LOAD_FLAG_SEARCH_SIZE * @error: A #GError or %NULL. * * Loads the icon into a local pixbuf. * * Returns: %TRUE for success * * Since: 0.3.1 **/ gboolean as_icon_load (AsIcon *icon, AsIconLoadFlags flags, GError **error) { AsIconPrivate *priv = GET_PRIVATE (icon); g_autofree gchar *fn_fallback = NULL; g_autoptr(GdkPixbuf) pixbuf = NULL; /* absolute filename */ if (priv->kind == AS_ICON_KIND_LOCAL) { if (priv->filename == NULL) { g_set_error (error, AS_ICON_ERROR, AS_ICON_ERROR_FAILED, "unable to load '%s' as no filename set", priv->name); return FALSE; } pixbuf = gdk_pixbuf_new_from_file_at_size (priv->filename, (gint) priv->width, (gint) priv->height, error); if (pixbuf == NULL) return FALSE; as_icon_set_pixbuf (icon, pixbuf); return TRUE; } /* not set */ if (priv->prefix == NULL) { g_set_error (error, AS_ICON_ERROR, AS_ICON_ERROR_FAILED, "unable to load '%s' as no prefix set", priv->name); return FALSE; } /* try getting a pixbuf of the right size */ if (flags & AS_ICON_LOAD_FLAG_SEARCH_SIZE) { guint widths[] = { priv->width, 64, 128, 0 }; guint height[] = { priv->height, 64, 128, 0 }; guint i; for (i = 0; widths[i] != 0; i++) { g_autofree gchar *fn_size = NULL; g_autofree gchar *size_str = NULL; size_str = g_strdup_printf ("%ux%u", widths[i], height[i]); fn_size = g_build_filename (priv->prefix, size_str, priv->name, NULL); if (g_file_test (fn_size, G_FILE_TEST_EXISTS)) { pixbuf = gdk_pixbuf_new_from_file (fn_size, error); if (pixbuf == NULL) return FALSE; as_icon_set_pixbuf (icon, pixbuf); return TRUE; } } } /* fall back to the old location */ fn_fallback = g_build_filename (priv->prefix, priv->name, NULL); pixbuf = gdk_pixbuf_new_from_file (fn_fallback, error); if (pixbuf == NULL) return FALSE; as_icon_set_pixbuf (icon, pixbuf); return TRUE; }
static void asb_task_init (AsbTask *task) { AsbTaskPrivate *priv = GET_PRIVATE (task); priv->plugins_to_run = g_ptr_array_new (); }