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.
187 lines
8.5 KiB
187 lines
8.5 KiB
#include "ubl-settings-manager.h"
|
|
|
|
typedef struct {
|
|
GtkWidget *expander;
|
|
GtkWidget *AppsList;
|
|
app_section *section;
|
|
} gnome_section;
|
|
|
|
gnome_section *yon_gnome_section_new();
|
|
void yon_gnome_section_setup_apps(gnome_section *cur_section, const char *target);
|
|
void yon_gnome_section_search_show(gnome_section *section, const char *string);
|
|
|
|
void on_gnome_plug_connected(GtkWidget *,gnome_theme_struct *theme){
|
|
gtk_widget_show(theme->SocketBox);
|
|
gtk_widget_hide(theme->HideBox);
|
|
}
|
|
|
|
void on_gnome_plug_disconnected(GtkWidget *,gnome_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_gnome_activate(GtkWidget *,GtkListBoxRow *self, gnome_theme_struct *theme);
|
|
void on_gnome_activate(GtkWidget *,GtkListBoxRow *self, gnome_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_gnome_plug_connected),theme);
|
|
g_signal_connect(G_OBJECT(theme->Socket),"destroy",G_CALLBACK(on_gnome_plug_disconnected),theme);
|
|
apps *cur_app = g_object_get_data(G_OBJECT(self),"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_gnome_selected(GtkWidget *self_list,GtkListBoxRow *, gnome_theme_struct *theme);
|
|
void on_gnome_selected(GtkWidget *self_list,GtkListBoxRow *, gnome_theme_struct *theme){
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(theme->AppsTree));
|
|
GList *iter;
|
|
for (iter=list;iter;iter=iter->next){
|
|
gnome_section *cur_section = g_object_get_data(G_OBJECT(iter->data),"gnome_section");
|
|
if (cur_section->AppsList != self_list){
|
|
g_signal_handlers_block_by_func(G_OBJECT(cur_section->AppsList),G_CALLBACK(on_gnome_selected),theme);
|
|
gtk_list_box_unselect_all(GTK_LIST_BOX(cur_section->AppsList));
|
|
g_signal_handlers_unblock_by_func(G_OBJECT(cur_section->AppsList),G_CALLBACK(on_gnome_selected),theme);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
gnome_section *yon_gnome_section_new(){
|
|
gnome_section *cur_section = malloc(sizeof(gnome_section));
|
|
memset(cur_section,0,sizeof(gnome_section));
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_gnome_section);
|
|
cur_section->expander = yon_gtk_builder_get_widget(builder,"MainExpander");
|
|
cur_section->AppsList = yon_gtk_builder_get_widget(builder,"AppsList");
|
|
int doubleclick=0;
|
|
if (!yon_window_config_get_parameter(settings_section,double_click_parameter,&doubleclick,YON_TYPE_BOOLEAN)){
|
|
gtk_list_box_set_activate_on_single_click(GTK_LIST_BOX(cur_section->AppsList),1);
|
|
|
|
} else {
|
|
gtk_list_box_set_activate_on_single_click(GTK_LIST_BOX(cur_section->AppsList),!doubleclick);
|
|
}
|
|
return cur_section;
|
|
}
|
|
|
|
void yon_gnome_section_setup_apps(gnome_section *cur_section, const char *target){
|
|
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));
|
|
|
|
}
|
|
GtkWidget *Label = gtk_label_new(cur_app->Name);
|
|
GtkWidget *Row = gtk_list_box_row_new();
|
|
GtkWidget *Box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(Row),Box);
|
|
gtk_box_pack_start(GTK_BOX(Box),Image,0,0,0);
|
|
gtk_box_pack_start(GTK_BOX(Box),Label,0,0,0);
|
|
gtk_label_set_xalign(GTK_LABEL(Label),0);
|
|
gtk_label_set_line_wrap(GTK_LABEL(Label),1);
|
|
gtk_label_set_line_wrap_mode(GTK_LABEL(Label),PANGO_WRAP_WORD);
|
|
gtk_list_box_insert(GTK_LIST_BOX(cur_section->AppsList),Row,-1);
|
|
|
|
g_object_set_data(G_OBJECT(Row),"gnome_section",cur_section);
|
|
g_object_set_data(G_OBJECT(Row),"apps",cur_app);
|
|
|
|
gtk_widget_show_all(Row);
|
|
}
|
|
|
|
void yon_gnome_section_setup(gnome_theme_struct *theme,app_section *section){
|
|
gnome_section *cur_section = yon_gnome_section_new();
|
|
cur_section->section = section;
|
|
gtk_expander_set_label(GTK_EXPANDER(cur_section->expander),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_gnome_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),"gnome_section",cur_section);
|
|
g_signal_connect(G_OBJECT(cur_section->AppsList),"row-activated",G_CALLBACK(on_gnome_activate),theme);
|
|
g_signal_connect(G_OBJECT(cur_section->AppsList),"row-selected",G_CALLBACK(on_gnome_selected),theme);
|
|
}
|
|
|
|
int yon_gnome_update(gnome_theme_struct *theme){
|
|
if (!main_config.sections) return 0;
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(theme->AppsTree));
|
|
GList *iter;
|
|
for (iter=list;iter;iter=iter->next){
|
|
gnome_section *cur_section = g_object_get_data(G_OBJECT(iter->data),"gnome_section");
|
|
gtk_widget_destroy(cur_section->expander);
|
|
free(cur_section);
|
|
}
|
|
|
|
dictionary *cur;
|
|
for_dictionaries(cur,main_config.sections){
|
|
app_section *section_data = yon_dictionary_get_data(cur,app_section*);
|
|
yon_gnome_section_setup(theme,section_data);
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
void yon_gnome_section_search_show(gnome_section *section, const char *string){
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(section->AppsList));
|
|
GList *iter;
|
|
for (iter=list;iter;iter=iter->next){
|
|
apps *cur_app = g_object_get_data(G_OBJECT(iter->data),"apps");
|
|
if (yon_char_is_empty(string)||yon_char_check_begins_with(cur_app->keywords,(char*)string)){
|
|
gtk_widget_show(GTK_WIDGET(iter->data));
|
|
} else {
|
|
gtk_widget_hide(GTK_WIDGET(iter->data));
|
|
}
|
|
}
|
|
g_list_free(list);
|
|
}
|
|
|
|
void on_gnome_search(GtkWidget *, gnome_theme_struct *theme){
|
|
const char *search_string = gtk_entry_get_text(GTK_ENTRY(theme->SearchEntry));
|
|
GList *list = gtk_container_get_children(GTK_CONTAINER(theme->AppsTree));
|
|
GList *iter;
|
|
for (iter=list;iter;iter=iter->next){
|
|
gnome_section *cur_section = g_object_get_data(G_OBJECT(iter->data),"gnome_section");
|
|
yon_gnome_section_search_show(cur_section,search_string);
|
|
}
|
|
g_list_free(list);
|
|
}
|
|
|
|
gnome_theme_struct *yon_gnome_theme_new(){
|
|
gnome_theme_struct *theme = malloc(sizeof(gnome_theme_struct));
|
|
|
|
GtkBuilder *builder = gtk_builder_new_from_resource(glade_path_gnome_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->GnomePaned = yon_gtk_builder_get_widget(builder,"GnomePaned");
|
|
theme->SearchEntry = yon_gtk_builder_get_widget(builder,"SearchEntry");
|
|
theme->GnomeInfoLogoImage = yon_gtk_builder_get_widget(builder,"GnomeInfoLogoImage");
|
|
theme->HideBox = yon_gtk_builder_get_widget(builder,"HideBox");
|
|
theme->IconCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"IconCell"));
|
|
theme->theme_name = yon_char_new(GNOME_THEME_LABEL);
|
|
theme->Socket = gtk_socket_new();
|
|
theme->list_update_func = (int(*)(struct gnome_theme_struct*))yon_gnome_update;
|
|
|
|
gtk_box_pack_start(GTK_BOX(theme->SocketBox),theme->Socket,1,1,0);
|
|
gtk_widget_show(theme->Socket);
|
|
|
|
g_signal_connect(G_OBJECT(theme->SearchEntry),"changed",G_CALLBACK(on_gnome_search),theme);
|
|
// gtk_cell_renderer_set_fixed_size(theme->IconCell,main_config.apps_icon_size,main_config.apps_icon_size);
|
|
return theme;
|
|
}
|