diff --git a/common/tablemodelistener.cpp b/common/tablemodelistener.cpp index 31e2eeb..5858c9d 100644 --- a/common/tablemodelistener.cpp +++ b/common/tablemodelistener.cpp @@ -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 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 resultMode = m_modeInterface->call("get_current_rotation"); + if (resultMode.isValid()) { + qDebug() << "Table value " << resultMode.value(); + return resultMode.value(); + } + } + return NORMAL; } \ No newline at end of file diff --git a/common/tablemodelistener.h b/common/tablemodelistener.h index e1a95db..c13057f 100644 --- a/common/tablemodelistener.h +++ b/common/tablemodelistener.h @@ -7,22 +7,26 @@ #include #include +#include -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 diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 6fd3b8c..325a3e1 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -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 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, diff --git a/ui/mainwindow.h b/ui/mainwindow.h index 08f871f..f185ec3 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -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