Rabbit Remote Control 0.0.33
Loading...
Searching...
No Matches
PluginClient.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include <QLocale>
4#include <QDebug>
5#include <QApplication>
6#include <QDir>
7#include <QLoggingCategory>
8
9#include "PluginClient.h"
10#include "RabbitCommonTools.h"
11
12static Q_LOGGING_CATEGORY(log, "Client.Plugin")
13
14CPluginClient::CPluginClient(QObject *parent) : QObject(parent)
15{}
16
18{
19 qDebug(log) << "CPluginClient::~CPluginClient()";
20 if(m_Translator)
21 RabbitCommon::CTools::Instance()->RemoveTranslator(m_Translator);
22}
23
24// 因为 Name() 是重载函数,需要子类化才有,所以此函数不能在构造函数中调用
26{
27 m_Translator = RabbitCommon::CTools::Instance()->InstallTranslator(
28 Name(),
29 RabbitCommon::CTools::TranslationType::Plugin,
30 "plugins/Client");
31 if(m_Translator)
32 return 0;
33
34 return -1;
35}
36
37const QString CPluginClient::Id() const
38{
39 return Protocol() + ":" + Name();
40}
41
42const QString CPluginClient::DisplayName() const
43{
44 return Name();
45}
46
47const QIcon CPluginClient::Icon() const
48{
49 return QIcon::fromTheme("network-wired");
50}
51
52const QString CPluginClient::Details() const
53{
54 return QString();
55}
56
58 const QString &szId, CParameterClient* para)
59{
60 CConnecter* p = OnCreateConnecter(szId);
61 if(p) {
62 int nRet = 0;
63 //nRet = p->Initial();
64 bool bRet = QMetaObject::invokeMethod(
65 p,
66 "Initial",
67 Qt::DirectConnection,
68 Q_RETURN_ARG(int, nRet));
69 if(!bRet) {
70 qCritical(log) << "Call p->Initial() fail.";
71 return nullptr;
72 }
73 if(nRet) {
74 qCritical(log) << "Connecter initial fail" << nRet;
76 return nullptr;
77 }
78 //nRet = p->SetParameterClient(para);
79 bRet = QMetaObject::invokeMethod(
80 p,
81 "SetParameterClient",
82 Qt::DirectConnection,
83 Q_RETURN_ARG(int, nRet),
84 Q_ARG(CParameterClient*, para));
85 if(!bRet) {
86 qCritical(log) << "Call p->SetParameterClient(para) fail.";
87 return nullptr;
88 }
89 if(nRet) {
90 qCritical(log) << "SetParameterClient fail" << nRet;
92 return nullptr;
93 }
94 }
95 return p;
96}
97
99{
100 qDebug(log) << Q_FUNC_INFO;
101 if(!p) return 0;
102 int nRet = 0;
103 bool bRet = false;
104 //nRet = p->Clean();
105 bRet = QMetaObject::invokeMethod(
106 p,
107 "Clean",
108 Qt::DirectConnection,
109 Q_RETURN_ARG(int, nRet));
110 if(!bRet) {
111 qCritical(log) << "Call p->Clean() fail.";
112 return -1;
113 }
114 if(nRet)
115 qWarning(log) << "Connecter clean fail" << nRet;
116 p->deleteLater();
117 return 0;
118}
Connecter interface.
Definition Connecter.h:62
The parameters of client.
The plugin interface.
virtual const QString Details() const
Display more information in About dialog or log.
virtual const QString Id() const
ID. Default: Protocol() + ":" + Name()
virtual const QString DisplayName() const
The plugin display name.
virtual const QString Name() const =0
This name must be the same as the project name (${PROJECT_NAME}). The translation file (${PROJECT_NAM...
virtual Q_INVOKABLE CConnecter * CreateConnecter(const QString &szId, CParameterClient *para)
New CConnecter instance.
Q_INVOKABLE int InitTranslator()
Initialize the translation resource, which is only called by CClient.
virtual const QString Protocol() const =0
Plugin Protocol.
virtual ~CPluginClient()
When the derived class is implemented, the resources are clean are unloaded here.
virtual Q_INVOKABLE int DeleteConnecter(CConnecter *p)
Delete CConnecter.