181178 【备份还原】kylin时间格式适配
This commit is contained in:
chairui 2023-11-23 14:01:42 +08:00 committed by 赵民勇
parent d1f70e3df9
commit 883b7ec29f
10 changed files with 181 additions and 3 deletions

10
debian/changelog vendored
View File

@ -1,3 +1,13 @@
yhkylin-backup-tools (4.1.0.1-ok9) nile; urgency=medium
* BUG: 无
* 任务号: 181178 【备份还原】kylin时间格式适配
* 需求号: 无
* 其他改动说明: 无
* 其他改动说明: 无
-- chairui <chairui@kylinos.cn> Thu, 23 Nov 2023 13:55:08 +0800
yhkylin-backup-tools (4.1.0.1-ok8) nile; urgency=medium
* BUG: 无

1
debian/control vendored
View File

@ -19,6 +19,7 @@ Build-Depends: debhelper (>= 9),
libkysdk-qtwidgets-dev,
libkysdk-waylandhelper-dev,
libkysdk-appcommon,
libkysdk-systime-dev,
Standards-Version: 3.9.5
Homepage: http://kylinos.cn

103
kybackup/datetimeutils.cpp Executable file
View File

@ -0,0 +1,103 @@
#include "datetimeutils.h"
#include <QDBusReply>
#include <QDebug>
#include <QStorageInfo>
DateTimeUtils::DateTimeUtils(QObject *parent /*= nullptr*/) :
QObject(parent)
{
//监听系统时间格式转换
m_dateSessionDbus = new QDBusInterface("com.kylin.kysdk.DateServer",
"/com/kylin/kysdk/Date",
"com.kylin.kysdk.DateInterface",
QDBusConnection::sessionBus(),
this);
if (m_dateSessionDbus->isValid()) {
connect(m_dateSessionDbus, SIGNAL(DateSignal(QString)), this, SLOT(DateFormatChange(QString)));
connect(m_dateSessionDbus, SIGNAL(ShortDateSignal(QString)), this, SLOT(DateFormatChange(QString)));
connect(m_dateSessionDbus, SIGNAL(LongDateSignal(QString)), this, SLOT(DateFormatChange(QString)));
connect(m_dateSessionDbus, SIGNAL(TimeSignal(QString)), this, SLOT(TimeFormatChange(QString)));
}
m_dateFormatOld = "yyyy-MM-dd";
m_dateFormatNow = kdk_system_get_shortformat();
m_timeFormatOld = "hh:mm:ss";
QString newTimeFormat(kdk_system_get_now_timeformat());
if (newTimeFormat.contains("12")) {
m_timeFormatNow = "ap hh:mm:ss";
} else {
m_timeFormatNow = "hh:mm:ss";
}
}
void DateTimeUtils::DateFormatChange(QString dateFormat)
{
Q_UNUSED(dateFormat)
QString shortDateFormat(kdk_system_get_shortformat());
if (m_dateFormatNow != shortDateFormat) {
m_dateFormatOld = m_dateFormatNow;
m_dateFormatNow = shortDateFormat;
emit this->ShortDateSignal();
}
}
void DateTimeUtils::TimeFormatChange(QString timeFormat)
{
QString newTimeFormat;
if (timeFormat.contains("12")) {
newTimeFormat = "ap hh:mm:ss";
} else {
newTimeFormat = "hh:mm:ss";
}
if (newTimeFormat != m_timeFormatNow) {
m_timeFormatOld = m_timeFormatNow;
m_timeFormatNow = newTimeFormat;
emit this->ShortDateSignal();
}
}
QString DateTimeUtils::TranslateDateFormat(const QString &dateTime, const QString &oldFormat /*= "yyyy-MM-dd hh:mm:ss"*/)
{
QDateTime qDateTime = QDateTime::fromString(dateTime, oldFormat);
if (!qDateTime.isValid())
return dateTime;
QString newFormat = m_dateFormatNow + " " + m_timeFormatNow;
return qDateTime.toString(newFormat);
}
struct tm DateTimeUtils::QDateTimeToCtm(const QDateTime &datetime)
{
struct tm c_time;
c_time.tm_year = datetime.date().year();
c_time.tm_mon = datetime.date().month();
c_time.tm_mday = datetime.date().day();
c_time.tm_hour = datetime.time().hour();
c_time.tm_min = datetime.time().minute();
c_time.tm_sec = datetime.time().second();
return c_time;
}
QString DateTimeUtils::TranslateDateFormat(const QDateTime &datetime)
{
struct tm c_time = QDateTimeToCtm(datetime);
QString result = kdk_system_shortformat_transform(&c_time);
result += " ";
// result += datetime.time().toString(m_timeFormatNow);
kdk_timeinfo * kdk_time = kdk_system_timeformat_transform(&c_time);
QString time;
if (kdk_time) {
result += kdk_time->time;
kdk_free_timeinfo(kdk_time);
}
return result;
}
DateTimeUtils::~DateTimeUtils()
{
if (m_dateSessionDbus)
delete m_dateSessionDbus;
}

43
kybackup/datetimeutils.h Executable file
View File

@ -0,0 +1,43 @@
#ifndef DATETIMEUTILS_H
#define DATETIMEUTILS_H
#include <QObject>
#include <QDBusInterface>
#include <QDateTime>
#include <libkydate.h>
class DateTimeUtils : public QObject
{
Q_OBJECT
public:
DateTimeUtils(QObject *parent = nullptr);
virtual ~DateTimeUtils();
signals:
void ShortDateSignal();
public slots:
void DateFormatChange(QString dateFormat);
void TimeFormatChange(QString timeFormat);
public:
QString TranslateDateFormat(const QDateTime &datetime);
QString TranslateDateFormat(const QString &dateTime, const QString &oldFormat = "yyyy-MM-dd hh:mm:ss");
QString getOldDateFormat() const {
return m_dateFormatOld + " " + m_timeFormatOld;
}
private:
struct tm QDateTimeToCtm(const QDateTime &datetime);
private:
QString m_dateFormatNow;
QString m_dateFormatOld;
QString m_timeFormatNow;
QString m_timeFormatOld;
// 监控是否平板的dbus接口
QDBusInterface * m_dateSessionDbus = nullptr;
};
#endif // DATETIMEUTILS_H

