master #66

Merged
asmeron merged 5 commits from YanTheKaller/libublsettings-gtk3:master into master 2 months ago

@ -185,6 +185,68 @@ char *yon_packages_get_description(enum YON_PACKAGES_DB_TYPE type, const char *p
}
}
char *yon_packages_get_groups(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)){
alpm_list_t *groups = alpm_pkg_get_groups(pkg);
alpm_list_t *iter;
config_str groups_list = NULL;
int parsed_size;
int size = alpm_list_count(groups);
for (int i=0;i<size;i++){
if (yon_char_parsed_check_exist(groups_list,parsed_size,groups->data)==-1){
yon_char_parsed_add_or_create_if_exists(groups_list,&parsed_size,yon_char_new(groups->data));
}
}
char *final = yon_char_parsed_to_string(groups_list,parsed_size,", ");
return yon_char_new(final);
}
}
return NULL;
}
long yon_packages_get_installed_size(enum YON_PACKAGES_DB_TYPE type, const char *package){
if (yon_char_is_empty(package)) return 0;
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)){
long size = alpm_pkg_get_isize(pkg);
return size;
}
}
return 0;
}
long yon_packages_get_size(enum YON_PACKAGES_DB_TYPE type, const char *package){
if (yon_char_is_empty(package)) return 0;
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)){
long size = alpm_pkg_get_size(pkg);
return size;
}
}
return 0;
}
char* yon_alpm_list_to_char(alpm_list_t *list){
if (!list) return NULL;
int size = 0;
@ -199,6 +261,27 @@ char* yon_alpm_list_to_char(alpm_list_t *list){
return final;
}
void yon_packages_info_struct_free(yon_packages_info *info){
if (!yon_char_is_empty(info->repo_name)) free(info->repo_name);
if (!yon_char_is_empty(info->package_name)) free(info->package_name);
if (!yon_char_is_empty(info->version)) free(info->version);
if (!yon_char_is_empty(info->description)) free(info->description);
if (!yon_char_is_empty(info->architecture)) free(info->architecture);
if (!yon_char_is_empty(info->url)) free(info->url);
if (!yon_char_is_empty(info->licence)) free(info->licence);
if (!yon_char_is_empty(info->groups)) free(info->groups);
if (!yon_char_is_empty(info->provides)) free(info->provides);
if (!yon_char_is_empty(info->depends)) free(info->depends);
if (!yon_char_is_empty(info->optional_depends)) free(info->optional_depends);
if (!yon_char_is_empty(info->conflicts)) free(info->conflicts);
if (!yon_char_is_empty(info->replaces)) free(info->replaces);
if (!yon_char_is_empty(info->download_size)) free(info->download_size);
if (!yon_char_is_empty(info->install_size)) free(info->install_size);
if (!yon_char_is_empty(info->packager)) free(info->packager);
if (!yon_char_is_empty(info->build_date)) free(info->build_date);
free(info);
}
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;
@ -406,6 +489,27 @@ GList *yon_packages_get_all(){
return list;
}
GList *yon_packages_search_all(char *pkgname_regex){
if (!packages_struct.init_status) return NULL;
GList *list = NULL;
alpm_list_t *sync_db = alpm_get_syncdbs(packages_struct.packages_handle);
for (alpm_list_t *iter=sync_db;iter;iter=alpm_list_next(iter)){
alpm_db_t *database = iter->data;
alpm_list_t *package_list = alpm_db_get_pkgcache(database);
for (alpm_list_t *iter = package_list;iter;iter=iter->next){
const char *cur_name = alpm_pkg_get_name(iter->data);
if (g_regex_match_simple(pkgname_regex,cur_name,0,0)){
if (!list) list = g_list_append(list,yon_char_new(cur_name));
else if (g_list_append(list,yon_char_new(cur_name))){};
}
}
}
return list;
}
int yon_packages_upac_init(){
}

@ -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;

@ -582,15 +582,47 @@ int yon_packages_check_installed(char *package);
int yon_packages_check_updates(char *package);
void yon_packages_finish();
GList *yon_packages_get_all();
GList *yon_packages_search_all(char *pkgname_regex);
void yon_packages_update();
int yon_packages_install(char *package);
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
/// @param type Source database for package
/// @param package Package name
/// @return The installed size of requested package in bytes
long yon_packages_get_installed_size(enum YON_PACKAGES_DB_TYPE type, const char *package);
/// @brief Get installed size for package
/// @param type Source database for package
/// @param package Package name
/// @return The download size of requested package in bytes
long yon_packages_get_size(enum YON_PACKAGES_DB_TYPE type, const char *package);
/// @brief Get dependences for package
/// @param type Source database for package
/// @param package Package name
/// @return A newly allocated char* array
config_str yon_packages_get_depends(enum YON_PACKAGES_DB_TYPE type, const char *package, int *size);
typedef struct {
@ -616,6 +648,7 @@ typedef struct {
yon_packages_info *yon_packages_get_info_struct(enum YON_PACKAGES_DB_TYPE type, const char *package);
void yon_packages_info_struct_free(yon_packages_info *info);
char *yon_packages_get_info_string(yon_packages_info *info);
void yon_combo_box_set_default(GtkComboBoxText *target, char *command, char*(result_callback)(char*));
@ -722,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
Loading…
Cancel
Save