3#include <QLoggingCategory>
6#include <QRegularExpression>
9#include <QCoreApplication>
10#include "RabbitCommonTools.h"
11#include "PluginClient.h"
13#include "ParameterWakeOnLanUI.h"
14#include "ConnecterWakeOnLan.h"
16static Q_LOGGING_CATEGORY(log,
"WakeOnLan.Connecter")
21 , m_pParameterClient(
nullptr)
23 qDebug(log) << Q_FUNC_INFO;
26CConnecterWakeOnLan::~CConnecterWakeOnLan()
28 qDebug(log) << Q_FUNC_INFO;
38 qDebug(log) << Q_FUNC_INFO;
45 if(!m_pView)
return -2;
46 m_pView->setWindowTitle(plugin->
Name());
47 check = connect(m_pView, &CFrmWakeOnLan::customContextMenuRequested,
48 this, [&](
const QPoint &pos){
49 m_Menu.exec(m_pView->mapToGlobal(pos));
53 m_Menu.addAction(QIcon::fromTheme(
"list-add"), tr(
"Add"),
54 this, SLOT(slotAdd()));
55 m_Menu.addAction(QIcon::fromTheme(
"document-edit"), tr(
"Edit"),
57 QSharedPointer<CParameterWakeOnLan> para
58 = m_pModel->GetData(m_pView->GetCurrentIndex());
60 QMessageBox::information(
63 tr(
"Please select a item"));
70 m_Menu.addAction(QIcon::fromTheme(
"list-remove"), tr(
"Remove"),
71 m_pView, SLOT(slotRemoveRow()));
73 if(RabbitCommon::CTools::HasAdministratorPrivilege())
75 m_Menu.addAction(QIcon::fromTheme(
"view-refresh"), tr(
"Refresh"),
77 foreach(
auto p, m_pModel->m_Data)
81 QIcon::fromTheme(
"mac"), tr(
"Get mac address"),
83 if(!m_pModel || !m_pView)
85 foreach(
auto index, m_pView->GetSelect()) {
86 QSharedPointer<CParameterWakeOnLan> p
87 = m_pModel->GetData(index);
90 p->SetHostState(CParameterWakeOnLan::HostState::GetMac);
95 m_Menu.addAction(QIcon::fromTheme(
"view-refresh"), tr(
"Refresh"),
97 foreach(
auto p, m_pModel->m_Data)
101 QIcon::fromTheme(
"mac"), tr(
"Get mac address"),
103 if(!m_pModel || !m_pView)
105 foreach(
auto index, m_pView->GetSelect()) {
106 QSharedPointer<CParameterWakeOnLan> p = m_pModel->GetData(index);
109 p->SetHostState(CParameterWakeOnLan::HostState::GetMac);
114 QIcon::fromTheme(
"lan"), tr(
"Wake on lan"),
116 if(!m_pModel || !m_pView)
118 foreach(
auto index, m_pView->GetSelect()) {
119 QSharedPointer<CParameterWakeOnLan> p = m_pModel->GetData(index);
121 if(!m_Arp.WakeOnLan(p))
122 p->SetHostState(CParameterWakeOnLan::HostState::WakeOnLan);
131 qDebug(log) << Q_FUNC_INFO;
151 QString szId =
Protocol() +
"_" + GetPlugClient()->
Name();
159 &&
GetParameter()->GetParameterClient()->GetShowProtocolPrefix())
161 szName += GetPlugClient()->
Name();
165int CConnecterWakeOnLan::Connect()
167#if defined(Q_OS_UNIX)
168 if(!RabbitCommon::CTools::HasAdministratorPrivilege())
170 static bool bShow =
false;
173 int nRet = QMessageBox::warning(
174 nullptr, tr(
"Warning"),
175 tr(
"There are no administrator privileges, "
176 "and some functions(Get mac address) are restricted. "
177 "Please restart the program with administrative privileges."),
178 QMessageBox::Yes | QMessageBox::No);
179 if(QMessageBox::Yes == nRet) {
180 bool bRet = RabbitCommon::CTools::executeByRoot(
181 QCoreApplication::applicationFilePath());
183 QCoreApplication::quit();
192int CConnecterWakeOnLan::DisConnect()
205 m_pParameterClient = pPara;
211 if(!m_pModel)
return -1;
212 return m_pModel->Load(set, m_pParameterClient);
217 if(!m_pModel)
return -1;
218 return m_pModel->Save(set);
221void CConnecterWakeOnLan::slotAdd()
224 para->SetParameterClient(m_pParameterClient);
227 int nRet = RC_SHOW_WINDOW(&dlg);
228 if(QDialog::Accepted == nRet)
229 m_pModel->AddItem(para);
连接接口。它由协议插件实现。 它默认启动一个定时器来开启一个非 Qt 事件循环(就是普通的循环处理)。 详见: Connect()、 slotTimeOut()、 OnProcess() 。 当然,它仍...
插件的连接者接口,此接口仅由插件使用。 所有的需要 CConnect 的插件连接者均需要从此接口派生。
virtual CParameterBase * GetParameter()
Get parameter
virtual CConnect * InstanceConnect() override
新建 CConnect 对象。它的所有者是调用者, 如果调用者不再使用它,调用者必须负责释放它。
virtual QDialog * OnOpenDialogSettings(QWidget *parent) override
得到设置对话框
virtual int Clean() override
Clean parameters and resource
virtual const QString Name() override
显示顺序:
virtual int Save(QSettings &set) override
保存参数
virtual int Load(QSettings &set) override
加载参数
virtual QWidget * GetViewer() override
得到显示视图
virtual int Initial() override
Initial parameters and resource
virtual const QString Id() override
Identity
virtual int SetParameterClient(CParameterClient *pPara) override
Set CParameterClient
virtual qint16 Version() override
Version
void sigConnected()
连接成功信号。仅由插件触发。 应用程序需要在此时设置视图属性 Enabled 为 true 。允许接收键盘和鼠标事件
void sigDisconnected()
断开连接成功信号。仅由插件触发
virtual const QString Protocol() const
Protocol
客户端库 (CClient) 参数。仅在客户端库 (CClient) 和插件中使用。
The wake on lan parameters UI
int SetParameter(CParameter *pParameter)
设置参数,并初始化界面
The wake on lan parameters.
客户端插件接口。用于建立 CConnecter 实例,它由协议插件实现。
virtual const QString Name() const =0
插件名,这个名一定要与工程名(${PROJECT_NAME})相同。 翻译文件(${PROJECT_NAME}_*.ts))名与其相关。