diff --git a/gresource.xml b/gresource.xml index 02e88c1..a172326 100644 --- a/gresource.xml +++ b/gresource.xml @@ -2,6 +2,7 @@ ubl-settings-system.glade + ubl-settings-system-layouts.glade ubl-settings-system.css diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 865fcbb..f2d6ea4 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -36,6 +36,7 @@ add_custom_target(GLADE ubl-settings-system.glade) set(DEPENDFILES ../ubl-settings-system.glade + ../ubl-settings-system-layouts.glade ../gresource.xml ../ubl-settings-system-banner.png ../ubl-settings-system.css diff --git a/source/ubl-settings-system.c b/source/ubl-settings-system.c index 86422f3..ca41b3c 100644 --- a/source/ubl-settings-system.c +++ b/source/ubl-settings-system.c @@ -103,30 +103,39 @@ void on_about(){ //functions void yon_load_proceed(YON_CONFIG_TYPE type){ - if (yon_config_load_register(type,"config",hostname_parameter,"config",id_parameter,"locale",console_font_parameter,"locale",language_parameter,NULL)) - yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); + if (yon_config_load_register(type,hostname_section,hostname_parameter,id_section,id_parameter,console_font_section,console_font_parameter,locale_section,locale_parameter,language_section,language_parameter,NULL)){} else yon_ubl_status_box_render(LOAD_FAILED_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); } void yon_config_local_load(GtkWidget *self, main_window *widgets){ + g_signal_handlers_block_by_func(G_OBJECT(widgets->IDEntry),G_CALLBACK(on_id_changed),widgets); gtk_entry_set_text(GTK_ENTRY(widgets->HostnameEntry),""); gtk_entry_set_text(GTK_ENTRY(widgets->IDEntry),""); - gtk_entry_set_text(GTK_ENTRY(widgets->IDEntry),""); + gtk_entry_set_text(GTK_ENTRY(widgets->LocaleEntry),DEFAULT_LABEL); + int size; + GtkTreeIter iter; + config_str rtn = yon_config_load(get_id_command,&size); + rtn[0]=yon_char_divide_search(rtn[0],"\n",-1); + gtk_entry_set_text(GTK_ENTRY(widgets->IDEntry),*rtn); gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->ConsoleFontCombo),0); gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->LanguageCombo),0); yon_load_proceed(YON_CONFIG_LOCAL); gtk_entry_set_text(GTK_ENTRY(widgets->HostnameEntry),yon_config_get_by_key(hostname_parameter)); + for_iter(GTK_TREE_MODEL(widgets->languagelist),&iter){ + gtk_list_store_set(widgets->languagelist,&iter,2,0,-1); + } char *id = yon_config_get_by_key(id_parameter); - if (!strcmp(id,"Random")) + if (!strcmp(id,"random")) gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->IDCombo),1); else if (!strcmp(id,"hardware")) gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->IDCombo),2); - else + else { gtk_entry_set_text(GTK_ENTRY(widgets->IDEntry),id); + gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->IDCombo),3); + } - GtkTreeIter iter; char *code; char *cons_font = yon_config_get_by_key(console_font_parameter); if (cons_font){ @@ -137,75 +146,170 @@ void yon_config_local_load(GtkWidget *self, main_window *widgets){ } } char *lang = yon_config_get_by_key(language_parameter); + char *avlocale = yon_config_get_by_key(locale_parameter); + int locsize; + if (avlocale); + config_str locale_parsed = yon_char_parse(avlocale,&locsize,","); + gboolean is_active; + char *locale_string=""; + char *loc_name; if (lang){ int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(widgets->languagelist),&iter); for(;valid;valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(widgets->languagelist),&iter)){ - gtk_tree_model_get(GTK_TREE_MODEL(widgets->languagelist),&iter,1,&code,-1); + gtk_tree_model_get(GTK_TREE_MODEL(widgets->languagelist),&iter,0,&loc_name,1,&code,2,&is_active,-1); if (code&&!strcmp(code,lang)) gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widgets->LanguageCombo),&iter); + if (avlocale) + for (int i=0;ilanguagelist,&iter,2,1,-1); + locale_string = yon_char_unite(strcmp(locale_string,"") ? yon_char_append(locale_string,"; ") : locale_string, loc_name,NULL); + } } + if (strcmp(locale_string,"")) gtk_entry_set_text(GTK_ENTRY(widgets->LocaleEntry),locale_string); } - + g_signal_handlers_unblock_by_func(G_OBJECT(widgets->IDEntry),G_CALLBACK(on_id_changed),widgets); + if (getuid()==0) + yon_ubl_status_box_render(LOCAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); } void yon_config_global_load(GtkWidget *self, main_window *widgets){ + g_signal_handlers_block_by_func(G_OBJECT(widgets->IDEntry),G_CALLBACK(on_id_changed),widgets); gtk_entry_set_text(GTK_ENTRY(widgets->HostnameEntry),""); gtk_entry_set_text(GTK_ENTRY(widgets->IDEntry),""); - gtk_entry_set_text(GTK_ENTRY(widgets->IDEntry),""); + gtk_entry_set_text(GTK_ENTRY(widgets->LocaleEntry),DEFAULT_LABEL); + int size; + GtkTreeIter iter; + config_str rtn = yon_config_load(get_id_command,&size); + rtn[0]=yon_char_divide_search(rtn[0],"\n",-1); + gtk_entry_set_text(GTK_ENTRY(widgets->IDEntry),*rtn); gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->ConsoleFontCombo),0); gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->LanguageCombo),0); yon_load_proceed(YON_CONFIG_GLOBAL); gtk_entry_set_text(GTK_ENTRY(widgets->HostnameEntry),yon_config_get_by_key(hostname_parameter)); + for_iter(GTK_TREE_MODEL(widgets->languagelist),&iter){ + gtk_list_store_set(widgets->languagelist,&iter,2,0,-1); + } char *id = yon_config_get_by_key(id_parameter); - if (!strcmp(id,"Random")) + if (!strcmp(id,"random")) gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->IDCombo),1); else if (!strcmp(id,"hardware")) gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->IDCombo),2); - else + else{ gtk_entry_set_text(GTK_ENTRY(widgets->IDEntry),id); + gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->IDCombo),3); + } - GtkTreeIter iter; char *code; char *cons_font = yon_config_get_by_key(console_font_parameter); if (cons_font){ int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(widgets->fontlist),&iter); - for(;valid;gtk_tree_model_iter_next(GTK_TREE_MODEL(widgets->fontlist),&iter)){ - gtk_tree_model_get(GTK_TREE_MODEL(widgets->fontlist),&iter,1,&code,-1); - if (code&&!strcmp(code,cons_font)){ gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widgets->ConsoleFontCombo),&iter); break; } - else { gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->ConsoleFontCombo),0); } + for(;valid;valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(widgets->fontlist),&iter)){ + gtk_tree_model_get(GTK_TREE_MODEL(widgets->fontlist),&iter,0,&code,-1); + if (code&&!strcmp(code,cons_font)) gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widgets->ConsoleFontCombo),&iter); } } char *lang = yon_config_get_by_key(language_parameter); + char *avlocale = yon_config_get_by_key(locale_parameter); + int locsize; + if (avlocale); + config_str locale_parsed = yon_char_parse(avlocale,&locsize,","); + gboolean is_active; + char *locale_string=""; + char *loc_name; if (lang){ int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(widgets->languagelist),&iter); for(;valid;valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(widgets->languagelist),&iter)){ - gtk_tree_model_get(GTK_TREE_MODEL(widgets->languagelist),&iter,1,&code,-1); - if (!strcmp(code,lang)){ gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widgets->LanguageCombo),&iter); break; } - else { gtk_combo_box_set_active(GTK_COMBO_BOX(widgets->LanguageCombo),0); } + gtk_tree_model_get(GTK_TREE_MODEL(widgets->languagelist),&iter,0,&loc_name,1,&code,2,&is_active,-1); + if (code&&!strcmp(code,lang)) gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widgets->LanguageCombo),&iter); + if (avlocale) + for (int i=0;ilanguagelist,&iter,2,1,-1); + locale_string = yon_char_unite(strcmp(locale_string,"") ? yon_char_append(locale_string,"; ") : locale_string, loc_name,NULL); + } } + if (strcmp(locale_string,"")) gtk_entry_set_text(GTK_ENTRY(widgets->LocaleEntry),locale_string); } - + g_signal_handlers_unblock_by_func(G_OBJECT(widgets->IDEntry),G_CALLBACK(on_id_changed),widgets); + if (getuid()==0) + yon_ubl_status_box_render(GLOBAL_LOAD_SUCCESS_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); } void yon_config_global_local_save(){ - yon_config_save_registered(NULL,""); + yon_config_save_registered(NULL); + yon_ubl_status_box_render(yon_char_unite(GLOBAL_LOCAL_SAVE_SUCCESS_LABEL,"\n", SAVE_WARNING_LABEL,NULL),BACKGROUND_IMAGE_SUCCESS_TYPE); } void yon_config_local_save(){ - yon_config_save_registered("system","config"); + yon_config_save_registered("system"); + yon_ubl_status_box_render(yon_char_unite(LOCAL_SAVE_SUCCESS_LABEL,"\n", SAVE_WARNING_LABEL,NULL),BACKGROUND_IMAGE_SUCCESS_TYPE); } void yon_config_global_save(){ - yon_config_save_registered("global",""); + yon_config_save_registered("global"); + yon_ubl_status_box_render(yon_char_unite(GLOBAL_SAVE_SUCCESS_LABEL,"\n", SAVE_WARNING_LABEL,NULL),BACKGROUND_IMAGE_SUCCESS_TYPE); } +void on_locale_toggle(GtkCellRendererToggle *self,GtkTreePath* path,GtkTreeViewColumn* column,locals_window *window){ + GtkTreeIter iter; + GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(window->MainTree)); + gtk_tree_model_get_iter(model,&iter,path); + gboolean is_active; + gtk_tree_model_get(model,&iter,2,&is_active,-1); + gtk_list_store_set(GTK_LIST_STORE(model),&iter,2,!is_active,-1); +} + +void on_locale_accept(GtkWidget *self, dictionary *dict){ + main_window *widgets = yon_dictionary_get_data(dict->first,main_window*); + locals_window *window = yon_dictionary_get_data(dict->first->next,locals_window*); + GtkTreeIter iter; + gboolean is_active; + char *final_string = ""; + char *final_ids = ""; + char *name, *id; + int valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(widgets->languagelist),&iter); + for (;valid;valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(widgets->languagelist),&iter)){ + gtk_tree_model_get(GTK_TREE_MODEL(widgets->languagelist),&iter,0,&name,1,&id,2,&is_active,-1); + if (is_active){ + final_string = yon_char_unite(strcmp(final_string,"") ? yon_char_append(final_string,"; ") : final_string,name,NULL); + final_ids = yon_char_unite(strcmp(final_ids,"") ? yon_char_append(final_ids,",") : final_ids,id,NULL); + } + } + gtk_entry_set_text(GTK_ENTRY(widgets->LocaleEntry),final_string); + if (yon_config_get_by_key("LOCALE")) yon_config_set("LOCALE",final_ids); + else yon_config_register("LOCALE",locale_section,final_ids); + on_close_subwindow(self); +} + +void on_locale_open(GtkWidget *self, main_window *widgets){ + locals_window *window = malloc(sizeof(locals_window)); + GtkBuilder *builder = gtk_builder_new_from_resource(glade_locales_path); + window->Window = yon_gtk_builder_get_widget(builder,"localesLayoutsWindow"); + window->MainTree = yon_gtk_builder_get_widget(builder,"localesTree"); + window->CloseButton = yon_gtk_builder_get_widget(builder,"localesCancelButton"); + window->AcceptButton = yon_gtk_builder_get_widget(builder,"localesAcceptButton"); + window->ToggleCell = GTK_CELL_RENDERER(gtk_builder_get_object(builder,"toggleCell")); + gtk_tree_view_set_model(GTK_TREE_VIEW(window->MainTree), GTK_TREE_MODEL(widgets->languagelist)); + + dictionary *dict = NULL; + yon_dictionary_add_or_create_if_exists_with_data(dict,"widgets",widgets); + yon_dictionary_add_or_create_if_exists_with_data(dict,"window",window); + + g_signal_connect(G_OBJECT(window->CloseButton),"clicked",G_CALLBACK(on_close_subwindow),NULL); + g_signal_connect(G_OBJECT(window->AcceptButton),"clicked",G_CALLBACK(on_locale_accept),dict); + g_signal_connect(G_OBJECT(window->MainTree),"row-activated",G_CALLBACK(on_locale_toggle),window); + gtk_dialog_run(GTK_DIALOG(window->Window)); + +} + void on_hostname_changed(GtkEntry *self, main_window *widgets){ char *text = (char*)gtk_entry_get_text(self); if (yon_config_get_by_key(hostname_parameter)){ yon_config_set(hostname_parameter,text); } else { - yon_config_register(hostname_parameter,"config",text); + yon_config_register(hostname_parameter,hostname_section,text); } } @@ -213,28 +317,41 @@ void on_id_combo_toggled(GtkComboBox *self, main_window *widgets){ int id = gtk_combo_box_get_active(self); if (id==2||id==1){ if (yon_config_get_by_key(id_parameter)){ - yon_config_set(id_parameter, id == 1 ? "Random" : "hardware"); + yon_config_set(id_parameter, id == 1 ? "random" : "hardware"); } else { - yon_config_register(id_parameter,"config", id == 1 ? "Random":"hardware"); + yon_config_register(id_parameter,id_section, id == 1 ? "random":"hardware"); } } if (id<3){ - gtk_widget_set_sensitive(widgets->IDEntry,0); - gtk_widget_set_sensitive(widgets->IDCopyButton,0); } else { - gtk_widget_set_sensitive(widgets->IDCopyButton,1); gtk_widget_set_sensitive(widgets->IDEntry,1); } } void on_id_changed(GtkEntry *self, main_window *widgets){ char *text = (char*)gtk_entry_get_text(self); - if (yon_config_get_by_key(id_parameter)){ - yon_config_set(id_parameter,text); + if (strcmp(text,"")){ + if (yon_config_get_by_key(id_parameter)){ + yon_config_set(id_parameter,text); + } else { + yon_config_register(id_parameter,id_section,text); + } + if (!main_config.lock_save_global) + gtk_widget_set_sensitive(widgets->SaveGlobalMenuItem,1); + if (!main_config.lock_save_global&&!main_config.lock_save_global) + gtk_widget_set_sensitive(widgets->SaveMenuItem,1); + if (!main_config.lock_save_local) + gtk_widget_set_sensitive(widgets->SaveLocalMenuItem,1); + gtk_widget_set_sensitive(widgets->IDCopyButton,1); + yon_ubl_status_box_render(INSERT_LABEL,BACKGROUND_IMAGE_SUCCESS_TYPE); } else { - yon_config_register(id_parameter,"config",text); + gtk_widget_set_sensitive(widgets->SaveGlobalMenuItem,0); + gtk_widget_set_sensitive(widgets->SaveMenuItem,0); + gtk_widget_set_sensitive(widgets->SaveLocalMenuItem,0); + gtk_widget_set_sensitive(widgets->IDCopyButton,0); + yon_ubl_status_box_render(ID_EMPTY_LABEL,BACKGROUND_IMAGE_FAIL_TYPE); } } @@ -258,25 +375,21 @@ void on_console_font_changed(GtkComboBox *self, main_window *widgets){ if (yon_config_get_by_key(console_font_parameter)){ yon_config_set(console_font_parameter,code); } else { - yon_config_register(console_font_parameter,"locale",code); + yon_config_register(console_font_parameter,console_font_section,code); } } } void on_language_changed(GtkComboBox *self, main_window *widgets){ GtkTreeIter iter; - if (gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->LanguageCombo))==0){ - yon_config_remove_by_key(language_parameter); + gtk_combo_box_get_active_iter(self,&iter); + char *code; + gtk_tree_model_get(GTK_TREE_MODEL(widgets->languagelist),&iter,1,&code,-1); + if (code) + if (yon_config_get_by_key(language_parameter)){ + yon_config_set(language_parameter,code); } else { - gtk_combo_box_get_active_iter(self,&iter); - char *code; - gtk_tree_model_get(GTK_TREE_MODEL(widgets->languagelist),&iter,1,&code,-1); - if (code) - if (yon_config_get_by_key(language_parameter)){ - yon_config_set(language_parameter,code); - } else { - yon_config_register(language_parameter,"locale",code); - } + yon_config_register(language_parameter,language_section,code); } } @@ -334,6 +447,9 @@ main_window *setup_window(){ widgets->ConsoleFontCombo = yon_gtk_builder_get_widget(builder,"ConsoleFontCombo"); widgets->LanguageCombo = yon_gtk_builder_get_widget(builder,"LanguageCombo"); + widgets->LocaleButton = yon_gtk_builder_get_widget(builder,"getLocalesButton"); + widgets->LocaleEntry = yon_gtk_builder_get_widget(builder,"localeEntry"); + widgets->fontlist = GTK_LIST_STORE(gtk_builder_get_object(builder,"fontlist")); widgets->languagelist = GTK_LIST_STORE(gtk_builder_get_object(builder,"languagelist")); @@ -347,18 +463,6 @@ main_window *setup_window(){ gtk_menu_shell_append(GTK_MENU_SHELL(menu),widgets->DocumentationMenuItem); gtk_menu_shell_append(GTK_MENU_SHELL(menu),widgets->AboutMenuItem); - if (main_config.lock_load_global == 1){ - gtk_widget_set_sensitive(widgets->LoadGlobalMenuItem,0); - } - if (main_config.lock_save_global == 1){ - gtk_widget_set_sensitive(widgets->SaveGlobalMenuItem,0); - gtk_widget_set_sensitive(widgets->SaveMenuItem,0); - } - if (main_config.lock_save_local == 1){ - gtk_widget_set_sensitive(widgets->SaveLocalMenuItem,0); - gtk_widget_set_sensitive(widgets->SaveMenuItem,0); - } - /* Widget registration for config monitoring | Регистрация виджетов для мониторинга конфига */ // yon_window_config_add_custom_parameter(widgets->HeadInfoLabel,"head-text","label",YON_TYPE_STRING); @@ -377,10 +481,11 @@ main_window *setup_window(){ g_signal_connect(G_OBJECT(widgets->IDCombo),"changed",G_CALLBACK(on_id_combo_toggled),widgets); g_signal_connect(G_OBJECT(widgets->IDEntry),"changed",G_CALLBACK(on_id_changed),widgets); g_signal_connect(G_OBJECT(widgets->IDCopyButton),"clicked",G_CALLBACK(on_id_copy),widgets); + g_signal_connect(G_OBJECT(widgets->LocaleButton),"clicked",G_CALLBACK(on_locale_open),widgets); g_signal_connect(G_OBJECT(widgets->ConsoleFontCombo),"changed",G_CALLBACK(on_console_font_changed),widgets); g_signal_connect(G_OBJECT(widgets->LanguageCombo),"changed",G_CALLBACK(on_language_changed),widgets); - // g_signal_connect(G_OBJECT(widgets->IDRandomCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button_inversed),widgets->IDCopyButton); - // g_signal_connect(G_OBJECT(widgets->IDRandomCheck),"toggled",G_CALLBACK(yon_gtk_widget_set_sensitive_from_toggle_button_inversed),widgets->IDEntry); + + main_config.localeslist = gtk_list_store_new(3,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_BOOLEAN); int size; config_str locales = yon_config_load(get_locales_command,&size); GtkTreeIter iter; @@ -389,7 +494,7 @@ main_window *setup_window(){ locales[i]=yon_char_divide_search(locales[i],"\n",-1); config_str loc_parsed = yon_char_parse(locales[i],&locsize,";"); gtk_list_store_append(widgets->languagelist,&iter); - gtk_list_store_set(widgets->languagelist,&iter,0,_(loc_parsed[1]),1,loc_parsed[0],-1); + gtk_list_store_set(widgets->languagelist,&iter,0,_(loc_parsed[1]),1,loc_parsed[0],2,0,-1); } config_str fonts = yon_config_load(get_fonts_command,&size); for (int i=0;ifontlist,&iter); gtk_list_store_set(widgets->fontlist,&iter,0,fonts[i],-1); } + if (main_config.lock_load_global == 1){ + gtk_widget_set_sensitive(widgets->LoadGlobalMenuItem,0); + } + if (main_config.lock_save_global == 1){ + gtk_widget_set_sensitive(widgets->SaveGlobalMenuItem,0); + gtk_widget_set_sensitive(widgets->SaveMenuItem,0); + } + if (main_config.lock_save_local == 1){ + gtk_widget_set_sensitive(widgets->SaveLocalMenuItem,0); + gtk_widget_set_sensitive(widgets->SaveMenuItem,0); + } gtk_widget_show(widgets->Window); return widgets; } @@ -421,6 +537,7 @@ int main(int argc, char *argv[]){ {"socket-ext-id", 1,0, 'e'}, {"socket-trd-id", 1,0, 't'}, {"debug", 0,0, 'd'}, + {"clean-config", 0,0, 'c'}, { NULL, 0, NULL, 0 } }; for (int i=0;iStatusIcon,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); diff --git a/source/ubl-settings-system.h b/source/ubl-settings-system.h index 02f4723..7ba558f 100644 --- a/source/ubl-settings-system.h +++ b/source/ubl-settings-system.h @@ -19,6 +19,7 @@ #define _(String) gettext(String) #define glade_path "/com/ublinux/ui/ubl-settings-system.glade" +#define glade_locales_path "/com/ublinux/ui/ubl-settings-system-layouts.glade" #define banner_path "/com/ublinux/images/ubl-settings-system-banner.png" #define CssPath "/com/ublinux/css/ubl-settings-system.css" #define config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL) @@ -32,8 +33,24 @@ #define get_locales_command "grep '' /usr/share/ubl-settings-system/csv/locales.csv" #define get_fonts_command "grep '' /usr/share/ubl-settings-system/csv/fonts.csv" +#define get_id_command "grep '' /etc/machine-id" // #define get_fonts_command "ls /usr/share/kbd/consolefonts/ |grep -v \"README\"|grep -oE \"^[-a-zA-Z0-9_]{3,}.psf\"|sed -e 's/\\.psf//g'" +#define hostname_parameter "HOSTNAME" +#define hostname_section "config" +#define id_parameter "MACHINEID" +#define id_section "config" +#define keyboard_layout_parameter "XKBLAYOUT" +#define keyboard_section "keyboard" +#define console_font_parameter "CONSOLE_FONT" +#define console_font_section "locale" +#define num_lock_boot_parameter "NUMLOCK" +#define num_lock_boot_section "config" +#define language_parameter "LANG" +#define language_section "locale" +#define locale_parameter "LOCALE" +#define locale_section "locale" + typedef char* string; string version_application; @@ -54,6 +71,7 @@ typedef struct { int lock_save_local; int lock_save_global; int lock_load_global; + GtkListStore *localeslist; } config; typedef struct { @@ -93,6 +111,9 @@ typedef struct { GtkWidget *ConsoleFontCombo; GtkWidget *LanguageCombo; + GtkWidget *LocaleButton; + GtkWidget *LocaleEntry; + GtkListStore *fontlist; GtkListStore *languagelist; @@ -111,4 +132,15 @@ typedef struct { GtkWidget *AcceptButton; } documentation_confirmation_window; -main_window *setup_window(); \ No newline at end of file +typedef struct { + GtkWidget *Window; + + GtkWidget *MainTree; + + GtkWidget *CloseButton; + GtkWidget *AcceptButton; + GtkCellRenderer *ToggleCell; +} locals_window; + +main_window *setup_window(); +void on_id_changed(GtkEntry *self, main_window *widgets); \ No newline at end of file diff --git a/source/ubl-strings.h b/source/ubl-strings.h index e8136b9..784063c 100644 --- a/source/ubl-strings.h +++ b/source/ubl-strings.h @@ -29,13 +29,14 @@ #define NOTHING_CHOSEN_LABEL _("Nothing were chosen") -#define GLOBAL_LOAD_SUCCESS_LABEL _("Global configuration loading succseeded.") -#define LOCAL_LOAD_SUCCESS_LABEL _("Local configuration loading succseeded.") +#define GLOBAL_LOAD_SUCCESS_LABEL _("Global configuration loading succeeded") +#define LOCAL_LOAD_SUCCESS_LABEL _("Local configuration loading succeeded") #define LOAD_FAILED_LABEL _("Config loading failed") -#define GLOBAL_LOCAL_SAVE_SUCCESS_LABEL _("Local and global configuration saving succseeded.") -#define GLOBAL_SAVE_SUCCESS_LABEL _("Global configuration saving succseeded.") -#define LOCAL_SAVE_SUCCESS_LABEL _("Local configuration saving succseeded.") +#define GLOBAL_LOCAL_SAVE_SUCCESS_LABEL _("Local and global configuration saving succeeded") +#define GLOBAL_SAVE_SUCCESS_LABEL _("Global configuration saving succeeded") +#define LOCAL_SAVE_SUCCESS_LABEL _("Local configuration saving succeeded") +#define SAVE_WARNING_LABEL _("Warning! New machine ID will apply after system reboot") #define HOSTNAME_LABEL _("Hostname:") #define ID_LABEL _("Work station ID:") @@ -45,9 +46,16 @@ #define MANUAL_LABEL _("Manual") #define CONSOLE_LABEL _("Console") #define FONT_LABEL _("Console font:") -#define LOCALE_LABEL _("Locale") +#define LOCALE_SECTION_LABEL _("Locale") +#define LOCALE_LABEL _("Locale:") #define LANGUAGE_LABEL _("Language:") #define DEFAULT_LABEL _("Default") -#define COPY_SUCCESS_LABEL _("Machine ID has been copied") \ No newline at end of file +#define COPY_SUCCESS_LABEL _("Machine ID has been copied") + +#define ID_EMPTY_LABEL _("ID field can't be empty!") + +#define INSERT_LABEL _("Insert data") + +#define ACCEPT_LABEL _("Accept") \ No newline at end of file diff --git a/source/ubl-utils.c b/source/ubl-utils.c index c5a6551..338e917 100644 --- a/source/ubl-utils.c +++ b/source/ubl-utils.c @@ -646,10 +646,10 @@ char **yon_char_parse(char *parameters, int *size, char *divider){ char *paramline=yon_char_new(parameters); char *param; while ((param=yon_char_divide_search(paramline,divider,1))){ + if (strcmp(param,paramline)==0) break; string=realloc(string,sizeof(char*)*i); string[i-1]=yon_char_new(param); i++; - if (strcmp(param,paramline)==0) break; } string=realloc(string,sizeof(char*)*i); string[i-1]=yon_char_new(paramline); @@ -942,6 +942,16 @@ apps *yon_apps_get_by_name(apps *applist, char *name, int size) return NULL; }; +config_str yon_file_open(char *file_path, int *size){ + FILE *file = fopen(file_path,"r"); + char str_loaded[4098]; + config_str final_string = NULL; + while (fgets(str_loaded,4098,file)){ + final_string ? yon_char_parsed_append(final_string,size,str_loaded) : yon_char_parsed_new(size,final_string,NULL); + } + return final_string; +} + //config functions typedef struct yon_config_parameter @@ -1243,7 +1253,7 @@ config_str yon_config_load(char *command, int *str_len){ * Выполняет команду [command], добавляя в конец все записи конфига в таком виде: * [ПАРАМЕТР1]="[значения1]" [ПАРАМЕТР2]="[значения2]" */ -int yon_config_save_registered(char *path, char *section){ +int yon_config_save_registered(char *path){ check_config{ dictionary *dct; dictionary *sections_add=NULL; @@ -1252,8 +1262,8 @@ int yon_config_save_registered(char *path, char *section){ if (dct->data&&strcmp(yon_dictionary_get_data(dct,char*),"")!=0){ if (((yon_config_parameter*)dct)->flag1==1){ ((yon_config_parameter*)dct)->flag1=0; - if (sections_add&&yon_dictionary_get(§ions_add,((yon_config_parameter*)dct)->section)) sections_add->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_add,char*)," ",dct->key,"=",yon_dictionary_get_data(dct,char*),NULL); - else yon_dictionary_add_or_create_if_exists_with_data(sections_add,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " set ", ((yon_config_parameter*)dct)->section, " ",dct->key,"=",yon_dictionary_get_data(dct,char*),NULL)); + if (sections_add&&yon_dictionary_get(§ions_add,((yon_config_parameter*)dct)->section)) sections_add->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_add,char*)," ",dct->key,"=\"",yon_dictionary_get_data(dct,char*),"\"",NULL); + else yon_dictionary_add_or_create_if_exists_with_data(sections_add,((yon_config_parameter*)dct)->section,yon_char_unite (ubconfig_save_command,path ? yon_char_append(" --target ",path):"", " set ", ((yon_config_parameter*)dct)->section," ", dct->key,"=\"",yon_dictionary_get_data(dct,char*),"\"",NULL)); } else if (((yon_config_parameter*)dct)->flag1==-1){ ((yon_config_parameter*)dct)->flag1=0; if (sections_remove&&yon_dictionary_get(§ions_remove,((yon_config_parameter*)dct)->section)) sections_remove->data=(void*)yon_char_unite(yon_dictionary_get_data(sections_remove,char*)," ",dct->key,NULL); @@ -1740,6 +1750,31 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end yon_dictionary_add_or_create_if_exists_with_data(__yon_main_window_config.deleted_parameters,param->parameter_name,param); } + int yon_window_config_get_parameter(char *section, char *config_parameter, void *return_value, enum YON_TYPE type){ + GError *err=NULL; + switch (type){ + case YON_TYPE_BOOLEAN: + *((int*)return_value) = g_key_file_get_boolean(__yon_window_config_file,section,config_parameter,&err); + if (err) return 0; else return 1; + break; + case YON_TYPE_INT: + *((int*)return_value) = g_key_file_get_integer(__yon_window_config_file,section,config_parameter,&err); + if (err) return 0; else return 1; + break; + case YON_TYPE_STRING: + *((char**)return_value) = g_key_file_get_string(__yon_window_config_file,section,config_parameter,&err); + if (err) return 0; else return 1; + break; + case YON_TYPE_STRING_LIST: + gsize size=0; + *((char***)return_value) = g_key_file_get_string_list(__yon_window_config_file,section,config_parameter,&size,&err); + *((char***)return_value)=yon_remalloc(return_value,size+1); + *((char***)return_value)[size]=NULL; + if (err) return 0; else return 1; + break; + } + } + GtkWidget *yon_ubl_menu_item_about_new(char *buttonname){ GtkWidget *menu_item = gtk_menu_item_new(); gtk_style_context_add_class(gtk_widget_get_style_context(menu_item),"menuitembottom"); diff --git a/source/ubl-utils.h b/source/ubl-utils.h index 88222c1..396ccd4 100644 --- a/source/ubl-utils.h +++ b/source/ubl-utils.h @@ -22,20 +22,13 @@ #define DesktopPath "/usr/share/applications/" #define for_dictionaries(obj, obj1) for (obj = obj1->first; obj != NULL; obj = obj->next) +#define for_iter(model,iter) for (int valid = gtk_tree_model_get_iter_first(model,iter);valid;valid=gtk_tree_model_iter_next(model,iter)) #define new(type) malloc(sizeof(type)) #define new_arr(type,size) malloc(sizeof(type)*size) #define get_home_dir_command yon_char_unite("getent passwd \"",yon_ubl_root_user_get(),"\" | cut -d: -f6",NULL) - -#define hostname_parameter "HOSTNAME" -#define id_parameter "MACHINEID" -#define keyboard_layout_parameter "XkbLayout" -#define console_font_parameter "CONSOLE_FONT" -#define num_lock_boot_parameter "NUMLOCK" -#define language_parameter "LANG" - typedef enum { #ifdef __GTK_H__ @@ -179,6 +172,8 @@ void yon_apps_sort(apps *applist, int size); apps *yon_apps_get_by_name(apps *applist, char *name, int size); +config_str yon_file_open(char *file_path, int *size); + //config functions #define ubconfig_save_command "ubconfig" @@ -192,7 +187,7 @@ typedef enum { config_str yon_config_load(char *command, int *str_len); -int yon_config_save_registered(char *path, char *section); +int yon_config_save_registered(char *path); char *yon_config_get_parameter(config_str parameters, int size, char *param); @@ -234,6 +229,7 @@ void yon_terminal_integrated_start(GtkWidget *terminal, char* command, void *end enum YON_TYPE{ YON_TYPE_STRING, + YON_TYPE_STRING_LIST, YON_TYPE_INT, YON_TYPE_BOOLEAN, YON_TYPE_OTHER @@ -270,6 +266,8 @@ void yon_window_config_add_custom_parameter(char *param_name, char *section, voi void yon_window_config_erase_custom_parameter(char *param_name, char *section); +int yon_window_config_get_parameter(char *section, char *config_parameter, void *return_value, enum YON_TYPE type); + int yon_gtk_combo_box_fill(GtkWidget *combo, char **parameters,int size); int yon_gtk_combo_box_text_find(GtkWidget *combo_box, char *text_to_find); diff --git a/ubl-settings-system-layouts.glade b/ubl-settings-system-layouts.glade index 6853c3b..2dfb5fc 100644 --- a/ubl-settings-system-layouts.glade +++ b/ubl-settings-system-layouts.glade @@ -12,77 +12,27 @@ False emblem-ok-symbolic - - - - - - - + 450 550 False - False - 450 - dialog-question-symbolic - + dialog + - True False - 5 - 5 - 5 - 5 - 5 - 5 vertical - 10 - - - True - True - in - - - True - True - keyboardList - False - - - - - - column - - - - 0 - - - - - - - - - True - True - 0 - - - - - True + 2 + + False - 5 + end - - Ok + + Cancel True True True - image9 + image8 @@ -95,12 +45,12 @@ - - Cancel + + Accept True True True - image8 + image9 @@ -115,6 +65,70 @@ False + False + 0 + + + + + True + False + 2 + 2 + 2 + 2 + vertical + 10 + + + True + True + in + + + True + True + False + True + + + none + + + + + column + + + + 2 + + + + + + + column + + + + 0 + + + + + + + + + True + True + 0 + + + + + True True 1 @@ -125,6 +139,7 @@ True False + True True diff --git a/ubl-settings-system.desktop b/ubl-settings-system.desktop index 941293e..89644e7 100644 --- a/ubl-settings-system.desktop +++ b/ubl-settings-system.desktop @@ -1,15 +1,15 @@ [Desktop Entry] Encoding=UTF-8 Name=System configuration -Name[ru]=TEMPLATE +Name[ru]=Системные настройки GenericName=ubl-settings-system -GenericName[ru]=TEMPLATE +GenericName[ru]=ubl-settings-system Comment=System basic parameters configuration -Comment[ru]=Приложение для TEMPLATE +Comment[ru]=Настройка основных параметров системы Type=Application Exec=pkexec ubl-settings-system Icon=com.ublinux.ubl-settings-system Terminal=false X-XfcePluggable=true X-UBLPluggable=true -Categories=XFCE;GTK;Settings;DesktopSettings;X-XFCE-SettingsDialog;X-XFCE-SystemSettings;X-UBL-SettingsManager;X-UBL-Personal-Settings; +Categories=XFCE;GTK;Settings;X-UBL-SettingsManager;X-UBL-System-Settings; diff --git a/ubl-settings-system.glade b/ubl-settings-system.glade index 85456f4..00b3a02 100644 --- a/ubl-settings-system.glade +++ b/ubl-settings-system.glade @@ -211,6 +211,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. False edit-copy-symbolic + + True + False + document-edit-symbolic + True False @@ -419,13 +424,9 @@ translated and supported by community. + + - - - Default - - - True @@ -496,8 +497,6 @@ translated and supported by community. 800 False - 800 - 600 com.ublinux.ubl-settings-system @@ -711,6 +710,7 @@ translated and supported by community. True True + True True @@ -865,14 +865,53 @@ translated and supported by community. True False + vertical 5 - + True False - Language: - True - 0 + 5 + + + True + False + Locale: + 0 + + + False + True + 0 + + + + + True + False + + + True + True + 1 + + + + + True + True + True + image2 + + + + False + True + 2 + + False @@ -881,20 +920,46 @@ translated and supported by community. - + True False - languagelist - 0 + 5 + + + True + False + Language: + True + 0 + + + False + True + 0 + + - - - 0 - + + True + False + languagelist + 0 + + + + 0 + + + + + True + True + 1 + - True + False True 1 @@ -1109,6 +1174,8 @@ translated and supported by community. + + diff --git a/ubl-settings-system.pot b/ubl-settings-system.pot index c0517de..1250dfa 100644 --- a/ubl-settings-system.pot +++ b/ubl-settings-system.pot @@ -150,11 +150,11 @@ msgid "Nothing were chosen" msgstr "" #: source/ubl-strings.h:32 -msgid "Global configuration loading succseeded." +msgid "Global configuration loading succeeded" msgstr "" #: source/ubl-strings.h:33 -msgid "Local configuration loading succseeded." +msgid "Local configuration loading succeeded" msgstr "" #: source/ubl-strings.h:34 @@ -162,65 +162,85 @@ msgid "Config loading failed" msgstr "" #: source/ubl-strings.h:36 -msgid "Local and global configuration saving succseeded." +msgid "Local and global configuration saving succeeded" msgstr "" #: source/ubl-strings.h:37 -msgid "Global configuration saving succseeded." +msgid "Global configuration saving succeeded" msgstr "" #: source/ubl-strings.h:38 -msgid "Local configuration saving succseeded." +msgid "Local configuration saving succeeded" msgstr "" -#: source/ubl-strings.h:40 -msgid "Hostname:" +#: source/ubl-strings.h:39 +msgid "Warning! New machine ID will apply after reboot" msgstr "" #: source/ubl-strings.h:41 -msgid "Work station ID:" +msgid "Hostname:" msgstr "" #: source/ubl-strings.h:42 -msgid "System" +msgid "Work station ID:" msgstr "" #: source/ubl-strings.h:43 -msgid "Random" +msgid "System" msgstr "" #: source/ubl-strings.h:44 -msgid "Hardware" +msgid "Random" msgstr "" #: source/ubl-strings.h:45 -msgid "Manual" +msgid "Hardware" msgstr "" #: source/ubl-strings.h:46 -msgid "Console" +msgid "Manual" msgstr "" #: source/ubl-strings.h:47 -msgid "Console font:" +msgid "Console" msgstr "" #: source/ubl-strings.h:48 +msgid "Console font:" +msgstr "" + +#: source/ubl-strings.h:49 msgid "Locale" msgstr "" #: source/ubl-strings.h:49 +msgid "Locale:" +msgstr "" + +#: source/ubl-strings.h:50 msgid "Language:" msgstr "" -#: source/ubl-strings.h:51 +#: source/ubl-strings.h:52 msgid "Default" msgstr "" -#: source/ubl-strings.h:53 +#: source/ubl-strings.h:54 msgid "Machine ID has been copied" msgstr "" +#: source/ubl-strings.h:56 +msgid "ID string can't be empty!" +msgstr "" + +#: source/ubl-strings.h:56 +msgid "Insert data" +msgstr "" + +#: source/ubl-strings.h:60 +msgid "Accept" +msgstr "" + msgid "Afrikaans, South Africa" msgstr "" diff --git a/ubl-settings-system_ru.po b/ubl-settings-system_ru.po index a47ba90..89c9dd4 100644 --- a/ubl-settings-system_ru.po +++ b/ubl-settings-system_ru.po @@ -111,7 +111,7 @@ msgstr "Сохранить" #: source/ubl-strings.h:18 msgid "Load local configuration" -msgstr "Загрузить локальную конфигуруцию" +msgstr "Загрузить локальную конфигурацию" #: source/ubl-strings.h:19 msgid "Load global configuration" @@ -154,11 +154,11 @@ msgid "Nothing were chosen" msgstr "Ничего не было выбрано" #: source/ubl-strings.h:32 -msgid "Global configuration loading succseeded." +msgid "Global configuration loading succeeded" msgstr "Успешно загружена глобальная конфигурация" #: source/ubl-strings.h:33 -msgid "Local configuration loading succseeded." +msgid "Local configuration loading succeeded" msgstr "Успешно загружена локальная конфигурация" #: source/ubl-strings.h:34 @@ -166,65 +166,85 @@ msgid "Config loading failed" msgstr "Ошибка загрузки конфигурации" #: source/ubl-strings.h:36 -msgid "Local and global configuration saving succseeded." +msgid "Local and global configuration saving succeeded" msgstr "Успешно записаны локальная и глобальная конфигурация" #: source/ubl-strings.h:37 -msgid "Global configuration saving succseeded." +msgid "Global configuration saving succeeded" msgstr "Успешно записана глобальная конфигурация" #: source/ubl-strings.h:38 -msgid "Local configuration saving succseeded." +msgid "Local configuration saving succeeded" msgstr "Успешно записана локальная конфигурация" -#: source/ubl-strings.h:40 +#: source/ubl-strings.h:39 +msgid "Warning! New machine ID will apply after system reboot" +msgstr "Внимание! Новый ID рабочей станции будет применён после перезагрузки системы" + +#: source/ubl-strings.h:41 msgid "Hostname:" msgstr "Имя хоста:" -#: source/ubl-strings.h:41 +#: source/ubl-strings.h:42 msgid "Work station ID:" msgstr "ID рабочей станции:" -#: source/ubl-strings.h:42 +#: source/ubl-strings.h:43 msgid "System" msgstr "Система" -#: source/ubl-strings.h:43 +#: source/ubl-strings.h:44 msgid "Random" msgstr "Случайный" -#: source/ubl-strings.h:44 +#: source/ubl-strings.h:45 msgid "Hardware" msgstr "Системный" -#: source/ubl-strings.h:45 +#: source/ubl-strings.h:46 msgid "Manual" msgstr "Вручную" -#: source/ubl-strings.h:46 +#: source/ubl-strings.h:47 msgid "Console" msgstr "Консоль" -#: source/ubl-strings.h:47 +#: source/ubl-strings.h:48 msgid "Console font:" -msgstr "Шрифт в консоли" +msgstr "Шрифт в консоли:" -#: source/ubl-strings.h:48 +#: source/ubl-strings.h:49 msgid "Locale" msgstr "Локаль" #: source/ubl-strings.h:49 +msgid "Locale:" +msgstr "Доступные языки в системе:" + +#: source/ubl-strings.h:50 msgid "Language:" -msgstr "Язык" +msgstr "Язык:" -#: source/ubl-strings.h:51 +#: source/ubl-strings.h:52 msgid "Default" msgstr "По умолчанию" -#: source/ubl-strings.h:53 +#: source/ubl-strings.h:54 msgid "Machine ID has been copied" msgstr "ID рабочей станции скопирован" +#: source/ubl-strings.h:56 +msgid "ID field can't be empty!" +msgstr "Поле ID не может быть пустым!" + +#: source/ubl-strings.h:56 +msgid "Insert data" +msgstr "Введите данные" + +#: source/ubl-strings.h:60 +msgid "Accept" +msgstr "Принять" + msgid "Afrikaans, South Africa" msgstr "Африканский, Южная Африка" @@ -238,7 +258,7 @@ msgid "Arabic, Algeria" msgstr "Арабский, Алжир" msgid "Arabic, Egypt" -msgstr "Арабский, Египт" +msgstr "Арабский, Египет" msgid "Arabic, Iraq" msgstr "Арабский, Ирак" @@ -484,7 +504,7 @@ msgid "Kannada, India" msgstr "Каннада, Индия" msgid "Korean, Korea" -msgstr "орейский, Корея" +msgstr "Корейский, Корея" msgid "Kashmiri, India" msgstr "Кашмирский, Индия" @@ -535,7 +555,7 @@ msgid "Oriya, India" msgstr "Ория, Индия" msgid "Punjabi, India" -msgstr "Панджаби" +msgstr "Панджаби, Индия" msgid "Polish, Poland" msgstr "Польский, Польша"