#include "rm_setting_time.h" #if (USE_DEVICE_SETTINGS && !USE_DEVICE_SETTINGS_JSON) #include "rm_include.h" #include #include #include #include #include #include #include #include #include "../ui/rm_button.h" #include "rm_settings_window_base.h" #include "../ui/rm_widget_checkbox.h" RMSettingTime::RMSettingTime(QWidget *parent) : QGroupBox(parent) { setFixedHeight(100); setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); setObjectName("settings"); // 日時 //#if (LIVE_LANGUAGE_CHANGE) // if(RMLanguage::isJP() == false) // { // setTitle("Time"); // } // else { //#else setTitle(MKU8("\xe6\x97\xa5\xe6\x99\x82")); //#endif //#if (LIVE_LANGUAGE_CHANGE) // } //#endif layout = new QVBoxLayout(this); layout->setAlignment(Qt::AlignVCenter | Qt::AlignLeading); layout->setContentsMargins(4,2,4,2); layout->setSpacing(3); QSpacerItem* space = new QSpacerItem(0,10); layout->addSpacerItem(space); // パソコンの時刻と同期 check = new RMWidgetCheckBox(this); //#if (LIVE_LANGUAGE_CHANGE) // if(RMLanguage::isJP() == false) // { // check->setText("PC Time Sync."); // } // else { //#else check->setText(MKU8("\xe3\x83\x91\xe3\x82\xbd\xe3\x82\xb3\xe3\x83\xb3\xe3\x81\xae\xe6\x99\x82\xe5\x88\xbb\xe3\x81\xa8\xe5\x90\x8c\xe6\x9c\x9f")); //#endif // LIVE_LANGUAGE_CHANGE //#if (LIVE_LANGUAGE_CHANGE) // } //#endif layout->addWidget(check); // 시계 기능 없음 #if !(SETTINGS_TIME_TYPE2) connect(check,SIGNAL(clicked()),SLOT(onCheckBoxTimeSync())); #endif check->setStyleSheet("font-size: 13px;color : white;"); QWidget* timeWidget = new QWidget(this); layout->addWidget(timeWidget); QHBoxLayout* timeLayout = new QHBoxLayout(timeWidget); date = new QDateEdit(timeWidget); date->setCalendarPopup(true); date->setStyleSheet("font-family: Arial;font-size: 14px;"); timeLayout->addWidget(date); time = new QTimeEdit(timeWidget); timeLayout->addWidget(time); time->setStyleSheet("font-family: Arial;font-size: 14px;"); time->setDisplayFormat("AP hh:mm:ss"); QString applyString = MKU8("\xe9\x81\xa9\xe7\x94\xa8"); //#if (LIVE_LANGUAGE_CHANGE) // if(RMLanguage::isJP() == false) // { // applyString = "Apply"; // } //#endif #if !(SETTINGS_TIME_TYPE2) #if (LIVE_LANGUAGE2) RMButton* applyButton = RMButton::create2(timeWidget,timeLayout,"button","apply",QSize(60,30)); #else // LIVE_LANGUAGE2 RMButton* applyButton = RMButton::create(timeWidget,timeLayout,"button",applyString,QSize(60,30)); #endif // LIVE_LANGUAGE2 applyButton->setText(applyString); connect(applyButton,SIGNAL(clicked()),this,SLOT(onSave())); #endif // SETTINGS_TIME_TYPE2 _syncTimer = NULL; // 읽어 오기는 한다 (나머지 공간에 저장값 그대로 유지하기 위해) memset(_buffer,0,TIME_SET_FILE_SIZE); QString timePath = QDir::cleanPath(RMSettingsWindowBase::lastSettingDisk + "//timeset.txt"); if(QFile::exists(timePath)) { FILE* f = fopen(timePath.toLocal8Bit(),"r+b"); if(f != NULL) { fread(_buffer,1,TIME_SET_FILE_SIZE,f); fclose(f); //_readFromBuffer(); } } onSyncTime(); } //void RMSettingTime::_readFromBuffer() //{ //// 0x10 2BYTE 2019 // 년 //// 0x12 2BYTE 01 // 월 //// 0x14 2BYTE 01 // 일 //// 0x16 2BYTE 01 // 시 //// 0x18 2BYTE 00 // 분 //// 0x1A 2BYTE 00 // 초 // int y = _buffer[0x11] << 8 | _buffer[0x10]; // int m = _buffer[0x13] << 8 | _buffer[0x12]; // int d = _buffer[0x15] << 8 | _buffer[0x14]; // int h = _buffer[0x17] << 8 | _buffer[0x16]; // int mm = _buffer[0x19] << 8 | _buffer[0x18]; // int s = _buffer[0x1B] << 8 | _buffer[0x1A]; // //qInfo() << year << month << day << h << m << s; // QDateTime dt; // dt.setDate(QDate(y,m,d)); // dt.setTime(QTime(h,mm,s)); // date->setDate(dt.date()); // time->setTime(dt.time()); // qInfo() << dt; //} void RMSettingTime::onSave() { #if (RM_MODEL == RM_MODEL_TYPE_XLDR_88) QString timePath = QDir::cleanPath(RMSettingsWindowBase::lastSettingDisk + "//data_time.cfg"); if(QFile::exists(timePath)) { QFile::remove(timePath); } QDateTime dt = date->dateTime(); dt.setTime(time->time()); // 2020 10 21 17 18 28 QString ts = dt.toString("yyyy MM dd HH mm ss"); QFile f(timePath); if(f.open(QIODevice::WriteOnly)) { f.write(ts.toUtf8()); f.close(); } #else int y = date->date().year(); int m = date->date().month(); int d = date->date().day(); int h = time->time().hour(); int mm = time->time().minute(); int s = time->time().second(); _buffer[0x10] = (y) & 0xFF; _buffer[0x11] = (y >> 8) & 0xFF; _buffer[0x12] = (m) & 0xFF; _buffer[0x13] = (m >> 8) & 0xFF; _buffer[0x14] = (d) & 0xFF; _buffer[0x15] = (d >> 8) & 0xFF; _buffer[0x16] = (h) & 0xFF; _buffer[0x17] = (h >> 8) & 0xFF; _buffer[0x18] = (mm) & 0xFF; _buffer[0x19] = (mm >> 8) & 0xFF; _buffer[0x1A] = (s) & 0xFF; _buffer[0x1B] = (s >> 8) & 0xFF; QString timePath = QDir::cleanPath(RMSettingsWindowBase::lastSettingDisk + "//timeset.txt"); if(QFile::exists(timePath)) { QFile::remove(timePath); } FILE* f = fopen(timePath.toLocal8Bit(),"w+b"); if(f != NULL) { fwrite(_buffer,1,TIME_SET_FILE_SIZE,f); fclose(f); } #endif } void RMSettingTime::onCheckBoxTimeSync() { QCheckBox* checkbox = qobject_cast(QObject::sender()); if(checkbox != NULL) { bool turnOn = (checkbox->checkState() != Qt::Unchecked ); _startStopTimer(turnOn); } } void RMSettingTime::_startStopTimer(bool bStart) { if(_syncTimer != NULL) { _syncTimer->stop(); delete _syncTimer; _syncTimer = NULL; } if(bStart) { _syncTimer = new QTimer(this); _syncTimer->setSingleShot(false); _syncTimer->setInterval(1000); connect(_syncTimer,SIGNAL(timeout()),SLOT(onSyncTime())); _syncTimer->start(); } } void RMSettingTime::onSyncTime() { QDateTime d = QDateTime::currentDateTime(); date->setDate(d.date()); time->setTime(d.time()); } #endif // #if (USE_DEVICE_SETTINGS)