diff --git a/source/libublsettingsui-gtk3.c b/source/libublsettingsui-gtk3.c index 405a3a6..2304c49 100644 --- a/source/libublsettingsui-gtk3.c +++ b/source/libublsettingsui-gtk3.c @@ -587,6 +587,91 @@ int yon_ubl_window_init(char *app_title, char *app_description, char *locale, ch template_app_information.app_locale=locale; } +int yon_ubl_setup_arguments(int argc, char *argv[],config_str *unfound_arguments, int *arguments_size, char *additional_options_output){ + (*arguments_size)=0; + 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}, + {"lock-load-local", 0,0, 6}, + {"socket-id", 1, 0, 's'}, + {"socket-ext-id", 1,0, 'e'}, + {"socket-trd-id", 1,0, 't'}, + {"clear-config", 0,0, 'c'}, + { NULL, 0, NULL, 0 } + }; + config_str unregistered_arguments=NULL; + for (int i=1;isocket_id=atoi(optarg); + break; + case 'e': + if(optarg) + template_config->save_socket_id=atoi(optarg); + break; + case 't': + if(optarg) + template_config->load_socket_id=atoi(optarg); + break; + case 'c': if (system(remove_config_dir_command)){}; + break; + case 1: + template_config->lock_help=1; + break; + case 2: + template_config->lock_save_local=1; + template_config->lock_save_global=1; + break; + case 3: + template_config->lock_save_local=1; + break; + case 4: + template_config->lock_save_global=1; + break; + case 5: + template_config->lock_load_global=1; + break; + case 6: + template_config->lock_load_global=1; + break; + default: + char *unfound = optarg; + yon_char_parsed_add_or_create_if_exists(unregistered_arguments,arguments_size,yon_char_unite(argv[i],!yon_char_is_empty(unfound)?"=":"",!yon_char_is_empty(unfound)?unfound:"",NULL)); + } + } + (*unfound_arguments)=unregistered_arguments; + if (show_help&&!template_config->lock_help){ + printf("%s\n",HELP_LABEL(additional_options_output)); + exit(0); + } + } + + if (getuid()!=0){ + template_config->lock_load_global=1; + template_config->lock_save_global=1; + template_config->lock_save_local=1; + } +} + template_main_window *yon_ubl_window_setup(){ textdomain (template_ui_LocaleName); setlocale(LC_ALL,""); diff --git a/source/libublsettingsui-gtk3.h b/source/libublsettingsui-gtk3.h index c223ff1..86b8f45 100644 --- a/source/libublsettingsui-gtk3.h +++ b/source/libublsettingsui-gtk3.h @@ -24,7 +24,12 @@ #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) +#define remove_config_dir_command yon_char_unite("rm -rfd ", yon_ubl_user_get_home_directory(),"/.config/",template_app_information.app_tech_name,"/",NULL) + #ifndef UBL_UI + #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",_("Options:"),"\n\t--help, -h\t\t\t",_("Show this help"),"\n\t--version, -V\t\t\t",_("Show package version"),"\n\t--lock-help\t\t\t",_("Lock this help menu"),"\n\t--lock-save\t\t\t",_("Lock configuration saving"),"\n\t--lock-save-local\t\t",_("Lock local configration saving"),"\n\t--lock-save-global\t\t",_("Lock global configration saving"),"\n\t--lock-load-global\t\t",_("Lock global configration loading"),"\n\t--clear-config\t\t\t",_("Reset application settings"),"\n",!yon_char_is_empty(rest)?rest:NULL,NULL) + #define template_ui_LocalePath "/usr/share/locale" #define template_ui_LocaleName "libublsettingsui-gtk3" @@ -125,6 +130,7 @@ typedef struct { int lock_save_local; int lock_save_global; int lock_load_global; + int lock_load_system; int load_mode; @@ -263,4 +269,6 @@ void on_open_documentation_confirmation(GtkWidget *self, char *link); * [RU] * Закрывает окно, в котором расположен виджет [self]. */ -void on_subwindow_close(GtkWidget *self); \ No newline at end of file +void on_subwindow_close(GtkWidget *self); + +int yon_ubl_setup_arguments(int argc, char *argv[],config_str *unfound_arguments, int *arguments_size, char *additional_options_output); \ No newline at end of file