3#include <QLoggingCategory>
6#include <QRegularExpression>
10#include <QCoreApplication>
11#include "RabbitCommonTools.h"
12#include "PluginClient.h"
14#include "ParameterWakeOnLanUI.h"
15#include "ConnecterWakeOnLan.h"
17static Q_LOGGING_CATEGORY(log,
"WakeOnLan.Connecter")
22 , m_pParameterClient(
nullptr)
24 qDebug(log) << Q_FUNC_INFO;
27CConnecterWakeOnLan::~CConnecterWakeOnLan()
29 qDebug(log) << Q_FUNC_INFO;
41 qDebug(log) << Q_FUNC_INFO;
48 if(!m_pView)
return -2;
49 m_pView->setWindowTitle(plugin->
Name());
50 check = connect(m_pView, &CFrmWakeOnLan::customContextMenuRequested,
51 this, [&](
const QPoint &pos){
52 m_Menu.exec(m_pView->mapToGlobal(pos));
56 m_Menu.addAction(QIcon::fromTheme(
"list-add"), tr(
"Add"),
57 this, SLOT(slotAdd()));
58 m_Menu.addAction(QIcon::fromTheme(
"document-edit"), tr(
"Edit"),
60 QSharedPointer<CParameterWakeOnLan> para
61 = m_pModel->GetData(m_pView->GetCurrentIndex());
63 QMessageBox::information(
66 tr(
"Please select a item"));
73 m_Menu.addAction(QIcon::fromTheme(
"list-remove"), tr(
"Remove"),
74 m_pView, SLOT(slotRemoveRow()));
76 QString szFlatpak_ID = qgetenv(
"FLATPAK_ID");
77 if(RabbitCommon::CTools::HasAdministratorPrivilege()
78 ||
"io.github.KangLin.RabbitRemoteControl" == szFlatpak_ID)
80 m_Menu.addAction(QIcon::fromTheme(
"view-refresh"), tr(
"Refresh"),
82 foreach(
auto p, m_pModel->m_Data)
86 QIcon::fromTheme(
"mac"), tr(
"Get mac address"),
88 if(!m_pModel || !m_pView)
90 foreach(
auto index, m_pView->GetSelect()) {
91 QSharedPointer<CParameterWakeOnLan> p
92 = m_pModel->GetData(index);
95 p->SetHostState(CParameterWakeOnLan::HostState::GetMac);
100 m_Menu.addAction(QIcon::fromTheme(
"view-refresh"), tr(
"Refresh"),
102 foreach(
auto p, m_pModel->m_Data)
106 QIcon::fromTheme(
"mac"), tr(
"Get mac address"),
108 if(!m_pModel || !m_pView)
110 foreach(
auto index, m_pView->GetSelect()) {
111 QSharedPointer<CParameterWakeOnLan> p = m_pModel->GetData(index);
114 p->SetHostState(CParameterWakeOnLan::HostState::GetMac);
119 QIcon::fromTheme(
"lan"), tr(
"Wake on lan"),
121 if(!m_pModel || !m_pView)
123 foreach(
auto index, m_pView->GetSelect()) {
124 QSharedPointer<CParameterWakeOnLan> p = m_pModel->GetData(index);
126 if(!m_Arp.WakeOnLan(p))
127 p->SetHostState(CParameterWakeOnLan::HostState::WakeOnLan);
136 qDebug(log) << Q_FUNC_INFO;
156 QString szId =
Protocol() +
"_" + GetPlugClient()->
Name();
164 &&
GetParameter()->GetParameterClient()->GetShowProtocolPrefix())
166 szName += GetPlugClient()->
Name();
170int CConnecterWakeOnLan::Connect()
172#if defined(Q_OS_UNIX)
173 if(!RabbitCommon::CTools::HasAdministratorPrivilege())
175 static bool bShow =
false;
180 QMessageBox::Warning, tr(
"Warning"),
181 tr(
"There are no administrator privileges, "
182 "and some functions(Get mac address) are restricted. "
183 "Please restart the program with administrative privileges."),
184 QMessageBox::Yes | QMessageBox::No);
185 msg.setCheckBox(
new QCheckBox(tr(
"Exit the program"), &msg));
186 msg.checkBox()->setCheckable(
true);
188 if(QMessageBox::Yes == nRet) {
189 QString szExec = QCoreApplication::applicationFilePath();
190 QString szAppImage = QString::fromLocal8Bit(qgetenv(
"APPIMAGE"));
191 if(!szAppImage.isEmpty())
193 if(!szExec.isEmpty()) {
194 bool bRet = RabbitCommon::CTools::ExecuteWithAdministratorPrivilege(szExec);
195 qDebug(log) <<
"Execute:" << bRet << QCoreApplication::applicationFilePath();
196 if(bRet && msg.checkBox()->isChecked()) {
197 QCoreApplication::quit();
208int CConnecterWakeOnLan::DisConnect()
221 m_pParameterClient = pPara;
227 if(!m_pModel)
return -1;
228 return m_pModel->Load(set, m_pParameterClient);
233 if(!m_pModel)
return -1;
234 return m_pModel->Save(set);
237void CConnecterWakeOnLan::slotAdd()
240 para->SetParameterClient(m_pParameterClient);
243 int nRet = RC_SHOW_WINDOW(&dlg);
244 if(QDialog::Accepted == nRet)
245 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.
virtual Q_INVOKABLE int Initial()
Initial parameters and resource.
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...