Skip to content

Commit

Permalink
Fix: Fix issues related to system information (#1725)
Browse files Browse the repository at this point in the history
  • Loading branch information
swq11 and swq authored Sep 25, 2024
1 parent 3c9713d commit b9854c4
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 62 deletions.
32 changes: 32 additions & 0 deletions src/plugin-systeminfo/operation/systeminfodbusproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ const QString &UserexperienceService = QStringLiteral("com.deepin.userexperience
const QString &UserexperiencePath = QStringLiteral("/com/deepin/userexperience/Daemon");
const QString &UserexperienceInterface = QStringLiteral("com.deepin.userexperience.Daemon");

const QString &SystemInfoService = QStringLiteral("com.deepin.system.SystemInfo");
const QString &SystemInfoPath = QStringLiteral("/com/deepin/system/SystemInfo");
const QString &SystemInfoInterface = QStringLiteral("com.deepin.system.SystemInfo");

const QString &TimedateService = QStringLiteral("com.deepin.daemon.Timedate");
const QString &TimedatePath = QStringLiteral("/com/deepin/daemon/Timedate");
const QString &TimedateInterface = QStringLiteral("com.deepin.daemon.Timedate");

SystemInfoDBusProxy::SystemInfoDBusProxy(QObject *parent)
: QObject(parent)
, m_hostname1Inter(new DDBusInterface(HostnameService, HostnamePath, HostnameInterface, QDBusConnection::systemBus(), this))
, m_licenseInfoInter(new DDBusInterface(LicenseInfoService, LicenseInfoPath, LicenseInfoInterface, QDBusConnection::systemBus(), this))
, m_licenseActivatorInter(new DDBusInterface(LicenseActivatorService, LicenseActivatorPath, LicenseActivatorInterface, QDBusConnection::sessionBus(), this))
, m_userexperienceInter(new DDBusInterface(UserexperienceService, UserexperiencePath, UserexperienceInterface, QDBusConnection::sessionBus(), this))
, m_systemInfo(new DDBusInterface(SystemInfoService, SystemInfoPath, SystemInfoInterface, QDBusConnection::systemBus(), this))
, m_timedateInter(new DDBusInterface(TimedateService, TimedatePath, TimedateInterface, QDBusConnection::sessionBus(), this))
{
}

Expand Down Expand Up @@ -69,6 +79,23 @@ void SystemInfoDBusProxy::setAuthorizationState(const int value)
m_licenseInfoInter->setProperty("AuthorizationState", QVariant::fromValue(value));
}

QString SystemInfoDBusProxy::timezone()
{
return qvariant_cast<QString>(m_timedateInter->property("Timezone"));
}

void SystemInfoDBusProxy::setTimezone(const QString &value)
{
QList<QVariant> argumentList;
argumentList << QVariant::fromValue(value) << QVariant::fromValue(true);
m_hostname1Inter->asyncCallWithArgumentList("SetTimezone", argumentList);
}

int SystemInfoDBusProxy::shortDateFormat()
{
return qvariant_cast<int>(m_timedateInter->property("ShortDateFormat"));
}

void SystemInfoDBusProxy::Enable(const bool value)
{
m_userexperienceInter->asyncCallWithArgumentList("Enable", { value });
Expand All @@ -82,6 +109,11 @@ bool SystemInfoDBusProxy::IsEnabled()
return false;
}

qulonglong SystemInfoDBusProxy::memorySize()
{
return m_systemInfo->property("MemorySize").toULongLong();
}

void SystemInfoDBusProxy::Show()
{
m_licenseActivatorInter->asyncCall("Show");
Expand Down
16 changes: 14 additions & 2 deletions src/plugin-systeminfo/operation/systeminfodbusproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,34 @@ class SystemInfoDBusProxy : public QObject
int authorizationState();
void setAuthorizationState(const int value);

Q_PROPERTY(QString Timezone READ timezone WRITE setTimezone NOTIFY TimezoneChanged)
QString timezone();
void setTimezone(const QString &value);

Q_PROPERTY(int ShortDateFormat READ shortDateFormat NOTIFY ShortDateFormatChanged)
int shortDateFormat();

// userexperience
void Enable(const bool value);
bool IsEnabled();
qulonglong memorySize();

signals:
Q_SIGNALS:
void StaticHostnameChanged(const QString &value) const;
void AuthorizationStateChanged(const int value) const;
void TimezoneChanged(const QString &value) const;
void ShortDateFormatChanged(const int value) const;

public slots:
public Q_SLOTS:
void Show();

private:
DDBusInterface *m_hostname1Inter;
DDBusInterface *m_licenseInfoInter;
DDBusInterface *m_licenseActivatorInter;
DDBusInterface *m_userexperienceInter;
DDBusInterface *m_systemInfo;
DDBusInterface *m_timedateInter;
};

#endif // SYSTEMINFODBUSPROXY_H
103 changes: 77 additions & 26 deletions src/plugin-systeminfo/operation/systeminfomodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
#include "QtQml/qqml.h"
#include "dccfactory.h"
#include "math.h"
#include "utils.h"

#include <qdebug.h>

namespace DCC_NAMESPACE{
namespace DCC_NAMESPACE {

static QString formatCap(qulonglong cap, const int size = 1024, quint8 precision = 1)
{
static QStringList type = {" B", " KB", " MB", " GB", " TB"};
static QStringList type = { " B", " KB", " MB", " GB", " TB" };
qulonglong lc = cap;
double dc = cap;
double ds = size;

for(int p = 0; p < type.count(); ++p) {
for (int p = 0; p < type.count(); ++p) {
if (cap < pow(size, p + 1) || p == type.count() - 1) {
if (!precision) {
#ifdef __sw_64__
Expand Down Expand Up @@ -47,17 +48,18 @@ SystemInfoModel::SystemInfoModel(QObject *parent)

}

void SystemInfoModel::setProductName(const QString& name)
void SystemInfoModel::setProductName(const QString &name)
{
if(m_productName == name)
if (m_productName == name)
return;

m_productName = name;
Q_EMIT productNameChanged(m_productName);
}
void SystemInfoModel::setVersionNumber(const QString& number)

void SystemInfoModel::setVersionNumber(const QString &number)
{
if(m_versionNumber == number)
if (m_versionNumber == number)
return;

m_versionNumber = number;
Expand All @@ -66,7 +68,7 @@ void SystemInfoModel::setVersionNumber(const QString& number)

void SystemInfoModel::setVersion(const QString &version)
{
if(m_version == version)
if (m_version == version)
return;

m_version = version;
Expand All @@ -75,16 +77,16 @@ void SystemInfoModel::setVersion(const QString &version)

void SystemInfoModel::setType(qlonglong type)
{
if(m_type == QString("%1").arg(type))
return ;
if (m_type == QString("%1").arg(type))
return;

m_type = QString("%1").arg(type);
typeChanged(m_type);
}

void SystemInfoModel::setProcessor(const QString &processor)
{
if(m_processor == processor)
if (m_processor == processor)
return;

m_processor = processor;
Expand All @@ -102,6 +104,55 @@ void SystemInfoModel::setEndUserAgreementPath(const QString &path)
m_endUserAgreementTextPath = path;
}

QString SystemInfoModel::graphicsPlatform() const
{
return m_graphicsPlatform;
}

void SystemInfoModel::setGraphicsPlatform(const QString &newGraphicsPlatform)
{
if (m_graphicsPlatform == newGraphicsPlatform)
return;
m_graphicsPlatform = newGraphicsPlatform;
Q_EMIT graphicsPlatformChanged();
}

bool SystemInfoModel::showAuthorization() const
{
return !(IS_COMMUNITY_SYSTEM || DSysInfo::UosEditionUnknown == DSysInfo::uosEditionType()) && DSysInfo::uosEditionType() != DSysInfo::UosEnterpriseC;
}

bool SystemInfoModel::showUserExperienceProgram() const
{
return !IS_SERVER_SYSTEM && !IS_COMMUNITY_SYSTEM && DSysInfo::isDeepin();
}

QString SystemInfoModel::systemInstallationDate() const
{
return m_systemInstallationDate;
}

void SystemInfoModel::setSystemInstallationDate(const QString &newSystemInstallationDate)
{
if (m_systemInstallationDate == newSystemInstallationDate)
return;
m_systemInstallationDate = newSystemInstallationDate;
Q_EMIT systemInstallationDateChanged();
}

QString SystemInfoModel::logoPath() const
{
return m_logoPath;
}

void SystemInfoModel::setLogoPath(const QString &newLogoPath)
{
if (m_logoPath == newLogoPath)
return;
m_logoPath = newLogoPath;
Q_EMIT logoPathChanged();
}

bool SystemInfoModel::showDetail() const
{
return m_showDetail;
Expand All @@ -112,7 +163,7 @@ void SystemInfoModel::setShowDetail(bool newShowDetail)
if (m_showDetail == newShowDetail)
return;
m_showDetail = newShowDetail;
emit showDetailChanged();
Q_EMIT showDetailChanged();
}

void SystemInfoModel::onLicenseStateChanged(const ActiveState &state)
Expand Down Expand Up @@ -150,7 +201,7 @@ void SystemInfoModel::setLicenseStatusColor(const QColor &newLicenseStatusColor)
if (m_licenseStatusColor == newLicenseStatusColor)
return;
m_licenseStatusColor = newLicenseStatusColor;
emit licenseStatusColorChanged();
Q_EMIT licenseStatusColorChanged();
}

QString SystemInfoModel::licenseActionText() const
Expand All @@ -163,7 +214,7 @@ void SystemInfoModel::setLicenseActionText(const QString &newLicenseActionText)
if (m_licenseActionText == newLicenseActionText)
return;
m_licenseActionText = newLicenseActionText;
emit licenseActionTextChanged();
Q_EMIT licenseActionTextChanged();
}

QString SystemInfoModel::licenseStatusText() const
Expand All @@ -176,7 +227,7 @@ void SystemInfoModel::setLicenseStatusText(const QString &newLicenseStatusText)
if (m_licenseStatusText == newLicenseStatusText)
return;
m_licenseStatusText = newLicenseStatusText;
emit licenseStatusTextChanged();
Q_EMIT licenseStatusTextChanged();
}

QString SystemInfoModel::systemCopyright() const
Expand All @@ -189,7 +240,7 @@ void SystemInfoModel::setSystemCopyright(const QString &newSystemCopyright)
if (m_systemCopyright == newSystemCopyright)
return;
m_systemCopyright = newSystemCopyright;
emit systemCopyrightChanged();
Q_EMIT systemCopyrightChanged();
}

bool SystemInfoModel::joinUeProgram() const
Expand All @@ -202,7 +253,7 @@ void SystemInfoModel::setJoinUeProgram(bool newJoinUeProgram)
if (m_joinUeProgram == newJoinUeProgram)
return;
m_joinUeProgram = newJoinUeProgram;
emit joinUeProgramChanged();
Q_EMIT joinUeProgramChanged();
}

QString SystemInfoModel::userExperienceProgramText() const
Expand All @@ -215,7 +266,7 @@ void SystemInfoModel::setUserExperienceProgramText(const QString &newUserExperie
if (m_userExperienceProgramText == newUserExperienceProgramText)
return;
m_userExperienceProgramText = newUserExperienceProgramText;
emit userExperienceProgramTextChanged();
Q_EMIT userExperienceProgramTextChanged();
}

QString SystemInfoModel::userLicense() const
Expand All @@ -228,7 +279,7 @@ void SystemInfoModel::setUserLicense(const QString &newUserLicense)
if (m_userLicense == newUserLicense)
return;
m_userLicense = newUserLicense;
emit userLicenseChanged();
Q_EMIT userLicenseChanged();
}

QString SystemInfoModel::gnuLinceseContent() const
Expand All @@ -241,7 +292,7 @@ void SystemInfoModel::setGnuLinceseContent(const QString &newGnuLinceseContent)
if (m_gnuLinceseContent == newGnuLinceseContent)
return;
m_gnuLinceseContent = newGnuLinceseContent;
emit gnuLinceseContentChanged();
Q_EMIT gnuLinceseContentChanged();
}

QString SystemInfoModel::gnuLinceseTitle() const
Expand All @@ -254,7 +305,7 @@ void SystemInfoModel::setGnuLinceseTitle(const QString &newGnuLinceseTitle)
if (m_gnuLinceseTitle == newGnuLinceseTitle)
return;
m_gnuLinceseTitle = newGnuLinceseTitle;
emit gnuLinceseTitleChanged();
Q_EMIT gnuLinceseTitleChanged();
}

QString SystemInfoModel::privacyPolicy() const
Expand All @@ -267,18 +318,18 @@ void SystemInfoModel::setPrivacyPolicy(const QString &newPrivacyPolicy)
if (m_privacyPolicy == newPrivacyPolicy)
return;
m_privacyPolicy = newPrivacyPolicy;
emit privacyPolicyChanged();
Q_EMIT privacyPolicyChanged();
}

void SystemInfoModel::setMemory(qulonglong totalMemory, qulonglong installedMemory)
{
QString mem_device_size = formatCap(installedMemory, 1024, 0);
QString mem = formatCap(totalMemory);
if(m_memory == mem)
return ;
if (m_memory == mem)
return;

m_memory = mem;
m_memory = QString("%1 (%2)").arg(mem, tr("available"));
m_memory = QString("%1 (%2 %3)").arg(mem_device_size, mem, tr("available"));
memoryChanged(m_memory);
}

Expand All @@ -302,4 +353,4 @@ void SystemInfoModel::setLicenseState(DCC_NAMESPACE::ActiveState state)
onLicenseStateChanged(state);
}

}
}
Loading

0 comments on commit b9854c4

Please sign in to comment.