Library updates WIP

pull/43/head
parent a52f8ecc16
commit a444724495

@ -9,6 +9,7 @@
<file>libublsettingsui-gtk3-filechooser.glade</file>
<file>libublsettingsui-gtk3-config-window.glade</file>
<file>libublsettingsui-gtk3-service-control.glade</file>
<file>libublsettingsui-gtk3-app-chooser.glade</file>
</gresource>
<gresource prefix="/com/ublinux/css">
<file>libublsettingsui-gtk3.css</file>

@ -0,0 +1,223 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">com.ublinux.libublsettingsui-gtk3.accept-symbolic</property>
</object>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">com.ublinux.libublsettingsui-gtk3.cancel-uncolored-symbolic</property>
</object>
<object class="GtkListStore" id="liststore1"/>
<object class="GtkTreeStore" id="treestore1">
<columns>
<!-- column-name Selected -->
<column type="gboolean"/>
<!-- column-name RenderText -->
<column type="gchararray"/>
<!-- column-name Description -->
<column type="gchararray"/>
<!-- column-name SectionTags -->
<column type="gchararray"/>
<!-- column-name IsSection -->
<column type="gboolean"/>
<!-- column-name Icon -->
<column type="gchararray"/>
<!-- column-name Exec -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkWindow" id="MainWindow">
<property name="width-request">225</property>
<property name="height-request">450</property>
<property name="can-focus">False</property>
<property name="modal">True</property>
<property name="icon-name">com.ublinux.ubl-settings-video</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkBox" id="StatusBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">5</property>
<property name="margin-end">5</property>
<property name="margin-bottom">5</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkCheckButton" id="RenderModeCheck">
<property name="label" translatable="yes">checkbutton</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkTreeView" id="MainTree">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">treestore1</property>
<property name="headers-visible">False</property>
<property name="search-column">1</property>
<property name="tooltip-column">2</property>
<property name="activate-on-single-click">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn">
<child>
<object class="GtkCellRendererToggle" id="SelectionCell"/>
<attributes>
<attribute name="active">0</attribute>
</attributes>
</child>
<child>
<object class="GtkCellRendererPixbuf">
<property name="stock_size">4</property>
</object>
<attributes>
<attribute name="icon-name">5</attribute>
</attributes>
</child>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkIconView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="margin">6</property>
<property name="model">liststore1</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar" id="SettingsBar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="show-close-button">True</property>
<child type="title">
<object class="GtkLabel" id="HeadLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Choose application</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
<child>
<object class="GtkImage" id="WindowIcon">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="pixel-size">32</property>
<property name="icon-name">com.ublinux.libublsettingsui-gtk3</property>
</object>
</child>
<child>
<object class="GtkButton" id="CancelButton">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image2</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="AcceptButton">
<property name="label" translatable="yes">Accept</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image1</property>
</object>
<packing>
<property name="pack-type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

@ -63,6 +63,7 @@
<object class="GtkBox" id="StatusBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-end">5</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>

