|
|
|
@ -5,48 +5,7 @@ struct return_struct {
|
|
|
|
int size;
|
|
|
|
int size;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct application {
|
|
|
|
int yon_apps_already_init=0;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
char *description;
|
|
|
|
|
|
|
|
char *tags;
|
|
|
|
|
|
|
|
char *execute;
|
|
|
|
|
|
|
|
char *icon;
|
|
|
|
|
|
|
|
config_str other;
|
|
|
|
|
|
|
|
int other_size;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config_str yon_apps_get_from_file(char *file,int *final_size){
|
|
|
|
|
|
|
|
(*final_size)=0;
|
|
|
|
|
|
|
|
config_str final = NULL;
|
|
|
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
config_str parsed = yon_dir_get_contents(file,&size);
|
|
|
|
|
|
|
|
for (int i=0;i<size;i++){
|
|
|
|
|
|
|
|
if (strstr(parsed[i],".desktop")){
|
|
|
|
|
|
|
|
char *path = yon_char_unite(file,"/",parsed[i],NULL);
|
|
|
|
|
|
|
|
yon_char_parsed_add_or_create_if_exists(final,final_size,path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
yon_char_parsed_free(parsed,size);
|
|
|
|
|
|
|
|
return final;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int yon_app_chooser_apps_get(yon_app_chooser_window *window){
|
|
|
|
|
|
|
|
window->apps = NULL;
|
|
|
|
|
|
|
|
window->apps_size=0;
|
|
|
|
|
|
|
|
int merged_size;
|
|
|
|
|
|
|
|
config_str merged = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// int temp_size;
|
|
|
|
|
|
|
|
// config_str temp = yon_apps_get_from_file("/usr/shared/applications",&temp_size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// int local_size;
|
|
|
|
|
|
|
|
// config_str local = yon_apps_get_from_file("/usr/local/shared/applications",&temp_size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window->apps = yon_apps_get_from_file("/usr/share/applications",&window->apps_size);
|
|
|
|
|
|
|
|
return window->apps_size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void yon_block_visibility_if_unallowed(GtkWidget *self, GParamSpec* pspec,yon_app_chooser_window *window){
|
|
|
|
void yon_block_visibility_if_unallowed(GtkWidget *self, GParamSpec* pspec,yon_app_chooser_window *window){
|
|
|
|
if (gtk_widget_get_visible(window->MainWindow)){
|
|
|
|
if (gtk_widget_get_visible(window->MainWindow)){
|
|
|
|
@ -56,65 +15,12 @@ void yon_block_visibility_if_unallowed(GtkWidget *self, GParamSpec* pspec,yon_ap
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int yon_app_chooser_convert_apps(yon_app_chooser_window *window){
|
|
|
|
|
|
|
|
GKeyFile *file = g_key_file_new();
|
|
|
|
|
|
|
|
window->apps_convert = NULL;
|
|
|
|
|
|
|
|
for (int i=0;i<window->apps_size;i++){
|
|
|
|
|
|
|
|
if (g_key_file_load_from_file(file,window->apps[i],G_KEY_FILE_KEEP_TRANSLATIONS,NULL)){
|
|
|
|
|
|
|
|
char *exec_temp = yon_char_new(window->apps[i]);
|
|
|
|
|
|
|
|
free(yon_char_divide(exec_temp,yon_char_find_last(exec_temp,'/')));
|
|
|
|
|
|
|
|
struct application *app = new(struct application);
|
|
|
|
|
|
|
|
memset(app,0,sizeof(struct application));
|
|
|
|
|
|
|
|
app->name = g_key_file_get_locale_string(file,"Desktop Entry","Name",setlocale(LC_ALL,NULL),NULL);
|
|
|
|
|
|
|
|
app->description = g_key_file_get_locale_string(file,"[Desktop Entry","Comment",setlocale(LC_ALL,NULL),NULL);
|
|
|
|
|
|
|
|
app->tags = g_key_file_get_string(file,"Desktop Entry","Categories",NULL);
|
|
|
|
|
|
|
|
app->execute = yon_char_divide(exec_temp,yon_char_find_last(exec_temp,'.'));
|
|
|
|
|
|
|
|
app->icon = g_key_file_get_string(file,"Desktop Entry","Icon",NULL);
|
|
|
|
|
|
|
|
app->path = yon_char_new(window->apps[i]);
|
|
|
|
|
|
|
|
yon_dictionary_add_or_create_if_exists_with_data(window->apps_convert,app->name,app);
|
|
|
|
|
|
|
|
free(exec_temp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->apps_convert) return 1; else return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// int yon_tree_store_setup_apps(yon_app_chooser_window *window){
|
|
|
|
|
|
|
|
// GtkTreeIter iter,itar;
|
|
|
|
|
|
|
|
// GtkTreeModel *model = GTK_TREE_MODEL(window->treestore);
|
|
|
|
|
|
|
|
// for_iter (model,&iter){
|
|
|
|
|
|
|
|
// char *tags;
|
|
|
|
|
|
|
|
// gtk_tree_model_get(model,&iter,3,&tags,-1);
|
|
|
|
|
|
|
|
// int required_size;
|
|
|
|
|
|
|
|
// config_str required_tags = yon_char_parse(tags,&required_size,";");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// dictionary *dict;
|
|
|
|
|
|
|
|
// for_dictionaries(dict,window->apps_convert){
|
|
|
|
|
|
|
|
// int parsed_size;
|
|
|
|
|
|
|
|
// struct application *cur_app = (struct application*)dict->data;
|
|
|
|
|
|
|
|
// config_str parsed_tags = yon_char_parse(cur_app->tags,&parsed_size,";");
|
|
|
|
|
|
|
|
// if (yon_char_parsed_includes_char_parsed(required_tags,parsed_tags,required_size,parsed_size)){
|
|
|
|
|
|
|
|
// gtk_tree_store_append(window->treestore,&itar,&iter);
|
|
|
|
|
|
|
|
// gtk_tree_store_set(window->treestore,&itar,0,0,1,cur_app->name,2,cur_app->description,3,cur_app->tags,4,0,5,cur_app->icon,6,cur_app->execute,-1);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int yon_tree_store_setup_apps(yon_app_chooser_window *window){
|
|
|
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
dictionary *dict;
|
|
|
|
|
|
|
|
for_dictionaries(dict,window->apps_convert){
|
|
|
|
|
|
|
|
int parsed_size;
|
|
|
|
|
|
|
|
struct application *cur_app = (struct application*)dict->data;
|
|
|
|
|
|
|
|
gtk_tree_store_append(window->treestore,&iter,NULL);
|
|
|
|
|
|
|
|
gtk_tree_store_set(window->treestore,&iter,0,0,1,cur_app->name,2,cur_app->description,3,cur_app->tags,4,0,5,cur_app->icon,6,cur_app->execute,-1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config_str yon_app_chooser_window_run(yon_app_chooser_window *window, int *size){
|
|
|
|
config_str yon_app_chooser_window_run(yon_app_chooser_window *window, int *size){
|
|
|
|
gtk_widget_show(window->MainWindow);
|
|
|
|
gtk_widget_show(window->MainWindow);
|
|
|
|
gtk_main();
|
|
|
|
gtk_main();
|
|
|
|
|
|
|
|
if (!yon_apps_already_init){
|
|
|
|
|
|
|
|
yon_apps_uninit();
|
|
|
|
|
|
|
|
}
|
|
|
|
config_str final = window->final->chosen_apps;
|
|
|
|
config_str final = window->final->chosen_apps;
|
|
|
|
(*size)=window->final->size;
|
|
|
|
(*size)=window->final->size;
|
|
|
|
free(window);
|
|
|
|
free(window);
|
|
|
|
@ -140,7 +46,7 @@ void on_app_chooser_accept(GtkWidget *, yon_app_chooser_window *window){
|
|
|
|
for_iter(model,&iter){
|
|
|
|
for_iter(model,&iter){
|
|
|
|
int status;
|
|
|
|
int status;
|
|
|
|
char *name;
|
|
|
|
char *name;
|
|
|
|
gtk_tree_model_get(GTK_TREE_MODEL(window->treestore),&iter,0,&status,6,&name,-1);
|
|
|
|
gtk_tree_model_get(GTK_TREE_MODEL(window->treestore),&iter,0,&status,1,&name,-1);
|
|
|
|
if (status){
|
|
|
|
if (status){
|
|
|
|
yon_char_parsed_add_or_create_if_exists(window->final->chosen_apps,&window->final->size,name);
|
|
|
|
yon_char_parsed_add_or_create_if_exists(window->final->chosen_apps,&window->final->size,name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -168,7 +74,12 @@ int yon_app_chooser_window_select(yon_app_chooser_window *window,config_str sele
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
yon_app_chooser_window *yon_app_chooser_window_new(int multiple_choise){
|
|
|
|
yon_app_chooser_window *yon_app_chooser_window_new(int multiple_choise,...){
|
|
|
|
|
|
|
|
if (yon_apps_check_init()){
|
|
|
|
|
|
|
|
yon_apps_already_init=1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
yon_apps_init();
|
|
|
|
|
|
|
|
}
|
|
|
|
yon_app_chooser_window *window = new(yon_app_chooser_window);
|
|
|
|
yon_app_chooser_window *window = new(yon_app_chooser_window);
|
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(ui_glade_path_app_chooser);
|
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(ui_glade_path_app_chooser);
|
|
|
|
window->MainWindow = yon_gtk_builder_get_widget(builder,"MainWindow");
|
|
|
|
window->MainWindow = yon_gtk_builder_get_widget(builder,"MainWindow");
|
|
|
|
@ -203,10 +114,33 @@ yon_app_chooser_window *yon_app_chooser_window_new(int multiple_choise){
|
|
|
|
gtk_cell_renderer_set_visible(GTK_CELL_RENDERER(window->SelectionCell),0);
|
|
|
|
gtk_cell_renderer_set_visible(GTK_CELL_RENDERER(window->SelectionCell),0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
va_list list;
|
|
|
|
if (!yon_app_chooser_apps_get(window)) return NULL;
|
|
|
|
va_start(list,multiple_choise);
|
|
|
|
if (!yon_app_chooser_convert_apps(window)) return NULL;
|
|
|
|
char *cur_section = NULL;
|
|
|
|
yon_tree_store_setup_apps(window);
|
|
|
|
int sections_size;
|
|
|
|
|
|
|
|
config_str sections_list = NULL;
|
|
|
|
|
|
|
|
int section_titles_size;
|
|
|
|
|
|
|
|
config_str section_titles_list = NULL;
|
|
|
|
|
|
|
|
while ((cur_section = va_arg(list,char*))){
|
|
|
|
|
|
|
|
if (yon_char_is_empty(cur_section)) break;
|
|
|
|
|
|
|
|
yon_char_parsed_add_or_create_if_exists(section_titles_list,§ion_titles_size,cur_section);
|
|
|
|
|
|
|
|
cur_section = va_arg(list,char*);
|
|
|
|
|
|
|
|
yon_char_parsed_add_or_create_if_exists(sections_list,§ions_size,cur_section);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<sections_size;i+=1){
|
|
|
|
|
|
|
|
GtkTreeIter parent, child;
|
|
|
|
|
|
|
|
int apps_size;
|
|
|
|
|
|
|
|
config_str apps_list = yon_apps_get_by_categories(&(sections_list[i]),1,&apps_size);
|
|
|
|
|
|
|
|
gtk_tree_store_append(window->treestore,&parent,NULL);
|
|
|
|
|
|
|
|
gtk_tree_store_set(window->treestore,&parent,1,section_titles_list[i],2,1,-1);
|
|
|
|
|
|
|
|
for (int k=0;k<apps_size;k++){
|
|
|
|
|
|
|
|
apps *cur_app = yon_apps_get(apps_list[k]);
|
|
|
|
|
|
|
|
gtk_tree_store_append(window->treestore,&child,&parent);
|
|
|
|
|
|
|
|
gtk_tree_store_set(window->treestore,&child,1,cur_app->Name,3,cur_app->Icon,-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
yon_char_parsed_free(apps_list,apps_size);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return window;
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
}
|