|
|
|
@ -20,6 +20,9 @@
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include "ubl_settings_datetime.h"
|
|
|
|
#include "ubl_settings_datetime.h"
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
string path_app= "/home/superadmin/Документы/Проект/ubconfig_new/ubl-settings-datetime/source/";
|
|
|
|
string path_app= "/home/superadmin/Документы/Проект/ubconfig_new/ubl-settings-datetime/source/";
|
|
|
|
@ -59,6 +62,7 @@ MainWindow::MainWindow(Glib::RefPtr<Gtk::Builder> const& builder) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::settings(){
|
|
|
|
void MainWindow::settings(){
|
|
|
|
|
|
|
|
year=0, month=0, day=0;
|
|
|
|
this->get_builder();
|
|
|
|
this->get_builder();
|
|
|
|
_numTimeHrs->set_range(0,23);
|
|
|
|
_numTimeHrs->set_range(0,23);
|
|
|
|
_numTimeMin->set_range(0,59);
|
|
|
|
_numTimeMin->set_range(0,59);
|
|
|
|
@ -286,8 +290,10 @@ void MainWindow::enter_zone(){
|
|
|
|
if(!(zone_text.empty()) && !(reg_text.empty())){
|
|
|
|
if(!(zone_text.empty()) && !(reg_text.empty())){
|
|
|
|
str_zone=zone_text.substr(zone_text.find(") ")+2,zone_text.length());
|
|
|
|
str_zone=zone_text.substr(zone_text.find(") ")+2,zone_text.length());
|
|
|
|
str_region=reg_text;
|
|
|
|
str_region=reg_text;
|
|
|
|
string cmd = "timedatectl set-timezone '" + str_region +"/" + str_zone+"'";
|
|
|
|
string cmd = "rm -f /etc/localtime";
|
|
|
|
system(cmd.c_str());
|
|
|
|
system(cmd.c_str());
|
|
|
|
|
|
|
|
string cmd1 = "ln -s /usr/share/zoneinfo/" + str_region + "/" + str_zone+" /etc/localtime";
|
|
|
|
|
|
|
|
system(cmd1.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
str_zone="";
|
|
|
|
str_zone="";
|
|
|
|
@ -322,11 +328,14 @@ void MainWindow::set_ntp_toggle(){
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//_txtDate->set_sensitive(!flag);
|
|
|
|
//_txtDate->set_sensitive(!flag);
|
|
|
|
//_btnUpdateDateTime->set_sensitive(!flag);
|
|
|
|
//_btnUpdateDateTime->set_sensitive(!flag);
|
|
|
|
|
|
|
|
string cmd = "";
|
|
|
|
if (flag==false){
|
|
|
|
if (flag==false){
|
|
|
|
system("systemctl --now disable systemd-timesyncd.service ntpd.service");
|
|
|
|
cmd="systemctl --now disable systemd-timesyncd.service ntpd.service";
|
|
|
|
|
|
|
|
system(cmd.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
system("systemctl --now enable systemd-timesyncd.service");
|
|
|
|
cmd = "systemctl --now enable systemd-timesyncd.service";
|
|
|
|
|
|
|
|
system(cmd.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -363,7 +372,8 @@ string MainWindow::call(string cmd){
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char path[PATH_MAX];
|
|
|
|
fp = popen(cmd.c_str(), "r");
|
|
|
|
fp = popen(cmd.c_str(), "r");
|
|
|
|
if (fp == NULL){
|
|
|
|
if (fp == NULL){
|
|
|
|
//return "";
|
|
|
|
cout << 3 << endl;
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (fgets(path, PATH_MAX, fp) != NULL){
|
|
|
|
while (fgets(path, PATH_MAX, fp) != NULL){
|
|
|
|
@ -373,10 +383,10 @@ string MainWindow::call(string cmd){
|
|
|
|
|
|
|
|
|
|
|
|
status = pclose(fp);
|
|
|
|
status = pclose(fp);
|
|
|
|
if (status == -1) {
|
|
|
|
if (status == -1) {
|
|
|
|
//return "";
|
|
|
|
cout << 1 << endl;
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
//return "";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -412,21 +422,16 @@ void MainWindow::update_time_date(){
|
|
|
|
minute = _numTimeMin->get_value_as_int();
|
|
|
|
minute = _numTimeMin->get_value_as_int();
|
|
|
|
time_t now = time(0);
|
|
|
|
time_t now = time(0);
|
|
|
|
tm *ltm = localtime(&now);
|
|
|
|
tm *ltm = localtime(&now);
|
|
|
|
string cmd = "timedatectl set-time \""+
|
|
|
|
string cmd = "date +%T -s \""+
|
|
|
|
to_string(hour) + ":" + to_string(minute)
|
|
|
|
to_string(hour) + ":" + to_string(minute)
|
|
|
|
+ ":" + to_string(ltm->tm_sec) +"\"";
|
|
|
|
+ ":" + to_string(ltm->tm_sec) +"\"";
|
|
|
|
system(cmd.c_str());
|
|
|
|
system(cmd.c_str());
|
|
|
|
if ((year==0) && (month == 0) && (day == 0)){
|
|
|
|
if ((year!=0) && (month !=0) && (day !=0)){
|
|
|
|
time_t now = time(0);
|
|
|
|
|
|
|
|
tm *ltm = localtime(&now);
|
|
|
|
|
|
|
|
year=1900+ ltm->tm_year;
|
|
|
|
|
|
|
|
month=ltm->tm_mon;
|
|
|
|
|
|
|
|
day=ltm->tm_mday;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
string str_month = "";
|
|
|
|
string str_month = "";
|
|
|
|
string str_day = "";
|
|
|
|
string str_day = "";
|
|
|
|
|
|
|
|
month+=2;
|
|
|
|
if (month <10){
|
|
|
|
if (month <10){
|
|
|
|
str_month = "0"+to_string(month+1);
|
|
|
|
str_month = "0"+to_string(month);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
str_month = to_string(month);
|
|
|
|
str_month = to_string(month);
|
|
|
|
@ -437,10 +442,14 @@ void MainWindow::update_time_date(){
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
str_day = to_string(day);
|
|
|
|
str_day = to_string(day);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
string cmd1 = "date --set=\"" +to_string(year)+
|
|
|
|
cmd = "date +%Y%m%d -s \"" + to_string(year)+
|
|
|
|
str_month+str_day + " " +to_string(hour) + ":" +
|
|
|
|
str_month+str_day+"\"";
|
|
|
|
to_string(minute)+"\"";
|
|
|
|
system(cmd.c_str());
|
|
|
|
system(cmd1.c_str());
|
|
|
|
cmd = "hwclock --systohc";
|
|
|
|
|
|
|
|
system(cmd.c_str());
|
|
|
|
|
|
|
|
_txtDate->set_text(str_day+"." + str_month+"." + to_string(year));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void MainWindow::update_hour_minute(){
|
|
|
|
void MainWindow::update_hour_minute(){
|
|
|
|
@ -453,7 +462,7 @@ void MainWindow::update_hour_minute(){
|
|
|
|
void MainWindow::update_calendar(){
|
|
|
|
void MainWindow::update_calendar(){
|
|
|
|
time_t now = time(0);
|
|
|
|
time_t now = time(0);
|
|
|
|
tm *ltm = localtime(&now);
|
|
|
|
tm *ltm = localtime(&now);
|
|
|
|
int year = 1900 + (int)ltm->tm_year;
|
|
|
|
int year1 = 1900 + (int)ltm->tm_year;
|
|
|
|
string str_month = "";
|
|
|
|
string str_month = "";
|
|
|
|
string str_day = "";
|
|
|
|
string str_day = "";
|
|
|
|
unsigned int month, day;
|
|
|
|
unsigned int month, day;
|
|
|
|
@ -471,10 +480,38 @@ void MainWindow::update_calendar(){
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
str_day = to_string(day);
|
|
|
|
str_day = to_string(day);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
string date = str_day + '.' + str_month + '.' + to_string(year);
|
|
|
|
string date = str_day + '.' + str_month + '.' + to_string(year1);
|
|
|
|
_txtDate->set_text(date);
|
|
|
|
_txtDate->set_text(date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
void MainWindow::read_file(){
|
|
|
|
|
|
|
|
string cmd_reg = "find /usr/share/zoneinfo/* -maxdepth 0 -type d -not \\( -name posix -o -name right \\) -printf \"%f\n\"";
|
|
|
|
|
|
|
|
string str_reg_all = this->call(cmd_reg);
|
|
|
|
|
|
|
|
cout << 222 << endl;
|
|
|
|
|
|
|
|
cout << 222 << endl;
|
|
|
|
|
|
|
|
cout << str_reg_all << endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char delim = '\n';
|
|
|
|
|
|
|
|
vector<std::string> vector_reg=this->split(str_reg_all, delim);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string str_zone_all = "";
|
|
|
|
|
|
|
|
string cmd_zone = "";
|
|
|
|
|
|
|
|
string key_reg = "";
|
|
|
|
|
|
|
|
for (const auto &str_reg : vector_reg){
|
|
|
|
|
|
|
|
cmd_zone = "find /usr/share/zoneinfo/"+str_reg+"/* -type f -printf \"%f\n\" | sort -u";
|
|
|
|
|
|
|
|
str_zone_all=this->call(cmd_zone);
|
|
|
|
|
|
|
|
vector<std::string> vector_zone = this->split(str_zone_all, delim);
|
|
|
|
|
|
|
|
vector<string> zone;
|
|
|
|
|
|
|
|
zone.push_back("");
|
|
|
|
|
|
|
|
for (const auto &str_zone : vector_zone){
|
|
|
|
|
|
|
|
zone.push_back(string(gettext(str_zone.c_str())));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
key_reg = string(gettext(key_reg.c_str()));
|
|
|
|
|
|
|
|
time_reg_map.insert({str_reg, zone});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
void MainWindow::read_file(){
|
|
|
|
void MainWindow::read_file(){
|
|
|
|
std::string line;
|
|
|
|
std::string line;
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
@ -495,7 +532,16 @@ void MainWindow::read_file(){
|
|
|
|
in.close();
|
|
|
|
in.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<std::string> MainWindow::split(const std::string &s, char delim){
|
|
|
|
|
|
|
|
std::stringstream ss(s);
|
|
|
|
|
|
|
|
std::string item;
|
|
|
|
|
|
|
|
std::vector<std::string> elems;
|
|
|
|
|
|
|
|
while (std::getline(ss, item, delim)) {
|
|
|
|
|
|
|
|
elems.push_back(item);
|
|
|
|
|
|
|
|
// elems.push_back(std::move(item)); // if C++11 (based on comment from @mchiasson)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return elems;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SettingsPlug::SettingsPlug(::Window p_socketID, Glib::RefPtr<Gtk::Builder> builder)
|
|
|
|
SettingsPlug::SettingsPlug(::Window p_socketID, Glib::RefPtr<Gtk::Builder> builder)
|
|
|
|
: Gtk::Plug{p_socketID}
|
|
|
|
: Gtk::Plug{p_socketID}
|
|
|
|
|