From 0693c4b9e223b647ff2e5bc8852861b55df30a09 Mon Sep 17 00:00:00 2001 From: Ivan Dmitrievich Yartsev Date: Tue, 17 Feb 2026 18:01:28 +0600 Subject: [PATCH] Added new size function --- source/libublsettings-gtk3.c | 18 ++++++++++++++++++ source/libublsettings-gtk3.h | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/source/libublsettings-gtk3.c b/source/libublsettings-gtk3.c index f12fcd9..49983cd 100644 --- a/source/libublsettings-gtk3.c +++ b/source/libublsettings-gtk3.c @@ -130,6 +130,24 @@ void yon_gtk_widget_register_parameter_activate(){ } } +char *yon_size_get_name_from_letter(char letter){ + switch (letter){ + case 'K': return yon_char_new(KB_LABEL); break; + case 'M': return yon_char_new(MB_LABEL); break; + case 'G': return yon_char_new(GB_LABEL); break; + case 'T': return yon_char_new(TB_LABEL); break; + } + return NULL; +} + +char *yon_size_long_convert_automatic_to_string(unsigned long bytes){ + char mod = '\0'; + double size_converted = yon_size_long_convert_automatic(bytes, &mod); + char *size_converted_str = yon_char_from_double(size_converted); + char *final = yon_char_unite(size_converted_str, " ", yon_size_get_name_from_letter(mod),NULL); + return final; +} + // dictionary *__yon_config_listeners = NULL; // typedef struct { // GtkWidget *target; diff --git a/source/libublsettings-gtk3.h b/source/libublsettings-gtk3.h index b47ddff..276b7ba 100644 --- a/source/libublsettings-gtk3.h +++ b/source/libublsettings-gtk3.h @@ -589,8 +589,22 @@ int yon_packages_remove(char *package); config_str yon_packages_find(enum YON_PACKAGES_DB_TYPE type, const char *search_string, gsize *size); +/// @brief Get groups string for package +/// @param type Source database for package +/// @param package Package name +/// @return A newly allocated string of groups for requested package in bytes char *yon_packages_get_version(enum YON_PACKAGES_DB_TYPE type, const char *package); + +/// @brief Get description for package +/// @param type Source database for package +/// @param package Package name +/// @return A newly allocated description string for requested package in bytes char *yon_packages_get_description(enum YON_PACKAGES_DB_TYPE type, const char *package); + +/// @brief Get groups string for package +/// @param type Source database for package +/// @param package Package name +/// @return A newly allocated string of groups for requested package in bytes char *yon_packages_get_groups(enum YON_PACKAGES_DB_TYPE type, const char *package); /// @brief Get installed size for package @@ -741,4 +755,14 @@ char *yon_timezone_get_zone(const char *timezone); /// @return A newly allocated char string with UTC modifier or NULL char *yon_timezone_get_utc(const char *timezone); + #define KB_LABEL _("Kb") + #define MB_LABEL _("Mb") + #define GB_LABEL _("Gb") + #define TB_LABEL _("Tb") + +/// @brief Get a string of bytes, converted to kilobytes, megabytes gigabytes or terabytes (K, M, G, T) +/// @param bytes bytes to convert +/// @return A newly allocated string with converted representation of bytes +char *yon_size_long_convert_automatic_to_string(unsigned long bytes); + #endif \ No newline at end of file