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.
181 lines
8.3 KiB
181 lines
8.3 KiB
#include "controler.h"
|
|
|
|
config_u_g_p cfg_u_g_p;
|
|
config_general cfg_general;
|
|
main_window cfg_main_gui;
|
|
custom_window cfg_custom_gui;
|
|
config_settings_gui main_config;
|
|
|
|
void fill_tree_view_u_g_p(custom_window* _config_gui, config_u_g_p* _config, int start, int flag_gui_add) {
|
|
GtkTreeModel *model = GTK_TREE_MODEL(_config_gui->list);
|
|
if (flag_gui_add == 0) {
|
|
g_object_ref(_config_gui->list);
|
|
gtk_list_store_clear(_config_gui->list);
|
|
}
|
|
for (int index = start; index < _config->size; index++) {
|
|
GtkTreeIter iter;
|
|
gtk_list_store_append(_config_gui->list,&iter);
|
|
if (strcmp(_config->type_arr[index], "project") != 0) {
|
|
gtk_list_store_set(_config_gui->list,&iter,
|
|
0,_config->name[index],
|
|
1,_config->quota[index],
|
|
2,_config->files[index],
|
|
3,philos_format_cfg_str_size_memory("", _config->soft_restriction_size[index],_config->soft_restriction_size_pow[index]),
|
|
4,philos_format_cfg_str_size_memory("", _config->soft_restriction_file[index],_config->soft_restriction_file_pow[index]),
|
|
5,philos_format_cfg_str_size_memory("", _config->severe_limitation_size[index],_config->severe_limitation_size_pow[index]),
|
|
6,philos_format_cfg_str_size_memory("", _config->severe_limitation_file[index], _config->severe_limitation_file_pow[index]),
|
|
7,philos_format_cfg_str_size_memory("", _config->deferring_size[index], _config->deferring_size_pow[index]),
|
|
8,philos_format_cfg_str_size_memory("", _config->deferring_file[index], _config->deferring_file_pow[index]),
|
|
-1);
|
|
}
|
|
else {
|
|
gtk_list_store_set(_config_gui->list,&iter,
|
|
0,_config->id[index],
|
|
1,_config->name[index],
|
|
2,_config->quota[index],
|
|
3,_config->files[index],
|
|
4,philos_format_cfg_str_size_memory("", _config->soft_restriction_size[index],_config->soft_restriction_size_pow[index]),
|
|
5,philos_format_cfg_str_size_memory("", _config->soft_restriction_file[index],_config->soft_restriction_file_pow[index]),
|
|
6,philos_format_cfg_str_size_memory("", _config->severe_limitation_size[index],_config->severe_limitation_size_pow[index]),
|
|
7,philos_format_cfg_str_size_memory("", _config->severe_limitation_file[index], _config->severe_limitation_file_pow[index]),
|
|
8,philos_format_cfg_str_size_memory("", _config->deferring_size[index], _config->deferring_size_pow[index]),
|
|
9,philos_format_cfg_str_size_memory("", _config->deferring_file[index], _config->deferring_file_pow[index]),
|
|
-1);
|
|
}
|
|
}
|
|
if (flag_gui_add != 0) {
|
|
gtk_tree_view_set_model(GTK_TREE_VIEW(_config_gui->treeViewMain), model);
|
|
}
|
|
}
|
|
void fill_tree_view_u_g(custom_window* _config_gui, config_u_g_p* _config, int start,int flag_gui_add) {
|
|
GtkTreeModel *model = GTK_TREE_MODEL(_config_gui->list);
|
|
if (flag_gui_add == 0) {
|
|
g_object_ref(_config_gui->list);
|
|
gtk_list_store_clear(_config_gui->list);
|
|
}
|
|
for (int index = start; index < _config->size; index++) {
|
|
GtkTreeIter iter;
|
|
gtk_list_store_append(_config_gui->list,&iter);
|
|
if (strcmp(_config->type_arr[index], "project") != 0) { // Баг
|
|
gtk_list_store_set(_config_gui->list,&iter, -1);
|
|
}
|
|
}
|
|
if (flag_gui_add != 0) {
|
|
gtk_tree_view_set_model(GTK_TREE_VIEW(_config_gui->treeViewMain), model);
|
|
}
|
|
}
|
|
|
|
|
|
void load_system_cfg() {
|
|
cfg_u_g_p.flag_load = 0;
|
|
load_template_load_cfg(&cfg_u_g_p, CMD_LOAD_SYSTEM);
|
|
yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS_LABEL, BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
}
|
|
|
|
void load_global_cfg() {
|
|
cfg_u_g_p.flag_load = 1;
|
|
load_template_load_cfg(&cfg_u_g_p, CMD_LOAD_GLOBAL);
|
|
yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
}
|
|
|
|
void control_event(main_window* _config_main_gui, custom_window* _config_custom_gui) {
|
|
g_signal_connect(G_OBJECT(_config_main_gui->LoadLocalMenuItem), "activate", G_CALLBACK(load_system_cfg), NULL);
|
|
g_signal_connect(G_OBJECT(_config_main_gui->LoadGlobalMenuItem), "activate", G_CALLBACK(load_global_cfg), NULL);
|
|
}
|
|
|
|
int main(int argc, char *argv[]){
|
|
local=setlocale(LC_ALL, "");
|
|
textdomain (LocaleName);
|
|
config_init(&main_config);
|
|
int option_index=0;
|
|
int show_help=0;
|
|
int debug_mode=0;
|
|
{
|
|
struct option long_options[] = {
|
|
{"help", 0, 0, 'h'},
|
|
{"version", 0, 0, 'V'},
|
|
{"lock-help", 0,0, 1},
|
|
{"lock-save", 0,0, 2},
|
|
{"lock-save-local", 0,0, 3},
|
|
{"lock-save-global", 0,0, 4},
|
|
{"lock-load-global", 0,0, 5},
|
|
{"socket-id", 1, 0, 's'},
|
|
{"socket-ext-id", 1,0, 'e'},
|
|
{"socket-trd-id", 1,0, 't'},
|
|
{"debug", 0,0, 'd'},
|
|
{ NULL, 0, NULL, 0 }
|
|
};
|
|
for (int i=0;i<argc;i++){
|
|
int argument=getopt_long(argc,argv,"hVvs:e:t:d",long_options,&option_index);
|
|
switch(argument){
|
|
case 'h':
|
|
show_help=1;
|
|
break;
|
|
case 'v':
|
|
case 'V':
|
|
printf("%s\n",VERSION_LABEL);
|
|
exit(0);
|
|
break;
|
|
case 's':
|
|
if(optarg)
|
|
main_config.socket_id=atoi(optarg);
|
|
break;
|
|
case 'e':
|
|
if(optarg)
|
|
main_config.load_socket_id=atoi(optarg);
|
|
break;
|
|
case 't':
|
|
if(optarg)
|
|
main_config.save_socket_id=atoi(optarg);
|
|
break;
|
|
case 1:
|
|
main_config.lock_help=1;
|
|
break;
|
|
case 2:
|
|
main_config.lock_save_local=1;
|
|
main_config.lock_save_global=1;
|
|
break;
|
|
case 3:
|
|
main_config.lock_save_local=1;
|
|
break;
|
|
case 4:
|
|
main_config.lock_save_global=1;
|
|
break;
|
|
case 5:
|
|
main_config.lock_load_global=1;
|
|
break;
|
|
}
|
|
}
|
|
if (show_help==1&&main_config.lock_help!=1){
|
|
printf("%s\n",HELP_LABEL);
|
|
exit(0);
|
|
}
|
|
}
|
|
|
|
if (getuid()!=0){
|
|
main_config.lock_load_global=1;
|
|
main_config.lock_save_global=1;
|
|
main_config.lock_save_local=1;
|
|
}
|
|
gtk_init(&argc,&argv);
|
|
|
|
|
|
main_window *widgets = setup_window(&cfg_main_gui);
|
|
control_event(widgets, &cfg_custom_gui);
|
|
yon_ubl_header_setup_resource(widgets->HeadOverlay,widgets->HeadBox,widgets->HeadImage,banner_path);
|
|
|
|
yon_ubl_status_box_setup(widgets->StatusIcon,widgets->StatusBox,widgets->StatusLabel);
|
|
if (getuid()!=0)
|
|
yon_ubl_status_box_render(ROOT_WARNING_LABEL,BACKGROUND_IMAGE_FAIL_TYPE);
|
|
else
|
|
yon_ubl_status_box_render(TITLE_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE);
|
|
yon_ubl_setup_sockets(widgets->PlugBox,widgets->LeftBox,widgets->RightBox,main_config.socket_id,main_config.load_socket_id,main_config.save_socket_id);
|
|
yon_window_config_setup(GTK_WINDOW(widgets->Window));
|
|
yon_window_config_load(config_path);
|
|
GtkCssProvider *css=gtk_css_provider_new();
|
|
gtk_css_provider_load_from_resource(css,CssPath);
|
|
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
|
|
GTK_STYLE_PROVIDER(css),
|
|
-1);
|
|
gtk_main();
|
|
} |