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.
207 lines
8.8 KiB
207 lines
8.8 KiB
#include "ubl-settings-manager.h"
|
|
|
|
typedef struct {
|
|
GtkWidget *expander;
|
|
GtkWidget *MainLabel;
|
|
GtkWidget *AppsList;
|
|
app_section *section;
|
|
} main_section;
|
|
|
|
void yon_main_section_setup_apps(main_section *cur_section, const char *target);
|
|
main_section *yon_main_section_new();
|
|
void yon_main_section_get_max_size(main_section *section, int *ret_width, int *ret_height);
|
|
|
|
void on_main_plug_connected(GtkWidget *,main_theme_struct *theme){
|
|
gtk_widget_show(theme->SocketBox);
|
|
gtk_widget_hide(theme->HideBox);
|
|
}
|
|
|
|
void on_main_plug_disconnected(GtkWidget *,main_theme_struct *theme){
|
|
gtk_widget_show(theme->HideBox);
|
|
gtk_widget_hide(theme->SocketBox);
|
|
on_plug_disconnected(GTK_SOCKET(theme->Socket),main_config.widgets);
|
|
}
|
|
|
|
void on_main_selected(GtkWidget* self, main_theme_struct *theme);
|
|
void on_main_selected(GtkWidget* self, main_theme_struct *theme){
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(theme->AppsTree));
|
|
GList *iter;
|
|
for (iter=list;iter;iter=iter->next){
|
|
main_section *cur_section = g_object_get_data(G_OBJECT(iter->data),"main_section");
|
|
if (cur_section->AppsList != self){
|
|
g_signal_handlers_block_by_func(G_OBJECT(cur_section->AppsList),G_CALLBACK(on_main_selected),theme);
|
|
GList *flowlist = gtk_flow_box_get_selected_children(GTK_FLOW_BOX(cur_section->AppsList));
|
|
if (flowlist){
|
|
gtk_flow_box_unselect_child(GTK_FLOW_BOX(cur_section->AppsList),GTK_FLOW_BOX_CHILD(flowlist->data));
|
|
g_list_free(flowlist);
|
|
}
|
|
g_signal_handlers_unblock_by_func(G_OBJECT(cur_section->AppsList),G_CALLBACK(on_main_selected),theme);
|
|
}
|
|
}
|
|
}
|
|
|
|
void on_main_activate(GtkFlowBox* , GtkFlowBoxChild* child, main_theme_struct *theme){
|
|
theme->Socket = GTK_WIDGET(yon_sockets_init(GTK_BOX(theme->SocketBox)));
|
|
g_signal_connect(G_OBJECT(theme->Socket),"plug_added",G_CALLBACK(on_main_plug_connected),theme);
|
|
g_signal_connect(G_OBJECT(theme->Socket),"destroy",G_CALLBACK(on_main_plug_disconnected),theme);
|
|
apps *cur_app = g_object_get_data(G_OBJECT(child),"apps");
|
|
char *command = cur_app->Exec;//launch_command(cur_app->Desktop_path);
|
|
char *command_args = NULL;
|
|
if (cur_app->DualPluggable==1){
|
|
char *save_socket = yon_get_save_socket();
|
|
char *load_socket = yon_get_load_socket();
|
|
char *main_socket_id = yon_char_from_long((long)gtk_socket_get_id(GTK_SOCKET(theme->Socket)));
|
|
command_args = launch_args_command(main_socket_id,load_socket,save_socket);
|
|
} else if (cur_app->Pluggable){
|
|
char *main_socket_id = yon_char_from_long((long)gtk_socket_get_id(GTK_SOCKET(theme->Socket)));
|
|
command_args = yon_char_unite("--socket-id=",main_socket_id,NULL);
|
|
|
|
}
|
|
yon_launch_app_with_arguments(command,command_args);
|
|
}
|
|
|
|
// void on_main_socket_add(){
|
|
|
|
// }
|
|
|
|
void yon_main_section_setup_apps(main_section *cur_section, const char *target){
|
|
if (yon_char_is_empty(target)) return;
|
|
apps *cur_app = yon_apps_get((char*)target);
|
|
GtkIconInfo *info = gtk_icon_theme_lookup_icon_for_scale(gtk_icon_theme_get_default(), !yon_char_is_empty(cur_app->Icon)?cur_app->Icon:icon_path, main_config.apps_icon_size,1,GTK_ICON_LOOKUP_FORCE_SIZE);
|
|
GtkWidget *Image = NULL;
|
|
if (info){
|
|
Image = gtk_image_new_from_pixbuf(gtk_icon_info_load_icon(info,NULL));
|
|
} else {
|
|
info = gtk_icon_theme_lookup_icon_for_scale(gtk_icon_theme_get_default(), icon_path, main_config.apps_icon_size,1,GTK_ICON_LOOKUP_FORCE_SIZE);
|
|
Image = gtk_image_new_from_pixbuf(gtk_icon_info_load_icon(info,NULL));
|
|
|
|
}
|
|
|
|
char *name = yon_char_wrap_to_length_str(cur_app->Name,20);
|
|
|
|
GtkWidget *Row = gtk_flow_box_child_new();
|
|
GtkWidget *Box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5);
|
|
GtkWidget *Label = gtk_label_new(name);
|
|
GtkWidget *Icon = Image;
|
|
|
|
gtk_box_pack_start(GTK_BOX(Box),Icon,0,0,0);
|
|
gtk_box_pack_start(GTK_BOX(Box),Label,0,0,0);
|
|
gtk_container_add(GTK_CONTAINER(Row),Box);
|
|
gtk_flow_box_insert(GTK_FLOW_BOX(cur_section->AppsList),Row,-1);
|
|
|
|
gtk_widget_set_size_request(Row,50,50);
|
|
|
|
gtk_widget_set_halign(Box,GTK_ALIGN_START);
|
|
gtk_widget_set_valign(Box,GTK_ALIGN_CENTER);
|
|
|
|
gtk_label_set_line_wrap_mode(GTK_LABEL(Label),PANGO_WRAP_WORD);
|
|
gtk_label_set_line_wrap(GTK_LABEL(Label),1);
|
|
gtk_label_set_xalign(GTK_LABEL(Label),0);
|
|
|
|
g_object_set_data(G_OBJECT(Row),"main_section",cur_section);
|
|
g_object_set_data(G_OBJECT(Row),"apps",cur_app);
|
|
g_object_set_data(G_OBJECT(Row),"Label",Label);
|
|
|
|
gtk_widget_show_all(Row);
|
|
}
|
|
|
|
main_section *yon_main_section_new(){
|
|
main_section *cur_section = malloc(sizeof(main_section));
|
|
memset(cur_section,0,sizeof(main_section));
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_main_section);
|
|
cur_section->expander = yon_gtk_builder_get_widget(builder,"MainExpander");
|
|
cur_section->MainLabel = yon_gtk_builder_get_widget(builder,"MainLabel");
|
|
cur_section->AppsList = yon_gtk_builder_get_widget(builder,"AppsFlow");
|
|
g_object_set_data(G_OBJECT(cur_section->expander),"main_section",cur_section);
|
|
int doubleclick=0;
|
|
if (!yon_window_config_get_parameter(settings_section,double_click_parameter,&doubleclick,YON_TYPE_BOOLEAN)){
|
|
gtk_flow_box_set_activate_on_single_click(GTK_FLOW_BOX(cur_section->AppsList),1);
|
|
} else {
|
|
gtk_flow_box_set_activate_on_single_click(GTK_FLOW_BOX(cur_section->AppsList),!doubleclick);
|
|
}
|
|
return cur_section;
|
|
}
|
|
|
|
void yon_main_section_setup(main_theme_struct *theme, app_section *section){
|
|
main_section *cur_section = yon_main_section_new();
|
|
cur_section->section = section;
|
|
gtk_label_set_text(GTK_LABEL(cur_section->MainLabel),section->name);
|
|
int app_size;
|
|
config_str app_list = yon_apps_get_by_categories(section->categories,section->categories_size,&app_size);
|
|
for(int i=0;i<app_size;i++){
|
|
yon_main_section_setup_apps(cur_section,app_list[i]);
|
|
}
|
|
gtk_box_pack_start(GTK_BOX(theme->AppsTree),cur_section->expander,0,0,0);
|
|
g_object_set_data(G_OBJECT(cur_section->expander),"main_section",cur_section);
|
|
g_signal_connect(G_OBJECT(cur_section->AppsList),"child-activated",G_CALLBACK(on_main_activate),theme);
|
|
g_signal_connect(G_OBJECT(cur_section->AppsList),"selected-children-changed",G_CALLBACK(on_main_selected),theme);
|
|
|
|
}
|
|
|
|
void yon_main_section_get_max_size(main_section *section, int *ret_width, int *ret_height){
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(section->AppsList));
|
|
GList *iter;
|
|
for (iter = list; iter;iter=iter->next){
|
|
gtk_widget_realize(GTK_WIDGET(iter->data));
|
|
int width;
|
|
int height;
|
|
GtkWidget *Label = g_object_get_data(G_OBJECT(iter->data),"Label");
|
|
|
|
gtk_widget_get_preferred_width(Label,NULL,&width);
|
|
gtk_widget_get_preferred_height(Label,NULL,&height);
|
|
if ((*ret_width)<width) (*ret_width) = width;
|
|
if ((*ret_height)<height) (*ret_height) = height;
|
|
}
|
|
}
|
|
|
|
void yon_main_theme_resize(main_theme_struct *theme){
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(theme->AppsTree));
|
|
GList *iter;
|
|
int max_width=0;
|
|
int max_height=0;
|
|
for (iter=list;iter;iter=iter->next){
|
|
main_section *section = g_object_get_data(G_OBJECT(iter->data),"main_section");
|
|
yon_main_section_get_max_size(section,&max_width,&max_height);
|
|
}
|
|
for (iter=list;iter;iter=iter->next){
|
|
main_section *section = g_object_get_data(G_OBJECT(iter->data),"main_section");
|
|
GList *child_list = gtk_container_get_children(GTK_CONTAINER(section->AppsList));
|
|
if (child_list){
|
|
GtkWidget *Label = g_object_get_data(G_OBJECT(child_list->data),"Label");
|
|
gtk_widget_set_size_request(Label,max_width,max_height);
|
|
}
|
|
}
|
|
}
|
|
|
|
int yon_main_update(main_theme_struct *theme){
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(theme->AppsTree));
|
|
GList *iter;
|
|
for (iter=list;iter;iter=iter->next){
|
|
gtk_widget_destroy(GTK_WIDGET(iter->data));
|
|
}
|
|
|
|
dictionary *cur;
|
|
for_dictionaries(cur,main_config.sections){
|
|
app_section *section_data = yon_dictionary_get_data(cur,app_section*);
|
|
yon_main_section_setup(theme,section_data);
|
|
}
|
|
|
|
yon_main_theme_resize(theme);
|
|
return 1;
|
|
}
|
|
|
|
main_theme_struct *yon_main_theme_new(){
|
|
main_theme_struct *theme = malloc(sizeof(main_theme_struct));
|
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_main_theme);
|
|
theme->MainBox = yon_gtk_builder_get_widget(builder,"MainBox");
|
|
theme->AppsTree = yon_gtk_builder_get_widget(builder,"AppsTree");
|
|
theme->SocketBox = yon_gtk_builder_get_widget(builder,"SocketBox");
|
|
theme->HideBox = yon_gtk_builder_get_widget(builder,"HideBox");
|
|
theme->theme_name = yon_char_new(MAIN_THEME_LABEL);
|
|
theme->Socket = NULL;
|
|
theme->list_update_func = (int(*)(struct main_theme_struct*))yon_main_update;
|
|
|
|
return theme;
|
|
}
|