diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 1a88396..379da09 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -36,6 +36,7 @@ endif() # -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security \ # -fstack-clash-protection -fcf-protection") add_library(${PROJECT_NAME} SHARED + ${PROJECT_NAME}-apps.c ${PROJECT_NAME}-calendar.c ${PROJECT_NAME}-menu.c ${PROJECT_NAME}-misc.c diff --git a/source/libublsettings-gtk3-apps.c b/source/libublsettings-gtk3-apps.c new file mode 100644 index 0000000..57921b9 --- /dev/null +++ b/source/libublsettings-gtk3-apps.c @@ -0,0 +1,67 @@ +#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;iName,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; +} \ No newline at end of file diff --git a/source/libublsettings-gtk3.h b/source/libublsettings-gtk3.h index 720702a..ac6c1bf 100644 --- a/source/libublsettings-gtk3.h +++ b/source/libublsettings-gtk3.h @@ -616,4 +616,21 @@ int yon_ip_check(char *ip); void yon_gtk_widget_register_parameter(GtkWidget *target, char *config_parameter, char *get_command, char *object_property); void yon_gtk_widget_register_parameter_manual(GtkWidget *target, char *config_parameter, char *get_command, char *object_property); void yon_gtk_widget_register_parameter_activate(); + +typedef struct apps +{ + char *Name; + int Type; + char *Comment; + int categories_size; + config_str Categories; + char *Exec; + char *Icon; + int Pluggable; + int DualPluggable; +} apps; + +void yon_apps_init(); +apps *yon_apps_get(char *name); +config_str yon_apps_get_by_categories(config_str categories, int categories_size, int *final_size); #endif \ No newline at end of file