From ae47c17807731b23d35dddeeb167b4079459e3ac Mon Sep 17 00:00:00 2001 From: amid Date: Sun, 22 Jan 2023 16:36:19 +0600 Subject: [PATCH] Many fix --- .gitignore | 1 - Makefile | 178 ++++++++++++------ ...icykit.ubl-settings-datetime.pkexec.policy | 14 +- source/CMakeLists.txt | 24 +++ .../ubl-settings-datetime.cpp | 37 ++-- ubl-settings-datetime.desktop | 13 +- ubl-settings-datetime.glade | 6 +- ubl-settings-datetime.po | 6 +- 8 files changed, 184 insertions(+), 95 deletions(-) create mode 100644 source/CMakeLists.txt rename ubl-settings-datetime.cpp => source/ubl-settings-datetime.cpp (92%) diff --git a/.gitignore b/.gitignore index 0611a0e..33f5078 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -UBTime main.cpp ubl-settings-datetime.glade~ test.cpp diff --git a/Makefile b/Makefile index 9ca9003..5a2f583 100644 --- a/Makefile +++ b/Makefile @@ -1,71 +1,129 @@ #!/usr/bin/make -f -pkgname=ubl-settings-datetime +MAKEFILE_FILEPATH := $(abspath $(lastword $(MAKEFILE_LIST))) +MAKEFILE_DIR := $(notdir $(patsubst %/,%,$(dir $(MAKEFILE_FILEPATH)))) +MAKEFILE_PATH := $(dir $(MAKEFILE_FILEPATH)) -all: uninstall init build check install clean +CMAKE_COMMAND = cmake +CMAKE_SOURCE_DIR = ./source +CMAKE_BUILD_DIR = ./compile +DEPENDS = cmake + +PKGNAME = $(MAKEFILE_DIR) +#PKGNAME = ubl-settings-datetime + +default_target: all +all: init build init: - mkdir -p /usr/share/${pkgname}/{images,ui,reg}/; + @echo "Initialize ..."; \ + echo "-- Build path: ${CMAKE_BUILD_DIR}" + +depend: + @echo "Check depends ..."; \ + if [ ! -f /bin/${DEPENDS} ]; then \ + echo "-- Depend '${DEPENDS}' not fount !"; \ + exit 1; \ + fi; \ + echo "Check depends: OK" +# $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 -uninstall: - @for size in 16 32 48; do \ - rm -f "/usr/share/icons/hicolor/$${size}x$${size}/apps/ublinux-datetime-settings.svg"; \ - rm -f "/usr/share/icons/hicolor/$${size}x$${size}/apps/ublinux-datetime-settings.png"; \ - done; - @for file_po in *.po; do \ - lang=$${file_po##*_};lang=$${lang%.*}; \ - file_mo=$${file_po##*/}; file_mo="$${file_mo%_*.po}.mo"; \ - path_file_mo="/usr/share/locale/$${lang}/LC_MESSAGES/$${file_mo}"; \ - rm -f "/usr/share/locale/$${lang}/LC_MESSAGES/$${file_mo}"; \ - done; - rm -f /usr/bin/${pkgname}; \ - rm -rf /usr/bin/${pkgname}/reg; \ - rm -f /usr/share/${pkgname}/ui/${pkgname}.glade; \ - rm -f /usr/share/applications/${pkgname}.desktop; \ - rm -f /usr/share/${pkgname}/images/ublinux-datetime-settings.svg; \ - rm -f /usr/share/${pkgname}/images/ublinux-datetime-settings.png; \ - rm -f /usr/share/polkit-1/actions/org.freedesktop.policykit.${pkgname}.pkexec.policy; \ +debug: + @echo "Debug ..." + if [ ! -d ${CMAKE_BUILD_DIR} ]; then \ + $(CMAKE_COMMAND) -S${CMAKE_SOURCE_DIR} -B${CMAKE_BUILD_DIR} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="/usr"; \ + fi; \ + echo "Debug: OK" -build: - echo "Build"; \ - g++ -O2 -std=c++20 -lstdc++ -o ubl-settings-datetime ubl-settings-datetime.cpp `pkg-config --cflags --libs gtkmm-3.0` -Wl,-export-dynamic -g; \ +prepare: + @echo "Prepare ..."; \ + if [ ! -d ${CMAKE_BUILD_DIR} ]; then \ + $(CMAKE_COMMAND) -S${CMAKE_SOURCE_DIR} -B${CMAKE_BUILD_DIR} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="/usr"; \ + fi; \ + echo "Prepare: OK" check: - echo "Check"; \ + @echo "Check ..."; \ + if [ -f ${CMAKE_BUILD_DIR}/${PKGNAME} ]; then \ + echo "Check: OK"; \ + else \ + echo "Check: ${CMAKE_BUILD_DIR}/${PKGNAME} not fount !"; \ + exit 1; \ + fi + +build: depend prepare + @echo "Build ..."; \ + make --directory=${CMAKE_BUILD_DIR}; \ + echo "Build: OK" +# g++ -O2 -std=c++20 -lstdc++ -o ubl-settings-datetime ubl-settings-datetime.cpp `pkg-config --cflags --libs gtkmm-3.0` -Wl,-export-dynamic -g + +uninstall: + @echo "Uninstall ..." + @for FILE_PO in $(wildcard *.po); do \ + LANG=$${FILE_PO##*_};LANG=$${LANG%.*}; \ + FILE_MO=$${FILE_PO##*/}; FILE_MO="$${FILE_MO%_*.po}.mo"; \ + PATH_FILE_MO="/usr/share/locale/$${LANG}/LC_MESSAGES/$${FILE_MO}"; \ + $(RM) "/usr/share/locale/$${LANG}/LC_MESSAGES/$${FILE_MO}"; \ + done + @for SIZE in 16x16 32x32 48x48 scalable; do \ + $(RM) "/usr/share/icons/hicolor/$${SIZE}/apps/${PKGNAME}.svg"; \ + $(RM) "/usr/share/icons/hicolor/$${SIZE}/apps/${PKGNAME}.png"; \ + done + @for FILE_SVG in $(wildcard *.svg); do \ + for SIZE in 16x16 32x32 48x48 scalable; do \ + $(RM) "/usr/share/icons/hicolor/$${SIZE}/status/$${FILE_SVG%.*}".{svg,png,jpg}; \ + done; \ + done + @$(RM) "/usr/bin/${PKGNAME}" + @$(RM) "/usr/share/applications/${PKGNAME}.desktop" + @$(RM) "/usr/share/polkit-1/actions/org.freedesktop.policykit.${PKGNAME}.pkexec.policy" + @$(RM) -rd "/usr/share/${PKGNAME}" + $(shell gtk-update-icon-cache -fiq /usr/share/icons/hicolor/ &>/dev/null) + @echo "Uninstall: OK" + +install: check uninstall + @echo "Install ..." + @for FILE_PO in $(wildcard *.po); do \ + LANG=$${FILE_PO##*_};LANG=$${LANG%.*}; \ + install -dm755 /usr/share/locale/$${LANG}/LC_MESSAGES; \ + FILE_MO=$${FILE_PO##*/}; FILE_MO="$${FILE_MO%_*.po}.mo"; \ + PATH_FILE_MO="/usr/share/locale/$${LANG}/LC_MESSAGES/$${FILE_MO}"; \ + echo $${FILE_PO}; \ + msgfmt "$${FILE_PO}" -v -f -o "$${PATH_FILE_MO}"; \ + done + @for SIZE in 16 32 48; do \ + install -dm755 /usr/share/icons/hicolor/$${SIZE}x$${SIZE}/apps; \ + rsvg-convert -w $${SIZE} -h $${SIZE} -f svg --keep-image-data ${PKGNAME}.svg -o "/usr/share/icons/hicolor/$${SIZE}x$${SIZE}/apps/${PKGNAME}.svg"; \ + done + @install -dm755 /usr/share/icons/hicolor/scalable/apps + @install -Dm644 -t /usr/share/icons/hicolor/scalable/apps/ ${PKGNAME}.svg + @install -Dm755 -t /usr/bin/ ${CMAKE_BUILD_DIR}/${PKGNAME} + @install -Dm644 -t /usr/share/applications/ ${PKGNAME}.desktop + @install -Dm644 -t /usr/share/polkit-1/actions/ org.freedesktop.policykit.${PKGNAME}.pkexec.policy + @install -dm755 /usr/share/${PKGNAME}/{ui,images,reg} + @install -Dm644 -t /usr/share/${PKGNAME}/ui/ ${PKGNAME}.glade + @install -Dm644 -t /usr/share/${PKGNAME}/images/ ${PKGNAME}.svg + @install -Dm644 -t /usr/share/${PKGNAME}/images/ ${PKGNAME}.png + @cp -afr reg/* /usr/share/${PKGNAME}/reg/ + $(shell gtk-update-icon-cache -fiq /usr/share/icons/hicolor/) + @echo "Install: OK" -install: - @for size in 16 32 48; do \ - install -dm755 /usr/share/icons/hicolor/$${size}x$${size}/apps; \ - rsvg-convert -w $$size -h $$size -f svg --keep-image-data ${pkgname}.svg -o "/usr/share/icons/hicolor/$${size}x$${size}/apps/$${pkgname}.svg"; \ - done; - @for file_po in *.po; do \ - lang=$${file_po##*_};lang=$${lang%.*}; \ - install -dm755 /usr/share/locale/$${lang}/LC_MESSAGES; \ - file_mo=$${file_po##*/}; file_mo="$${file_mo%_*.po}.mo"; \ - path_file_mo="/usr/share/locale/$${lang}/LC_MESSAGES/$${file_mo}"; \ - echo $$file_po; \ - msgfmt "$${file_po}" -v -f -o "$${path_file_mo}"; \ - done; - install -vDm0755 ${pkgname} -t /usr/bin/; \ - install -vDm0644 ${pkgname}.glade -t /usr/share/${pkgname}/ui/; \ - install -vDm0644 ${pkgname}.desktop -t /usr/share/applications/; \ - install -vDm0644 ubl-settings-datetime.svg -t /usr/share/icons/hicolor/scalable/apps/ - install -vDm0644 ubl-settings-datetime.svg -t /usr/share/${pkgname}/images/; \ - install -vDm0644 ubl-settings-datetime.png -t /usr/share/${pkgname}/images/; \ - install -vDm0644 org.freedesktop.policykit.${pkgname}.pkexec.policy -t /usr/share/polkit-1/actions/; - install -vDm0644 reg/Africa -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/America -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/Antarctica -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/Arctic -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/Asia -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/Atlantic -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/Australia -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/Brazil -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/Chile -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/Europe -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/Indian -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/Mexico -t /usr/share/${pkgname}/reg/; \ - install -vDm0644 reg/US -t /usr/share/${pkgname}/reg/; clean: - echo "Clean"; - \ No newline at end of file + @echo "Clean ..." + @$(RM) -rd ${CMAKE_BUILD_DIR} + @if [ -d ${CMAKE_BUILD_DIR} ]; then \ + echo "Clean: error, compile directory exist ${CMAKE_BUILD_DIR}"; \ + else \ + echo "Clean: OK"; \ + fi + +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... init" + @echo "... debug" + @echo "... prepare" + @echo "... compile" + @echo "... install" + @echo "... uninstall" + @echo "... clean" diff --git a/org.freedesktop.policykit.ubl-settings-datetime.pkexec.policy b/org.freedesktop.policykit.ubl-settings-datetime.pkexec.policy index eb3e5c8..bd85ed6 100644 --- a/org.freedesktop.policykit.ubl-settings-datetime.pkexec.policy +++ b/org.freedesktop.policykit.ubl-settings-datetime.pkexec.policy @@ -4,20 +4,20 @@ "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"> - UBSoft + UBLinux https://ublinux.ru - - Run ubl-settings-datetime as root - Запуск ubl-settings-datetime с правами root - Authentication is required to run the ubl-settings-datetime - Требуется авторизация для запуска ubl-settings-datetime с правами root + + Run "Time date settings" as root + Запуск настройки даты и времени" с правами root + Authentication is required to run the time date settings + Требуется авторизация для запуска настройки даты и времени с правами root auth_admin auth_admin auth_admin - /home/superadmin/Документы/Проект/ubconfig_new/ubl-settings-datetime/ + /usr/bin/ubl-settings-datetime true diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt new file mode 100644 index 0000000..e4f8297 --- /dev/null +++ b/source/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.7) +project(ubl-settings-datetime) + +find_package(PkgConfig REQUIRED) + +pkg_check_modules(GTK REQUIRED gtkmm-3.0) +include_directories(${GTK_INCLUDE_DIRS}) +link_directories(${GTK_LIBRARY_DIRS}) +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") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -fdiagnostics-color=always") + +set(SOURCE_FILES + ubl-settings-datetime.cpp) + +set(LIBRARIES + ${GTK_LIBRARIES} + pthread) + +add_executable(ubl-settings-datetime ${SOURCE_FILES}) +target_link_libraries(ubl-settings-datetime ${LIBRARIES}) +install(TARGETS ubl-settings-datetime DESTINATION bin) diff --git a/ubl-settings-datetime.cpp b/source/ubl-settings-datetime.cpp similarity index 92% rename from ubl-settings-datetime.cpp rename to source/ubl-settings-datetime.cpp index fd83206..6c05d25 100644 --- a/ubl-settings-datetime.cpp +++ b/source/ubl-settings-datetime.cpp @@ -170,7 +170,7 @@ public: } else{ string cmd = ""; - cmd = "sudo /usr/bin/ubconfig set network NTPSERVERS=" + _txtNtpServer->get_text(); + cmd = "/usr/bin/ubconfig set network NTPSERVERS=" + _txtNtpServer->get_text(); this->call(cmd.c_str()); } @@ -184,14 +184,14 @@ public: Glib::ustring str_dhcp = _cbDhcp->get_active_text(); if (str_dhcp.length()!=0){ if (str_dhcp=="DHCP"){ - string cmd = "sudo /usr/bin/ubconfig set network NTPSERVERS=dhcp"; + string cmd = "/usr/bin/ubconfig set network NTPSERVERS=dhcp"; system(cmd.c_str()); _txtNtpServer->set_sensitive(false); _cbDhcp->set_active(0); _txtNtpServer->set_text(""); } else{ - string str_dhcp = this->call("sudo /usr/bin/ubconfig get network NTPSERVERS"); + string str_dhcp = this->call("/usr/bin/ubconfig get network NTPSERVERS"); if ((str_dhcp!="") && (str_dhcp!="(null)") ){ str_dhcp = str_dhcp.substr(str_dhcp.find("=")+1,str_dhcp.length()); @@ -207,7 +207,7 @@ public: } } else{ - string cmd = "sudo /usr/bin/ubconfig set network NTPSERVERS=dhcp"; + string cmd = "/usr/bin/ubconfig set network NTPSERVERS=dhcp"; system(cmd.c_str()); //_txtNtpServer->set_sensitive(false); _cbDhcp->set_active(0); @@ -250,7 +250,7 @@ public: } void enry_dhcp_mess(){ - string str_dhcp = this->call("sudo /usr/bin/ubconfig get network NTPSERVERS"); + string str_dhcp = this->call("/usr/bin/ubconfig get network NTPSERVERS"); if ((str_dhcp!="") && (str_dhcp!="(null)")){ _cbxSynchronizeNtp->set_active(1); str_dhcp = str_dhcp.substr(str_dhcp.find("=")+1,str_dhcp.length()); @@ -290,7 +290,7 @@ public: //this->event_entry_cbDhcp(); this->enry_dhcp_mess(); - string str_ntp = this->call("sudo 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) { _cbxSynchronizeNtp->set_active(false); } @@ -298,7 +298,7 @@ public: _cbxSynchronizeNtp->set_active(true); } - string read_reg_zon_cfg = this->call("sudo /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)")){ 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(0,read_reg_zon_cfg.find("\n")); @@ -321,7 +321,7 @@ public: 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 = "sudo timedatectl set-timezone '" + str_region +"/" + str_zone+"'"; + string cmd = "timedatectl set-timezone '" + str_region +"/" + str_zone+"'"; system(cmd.c_str()); } else{ @@ -336,7 +336,7 @@ public: if(!(zone_text.empty()) && !(reg_text.empty())){ str_zoneGlob = zone_text.substr(zone_text.find(") ")+2,zone_text.length()); str_region_glob = reg_text; - string cmd = "sudo /usr/bin/ubconfig set clock ZONE=" +str_region_glob +"/" + str_zoneGlob; + string cmd = "/usr/bin/ubconfig set clock ZONE=" +str_region_glob +"/" + str_zoneGlob; system(cmd.c_str()); } else{ @@ -360,10 +360,10 @@ public: //_btnUpdateDateTime->set_sensitive(!flag); if (flag==false){ - system("sudo systemctl --now disable systemd-timesyncd.service ntpd.service"); + system("systemctl --now disable systemd-timesyncd.service ntpd.service"); } else { - system("sudo systemctl --now enable systemd-timesyncd.service"); + system("systemctl --now enable systemd-timesyncd.service"); } } @@ -452,7 +452,7 @@ public: minute = _numTimeMin->get_value_as_int(); time_t now = time(0); tm *ltm = localtime(&now); - string cmd = "sudo timedatectl set-time \""+ + string cmd = "timedatectl set-time \""+ to_string(hour) + ":" + to_string(minute) + ":" + to_string(ltm->tm_sec) +"\""; system(cmd.c_str()); @@ -477,7 +477,7 @@ public: else{ str_day = to_string(day); } - string cmd1 = "sudo date --set=\"" +to_string(year)+ + string cmd1 = "date --set=\"" +to_string(year)+ str_month+str_day + " " +to_string(hour) + ":" + to_string(minute)+"\""; system(cmd1.c_str()); @@ -594,6 +594,12 @@ private: }; void help(){ + g_print("Usage: ubl-settings-datetime [--lock-timezone] [--lock-ntp] [--lock-datetime] [--lock-update]\n"); + g_print("Options:\n"); + g_print(" --lock-timezone Disable timezone field editing\n"); + g_print(" --lock-ntp Disable ntp field editing\n"); + g_print(" --lock-datetime Disable datetime field editing\n"); + g_print(" --lock-update Disable save changes\n"); cout << "Параметры командной строки --lock-datetime\n --lock-timezone\n --lock-ntp\n --lock-update\n" << endl; } @@ -611,7 +617,8 @@ int main(int argc, char* argv[]) { } if (geteuid()!=0){ - string cmd = "pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY " + path_app + app_name + " " + str_cmd_argv ; +// string cmd = "pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY " + path_app + app_name + " " + str_cmd_argv ; + string cmd = "pkexec " + app_name + " " + str_cmd_argv ; system(cmd.c_str()); return 0; } @@ -625,7 +632,7 @@ int main(int argc, char* argv[]) { int index=1; cout << argv[0] << endl; for (int i=0; i False - UBconfig - Дата и время - ../../../../../../usr/share/ubl-settings-datetime/images/ubl-settings-datetime.png + Настройки даты и времени + /usr/share/ubl-settings-datetime/images/ubl-settings-datetime.png True @@ -108,7 +108,7 @@ 5 6 6 - ../../../../../../usr/share/ubl-settings-datetime/images/ubl-settings-datetime.png + /usr/share/ubl-settings-datetime/images/ubl-settings-datetime.png False diff --git a/ubl-settings-datetime.po b/ubl-settings-datetime.po index b74586b..902df90 100644 --- a/ubl-settings-datetime.po +++ b/ubl-settings-datetime.po @@ -29,10 +29,10 @@ msgctxt "Enter DHCP" msgid "Введите DHCP" msgstr "" -#. UBconfig - Дата и время +#. Date and time settings #: ubconfig_date_time.glade:88 -msgctxt "UBconfig - Дата и время" -msgid "UBconfig - Дата и время" +msgctxt "Date and time settings" +msgid "Настройки даты и времени" msgstr "" #: ubconfig_date_time.glade:123