App system changes #56

Merged
asmeron merged 1 commits from YanTheKaller/libublsettings-gtk3:master into master 1 month ago

@ -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;i<parsed_size;i++){
if ((strlen(parsed[i])==2&&parsed[i][0]=='%')||parsed[i][0]=='-'){
free(parsed[i]);
parsed[i] = yon_char_new(" ");
parsed[i][0]='\0';
}
}
free(target->Exec);
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;i<size;i++){
if (!strstr(paths[i],".desktop")) continue;
char *cur_path = yon_char_unite(DesktopPath,"/",paths[i],NULL);
apps *cur_app = yon_app_new();
yon_app_set_from_file(cur_app,cur_path);
g_hash_table_insert(_apps,cur_app->Name,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;

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

Loading…
Cancel
Save