You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libublsettings-gtk3/source/libublsettings-gtk3-apps.c

67 lines
2.6 KiB

#include "libublsettings-gtk3.h"
GHashTable *_apps = NULL;
apps *yon_app_new(){
apps *new_app = malloc(sizeof(apps));
memset(new_app,0,sizeof(apps));
return new_app;
}
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);
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,";");
target->Exec = g_key_file_get_string(cur_file,"Desktop Entry","Exec",NULL);
target->Icon = g_key_file_get_string(cur_file,"Desktop Entry","Icon",NULL);
char *pluggable = g_key_file_get_string(cur_file,"Desktop Entry","X-XfxePluggable",NULL);
target->Pluggable = !yon_char_is_empty(pluggable)&&!strcmp(pluggable,"true");
char *dual_pluggable = g_key_file_get_string(cur_file,"Desktop Entry","X-UBLPluggable",NULL);
target->DualPluggable = !yon_char_is_empty(dual_pluggable)&&!strcmp(dual_pluggable,"true");
char *type = g_key_file_get_string(cur_file,"Desktop Entry","Type",NULL);
target->Type = !yon_char_is_empty(type)&&!strcmp(type,"Application");
free(categories);
free(pluggable);
free(dual_pluggable);
free(type);
return 1;
}
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);
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);
}
}
apps *yon_apps_get(char *name){
apps *cur_app = g_hash_table_lookup(_apps,name);
return cur_app;
}
config_str yon_apps_get_by_categories(config_str categories, int categories_size, int *final_size){
(*final_size) = 0;
GList *list = g_hash_table_get_values(_apps);
if (!list) return NULL;
config_str final = NULL;
GList *iter;
for (iter=list;iter;iter=iter->next){
apps *cur_app = (apps*)iter->data;
if (yon_char_parsed_includes_char_parsed(cur_app->Categories,categories,cur_app->categories_size, categories_size)){
yon_char_parsed_add_or_create_if_exists(final,final_size,cur_app->Name);
}
}
return final;
}