Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ConnecterConnect.cpp
1#include <QLoggingCategory>
2#include <QRegularExpression>
3#include "ConnecterConnect.h"
4#include "PluginClientThread.h"
5
6static Q_LOGGING_CATEGORY(log, "Client.Connecter.Connect")
8 : CConnecter(plugin)
9 , m_pConnect(nullptr)
10{
11 qDebug(log) << Q_FUNC_INFO;
12}
13
14CConnecterConnect::~CConnecterConnect()
15{
16 qDebug(log) << Q_FUNC_INFO;
17}
18
19const QString CConnecterConnect::Id()
20{
21 QString szId = Protocol() + "_" + GetPlugClient()->Name();
22 if(GetParameter())
23 {
24 if(!GetParameter()->GetName().isEmpty())
25 szId += "_" + GetParameter()->GetName();
26 if(!GetParameter()->m_Net.GetHost().isEmpty())
27 szId += "_" + GetParameter()->m_Net.GetHost()
28 + "_" + QString::number(GetParameter()->m_Net.GetPort());
29 }
30 static QRegularExpression exp("[-@:/#%!^&* \\.]");
31 szId = szId.replace(exp, "_");
32 return szId;
33}
34
52{
53 QString szName;
54 if(GetParameter() && GetParameter()->GetParameterClient()
55 && GetParameter()->GetParameterClient()->GetShowProtocolPrefix())
56 szName = Protocol() + ":";
57
58 if(GetParameter() && !(GetParameter()->GetName().isEmpty()))
59 szName += GetParameter()->GetName();
60 else
61 szName += ServerName();
62 return szName;
63}
64
66{
67 return tr("Name: ") + Name() + "\n"
68 + tr("Protocol: ") + Protocol()
69#ifdef DEBUG
70 + " - " + GetPlugClient()->DisplayName()
71#endif
72 + "\n"
73 + tr("Server name: ") + ServerName() + "\n"
74 + tr("Description: ") + GetPlugClient()->Description();
75}
76
78{
79 return qobject_cast<CParameterBase*>(CConnecter::GetParameter());
80}
81
82int CConnecterConnect::SetParameter(CParameterBase *p)
83{
84 int nRet = CConnecter::SetParameter(p);
85 if(nRet) return nRet;
86 if(GetParameter())
87 {
88 bool check = false;
89 check = connect(GetParameter(), SIGNAL(sigNameChanged()),
90 this, SLOT(slotUpdateName()));
91 Q_ASSERT(check);
92 check = connect(GetParameter(), SIGNAL(sigShowServerNameChanged()),
93 this, SLOT(slotShowServerName()));
94 Q_ASSERT(check);
95 check = connect(GetParameter(), &CParameter::sigChanged,
96 this, [&](){
97 emit this->sigUpdateParameters(this);
98 });
99 Q_ASSERT(check);
100 CFrmViewer* pViewer = qobject_cast<CFrmViewer*>(GetViewer());
101 if(pViewer) {
102 check = connect(GetParameter(), SIGNAL(sigZoomFactorChanged(double)),
103 pViewer, SLOT(slotSetZoomFactor(double)));
104 Q_ASSERT(check);
105 check = connect(
106 GetParameter(),
107 SIGNAL(sigAdaptWindowsChanged(CFrmViewer::ADAPT_WINDOWS)),
108 pViewer, SLOT(slotSetAdaptWindows(CFrmViewer::ADAPT_WINDOWS)));
109 Q_ASSERT(check);
110 }
111 }
112 return 0;
113}
114
116{
117 if(GetParameter())
118 {
119 GetParameter()->SetParameterClient(pPara);
120 if(pPara)
121 {
122 bool check = connect(pPara, SIGNAL(sigShowProtocolPrefixChanged()),
123 this, SLOT(slotUpdateName()));
124 Q_ASSERT(check);
125 check = connect(pPara, SIGNAL(sigSHowIpPortInNameChanged()),
126 this, SLOT(slotUpdateName()));
127 Q_ASSERT(check);
128 }
129 return 0;
130 } else {
131 QString szMsg = "The CConnecter is not parameters! "
132 "please first create parameters, "
133 "then call SetParameter in the ";
134 szMsg += metaObject()->className() + QString("::")
135 + metaObject()->className();
136 szMsg += QString(" or ") + metaObject()->className()
137 + QString("::") + "Initial()";
138 szMsg += " to set the parameters pointer. "
139 "Default set CParameterClient for the parameters of connecter "
140 "(CParameterConnecter or its derived classes) "
141 "See: CClient::CreateConnecter. "
142 "If you are sure the parameter of connecter "
143 "does not need CParameterClient. "
144 "Please overload the SetParameterClient in the ";
145 szMsg += QString(metaObject()->className()) + " . don't set it";
146 qCritical(log) << szMsg.toStdString().c_str();
147 Q_ASSERT(false);
148 }
149 return -1;
150}
151
153{
154 qDebug(log) << Q_FUNC_INFO;
156 = qobject_cast<CPluginClientThread*>(GetPlugClient());
157 if(pPlug)
158 emit sigOpenConnect(this);
159 else {
160 m_pConnect = InstanceConnect();
161 if(m_pConnect) {
162 int nRet = m_pConnect->Connect();
163 emit sigConnected();
164 return nRet;
165 }
166 }
167 return 0;
168}
169
171{
172 qDebug(log) << Q_FUNC_INFO;
174 = qobject_cast<CPluginClientThread*>(GetPlugClient());
175 if(pPlug)
176 emit sigCloseconnect(this);
177 else {
178 if(m_pConnect) {
179 int nRet = m_pConnect->Disconnect();
180 m_pConnect->deleteLater();
181 emit sigDisconnected();
182 return nRet;
183 }
184 }
185 return 0;
186}
187
189{
190 if(GetParameter() && GetParameter()->GetParameterClient()
191 && GetParameter()->GetParameterClient()->GetShowIpPortInName())
192 {
193 return GetParameter()->m_Net.GetHost()
194 + ":" + QString::number(GetParameter()->m_Net.GetPort());
195 }
196
197 if(m_szServerName.isEmpty() && GetParameter())
198 return GetParameter()->GetServerName();
199 return m_szServerName;
200}
201
202void CConnecterConnect::slotSetServerName(const QString& szName)
203{
204 if(m_szServerName == szName)
205 return;
206
207 m_szServerName = szName;
208 if(GetParameter())
209 {
210 if(GetParameter()->GetServerName() == szName)
211 return;
212 GetParameter()->SetServerName(szName);
213 }
214
215 emit sigUpdateName(Name());
216}
virtual int Disconnect()
Disconnect.
Definition Connect.cpp:89
virtual int Connect()
Start connect.
Definition Connect.cpp:77
The connector interface of the plug-in, which is only used by the plug-in.
virtual const QString Id() override
Identity.
virtual int DisConnect() override
emit sigDisconnected() in here
virtual const QString Description() override
Description.
virtual int Connect() override
virtual void slotSetServerName(const QString &szName)
virtual CParameterBase * GetParameter()
Get parameter.
virtual const QString Name() override
Display order:
virtual int SetParameterClient(CParameterClient *pPara) override
Set CParameterClient.
virtual CConnect * InstanceConnect()=0
New connect.
virtual QString ServerName()
Current connect server name (remote desktop name, if not present, then IP:PORT).
Connecter interface.
Definition Connecter.h:62
void sigUpdateName(const QString &szName)
void sigConnected()
Successful connection signal.
virtual QWidget * GetViewer()=0
Get Viewer.
void sigDisconnected()
Successful disconnection signal.
virtual int SetParameter(CParameter *p)
Set parameters.
virtual const QString Protocol() const
Protocol.
Definition Connecter.cpp:69
void sigUpdateParameters(CConnecter *pConnecter)
Update parameters, notify application to save or show parameters.
A widget which displays output image from a CConnectDesktop and sends input keypresses and mouse acti...
Definition FrmViewer.h:49
ADAPT_WINDOWS
The ADAPT_WINDOWS enum.
Definition FrmViewer.h:61
The interface of connecter parameters.
The parameters of client.
void sigChanged()
emit when the parameter changes Usually if required, the corresponding parameter corresponds to a cha...
It starts a background thread by default.
The plugin interface.
virtual const QString DisplayName() const
The plugin display name.
virtual const QString Description() const =0
Plugin description.
virtual const QString Name() const =0
This name must be the same as the project name (${PROJECT_NAME}). The translation file (${PROJECT_NAM...