🐞 fix(UI模块): 重新封装系统状态切换接口

This commit is contained in:
huheng@kylinos.cn 2023-03-31 15:39:41 +08:00
parent f1d44ec2bf
commit 0fd9287508
4 changed files with 35 additions and 24 deletions

View File

@ -9,22 +9,26 @@
#define KYLIN_STATUS_MANAGER_NAME "com.kylin.statusmanager.interface" #define KYLIN_STATUS_MANAGER_NAME "com.kylin.statusmanager.interface"
#define KYLIN_STATUS_MANAGER_INTERFACE "com.kylin.statusmanager.interface" #define KYLIN_STATUS_MANAGER_INTERFACE "com.kylin.statusmanager.interface"
TableModeListener::TableModeListener(QObject *parent) : QObject(parent){ TableModeListener::TableModeListener(QObject *parent) : QObject(parent)
{
// 平板模式切换 // 平板模式切换
m_modeInterface = new QDBusInterface(KYLIN_STATUS_MANAGER_NAME, KYLIN_STATUS_MANAGER_PATH, m_modeInterface = new QDBusInterface(KYLIN_STATUS_MANAGER_NAME, KYLIN_STATUS_MANAGER_PATH,
KYLIN_STATUS_MANAGER_INTERFACE, QDBusConnection::sessionBus()); KYLIN_STATUS_MANAGER_INTERFACE, QDBusConnection::sessionBus());
QObject::connect(m_modeInterface, SIGNAL(mode_change_signal(bool)), this, SIGNAL(sigModeChange(bool))); QObject::connect(m_modeInterface, SIGNAL(mode_change_signal(bool)), this, SIGNAL(sigModeChange(bool)));
QObject::connect(m_modeInterface, SIGNAL(rotations_change_signal(QString)), this,
SIGNAL(sigRotationsChange(QString)));
} }
TableModeListener::~TableModeListener() { TableModeListener::~TableModeListener()
{
if (m_modeInterface) { if (m_modeInterface) {
delete m_modeInterface; delete m_modeInterface;
m_modeInterface = nullptr; m_modeInterface = nullptr;
} }
} }
bool TableModeListener::getMode() { bool TableModeListener::getMode()
{
if (m_modeInterface && m_modeInterface->isValid()) { if (m_modeInterface && m_modeInterface->isValid()) {
QDBusPendingReply<bool> resultMode = m_modeInterface->call("get_current_tabletmode"); QDBusPendingReply<bool> resultMode = m_modeInterface->call("get_current_tabletmode");
if (resultMode.isValid()) { if (resultMode.isValid()) {
@ -33,3 +37,15 @@ bool TableModeListener::getMode() {
} }
return false; return false;
} }
QString TableModeListener::getRotations()
{
if (m_modeInterface && m_modeInterface->isValid()) {
QDBusPendingReply<QString> resultMode = m_modeInterface->call("get_current_rotation");
if (resultMode.isValid()) {
qDebug() << "Table value " << resultMode.value();
return resultMode.value();
}
}
return NORMAL;
}

View File

@ -7,18 +7,22 @@
#include <QObject> #include <QObject>
#include <QDBusInterface> #include <QDBusInterface>
#include <QDebug>
class TableModeListener : public QObject { const QString NORMAL = "normal";
class TableModeListener : public QObject
{
Q_OBJECT Q_OBJECT
public: public:
TableModeListener(QObject *parent = nullptr); TableModeListener(QObject *parent = nullptr);
~TableModeListener(); ~TableModeListener();
bool getMode(); bool getMode();
private: QString getRotations();
Q_SIGNALS: Q_SIGNALS:
void sigModeChange(bool isTable); void sigModeChange(bool);
void sigRotationsChange(QString);
private: private:
QDBusInterface *m_modeInterface = nullptr; //平板模式切换 QDBusInterface *m_modeInterface = nullptr; //平板模式切换

View File

@ -222,19 +222,9 @@ void MainWindow::initDbus()
} }
// 平板模式切换 // 平板模式切换
m_modeDbusInterface = new QDBusInterface(KYLIN_STATUS_MANAGER_NAME, KYLIN_STATUS_MANAGER_PATH, m_tableModeListener = new TableModeListener(this);
KYLIN_STATUS_MANAGER_INTERFACE, QDBusConnection::sessionBus()); connect(m_tableModeListener, &TableModeListener::sigModeChange, this, &MainWindow::slotModeChanged);
QObject::connect(m_modeDbusInterface, SIGNAL(mode_change_signal(bool)), this, SLOT(slotModeChanged(bool))); slotModeChanged(m_tableModeListener->getMode());
if (m_modeDbusInterface->isValid()) {
QDBusPendingReply<bool> reply_pcORpad = m_modeDbusInterface->call("get_current_tabletmode");
if (reply_pcORpad.isValid()) {
slotModeChanged(reply_pcORpad.value());
} else {
slotModeChanged(false);
}
} else {
slotModeChanged(false);
}
// 防止熄屏 // 防止熄屏
m_activityDbusInterface = new QDBusInterface(GNOME_SESSION_MANAGER_NAME, GNOME_SESSION_MANAGER_PATH, m_activityDbusInterface = new QDBusInterface(GNOME_SESSION_MANAGER_NAME, GNOME_SESSION_MANAGER_PATH,

View File

@ -46,6 +46,7 @@
#include "androidhomepage.h" #include "androidhomepage.h"
#include "fileview.h" #include "fileview.h"
#include "messagedialog.h" #include "messagedialog.h"
#include "tablemodelistener.h"
#define KYLIN_CONNECTIVITY_SEND_SERVICE "com.kylin.connectivity.send" #define KYLIN_CONNECTIVITY_SEND_SERVICE "com.kylin.connectivity.send"
#define KYLIN_CONNECTIVITY_SEND_PATH "/com/kylin/connectivity" #define KYLIN_CONNECTIVITY_SEND_PATH "/com/kylin/connectivity"
@ -215,7 +216,7 @@ private:
PcScreenManage *m_pcScreen = nullptr; // PC投屏 PcScreenManage *m_pcScreen = nullptr; // PC投屏
QDBusInterface *m_dbusInterface = nullptr; // 挂载ftpdubs QDBusInterface *m_dbusInterface = nullptr; // 挂载ftpdubs
DirManager *m_dirManager = nullptr; // 本地用户目录信息管理 DirManager *m_dirManager = nullptr; // 本地用户目录信息管理
QDBusInterface *m_modeDbusInterface = nullptr; // 平板模式切换 TableModeListener *m_tableModeListener = nullptr; // 平板模式切换
QDBusInterface *m_activityDbusInterface = nullptr; // 防止熄屏 QDBusInterface *m_activityDbusInterface = nullptr; // 防止熄屏
QTimer *m_timer = nullptr; // 连接加载定时器,连接超时处理 QTimer *m_timer = nullptr; // 连接加载定时器,连接超时处理
// disc // disc