mirror of https://gitee.com/openkylin/peony.git
Task 156470 适配控制面板长短日期格式,统一使用SDK接口
This commit is contained in:
parent
2a5e2fc3b7
commit
041a4d71fe
|
@ -45,3 +45,8 @@ exists("/usr/include/kysdk/desktop/kysdk-soundeffects_global.h") {
|
|||
DEFINES += KY_SDK_SOUND_EFFECTS
|
||||
PKGCONFIG += kysdk-soundeffects
|
||||
}
|
||||
|
||||
exists("/usr/include/kysdk/kysdk-system/libkydate.h") {
|
||||
DEFINES += KY_SDK_DATE
|
||||
PKGCONFIG += kysdk-systime
|
||||
}
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
|
||||
#include <QPainter>
|
||||
#include <QGSettings>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusReply>
|
||||
|
||||
#include "icon-container.h"
|
||||
|
||||
|
@ -119,6 +121,31 @@ DefaultPreviewPage::DefaultPreviewPage(QWidget *parent) : QStackedWidget (parent
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef KY_SDK_DATE
|
||||
QDBusConnection conn = QDBusConnection::sessionBus();
|
||||
if (! conn.isConnected()) {
|
||||
qCritical()<<"failed to init mDbusDateServer, can not connect to session dbus";
|
||||
return;
|
||||
}
|
||||
|
||||
mDbusDateServer = new QDBusInterface(SDK_DATE_SERVER_SERVICE,
|
||||
SDK_DATE_SERVER_PATH,
|
||||
SDK_DATE_SERVER_INTERFACE,
|
||||
QDBusConnection::sessionBus());
|
||||
|
||||
if (! mDbusDateServer->isValid()){
|
||||
qCritical() << "Create /com/kylin/kysdk/Date Interface Failed " << QDBusConnection::systemBus().lastError();
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusConnection::sessionBus().connect(SDK_DATE_SERVER_SERVICE,
|
||||
SDK_DATE_SERVER_PATH,
|
||||
SDK_DATE_SERVER_INTERFACE,
|
||||
"LongDateSignal",
|
||||
this,
|
||||
SLOT(updateDateFormat(QString)));
|
||||
#endif
|
||||
}
|
||||
|
||||
DefaultPreviewPage::~DefaultPreviewPage()
|
||||
|
@ -126,6 +153,25 @@ DefaultPreviewPage::~DefaultPreviewPage()
|
|||
cancel();
|
||||
}
|
||||
|
||||
void DefaultPreviewPage::updateDateFormat(QString dateFormat)
|
||||
{
|
||||
//update date and time show format, task #101605
|
||||
qDebug() << "sdk format signal:"<<dateFormat;
|
||||
if (m_date_format != dateFormat){
|
||||
if (m_support && m_preview_tab_widget) {
|
||||
if (m_info) {
|
||||
FileInfoJob* infoJob = new FileInfoJob(m_info, this);
|
||||
infoJob->setAutoDelete(true);
|
||||
connect(infoJob, &FileInfoJob::queryAsyncFinished, this, [=] {
|
||||
m_preview_tab_widget->updateInfo(m_info.get());
|
||||
});
|
||||
infoJob->queryAsync();
|
||||
}
|
||||
}
|
||||
m_date_format = dateFormat;
|
||||
}
|
||||
}
|
||||
|
||||
bool DefaultPreviewPage::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
if (obj == m_preview_tab_widget) {
|
||||
|
@ -346,6 +392,14 @@ void FilePreviewPage::updateInfo(FileInfo *info)
|
|||
if (QRegExp("^file:///data/usershare(/{,1})$").exactMatch(info->uri())) {
|
||||
displayName = tr("usershare");
|
||||
}
|
||||
|
||||
QString accessDate = info->accessDate();
|
||||
QString modifyDate = info->modifiedDate();
|
||||
#ifdef KY_SDK_DATE
|
||||
accessDate = GlobalSettings::getInstance()->transToSystemTimeFormat(info->accessTime(), true);
|
||||
modifyDate = GlobalSettings::getInstance()->transToSystemTimeFormat(info->modifiedTime(), true);
|
||||
#endif
|
||||
|
||||
wrapData(m_display_name_label, displayName);
|
||||
m_form_label_map[m_display_name_label] = displayName;
|
||||
|
||||
|
@ -365,11 +419,11 @@ void FilePreviewPage::updateInfo(FileInfo *info)
|
|||
wrapData(m_time_create_label, createTime);
|
||||
m_form_label_map[m_time_create_label] = createTime;
|
||||
|
||||
wrapData(m_time_access_label, info->accessDate());
|
||||
m_form_label_map[m_time_access_label] = info->accessDate();
|
||||
wrapData(m_time_access_label, accessDate);
|
||||
m_form_label_map[m_time_access_label] = accessDate;
|
||||
|
||||
wrapData(m_time_modified_label, info->modifiedDate());
|
||||
m_form_label_map[m_time_modified_label] = info->modifiedDate();
|
||||
wrapData(m_time_modified_label, modifyDate);
|
||||
m_form_label_map[m_time_modified_label] = modifyDate;
|
||||
|
||||
m_file_count_label->setText(tr(""));
|
||||
m_form_label_map[m_file_count_label] = "";
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <memory>
|
||||
#include <QLabel>
|
||||
#include <QMap>
|
||||
|
||||
#include <QDBusInterface>
|
||||
class QVBoxLayout;
|
||||
class QPushButton;
|
||||
class QFormLayout;
|
||||
|
@ -60,6 +60,9 @@ public:
|
|||
void cancel() override;
|
||||
void closePreviewPage() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void updateDateFormat(QString dateFormat);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *ev) override;
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
@ -75,6 +78,8 @@ private:
|
|||
std::shared_ptr<FileWatcher> m_watcher;
|
||||
|
||||
bool m_support = true;
|
||||
QString m_date_format = "";
|
||||
QDBusInterface *mDbusDateServer;
|
||||
};
|
||||
|
||||
class FileCountOperation;
|
||||
|
|
|
@ -495,6 +495,31 @@ void BasicPropertiesPage::loadOptionalData()
|
|||
});
|
||||
}
|
||||
|
||||
#ifdef KY_SDK_DATE
|
||||
QDBusConnection conn = QDBusConnection::sessionBus();
|
||||
if (! conn.isConnected()) {
|
||||
qCritical()<<"failed to init mDbusDateServer, can not connect to session dbus";
|
||||
return;
|
||||
}
|
||||
|
||||
mDbusDateServer = new QDBusInterface(SDK_DATE_SERVER_SERVICE,
|
||||
SDK_DATE_SERVER_PATH,
|
||||
SDK_DATE_SERVER_INTERFACE,
|
||||
QDBusConnection::sessionBus());
|
||||
|
||||
if (! mDbusDateServer->isValid()){
|
||||
qCritical() << "Create /com/kylin/kysdk/Date Interface Failed " << QDBusConnection::systemBus().lastError();
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusConnection::sessionBus().connect(SDK_DATE_SERVER_SERVICE,
|
||||
SDK_DATE_SERVER_PATH,
|
||||
SDK_DATE_SERVER_INTERFACE,
|
||||
"LongDateSignal",
|
||||
this,
|
||||
SLOT(updateDateFormat(QString)));
|
||||
#endif
|
||||
|
||||
updateInfo(m_info.get()->uri());
|
||||
connect(m_watcher.get(), &FileWatcher::locationChanged, [=](const QString&, const QString &uri) {
|
||||
this->updateInfo(uri);
|
||||
|
@ -942,6 +967,16 @@ void BasicPropertiesPage::updateCountInfo(bool isDone)
|
|||
}
|
||||
}
|
||||
|
||||
void BasicPropertiesPage::updateDateFormat(QString dateFormat)
|
||||
{
|
||||
//update date and time show format, task #101605
|
||||
qDebug() << "sdk format signal:"<<dateFormat;
|
||||
if (m_date_format != dateFormat){
|
||||
updateInfo(m_info->uri());
|
||||
m_date_format = dateFormat;
|
||||
}
|
||||
}
|
||||
|
||||
void BasicPropertiesPage::updateInfo(const QString &uri)
|
||||
{
|
||||
//QT获取文件相关时间 ,
|
||||
|
@ -975,15 +1010,17 @@ void BasicPropertiesPage::updateInfo(const QString &uri)
|
|||
|
||||
m_timeModified = g_file_info_get_attribute_uint64(info,"time::modified");
|
||||
if(m_timeModifiedLabel) {
|
||||
QDateTime date2 = QDateTime::fromMSecsSinceEpoch(m_timeModified*1000);
|
||||
QString time2 = date2.toString(m_systemTimeFormat);
|
||||
// QDateTime date2 = QDateTime::fromMSecsSinceEpoch(m_timeModified*1000);
|
||||
// QString time2 = date2.toString(m_systemTimeFormat);
|
||||
QString time2 = GlobalSettings::getInstance()->transToSystemTimeFormat(m_timeModified, true);
|
||||
m_timeModifiedLabel->setText(time2);
|
||||
}
|
||||
|
||||
if(m_timeAccessLabel) {
|
||||
m_timeAccess = g_file_info_get_attribute_uint64(info,"time::access");
|
||||
QDateTime date3 = QDateTime::fromMSecsSinceEpoch(m_timeAccess*1000);
|
||||
QString time3 = date3.toString(m_systemTimeFormat);
|
||||
// QDateTime date3 = QDateTime::fromMSecsSinceEpoch(m_timeAccess*1000);
|
||||
// QString time3 = date3.toString(m_systemTimeFormat);
|
||||
QString time3 = GlobalSettings::getInstance()->transToSystemTimeFormat(m_timeAccess, true);
|
||||
m_timeAccessLabel->setText(time3);
|
||||
}
|
||||
|
||||
|
@ -999,8 +1036,9 @@ void BasicPropertiesPage::updateInfo(const QString &uri)
|
|||
// minTime = qMin (minTime, m_timeAccess);
|
||||
// m_timeCreated = minTime;
|
||||
if (m_timeCreated) {
|
||||
QDateTime createDate = QDateTime::fromMSecsSinceEpoch(m_timeCreated*1000);
|
||||
QString createTime = createDate.toString(m_systemTimeFormat);
|
||||
// QDateTime createDate = QDateTime::fromMSecsSinceEpoch(m_timeCreated*1000);
|
||||
// QString createTime = createDate.toString(m_systemTimeFormat);
|
||||
QString createTime = GlobalSettings::getInstance()->transToSystemTimeFormat(m_timeCreated, true);
|
||||
m_timeCreatedLabel->setText(createTime);
|
||||
} else {
|
||||
QFormLayout *layout = this->findChild<QFormLayout*>("floorTwoBaseLayout");
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <QtConcurrent>
|
||||
#include <QProxyStyle>
|
||||
#include <QComboBox>
|
||||
#include <QDBusInterface>
|
||||
|
||||
#include "properties-window-tab-iface.h"
|
||||
#include "open-with-properties-page.h"
|
||||
|
@ -143,6 +144,7 @@ protected Q_SLOTS:
|
|||
void onFileCountOne(const QString &uri, quint64 size);
|
||||
void cancelCount();
|
||||
void updateInfo(const QString &uri);
|
||||
void updateDateFormat(QString dateFormat);
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_layout = nullptr;
|
||||
|
@ -202,6 +204,9 @@ private:
|
|||
|
||||
QTimer *m_timer = nullptr;
|
||||
bool m_isReadOnly = false;
|
||||
|
||||
QString m_date_format = "";
|
||||
QDBusInterface *mDbusDateServer;
|
||||
};
|
||||
|
||||
class PushButtonStyle : public QProxyStyle
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "linux-pwd-helper.h"
|
||||
#include "global-settings.h"
|
||||
#include "file-watcher.h"
|
||||
#include "global-settings.h"
|
||||
|
||||
using namespace Peony;
|
||||
|
||||
|
@ -206,15 +207,40 @@ void DetailsPropertiesPage::initDetailsPropertiesPage()
|
|||
// set time
|
||||
connect(GlobalSettings::getInstance(), &GlobalSettings::valueChanged, this, [=] (const QString& key) {
|
||||
if (UKUI_CONTROL_CENTER_PANEL_PLUGIN_TIME == key) {
|
||||
if ("12" == GlobalSettings::getInstance()->getValue(key)) {
|
||||
setSystemTimeFormat(tr("yyyy-MM-dd, hh:mm:ss AP"));
|
||||
} else if ("24" == GlobalSettings::getInstance()->getValue(key)) {
|
||||
setSystemTimeFormat(tr("yyyy-MM-dd, HH:mm:ss"));
|
||||
}
|
||||
// if ("12" == GlobalSettings::getInstance()->getValue(key)) {
|
||||
// setSystemTimeFormat(tr("yyyy-MM-dd, hh:mm:ss AP"));
|
||||
// } else if ("24" == GlobalSettings::getInstance()->getValue(key)) {
|
||||
// setSystemTimeFormat(tr("yyyy-MM-dd, HH:mm:ss"));
|
||||
// }
|
||||
updateFileInfo(m_fileInfo.get()->uri());
|
||||
}
|
||||
});
|
||||
|
||||
#ifdef KY_SDK_DATE
|
||||
QDBusConnection conn = QDBusConnection::sessionBus();
|
||||
if (! conn.isConnected()) {
|
||||
qCritical()<<"failed to init mDbusDateServer, can not connect to session dbus";
|
||||
return;
|
||||
}
|
||||
|
||||
mDbusDateServer = new QDBusInterface(SDK_DATE_SERVER_SERVICE,
|
||||
SDK_DATE_SERVER_PATH,
|
||||
SDK_DATE_SERVER_INTERFACE,
|
||||
QDBusConnection::sessionBus());
|
||||
|
||||
if (! mDbusDateServer->isValid()){
|
||||
qCritical() << "Create /com/kylin/kysdk/Date Interface Failed " << QDBusConnection::systemBus().lastError();
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusConnection::sessionBus().connect(SDK_DATE_SERVER_SERVICE,
|
||||
SDK_DATE_SERVER_PATH,
|
||||
SDK_DATE_SERVER_INTERFACE,
|
||||
"LongDateSignal",
|
||||
this,
|
||||
SLOT(updateDateFormat(QString)));
|
||||
#endif
|
||||
|
||||
//size
|
||||
this->addRow(tr("File size:"),m_fileInfo->fileSize());
|
||||
|
||||
|
@ -265,6 +291,16 @@ void DetailsPropertiesPage::setSystemTimeFormat(QString format)
|
|||
this->m_systemTimeFormat = format;
|
||||
}
|
||||
|
||||
void DetailsPropertiesPage::updateDateFormat(QString dateFormat)
|
||||
{
|
||||
//update date and time show format, task #101605
|
||||
qDebug() << "sdk format signal:"<<dateFormat;
|
||||
if (m_date_format != dateFormat){
|
||||
updateFileInfo(m_fileInfo.get()->uri());
|
||||
m_date_format = dateFormat;
|
||||
}
|
||||
}
|
||||
|
||||
void DetailsPropertiesPage::updateFileInfo(const QString &uri)
|
||||
{
|
||||
this->getFIleInfo();
|
||||
|
@ -311,8 +347,9 @@ void DetailsPropertiesPage::updateFileInfo(const QString &uri)
|
|||
g_object_unref(file);
|
||||
|
||||
quint64 timeNum2 = g_file_info_get_attribute_uint64(info,"time::modified");
|
||||
QDateTime date2 = QDateTime::fromMSecsSinceEpoch(timeNum2*1000);
|
||||
QString time2 = date2.toString(m_systemTimeFormat);
|
||||
// QDateTime date2 = QDateTime::fromMSecsSinceEpoch(timeNum2*1000);
|
||||
// QString time2 = date2.toString(m_systemTimeFormat);
|
||||
QString time2 = GlobalSettings::getInstance()->transToSystemTimeFormat(timeNum2, true);
|
||||
m_modifyDateLabel->setText(time2);
|
||||
|
||||
g_object_unref(info);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QTableWidget>
|
||||
#include <QDBusInterface>
|
||||
|
||||
namespace Peony {
|
||||
|
||||
|
@ -62,6 +63,9 @@ public:
|
|||
Q_SIGNALS:
|
||||
void fileInfoReady();
|
||||
|
||||
public Q_SLOTS:
|
||||
void updateDateFormat(QString dateFormat);
|
||||
|
||||
private:
|
||||
QString m_uri = nullptr;
|
||||
std::shared_ptr<FileInfo> m_fileInfo = nullptr;
|
||||
|
@ -84,6 +88,9 @@ private:
|
|||
QLabel *m_localLabel = nullptr;
|
||||
QLabel *m_nameLabel = nullptr;
|
||||
|
||||
QString m_date_format = "";
|
||||
QDBusInterface *mDbusDateServer;
|
||||
|
||||
QWidget *createTableRow(QString labelText, QString content);
|
||||
QWidget *createTableRow(QString labelText, QLabel *contentLabel);
|
||||
|
||||
|
|
|
@ -176,24 +176,39 @@ void RecentAndTrashPropertiesPage::init()
|
|||
nullptr,
|
||||
nullptr);
|
||||
|
||||
//use sdk interface to get time format
|
||||
QString deletion_date = m_fileInfo->deletionDate();
|
||||
quint64 delete_width = FIXED_ROW_WIDTH - delete_label->fontMetrics().width(tr("Deletion Date: "));
|
||||
delete_label->setText(label->fontMetrics().elidedText(deletion_date, Qt::ElideMiddle, delete_width));
|
||||
delete_label->setWordWrap(true);
|
||||
|
||||
if (QGSettings::isSchemaInstalled("org.ukui.control-center.panel.plugins")) {
|
||||
QGSettings *settings = new QGSettings("org.ukui.control-center.panel.plugins", "", this);
|
||||
connect(settings, &QGSettings::changed, this, [=](const QString &key) {
|
||||
if(key == "date" || "hoursystem" == key) {
|
||||
QDateTime deleteTime = QDateTime::fromMSecsSinceEpoch(m_fileInfo->deletionTime (), Qt::LocalTime);
|
||||
QString format = GlobalSettings::getInstance()->getSystemTimeFormat();
|
||||
QString deletion_date = deleteTime.toString(format);
|
||||
quint64 delete_width = FIXED_ROW_WIDTH - delete_label->fontMetrics().width(tr("Deletion Date: "));
|
||||
delete_label->setText(label->fontMetrics().elidedText(deletion_date, Qt::ElideMiddle, delete_width));
|
||||
delete_label->setWordWrap(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
//no need of old way
|
||||
// if (QGSettings::isSchemaInstalled("org.ukui.control-center.panel.plugins")) {
|
||||
// QGSettings *settings = new QGSettings("org.ukui.control-center.panel.plugins", "", this);
|
||||
// connect(settings, &QGSettings::changed, this, [=](const QString &key) {
|
||||
// if(key == "date") {
|
||||
// QString current_text = delete_label->text();
|
||||
// QString new_date_type = settings->get("date").toString();
|
||||
// //cn : 1999/11/11
|
||||
// //en : 1999-11-11
|
||||
// if ((new_date_type == "cn") && current_text.contains("-")) {
|
||||
// delete_label->setText(current_text.replace("-", "/"));
|
||||
|
||||
// } else if ((new_date_type == "en") && current_text.contains("/")) {
|
||||
// delete_label->setText(current_text.replace("/", "-"));
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// QString current_text = delete_label->text();
|
||||
// QString new_date_type = settings->get("date").toString();
|
||||
// if ((new_date_type == "cn") && current_text.contains("-")) {
|
||||
// delete_label->setText(current_text.replace("-", "/"));
|
||||
|
||||
// } else if ((new_date_type == "en") && current_text.contains("/")) {
|
||||
// delete_label->setText(current_text.replace("/", "-"));
|
||||
// }
|
||||
// }
|
||||
|
||||
g_object_unref(info);
|
||||
g_object_unref(file);
|
||||
|
|
|
@ -421,29 +421,31 @@ void FileInfoJob::refreshInfoContents(GFileInfo *new_info)
|
|||
info->m_file_size = nullptr;
|
||||
}
|
||||
|
||||
auto systemTimeFormat = GlobalSettings::getInstance()->getSystemTimeFormat();
|
||||
QDateTime date = QDateTime::fromMSecsSinceEpoch(info->m_modified_time*1000);
|
||||
// auto systemTimeFormat = GlobalSettings::getInstance()->getSystemTimeFormat();
|
||||
// QDateTime date = QDateTime::fromMSecsSinceEpoch(info->m_modified_time*1000);
|
||||
if (info->m_modified_time) {
|
||||
info->m_modified_date = date.toString(systemTimeFormat);
|
||||
//info->m_modified_date = date.toString(systemTimeFormat);
|
||||
info->m_modified_date = GlobalSettings::getInstance()->transToSystemTimeFormat(info->m_modified_time);
|
||||
} else {
|
||||
info->m_modified_date = nullptr;
|
||||
}
|
||||
|
||||
if (info->m_access_time) {
|
||||
date = QDateTime::fromMSecsSinceEpoch(info->m_access_time*1000);
|
||||
info->m_access_date = date.toString(systemTimeFormat);
|
||||
// date = QDateTime::fromMSecsSinceEpoch(info->m_access_time*1000);
|
||||
// info->m_access_date = date.toString(systemTimeFormat);
|
||||
info->m_access_date = GlobalSettings::getInstance()->transToSystemTimeFormat(info->m_access_time);
|
||||
} else {
|
||||
info->m_access_date = nullptr;
|
||||
}
|
||||
|
||||
if (g_file_info_has_attribute(new_info, "trash::deletion-date"))
|
||||
{
|
||||
QString deletionDate = g_file_info_get_attribute_as_string(new_info, G_FILE_ATTRIBUTE_TRASH_DELETION_DATE);
|
||||
info->m_deletion_date = deletionDate.replace("T", " ");
|
||||
QDateTime dateTime = QDateTime::fromString (deletionDate, "yyyy-MM-dd HH:mm:ss");
|
||||
info->m_deletion_date_uint64 = dateTime.toMSecsSinceEpoch ();
|
||||
date = QDateTime::fromMSecsSinceEpoch(info->m_deletion_date_uint64);
|
||||
info->m_deletion_date = date.toString(systemTimeFormat);
|
||||
QString deletionDate = g_file_info_get_attribute_as_string(new_info, G_FILE_ATTRIBUTE_TRASH_DELETION_DATE);
|
||||
info->m_deletion_date = deletionDate.replace("T", " ");
|
||||
QDateTime dateTime = QDateTime::fromString (deletionDate, "yyyy-MM-dd HH:mm:ss");
|
||||
info->m_deletion_date_uint64 = dateTime.toMSecsSinceEpoch ();
|
||||
//time already processed, need /1000 to origin state
|
||||
info->m_deletion_date = GlobalSettings::getInstance()->transToSystemTimeFormat(info->m_deletion_date_uint64/1000);
|
||||
}
|
||||
if (g_file_info_has_attribute(new_info, G_FILE_ATTRIBUTE_TRASH_ORIG_PATH)) {
|
||||
auto origPath = g_file_info_get_attribute_byte_string(new_info, G_FILE_ATTRIBUTE_TRASH_ORIG_PATH);
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
#include <QApplication>
|
||||
#include <QPalette>
|
||||
#include <QScreen>
|
||||
#ifdef KY_SDK_DATE
|
||||
#include <kysdk/kysdk-system/libkydate.h>
|
||||
#endif
|
||||
|
||||
#ifdef KY_SDK_SYSINFO
|
||||
#include <kysdk/kysdk-system/libkysysinfo.h>
|
||||
|
@ -465,6 +468,55 @@ QString GlobalSettings::getSystemTimeFormat()
|
|||
//m_system_time_format = m_date_format + " " + m_time_format;
|
||||
return m_system_time_format;
|
||||
}
|
||||
|
||||
QString GlobalSettings::transToSystemTimeFormat(guint64 mtime, bool longFormat)
|
||||
{
|
||||
QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(mtime *1000);
|
||||
QString systemTimeFormat = GlobalSettings::getInstance()->getSystemTimeFormat();
|
||||
|
||||
#ifdef KY_SDK_DATE
|
||||
struct tm *m_tm;
|
||||
time_t lt;
|
||||
lt = time(NULL);
|
||||
m_tm = localtime(<);
|
||||
|
||||
QDate date = dateTime.date();
|
||||
QTime qtime = dateTime.time();
|
||||
|
||||
m_tm->tm_year = date.year();
|
||||
m_tm->tm_mon = date.month();
|
||||
m_tm->tm_mday = date.day();
|
||||
|
||||
m_tm->tm_hour = qtime.hour();
|
||||
m_tm->tm_min = qtime.minute();
|
||||
m_tm->tm_sec = qtime.second();
|
||||
qDebug() << "year:"<<date.year()<<"month:"<<date.month()<<"day:"<<date.day();
|
||||
//set date and time show format, task #101605
|
||||
auto ret = kdk_system_timeformat_transform(m_tm);
|
||||
auto formatDate = kdk_system_shortformat_transform(m_tm);
|
||||
//sdk接口会改变结构体数据,需要重初始化要使用的日期数据
|
||||
//属于接口缺陷,已跟SDK接口负责人沟通,先使用此方式
|
||||
m_tm->tm_year = date.year();
|
||||
m_tm->tm_mon = date.month();
|
||||
m_tm->tm_mday = date.day();
|
||||
if (longFormat)
|
||||
formatDate = kdk_system_longformat_transform(m_tm);
|
||||
if (ret && formatDate){
|
||||
QString dateStr = g_strdup_printf("%s %s", formatDate, ret->timesec);
|
||||
qDebug() << "transToSystemTimeFormat:"<<dateStr<<systemTimeFormat;
|
||||
//释放结构体
|
||||
kdk_free_timeinfo(ret);
|
||||
|
||||
//use sdk interface
|
||||
if (dateStr.trimmed().length() > 0)
|
||||
return dateStr;
|
||||
}
|
||||
#endif
|
||||
|
||||
//old way of date, processed by self
|
||||
return dateTime.toString(systemTimeFormat);
|
||||
}
|
||||
|
||||
void GlobalSettings::setGSettingValue(const QString &key, const QVariant &value)
|
||||
{
|
||||
if (!m_peony_gsettings)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <QMutex>
|
||||
|
||||
#include "peony-core_global.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
//顶部菜单 - Top menu
|
||||
#define RESIDENT_IN_BACKEND "resident"
|
||||
|
@ -133,6 +134,12 @@
|
|||
//dbus
|
||||
#define DBUS_STATUS_MANAGER_IF "com.kylin.statusmanager.interface"
|
||||
|
||||
#ifdef KY_SDK_DATE
|
||||
#define SDK_DATE_SERVER_PATH "/com/kylin/kysdk/Date"
|
||||
#define SDK_DATE_SERVER_SERVICE "com.kylin.kysdk.DateServer"
|
||||
#define SDK_DATE_SERVER_INTERFACE "com.kylin.kysdk.DateInterface"
|
||||
#endif
|
||||
|
||||
class QGSettings;
|
||||
|
||||
namespace Peony {
|
||||
|
@ -167,6 +174,7 @@ public Q_SLOTS:
|
|||
void setTimeFormat(const QString &value);
|
||||
void setDateFormat(const QString &value);
|
||||
QString getSystemTimeFormat();
|
||||
QString transToSystemTimeFormat(guint64 mtime, bool longFormat=false);
|
||||
|
||||
/*!
|
||||
* \brief 通过GSetting保存设置
|
||||
|
|
|
@ -293,9 +293,10 @@ QVariant FileItemModel::data(const QModelIndex &index, int role) const
|
|||
case Qt::DisplayRole:
|
||||
//trash files show delete Date
|
||||
if (m_root_uri.startsWith("trash://") && !item->m_info->deletionDate().isNull()) {
|
||||
QDateTime deleteTime = QDateTime::fromMSecsSinceEpoch(item->m_info->deletionTime (), Qt::LocalTime);
|
||||
QString format = GlobalSettings::getInstance()->getSystemTimeFormat();
|
||||
return QVariant(deleteTime.toString(format));
|
||||
// QDateTime deleteTime = QDateTime::fromMSecsSinceEpoch(item->m_info->deletionTime (), Qt::LocalTime);
|
||||
// QString format = GlobalSettings::getInstance()->getSystemTimeFormat();
|
||||
//use sdk interface to get time format
|
||||
return QVariant(item->m_info->deletionDate());
|
||||
}
|
||||
return QVariant(item->m_info->modifiedDate());
|
||||
default:
|
||||
|
|
|
@ -120,6 +120,9 @@
|
|||
|
||||
#define FONT_SETTINGS "org.ukui.style"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusReply>
|
||||
|
||||
static MainWindow *last_resize_window = nullptr;
|
||||
|
||||
static QWidgetList blur_window_list;
|
||||
|
@ -216,6 +219,31 @@ MainWindow::MainWindow(const QString &uri, QWidget *parent) : QMainWindow(parent
|
|||
m_is_blur_window = true;
|
||||
KWindowEffects::enableBlurBehind(winId(), true);
|
||||
}
|
||||
|
||||
#ifdef KY_SDK_DATE
|
||||
QDBusConnection conn = QDBusConnection::sessionBus();
|
||||
if (! conn.isConnected()) {
|
||||
qCritical()<<"failed to init mDbusDateServer, can not connect to session dbus";
|
||||
return;
|
||||
}
|
||||
|
||||
mDbusDateServer = new QDBusInterface(SDK_DATE_SERVER_SERVICE,
|
||||
SDK_DATE_SERVER_PATH,
|
||||
SDK_DATE_SERVER_INTERFACE,
|
||||
QDBusConnection::sessionBus());
|
||||
|
||||
if (! mDbusDateServer->isValid()){
|
||||
qCritical() << "Create /com/kylin/kysdk/Date Interface Failed " << QDBusConnection::systemBus().lastError();
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusConnection::sessionBus().connect(SDK_DATE_SERVER_SERVICE,
|
||||
SDK_DATE_SERVER_PATH,
|
||||
SDK_DATE_SERVER_INTERFACE,
|
||||
"ShortDateSignal",
|
||||
this,
|
||||
SLOT(updateDateFormat(QString)));
|
||||
#endif
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -231,6 +259,16 @@ MainWindow::~MainWindow()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateDateFormat(QString dateFormat)
|
||||
{
|
||||
//update date and time show format, task #101605
|
||||
qDebug() << "sdk format signal:"<<dateFormat;
|
||||
if (m_date_format != dateFormat){
|
||||
this->refresh();
|
||||
m_date_format = dateFormat;
|
||||
}
|
||||
}
|
||||
|
||||
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::MouseMove) {
|
||||
|
|
|
@ -159,6 +159,8 @@ public Q_SLOTS:
|
|||
|
||||
void updateSearchStatus(bool isSearching);
|
||||
|
||||
void updateDateFormat(QString dateFormat);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
@ -217,6 +219,9 @@ private:
|
|||
|
||||
QDBusInterface *m_statusManagerDBus = nullptr;
|
||||
bool m_is_blur_window = false;
|
||||
|
||||
QString m_date_format = "";
|
||||
QDBusInterface *mDbusDateServer;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
Loading…
Reference in New Issue