@ -45,6 +45,7 @@ set(DEPENDFILES
../libublsettingsui-gtk3-debugger.glade
../libublsettingsui-gtk3-config-window.glade
../libublsettingsui-gtk3-service-control.glade
../libublsettingsui-gtk3-app-chooser.glade
../gresource.xml
../libublsettingsui-gtk3-banner.png
../libublsettingsui-gtk3.css
@ -83,6 +84,7 @@ add_library(${PROJECT_NAME} SHARED
libublsettingsui-gtk3-config-window.c
libublsettingsui-gtk3-filechooser.c
libublsettingsui-gtk3-service.c
libublsettingsui-gtk3-app-chooser.c
libublsettingsui-gtk3.h
${CMAKE_CURRENT_BINARY_DIR}/${GRESOURCE_C})

@ -1,28 +1,9 @@
#include "libublsettingsui-gtk3.h"
typedef struct {
GtkWidget *MainWindow;
GtkWidget *StatusBox;
GtkWidget *HeadLabel;
GtkWidget *WindowImage;
GtkWidget *CancelButton;
GtkWidget *AcceptButton;
GtkWidget *MainTree;
GtkCellRenderer *SelectionCell;
GtkTreeStore *treestore;
GtkWidget *MainIconView;
GtkListStore *liststore;
int apps_size;
config_str apps;
dictionary *apps_convert;
int multiple;
} yon_app_chooser_window;
struct return_struct {
config_str chosen_apps;
int size;
};
struct application {
char *name;
@ -43,8 +24,8 @@ config_str yon_apps_get_from_file(char *file,int *final_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]);
yon_char_parsed_add_or_create_if_exists(final,&final_size,path);
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);
@ -63,21 +44,30 @@ int yon_apps_get(yon_app_chooser_window *window){
// 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/shared/applications",&window->apps_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){
if (gtk_widget_get_visible(window->MainWindow)){
if (!window->visible_allowed)
gtk_widget_set_visible(window->MainWindow,0);
else g_signal_handlers_block_by_func(G_OBJECT(window->MainWindow),yon_block_visibility_if_unallowed,window);
}
}
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)){
struct application *app = new(struct application);
app->name = g_key_file_get_string(file,"[Desktop Entry]","Name",NULL);
app->description = g_key_file_get_string(file,"[Desktop Entry]","Comment",NULL);
app->tags = g_key_file_get_string(file,"[Desktop Entry]","Categories",NULL);
app->execute = g_key_file_get_string(file,"[Desktop Entry]","Exec",NULL);
app->icon = g_key_file_get_string(file,"[Desktop Entry]","Icon",NULL);
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 = g_key_file_get_string(file,"Desktop Entry","Exec",NULL);
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);
}
@ -85,26 +75,81 @@ int yon_app_chooser_convert_apps(yon_app_chooser_window *window){
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,itar;
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){
gtk_widget_show(window->MainWindow);
gtk_main();
config_str final = window->final->chosen_apps;
(*size)=window->final->size;
free(window);
return final;
}
void on_app_selection_toggled(GtkWidget *, char *path, yon_app_chooser_window *window){
GtkTreeIter iter;
int status;
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(window->treestore),&iter,path);
gtk_tree_model_get(GTK_TREE_MODEL(window->treestore),&iter,0,&status,-1);
gtk_tree_store_set(window->treestore,&iter,0,!status,-1);
}
void on_app_chooser_window_closed(GtkWidget *, yon_app_chooser_window *window){
gtk_main_quit();
}
void on_app_chooser_accept(GtkWidget *, yon_app_chooser_window *window){
GtkTreeIter iter;
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);
if (window->multiple){
for_iter(model,&iter){
int status;
char *name;
gtk_tree_model_get(GTK_TREE_MODEL(window->treestore),&iter,0,&status,1,&name,-1);
if (status){
yon_char_parsed_add_or_create_if_exists(window->final->chosen_apps,&window->final->size,name);
}
}
} else {
if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(window->MainTree)),&model,&iter)){
char *name;
gtk_tree_model_get(GTK_TREE_MODEL(window->treestore),&iter,1,&name,-1);
yon_char_parsed_add_or_create_if_exists(window->final->chosen_apps,&window->final->size,name);
}
}
gtk_widget_destroy(window->MainWindow);
}
yon_app_chooser_window *yon_app_chooser_window_new(int multiple_choise){
@ -119,22 +164,32 @@ yon_app_chooser_window *yon_app_chooser_window_new(int multiple_choise){
window->AcceptButton = yon_gtk_builder_get_widget(builder,"AcceptButton");
window->MainTree = yon_gtk_builder_get_widget(builder,"MainTree");
window->SelectionCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"MainWindow"));
window->treestore = GTK_TREE_STORE(gtk_builder_get_object(builder,"MainWindow"));
window->SelectionCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"SelectionCell"));
window->treestore = GTK_TREE_STORE(gtk_builder_get_object(builder,"treestore1"));
window->MainIconView = yon_gtk_builder_get_widget(builder,"MainIconView");
window->liststore = GTK_LIST_STORE(gtk_builder_get_object(builder,"MainWindow"));
window->liststore = GTK_LIST_STORE(gtk_builder_get_object(builder,"liststore1"));
window->visible_allowed=0;
window->final = new(struct return_struct);
memset(window->final,0,sizeof(struct return_struct));
g_signal_connect(G_OBJECT(window->MainWindow),"notify::visibile",G_CALLBACK(yon_block_visibility_if_unallowed),window);
g_signal_connect(G_OBJECT(window->MainWindow),"destroy",G_CALLBACK(on_app_chooser_window_closed),window);
g_signal_connect(G_OBJECT(window->CancelButton),"clicked",G_CALLBACK(on_subwindow_close),NULL);
g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(on_app_chooser_accept),window);
g_signal_connect(G_OBJECT(window->SelectionCell),"toggled",G_CALLBACK(on_app_selection_toggled),window);
if (!window->multiple){
gtk_cell_renderer_set_visible(GTK_CELL_RENDERER(window->SelectionCell),0);
}
window->multiple = multiple_choise;
if (!yon_apps_get(window)) return NULL;
if (!yon_app_chooser_convert_apps(window)) return NULL;
yon_tree_store_setup_apps(window);
return window;
}

