#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //this->setGeometry(0,0,480,272); //Make window show at upper right corner this->setGeometry(100,100,480,272); //Make window show at upper right corner - For Windows ui->stackedWidget->setCurrentIndex(0); system("cd /home/AppList01 \n./ntpclient -s -d -c 1 -i 5 -h 182.92.12.11"); //Connect ntp server system("hwclock -w"); sysLanguage = 1; ui->btnLanguage->setText("En"); secondShow = 0; //The falg to judge if need to show second applicationDirPath = QCoreApplication::applicationDirPath(); //Save logs at app path mainCount = 1; //For reboot uiHiddenCount = 1; //To hide ui startTimer(1000); //Return value is 1 = timerId } MainWindow::~MainWindow() { delete ui; } void MainWindow::timerEvent(QTimerEvent *t) //Main timer { mainCount++; //Count to reboot app to clear the memory uiHiddenCount++; if(uiHiddenCount >= 6) { ui->btnBack->setStyleSheet("color: rgba(255, 255, 255, 0);"); ui->btnLanguage->setStyleSheet("color: rgba(255, 255, 255, 0);"); } if(mainCount >= 300) { mainCount = 0; system("cd /home/AppList01 \n./ntpclient -s -d -c 1 -i 5 -h 182.92.12.11"); system("hwclock -w"); QString appPathApp = applicationDirPath + "/Clock01 -qws"; QByteArray appPathAppByte = appPathApp.toLatin1(); char *appPathAppChar = appPathAppByte.data(); qDebug() << appPathAppChar; QProcess *newApp = new QProcess; //Reboot app newApp->start(appPathAppChar); //The path where the app exist QApplication::exit(0); } dateTime = QDateTime::currentDateTime(); //Get current date and time //dateTime = dateTime.addSecs(28800); strDate = dateTime.date().toString("yyyy-MM-dd "); //Formatting for Display if(secondShow) { strTime = dateTime.time().toString("hh:mm:ss:AP"); //If show second or not ui->lblTime->setText(strTime.left(8)); } else { strTime = dateTime.time().toString("hh:mm:AP"); ui->lblTime->setText(strTime.left(5)); } if(!sysLanguage) { //qDebug("En"); if((dateTime.date().toString("ddd") == "Mon") || (dateTime.date().toString("ddd") == "Tue") || (dateTime.date().toString("ddd") == "Wed") || (dateTime.date().toString("ddd") == "Thu") || (dateTime.date().toString("ddd") == "Fri") || (dateTime.date().toString("ddd") == "Sat") || (dateTime.date().toString("ddd") == "Sun")) { strDate.append(dateTime.date().toString("ddd")); } else { if(dateTime.date().toString("ddd") == "周一") strDate.append(tr("Mon")); else if(dateTime.date().toString("ddd") == "周二") strDate.append(tr("Tue")); else if(dateTime.date().toString("ddd") == "周三") strDate.append(tr("Wed")); else if(dateTime.date().toString("ddd") == "周四") strDate.append(tr("Thu")); else if(dateTime.date().toString("ddd") == "周五") strDate.append(tr("Fri")); else if(dateTime.date().toString("ddd") == "周六") strDate.append(tr("Sat")); else if(dateTime.date().toString("ddd") == "周日") strDate.append(tr("Sun")); } ui->lblHalfDay->setText(strTime.right(2)); } else { //qDebug("Ch"); if((dateTime.date().toString("ddd") == "周一") || (dateTime.date().toString("ddd") == "周二") || (dateTime.date().toString("ddd") == "周三") || (dateTime.date().toString("ddd") == "周四") || (dateTime.date().toString("ddd") == "周五") || (dateTime.date().toString("ddd") == "周六") || (dateTime.date().toString("ddd") == "周日")) { strDate.append(dateTime.date().toString("ddd")); } else { if(dateTime.date().toString("ddd") == "Mon") strDate.append(tr("周一")); else if(dateTime.date().toString("ddd") == "Tue") strDate.append(tr("周二")); else if(dateTime.date().toString("ddd") == "Wed") strDate.append(tr("周三")); else if(dateTime.date().toString("ddd") == "Thu") strDate.append(tr("周四")); else if(dateTime.date().toString("ddd") == "Fri") strDate.append(tr("周五")); else if(dateTime.date().toString("ddd") == "Sat") strDate.append(tr("周六")); else if(dateTime.date().toString("ddd") == "Sun") strDate.append(tr("周日")); } if(strTime.right(2) == "AM") ui->lblHalfDay->setText(tr("上午")); else if(strTime.right(2) == "PM") ui->lblHalfDay->setText(tr("下午")); } ui->lblDate->setText(strDate); //Show date and time on label } void MainWindow::on_butChange_clicked() //Push button to change if show second or not { if(secondShow) secondShow = 0; else secondShow = 1; } void MainWindow::on_btnBack_clicked() { QString appPathList = applicationDirPath + "/AppList01 -qws"; QByteArray appPathListByte = appPathList.toLatin1(); char *appPathListChar = appPathListByte.data(); QProcess *newApp = new QProcess; newApp->start(appPathListChar); QApplication::exit(0); } void MainWindow::on_btnSet_clicked() { dateTime = QDateTime::currentDateTime(); //Get current date and time ui->dateTimeEdit->setDateTime(dateTime); ui->stackedWidget->setCurrentIndex(1); } void MainWindow::on_btnCancel_clicked() { ui->stackedWidget->setCurrentIndex(0); } void MainWindow::on_btnOk_clicked() { QString dateTimeChanged = "date -s '" + ui->dateTimeEdit->text() + "'"; qDebug() << dateTimeChanged; QByteArray dateTimeChangedByte = dateTimeChanged.toLatin1(); char *dateTimeChangedChar = dateTimeChangedByte.data(); system(dateTimeChangedChar); system("hwclock -w"); ui->stackedWidget->setCurrentIndex(0); } void MainWindow::on_btnLanguage_clicked() { ui->btnBack->setStyleSheet("color: rgba(0, 255, 255, 255);"); ui->btnLanguage->setStyleSheet("color: rgba(0, 255, 255, 255);"); uiHiddenCount = 1; if(!sysLanguage) { sysLanguage = 1; ui->btnLanguage->setText("En"); } else { sysLanguage = 0; ui->btnLanguage->setText("中文"); } }