|
|
|
@ -8,11 +8,21 @@ apps *yon_app_new(){
|
|
|
|
return new_app;
|
|
|
|
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){
|
|
|
|
int yon_app_set_from_file(apps *target, const char *path){
|
|
|
|
GKeyFile *cur_file = g_key_file_new();
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
char *categories = g_key_file_get_string(cur_file,"Desktop Entry","Categories",NULL);
|
|
|
|
target->Categories = yon_char_parse(categories,&target->categories_size,";");
|
|
|
|
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);
|
|
|
|
char *type = g_key_file_get_string(cur_file,"Desktop Entry","Type",NULL);
|
|
|
|
target->Type = !yon_char_is_empty(type)&&!strcmp(type,"Application");
|
|
|
|
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(categories);
|
|
|
|
free(pluggable);
|
|
|
|
free(pluggable);
|
|
|
|
free(dual_pluggable);
|
|
|
|
free(dual_pluggable);
|
|
|
|
@ -35,17 +59,32 @@ int yon_app_set_from_file(apps *target, const char *path){
|
|
|
|
void yon_apps_init(){
|
|
|
|
void yon_apps_init(){
|
|
|
|
int size;
|
|
|
|
int size;
|
|
|
|
config_str paths = yon_dir_get_contents(DesktopPath,&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++){
|
|
|
|
for (int i=0;i<size;i++){
|
|
|
|
if (!strstr(paths[i],".desktop")) continue;
|
|
|
|
if (!strstr(paths[i],".desktop")) continue;
|
|
|
|
char *cur_path = yon_char_unite(DesktopPath,"/",paths[i],NULL);
|
|
|
|
char *cur_path = yon_char_unite(DesktopPath,"/",paths[i],NULL);
|
|
|
|
apps *cur_app = yon_app_new();
|
|
|
|
apps *cur_app = yon_app_new();
|
|
|
|
yon_app_set_from_file(cur_app,cur_path);
|
|
|
|
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 *yon_apps_get(char *name){
|
|
|
|
apps *cur_app = g_hash_table_lookup(_apps,name);
|
|
|
|
apps *cur_app = g_hash_table_lookup(_apps,name);
|
|
|
|
return cur_app;
|
|
|
|
return cur_app;
|
|
|
|
|