@ -2,12 +2,6 @@
# include "ubl-settings-datetime.h"
using namespace std ;
const string path_app = " /usr/bin/ " ;
const string path_glade = " /usr/share/ubl-settings-datetime/ui/ " ;
const string app_name = " ubl-settings-datetime " ;
const string path_locale = " /usr/share/locale/ " ;
const string path_css = " /usr/share/ubl-settings-datetime/css/ubl-settings-datetime.css " ;
const string path_img_head_background = " /usr/share/ubl-settings-datetime/images/logo-background.png " ;
bool flag_datetime = false ;
bool flag_timezone = false ;
bool flag_ntp_mode = false ;
@ -19,7 +13,7 @@ bool flag_load_global = false;
bool flag_sync_hwclock = false ;
int socket_ext_id_I = 0 ;
int socket_trd_id_I = 0 ;
string version_application = " 1. 5 " ;
string version_application = " 1. 6 " ;
CmdArgParser : : CmdArgParser ( const std : : string & p_name , const std : : string & p_description , const std : : string & p_help )
: Glib : : OptionGroup { p_name , p_description , p_help } {
@ -55,34 +49,31 @@ MainWindow::MainWindow(Glib::RefPtr<Gtk::Builder> const& builder) {
}
void MainWindow : : settings ( ) {
map_error [ " xdg-open https://wiki.ublinux.ru/ru/home " ] = string ( gettext ( " : \" xdg-open \" " ) ) ;
map_error [ " ubconfig --default --source system get clock ZONE " ] = string ( gettext ( " : \" Time Zone \" " ) ) ;
map_error [ " hwclock --systohc " ] = string ( gettext ( " : \" Hardware time \" " ) ) ;
map_error [ " ubconfig --default --source system get network NTPSERVERS " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " ubconfig --source=default get NTPSERVERS_DEFAULT " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " ubconfig --default --source system get clock HWCLOCK_SYNC " ] = string ( gettext ( " : \" Hardware time \" " ) ) ;
map_error [ " ubconfig --default --source global get network NTPSERVERS " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " ubconfig --default --source global get clock ZONE " ] = string ( gettext ( " : \" Time Zone \" " ) ) ;
map_error [ " ubconfig --default --source global get clock HWCLOCK_SYNC " ] = string ( gettext ( " : \" Hardware time \" " ) ) ;
map_error [ " ubconfig --source global get clock HWCLOCK_SYNC " ] = string ( gettext ( " : \" Hardware time \" " ) ) ;
map_error [ " ubconfig --target system set clock ZONE= " ] = string ( gettext ( " : \" Time Zone \" " ) ) ;
map_error [ " ubconfig --target system set network NTPSERVERS=default " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " ubconfig --target system set network NTPSERVERS=dhcp " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " ubconfig --target system set network NTPSERVERS= \" " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " ubconfig --target system remove network NTPSERVERS " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " ubconfig --target system set clock HWCLOCK_SYNC=localtime " ] = string ( gettext ( " : \" Hardware time \" " ) ) ;
map_error [ " ubconfig --target system set clock HWCLOCK_SYNC=utc " ] = string ( gettext ( " : \" Hardware time \" " ) ) ;
map_error [ " ubconfig --target global set clock ZONE= " ] = string ( gettext ( " : \" Time Zone \" " ) ) ;
map_error [ " ubconfig --target global set network NTPSERVERS=default " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " ubconfig --target global set network NTPSERVERS=dhcp " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " ubconfig --target global set network NTPSERVERS= \" " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " ubconfig --target global remove network NTPSERVERS " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " ubconfig --target global set clock HWCLOCK_SYNC=localtime " ] = string ( gettext ( " : \" Hardware time \" " ) ) ;
map_error [ " ubconfig --target global set clock HWCLOCK_SYNC=utc " ] = string ( gettext ( " : \" Hardware time \" " ) ) ;
map_error [ " ubconfig --source default get [] NTPSERVERS_DEFAULT " ] = string ( gettext ( " : \" NTP \" " ) ) ;
map_error [ " date +%Y%m%d -s \" " ] = string ( gettext ( " : \" Date \" " ) ) ;
map_error [ " date +%T -s \" " ] = string ( gettext ( " : \" Date \" " ) ) ;
map_error [ " ubconfig --source default get clock HWCLOCK_SYNC " ] = string ( gettext ( " : \" Hardware time \" " ) ) ;
map_error [ get_system_ZONE ] = string ( str_time_zone_flag ) ;
map_error [ set_hwclock ] = string ( str_hardware_time_flag ) ;
map_error [ get_system_NTPSERVERS ] = string ( str_NTP_flag ) ;
map_error [ get_system_HWCLOCK_SYNC ] = string ( str_hardware_time_flag ) ;
map_error [ get_global_NTPSERVERS ] = string ( str_NTP_flag ) ;
map_error [ get_global_ZONE ] = string ( str_time_zone_flag ) ;
map_error [ get_global_defalult_HWCLOCK_SYNC ] = string ( str_hardware_time_flag ) ;
map_error [ get_global_HWCLOCK_SYNC ] = string ( str_hardware_time_flag ) ;
map_error [ set_system_ZONE ] = string ( str_time_zone_flag ) ;
map_error [ set_system_NTPSERVERS_default ] = string ( str_NTP_flag ) ;
map_error [ set_system_NTPSERVERS_dhcp ] = string ( str_NTP_flag ) ;
map_error [ set_system_NTPSERVERS ] = string ( str_NTP_flag ) ;
map_error [ remove_system_NTPSERVERS ] = string ( str_NTP_flag ) ;
map_error [ set_system_HWCLOCK_SYNC_localtime ] = string ( str_hardware_time_flag ) ;
map_error [ set_system_HWCLOCK_SYNC_utc ] = string ( str_hardware_time_flag ) ;
map_error [ set_global_ZONE ] = string ( str_time_zone_flag ) ;
map_error [ set_global_NTPSERVERS_default ] = string ( str_NTP_flag ) ;
map_error [ set_global_NTPSERVERS_dhcp ] = string ( str_NTP_flag ) ;
map_error [ set_global_NTPSERVERS ] = string ( str_NTP_flag ) ;
map_error [ remove_global_NTPSERVERS ] = string ( str_NTP_flag ) ;
map_error [ set_global_HWCLOCK_SYNC_localtime ] = string ( str_hardware_time_flag ) ;
map_error [ set_global_HWCLOCK_SYNC_utc ] = string ( str_hardware_time_flag ) ;
map_error [ get_NTPSERVERS_DEFAULT ] = string ( str_NTP_flag ) ;
map_error [ " date +%Y%m%d -s \" " ] = string ( str_date_flag ) ;
map_error [ " date +%T -s \" " ] = string ( str_date_flag ) ;
this - > get_builder ( ) ;
this - > add_CSS ( ) ;
Gtk : : Widget * boxWidget ;
@ -95,6 +86,11 @@ void MainWindow::settings() {
day = 0 ;
this - > lacalization ( ) ;
btnBoxAboutDialog - > set_visible ( false ) ;
# ifdef WEBKIT_FOUND
one = WEBKIT_WEB_VIEW ( webkit_web_view_new ( ) ) ;
three = Glib : : wrap ( GTK_WIDGET ( one ) ) ;
wndWeb - > add ( * three ) ;
# endif
if ( geteuid ( ) = = 0 ) {
numTimeHrs - > set_range ( 0 , 23 ) ;
numTimeMin - > set_range ( 0 , 59 ) ;
@ -106,8 +102,7 @@ void MainWindow::settings() {
this - > parse_text_date ( ) ;
this - > load_globl_cfg ( ) ;
this - > load_local_cfg ( ) ;
string cmd = " ubconfig --source default get [] NTPSERVERS_DEFAULT " ;
default_get_dhcp = this - > get_ubconfig_value ( cmd ) ;
default_get_dhcp = this - > get_ubconfig_value ( get_NTPSERVERS_DEFAULT ) ;
this - > str_remove ( default_get_dhcp , " \" " ) ;
}
else {
@ -116,9 +111,9 @@ void MainWindow::settings() {
boxButton - > set_sensitive ( false ) ;
btnSave - > set_sensitive ( false ) ;
this - > event ( ) ;
imgInfo - > set_from_icon_name ( " com.ublinux.ubl-settings-datetime.warning " , Gtk : : ICON_SIZE_MENU ) ;
info_status_app ( " boxInfoMessError " ) ;
lblWarning - > set_text ( gettext( " The program must be run as root " ) ) ;
imgInfo - > set_from_icon_name ( icon_warning , Gtk : : ICON_SIZE_MENU ) ;
info_status_app ( info_box_error_css ) ;
lblWarning - > set_text ( program_as_root ) ;
}
}
@ -126,40 +121,50 @@ void MainWindow::lacalization() {
time_t now = time ( 0 ) ;
tm * ltm = localtime ( & now ) ;
unsigned int year = 1900 + ltm - > tm_year ;
string str_authors = string ( gettext ( " Copyright © UBSoft LLC, 2022 - " ) ) + to_string ( year ) ;
string str_authors = string ( copyright ) + to_string ( year ) ;
aboutWindows - > set_program_name ( name_app ) ;
aboutWindows - > set_copyright ( str_authors ) ;
aboutWindows - > set_comments ( gettext ( " Date and Time " ) ) ;
aboutWindows - > set_website ( gettext ( " https://wiki.ublinux.com " ) ) ;
aboutWindows - > set_version ( gettext ( version_application . c_str ( ) ) ) ;
aboutWindows - > set_website_label ( gettext ( " Project Home Page " ) ) ;
lblSave - > set_label ( gettext ( " Save " ) ) ;
lblLoad - > set_label ( gettext ( " Load " ) ) ;
txtDate - > set_tooltip_text ( gettext ( " Date of \n Format: DD.MM.YYYY " ) ) ;
txtNtpServer - > set_tooltip_text ( gettext ( " Enter the name of the ntp-server or its ip-address. \n When entering multiple addresses, separate them with commas. " ) ) ;
lblSynchronizebChkGLob - > set_text ( gettext ( " Synchronize via NTP " ) ) ;
cbDhcp - > append ( gettext ( " Default " ) ) ;
cbDhcp - > append ( gettext ( " DHCP " ) ) ;
cbDhcp - > append ( gettext ( " Manual " ) ) ;
cbDhcp - > append ( gettext ( " Disabled " ) ) ;
lblDateTimeSetting - > set_text ( gettext ( " Current date and time " ) ) ;
lblHead - > set_text ( gettext ( " Setting the date and time " ) ) ;
lblTime - > set_text ( gettext ( " Time: " ) ) ;
lblData - > set_text ( gettext ( " Date: " ) ) ;
lblTimeZone - > set_text ( gettext ( " Time zone " ) ) ;
lblReg - > set_text ( gettext ( " Region: " ) ) ;
lblZone - > set_text ( gettext ( " Zone: " ) ) ;
lblSynchronizeBtn - > set_text ( gettext ( " Sync by " ) ) ;
lblHeader - > set_text ( gettext ( " ubl-settings-datetime " ) ) ;
windowMessDchp - > set_title ( gettext ( " Attention " ) ) ;
lblTimeBios - > set_text ( gettext ( " Synchronize hardware time " ) ) ;
lblHW - > set_text ( gettext ( " Synchronize hardware time: " ) ) ;
array_hw_local [ 0 ] = gettext ( " UTC time " ) ;
array_hw_local [ 1 ] = gettext ( " Local time " ) ;
aboutWindows - > set_comments ( str_date_time ) ;
aboutWindows - > set_website ( website ) ;
aboutWindows - > set_version ( _ ( version_application . c_str ( ) ) ) ;
aboutWindows - > set_website_label ( home_page ) ;
lblHeaderAboutTopic - > set_label ( str_about ) ;
lblSave - > set_label ( str_save ) ;
lblLoad - > set_label ( str_load ) ;
txtDate - > set_tooltip_text ( data_format_d_m_y ) ;
txtNtpServer - > set_tooltip_text ( enter_name_ntp_tooltip ) ;
lblSynchronizebChkGLob - > set_text ( synchronize_ntp ) ;
cbDhcp - > append ( str_default ) ;
cbDhcp - > append ( str_DHCP ) ;
cbDhcp - > append ( str_manual ) ;
cbDhcp - > append ( str_disabled ) ;
lblDateTimeSetting - > set_text ( current_date_time ) ;
lblHead - > set_text ( setting_date_time ) ;
lblTime - > set_text ( str_time ) ;
lblData - > set_text ( str_date ) ;
lblTimeZone - > set_text ( str_time_zone ) ;
lblReg - > set_text ( str_region ) ;
lblZone - > set_text ( str_zone ) ;
lblSynchronizeBtn - > set_text ( str_sync_by ) ;
lblHeader - > set_text ( name_app ) ;
lblHeadeWndWeb - > set_text ( name_app ) ;
windowMessDchp - > set_title ( str_attention ) ;
lblTimeBios - > set_text ( synchronize_hw ) ;
lblHW - > set_text ( string ( synchronize_hw ) + " : " ) ;
array_hw_local [ 0 ] = utc_time ;
array_hw_local [ 1 ] = str_local_time ;
array_hw [ 0 ] = " utc " ;
array_hw [ 1 ] = " localtime " ;
this - > bubble_sort ( array_hw , array_hw_local , 2 ) ;
cbHw - > append ( array_hw_local [ 0 ] ) ;
cbHw - > append ( array_hw_local [ 1 ] ) ;
lblhelpHeader - > set_text ( read_documentation_web ) ;
lblhelpText - > set_text ( redirected_documentation ) ;
btnReadHelp - > set_label ( read_online ) ;
btnCancelHelp - > set_label ( cancel ) ;
chkAlwaysOpenHelp - > set_label ( always_redirect ) ;
lblwebHeaderName - > set_label ( name_app ) ;
}
void MainWindow : : bubble_sort ( string arr [ ] , string arr_local [ ] , int len_arr ) {
@ -246,8 +251,8 @@ void MainWindow::add_CSS() {
void MainWindow : : info_status_app ( string stule ) {
Glib : : RefPtr < Gtk : : StyleContext > boxInfo = boxInfoError - > get_style_context ( ) ;
boxInfo - > remove_class ( " boxInfoMessOK " ) ;
boxInfo - > remove_class ( " boxInfoMessError " ) ;
boxInfo - > remove_class ( info_box_ok_css ) ;
boxInfo - > remove_class ( info_box_error_css ) ;
boxInfo - > add_class ( stule ) ;
}
@ -313,10 +318,26 @@ void MainWindow::get_builder() {
builder - > get_widget ( " boxWidgetFunc " , boxWidgetFunc ) ;
builder - > get_widget ( " overHead " , overHead ) ;
builder - > get_widget ( " imgHeadBackground " , imgHeadBackground ) ;
# ifdef WEBKIT_FOUND
builder - > get_widget ( " wndWeb " , wndWeb ) ;
# endif
builder - > get_widget ( " lblHeadeWndWeb " , lblHeadeWndWeb ) ;
builder - > get_widget ( " lblHeaderAboutTopic " , lblHeaderAboutTopic ) ;
builder - > get_widget ( " lblwebHeaderName " , lblwebHeaderName ) ;
builder - > get_widget ( " lblhelpText " , lblhelpText ) ;
builder - > get_widget ( " lblhelpHeader " , lblhelpHeader ) ;
builder - > get_widget ( " chkAlwaysOpenHelp " , chkAlwaysOpenHelp ) ;
builder - > get_widget ( " btnReadHelp " , btnReadHelp ) ;
builder - > get_widget ( " btnCancelHelp " , btnCancelHelp ) ;
builder - > get_widget ( " wndShowWeb " , wndShowWeb ) ;
}
void MainWindow : : event ( ) {
btnCancelHelp - > signal_clicked ( ) . connect ( [ & ] ( ) { wndShowWeb - > hide ( ) ; } ) ;
chkAlwaysOpenHelp - > signal_toggled ( ) . connect ( [ & ] ( ) { flag_open_browser = true ; } ) ;
btnReadHelp - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : open_browser ) ) ;
btnSynopsis - > signal_activate ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : synopsis_show ) ) ;
btnHardwareTime - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : hardware_clock ) ) ;
btnMessClose - > signal_clicked ( ) . connect ( sigc : : mem_fun ( * this , & MainWindow : : gui_mess_close ) ) ;
//cldrDate->signal_day_selected().connect(sigc::mem_fun(*this, &MainWindow::get_calendar));
@ -384,30 +405,46 @@ void MainWindow::event_zone() {
}
void MainWindow : : synopsis_show ( ) {
int start_error = error_info ;
string cmd = " xdg-open " + string ( gettext ( " https://wiki.ublinux.com/ru/Пр о г р а ммно е _о б е с пе че ние /Пр о г р а ммы_и_у тилиты/В с е / " ) ) + app_name ;
if ( geteuid ( ) = = 0 ) {
string response_user = getlogin ( ) ;
cmd = " su -l " + response_user + " -c \" DISPLAY=$DISPLAY " + cmd + " \" " ;
if ( flag_open_browser = = true ) {
this - > open_browser ( ) ;
}
wrapper_system ( cmd , " & " ) ;
if ( start_error ! = error_info ) {
error_info = start_error ;
else {
wndShowWeb - > show_all ( ) ;
}
}
void MainWindow : : open_browser ( ) {
# ifdef WEBKIT_FOUND
webkit_web_view_load_uri ( one , link_doc ) ;
wndWeb - > show_all ( ) ;
# else
this - > template_open_browser ( ) ;
# endif
}
void MainWindow : : template_open_browser ( ) {
string cmd = cmd_xdg + string ( _ ( link_doc ) ) + " & " ;
string buf = " " ;
if ( geteuid ( ) = = 0 ) {
string response_user = getlogin ( ) ;
int size_s = std : : snprintf ( nullptr , 0 , cmd_execute , response_user . c_str ( ) , cmd . c_str ( ) ) + 1 ;
auto size = static_cast < size_t > ( size_s ) ;
std : : unique_ptr < char [ ] > buf ( new char [ size ] ) ;
std : : snprintf ( buf . get ( ) , size , cmd_execute , response_user . c_str ( ) , cmd . c_str ( ) ) ;
cmd = std : : string ( buf . get ( ) , buf . get ( ) + size - 1 ) ;
}
index_error = system ( cmd . c_str ( ) ) ;
}
void MainWindow : : load_local_cfg ( ) {
flag_local_global_load = 0 ;
flag_load = false ;
string cmd_zone = " ubconfig --default --source system get clock ZONE " ;
this - > fill_in_reg_zone ( cmd_zone ) ;
this - > fill_in_reg_zone ( get_system_ZONE ) ;
this - > update_hour_minute ( ) ;
this - > update_calendar ( ) ;
string cmd_get_dhcp = " ubconfig --default --source system get network NTPSERVERS " ;
string cmd_default_get_dhcp = " ubconfig --source default get [] NTPSERVERS_DEFAULT " ;
this - > entry_dhcp_mess ( cmd_get_dhcp , cmd_default_get_dhcp ) ;
string hw = " ubconfig --default --source system get clock HWCLOCK_SYNC " ;
this - > get_hardware_clock ( hw ) ;
this - > entry_dhcp_mess ( get_system_NTPSERVERS , get_NTPSERVERS_DEFAULT ) ;
this - > get_hardware_clock ( get_system_HWCLOCK_SYNC ) ;
info_warning_error ( 0 ) ;
map_config_data_global_old = map_config_data_global ;
map_config_data_local_old = map_config_data_local ;
@ -417,13 +454,9 @@ void MainWindow::load_local_cfg() {
void MainWindow : : load_globl_cfg ( ) {
flag_local_global_load = 1 ;
flag_load = true ;
string cmd_get_dhcp = " ubconfig --default --source global get network NTPSERVERS " ;
string cmd_default_get_dhcp = " ubconfig --source default get [] NTPSERVERS_DEFAULT " ;
this - > entry_dhcp_mess ( cmd_get_dhcp , cmd_default_get_dhcp ) ;
string cmd_zone = " ubconfig --default --source global get clock ZONE " ;
this - > fill_in_reg_zone ( cmd_zone ) ;
string hw = " ubconfig --source global get clock HWCLOCK_SYNC " ;
this - > get_hardware_clock ( hw ) ;
this - > entry_dhcp_mess ( get_global_NTPSERVERS , get_NTPSERVERS_DEFAULT ) ;
this - > fill_in_reg_zone ( get_global_ZONE ) ;
this - > get_hardware_clock ( get_global_HWCLOCK_SYNC ) ;
info_warning_error ( 1 ) ;
map_config_data_global_old = map_config_data_global ;
map_config_data_local_old = map_config_data_local ;
@ -433,17 +466,17 @@ void MainWindow::load_globl_cfg() {
void MainWindow : : save_local_cfg ( ) {
if ( ( this - > check_config ( " region " , 0 ) & & this - > check_config ( " zone " , 0 ) & &
this - > check_config ( " dhcp " , 0 ) & & this - > check_config ( " hw " , 0 ) ) ) {
info_status_app ( " boxInfoMessOK " ) ;
lblWarning - > set_text ( gettext( " Nothing to save! " ) ) ;
info_status_app ( info_box_ok_css ) ;
lblWarning - > set_text ( nothing_save ) ;
}
else {
string cmd_zone = " ubconfig --target system set clock ZONE= " ;
string cmd_default = " ubconfig --target system set network NTPSERVERS=default " ;
string cmd_dhcp = " ubconfig --target system set network NTPSERVERS=dhcp " ;
string cmd_set_ntp = " ubconfig --target system set network NTPSERVERS= \" " ;
string remove_ntp = " ubconfig --target system remove network NTPSERVERS " ;
string local = " ubconfig --target system set clock HWCLOCK_SYNC=localtime " ;
string hw = " ubconfig --target system set clock HWCLOCK_SYNC=utc " ;
string cmd_zone = set_system_ZONE ;
string cmd_default = set_system_NTPSERVERS_default ;
string cmd_dhcp = set_system_NTPSERVERS_dhcp ;
string cmd_set_ntp = set_system_NTPSERVERS ;
string remove_ntp = remove_system_NTPSERVERS ;
string local = set_system_HWCLOCK_SYNC_localtime ;
string hw = set_system_HWCLOCK_SYNC_utc ;
if ( ( this - > check_config ( " region " , 0 ) = = false | | this - > check_config ( " zone " , 0 ) = = false ) ) {
this - > enter_zone ( cmd_zone ) ;
}
@ -462,17 +495,17 @@ void MainWindow::save_local_cfg() {
void MainWindow : : save_global_cfg ( ) {
if ( ( this - > check_config ( " region " , 1 ) & & this - > check_config ( " zone " , 1 ) & &
this - > check_config ( " dhcp " , 1 ) & & this - > check_config ( " hw " , 1 ) ) ) {
info_status_app ( " boxInfoMessOK " ) ;
lblWarning - > set_text ( gettext( " Nothing to save! " ) ) ;
info_status_app ( info_box_ok_css ) ;
lblWarning - > set_text ( nothing_save ) ;
}
else {
string cmd = " ubconfig --target global set clock ZONE= " ;
string cmd_default = " ubconfig --target global set network NTPSERVERS=default " ;
string cmd_dhcp = " ubconfig --target global set network NTPSERVERS=dhcp " ;
string cmd_set_ntp = " ubconfig --target global set network NTPSERVERS= \" " ;
string remove_ntp = " ubconfig --target global remove network NTPSERVERS " ;
string local = " ubconfig --target global set clock HWCLOCK_SYNC=localtime " ;
string hw = " ubconfig --target global set clock HWCLOCK_SYNC=utc " ;
string cmd = set_global_ZONE ;
string cmd_default = set_global_NTPSERVERS_default ;
string cmd_dhcp = set_global_NTPSERVERS_dhcp ;
string cmd_set_ntp = set_global_NTPSERVERS ;
string remove_ntp = remove_global_NTPSERVERS ;
string local = set_global_HWCLOCK_SYNC_localtime ;
string hw = set_global_HWCLOCK_SYNC_utc ;
if ( ( this - > check_config ( " region " , 1 ) = = false | | this - > check_config ( " zone " , 1 ) = = false ) ) {
this - > enter_zone ( cmd ) ;
}
@ -493,8 +526,8 @@ void MainWindow::save_global_local_cfg() {
this - > check_config ( " dhcp " , 0 ) & & this - > check_config ( " hw " , 0 ) ) & &
( this - > check_config ( " region " , 1 ) & & this - > check_config ( " zone " , 1 ) & &
this - > check_config ( " dhcp " , 1 ) & & this - > check_config ( " hw " , 1 ) ) ) {
info_status_app ( " boxInfoMessOK " ) ;
lblWarning - > set_text ( gettext( " Nothing to save! " ) ) ;
info_status_app ( info_box_ok_css ) ;
lblWarning - > set_text ( nothing_save ) ;
}
else {
string cmd = " " ;
@ -510,46 +543,46 @@ void MainWindow::save_global_local_cfg() {
if ( flag_global = = false ) { }
if ( ( this - > check_config ( " region " , 0 ) = = false | | this - > check_config ( " zone " , 0 ) = = false ) ) {
if ( flag_local = = false ) {
cmd_zone = " ubconfig --target system set clock ZONE= " ;
cmd_zone = set_system_ZONE ;
this - > enter_zone ( cmd_zone ) ;
}
}
if ( ( this - > check_config ( " region " , 1 ) = = false | | this - > check_config ( " zone " , 1 ) = = false ) ) {
if ( flag_global = = false ) {
cmd_zone = " ubconfig --target global set clock ZONE= " ;
cmd_zone = set_global_ZONE ;
this - > enter_zone ( cmd_zone ) ;
}
}
if ( this - > check_config ( " dhcp " , 0 ) = = false ) {
if ( flag_local = = false ) {
cmd_default = " ubconfig --target system set network NTPSERVERS=default " ;
cmd_dhcp = " ubconfig --target system set network NTPSERVERS=dhcp " ;
cmd_set_ntp = " ubconfig --target system set network NTPSERVERS= \" " ;
remove_ntp = " ubconfig --target system remove network NTPSERVERS " ;
cmd_default = set_system_NTPSERVERS_default ;
cmd_dhcp = set_system_NTPSERVERS_dhcp ;
cmd_set_ntp = set_system_NTPSERVERS ;
remove_ntp = remove_system_NTPSERVERS ;
this - > save_Dhcp ( cmd_default , cmd_dhcp , remove_ntp , cmd_set_ntp ) ;
}
}
if ( this - > check_config ( " dhcp " , 1 ) = = false ) {
if ( flag_global = = false ) {
cmd_default = " ubconfig --target global set network NTPSERVERS=default " ;
cmd_dhcp = " ubconfig --target global set network NTPSERVERS=dhcp " ;
cmd_set_ntp = " ubconfig --target global set network NTPSERVERS= \" " ;
remove_ntp = " ubconfig --target global remove network NTPSERVERS " ;
cmd_default = set_global_NTPSERVERS_default ;
cmd_dhcp = set_global_NTPSERVERS_dhcp ;
cmd_set_ntp = set_global_NTPSERVERS ;
remove_ntp = remove_global_NTPSERVERS ;
this - > save_Dhcp ( cmd_default , cmd_dhcp , remove_ntp , cmd_set_ntp ) ;
}
}
if ( this - > check_config ( " hw " , 0 ) = = false ) {
if ( flag_local = = false ) {
local = " ubconfig --target system set clock HWCLOCK_SYNC=localtime " ;
hw = " ubconfig --target system set clock HWCLOCK_SYNC=utc " ;
local = set_system_HWCLOCK_SYNC_localtime ;
hw = set_system_HWCLOCK_SYNC_utc ;
this - > set_hardware_clock ( local , hw ) ;
}
}
if ( this - > check_config ( " hw " , 1 ) = = false ) {
if ( flag_global = = false ) {
local = " ubconfig --target global set clock HWCLOCK_SYNC=localtime " ;
hw = " ubconfig --target global set clock HWCLOCK_SYNC=utc " ;
local = set_global_HWCLOCK_SYNC_localtime ;
hw = set_global_HWCLOCK_SYNC_utc ;
this - > set_hardware_clock ( local , hw ) ;
}
}
@ -668,7 +701,7 @@ bool MainWindow::check_config(string key, int key_save) {
return false ;
}
string MainWindow : : get_ubconfig_value ( string & cmd ) {
string MainWindow : : get_ubconfig_value ( string cmd ) {
struct Result < string > obj_result = this - > wrapper_call ( cmd ) ;
if ( obj_result . error = = 0 ) {
return obj_result . response ;
@ -684,50 +717,50 @@ string MainWindow::get_ubconfig_value(string &cmd){
void MainWindow : : info_warning_error ( int mess ) {
if ( error_info > 0 | | warning_info > 0 ) {
info_status_app ( " boxInfoMessError " ) ;
imgInfo - > set_from_icon_name ( " com.ublinux.ubl-settings-datetime.warning " , Gtk : : ICON_SIZE_MENU ) ;
info_status_app ( info_box_error_css ) ;
imgInfo - > set_from_icon_name ( icon_warning , Gtk : : ICON_SIZE_MENU ) ;
error_info = 0 ;
warning_info = 0 ;
string mess_error = " " ;
if ( mess = = 0 ) {
mess_error = string ( gettext( " Local configuration reading error " ) ) + cmd_error ;
mess_error = string ( local_read_error ) + cmd_error ;
lblWarning - > set_text ( mess_error ) ;
}
else if ( mess = = 1 ) {
mess_error = string ( g ettext( " Global configuration read error " ) ) + cmd_error ;
mess_error = string ( g lobal_read_error ) + cmd_error ;
lblWarning - > set_text ( mess_error ) ;
}
else if ( mess = = 2 ) {
mess_error = string ( gettext( " Local configuration write error " ) ) + cmd_error ;
mess_error = string ( local_write_error ) + cmd_error ;
lblWarning - > set_text ( mess_error ) ;
}
else if ( mess = = 3 ) {
mess_error = string ( g ettext( " Global configuration write error " ) ) + cmd_error ;
mess_error = string ( g lobal_write_error ) + cmd_error ;
lblWarning - > set_text ( mess_error ) ;
}
else if ( mess = = 4 ) {
mess_error = string ( gettext( " Error saved local and global configuration " ) ) + cmd_error ;
mess_error = string ( error_save_all ) + cmd_error ;
lblWarning - > set_text ( mess_error ) ;
}
cmd_error = " " ;
}
else {
info_status_app ( " boxInfoMessOK " ) ;
imgInfo - > set_from_icon_name ( " com.ublinux.ubl-settings-datetime.checked " , Gtk : : ICON_SIZE_MENU ) ; //Gtk::IconSize::INHERIT);
info_status_app ( info_box_ok_css ) ;
imgInfo - > set_from_icon_name ( icon_checked , Gtk : : ICON_SIZE_MENU ) ; //Gtk::IconSize::INHERIT);
if ( mess = = 0 ) {
lblWarning - > set_text ( gettext( " Local configuration downloaded successfully " ) ) ;
lblWarning - > set_text ( local_load_ok ) ;
}
else if ( mess = = 1 ) {
lblWarning - > set_text ( g ettext( " Global configuration downloaded successfully " ) ) ;
lblWarning - > set_text ( g lobal_load_ok ) ;
}
else if ( mess = = 2 ) {
lblWarning - > set_text ( gettext( " Local configuration successfully written " ) ) ;
lblWarning - > set_text ( local_ok_written ) ;
}
else if ( mess = = 3 ) {
lblWarning - > set_text ( g ettext( " Global configuration successfully written " ) ) ;
lblWarning - > set_text ( g lobal_ok_written ) ;
}
else if ( mess = = 4 ) {
lblWarning - > set_text ( gettext( " Successfully saved local and global configuration " ) ) ;
lblWarning - > set_text ( successfully_save_all ) ;
}
}
}
@ -772,7 +805,7 @@ void MainWindow::set_hardware_clock(string &local, string &etc) {
}
}
void MainWindow : : get_hardware_clock ( string & cmd ) {
void MainWindow : : get_hardware_clock ( string cmd ) {
int error = warning_info ;
struct Result < string > obj_result = this - > wrapper_call ( cmd ) ;
if ( obj_result . error = = 0 ) {
@ -810,15 +843,15 @@ void MainWindow::get_hardware_clock(string &cmd) {
void MainWindow : : hardware_clock ( ) {
int error_hw = error_info ;
string cmd = " hwclock --systohc " ;
string cmd = set_hwclock ;
wrapper_system ( cmd ) ;
if ( error_hw ! = error_info ) {
lblWarning - > set_text ( gettext( " Hardware clock synchronization error " ) ) ;
info_status_app ( " boxInfoMessError " ) ;
lblWarning - > set_text ( hardware_clock_error ) ;
info_status_app ( info_box_error_css ) ;
}
else {
lblWarning - > set_text ( gettext( " Hardware clock successfully synchronized " ) ) ;
info_status_app ( " boxInfoMessOK " ) ;
lblWarning - > set_text ( hardware_clock_ok ) ;
info_status_app ( info_box_ok_css ) ;
}
}
@ -828,8 +861,8 @@ void MainWindow::gui_mess_close() {
bool MainWindow : : focus_ntp_text ( ) {
if ( txtNtpServer - > get_text ( ) = = " " | | txtNtpServer - > get_text ( ) = = " " ) {
lblWarning - > set_text ( gettext( " Enter a list of NTP servers " ) ) ;
info_status_app ( " boxInfoMessError " ) ;
lblWarning - > set_text ( entry_list_ntp ) ;
info_status_app ( info_box_error_css ) ;
btnSave - > set_sensitive ( false ) ;
return false ;
}
@ -852,20 +885,20 @@ bool MainWindow::focus_ntp_text() {
}
if ( ( flag_error = = false ) & & ( flag_error_check_ntp = = false ) ) {
this - > write_config ( str_ntp , " dhcp " ) ;
lblWarning - > set_text ( gettext( " NTP server name is correct " ) ) ;
info_status_app ( " boxInfoMessOK " ) ;
lblWarning - > set_text ( ntp_server_ok ) ;
info_status_app ( info_box_ok_css ) ;
btnSave - > set_sensitive ( true ) ;
return true ;
}
else {
if ( flag_error = = true ) {
lblWarning - > set_text ( gettext( " An invalid character is entered " ) ) ;
info_status_app ( " boxInfoMessError " ) ;
lblWarning - > set_text ( invalid_character_entry ) ;
info_status_app ( info_box_error_css ) ;
btnSave - > set_sensitive ( false ) ;
}
else if ( flag_error_check_ntp = = true ) {
lblWarning - > set_text ( gettext( " Error in the NTP server name " ) ) ;
info_status_app ( " boxInfoMessError " ) ;
lblWarning - > set_text ( error_ntp_name ) ;
info_status_app ( info_box_error_css ) ;
btnSave - > set_sensitive ( false ) ;
}
return false ;
@ -1009,10 +1042,10 @@ void MainWindow::event_entry_cbDhcp() {
txtNtpServer - > grab_focus ( ) ;
string cmd = " " ;
if ( flag_load = = false ) {
cmd = " ubconfig --default --source system get network NTPSERVERS " ;
cmd = get_system_NTPSERVERS ;
}
else {
cmd = " ubconfig --default --source global get network NTPSERVERS " ;
cmd = get_global_NTPSERVERS ;
}
string response = this - > get_ubconfig_value ( cmd ) ;
if ( response ! = " dhcp " & & response ! = " default " ) {
@ -1100,8 +1133,8 @@ void MainWindow::entry_dhcp_mess(string cmd_get_dhcp, string cmd_default_get_dhc
// btnUpdateDateTime->set_sensitive(false);
if ( str_dhcp = = " " ) {
this - > write_config ( " " , " dhcp " ) ;
lblWarning - > set_text ( gettext( " Enter a list of NTP servers " ) ) ;
info_status_app ( " boxInfoMessError " ) ;
lblWarning - > set_text ( entry_list_ntp ) ;
info_status_app ( info_box_error_css ) ;
btnSave - > set_sensitive ( false ) ;
}
else if ( str_dhcp = = " (null) " ) {
@ -1177,7 +1210,7 @@ void MainWindow::calendar_show() {
popCalendar - > show ( ) ;
}
void MainWindow : : fill_in_reg_zone ( string & cmd ) {
void MainWindow : : fill_in_reg_zone ( string cmd ) {
int error = warning_info ;
struct Result < string > obj_result_1 = this - > wrapper_call ( cmd ) ;
if ( obj_result_1 . error = = 0 ) {
@ -1246,19 +1279,19 @@ void MainWindow::enter_zone(string &cmd) {
index + = 1 ;
}
if ( ! ( zone_text . empty ( ) ) ) {
str_zone = zone_text ;
str_region = reg_text ;
cmd = cmd + str_region + " / " + str_zone ;
str_zone _buff = zone_text ;
str_region _buff = reg_text ;
cmd = cmd + str_region _buff + " / " + str_zone _buff ;
wrapper_system ( cmd , " & " ) ;
}
else {
str_zone = " " ;
str_region = " " ;
str_zone _buff = " " ;
str_region _buff = " " ;
}
}
else {
str_zone = " " ;
str_region = " " ;
str_zone _buff = " " ;
str_region _buff = " " ;
}
}
@ -1274,13 +1307,13 @@ void MainWindow::parse_text_date() {
void MainWindow : : append_region_zone ( string region , string zone , Gtk : : ComboBoxText * tmpCbReg , Gtk : : ComboBoxText * tmpCbZone ) {
this - > write_config ( region , " region " ) ;
this - > write_config ( zone , " zone " ) ;
str_region = region ;
str_region _buff = region ;
int index = 0 ;
Glib : : ustring reg_local = " " ;
int size_vec = array_region_local . size ( ) ;
if ( size_vec = = 0 ) {
for ( auto & [ key , value ] : time_reg_map ) {
array_region_local . push_back ( string ( gettext ( key . c_str ( ) ) ) ) ;
array_region_local . push_back ( string ( _ ( key . c_str ( ) ) ) ) ;
array_region . push_back ( key ) ;
index + = 1 ;
}
@ -1306,7 +1339,7 @@ void MainWindow::append_region_zone(string region, string zone, Gtk::ComboBoxTex
if ( size_vec = = 0 ) {
tmpCbReg - > append ( Glib : : ustring ( reg ) ) ;
}
if ( reg = = string ( gettext ( region . c_str ( ) ) ) ) {
if ( reg = = string ( _ ( region . c_str ( ) ) ) ) {
tmpCbReg - > set_active_text ( reg ) ;
}
}
@ -1316,7 +1349,7 @@ void MainWindow::append_region_zone(string region, string zone, Gtk::ComboBoxTex
string path_reg_zone = " " ;
string zone_offest = " " ;
path_reg_zone = region + " / " + zone ;
zone_offest = this - > zone_file_read ( path_reg_zone ) + gettext ( zone . c_str ( ) ) ;
zone_offest = this - > zone_file_read ( path_reg_zone ) + _ ( zone . c_str ( ) ) ;
if ( region = = " " ) {
tmpCbZone - > append ( " " ) ;
tmpCbZone - > set_active ( 0 ) ;
@ -1376,12 +1409,12 @@ void MainWindow::append_zone() {
cbZone - > remove_all ( ) ;
int index = cbRegion - > get_active_row_number ( ) ;
if ( index ! = - 1 ) {
string str_region = array_region [ index ] ;
string str_region _buff = array_region [ index ] ;
string zone_mixing = " " ;
this - > write_config ( str_region , " region " ) ;
this - > write_config ( str_region _buff , " region " ) ;
string path_dir = " " ;
if ( str_region . length ( ) ! = 0 ) {
for ( const auto & _str_zone : time_reg_map_local . at ( str_region ) ) {
if ( str_region _buff . length ( ) ! = 0 ) {
for ( const auto & _str_zone : time_reg_map_local . at ( str_region _buff ) ) {
cbZone - > append ( Glib : : ustring ( _str_zone ) ) ;
}
}
@ -1420,8 +1453,8 @@ void MainWindow::update_time_date() {
year = 0 ;
month = 0 ;
day = 0 ;
lblWarning - > set_text ( gettext( " Date and time are successfully synchronized " ) ) ;
info_status_app ( " boxInfoMessOK " ) ;
lblWarning - > set_text ( date_time_ok_synchronized ) ;
info_status_app ( info_box_ok_css ) ;
flag_error_time = false ;
}
else {
@ -1438,8 +1471,8 @@ void MainWindow::update_time_date() {
day = 0 ;
}
if ( flag_error_time = = false ) {
lblWarning - > set_text ( gettext( " Date and time are successfully synchronized " ) ) ;
info_status_app ( " boxInfoMessOK " ) ;
lblWarning - > set_text ( date_time_ok_synchronized ) ;
info_status_app ( info_box_ok_css ) ;
hour = numTimeHrs - > get_value_as_int ( ) ;
minute = numTimeMin - > get_value_as_int ( ) ;
time_t now = time ( 0 ) ;
@ -1464,19 +1497,19 @@ bool MainWindow::post_entry_data() {
string str_error_clock = this - > call ( cmd ) ;
size_t index = str_error_clock . find ( " date: " ) ;
if ( index ! = std : : string : : npos ) {
lblWarning - > set_text ( gettext( " Incorrect date format " ) ) ;
info_status_app ( " boxInfoMessError " ) ;
lblWarning - > set_text ( incorrect_date_f ) ;
info_status_app ( info_box_error_css ) ;
return true ;
}
else {
lblWarning - > set_text ( gettext( " Date and time are successfully synchronized " ) ) ;
info_status_app ( " boxInfoMessOK " ) ;
lblWarning - > set_text ( date_time_ok_synchronized ) ;
info_status_app ( info_box_ok_css ) ;
return false ;
}
}
else {
lblWarning - > set_text ( gettext( " Incorrect date format " ) ) ;
info_status_app ( " boxInfoMessError " ) ;
lblWarning - > set_text ( incorrect_date_f ) ;
info_status_app ( info_box_error_css ) ;
return true ;
}
}
@ -1541,7 +1574,7 @@ void MainWindow::read_file() {
string reg_reg_zone = entry_reg_reg_zone . path ( ) . filename ( ) . string ( ) ;
zone . push_back ( reg_reg_zone ) ;
path_reg_zone = key_reg + " / " + reg_reg_zone ;
key_zone_local = this - > zone_file_read ( path_reg_zone ) + gettext ( reg_reg_zone . c_str ( ) ) ;
key_zone_local = this - > zone_file_read ( path_reg_zone ) + _ ( reg_reg_zone . c_str ( ) ) ;
zone_local . push_back ( key_zone_local ) ;
}
in2 . close ( ) ;
@ -1550,7 +1583,7 @@ void MainWindow::read_file() {
else if ( key_zone . length ( ) ! = 0 | | key_zone ! = " " ) {
zone . push_back ( key_zone ) ;
path_reg_zone = key_reg + " / " + key_zone ;
key_zone_local = this - > zone_file_read ( path_reg_zone ) + gettext ( key_zone . c_str ( ) ) ;
key_zone_local = this - > zone_file_read ( path_reg_zone ) + _ ( key_zone . c_str ( ) ) ;
zone_local . push_back ( key_zone_local ) ;
}
}
@ -1654,6 +1687,9 @@ string MainWindow::zone_file_read(string zone) {
return str_utc ;
}
MainWindow : : ~ MainWindow ( ) {
}
vector < std : : string > MainWindow : : split ( const std : : string & s , char delim ) {
std : : stringstream ss ( s ) ;
std : : string item ;
@ -1675,24 +1711,9 @@ SettingsPlug::SettingsPlug(::Window p_socketID, Glib::RefPtr<Gtk::Builder> build
}
void help ( ) {
string version = string ( gettext ( " ubl-settings-datetime version: " ) ) + version_application + " \n " ;
cout < < version . c_str ( ) ;
string help ;
help = " GTK settings datetime for UBLinux \n \n "
" Usage: ubl-settings-datetime [OPTIONS...] \n "
" Options: \n "
" -h, --help Show this help \n "
" -V, --version Show package version \n "
" --lock-datetime Lock date and time changes \n "
" --lock-timezone Lock time zone changes \n "
" --lock-ntp-mode Lock NTP mode selection \n "
" --lock-ntp-edit Lock editing NTP servers \n "
" --lock-sync-hwclock Lock sync hwclock mode selection \n "
" --lock-save Lock saving local and global configuration \n "
" --lock-save-local Lock save global configuration \n "
" --lock-save-global Lock load global configuration \n "
" --lock-load-global Lock load global configuration \n " ;
cout < < gettext ( help . c_str ( ) ) ;
string version = string ( str_version ) + version_application + " \n " ;
cout < < version . c_str ( ) ; ;
cout < < str_help_h ;
}