6#include <QGenericArgument>
8#include <QLoggingCategory>
13#include "PluginClient.h"
14#include "RabbitCommonTools.h"
16static Q_LOGGING_CATEGORY(log,
"Client.Connecter")
19 m_pPluginClient(plugin),
24 if(QApplication::clipboard())
26 check = connect(QApplication::clipboard(), SIGNAL(dataChanged()),
27 this, SIGNAL(sigClipBoardChanged()));
31 m_Menu.setIcon(plugin->Icon());
32 m_Menu.setTitle(plugin->DisplayName());
33 m_Menu.setToolTip(plugin->DisplayName());
34 m_Menu.setStatusTip(plugin->DisplayName());
36 m_pSettings =
new QAction(QIcon::fromTheme(
"system-settings"),
37 tr(
"Settings"), &m_Menu);
38 check = connect(m_pSettings, SIGNAL(triggered()),
this, SLOT(slotSettings()));
42CConnecter::~CConnecter()
44 qDebug(log) <<
"CConnecter::~CConnecter";
49 QString szId =
Protocol() +
"_" + GetPlugClient()->
Name();
55 return GetPlugClient()->
Name();
60 return tr(
"Name: ") +
Name() +
"\n"
66 + tr(
"Description: ") + GetPlugClient()->
Description();
76 return GetPlugClient()->Icon();
81 QClipboard* pClipboard = QApplication::clipboard();
85 pClipboard->setMimeData(data);
95 int nRet = QDialog::Accepted;
103 p->setWindowIcon(this->
Icon());
104 p->setWindowTitle(tr(
"Set ") + GetPlugClient()->DisplayName());
105 p->setAttribute(Qt::WA_DeleteOnClose);
106 nRet = RC_SHOW_WINDOW(p);
108 qCritical(log) <<
"The Protocol [" <<
Protocol() <<
"] don't settings dialog";
115 if(m_Menu.actions().isEmpty())
122 Q_ASSERT(!szFile.isEmpty());
125 qCritical(log) <<
"The load file is empty";
128 QSettings set(szFile, QSettings::IniFormat);
134 Q_ASSERT(!szFile.isEmpty());
137 qCritical(log) <<
"The load file is empty";
140 QSettings set(szFile, QSettings::IniFormat);
147 Q_ASSERT(m_pParameter);
149 nRet = m_pParameter->
Load(set);
156 Q_ASSERT(m_pParameter);
158 m_pParameter->
Save(set);
167 QString szMsg =
"The CConnecter is not parameters! "
168 "please first create parameters, "
169 "then call SetParameter in the ";
170 szMsg += metaObject()->className() + QString(
"::")
171 + metaObject()->className();
172 szMsg += QString(
" or ") + metaObject()->className()
173 + QString(
"::") +
"Initial()";
174 szMsg +=
" to set the parameters pointer. "
175 "Default set CParameterClient for the parameters of connecter "
176 "(CParameterConnecter or its derived classes) "
177 "See: CClient::CreateConnecter. "
178 "If you are sure the parameter of connecter "
179 "does not need CParameterClient. "
180 "Please overload the SetParameterClient in the ";
181 szMsg += QString(metaObject()->className()) +
" . don't set it";
182 qCritical(log) << szMsg.toStdString().c_str();
191 m_pParameter->disconnect(
this);
205 return m_pPluginClient;
208void CConnecter::slotShowServerName()
213void CConnecter::slotUpdateName()
218QObject* CConnecter::createObject(
const QString& className, QObject* parent)
222#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
223 QMetaType::fromName(className.toStdString().c_str()).id();
225 QMetaType::type(className.toStdString().c_str());
227 if(QMetaType::UnknownType == type)
229 qCritical(log) << className <<
" is QMetaType::UnknownType";
233#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
234 (QObject*)QMetaType(type).create();
236 (QObject*)QMetaType::create(type);
240 qCritical(log) <<
"QMetaType::create fail: " << type;
251 QObject *obj = createObject(className);
252 Q_ASSERT_X(obj,
"Connecter", QString(
"Create object failed: " + className).toStdString().c_str());
260 if(-1 == obj->metaObject()->indexOfMethod(
"SetContext(void*)"))
263 szErr =
"The class " + className +
" is not method SetContext. It must be SetContext(void*) method.";
264 qCritical(log) << szErr;
265 Q_ASSERT_X(
false,
"Connecter", szErr.toStdString().c_str());
267 obj->metaObject()->invokeMethod(obj,
"SetContext", Q_ARG(
void*, pContext));
268 if(-1 < obj->metaObject()->indexOfMethod(
"SetConnecter(CConnecter*)"))
270 obj->metaObject()->invokeMethod(obj,
"SetConnecter", Q_ARG(
CConnecter*,
this));
273 if(obj->inherits(
"QDialog"))
275 QDialog* pDlg = qobject_cast<QDialog*>(obj);
276 pDlg->setAttribute(Qt::WA_DeleteOnClose);
278 pDlg, SLOT(reject()));
280 nRet = RC_SHOW_WINDOW(pDlg);
281 }
else if(obj->inherits(
"QWidget")) {
282 QWidget* pWdg = qobject_cast<QWidget*>(obj);
283 pWdg->setAttribute(Qt::WA_DeleteOnClose);
285 pWdg, SLOT(close()));
287 nRet = RC_SHOW_WINDOW(pWdg);
292 QMessageBox::StandardButtons buttons,
293 QMessageBox::StandardButton &nRet,
295 QString szCheckBoxContext)
297 QCheckBox* pBox =
nullptr;
298 QMessageBox msg(QMessageBox::Information,
299 szTitle, szMessage, buttons,
GetViewer());
300 if(!szCheckBoxContext.isEmpty())
302 pBox =
new QCheckBox(szCheckBoxContext);
304 pBox->setCheckable(
true);
305 msg.setCheckBox(pBox);
307 nRet = (QMessageBox::StandardButton)RC_SHOW_WINDOW(&msg);
309 checkBox = pBox->isChecked();
313 const QString &szMessage,
317 QString t = QInputDialog::getText(
nullptr,
323 if(ok && !t.isEmpty())
327void CConnecter::slotSettings()
void sigUpdateName(const QString &szName)
virtual void slotBlockShowWidget(const QString &className, int &nRet, void *pContext)
Blocks the background thread and displays the window in the foreground thread.
virtual const QIcon Icon() const
Icon.
virtual void slotBlockInputDialog(const QString &szTitle, const QString &szLable, const QString &szMessage, QString &szText)
Block background threads and display input dialogs in foreground threads (QInputDialog)
virtual int Load(QSettings &set)
Load parameters.
virtual Q_INVOKABLE int SetParameterClient(CParameterClient *pPara)
Set CParameterClient.
virtual QDialog * OnOpenDialogSettings(QWidget *parent=nullptr)=0
Open settgins dialog.
virtual int OpenDialogSettings(QWidget *parent=nullptr)
Open settings dialog.
virtual QWidget * GetViewer()=0
Get Viewer.
void sigDisconnected()
Successful disconnection signal.
virtual int Save(QSettings &set)
Save parameters.
virtual int SetParameter(CParameter *p)
Set parameters.
virtual const QString Description()
Description.
virtual const QString Protocol() const
Protocol.
virtual const QString Id()
Identity.
virtual QMenu * GetMenu(QWidget *parent=nullptr)
Get operate menu.
virtual void slotSetClipboard(QMimeData *data)
virtual const QString Name()
Name.
virtual void slotBlockShowMessageBox(const QString &szTitle, const QString &szMessage, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton &nRet, bool &checkBox, QString szCheckBoxContext=QString())
Block background threads and display message dialogs in foreground threads (QMessageBox)
The parameters of client.
virtual int Save(QString szFile=QString(), bool bForce=true)
Save to file.
virtual int Load(QString szFile=QString())
Load from file.
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...
virtual const QString Protocol() const =0
Plugin Protocol.