/** * pk_package_equal_id: * @package1: a valid #PkPackage instance * @package2: a valid #PkPackage instance * * Do the #PkPackage's have the same ID. * * Return value: %TRUE if the packages have the same package_id. * * Since: 0.5.4 **/ gboolean pk_package_equal_id (PkPackage *package1, PkPackage *package2) { g_return_val_if_fail (PK_IS_PACKAGE (package1), FALSE); g_return_val_if_fail (PK_IS_PACKAGE (package2), FALSE); return (g_strcmp0 (package1->priv->package_id, package2->priv->package_id) == 0); }
/** * pk_package_equal: * @package1: a valid #PkPackage instance * @package2: a valid #PkPackage instance * * Do the #PkPackage's have the same ID. * * Return value: %TRUE if the packages have the same package_id, info and summary. * * Since: 0.5.4 **/ gboolean pk_package_equal (PkPackage *package1, PkPackage *package2) { g_return_val_if_fail (PK_IS_PACKAGE (package1), FALSE); g_return_val_if_fail (PK_IS_PACKAGE (package2), FALSE); return (g_strcmp0 (package1->priv->summary, package2->priv->summary) == 0 && g_strcmp0 (package1->priv->package_id, package2->priv->package_id) == 0 && package1->priv->info == package2->priv->info); }
/** * pk_package_set_summary: * @package: a valid #PkPackage instance * @summary: the package summary * * Sets the package summary. * * Since: 0.8.14 **/ void pk_package_set_summary (PkPackage *package, const gchar *summary) { g_return_if_fail (PK_IS_PACKAGE (package)); g_free (package->priv->summary); package->priv->summary = g_strdup (summary); }
/** * pk_package_sack_remove_package: * @sack: a valid #PkPackageSack instance * @package: a valid #PkPackage instance * * Removes a package reference from the sack. The pointers have to match exactly. * * Return value: %TRUE if the package was removed from the sack * * Since: 0.5.2 **/ gboolean pk_package_sack_remove_package (PkPackageSack *sack, PkPackage *package) { g_return_val_if_fail (PK_IS_PACKAGE_SACK (sack), FALSE); g_return_val_if_fail (PK_IS_PACKAGE (package), FALSE); /* remove from array */ g_hash_table_remove (sack->priv->table, pk_package_get_id (package)); return g_ptr_array_remove (sack->priv->array, package); }
/** * pk_package_sack_add_package: * @sack: a valid #PkPackageSack instance * @package: a valid #PkPackage instance * * Adds a package to the sack. * * Return value: %TRUE if the package was added to the sack * * Since: 0.5.2 **/ gboolean pk_package_sack_add_package (PkPackageSack *sack, PkPackage *package) { g_return_val_if_fail (PK_IS_PACKAGE_SACK (sack), FALSE); g_return_val_if_fail (PK_IS_PACKAGE (package), FALSE); /* add to array */ g_ptr_array_add (sack->priv->array, g_object_ref (package)); return TRUE; }
/** * pk_package_print: * @package: a valid #PkPackage instance * * Prints details about the package to standard out. * * Since: 0.5.4 **/ void pk_package_print (PkPackage *package) { PkPackagePrivate *priv = package->priv; g_return_if_fail (PK_IS_PACKAGE (package)); g_print ("%s-%s.%s\t%s\t%s\n", priv->package_id_split[PK_PACKAGE_ID_NAME], priv->package_id_split[PK_PACKAGE_ID_VERSION], priv->package_id_split[PK_PACKAGE_ID_ARCH], priv->package_id_split[PK_PACKAGE_ID_DATA], package->priv->summary); }
/** * pk_package_sack_remove_package: * @sack: a valid #PkPackageSack instance * @package: a valid #PkPackage instance * * Removes a package reference from the sack. The pointers have to match exactly. * * Return value: %TRUE if the package was removed from the sack * * Since: 0.5.2 **/ gboolean pk_package_sack_remove_package (PkPackageSack *sack, PkPackage *package) { gboolean ret; g_return_val_if_fail (PK_IS_PACKAGE_SACK (sack), FALSE); g_return_val_if_fail (PK_IS_PACKAGE (package), FALSE); /* remove from array */ ret = g_ptr_array_remove (sack->priv->array, package); return ret; }
/** * pk_package_sack_add_package: * @sack: a valid #PkPackageSack instance * @package: a valid #PkPackage instance * * Adds a package to the sack. * * Return value: %TRUE if the package was added to the sack * * Since: 0.5.2 **/ gboolean pk_package_sack_add_package (PkPackageSack *sack, PkPackage *package) { g_return_val_if_fail (PK_IS_PACKAGE_SACK (sack), FALSE); g_return_val_if_fail (PK_IS_PACKAGE (package), FALSE); /* add to array */ g_ptr_array_add (sack->priv->array, g_object_ref (package)); g_hash_table_insert (sack->priv->table, g_strdup (pk_package_get_id (package)), g_object_ref (package)); return TRUE; }
/** * pk_package_set_id: * @package: a valid #PkPackage instance * @package_id: the valid package_id * @error: a %GError to put the error code and message in, or %NULL * * Sets the package object to have the given ID * * Return value: %TRUE if the package_id was set * * Since: 0.5.4 **/ gboolean pk_package_set_id (PkPackage *package, const gchar *package_id, GError **error) { PkPackagePrivate *priv = package->priv; gboolean ret; guint cnt = 0; guint i; g_return_val_if_fail (PK_IS_PACKAGE (package), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); /* free old data */ g_free (priv->package_id); g_free (priv->package_id_data); /* copy the package-id into package_id_data, change the ';' into '\0' * and reference the pointers in the const gchar * array */ priv->package_id = g_strdup (package_id); priv->package_id_data = g_strdup (package_id); priv->package_id_split[0] = priv->package_id_data; for (i = 0; priv->package_id_data[i] != '\0'; i++) { if (package_id[i] == ';') { if (++cnt > 3) continue; priv->package_id_split[cnt] = &priv->package_id_data[i+1]; priv->package_id_data[i] = '\0'; } } if (cnt != 3) { ret = FALSE; g_set_error (error, 1, 0, "invalid number of sections %i", cnt); goto out; } /* name has to be valid */ ret = (priv->package_id_split[0][0] != '\0'); if (!ret) { g_set_error_literal (error, 1, 0, "name invalid"); goto out; } out: return ret; }
/** * pk_package_parse: * @package: a valid #PkPackage instance * @data: the data describing the package * @error: a %GError to put the error code and message in, or %NULL * * Parses the data to populate the #PkPackage. * * Return value: %TRUE if the data was parsed correcty * * Since: 0.8.11 **/ gboolean pk_package_parse (PkPackage *package, const gchar *data, GError **error) { _cleanup_strv_free_ gchar **sections = NULL; g_return_val_if_fail (PK_IS_PACKAGE (package), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); /* split */ sections = g_strsplit (data, "\t", -1); if (g_strv_length (sections) != 3) { g_set_error_literal (error, 1, 0, "data invalid"); return FALSE; } /* parse object */ package->priv->info = pk_info_enum_from_string (sections[0]); if (!pk_package_set_id (package, sections[1], error)) return FALSE; g_free (package->priv->summary); package->priv->summary = g_strdup (sections[2]); return TRUE; }
/** * pk_package_get_data: * @package: a valid #PkPackage instance * * Gets the package data, which is usually the repository ID that contains the * package. Special ID's include "installed" for installed packages, and "local" * for local packages that exist on disk but not in a repoitory. * * Return value: the data, or %NULL if unset * * Since: 0.6.4 **/ const gchar * pk_package_get_data (PkPackage *package) { g_return_val_if_fail (PK_IS_PACKAGE (package), NULL); return package->priv->package_id_split[PK_PACKAGE_ID_DATA]; }
/** * pk_package_get_version: * @package: a valid #PkPackage instance * * Gets the package version. * * Return value: the version, or %NULL if unset * * Since: 0.6.4 **/ const gchar * pk_package_get_version (PkPackage *package) { g_return_val_if_fail (PK_IS_PACKAGE (package), NULL); return package->priv->package_id_split[PK_PACKAGE_ID_VERSION]; }
/** * pk_package_get_summary: * @package: a valid #PkPackage instance * * Gets the package object ID * * Return value: the summary, or %NULL if unset * * Since: 0.5.4 **/ const gchar * pk_package_get_summary (PkPackage *package) { g_return_val_if_fail (PK_IS_PACKAGE (package), NULL); return package->priv->summary; }
/** * pk_package_set_info: * @package: a valid #PkPackage instance * @info: the %PkInfoEnum * * Sets the package info enum. * * Since: 0.8.14 **/ void pk_package_set_info (PkPackage *package, PkInfoEnum info) { g_return_if_fail (PK_IS_PACKAGE (package)); package->priv->info = info; }
/** * pk_package_get_info: * @package: a valid #PkPackage instance * * Gets the package object ID * * Return value: the %PkInfoEnum * * Since: 0.5.4 **/ PkInfoEnum pk_package_get_info (PkPackage *package) { g_return_val_if_fail (PK_IS_PACKAGE (package), FALSE); return package->priv->info; }