🐞 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_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,
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(rotations_change_signal(QString)), this,
SIGNAL(sigRotationsChange(QString)));
}
TableModeListener::~TableModeListener() {
if (m_modeInterface){
TableModeListener::~TableModeListener()
{
if (m_modeInterface) {
delete m_modeInterface;
m_modeInterface = nullptr;
}
}
bool TableModeListener::getMode() {
bool TableModeListener::getMode()
{
if (m_modeInterface && m_modeInterface->isValid()) {
QDBusPendingReply<bool> resultMode = m_modeInterface->call("get_current_tabletmode");
if (resultMode.isValid()) {
@ -32,4 +36,16 @@ bool TableModeListener::getMode() {
}
}
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,22 +7,26 @@
#include <QObject>
#include <QDBusInterface>
#include <QDebug>
class TableModeListener : public QObject {
const QString NORMAL = "normal";
class TableModeListener : public QObject
{
Q_OBJECT
public:
TableModeListener(QObject *parent = nullptr);
~TableModeListener();
bool getMode();
private:
QString getRotations();
Q_SIGNALS:
void sigModeChange(bool isTable);
void sigModeChange(bool);
void sigRotationsChange(QString);
private:
QDBusInterface *m_modeInterface = nullptr; //平板模式切换
};
#endif //KYLIN_CONNECTIVITY_TABLEMODELISTENER_H
#endif // KYLIN_CONNECTIVITY_TABLEMODELISTENER_H

View File

@ -222,19 +222,9 @@ void MainWindow::initDbus()
}
// 平板模式切换
m_modeDbusInterface = new QDBusInterface(KYLIN_STATUS_MANAGER_NAME, KYLIN_STATUS_MANAGER_PATH,
KYLIN_STATUS_MANAGER_INTERFACE, QDBusConnection::sessionBus());
QObject::connect(m_modeDbusInterface, SIGNAL(mode_change_signal(bool)), this, SLOT(slotModeChanged(bool)));
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_tableModeListener = new TableModeListener(this);
connect(m_tableModeListener, &TableModeListener::sigModeChange, this, &MainWindow::slotModeChanged);
slotModeChanged(m_tableModeListener->getMode());
// 防止熄屏
m_activityDbusInterface = new QDBusInterface(GNOME_SESSION_MANAGER_NAME, GNOME_SESSION_MANAGER_PATH,

View File

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