Починил makefile и иконки в .glade

pull/16/head
Igor Belitskiy 3 years ago
parent 83d57503e8
commit 0819e68a89

@ -1,16 +1,19 @@
#!/usr/bin/make -f #!/usr/bin/make -f
#!/usr/bin/make -f
#SHELL := /bin/bash
MAKEFILE_FILEPATH := $(abspath $(lastword $(MAKEFILE_LIST))) MAKEFILE_FILEPATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MAKEFILE_DIR := $(notdir $(patsubst %/,%,$(dir $(MAKEFILE_FILEPATH)))) MAKEFILE_DIR := $(notdir $(patsubst %/,%,$(dir $(MAKEFILE_FILEPATH))))
MAKEFILE_PATH := $(dir $(MAKEFILE_FILEPATH)) MAKEFILE_PATH := $(dir $(MAKEFILE_FILEPATH))
CMAKE_COMMAND = cmake CMAKE_COMMAND = cmake
#CMAKE_SOURCE_DIR = $(MAKEFILE_PATH)source
#CMAKE_BUILD_DIR = $(MAKEFILE_PATH)compile
CMAKE_SOURCE_DIR = ./source CMAKE_SOURCE_DIR = ./source
CMAKE_BUILD_DIR = ./compile CMAKE_BUILD_DIR = ./compile
DEPENDS = cmake DEPENDS = cmake
#PKGNAME = $(MAKEFILE_DIR)
PKGNAME = $(MAKEFILE_DIR) PKGNAME = ubl-settings-datetime
#PKGNAME = ubl-settings-datetime
default_target: all default_target: all
all: init build all: init build
@ -22,8 +25,8 @@ init:
depend: depend:
@echo "Check depends ..."; \ @echo "Check depends ..."; \
if [ ! -f /bin/${DEPENDS} ]; then \ if [ ! -f /bin/${DEPENDS} ]; then \
echo "-- Depend '${DEPENDS}' not fount !"; \ echo "-- Depend '${DEPENDS}' not fount !"; \
exit 1; \ exit 1; \
fi; \ fi; \
echo "Check depends: OK" echo "Check depends: OK"
# $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 # $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
@ -55,9 +58,6 @@ build: depend prepare
@echo "Build ..."; \ @echo "Build ..."; \
make --directory=${CMAKE_BUILD_DIR}; \ make --directory=${CMAKE_BUILD_DIR}; \
echo "Build: OK" echo "Build: OK"
g++ -Werror -Wall -Waddress -Wbool-compare -Wbool-operation -std=c++20 -o source/ubl_settings_datetime.o -c -lstdc++ source/ubl_settings_datetime.cc `pkg-config --cflags --libs gtkmm-3.0` -g;
g++ -Werror -Wall -Waddress -Wbool-compare -Wbool-operation -std=c++20 -o source/main.o -c -lstdc++ source/main.cc `pkg-config --cflags --libs gtkmm-3.0` -Wl,-export-dynamic -g -Wall -Waddress -Wbool-compare -Wbool-operation;
g++ -Werror -Wall -Waddress -Wbool-compare -Wbool-operation -o source/ubl_settings_datetime source/main.o source/ubl_settings_datetime.o `pkg-config --cflags --libs gtkmm-3.0` -Wl,-export-dynamic -g;
uninstall: uninstall:
@echo "Uninstall ..." @echo "Uninstall ..."
@ -78,7 +78,7 @@ uninstall:
done done
@$(RM) "/usr/bin/${PKGNAME}" @$(RM) "/usr/bin/${PKGNAME}"
@$(RM) "/usr/share/applications/${PKGNAME}.desktop" @$(RM) "/usr/share/applications/${PKGNAME}.desktop"
@$(RM) "/usr/share/polkit-1/actions/org.freedesktop.policykit.${PKGNAME}.pkexec.policy" @$(RM) "/usr/share/polkit-1/actions/ru.ublinux.pkexec.${PKGNAME}.exec.policy"
@$(RM) -rd "/usr/share/${PKGNAME}" @$(RM) -rd "/usr/share/${PKGNAME}"
@gtk-update-icon-cache -fiq /usr/share/icons/hicolor/ &>/dev/null @gtk-update-icon-cache -fiq /usr/share/icons/hicolor/ &>/dev/null
@update-desktop-database --quiet 2>/dev/null @update-desktop-database --quiet 2>/dev/null
@ -103,12 +103,12 @@ install: check uninstall
@install -Dm644 -t /usr/share/icons/hicolor/scalable/apps/ ${PKGNAME}.svg @install -Dm644 -t /usr/share/icons/hicolor/scalable/apps/ ${PKGNAME}.svg
@install -Dm755 -t /usr/bin/ ${CMAKE_BUILD_DIR}/${PKGNAME} @install -Dm755 -t /usr/bin/ ${CMAKE_BUILD_DIR}/${PKGNAME}
@install -Dm644 -t /usr/share/applications/ ${PKGNAME}.desktop @install -Dm644 -t /usr/share/applications/ ${PKGNAME}.desktop
@install -Dm644 -t /usr/share/polkit-1/actions/ org.freedesktop.policykit.${PKGNAME}.pkexec.policy @install -Dm644 -t /usr/share/polkit-1/actions/ ru.ublinux.pkexec.${PKGNAME}.exec.policy
@install -dm755 /usr/share/${PKGNAME}/{ui,images,reg} @install -dm755 /usr/share/${PKGNAME}/{ui,images,css}
@install -Dm644 -t /usr/share/${PKGNAME}/ui/ ${PKGNAME}.glade @install -Dm644 -t /usr/share/${PKGNAME}/ui/ ${PKGNAME}.glade
@install -Dm644 -t /usr/share/${PKGNAME}/css/ style.css
@install -Dm644 -t /usr/share/${PKGNAME}/images/ ${PKGNAME}.svg @install -Dm644 -t /usr/share/${PKGNAME}/images/ ${PKGNAME}.svg
@install -Dm644 -t /usr/share/${PKGNAME}/images/ ${PKGNAME}.png @install -Dm644 -t /usr/share/${PKGNAME}/images/ ${PKGNAME}.png
@cp -afr reg/* /usr/share/${PKGNAME}/reg/
@gtk-update-icon-cache -fiq /usr/share/icons/hicolor/ @gtk-update-icon-cache -fiq /usr/share/icons/hicolor/
@update-desktop-database --quiet 2>/dev/null @update-desktop-database --quiet 2>/dev/null
@touch /usr/share/applications @touch /usr/share/applications
@ -121,9 +121,6 @@ clean:
echo "Clean: error, compile directory exist ${CMAKE_BUILD_DIR}"; \ echo "Clean: error, compile directory exist ${CMAKE_BUILD_DIR}"; \
else \ else \
echo "Clean: OK"; \ echo "Clean: OK"; \
@$(RM) "${CMAKE_BUILD_DIR}/main.o"
@$(RM) "${CMAKE_BUILD_DIR}/${PKGNAME}.o"
@$(RM) "${CMAKE_BUILD_DIR}/${PKGNAME}"
fi fi
help: help:

@ -9,11 +9,12 @@ link_directories(${GTK_LIBRARY_DIRS})
add_definitions(${GTK_CFLAGS_OTHER}) add_definitions(${GTK_CFLAGS_OTHER})
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -std=c++2a") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always -std=c++2a")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Werror -Wmissing-declarations -fdiagnostics-color=always")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -fdiagnostics-color=always")
set(SOURCE_FILES set(SOURCE_FILES
ubl-settings-datetime.cpp) main.cc
ubl-settings-datetime.cc
ubl-settings-datetime.h)
set(LIBRARIES set(LIBRARIES
${GTK_LIBRARIES} ${GTK_LIBRARIES}

@ -19,7 +19,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h> #include <stdio.h>
#include "ubl_settings_datetime.h" #include "ubl-settings-datetime.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
string str_argv=""; string str_argv="";
string str_cmd_argv = ""; string str_cmd_argv = "";

@ -23,19 +23,19 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <vector> #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_glade= "/home/superadmin/Документы/Проект/ubconfig_new/ubl-settings-datetime/"; string path_app= "/usr/bin/";
string path_glade= "/usr/share/ubl-settings-datetime/ui/";
string app_name = "ubl-settings-datetime"; string app_name = "ubl-settings-datetime";
string path_locale = "/usr/share/locale/"; string path_locale = "/usr/share/locale/";
string path_css = "/home/superadmin/Документы/Проект/ubconfig_new/ubl-settings-datetime/style.css"; string path_css = "/usr/share/ubl-settings-datetime/css/style.css";
bool flag_datetime = false; bool flag_datetime = false;
bool flag_timezone = false; bool flag_timezone = false;
bool flag_ntp = false; bool flag_ntp = false;
bool flag_update = false; bool flag_update = false;
CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help) 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} : Glib::OptionGroup{p_name, p_description, p_help}
{ {
@ -44,21 +44,21 @@ CmdArgParser::CmdArgParser(const std::string& p_name, const std::string& p_descr
socketIDArg.set_short_name('s'); socketIDArg.set_short_name('s');
socketIDArg.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); socketIDArg.set_flags(Glib::OptionEntry::FLAG_IN_MAIN);
socketIDArg.set_description("Settings manager socket"); socketIDArg.set_description("Settings manager socket");
// Register it in the parser. It value will be recorded in m_socketID for later usage.
add_entry(socketIDArg, m_socketID); add_entry(socketIDArg, m_socketID);
} }
::Window CmdArgParser::GetSocketID() const ::Window CmdArgParser::GetSocketID() const
{ {
return m_socketID; return m_socketID;
} }
MainWindow::MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder) MainWindow::MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder)
: Gtk::ApplicationWindow(obj) : Gtk::ApplicationWindow(obj)
, builder{builder} , builder{builder}
{ {
this->settings(); this->settings();
} }
MainWindow::MainWindow(Glib::RefPtr<Gtk::Builder> const& builder) { MainWindow::MainWindow(Glib::RefPtr<Gtk::Builder> const& builder) {
this->builder = builder; this->builder = builder;
this->settings(); this->settings();
@ -72,7 +72,6 @@ void MainWindow::settings(){
_numTimeHrs->set_increments(1.0,1.0); _numTimeHrs->set_increments(1.0,1.0);
_numTimeMin->set_increments(1.0,1.0); _numTimeMin->set_increments(1.0,1.0);
this->lacalization(); this->lacalization();
//_txtDate->set_sensitive(false);
this->get_config(); this->get_config();
this->flag_block_gui(); this->flag_block_gui();
this->event(); this->event();
@ -81,7 +80,6 @@ void MainWindow::settings(){
void MainWindow::lacalization(){ void MainWindow::lacalization(){
_cbDhcp->append(gettext("DHCP")); _cbDhcp->append(gettext("DHCP"));
_cbDhcp->append(gettext("Manually")); _cbDhcp->append(gettext("Manually"));
_lblDateTimeSetting->set_text(gettext("Setting the date and time")); _lblDateTimeSetting->set_text(gettext("Setting the date and time"));
_lblNtpServer1->set_text(gettext("Setting the date and time")); _lblNtpServer1->set_text(gettext("Setting the date and time"));
_lblTime->set_text(gettext("Time")); _lblTime->set_text(gettext("Time"));
@ -98,9 +96,8 @@ void MainWindow::lacalization(){
this->set_title(gettext("ubl-settings-datetime")); this->set_title(gettext("ubl-settings-datetime"));
_txtDate->set_tooltip_text("Date of\nFormat: DD.MM.YYYY"); _txtDate->set_tooltip_text("Date of\nFormat: DD.MM.YYYY");
_mess_dchp->set_title("Warning!"); _mess_dchp->set_title("Warning!");
} }
void MainWindow::flag_block_gui(){ void MainWindow::flag_block_gui(){
if (flag_datetime==true){ if (flag_datetime==true){
_numTimeHrs->set_sensitive(false); _numTimeHrs->set_sensitive(false);
@ -125,6 +122,7 @@ void MainWindow::flag_block_gui(){
_btnUpdateDateTime->set_sensitive(false); _btnUpdateDateTime->set_sensitive(false);
} }
} }
void MainWindow::add_CSS(){ void MainWindow::add_CSS(){
Glib::RefPtr<Gtk::CssProvider> cssProvider = Gtk::CssProvider::create(); Glib::RefPtr<Gtk::CssProvider> cssProvider = Gtk::CssProvider::create();
cssProvider->load_from_path(path_css); cssProvider->load_from_path(path_css);
@ -134,9 +132,8 @@ void MainWindow::add_CSS(){
Glib::RefPtr<Gtk::StyleContext> context = _boxColor->get_style_context(); Glib::RefPtr<Gtk::StyleContext> context = _boxColor->get_style_context();
context->add_class("cssboxColor1"); context->add_class("cssboxColor1");
} }
void MainWindow::get_builder(){
void MainWindow::get_builder(){
builder->get_widget("boxColor", _boxColor); builder->get_widget("boxColor", _boxColor);
builder->get_widget("btnUpdateDateTime", _btnUpdateDateTime); builder->get_widget("btnUpdateDateTime", _btnUpdateDateTime);
builder->get_widget("btnChooseDate", _btnChooseDate); builder->get_widget("btnChooseDate", _btnChooseDate);
@ -169,7 +166,8 @@ void MainWindow::get_builder(){
builder->get_widget("lblSynchronizeBtn",_lblSynchronizeBtn); builder->get_widget("lblSynchronizeBtn",_lblSynchronizeBtn);
builder->get_widget("lblDateTimeSettingGlob",_lblDateTimeSettingGlob); builder->get_widget("lblDateTimeSettingGlob",_lblDateTimeSettingGlob);
this->add_CSS(); this->add_CSS();
} }
void MainWindow::event(){ void MainWindow::event(){
_btnMessClose->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::gui_mess_close)); _btnMessClose->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::gui_mess_close));
_cldrDate->signal_day_selected().connect(sigc::mem_fun(*this, &MainWindow::get_calendar)); _cldrDate->signal_day_selected().connect(sigc::mem_fun(*this, &MainWindow::get_calendar));
@ -189,7 +187,6 @@ void MainWindow::gui_mess_close(){
_mess_dchp->hide(); _mess_dchp->hide();
} }
bool MainWindow::focus_ntp(GdkEventFocus* event){ bool MainWindow::focus_ntp(GdkEventFocus* event){
if (event!=NULL){} if (event!=NULL){}
if (_txtNtpServer->get_text()=="" || _txtNtpServer->get_text()==" "){ if (_txtNtpServer->get_text()=="" || _txtNtpServer->get_text()==" "){
@ -205,9 +202,6 @@ bool MainWindow::focus_ntp(GdkEventFocus* event){
return true; return true;
} }
void MainWindow::event_entry_cbDhcp(){ void MainWindow::event_entry_cbDhcp(){
Glib::ustring str_dhcp = _cbDhcp->get_active_text(); Glib::ustring str_dhcp = _cbDhcp->get_active_text();
if (str_dhcp.length()!=0){ if (str_dhcp.length()!=0){
@ -234,7 +228,6 @@ void MainWindow::event_entry_cbDhcp(){
else{ else{
string cmd = "/usr/bin/ubconfig set network NTPSERVERS=dhcp"; string cmd = "/usr/bin/ubconfig set network NTPSERVERS=dhcp";
system(cmd.c_str()); system(cmd.c_str());
//_txtNtpServer->set_sensitive(false);
_cbDhcp->set_active(0); _cbDhcp->set_active(0);
} }
} }
@ -243,7 +236,6 @@ void MainWindow::get_calendar(){
string str_month = ""; string str_month = "";
string str_day = ""; string str_day = "";
_cldrDate->get_date(year, month, day); _cldrDate->get_date(year, month, day);
if (month <10){ if (month <10){
str_month = "0"+to_string(month+1); str_month = "0"+to_string(month+1);
} }
@ -259,8 +251,7 @@ void MainWindow::get_calendar(){
string date = str_day + '.' + str_month + '.' + to_string(year); string date = str_day + '.' + str_month + '.' + to_string(year);
_txtDate->set_text(date); _txtDate->set_text(date);
_popCalendar->hide(); _popCalendar->hide();
} }
void MainWindow::calendar_show(){ void MainWindow::calendar_show(){
if (year==0){ if (year==0){
@ -289,7 +280,6 @@ void MainWindow::enry_dhcp_mess(){
if (str_dhcp=="dhcp"){ if (str_dhcp=="dhcp"){
_cbDhcp->set_active(0); _cbDhcp->set_active(0);
_txtNtpServer->set_sensitive(false); _txtNtpServer->set_sensitive(false);
//_cbxSynchronizeNtp->set_sensitive(true);
} }
else{ else{
if (str_dhcp==""){ if (str_dhcp==""){
@ -298,12 +288,9 @@ void MainWindow::enry_dhcp_mess(){
} }
else{ else{
_cbDhcp->set_active(1); _cbDhcp->set_active(1);
//_txtNtpServer->set_sensitive(true);
//_cbxSynchronizeNtp->set_sensitive(false);
_txtNtpServer->set_text(str_dhcp); _txtNtpServer->set_text(str_dhcp);
} }
} }
//_cbxDhcp->set_active(true);
this->set_ntp_toggle(); this->set_ntp_toggle();
} }
else{ else{
@ -312,11 +299,11 @@ void MainWindow::enry_dhcp_mess(){
_txtNtpServer->set_sensitive(0); _txtNtpServer->set_sensitive(0);
} }
} }
void MainWindow::get_config(){ void MainWindow::get_config(){
this->read_file(); this->read_file();
this->update_hour_minute(); this->update_hour_minute();
this->update_calendar(); this->update_calendar();
//this->event_entry_cbDhcp();
this->enry_dhcp_mess(); this->enry_dhcp_mess();
string str_ntp = this->call("systemctl status ntpd.service systemd-timesyncd.service | grep \"Active: active\""); string str_ntp = this->call("systemctl status ntpd.service systemd-timesyncd.service | grep \"Active: active\"");
if (str_ntp.length()<50) { if (str_ntp.length()<50) {
@ -325,7 +312,6 @@ void MainWindow::get_config(){
else{ else{
_cbxSynchronizeNtp->set_active(true); _cbxSynchronizeNtp->set_active(true);
} }
string read_reg_zon_cfg = this->call("/usr/bin/ubconfig get clock ZONE"); string read_reg_zon_cfg = this->call("/usr/bin/ubconfig get clock ZONE");
if ((read_reg_zon_cfg != "") && (read_reg_zon_cfg !="(null)")){ if ((read_reg_zon_cfg != "") && (read_reg_zon_cfg !="(null)")){
read_reg_zon_cfg = read_reg_zon_cfg.substr(read_reg_zon_cfg.find("=")+1,read_reg_zon_cfg.length()); read_reg_zon_cfg = read_reg_zon_cfg.substr(read_reg_zon_cfg.find("=")+1,read_reg_zon_cfg.length());
@ -334,7 +320,6 @@ void MainWindow::get_config(){
string str_filling_zon = read_reg_zon_cfg.substr(read_reg_zon_cfg.find("/")+1,read_reg_zon_cfg.length()); string str_filling_zon = read_reg_zon_cfg.substr(read_reg_zon_cfg.find("/")+1,read_reg_zon_cfg.length());
str_filling_zon = str_filling_zon.substr(0,str_filling_zon.find("\n")); str_filling_zon = str_filling_zon.substr(0,str_filling_zon.find("\n"));
string str_zone_check = ""; string str_zone_check = "";
cout << str_filling_zon << endl;
this->append_region_zone(str_filling_reg,str_filling_zon); this->append_region_zone(str_filling_reg,str_filling_zon);
} }
else { else {
@ -365,9 +350,7 @@ void MainWindow::parse_text_date(){
string day = data.substr(0,2); string day = data.substr(0,2);
string month1 = data.substr(3,2); string month1 = data.substr(3,2);
string year = data.substr(6,data.length()); string year = data.substr(6,data.length());
cout << day << " " << month1 << " " << year << endl;
} }
} }
void MainWindow::enter_zone_glob(){ void MainWindow::enter_zone_glob(){
@ -388,7 +371,6 @@ void MainWindow::enter_zone_glob(){
void MainWindow::set_ntp_toggle(){ void MainWindow::set_ntp_toggle(){
bool flag = _cbxSynchronizeNtp->get_active(); bool flag = _cbxSynchronizeNtp->get_active();
if (flag_datetime==true){ if (flag_datetime==true){
} }
else { else {
_numTimeHrs->set_sensitive(!flag); _numTimeHrs->set_sensitive(!flag);
@ -396,8 +378,6 @@ void MainWindow::set_ntp_toggle(){
_btnChooseDate->set_sensitive(!flag); _btnChooseDate->set_sensitive(!flag);
_txtDate->set_sensitive(!flag); _txtDate->set_sensitive(!flag);
} }
//_txtDate->set_sensitive(!flag);
//_btnUpdateDateTime->set_sensitive(!flag);
string cmd = ""; string cmd = "";
if (flag==false){ if (flag==false){
cmd="systemctl --now disable systemd-timesyncd.service ntpd.service"; cmd="systemctl --now disable systemd-timesyncd.service ntpd.service";
@ -442,18 +422,14 @@ 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){
cout << 3 << endl;
exit(1); exit(1);
} }
while (fgets(path, PATH_MAX, fp) != NULL){ while (fgets(path, PATH_MAX, fp) != NULL){
printf("%s", path); printf("%s", path);
break; break;
} }
status = pclose(fp); status = pclose(fp);
if (status == -1) { if (status == -1) {
cout << 1 << endl;
exit(1); exit(1);
} }
else { else {
@ -464,14 +440,12 @@ string MainWindow::call(string cmd){
void MainWindow::append_zone(){ void MainWindow::append_zone(){
Glib::ustring text = _cbRegion->get_active_text(); Glib::ustring text = _cbRegion->get_active_text();
_cbZone->remove_all(); _cbZone->remove_all();
if(!(text.empty())){ if(!(text.empty())){
str_region = text; str_region = text;
for (const auto &_str_zone : time_reg_map.at(str_region)){ for (const auto &_str_zone : time_reg_map.at(str_region)){
_cbZone->append(_str_zone); _cbZone->append(_str_zone);
} }
} }
} }
void MainWindow::append_zone_glob(){ void MainWindow::append_zone_glob(){
@ -482,8 +456,9 @@ void MainWindow::append_zone_glob(){
for (const auto &_str_zone : time_reg_map.at(str_region_glob)){ for (const auto &_str_zone : time_reg_map.at(str_region_glob)){
_cbZoneGlob->append(_str_zone); _cbZoneGlob->append(_str_zone);
} }
} }
} }
void MainWindow::update_time_date(){ void MainWindow::update_time_date(){
this->enter_zone(); this->enter_zone();
bool flag = _cbxSynchronizeNtp->get_active(); bool flag = _cbxSynchronizeNtp->get_active();
@ -526,7 +501,6 @@ void MainWindow::update_time_date(){
string str_error_clock = this->call(cmd); string str_error_clock = this->call(cmd);
size_t index = str_error_clock.find("date: "); size_t index = str_error_clock.find("date: ");
if (index==std::string::npos){ if (index==std::string::npos){
} }
} }
else{ else{
@ -547,6 +521,7 @@ void MainWindow::update_time_date(){
cmd = "hwclock --systohc"; cmd = "hwclock --systohc";
system(cmd.c_str()); system(cmd.c_str());
} }
void MainWindow::update_hour_minute(){ void MainWindow::update_hour_minute(){
time_t now = time(0); time_t now = time(0);
tm *ltm = localtime(&now); tm *ltm = localtime(&now);
@ -581,54 +556,40 @@ void MainWindow::update_calendar(){
void MainWindow::read_file(){ void MainWindow::read_file(){
std::string line; std::string line;
namespace fs = std::filesystem; namespace fs = std::filesystem;
for (const auto & entry : fs::directory_iterator("/usr/share/zoneinfo/")){ for (const auto & entry : fs::directory_iterator("/usr/share/zoneinfo/")){
std::ifstream in(entry.path()); // окрываем файл для чтения std::ifstream in(entry.path()); // окрываем файл для чтения
if (in.is_open()) if (in.is_open()){
{ string key_reg = entry.path().filename().string();
string key_reg = entry.path().filename().string(); string path_dir = "/usr/share/zoneinfo/"+key_reg;
if (fs::is_directory(path_dir)){
string path_dir = "/usr/share/zoneinfo/"+key_reg; vector<string> zone;
if (fs::is_directory(path_dir)){ zone.push_back("");
vector<string> zone; for (const auto & entry_zone : fs::directory_iterator(path_dir)){
zone.push_back(""); std::ifstream in1(entry_zone.path()); // окрываем файл для чтения
for (const auto & entry_zone : fs::directory_iterator(path_dir)){ if (in1.is_open()){
std::ifstream in1(entry_zone.path()); // окрываем файл для чтения string key_zone = entry_zone.path().filename().string();
if (in1.is_open()) if (key_zone.length()!=0 || key_zone!=" "){
{ zone.push_back(string(gettext(key_zone.c_str())));
string key_zone = entry_zone.path().filename().string();
if (key_zone.length()!=0 || key_zone!=" "){
zone.push_back(string(gettext(key_zone.c_str())));
}
} }
in1.close();
}
key_reg = string(gettext(key_reg.c_str()));
time_reg_map.insert({key_reg, zone});
while (getline(in, line))
{
} }
in1.close();
}
key_reg = string(gettext(key_reg.c_str()));
time_reg_map.insert({key_reg, zone});
} }
} }
in.close(); in.close();
} }
} }
vector<std::string> MainWindow::split(const std::string &s, char delim){ vector<std::string> MainWindow::split(const std::string &s, char delim){
std::stringstream ss(s); std::stringstream ss(s);
std::string item; std::string item;
std::vector<std::string> elems; std::vector<std::string> elems;
while (std::getline(ss, item, delim)) { while (std::getline(ss, item, delim)) {
elems.push_back(item); elems.push_back(item);
// elems.push_back(std::move(item)); // if C++11 (based on comment from @mchiasson)
} }
return elems; return elems;
} }
@ -636,8 +597,6 @@ vector<std::string> MainWindow::split(const std::string &s, char delim){
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}
{ {
//MainWindow* wnd = nullptr;
//builder->get_widget_derived("window", wnd);
builder->get_widget("plugBox", plugBox); builder->get_widget("plugBox", plugBox);
plugBox->get_parent()->remove(*plugBox); plugBox->get_parent()->remove(*plugBox);
add(*plugBox); add(*plugBox);

@ -23,7 +23,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h> #include <stdio.h>
using namespace std; using namespace std;
// g++ -Wall -Waddress -Wbool-compare -Wbool-operation -O2 -std=c++20 -lstdc++ -o main.cc `pkg-config --cflags --libs gtkmm-3.0` -Wl,-export-dynamic -g
extern string path_app; extern string path_app;
extern string path_glade; extern string path_glade;
extern string app_name; extern string app_name;
@ -34,29 +34,15 @@ extern bool flag_timezone;
extern bool flag_ntp; extern bool flag_ntp;
extern bool flag_update; extern bool flag_update;
class CmdArgParser : public Glib::OptionGroup class CmdArgParser : public Glib::OptionGroup
{ {
public: public:
CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help); CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help);
// Override this to handle errors. I skipped it for simplicity.
// void on_error(Glib::OptionContext& context, const Glib::Error& error) override;
::Window GetSocketID() const; ::Window GetSocketID() const;
private: private:
int m_socketID = 0; int m_socketID = 0;
}; };
class MainWindow : public Gtk::ApplicationWindow { class MainWindow : public Gtk::ApplicationWindow {
public: public:
MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder); MainWindow(BaseObjectType* obj, Glib::RefPtr<Gtk::Builder> const& builder);
@ -98,7 +84,6 @@ class MainWindow : public Gtk::ApplicationWindow {
Gtk::SpinButton *_numTimeMin; Gtk::SpinButton *_numTimeMin;
Gtk::CheckButton *_cbxSynchronizeNtp; Gtk::CheckButton *_cbxSynchronizeNtp;
Gtk::Box *_boxColor; Gtk::Box *_boxColor;
Gtk::Entry *_txtDate; Gtk::Entry *_txtDate;
Gtk::ComboBoxText *_cbRegion; Gtk::ComboBoxText *_cbRegion;
Gtk::ComboBoxText *_cbRegionGlob; Gtk::ComboBoxText *_cbRegionGlob;
@ -109,7 +94,6 @@ class MainWindow : public Gtk::ApplicationWindow {
Gtk::Popover *_popCalendar; Gtk::Popover *_popCalendar;
Gtk::Calendar *_cldrDate; Gtk::Calendar *_cldrDate;
Gtk::Label *_lblMessage; Gtk::Label *_lblMessage;
Gtk::Label *_lblDateTimeSetting; Gtk::Label *_lblDateTimeSetting;
Gtk::Label *_lblNtpServer1; Gtk::Label *_lblNtpServer1;
Gtk::Label *_lblTime; Gtk::Label *_lblTime;
@ -123,10 +107,10 @@ class MainWindow : public Gtk::ApplicationWindow {
Gtk::Label *_lblSynchronizebChk; Gtk::Label *_lblSynchronizebChk;
Gtk::Label *_lblSynchronizeBtn; Gtk::Label *_lblSynchronizeBtn;
Gtk::Label *_lblDateTimeSettingGlob; Gtk::Label *_lblDateTimeSettingGlob;
std::map <string, vector<string>> time_reg_map;
unsigned int year=0;
unsigned int month=0;
unsigned int year=0, month=0, day=0; unsigned int day=0;
int hour; int hour;
int minute; int minute;
string str_region=""; string str_region="";
@ -135,21 +119,17 @@ class MainWindow : public Gtk::ApplicationWindow {
string str_txtNtpServer; string str_txtNtpServer;
string str_zone=""; string str_zone="";
string str_zoneGlob; string str_zoneGlob;
std::map <string, vector<string>> time_reg_map;
}; };
class SettingsPlug : public Gtk::Plug class SettingsPlug : public Gtk::Plug
{ {
public: public:
Gtk::Window *window; Gtk::Window *window;
SettingsPlug(::Window p_socketID, Glib::RefPtr<Gtk::Builder> builder); SettingsPlug(::Window p_socketID, Glib::RefPtr<Gtk::Builder> builder);
private: private:
Gtk::Widget *plugBox; Gtk::Widget *plugBox;
Gtk::Widget *parent; Gtk::Widget *parent;
}; };
void help(); void help();
#endif #endif

@ -5,7 +5,6 @@
<object class="GtkWindow" id="mess_dchp"> <object class="GtkWindow" id="mess_dchp">
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="title" translatable="yes">Внимание!</property> <property name="title" translatable="yes">Внимание!</property>
<property name="icon">usr/share/icons/hicolor/scalable/apps/ubl-settings-datetime.png</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property> <property name="visible">True</property>
@ -83,7 +82,6 @@
<object class="GtkWindow" id="window"> <object class="GtkWindow" id="window">
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="title" translatable="yes" context="Settings the date and time" comments="Date and Time Settings">Настройки даты и времени</property> <property name="title" translatable="yes" context="Settings the date and time" comments="Date and Time Settings">Настройки даты и времени</property>
<property name="icon">usr/share/icons/hicolor/scalable/apps/ubl-settings-datetime.png</property>
<child> <child>
<object class="GtkBox" id="id_plug"> <object class="GtkBox" id="id_plug">
<property name="visible">True</property> <property name="visible">True</property>
@ -104,7 +102,8 @@
<property name="margin-end">5</property> <property name="margin-end">5</property>
<property name="margin-top">6</property> <property name="margin-top">6</property>
<property name="margin-bottom">6</property> <property name="margin-bottom">6</property>
<property name="pixbuf">usr/share/icons/hicolor/scalable/apps/ubl-settings-datetime.png</property> <property name="pixel-size">69</property>
<property name="icon-name">ubl-settings-datetime</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>

Loading…
Cancel
Save