🐞 fix(反控): 添加对快捷键反控的处理
通过接收反控进程的消息处理通过快捷键反控的处理 180739 【多端协同】麒麟之间建立投屏后,使用快捷键ctrl+h进行反控与点击反控选项,顶部悬浮框显示不同
This commit is contained in:
parent
79ca988167
commit
95156ac086
|
@ -4,6 +4,8 @@
|
|||
#include <QDebug>
|
||||
|
||||
const int CONTROL_PORT = 27191;
|
||||
const QByteArray CONTROL_START = "control:start";
|
||||
const QByteArray CONTROL_END = "control:end";
|
||||
|
||||
Control::Control(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
@ -11,6 +13,13 @@ Control::Control(QObject *parent) : QObject(parent)
|
|||
connect(m_process, &QProcess::started, this, [=]() {
|
||||
if (m_isServer) {
|
||||
qInfo() << "Anti control server started successfully!";
|
||||
m_server = new QLocalServer(this);
|
||||
connect(m_server, &QLocalServer::newConnection, this, &Control::slotNewConnected);
|
||||
// 设置服务器名字
|
||||
bool flag = m_server->listen("/tmp/anti_control_server.socket");
|
||||
if (!flag) {
|
||||
qWarning() << "anti_control_server start listen error!";
|
||||
}
|
||||
Q_EMIT sigServerState(true);
|
||||
} else {
|
||||
qInfo() << "Anti control client started successfully!";
|
||||
|
@ -42,10 +51,11 @@ Control::~Control()
|
|||
void Control::startServer()
|
||||
{
|
||||
m_isServer = true;
|
||||
QString serverpara = "anti-control-server -f --debug DEBUG --name server --disable-crypto --log " + QDir::homePath()
|
||||
+ "/.log/kylin-connectivity-control.log --disable-client-cert-checking"
|
||||
" -c "
|
||||
+ "/usr/share/kylin-connectivity/control.conf --address :" + QString::number(CONTROL_PORT);
|
||||
QString serverpara = "anti-control-server -f --debug DEBUG --name server --disable-crypto --log " +
|
||||
QDir::homePath() +
|
||||
"/.log/kylin-connectivity-control.log --disable-client-cert-checking"
|
||||
" -c " +
|
||||
"/usr/share/kylin-connectivity/control.conf --address :" + QString::number(CONTROL_PORT);
|
||||
qInfo() << "Anti control server starting...";
|
||||
m_process->start(serverpara);
|
||||
}
|
||||
|
@ -53,10 +63,33 @@ void Control::startServer()
|
|||
void Control::startClient(QString address)
|
||||
{
|
||||
m_isServer = false;
|
||||
QString clientpara = "anti-control-client -f --debug DEBUG --name client --disable-crypto --log " + QDir::homePath()
|
||||
+ "/.log/kylin-connectivity-control.log"
|
||||
" ["
|
||||
+ address + "]:" + QString::number(CONTROL_PORT);
|
||||
QString clientpara = "anti-control-client -f --debug DEBUG --name client --disable-crypto --log " +
|
||||
QDir::homePath() +
|
||||
"/.log/kylin-connectivity-control.log"
|
||||
" [" +
|
||||
address + "]:" + QString::number(CONTROL_PORT);
|
||||
qInfo() << "Anti control client starting..";
|
||||
m_process->start(clientpara);
|
||||
}
|
||||
|
||||
void Control::slotNewConnected()
|
||||
{
|
||||
qInfo() << "anti_control_server new connection";
|
||||
m_socket = m_server->nextPendingConnection();
|
||||
connect(m_socket, &QLocalSocket::readyRead, this, &Control::slotReadyRead);
|
||||
}
|
||||
|
||||
void Control::slotReadyRead()
|
||||
{
|
||||
if (m_socket) {
|
||||
// 处理接收到的数据
|
||||
QByteArray data = m_socket->readAll();
|
||||
qInfo() << "anti_control_server revc msg: " << data;
|
||||
if (data.contains(CONTROL_START)) {
|
||||
Q_EMIT sigControlState(true);
|
||||
}
|
||||
if (data.contains(CONTROL_END)) {
|
||||
Q_EMIT sigControlState(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
#include <QLocalServer>
|
||||
#include <QLocalSocket>
|
||||
|
||||
class Control : public QObject
|
||||
{
|
||||
|
@ -17,11 +19,16 @@ public:
|
|||
Q_SIGNALS:
|
||||
void sigServerState(bool);
|
||||
void sigClientState(bool);
|
||||
void sigControlState(bool);
|
||||
private Q_SLOTS:
|
||||
void slotNewConnected();
|
||||
void slotReadyRead();
|
||||
|
||||
private:
|
||||
QProcess *m_process = nullptr;
|
||||
QLocalServer *m_server = nullptr;
|
||||
QLocalSocket *m_socket = nullptr;
|
||||
bool m_isServer = true;
|
||||
};
|
||||
|
||||
#endif // CONTROL_H
|
||||
#endif // CONTROL_H
|
|
@ -148,6 +148,22 @@ void PcScreenManage::startCurtain(QString roomid)
|
|||
void PcScreenManage::startControl()
|
||||
{
|
||||
m_control = new Control(this);
|
||||
connect(m_control, &Control::sigControlState, this, [=](bool state) {
|
||||
if (state && !m_isAtiveStarted) {
|
||||
ScreenManageMsg message;
|
||||
message.set_msg(ScreenManageMsg::STARTEDCONTROL);
|
||||
sendMessage(message);
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::PassiveControl);
|
||||
showView();
|
||||
m_curtain->hideTabBar();
|
||||
} else if (!state && !m_isAtiveEnd) {
|
||||
ScreenManageMsg message;
|
||||
message.set_msg(ScreenManageMsg::EXITCONTROL);
|
||||
sendMessage(message);
|
||||
showView();
|
||||
m_curtain->showTabBar();
|
||||
}
|
||||
});
|
||||
connect(m_control, &Control::sigServerState, this, [=](bool isSuccess) {
|
||||
if (isSuccess) {
|
||||
ScreenManageMsg message;
|
||||
|
@ -183,6 +199,8 @@ void PcScreenManage::startedControl()
|
|||
sendMessage(message);
|
||||
showView();
|
||||
m_curtain->hideTabBar();
|
||||
m_isAtiveStarted = true;
|
||||
m_isAtiveEnd = false;
|
||||
QString common = "xdotool key ctrl+h";
|
||||
system(common.toUtf8().constData());
|
||||
}
|
||||
|
@ -235,6 +253,8 @@ void PcScreenManage::closeCurtain()
|
|||
|
||||
void PcScreenManage::closeControl()
|
||||
{
|
||||
m_isAtiveEnd = false;
|
||||
m_isAtiveStarted = false;
|
||||
if (m_control != nullptr) {
|
||||
delete m_control;
|
||||
m_control = nullptr;
|
||||
|
@ -254,8 +274,8 @@ void PcScreenManage::slotServerNewConnection()
|
|||
return;
|
||||
}
|
||||
m_messageTcpSocket = m_tcpServer->nextPendingConnection();
|
||||
connect(m_messageTcpSocket, &QTcpSocket::readyRead, this, &PcScreenManage::onMessageReadyRead);
|
||||
connect(m_messageTcpSocket, &QTcpSocket::disconnected, this, &PcScreenManage::slotSocketDisconnect);
|
||||
connect(m_messageTcpSocket, &QTcpSocket::readyRead, this, &PcScreenManage::onMessageReadyRead);
|
||||
connect(m_messageTcpSocket, &QTcpSocket::disconnected, this, &PcScreenManage::slotSocketDisconnect);
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::SharingRequest);
|
||||
}
|
||||
|
||||
|
@ -295,82 +315,84 @@ void PcScreenManage::onMessageReadyRead()
|
|||
}
|
||||
|
||||
switch (message.msg()) {
|
||||
case ScreenManageMsg::REFUSE: {
|
||||
qInfo() << "Remote rejection of screen projection request.";
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::RemoteRejection);
|
||||
} break;
|
||||
case ScreenManageMsg::CURTAINREADY: {
|
||||
qInfo() << "Remote consent to screen projection request.";
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::Successfully);
|
||||
if (m_deviceType == PcScreenManage::DeviceType::PC) {
|
||||
startControl();
|
||||
} else {
|
||||
startPcService();
|
||||
}
|
||||
} break;
|
||||
case ScreenManageMsg::SCREENREADY: {
|
||||
qInfo() << "Receive remote screen projection information.";
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::StartedScreen);
|
||||
QString roomid = QString::fromStdString(message.roomid());
|
||||
startCurtain(roomid);
|
||||
} break;
|
||||
case ScreenManageMsg::CURTAINEXIT: {
|
||||
qInfo() << "The screen receiver has disconnected the screen projection.";
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::ScreenExit);
|
||||
disconnected();
|
||||
} break;
|
||||
case ScreenManageMsg::SCREENEXIT: {
|
||||
qInfo() << "The screen sharing party quit the service.";
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::ScreenExit);
|
||||
disconnected();
|
||||
} break;
|
||||
case ScreenManageMsg::STARTEDCONTROL: {
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::StartedControl);
|
||||
} break;
|
||||
case ScreenManageMsg::EXITCONTROL: {
|
||||
qInfo() << "Exit anti control.";
|
||||
if (m_isService) {
|
||||
QString common = "xdotool key ctrl+g";
|
||||
system(common.toUtf8().constData());
|
||||
m_curtain->showTabBar();
|
||||
} else {
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::ExitControl);
|
||||
}
|
||||
} break;
|
||||
case ScreenManageMsg::REFUSE: {
|
||||
qInfo() << "Remote rejection of screen projection request.";
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::RemoteRejection);
|
||||
} break;
|
||||
case ScreenManageMsg::CURTAINREADY: {
|
||||
qInfo() << "Remote consent to screen projection request.";
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::Successfully);
|
||||
if (m_deviceType == PcScreenManage::DeviceType::PC) {
|
||||
startControl();
|
||||
} else {
|
||||
startPcService();
|
||||
}
|
||||
} break;
|
||||
case ScreenManageMsg::SCREENREADY: {
|
||||
qInfo() << "Receive remote screen projection information.";
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::StartedScreen);
|
||||
QString roomid = QString::fromStdString(message.roomid());
|
||||
startCurtain(roomid);
|
||||
} break;
|
||||
case ScreenManageMsg::CURTAINEXIT: {
|
||||
qInfo() << "The screen receiver has disconnected the screen projection.";
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::ScreenExit);
|
||||
disconnected();
|
||||
} break;
|
||||
case ScreenManageMsg::SCREENEXIT: {
|
||||
qInfo() << "The screen sharing party quit the service.";
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::ScreenExit);
|
||||
disconnected();
|
||||
} break;
|
||||
case ScreenManageMsg::STARTEDCONTROL: {
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::StartedControl);
|
||||
} break;
|
||||
case ScreenManageMsg::EXITCONTROL: {
|
||||
qInfo() << "Exit anti control.";
|
||||
if (m_isService) {
|
||||
m_isAtiveEnd = true;
|
||||
m_isAtiveStarted = false;
|
||||
QString common = "xdotool key ctrl+g";
|
||||
system(common.toUtf8().constData());
|
||||
m_curtain->showTabBar();
|
||||
} else {
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::ExitControl);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void PcScreenManage::handleStateChange(QAbstractSocket::SocketState state)
|
||||
{
|
||||
switch (state) {
|
||||
case QAbstractSocket::UnconnectedState:
|
||||
// 套接字未连接。
|
||||
qInfo() << "The socket is not connected.";
|
||||
break;
|
||||
case QAbstractSocket::HostLookupState:
|
||||
// 套接字正在查询主机。
|
||||
qInfo() << "The socket is performing a host name lookup.";
|
||||
break;
|
||||
case QAbstractSocket::ConnectingState:
|
||||
// 套接字开始建立连接。
|
||||
qInfo() << "The socket has started establishing a connection.";
|
||||
break;
|
||||
case QAbstractSocket::ConnectedState:
|
||||
// 新的连接已建立。
|
||||
qInfo() << "A connection is established.";
|
||||
break;
|
||||
case QAbstractSocket::BoundState:
|
||||
// 套接字已绑定到一个地址和端口。
|
||||
qInfo() << "The socket is bound to an address and port.";
|
||||
break;
|
||||
case QAbstractSocket::ClosingState:
|
||||
// 套接字即将关闭(数据可能仍在等待写入)。
|
||||
qInfo() << "The socket is about to close (data may still be waiting to be written).";
|
||||
break;
|
||||
case QAbstractSocket::ListeningState:
|
||||
// 套接字仅限内部使用。
|
||||
qInfo() << "For internal use only.";
|
||||
break;
|
||||
case QAbstractSocket::UnconnectedState:
|
||||
// 套接字未连接。
|
||||
qInfo() << "The socket is not connected.";
|
||||
break;
|
||||
case QAbstractSocket::HostLookupState:
|
||||
// 套接字正在查询主机。
|
||||
qInfo() << "The socket is performing a host name lookup.";
|
||||
break;
|
||||
case QAbstractSocket::ConnectingState:
|
||||
// 套接字开始建立连接。
|
||||
qInfo() << "The socket has started establishing a connection.";
|
||||
break;
|
||||
case QAbstractSocket::ConnectedState:
|
||||
// 新的连接已建立。
|
||||
qInfo() << "A connection is established.";
|
||||
break;
|
||||
case QAbstractSocket::BoundState:
|
||||
// 套接字已绑定到一个地址和端口。
|
||||
qInfo() << "The socket is bound to an address and port.";
|
||||
break;
|
||||
case QAbstractSocket::ClosingState:
|
||||
// 套接字即将关闭(数据可能仍在等待写入)。
|
||||
qInfo() << "The socket is about to close (data may still be waiting to be written).";
|
||||
break;
|
||||
case QAbstractSocket::ListeningState:
|
||||
// 套接字仅限内部使用。
|
||||
qInfo() << "For internal use only.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -383,20 +405,20 @@ void PcScreenManage::slotSocketDisconnect()
|
|||
void PcScreenManage::slotStateChange(Curtain::States state)
|
||||
{
|
||||
switch (state) {
|
||||
case Curtain::States::Control: {
|
||||
// 进入反控
|
||||
startedControl();
|
||||
} break;
|
||||
case Curtain::States::ReturnDesktop: {
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::HideView);
|
||||
} break;
|
||||
case Curtain::States::ScreenShare: {
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::ShowView);
|
||||
} break;
|
||||
case Curtain::States::Exit: {
|
||||
disconnected();
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::Exit);
|
||||
} break;
|
||||
case Curtain::States::Control: {
|
||||
// 进入反控
|
||||
startedControl();
|
||||
} break;
|
||||
case Curtain::States::ReturnDesktop: {
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::HideView);
|
||||
} break;
|
||||
case Curtain::States::ScreenShare: {
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::ShowView);
|
||||
} break;
|
||||
case Curtain::States::Exit: {
|
||||
disconnected();
|
||||
Q_EMIT sigRequestReceived(ScreenMsg::Exit);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include <QTcpSocket>
|
||||
#include <QAbstractSocket>
|
||||
#include <QThread>
|
||||
//#include <QDBusMessage>
|
||||
//#include <QDBusInterface>
|
||||
// #include <QDBusMessage>
|
||||
// #include <QDBusInterface>
|
||||
#include "screenmanagemsg.pb.h"
|
||||
#include "pcscreen.h"
|
||||
#include "curtain.h"
|
||||
|
@ -23,23 +23,24 @@ public:
|
|||
~PcScreenManage();
|
||||
|
||||
enum ScreenMsg {
|
||||
SharingRequest = 0, // 投屏请求
|
||||
RemoteRejection = 1, // 远程主机拒绝
|
||||
StartedScreen = 2, // 投屏服务已启动
|
||||
ScreenExit = 3, // 投屏服务退出
|
||||
ScreenError = 4, // 投屏错误
|
||||
Disconnect = 5, // 投屏断开
|
||||
Successfully = 6, // 投屏请求成功
|
||||
StartedControl = 7, // 启动反控
|
||||
ExitControl = 8, // 退出反控
|
||||
HideView = 9, // 隐藏投屏
|
||||
ShowView = 10, // 显示投屏
|
||||
Exit = 11, // 主动退出
|
||||
SharingRequest = 0, // 投屏请求
|
||||
RemoteRejection = 1, // 远程主机拒绝
|
||||
StartedScreen = 2, // 投屏服务已启动
|
||||
ScreenExit = 3, // 投屏服务退出
|
||||
ScreenError = 4, // 投屏错误
|
||||
Disconnect = 5, // 投屏断开
|
||||
Successfully = 6, // 投屏请求成功
|
||||
StartedControl = 7, // 启动反控
|
||||
ExitControl = 8, // 退出反控
|
||||
HideView = 9, // 隐藏投屏
|
||||
ShowView = 10, // 显示投屏
|
||||
Exit = 11, // 主动退出
|
||||
PassiveControl = 12, // 通过快捷键进入反控
|
||||
};
|
||||
Q_ENUM(ScreenMsg)
|
||||
enum DeviceType {
|
||||
PC = 0, // PC
|
||||
Android = 1, // Android
|
||||
PC = 0, // PC
|
||||
Android = 1, // Android
|
||||
};
|
||||
Q_ENUM(DeviceType)
|
||||
|
||||
|
@ -88,21 +89,23 @@ private Q_SLOTS:
|
|||
// void slotEnterControl(bool isControl);
|
||||
|
||||
private:
|
||||
QTcpServer *m_tcpServer = nullptr; // Tcp服务
|
||||
QTcpSocket *m_messageTcpSocket = nullptr; // 消息通道
|
||||
PCScreen *m_pcScreen = nullptr; // PC投屏服务
|
||||
QThread *m_pcScreenThread = nullptr; //投屏服务线程
|
||||
Curtain *m_curtain = nullptr; // 投屏幕布
|
||||
Control *m_control = nullptr; // 反控
|
||||
QTcpServer *m_tcpServer = nullptr; // Tcp服务
|
||||
QTcpSocket *m_messageTcpSocket = nullptr; // 消息通道
|
||||
PCScreen *m_pcScreen = nullptr; // PC投屏服务
|
||||
QThread *m_pcScreenThread = nullptr; // 投屏服务线程
|
||||
Curtain *m_curtain = nullptr; // 投屏幕布
|
||||
Control *m_control = nullptr; // 反控
|
||||
PcScreenManage::DeviceType m_deviceType = PcScreenManage::DeviceType::PC;
|
||||
// QDBusInterface *m_dbusInterface = nullptr; // 反控dbus
|
||||
|
||||
QString m_address = ""; // 客服端ip
|
||||
qint64 m_dataSize = 0; // 接收的数据大小
|
||||
QByteArray m_data; // 需要发送的数据
|
||||
bool m_isHead = true; // 是否为消息头
|
||||
bool m_isService = true; // 是否为服务端
|
||||
PublicAttributes::Theme m_theme = PublicAttributes::Theme::Light; // 主题
|
||||
QString m_address = ""; // 客服端ip
|
||||
qint64 m_dataSize = 0; // 接收的数据大小
|
||||
QByteArray m_data; // 需要发送的数据
|
||||
bool m_isHead = true; // 是否为消息头
|
||||
bool m_isService = true; // 是否为服务端
|
||||
PublicAttributes::Theme m_theme = PublicAttributes::Theme::Light; // 主题
|
||||
bool m_isAtiveStarted = false;
|
||||
bool m_isAtiveEnd = false;
|
||||
};
|
||||
|
||||
#endif // PCSCREENMANAGE_H
|
||||
#endif // PCSCREENMANAGE_H
|
|
@ -1446,6 +1446,11 @@ void MainWindow::slotRequestReceived(PcScreenManage::ScreenMsg msg)
|
|||
} break;
|
||||
case PcScreenManage::ScreenMsg::ScreenExit: {
|
||||
// 投屏退出
|
||||
if (m_suspendTabBar != nullptr) {
|
||||
m_suspendTabBar->hideTabBar();
|
||||
delete m_suspendTabBar;
|
||||
m_suspendTabBar = nullptr;
|
||||
}
|
||||
show();
|
||||
if (m_connectInfo.deviceRole == ConnectionService::DeviceRole::RECIPIENT && m_connectedWin != nullptr) {
|
||||
m_connectedWin->restoreScreenButton();
|
||||
|
@ -1511,6 +1516,14 @@ void MainWindow::slotRequestReceived(PcScreenManage::ScreenMsg msg)
|
|||
case PcScreenManage::ScreenMsg::Exit: {
|
||||
show();
|
||||
} break;
|
||||
case PcScreenManage::ScreenMsg::PassiveControl: {
|
||||
if (m_suspendTabBar != nullptr) {
|
||||
m_suspendTabBar->hideTabBar();
|
||||
delete m_suspendTabBar;
|
||||
m_suspendTabBar = nullptr;
|
||||
}
|
||||
hide();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2037,6 +2050,7 @@ void MainWindow::slotTabBtnClicked(SuspendTabBar::BtnType type)
|
|||
delete m_suspendTabBar;
|
||||
m_suspendTabBar = nullptr;
|
||||
}
|
||||
hide();
|
||||
m_pcScreen->startedControl();
|
||||
} break;
|
||||
case SuspendTabBar::BtnType::CloseControlBtn: {
|
||||
|
|
Loading…
Reference in New Issue