View File

@ -16,7 +16,7 @@ LIBS +=-lX11
# 配置gsettings
CONFIG += link_pkgconfig
PKGCONFIG += gsettings-qt
PKGCONFIG += kysdk-qtwidgets kysdk-waylandhelper
PKGCONFIG += kysdk-qtwidgets kysdk-waylandhelper kysdk-systime
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
@ -63,6 +63,7 @@ HEADERS += \
component/pixmapbutton.h \
component/pixmaplabel.h \
component/ringsprogressbar.h \
datetimeutils.h \
deletebackupdialog.h \
functypeconverter.h \
globalbackupinfo.h \
@ -115,6 +116,7 @@ SOURCES += \
component/pixmapbutton.cpp \
component/pixmaplabel.cpp \
component/ringsprogressbar.cpp \
datetimeutils.cpp \
deletebackupdialog.cpp \
functypeconverter.cpp \
gsettingswrapper.cpp \

View File

@ -3,6 +3,7 @@
#include "../backuppointlistdialog.h"
#include "component/mypushbutton.h"
#include "../datetimeutils.h"
class ManageBackupPointList : public BackupPointListDialog
{
@ -30,6 +31,7 @@ private:
int m_deleteRow = -1;
// 删除按钮
MyPushButton * m_buttonDelete;
DateTimeUtils m_dateUtils;
};
#endif // MANAGEBACKUPPOINTLIST_H

View File

@ -85,6 +85,8 @@ void OperationLog::initHomePage()
homePage->setLayout(vlayout);
connect(&m_dateUtils, &DateTimeUtils::ShortDateSignal, this, &OperationLog::updateTimeVolumn);
QList<BackupWrapper> list = Utils::getBackupLogList();
if (list.isEmpty()) {
labelEmptyLogo->setVisible(true);
@ -123,7 +125,8 @@ void OperationLog::initOperationLogs(const QList<BackupWrapper>& list)
setItem(indexOfRow, 0, backupPoint.m_backupName);
setItem(indexOfRow, 1, backupPoint.m_uuid);
setItem(indexOfRow, 2, castTypeToString(backupPoint.m_type));
setItem(indexOfRow, 3, backupPoint.m_time);
// setItem(indexOfRow, 3, backupPoint.m_time);
setItem(indexOfRow, 3, m_dateUtils.TranslateDateFormat(backupPoint.m_time));
++indexOfRow;
}
@ -198,4 +201,11 @@ QString OperationLog::castTypeToString(int type)
return name;
}
// 更新操作日志的时间卷
void OperationLog::updateTimeVolumn()
{
QList<BackupWrapper> list = Utils::getBackupLogList();
if (!list.isEmpty())
initOperationLogs(list);
}

View File

@ -5,6 +5,7 @@
#include <QTableWidget>
#include "../common/utils.h"
#include "../../common/dynamiccreator.h"
#include "../datetimeutils.h"
class OperationLog : public QStackedWidget
{
@ -28,8 +29,10 @@ private:
void initOperationLogs(const QList<BackupWrapper>& list);
void setItem(int row, int column, const QString& text, int alignFlag = Qt::AlignLeft | Qt::AlignVCenter);
QString castTypeToString(int type);
void updateTimeVolumn();
QTableWidget *m_tableWidget;
DateTimeUtils m_dateUtils;
};
#endif // OPERATIONLOG_H

View File

@ -43,6 +43,7 @@ SelectRestorePoint::SelectRestorePoint(QWidget *parent, BackupPointType backupTy
});
// connect(buttonRefresh, &MyPushButton::clicked, this, &SelectRestorePoint::initTableWidget);
connect(this, &SelectRestorePoint::udiskChange, this, &SelectRestorePoint::initTableWidget);
connect(&m_dateUtils, &DateTimeUtils::ShortDateSignal, this, &SelectRestorePoint::initTableWidget);
connect(buttonOk, &MyPushButton::clicked, this, [=](){
// 判断是否已经选中备份点
@ -157,7 +158,8 @@ void SelectRestorePoint::insertLines(const QList<ParseBackupList::BackupPoint> &
m_tableWidget->insertRow(indexOfRow);
setItem(indexOfRow, Column_Index::Backup_Name, backupPoint.m_backupName);
setItem(indexOfRow, Column_Index::UUID, backupPoint.m_uuid);
setItem(indexOfRow, Column_Index::Backup_Time, backupPoint.m_time);
// setItem(indexOfRow, Column_Index::Backup_Time, backupPoint.m_time);
setItem(indexOfRow, Column_Index::Backup_Time, m_dateUtils.TranslateDateFormat(QString("20") + backupPoint.m_time));
setItem(indexOfRow, Column_Index::Backup_Size, backupPoint.m_size);
QString prefixPath_to_device;

View File

@ -2,6 +2,7 @@
#define SELECTRESTOREPOINT_H
#include "../backuppointlistdialog.h"
#include "../datetimeutils.h"
class SelectRestorePoint : public BackupPointListDialog
{
@ -28,6 +29,7 @@ private:
private:
BackupPointType m_backupType;
bool m_needConfirm = true;
DateTimeUtils m_dateUtils;
};
#endif // SELECTRESTOREPOINT_H