From 7cd4013dd4e1c3267a543e73fba6d245dc109cb4 Mon Sep 17 00:00:00 2001 From: Ivan Dmitrievich Yartsev Date: Tue, 20 Jan 2026 18:20:27 +0000 Subject: [PATCH] Added package info function --- source/libublsettings-gtk3-packages.c | 154 +++++++++++++++++++++++++- source/libublsettings-gtk3.h | 25 +++++ 2 files changed, 178 insertions(+), 1 deletion(-) diff --git a/source/libublsettings-gtk3-packages.c b/source/libublsettings-gtk3-packages.c index 8a8743b..803c44b 100644 --- a/source/libublsettings-gtk3-packages.c +++ b/source/libublsettings-gtk3-packages.c @@ -92,7 +92,8 @@ int yon_packages_init(){ int yon_packages_check_exist(const char *package_name){ alpm_list_t *sync_db = _yon_packages_get_db_list(YON_PACKAGES_ALL); - for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){ + alpm_list_t *iter; + for (iter=sync_db;iter;iter=alpm_list_next(iter)){ alpm_db_t *database = iter->data; alpm_pkg_t *package = alpm_db_get_pkg(database,package_name); @@ -184,6 +185,157 @@ char *yon_packages_get_description(enum YON_PACKAGES_DB_TYPE type, const char *p } } +char* yon_alpm_list_to_char(alpm_list_t *list){ + if (!list) return NULL; + int size = 0; + size_t list_size = alpm_list_count(list); + config_str parsed = NULL; + for (size_t i=0;idata) + list=list->next; + } + char *final = yon_char_parsed_to_string(parsed,size," "); + yon_char_parsed_free(parsed,size); + return final; +} + +yon_packages_info *yon_packages_get_info_struct(enum YON_PACKAGES_DB_TYPE type, const char *package){ + if (yon_char_is_empty(package)) return NULL; + + alpm_list_t *databases = _yon_packages_get_db_list(type); + alpm_list_t *iter = NULL; + for (iter = databases; iter; iter=iter->next){ + alpm_pkg_t *pkg = alpm_db_get_pkg(iter->data,package); + if (!pkg) continue; + const char *name = alpm_pkg_get_name(pkg); + if (!strcmp(name,package)){ + yon_packages_info *package_info = malloc(sizeof(yon_packages_info)); + memset(package_info,0,sizeof(yon_packages_info)); + package_info->repo_name = yon_char_new(alpm_db_get_name(iter->data)); + package_info->package_name = yon_char_new(alpm_pkg_get_name(pkg)); + package_info->version = yon_char_new(alpm_pkg_get_version(pkg)); + package_info->description = yon_char_new(alpm_pkg_get_desc(pkg)); + package_info->architecture = yon_char_new(alpm_pkg_get_arch(pkg)); + package_info->url = yon_char_new(alpm_pkg_get_url(pkg)); + + size_t size=0; + alpm_list_t *licence_list = alpm_pkg_get_licenses(pkg); + package_info->licence = yon_alpm_list_to_char(licence_list); + alpm_list_free(licence_list); + + alpm_list_t *groups_list = alpm_pkg_get_groups(pkg); + package_info->groups = yon_alpm_list_to_char(groups_list); + alpm_list_free(groups_list); + + { + alpm_list_t *provides_list = alpm_pkg_get_provides(pkg); + size = alpm_list_count(provides_list); + int parsed_size=0; + config_str parsed = NULL; + for (int i=0;idata)->name); + } + package_info->provides = yon_char_parsed_to_string(parsed,parsed_size, " "); + alpm_list_free(provides_list); + } + + { + alpm_list_t *depends_list = alpm_pkg_get_depends(pkg); + size = alpm_list_count(depends_list); + int parsed_size=0; + config_str parsed = NULL; + for (int i=0;idata)->name); + } + package_info->depends = yon_char_parsed_to_string(parsed,parsed_size, " "); + alpm_list_free(depends_list); + } + + { + alpm_list_t *optdepends_list = alpm_pkg_get_optdepends(pkg); + size = alpm_list_count(optdepends_list); + int parsed_size=0; + config_str parsed = NULL; + for (int i=0;idata)->name); + } + package_info->optional_depends = yon_char_parsed_to_string(parsed,parsed_size, " "); + alpm_list_free(optdepends_list); + } + + { + alpm_list_t *conflicts_list = alpm_pkg_get_conflicts(pkg); + size = alpm_list_count(conflicts_list); + int parsed_size=0; + config_str parsed = NULL; + for (int i=0;idata)->name); + } + package_info->conflicts = yon_char_parsed_to_string(parsed,parsed_size, " "); + alpm_list_free(conflicts_list); + } + + { + alpm_list_t *replaces_list = alpm_pkg_get_replaces(pkg); + size = alpm_list_count(replaces_list); + int parsed_size=0; + config_str parsed = NULL; + for (int i=0;idata)->name); + } + package_info->replaces = yon_char_parsed_to_string(parsed,parsed_size, " "); + alpm_list_free(replaces_list); + } + + int size_mod = 0; + int fin_size = yon_size_convert_automatic(alpm_pkg_get_size(pkg),&size_mod); + char *size_letter = yon_size_get_mod(size_mod); + char *size_string = yon_char_from_int(fin_size); + package_info->download_size = yon_char_unite(size_string,size_letter,NULL); + free(size_string); + + size_mod = 0; + fin_size = yon_size_convert_automatic(alpm_pkg_get_isize(pkg),&size_mod); + size_letter = yon_size_get_mod(size_mod); + size_string = yon_char_from_int(fin_size); + package_info->install_size = yon_char_unite(size_string,size_letter,NULL); + free(size_string); + + package_info->packager = yon_char_new(alpm_pkg_get_packager(pkg)); + GDateTime *datetime = g_date_time_new_from_unix_local(alpm_pkg_get_builddate(pkg)); + package_info->build_date = g_date_time_format(datetime,"%Ec"); + package_info->validate_by = alpm_pkg_get_validation(pkg); + + return package_info; + } + } +} + +char *yon_packages_get_info_string(yon_packages_info *info){ + char *packager = yon_char_return_if_exist(info->packager,""); + char *info_label = yon_char_unite( + "Repository :",yon_char_return_if_exist(info->repo_name,""),"\n", + "Name :",yon_char_return_if_exist(info->package_name,""),"\n", + "Version :",yon_char_return_if_exist(info->version,""),"\n", + "Description :",yon_char_return_if_exist(info->description,""),"\n", + "Architecture :",yon_char_return_if_exist(info->architecture,""),"\n", + "URL :",yon_char_return_if_exist(info->url,""),"\n", + "Licenses :",yon_char_return_if_exist(info->licence,""),"\n", + "Groups :",yon_char_return_if_exist(info->groups,""),"\n", + "Provides :",yon_char_return_if_exist(info->provides,""),"\n", + "Depends On :",yon_char_return_if_exist(info->depends,""),"\n", + "Optional Deps :",yon_char_return_if_exist(info->optional_depends,""),"\n", + "Conflicts With :",yon_char_return_if_exist(info->conflicts,""),"\n", + "Replaces :",yon_char_return_if_exist(info->replaces,""),"\n", + "Download Size :",yon_char_return_if_exist(info->download_size,""),"\n", + "Installed Size :",yon_char_return_if_exist(info->install_size,""),"\n", + "Packager :",g_markup_escape_text(packager,strlen(packager)),"\n", + "Build Date :",yon_char_return_if_exist(info->build_date,""),"\n", + "Validated By :",yon_char_return_if_exist(info->architecture,""), + NULL); +return info_label; +} + config_str yon_packages_get_depends(enum YON_PACKAGES_DB_TYPE type, const char *package, int *size){ (*size)=0; if (yon_char_is_empty(package)) return NULL; diff --git a/source/libublsettings-gtk3.h b/source/libublsettings-gtk3.h index 117a90f..518d268 100644 --- a/source/libublsettings-gtk3.h +++ b/source/libublsettings-gtk3.h @@ -620,6 +620,31 @@ char *yon_packages_get_description(enum YON_PACKAGES_DB_TYPE type, const char *p config_str yon_packages_get_depends(enum YON_PACKAGES_DB_TYPE type, const char *package, int *size); +typedef struct { + char *repo_name; + char *package_name; + char *version; + char *description; + char *architecture; + char *url; + char *licence; + char *groups; + char *provides; + char *depends; + char *optional_depends; + char *conflicts; + char *replaces; + char *download_size; + char *install_size; + char *packager; + char *build_date; + int validate_by; +} yon_packages_info; + +yon_packages_info *yon_packages_get_info_struct(enum YON_PACKAGES_DB_TYPE type, const char *package); + +char *yon_packages_get_info_string(yon_packages_info *info); + void yon_combo_box_set_default(GtkComboBoxText *target, char *command, char*(result_callback)(char*)); int yon_ip_mask_get_bits(char *mask);