diff --git a/source/ubl-settings-datetime.cc b/source/ubl-settings-datetime.cc index 12492e6..aea15cc 100644 --- a/source/ubl-settings-datetime.cc +++ b/source/ubl-settings-datetime.cc @@ -68,8 +68,13 @@ void MainWindow::settings(){ this->flag_block_gui(); this->event(); this->parse_text_date(); + btnSaveGlobl->set_sensitive(false); + this->download_local_cfg(); } else{ + btnSaveLocal->set_sensitive(false); + btnSaveGlobl->set_sensitive(false); + btnDownload->set_sensitive(false); numTimeHrs->set_sensitive(false); numTimeMin->set_sensitive(false); lblTime->set_sensitive(false); @@ -87,8 +92,6 @@ void MainWindow::settings(){ lblSynchronizebChkGLob->set_sensitive(false); cbDhcp->set_sensitive(false); txtNtpServer->set_sensitive(false); - lblTimeZoneGlob->set_sensitive(false); - lblRegGlob->set_sensitive(false); lblZone1Glob->set_sensitive(false); lblDateTimeSetting->set_sensitive(false); this->event(); @@ -104,13 +107,14 @@ int MainWindow::check_root(){ } return 0; } + void MainWindow::lacalization(){ lblSave->set_label(_("Save")); lblDownload->set_label(_("Download")); btnDownloadGlobal->set_label(_("Download global")); - btnSaveLocal->set_label(_("Save global")); - btnSaveGlobl->set_label(_("Save local")); - + btnDownloadlocal->set_label(_("Download local")); + btnSaveLocal->set_label(_("Save local")); + btnSaveGlobl->set_label(_("Save global")); txtDate->set_tooltip_text(_("Date of\nFormat: DD.MM.YYYY")); txtNtpServer->set_tooltip_text(_("Enter the name of the ntp-server or its ip-address.\nWhen entering multiple addresses, separate them with commas.")); lblSynchronizebChkGLob->set_text(_("Synchronize via NTP:")); @@ -125,9 +129,6 @@ void MainWindow::lacalization(){ lblTimeZone->set_text(_("Time zone")); lblReg->set_text(_("Region")); lblZone->set_text(_("Zone")); - lblRegGlob->set_text(_("Region")); - lblZone1Glob->set_text(_("Zone")); - lblTimeZoneGlob->set_text(_("Time zone")); lblSynchronizeBtn->set_text(_("Sync by")); lblDateTimeSettingGlob->set_text(_("Global customization")); this->set_title(_("ubl-settings-datetime")); @@ -159,8 +160,6 @@ void MainWindow::flag_block_gui(){ if (flag_timezone==true){ cbRegion->set_sensitive(false); cbZone->set_sensitive(false); - cbRegionGlob->set_sensitive(false); - cbZoneGlob->set_sensitive(false); //btnChooseDate->set_sensitive(false); cbDhcp->set_sensitive(false); } @@ -170,12 +169,6 @@ void MainWindow::flag_block_gui(){ } if (flag_update==true){ lblDateTimeSettingGlob->set_sensitive(false); - //lblSynchronizebChkGLob->set_sensitive(false); - lblTimeZoneGlob->set_sensitive(false); - lblRegGlob->set_sensitive(false); - cbRegionGlob->set_sensitive(false); - lblZone1Glob->set_sensitive(false); - cbZoneGlob->set_sensitive(false); txtNtpServer->set_sensitive(false); cbDhcp->set_sensitive(false); } @@ -207,9 +200,7 @@ void MainWindow::get_builder(){ builder->get_widget("cbDhcp", cbDhcp); builder->get_widget("txtDate", txtDate); builder->get_widget("cbRegion", cbRegion); - builder->get_widget("cbRegionGlob", cbRegionGlob); builder->get_widget("cbZone", cbZone); - builder->get_widget("cbZoneGlob", cbZoneGlob); builder->get_widget("txtNtpServer", txtNtpServer); builder->get_widget("cldrDate", cldrDate); builder->get_widget("mess_dchp", mess_dchp); @@ -221,9 +212,6 @@ void MainWindow::get_builder(){ builder->get_widget("lblTimeZone",lblTimeZone); builder->get_widget("lblReg",lblReg); builder->get_widget("lblZone",lblZone); - builder->get_widget("lblRegGlob",lblRegGlob); - builder->get_widget("lblZone1Glob",lblZone1Glob); - builder->get_widget("lblTimeZoneGlob",lblTimeZoneGlob); //builder->get_widget("lblSynchronizebChk",_lblSynchronizebChk); builder->get_widget("lblSynchronizebChkGLob",lblSynchronizebChkGLob); builder->get_widget("lblSynchronizeBtn",lblSynchronizeBtn); @@ -242,9 +230,11 @@ void MainWindow::get_builder(){ builder->get_widget("btnSaveLocal",btnSaveLocal); builder->get_widget("btnSaveGlobl",btnSaveGlobl); builder->get_widget("lblSave",lblSave); + builder->get_widget("btnSave",btnSave); builder->get_widget("btnDownload",btnDownload); builder->get_widget("lblDownload",lblDownload); builder->get_widget("btnDownloadGlobal", btnDownloadGlobal); + builder->get_widget("btnDownloadlocal", btnDownloadlocal); //builder->get_widget("cbxSynchronizeNtp",cbxSynchronizeNtp); @@ -269,15 +259,40 @@ void MainWindow::event(){ btnChooseDate->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::calendar_show)); cbDhcp->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::event_entry_cbDhcp)); cbRegion->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::append_zone)); - cbRegionGlob->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::append_zone_glob)); - cbZone->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::enter_zone)); - cbZoneGlob->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::enter_zone_glob)); - txtNtpServer->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_ntp)); cldrDate->signal_day_selected_double_click().connect(sigc::mem_fun(*this, &MainWindow::get_calendar)); mess_sudo->signal_delete_event().connect(sigc::mem_fun(*this, &MainWindow::gui_exit_2)); btnNtpWinClose->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::wind_close_ntp)); btnNtpStop->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::stop_ntp)); + btnDownloadGlobal->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::download_globl_cfg)); + btnSaveLocal->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::save_local_cfg)); + btnSaveGlobl->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::save_global_cfg)); + btnDownloadlocal->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::download_local_cfg)); +} + +void MainWindow::download_globl_cfg(){ + this->entry_dhcp_mess(); + string cmd = "/usr/bin/ubconfig --default --source global get clock ZONE"; + this->fill_in_reg_zone(cmd); + btnSaveGlobl->set_sensitive(true); +} + +void MainWindow::download_local_cfg(){ + string cmd = "/usr/bin/ubconfig --default --source system get clock ZONE"; + this->fill_in_reg_zone(cmd); } + +void MainWindow::save_local_cfg(){ + string cmd = "ubconfig --target system set clock ZONE="; + this->enter_zone(cmd); +} + +void MainWindow::save_global_cfg(){ + string cmd = "/usr/bin/ubconfig --target global set clock ZONE="; + this->enter_zone(cmd); + this->save_Dhcp(); +} + + void MainWindow::wind_close_ntp(){ windowsNnpClose->hide(); } @@ -309,8 +324,7 @@ void MainWindow::gui_mess_close(){ mess_dchp->hide(); } -bool MainWindow::focus_ntp(GdkEventFocus* event){ - if (event!=NULL){} +bool MainWindow::focus_ntp(){ if (txtNtpServer->get_text()=="" || txtNtpServer->get_text()==" "){ lblMessage->set_text(_("Enter DHCP!")); mess_dchp->show(); @@ -455,76 +469,88 @@ struct MainWindow::Result MainWindow::wrapper_call(string cmd){ } return obj_result; } - void MainWindow::event_entry_cbDhcp(){ - Glib::ustring str_dhcp = cbDhcp->get_active_text(); + string str_dhcp = cbDhcp->get_active_text(); + string cmd = ""; int activ_index = cbDhcp->get_active_row_number(); - if (str_dhcp.length()!=0){ - if (activ_index==0){ - btnUpdateDateTime->set_sensitive(false); - string cmd = "/usr/bin/ubconfig set network NTPSERVERS=default"; - response_cmd=system(cmd.c_str()); - txtNtpServer->set_sensitive(false); - cbDhcp->set_active(activ_index); - cmd = "/usr/bin/ubconfig --source=default get NTPSERVERS_DEFAULT"; - struct Result obj_result = this->wrapper_call(cmd); - if (obj_result.error==0){ - txtNtpServer->set_text(obj_result.response); - } - else{ - //string error = ""; - //error = string(_("ERROR")) + "\n" + obj_result.response; - //lblMessage->set_text(error); - //mess_dchp->show(); - } + if (str_dhcp.length()==0){ + cbDhcp->set_active(0); + } + else if (activ_index==0){ + txtNtpServer->set_text(""); + btnUpdateDateTime->set_sensitive(false); + txtNtpServer->set_sensitive(false); + /* + cmd = "/usr/bin/ubconfig --source=default get NTPSERVERS_DEFAULT"; + struct Result obj_result = this->wrapper_call(cmd); + if (obj_result.error==0){ + txtNtpServer->set_text(obj_result.response); } - else if (activ_index==1){ - btnUpdateDateTime->set_sensitive(false); - string cmd = "/usr/bin/ubconfig set network NTPSERVERS=dhcp"; - response_cmd=system(cmd.c_str()); - txtNtpServer->set_sensitive(false); + else{ + //string error = ""; + //error = string(_("ERROR")) + "\n" + obj_result.response; + //lblMessage->set_text(error); + //mess_dchp->show(); + }*/ + + } + else if (activ_index==1){ + btnUpdateDateTime->set_sensitive(false); + txtNtpServer->set_sensitive(false); + txtNtpServer->set_text(""); + } + else if (activ_index==2){ + txtNtpServer->set_sensitive(true); + /* + string cmd = "/usr/bin/ubconfig get network NTPSERVERS"; + struct Result obj_result = this->wrapper_call(cmd); + if (obj_result.error==0){ + if (obj_result.response.find("default")==std::string::npos){ + if (obj_result.response.find("dhcp")==std::string::npos){ + txtNtpServer->set_text(obj_result.response); + } cbDhcp->set_active(activ_index); - txtNtpServer->set_text(""); - } - else if (activ_index==2){ - btnUpdateDateTime->set_sensitive(false); - txtNtpServer->set_sensitive(true); - if (txtNtpServer->get_text().find("default")!=std::string::npos){ - txtNtpServer->set_text(""); - } - string cmd = "/usr/bin/ubconfig get network NTPSERVERS"; - struct Result obj_result = this->wrapper_call(cmd); - if (obj_result.error==0){ - if (obj_result.response.find("default")==std::string::npos){ - if (obj_result.response.find("dhcp")==std::string::npos){ - txtNtpServer->set_text(obj_result.response); - } - cbDhcp->set_active(activ_index); - } } - else if (obj_result.error==3){} - else{ - string error = ""; - error = string(_("ERROR")) + "\n" + obj_result.response; - lblMessage->set_text(error); - mess_dchp->show(); - } } - else if (activ_index==3){ - string cmd = "/usr/bin/ubconfig remove network NTPSERVERS"; - response_cmd=system(cmd.c_str()); - txtNtpServer->set_text(""); - txtNtpServer->set_sensitive(false); - btnUpdateDateTime->set_sensitive(true); - this->stop_ntp(); - } + else if (obj_result.error==3){} + else{ + string error = ""; + error = string(_("ERROR")) + "\n" + obj_result.response; + lblMessage->set_text(error); + mess_dchp->show(); } - - else{ + */ + } + else if (activ_index==3){ + txtNtpServer->set_text(""); + txtNtpServer->set_sensitive(false); + btnUpdateDateTime->set_sensitive(true); + this->stop_ntp(); + } +} + +void MainWindow::save_Dhcp(){ + int activ_index = cbDhcp->get_active_row_number(); + string str_dhcp = cbDhcp->get_active_text(); + string cmd = ""; + if (str_dhcp.length()==0){ + + } + else if (activ_index==0){ + string cmd = "/usr/bin/ubconfig set network NTPSERVERS=default"; + response_cmd=system(cmd.c_str()); + } + else if (activ_index==1){ string cmd = "/usr/bin/ubconfig set network NTPSERVERS=dhcp"; response_cmd=system(cmd.c_str()); - cbDhcp->set_active(0); } + else if (activ_index==2){ + this->focus_ntp(); + } + else if (activ_index==3){ + string cmd = "/usr/bin/ubconfig remove network NTPSERVERS"; + response_cmd=system(cmd.c_str()); + } } string MainWindow::str_remove(std::string& source, const std::string to_remove){ @@ -575,7 +601,7 @@ void MainWindow::calendar_show(){ popCalendar->show(); } -void MainWindow::enry_dhcp_mess(){ +void MainWindow::entry_dhcp_mess(){ string cmd = "/usr/bin/ubconfig get network NTPSERVERS"; struct Result obj_result = this->wrapper_call(cmd); if (obj_result.error==0){ @@ -629,27 +655,8 @@ void MainWindow::enry_dhcp_mess(){ } } -void MainWindow::get_config(){ - this->read_file(); - this->update_hour_minute(); - this->update_calendar(); - this->enry_dhcp_mess(); - string cmd = "/usr/bin/ubconfig --default --source global get clock ZONE"; - struct Result obj_result = this->wrapper_call(cmd); - if (obj_result.error==0){ - auto arr_reg_zone_glob = this->split_region_zone(obj_result.response); - if (arr_reg_zone_glob[0].length()!=0){ - this->append_region_zone(arr_reg_zone_glob[0],arr_reg_zone_glob[1],cbRegionGlob,cbZoneGlob); - } - else{ - this->append_region_zone("","",cbRegionGlob,cbZoneGlob); - } +void MainWindow::fill_in_reg_zone(string &cmd){ - } - else { - this->append_region_zone("","",cbRegionGlob,cbZoneGlob); - } - cmd = "/usr/bin/ubconfig --default --source system get clock ZONE"; struct Result obj_result_1 = this->wrapper_call(cmd); if (obj_result_1.error==0){ auto arr_reg_zone = this->split_region_zone(obj_result_1.response); @@ -663,6 +670,16 @@ void MainWindow::get_config(){ else { this->append_region_zone("","",cbRegion,cbZone); } +} + + + +void MainWindow::get_config(){ + this->read_file(); + this->update_hour_minute(); + this->update_calendar(); + this->entry_dhcp_mess(); + } @@ -684,7 +701,7 @@ array MainWindow::split_region_zone(string read_reg_zon_cfg){ } -void MainWindow::enter_zone(){ +void MainWindow::enter_zone(string &cmd){ int activ_index_reg = cbRegion->get_active_row_number(); string reg_text=array_region[activ_index_reg]; int activ_index = cbZone->get_active_row_number(); @@ -700,8 +717,7 @@ void MainWindow::enter_zone(){ if (!(zone_text.empty())){ str_zone=zone_text; str_region=reg_text; - string cmd = ""; - cmd = " ubconfig --target system set clock ZONE=" + str_region + "/" + str_zone; + cmd = cmd + str_region + "/" + str_zone; response_cmd=system(cmd.c_str()); } else{ @@ -724,36 +740,6 @@ void MainWindow::parse_text_date(){ } } -void MainWindow::enter_zone_glob(){ - int activ_index_reg = cbRegionGlob->get_active_row_number(); - string reg_text=array_region[activ_index_reg]; - int activ_index = cbZoneGlob->get_active_row_number(); - string zone_text=""; - if(!(reg_text.empty())){ - int index=0; - for (const auto &zone :time_reg_map.at(reg_text)){ - if (index==activ_index){ - zone_text=zone; - } - index+=1; - } - if (!(zone_text.empty())){ - //str_zoneGlob = zone_text.substr(zone_text.find(") ")+2,zone_text.length()); - string cmd = "/usr/bin/ubconfig --target global set clock ZONE=" +reg_text +"/" + zone_text; - response_cmd=system(cmd.c_str()); - } - else{ - str_zoneGlob=""; - str_region_glob=""; - } - } - else{ - str_zoneGlob=""; - str_region_glob=""; - } -} - - void MainWindow::append_region_zone(string region, string zone, Gtk::ComboBoxText *tmpCbReg, Gtk::ComboBoxText *tmpCbZone){ str_region=region; str_region_glob=region; @@ -789,6 +775,7 @@ void MainWindow::append_region_zone(string region, string zone, Gtk::ComboBoxTex tmpCbReg->set_active_text(reg); } } + tmpCbZone->remove_all(); index = 0; string zone_mixing = ""; string path_reg_zone = ""; @@ -852,23 +839,7 @@ void MainWindow::append_zone(){ cbZone->set_active(0); } -void MainWindow::append_zone_glob(){ - cbZoneGlob->remove_all(); - int index = cbRegionGlob->get_active_row_number(); - string str_region_glob = array_region[index]; - string zone_mixing=""; - string path_dir=""; - - if(str_region_glob.length()!=0){ - for (const auto &_str_zone : time_reg_map_local.at(str_region_glob)){ - cbZoneGlob->append(Glib::ustring(_str_zone)); - } - } - cbZoneGlob->set_active(0); -} - void MainWindow::update_time_date(){ - //this->enter_zone(); string cmd = ""; if ((year!=0) && (month !=0) && (day !=0)){ string str_month = ""; diff --git a/source/ubl-settings-datetime.h b/source/ubl-settings-datetime.h index 35ec850..0e2640b 100644 --- a/source/ubl-settings-datetime.h +++ b/source/ubl-settings-datetime.h @@ -53,9 +53,7 @@ class MainWindow : public Gtk::ApplicationWindow { Gtk::CheckButton *cbxSynchronizeNtpGlob; Gtk::Box *boxColor; Gtk::ComboBoxText *cbRegion; - Gtk::ComboBoxText *cbRegionGlob; Gtk::ComboBoxText *cbZone; - Gtk::ComboBoxText *cbZoneGlob; Gtk::Window *mess_dchp; Gtk::Window *mess_sudo; Gtk::Popover *popCalendar; @@ -69,9 +67,7 @@ class MainWindow : public Gtk::ApplicationWindow { Gtk::Label *lblTimeZone; Gtk::Label *lblReg; Gtk::Label *lblZone; - Gtk::Label *lblRegGlob; Gtk::Label *lblZone1Glob; - Gtk::Label *lblTimeZoneGlob; Gtk::Label *lblSynchronizebChk; Gtk::Label *lblSynchronizebChkGLob; Gtk::Label *lblSynchronizeBtn; @@ -93,7 +89,9 @@ class MainWindow : public Gtk::ApplicationWindow { Gtk::Widget *btnDownload; Gtk::MenuItem *btnSaveLocal; Gtk::MenuItem *btnSaveGlobl; + Gtk::MenuItem *btnDownloadGlobal; + Gtk::MenuItem *btnDownloadlocal; std::map > time_reg_map; std::map > time_reg_map_local; unsigned int year=0; @@ -120,6 +118,12 @@ class MainWindow : public Gtk::ApplicationWindow { MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder); MainWindow(Glib::RefPtr const& builder); virtual ~MainWindow() = default; + void fill_in_reg_zone(string &cmd); + void download_globl_cfg(); + void save_local_cfg(); + void save_global_cfg(); + void save_Dhcp(); + void download_local_cfg(); void post_entry_data(); void lacalization(); void settings(); @@ -128,14 +132,13 @@ class MainWindow : public Gtk::ApplicationWindow { void get_builder(); void event(); void gui_mess_close(); - bool focus_ntp(GdkEventFocus* event); + bool focus_ntp(); void event_entry_cbDhcp(); void get_calendar(); void calendar_show(); - void enry_dhcp_mess(); + void entry_dhcp_mess(); void get_config(); - void enter_zone(); - void enter_zone_glob(); + void enter_zone(string &cmd); void set_ntp_toggle(); void append_region_zone(string region, string zone, Gtk::ComboBoxText *tmpCbReg, Gtk::ComboBoxText *tmpCbZone); string call(string cmd); diff --git a/ubl-settings-datetime.glade b/ubl-settings-datetime.glade index da31a0f..6ef784d 100644 --- a/ubl-settings-datetime.glade +++ b/ubl-settings-datetime.glade @@ -33,6 +33,14 @@ True + + + True + False + Download Local + True + + False @@ -692,138 +700,6 @@ Format: DD.MM.YYYY 1 - - - True - False - 5 - 10 - 5 - 10 - 6 - 0.019999999552965164 - in - - - True - False - - - True - False - - - False - True - 1 - - - - - True - False - 8 - 5 - 8 - 5 - 6 - 13 - Region - 0 - - - False - True - 2 - - - - - True - False - 5 - 5 - 5 - 5 - 6 - 13 - - - False - True - 3 - - - - - True - False - 10 - 5 - 10 - 5 - 5 - 13 - Area - 0 - - - False - True - 4 - - - - - True - False - 5 - 5 - 5 - 5 - 6 - 13 - - - False - True - 5 - - - - - 5 - True - False - 15 - 5 - 15 - 5 - 5 - 5 - - - False - True - 6 - - - - - - - True - False - Time Zone - - - - - False - True - 2 - - diff --git a/ubl-settings-datetime_ru.po b/ubl-settings-datetime_ru.po index 49531f0..f28ed5e 100644 --- a/ubl-settings-datetime_ru.po +++ b/ubl-settings-datetime_ru.po @@ -1648,6 +1648,9 @@ msgstr "Сохранить локально" msgid "Download global" msgstr "Загрузить глобально" +msgid "Download local" +msgstr "Загрузить локально" + msgid "Disabled" msgstr "Отключено"