diff --git a/source/libublsettings-gtk3-apps.c b/source/libublsettings-gtk3-apps.c index 57921b9..2bda4fc 100644 --- a/source/libublsettings-gtk3-apps.c +++ b/source/libublsettings-gtk3-apps.c @@ -8,11 +8,21 @@ apps *yon_app_new(){ return new_app; } +void yon_app_free(apps *target){ + if (!yon_char_is_empty(target->Comment)) free(target->Comment); + if (!yon_char_is_empty(target->Exec)) free(target->Exec); + if (!yon_char_is_empty(target->Icon)) free(target->Icon); + if (target->categories_size) yon_char_parsed_free(target->Categories,target->categories_size); +} + int yon_app_set_from_file(apps *target, const char *path){ GKeyFile *cur_file = g_key_file_new(); if (!g_key_file_load_from_file(cur_file,path,G_KEY_FILE_KEEP_TRANSLATIONS,NULL)) return 0; - target->Name = g_key_file_get_string(cur_file,"Desktop Entry","Name",NULL); + gsize names_size; + config_str names = g_key_file_get_locale_string_list(cur_file,"Desktop Entry","Name",NULL,&names_size,NULL); + target->Desktop_path = yon_char_new(path); + target->Name = names[0]; target->Comment = g_key_file_get_string(cur_file,"Desktop Entry","Comment",NULL); char *categories = g_key_file_get_string(cur_file,"Desktop Entry","Categories",NULL); target->Categories = yon_char_parse(categories,&target->categories_size,";"); @@ -25,6 +35,20 @@ int yon_app_set_from_file(apps *target, const char *path){ char *type = g_key_file_get_string(cur_file,"Desktop Entry","Type",NULL); target->Type = !yon_char_is_empty(type)&&!strcmp(type,"Application"); + if (!yon_char_is_empty(target->Exec)){ + int parsed_size; + config_str parsed = yon_char_parse(target->Exec,&parsed_size," "); + for (int i=0;iExec); + target->Exec = yon_char_parsed_to_string(parsed,parsed_size," "); + } + free(categories); free(pluggable); free(dual_pluggable); @@ -35,17 +59,32 @@ int yon_app_set_from_file(apps *target, const char *path){ void yon_apps_init(){ int size; config_str paths = yon_dir_get_contents(DesktopPath,&size); - _apps = g_hash_table_new(g_str_hash,g_str_equal); + _apps = g_hash_table_new_full(g_str_hash,g_str_equal,(GDestroyNotify)free,(GDestroyNotify)yon_app_free); for (int i=0;iName,cur_app); + g_hash_table_insert(_apps,yon_char_new(cur_app->Name),cur_app); } } +gboolean __yon_apps_uninit_remove(char *key, apps *value, void*){ + free(key); + yon_app_free(value); + +} + +void yon_apps_uninit(){ + g_hash_table_destroy(_apps); + _apps=NULL; +} + +gboolean yon_apps_check_init(){ + return !!_apps; +} + apps *yon_apps_get(char *name){ apps *cur_app = g_hash_table_lookup(_apps,name); return cur_app; diff --git a/source/libublsettings-gtk3.h b/source/libublsettings-gtk3.h index 02c055a..3ebf4a6 100644 --- a/source/libublsettings-gtk3.h +++ b/source/libublsettings-gtk3.h @@ -620,6 +620,7 @@ void yon_gtk_widget_register_parameter_activate(); typedef struct apps { char *Name; + char *Desktop_path; int Type; char *Comment; int categories_size; @@ -630,8 +631,26 @@ typedef struct apps int DualPluggable; } apps; +/// @brief Initiallize applications system void yon_apps_init(); + +/// @brief Uninitiallize applications system +void yon_apps_uninit(); + +/// @brief Check the initialization of the applications system +/// @return true if initialised, false otherwise +gboolean yon_apps_check_init(); + +/// @brief Get a structure with information about the application +/// @param name Application name +/// @return Structure with information about the application from the system apps *yon_apps_get(char *name); + +/// @brief Get all apps from the category list +/// @param categories List of categories for which applications are searched +/// @param categories_size The length of the category list +/// @param final_size The size of the final array with application names +/// @return An array of strings containing the names of all applications in the given categories. config_str yon_apps_get_by_categories(config_str categories, int categories_size, int *final_size);