@ -0,0 +1,57 @@
#include "libublsettingsui-gtk3.h"
char *config_get_default_command = NULL;
char *config_get_global_command = NULL;
char *config_get_local_command = NULL;
void yon_load_proceed(YON_CONFIG_TYPE type){
yon_config_clean();
if (!yon_char_is_empty(config_get_default_command))
yon_config_load_config(YON_CONFIG_DEFAULT,config_get_default_command,NULL);
if (type==YON_CONFIG_GLOBAL){
yon_config_load_config(type,config_get_global_command,NULL);
} else if (type==YON_CONFIG_LOCAL){
yon_config_load_config(type,config_get_local_command,NULL);
} else if (type==YON_CONFIG_CUSTOM){
char *path="";
GtkWidget *dialog = gtk_file_chooser_dialog_new(template_app_information.app_title,NULL,GTK_FILE_CHOOSER_ACTION_SAVE,
yon_char_get_localised_from_lib(CANCEL_LABEL),GTK_RESPONSE_CANCEL,
yon_char_get_localised_from_lib(OPEN_LABEL),GTK_RESPONSE_ACCEPT,NULL);
yon_gtk_window_setup(GTK_WINDOW(dialog),NULL,template_app_information.app_title,yon_char_append("com.ublinux.",template_app_information.app_tech_name),"FileChooserWindow");
gtk_window_set_icon_name(GTK_WINDOW(dialog),"com.ublinux.ubl-settings-video");
gtk_window_set_title(GTK_WINDOW(dialog),template_app_information.app_title);
GtkFileFilter *filter = gtk_file_filter_new();
gtk_file_filter_add_pattern(filter,"*.ini");
gtk_file_filter_set_name(filter, "*.ini");
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter);
gtk_widget_show(dialog);
int response = gtk_dialog_run(GTK_DIALOG(dialog));
if (response == GTK_RESPONSE_ACCEPT){
char *file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
if (!yon_char_is_empty(file)){
path=yon_char_unite("'",file,"'",NULL);
free(file);
}
gtk_widget_destroy(dialog);
} else {
gtk_widget_destroy(dialog);
}
yon_config_load_config(type,yon_config_get_custom_command(path),NULL);
}
}
void on_config_local_load(){
yon_load_proceed(YON_CONFIG_LOCAL);
}
void on_config_global_load(){
yon_load_proceed(YON_CONFIG_GLOBAL);
}
void on_config_custom_load(){
yon_load_proceed(YON_CONFIG_CUSTOM);
}
void on_config_global_local_save(){
yon_save_proceed(NULL,YON_CONFIG_BOTH,config_get_global_command,NULL);
}

@ -27,6 +27,7 @@
#define ui_glade_path_filechooser "/com/ublinux/ui/libublsettingsui-gtk3-filechooser.glade"
#define ui_glade_path_debug "/com/ublinux/ui/libublsettingsui-gtk3-debugger.glade"
#define ui_glade_path_service "/com/ublinux/ui/libublsettingsui-gtk3-service-control.glade"
#define ui_glade_path_app_chooser "/com/ublinux/ui/libublsettingsui-gtk3-app-chooser.glade"
#define ui_banner_path "/com/ublinux/images/libublsettingsui-gtk3-banner.png"
#define ui_CssPath "/com/ublinux/css/libublsettingsui-gtk3.css"
#define ui_config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",template_app_information.app_tech_name,"/",template_app_information.app_tech_name,".conf",NULL)
@ -331,12 +332,42 @@ typedef struct {
char *check_enable_command;
} service_window;
typedef struct {
GtkWidget *MainWindow;
GtkWidget *StatusBox;
GtkWidget *HeadLabel;
GtkWidget *WindowImage;
GtkWidget *CancelButton;
GtkWidget *AcceptButton;
GtkWidget *MainTree;
GtkCellRenderer *SelectionCell;
GtkTreeStore *treestore;
GtkWidget *MainIconView;
GtkListStore *liststore;
int apps_size;
config_str apps;
dictionary *apps_convert;
struct return_struct *final;
int multiple;
int visible_allowed;
} yon_app_chooser_window;
service_window *yon_service_window_new(char *name, char *start_command,
char *stop_command, char *enable_command,
char *disable_command, char *info_command,
char *check_active_command, char *check_enable_command);
void yon_service_window_run(service_window *window);
config_str yon_app_chooser_window_run(yon_app_chooser_window *window, int *size);
yon_app_chooser_window *yon_app_chooser_window_new(int multiple_choise);
#define VERSION_LABEL yon_char_unite(_("Version:")," ",!yon_char_is_empty(template_app_information.app_version)?template_app_information.app_version:"","\n",NULL)
#define HELP_LABEL(rest) yon_char_unite(template_app_information.app_tech_name,_(" version:")," ", !yon_char_is_empty(template_app_information.app_version)?template_app_information.app_version:"","\n",\
template_app_information.app_title,"\n",_("Usage:"), " ",template_app_information.app_tech_name," ",_("[OPTIONS]"),"\n",\

Loading…
Cancel
Save