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);
The connector interface of the plug-in, which is only used by the plug-in.
virtual CParameterBase * GetParameter()
Get parameter.
virtual CConnect * InstanceConnect() override
New connect.
virtual QDialog * OnOpenDialogSettings(QWidget *parent) override
Open settgins dialog.
virtual int Clean() override
Clean parameters and resource.
virtual const QString Name() override
Display order:
virtual int Save(QSettings &set) override
Save parameters.
virtual int Load(QSettings &set) override
Load parameters.
virtual QWidget * GetViewer() override
Get Viewer.
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()
Successful connection signal.
void sigDisconnected()
Successful disconnection signal.
virtual const QString Protocol() const
Protocol.
The parameters of client.
The wake on lan parameters UI.
int SetParameter(CParameter *pParameter)
Set the parameters and initialize the user interface.
The wake on lan parameters.
virtual const QString Name() const =0
This name must be the same as the project name (${PROJECT_NAME}). The translation file (${PROJECT_NAM...