Исправлена синхронизация

pull/16/head
Igor Belitskiy 3 years ago
parent b6775f6b89
commit ec92b44668

@ -0,0 +1 @@
/usr/share/zoneinfo/Asia/Bishkek/etc/localtime

Binary file not shown.

@ -20,6 +20,9 @@
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include "ubl_settings_datetime.h"
using namespace std;
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(){
year=0, month=0, day=0;
this->get_builder();
_numTimeHrs->set_range(0,23);
_numTimeMin->set_range(0,59);
@ -286,8 +290,10 @@ void MainWindow::enter_zone(){
if(!(zone_text.empty()) && !(reg_text.empty())){
str_zone=zone_text.substr(zone_text.find(") ")+2,zone_text.length());
str_region=reg_text;
string cmd = "timedatectl set-timezone '" + str_region +"/" + str_zone+"'";
string cmd = "rm -f /etc/localtime";
system(cmd.c_str());
string cmd1 = "ln -s /usr/share/zoneinfo/" + str_region + "/" + str_zone+" /etc/localtime";
system(cmd1.c_str());
}
else{
str_zone="";
@ -322,12 +328,15 @@ void MainWindow::set_ntp_toggle(){
}
//_txtDate->set_sensitive(!flag);
//_btnUpdateDateTime->set_sensitive(!flag);
string cmd = "";
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 {
system("systemctl --now enable systemd-timesyncd.service");
}
cmd = "systemctl --now enable systemd-timesyncd.service";
system(cmd.c_str());
}
}
void MainWindow::append_region_zone(string region, string zone){
@ -363,7 +372,8 @@ string MainWindow::call(string cmd){
char path[PATH_MAX];
fp = popen(cmd.c_str(), "r");
if (fp == NULL){
//return "";
cout << 3 << endl;
exit(1);
}
while (fgets(path, PATH_MAX, fp) != NULL){
@ -373,10 +383,10 @@ string MainWindow::call(string cmd){
status = pclose(fp);
if (status == -1) {
//return "";
cout << 1 << endl;
exit(1);
}
else {
//return "";
}
return path;
}
@ -412,35 +422,34 @@ void MainWindow::update_time_date(){
minute = _numTimeMin->get_value_as_int();
time_t now = time(0);
tm *ltm = localtime(&now);
string cmd = "timedatectl set-time \""+
string cmd = "date +%T -s \""+
to_string(hour) + ":" + to_string(minute)
+ ":" + to_string(ltm->tm_sec) +"\"";
system(cmd.c_str());
if ((year!=0) && (month !=0) && (day !=0)){
string str_month = "";
string str_day = "";
month+=2;
if (month <10){
str_month = "0"+to_string(month);
}
else{
str_month = to_string(month);
}
if (day <10){
str_day = "0"+to_string(day);
}
else{
str_day = to_string(day);
}
cmd = "date +%Y%m%d -s \"" + to_string(year)+
str_month+str_day+"\"";
system(cmd.c_str());
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_day = "";
if (month <10){
str_month = "0"+to_string(month+1);
}
else{
str_month = to_string(month);
}
if (day <10){
str_day = "0"+to_string(day);
}
else{
str_day = to_string(day);
cmd = "hwclock --systohc";
system(cmd.c_str());
_txtDate->set_text(str_day+"." + str_month+"." + to_string(year));
}
string cmd1 = "date --set=\"" +to_string(year)+
str_month+str_day + " " +to_string(hour) + ":" +
to_string(minute)+"\"";
system(cmd1.c_str());
}
}
void MainWindow::update_hour_minute(){
@ -453,7 +462,7 @@ void MainWindow::update_hour_minute(){
void MainWindow::update_calendar(){
time_t now = time(0);
tm *ltm = localtime(&now);
int year = 1900 + (int)ltm->tm_year;
int year1 = 1900 + (int)ltm->tm_year;
string str_month = "";
string str_day = "";
unsigned int month, day;
@ -471,10 +480,38 @@ void MainWindow::update_calendar(){
else{
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);
}
/*
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(){
std::string line;
namespace fs = std::filesystem;
@ -495,7 +532,16 @@ void MainWindow::read_file(){
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)
: Gtk::Plug{p_socketID}

@ -1,6 +1,5 @@
#ifndef UBL_SETTINGS_DATETIME_H
#define UBL_SETTINGS_DATETIME_H
//g++ -O2 -std=c++20 -lstdc++-c ubl-settings-datetime.h ubl-settings-datetime.cc `pkg-config --cflags --libs gtkmm-3.0` -Wl,-export-dynamic -g
#include <gtkmm/window.h>
#include <stddef.h>
#include <cstddef>
@ -84,7 +83,7 @@ public:
void update_hour_minute();
void update_calendar();
void read_file();
vector<std::string> split(const std::string &s, char delim);
private:
Glib::RefPtr<Gtk::Builder> builder;
Gtk::Button *_btnUpdateDateTime;
@ -104,7 +103,7 @@ private:
Gtk::Window *_mess_dchp;
Gtk::Popover *_popCalendar;
Gtk::Calendar *_cldrDate;
unsigned int year, month, day;
unsigned int year=0, month=0, day=0;
int hour;
int minute;
string str_region="";

Loading…
Cancel
Save