![]() |
![]() |
![]() |
PackageKit Reference Manual | ![]() |
---|---|---|---|---|
#define PK_DBUS_SERVICE #define PK_DBUS_PATH #define PK_DBUS_PATH_NOTIFY #define PK_DBUS_INTERFACE #define PK_DBUS_INTERFACE_NOTIFY #define PK_DBUS_INTERFACE_TRANSACTION guint pk_strlen (gchar *text, guint max_length); gboolean pk_strzero (const gchar *text); gboolean pk_strvalidate (const gchar *text); gboolean pk_strequal (const gchar *id1, const gchar *id2); gboolean pk_strnumber (const gchar *text); gboolean pk_strtoint (const gchar *text, gint *value); gboolean pk_strtouint (const gchar *text, guint *value); gchar* pk_strpad (const gchar *data, guint length); gchar* pk_strpad_extra (const gchar *data, guint length, guint *extra); gchar* pk_strsafe (const gchar *text); gchar** pk_strsplit (const gchar *id, guint parts); gchar* pk_strbuild_va (const gchar *first_element, va_list *args); gchar** pk_ptr_array_to_argv (GPtrArray *array); gchar** pk_va_list_to_argv (const gchar *string_first, va_list *args); gboolean pk_strcmp_sections (const gchar *id1, const gchar *id2, guint parts, guint compare); gchar* pk_iso8601_present (void); guint pk_iso8601_difference (const gchar *isodate); gboolean pk_delay_yield (gfloat delay); gchar* pk_get_distro_id (void);
#define PK_DBUS_PATH_NOTIFY "/org/freedesktop/PackageKit/Notify"
The DBUS path for the notifications (why can't we use PK_DBUS_PATH?)
#define PK_DBUS_INTERFACE_NOTIFY "org.freedesktop.PackageKit.Notify"
The DBUS interface for the notifications
#define PK_DBUS_INTERFACE_TRANSACTION "org.freedesktop.PackageKit.Transaction"
The DBUS interface for the transactions
guint pk_strlen (gchar *text, guint max_length);
This function is a much safer way of doing strlen as it checks for NULL and a stupidly long string. This also modifies the string in place if it is over-range by inserting a NULL at the max_length.
|
The text to check |
|
The maximum length of the string |
Returns : |
the length of the string, or max_length. |
gboolean pk_strzero (const gchar *text);
This function is a much safer way of doing "if (strlen (text) == 0))" as it does not rely on text being NULL terminated. It's also much quicker as it only checks the first byte rather than scanning the whole string just to verify it's not zero length.
|
The text to check |
Returns : |
TRUE if the string was converted correctly
|
gboolean pk_strvalidate (const gchar *text);
Tests a string to see if it may be dangerous or invalid.
|
The text to check for validity |
Returns : |
TRUE if the string is valid
|
gboolean pk_strequal (const gchar *id1, const gchar *id2);
This function is a much safer way of doing strcmp as it checks for NULL first, and returns boolean TRUE, not zero for success.
gboolean pk_strnumber (const gchar *text);
Tests a string to see if it is a number. Both positive and negative numbers are allowed.
|
The text the validate |
Returns : |
TRUE if the string represents a numeric value
|
gboolean pk_strtoint (const gchar *text, gint *value);
Converts a string into a signed integer value in a safe way.
|
The text the convert |
|
The return numeric return value, or 0 if invalid. |
Returns : |
TRUE if the string was converted correctly
|
gboolean pk_strtouint (const gchar *text, guint *value);
Converts a string into a unsigned integer value in a safe way.
|
The text the convert |
|
The return numeric return value, or 0 if invalid. |
Returns : |
TRUE if the string was converted correctly
|
gchar* pk_strpad (const gchar *data, guint length);
Returns the text padded to a length with spaces. If the string is longer than length then a longer string is returned.
|
the input string |
|
the desired length of the output string, with padding |
Returns : |
The padded string |
gchar* pk_strpad_extra (const gchar *data, guint length, guint *extra);
This function pads a string, but allows a follow-on value. This is useful if the function is being used to print columns of text, and one oversize one has to be absorbed into the next where possible.
|
the input string |
|
the desired length of the output string, with padding |
|
if we are running with a deficit, we might have a positive offset |
Returns : |
The padded string |
gchar* pk_strsafe (const gchar *text);
Replaces chars in the text that may be dangerous, or that may print incorrectly. These chars include new lines, tabs and quotes, and are replaced by spaces.
|
The input text to make safe |
Returns : |
the new string with no insane chars |
gchar** pk_strsplit (const gchar *id, guint parts);
Splits a string into the correct number of parts, checking the correct number of delimiters are present.
|
the ; delimited string to split |
|
how many parts the delimted string should be split into |
Returns : |
a char array is split correctly, NULL if invalid
Note: You need to use g_strfreev on the returned value
|
gchar* pk_strbuild_va (const gchar *first_element, va_list *args);
This function converts a va_list into a string in a safe and efficient way, e.g. pk_strbuild_va("foo","bar","baz") == "foo bar baz"
|
The first string item, or NULL |
|
the va_list |
Returns : |
the single string |
gchar** pk_ptr_array_to_argv (GPtrArray *array);
Form a composite string array of strings. The data in the GPtrArray is copied.
|
the GPtrArray of strings |
Returns : |
the string array, or NULL if invalid
|
gchar** pk_va_list_to_argv (const gchar *string_first, va_list *args);
Form a composite string array of string, with a special twist; if the entry contains a '|', then it is split as seporate parts of the array.
|
the first string |
|
any subsequant string's |
Returns : |
the string array, or NULL if invalid
|
gboolean pk_strcmp_sections (const gchar *id1, const gchar *id2, guint parts, guint compare);
We only want to compare some first sections, not all the data when comparing package_id's and transaction_id's.
|
the first item of text to test |
|
the second item of text to test |
|
the number of parts each id should have |
|
the leading number of parts to compare |
Returns : |
TRUE if the strings can be considered the same.
|
guint pk_iso8601_difference (const gchar *isodate);
|
The ISO8601 date to compare |
Returns : |
The difference in seconds between the iso8601 date and current |
gboolean pk_delay_yield (gfloat delay);
|
the desired delay in seconds |
Returns : |
success |