diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0611a0e --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +UBTime +main.cpp +ubl-settings-datetime.glade~ +test.cpp +ubl-settings-datetime +a.out \ No newline at end of file diff --git a/Makefile b/Makefile index 5161b99..9ca9003 100644 --- a/Makefile +++ b/Makefile @@ -1,61 +1,71 @@ #!/usr/bin/make -f -pkgname="ubconfig" +pkgname=ubl-settings-datetime -all: uninstall build check install clean +all: uninstall init build check install clean + +init: + mkdir -p /usr/share/${pkgname}/{images,ui,reg}/; uninstall: - pkgname="ubconfig" - for size in 16 32 48; do - rm -f "/usr/share/icons/hicolor/${size}x${size}/apps/ublinux-${pkgname}.svg" - rm -f "/usr/share/icons/hicolor/${size}x${size}/apps/hide_pass_icon.svg" - rm -f "/usr/share/icons/hicolor/${size}x${size}/apps/show_pass_icon.svg" - 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 -f /usr/bin/"${pkgname}".gtk - rm -f /usr/share/"${pkgname}"/ui/"${pkgname}".glade - rm -f /usr/share/applications/"${pkgname}".desktop - rm -f /usr/share/"${pkgname}"/css/style.css - rm -f /usr/share/"${pkgname}"/images/side_img_ubc_v_dark.png - rm -f /usr/share/"${pkgname}"/images/side_img_ubc_v_light.png - rm -f /usr/share/polkit-1/actions/org.freedesktop.policykit."${pkgname}".pkexec.policy + @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; \ build: - echo "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; \ check: - echo "Check" + echo "Check"; \ 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 "ublinux-${pkgname}.svg" -o "/usr/share/icons/hicolor/${size}x${size}/apps/ublinux-${pkgname}.svg" - rsvg-convert -w ${size} -h ${size} -f svg --keep-image-data "hide_pass_icon.svg" -o "/usr/share/icons/hicolor/${size}x${size}/apps/hide_pass_icon.svg" - rsvg-convert -w ${size} -h ${size} -f svg --keep-image-data "show_pass_icon.svg" -o "/usr/share/icons/hicolor/${size}x${size}/apps/show_pass_icon.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}" - msgfmt "${file_po}" -v -f -o "${path_file_mo}" - done - install -vDm0755 "${pkgname}" -t /usr/bin/ - install -vDm0755 "${pkgname}".gtk -t /usr/bin/ - install -vDm0644 "${pkgname}".glade -t /usr/share/"${pkgname}"/ui/ - install -vDm0644 "${pkgname}".desktop -t /usr/share/applications/ - install -vDm0644 style.css -t /usr/share/"${pkgname}"/css/ - install -vDm0644 side_img_ubc_v_dark.png -t /usr/share/"${pkgname}"/images/ - install -vDm0644 side_img_ubc_v_light.png -t /usr/share/"${pkgname}"/images/ - install -vDm0644 org.freedesktop.policykit."${pkgname}".pkexec.policy -t /usr/share/polkit-1/actions/ - - + @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" - + echo "Clean"; + \ No newline at end of file diff --git a/README.md b/README.md index 8ab6612..ccab309 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # ubl-settings-datetime +![alt text](screen_app.png) + +- [ ] Локализация +- [x] Makefile +- [ ] Парсинг TimeZone C++ + diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 4b06858..0000000 --- a/main.cpp +++ /dev/null @@ -1,477 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -class MainWindow; - -class MainWindow { -public: - MainWindow(Glib::RefPtr const& builder) - { - this->builder = builder; - this->get_builder(); - _numTimeHrs->set_range(0,23); - _numTimeMin->set_range(0,59); - _numTimeHrs->set_increments(1.0,1.0); - _numTimeMin->set_increments(1.0,1.0); - _txtDate->set_sensitive(false); - this->get_config(); - this->event(); - - - } - - virtual ~MainWindow() = default; - // Функция вызывается btnUpdateDate для обновления времени - void get_builder(){ - builder->get_widget("btnUpdateDateTime", _btnUpdateDateTime); - builder->get_widget("btnChooseDate", _btnChooseDate); - builder->get_widget("cbxSynchronizeNtp", _cbxSynchronizeNtp); - builder->get_widget("popCalendar", _popCalendar); - builder->get_widget("numTimeHrs", _numTimeHrs); - builder->get_widget("numTimeMin", _numTimeMin); - builder->get_widget("cbDhcp", _cbDhcp); - builder->get_widget("txtDate", _txtDate); - builder->get_widget("cbRegion", _cbRegion); - builder->get_widget("cbRegionGlob", _cbRegionGlob); - builder->get_widget("cbZone", _cbZone); - builder->get_widget("cbZoneGlob", _cbZoneGlob); - builder->get_widget("txtNtpServer", _txtNtpServer); - builder->get_widget("cldrDate", _cldrDate); - builder->get_widget("mess_dchp", _mess_dchp); - - } - void event(){ - _cldrDate->signal_day_selected().connect(sigc::mem_fun(*this, &MainWindow::get_calendar)); - _cbxSynchronizeNtp->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::set_ntp_toggle)); - _btnUpdateDateTime->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::update_time_date)); - _btnChooseDate->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::calendar_show)); - _cbDhcp->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::get_ghcp)); - _cbRegion->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::append_zone)); - _cbRegionGlob->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::append_zone_glob)); - _cbZone->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::enter_zone)); - _cbZoneGlob->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::enter_zone_glob)); - _txtNtpServer->signal_activate().connect(sigc::mem_fun(*this, &MainWindow::A));; - } - - void focus_ntp(){ - - } - void A(){ - cout << "A" << endl; - //_txtNtpServer->signal_focus_out_event().connect(sigc::mem_fun(*this, &MainWindow::focus_ntp)); - } - - - - - void enry_dhcp_mess(){} - - void get_ghcp(){ - 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"; - system(cmd.c_str()); - //_txtNtpServer->set_active(false); - _cbDhcp->set_active(0); - } - else{ - string cmd = "sudo /usr/bin/ubconfig set network NTPSERVERS=" + _txtNtpServer->get_text(); - //_txtNtpServer->set_active(true); - system(cmd.c_str()); - _cbDhcp->set_active(1); - } - } - else{ - string cmd = "sudo /usr/bin/ubconfig set network NTPSERVERS=dhcp"; - system(cmd.c_str()); - //_txtNtpServer->set_sensitive(false); - _cbDhcp->set_active(0); - } - } - - void get_calendar(){ - _cldrDate->get_date(year, month, day); - string date = to_string(day) + ':' + to_string(month+1) + ':' + to_string(year); - _txtDate->set_text(date); - } - - - void calendar_show(){ - time_t now = time(0); - tm *ltm = localtime(&now); - unsigned int y=1900+ ltm->tm_year; - unsigned int m=ltm->tm_mon; - unsigned int d=ltm->tm_mday; - - - _cldrDate->select_month(m,y); - _cldrDate->select_day(d); - _popCalendar->show(); - } - - void get_config(){ - this->read_file(); - this->update_hour_minute(); - this->update_calendar(); - this->get_ghcp(); - string str_dhcp = this->call("sudo /usr/bin/ubconfig get network NTPSERVERS"); - cout << str_dhcp << endl; - if ((str_dhcp!="") && (str_dhcp!="(null)")){ - str_dhcp = str_dhcp.substr(str_dhcp.find("=")+1,str_dhcp.length()); - str_dhcp = str_dhcp.substr(0,str_dhcp.find("\n")); - if (str_dhcp=="dhcp"){ - _cbDhcp->set_active(0); - //_txtNtpServer->set_sensitive(false); - //_cbxSynchronizeNtp->set_sensitive(true); - } - else{ - if (str_dhcp==""){ - _mess_dchp->show(); - } - else{ - _cbDhcp->set_active(1); - //_txtNtpServer->set_sensitive(true); - //_cbxSynchronizeNtp->set_sensitive(false); - _txtNtpServer->set_text(str_dhcp); - } - } - - - //_cbxDhcp->set_active(true); - this->set_ntp_toggle(); - } - string str_ntp = this->call("sudo systemctl status ntpd.service systemd-timesyncd.service | grep \"Active: active\""); - if (str_ntp.length()<50) { - _cbxSynchronizeNtp->set_active(false); - } - else{ - _cbxSynchronizeNtp->set_active(true); - } - - string read_reg_zon_cfg = this->call("sudo /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")); - string str_filling_reg = read_reg_zon_cfg.substr(0,read_reg_zon_cfg.find("/")); - 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")); - string str_zone_check = ""; - this->append_region_zone(str_filling_reg,str_filling_zon); - } - else { - this->append_region_zone("Asia","Omsk"); - - } - - } - - void enter_zone(){ - Glib::ustring zone_text = _cbZone->get_active_text(); - Glib::ustring reg_text = _cbRegion->get_active_text(); - 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+"'"; - system(cmd.c_str()); - } - else{ - str_zone=""; - str_region=""; - } - } - - void enter_zone_glob(){ - Glib::ustring zone_text = _cbZoneGlob->get_active_text(); - Glib::ustring reg_text = _cbRegionGlob->get_active_text(); - 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; - system(cmd.c_str()); - } - else{ - str_zoneGlob=""; - str_region_glob=""; - } - } - - void set_ntp_toggle(){ - bool flag = _cbxSynchronizeNtp->get_active(); - _numTimeHrs->set_sensitive(!flag); - _numTimeMin->set_sensitive(!flag); - //_txtDate->set_sensitive(!flag); - _btnChooseDate->set_sensitive(!flag); - //_btnUpdateDateTime->set_sensitive(!flag); - if (flag==false){ - system("sudo systemctl --now disable systemd-timesyncd.service ntpd.service"); - } - else { - system("sudo systemctl --now enable systemd-timesyncd.service"); - } - - } - - void append_region_zone(string region, string zone){ - int index = 0; - for ( const auto &text : time_reg_map ) { - _cbRegion->append(text.first); - _cbRegionGlob->append(text.first); - if (text.first == region){ - _cbRegionGlob->set_active(index); - _cbRegion->set_active(index); - - } - index+=1; - } - index = 0; - string cheek_zone = ""; - for (const auto &_str_zone : time_reg_map.at(region)){ - _cbZone->append(_str_zone); - _cbZoneGlob->append(_str_zone); - if (_str_zone!=""){ - cheek_zone = _str_zone.substr(_str_zone.find(") ")+2,_str_zone.length()); - if (cheek_zone == zone){ - _cbZone->set_active(index); - _cbZoneGlob->set_active(index); - } - } - index+=1; - } - } - string call(string cmd){ - FILE *fp; - int status; - char path[PATH_MAX]; - fp = popen(cmd.c_str(), "r"); - if (fp == NULL){ - //return ""; - } - - while (fgets(path, PATH_MAX, fp) != NULL){ - printf("%s", path); - break; - - } - - status = pclose(fp); - if (status == -1) { - //return ""; - } - else { - //return ""; - } - return path; - } - - void append_zone(){ - Glib::ustring text = _cbRegion->get_active_text(); - _cbZone->remove_all(); - - if(!(text.empty())){ - str_region = text; - for (const auto &_str_zone : time_reg_map.at(str_region)){ - _cbZone->append(_str_zone); - } - } - - } - - void append_zone_glob(){ - Glib::ustring text = _cbRegionGlob->get_active_text(); - _cbZoneGlob->remove_all(); - if(!(text.empty())){ - str_region_glob = text; - for (const auto &_str_zone : time_reg_map.at(str_region_glob)){ - _cbZoneGlob->append(_str_zone); - } - } - - } - void update_time_date(){ - this->enter_zone(); - bool flag = _cbxSynchronizeNtp->get_active(); - if (flag==false){ - hour = _numTimeHrs->get_value_as_int(); - minute = _numTimeMin->get_value_as_int(); - time_t now = time(0); - tm *ltm = localtime(&now); - string cmd = "sudo timedatectl set-time \""+ - to_string(hour) + ":" + to_string(minute) - + ":" + to_string(ltm->tm_sec) +"\""; - 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+1; - day=ltm->tm_mday; - } - string str_mount = ""; - string str_day = ""; - if (month <10){ - str_mount = "0"+to_string(month+1); - } - else{ - str_mount = to_string(month+1); - } - if (day <10){ - str_day = "0"+to_string(day); - } - else{ - str_day = to_string(day); - } - string cmd1 = "sudo date --set=\"" +to_string(year)+ - str_mount+str_day + " " +to_string(hour) + ":" + - to_string(minute)+"\""; - system(cmd1.c_str()); - } - - - } - void update_hour_minute(){ - time_t now = time(0); - tm *ltm = localtime(&now); - _numTimeHrs->set_value(ltm->tm_hour); - _numTimeMin->set_value(ltm->tm_min); - } - - void update_calendar(){ - time_t now = time(0); - tm *ltm = localtime(&now); - int year = 1900 + (int)ltm->tm_year; - string date = to_string(ltm->tm_mday) + ':' + to_string(ltm->tm_mon+1) + ':' + to_string(year); - _txtDate->set_text(date); - } - void read_file(){ - std::string line; - namespace fs = std::filesystem; - for (const auto & entry : fs::directory_iterator(path_file)){ - std::ifstream in(entry.path()); // окрываем файл для чтения - if (in.is_open()) - { - vector zone; - zone.push_back(""); - while (getline(in, line)) - { - zone.push_back(string(gettext(line.c_str()))); - } - string key_reg = entry.path().filename().string(); - key_reg = string(gettext(key_reg.c_str())); - time_reg_map.insert({key_reg, zone}); - } - in.close(); - } - } - -private: - string path_file="reg/"; - Glib::RefPtr builder; - Gtk::Button *_btnUpdateDateTime; - Gtk::Button *_btnChooseDate; - Gtk::ComboBoxText *_cbDhcp; - Gtk::SpinButton *_numTimeHrs; - Gtk::SpinButton *_numTimeMin; - Gtk::CheckButton *_cbxSynchronizeNtp; - - Gtk::Entry *_txtDate; - Gtk::ComboBoxText *_cbRegion; - Gtk::ComboBoxText *_cbRegionGlob; - Gtk::ComboBoxText *_cbZone; - Gtk::ComboBoxText *_cbZoneGlob; - Gtk::Entry *_txtNtpServer; - Gtk::MessageDialog *_mess_dchp; - Gtk::Popover *_popCalendar; - Gtk::Calendar *_cldrDate; - unsigned int year, month, day; - int hour; - int minute; - string str_region=""; - string str_region_glob=""; - string str_txtDate; - string str_txtNtpServer; - string str_zone=""; - string str_zoneGlob; - std::map > time_reg_map; - -}; - -class WrapperMainWindow : public Gtk::ApplicationWindow { - public: - WrapperMainWindow(BaseObjectType* obj, Glib::RefPtr const& builder) - : Gtk::ApplicationWindow(obj) - , builder{builder} - { - MainWindow MainWindow(builder); - } - virtual ~WrapperMainWindow() = default; - - private: - Glib::RefPtr builder; -}; -/* -class PlugMainWindow : public Gtk::Plug -{ - -public: - - SettingsPlug(::Window p_socketID) - : Gtk::Plug{p_socketID} - { - - } - void get_builder(Glib::RefPtr const& builder) - { - this->builder = builder; - } - private: - Glib::RefPtr builder; -} -*/ -int main(int argc, char* argv[]) { - string app_name = "main"; - //setlocale(LC_ALL, ""); - //bindtextdomain(app_name, "/usr/share/locale"); - //textdomain(app_name); - auto app = Gtk::Application::create(argc, argv, "de.engelmarkus.example"); - auto builder = Gtk::Builder::create_from_file("ubconfig_date_time.glade"); - - Glib::OptionContext context; - /*CmdArgParser parser{ - "Socket ID", - "Command line argument for socket ID communication.", - "No help available, sorry" - }*/ - - - //context.set_main_group(parser); - //context.parse(argc, argv); - - //::Window socketID = parser.GetSocketID(); - //SettingsPlug plug{socketID}; - //plug.show(); - - WrapperMainWindow * wnd = nullptr; - - builder->get_widget_derived("window", wnd); - - auto r = app->run(*wnd); - - delete wnd; - - return r; -} \ No newline at end of file diff --git a/org.freedesktop.policykit.UBTime.pkexec.policy b/org.freedesktop.policykit.ubl-settings-datetime.pkexec.policy similarity index 51% rename from org.freedesktop.policykit.UBTime.pkexec.policy rename to org.freedesktop.policykit.ubl-settings-datetime.pkexec.policy index 7c1f2be..eb3e5c8 100644 --- a/org.freedesktop.policykit.UBTime.pkexec.policy +++ b/org.freedesktop.policykit.ubl-settings-datetime.pkexec.policy @@ -7,17 +7,17 @@ UBSoft https://ublinux.ru - - Run UBConfig as root - Запуск UBTime с правами root - Authentication is required to run the UBConfig - Требуется авторизация для запуска UBTime с правами root + + Run ubl-settings-datetime as root + Запуск ubl-settings-datetime с правами root + Authentication is required to run the ubl-settings-datetime + Требуется авторизация для запуска ubl-settings-datetime с правами root auth_admin auth_admin auth_admin - /usr/bin/UBTime + /home/superadmin/Документы/Проект/ubconfig_new/ubl-settings-datetime/ true diff --git a/reg/locali111 b/reg/locali111 deleted file mode 100644 index f14d13c..0000000 --- a/reg/locali111 +++ /dev/null @@ -1,69 +0,0 @@ -msgid "Ok" -msgstr "Oк" - -msgid "Enter DHCP" -msgstr "Введите DHCP" - -msgid "UBconfig - Дата и время" -msgstr "UBconfig - Дата и время" - -msgid "Setting the date and time" -msgstr "Настройка даты и времени" - -msgid "Time" -msgstr "Время" - -msgid "Clock" -msgstr "Часы" - -msgid "Minutes" -msgstr "Минуты" - -msgid "Date" -msgstr "Дата" - -msgid "" -msgstr "" - -msgid "Interactive date picker" -msgstr "Интерактивный выбор даты" - -msgid "Change zone setting" -msgstr "Изменить параметр зоны" - -msgid "time zone" -msgstr "Временная зона" - -msgid "Region" -msgstr "Регион" - -msgid "Zone" -msgstr "Зона" - -msgid "Update date and time" -msgstr "Обновить дату и время" - -msgid "Synchronize via NTP" -msgstr "Синхронизировать через NTP" - -msgid "Automatic time synchronization" -msgstr "Автоматическая синхронизация времени" - -msgid "Synchronization method" -msgstr "Способ синхронизации" - -msgid "DHCP" -msgstr "DHCP" - -msgid "Manually" -msgstr "Вручную" - -msgid "" -msgstr "" - -msgid "Time zone" -msgstr "Временная зона" - -msgid "Setting date and time in global configuration" -msgstr "Настройка даты и времени в глобальной конфигурации" - diff --git a/screen_app.png b/screen_app.png new file mode 100644 index 0000000..39c88a4 Binary files /dev/null and b/screen_app.png differ diff --git a/UBTime.cpp b/ubl-settings-datetime.cpp similarity index 83% rename from UBTime.cpp rename to ubl-settings-datetime.cpp index 90f2abe..fd83206 100644 --- a/UBTime.cpp +++ b/ubl-settings-datetime.cpp @@ -21,20 +21,67 @@ #include using namespace std; -string path_app= "/home/superadmin/Документы/Проект/ubconfig_new/Ubconfig_date_time/"; -string app_name = "UBTime"; +string path_app= "/usr/bin/"; +string path_glade= "/usr/share/ubl-settings-datetime/ui/"; +string app_name = "ubl-settings-datetime"; bool flag_datetime = false; bool flag_timezone = false; bool flag_ntp = false; bool flag_update = false; + +class CmdArgParser : public Glib::OptionGroup +{ + +public: + + CmdArgParser(const std::string& p_name, const std::string& p_description, const std::string& p_help) + : Glib::OptionGroup{p_name, p_description, p_help} + { + // Define the 'socket ID' argument options: + Glib::OptionEntry socketIDArg; + socketIDArg.set_long_name("socket-id"); + socketIDArg.set_short_name('s'); + socketIDArg.set_flags(Glib::OptionEntry::FLAG_IN_MAIN); + 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); + } + + // Override this to handle errors. I skipped it for simplicity. + // void on_error(Glib::OptionContext& context, const Glib::Error& error) override; + + ::Window GetSocketID() const + { + return m_socketID; + } + +private: + + int m_socketID = 0; + +}; + + + class MainWindow : public Gtk::ApplicationWindow { public: MainWindow(BaseObjectType* obj, Glib::RefPtr const& builder) : Gtk::ApplicationWindow(obj) , builder{builder} { - path_file+="reg/"; + this->settings(); + + } + MainWindow(Glib::RefPtr const& builder) { + this->builder = builder; + this->settings(); + } + + virtual ~MainWindow() = default; + + void settings(){ this->get_builder(); _numTimeHrs->set_range(0,23); _numTimeMin->set_range(0,59); @@ -44,11 +91,8 @@ public: this->get_config(); this->flag_block_gui(); this->event(); - } - virtual ~MainWindow() = default; - void flag_block_gui(){ if (flag_datetime==true){ _numTimeHrs->set_sensitive(false); @@ -174,7 +218,7 @@ public: _cldrDate->get_date(year, month, day); string str_month = ""; string str_day = ""; - month=month+1; + month+=1; if (month <10){ str_month = "0"+to_string(month); } @@ -416,7 +460,7 @@ public: time_t now = time(0); tm *ltm = localtime(&now); year=1900+ ltm->tm_year; - month=ltm->tm_mon+1; + month=ltm->tm_mon; day=ltm->tm_mday; } string str_month = ""; @@ -425,7 +469,7 @@ public: str_month = "0"+to_string(month+1); } else{ - str_month = to_string(month+1); + str_month = to_string(month); } if (day <10){ str_day = "0"+to_string(day); @@ -475,7 +519,7 @@ public: void read_file(){ std::string line; namespace fs = std::filesystem; - for (const auto & entry : fs::directory_iterator(path_file)){ + for (const auto & entry : fs::directory_iterator("/usr/share/ubl-settings-datetime/reg/")){ std::ifstream in(entry.path()); // окрываем файл для чтения if (in.is_open()) { @@ -494,7 +538,6 @@ public: } private: - string path_file=path_app; Glib::RefPtr builder; Gtk::Button *_btnUpdateDateTime; Gtk::Button *_btnChooseDate; @@ -526,12 +569,37 @@ private: }; +class SettingsPlug : public Gtk::Plug +{ + +public: + Gtk::Window *window; + SettingsPlug(::Window p_socketID, Glib::RefPtr builder) + : Gtk::Plug{p_socketID} + { + + //MainWindow* wnd = nullptr; + //builder->get_widget_derived("window", wnd); + builder->get_widget("plugBox", plugBox); + plugBox->get_parent()->remove(*plugBox); + add(*plugBox); + + show_all_children(); + } + +private: + + Gtk::Widget *plugBox; + Gtk::Widget *parent; +}; + void help(){ cout << "Параметры командной строки --lock-datetime\n --lock-timezone\n --lock-ntp\n --lock-update\n" << endl; } int main(int argc, char* argv[]) { + //path_app=filesystem::current_path(); //path_app+="/"; //cout << *argv[0] << endl; @@ -541,59 +609,69 @@ int main(int argc, char* argv[]) { for (int i=1; iget_widget_derived("window", wnd); + auto r = app->run(*wnd); + + delete wnd; + return r; } - - - //Glib::OptionContext context; - /*CmdArgParser parser{ - "Socket ID", - "Command line argument for socket ID communication.", - "No help available, sorry" - }*/ - + else{ + Glib::init(); + setlocale(LC_ALL, ""); + Glib::OptionContext context; + + CmdArgParser parser{ + "Socket ID", + "Command line argument for socket ID communication.", + "No help available, sorry" + }; - //context.set_main_group(parser); - //context.parse(argc, argv); + context.set_main_group(parser); + context.parse(argc, argv); - //::Window socketID = parser.GetSocketID(); - //SettingsPlug plug{socketID}; - //plug.show(); - MainWindow* wnd = nullptr; - builder->get_widget_derived("window", wnd); - auto r = app->run(*wnd); + ::Window socketID = parser.GetSocketID(); - delete wnd; + // Handle plug: + SettingsPlug plug{socketID, builder}; + plug.show(); + + app->run(plug); + + } - return r; + } \ No newline at end of file diff --git a/ubl-settings-datetime.desktop b/ubl-settings-datetime.desktop new file mode 100644 index 0000000..ec87043 --- /dev/null +++ b/ubl-settings-datetime.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Type=Application +Exec=ubl-settings-datetime +Icon=ubl-settings-datetime +Comment=Time setting app +Comment[ru]=Приложение для настройки времени +Terminal=false +Name=Time setting +Name[ru]=Настройка времени +GenericName=Time setting app +GenericName[ru]=Настройка времени +Categories=XFCE;GTK;Settings;DesktopSettings;X-XFCE-SettingsDialog;X-XFCE-SystemSettings; \ No newline at end of file diff --git a/ubconfig_date_time.glade b/ubl-settings-datetime.glade similarity index 99% rename from ubconfig_date_time.glade rename to ubl-settings-datetime.glade index 796c316..acb6aeb 100644 --- a/ubconfig_date_time.glade +++ b/ubl-settings-datetime.glade @@ -87,7 +87,7 @@ False UBconfig - Дата и время - ublinux-logo.png + ../../../../../../usr/share/ubl-settings-datetime/images/ubl-settings-datetime.png True @@ -108,7 +108,7 @@ 5 6 6 - ublinux-logo.png + ../../../../../../usr/share/ubl-settings-datetime/images/ubl-settings-datetime.png False diff --git a/ublinux-logo.png b/ubl-settings-datetime.png similarity index 100% rename from ublinux-logo.png rename to ubl-settings-datetime.png diff --git a/messages.pot b/ubl-settings-datetime.po similarity index 99% rename from messages.pot rename to ubl-settings-datetime.po index 5aac87c..b74586b 100644 --- a/messages.pot +++ b/ubl-settings-datetime.po @@ -850,9 +850,6 @@ msgstr "" msgid "Panama" msgstr "" -msgid "Indiana" -msgstr "" - msgid "New_York" msgstr "" @@ -1165,9 +1162,6 @@ msgstr "" msgid "Famagusta" msgstr "" -msgid "Nicosia" -msgstr "" - msgid "Hebron" msgstr "" @@ -1192,9 +1186,6 @@ msgstr "" msgid "Baghdad" msgstr "" -msgid "Istanbul" -msgstr "" - msgid "Kuwait" msgstr "" @@ -1540,9 +1531,6 @@ msgstr "" msgid "Acre" msgstr "" -msgid "West" -msgstr "" - msgid "East" msgstr "" diff --git a/ublinux-datetime-settings.svg b/ubl-settings-datetime.svg similarity index 100% rename from ublinux-datetime-settings.svg rename to ubl-settings-datetime.svg