4#include <QLoggingCategory>
9#include "RabbitCommonTools.h"
10#include "RabbitCommonDir.h"
12static Q_LOGGING_CATEGORY(log,
"Operate")
17 , m_pActionSettings(
nullptr)
19 qDebug(log) << Q_FUNC_INFO;
20 if(QApplication::clipboard())
22 bool check = connect(QApplication::clipboard(), SIGNAL(dataChanged()),
23 this, SIGNAL(sigClipBoardChanged()));
30 qDebug(log) << Q_FUNC_INFO;
48 QString szDescription;
50 szDescription = tr(
"Name: ") +
Name() +
"\n";
53 szDescription += tr(
"Type:") +
GetTypeName() +
"\n";
56 szDescription += tr(
"Protocol: ") +
Protocol();
61 szDescription +=
"\n";
64 if(GetSecurityLevel() != SecurityLevel::No)
65 szDescription += tr(
"Security level: ") + GetSecurityLevelString() +
"\n";
89 int nRet = QDialog::Accepted;
97 p->setWindowIcon(this->
Icon());
98 p->setWindowTitle(tr(
"Set ") +
GetPlugin()->DisplayName());
99 p->setAttribute(Qt::WA_DeleteOnClose);
100 nRet = RC_SHOW_WINDOW(p);
102 qCritical(log) <<
"The Protocol [" <<
Protocol() <<
"] don't settings dialog";
109 if(m_Menu.actions().isEmpty())
114COperate::SecurityLevel COperate::GetSecurityLevel()
116 return SecurityLevel::No;
119QString COperate::GetSecurityLevelString()
121 return GetSecurityLevelString(GetSecurityLevel());
124QString COperate::GetSecurityLevelString(SecurityLevel level)
127 case SecurityLevel::No:
129 case SecurityLevel::Secure:
131 case SecurityLevel::NonSecureAuthentication:
132 return tr(
"Non-secure authentication over a secure channel");
133 case SecurityLevel::Normal:
134 return tr(
"Channel is secure.");
135 case SecurityLevel::SecureAuthentication:
136 return tr(
"There is security verification, not a secure channel.");
137 case SecurityLevel::Risky:
145QColor COperate::GetSecurityLevelColor()
147 return GetSecurityLevelColor(GetSecurityLevel());
150QColor COperate::GetSecurityLevelColor(SecurityLevel level)
153 case SecurityLevel::Secure:
154 return Qt::GlobalColor::green;
155 case SecurityLevel::NonSecureAuthentication:
156 return Qt::GlobalColor::blue;
157 case SecurityLevel::Normal:
158 return Qt::GlobalColor::yellow;
159 case SecurityLevel::SecureAuthentication:
160 return Qt::GlobalColor::darkRed;
161 case SecurityLevel::Risky:
162 return Qt::GlobalColor::red;
169QString COperate::GetSettingsFile()
171 if(m_szSettings.isEmpty())
173 m_szSettings = RabbitCommon::CDir::Instance()->GetDirUserData()
181int COperate::SetSettingsFile(
const QString &szFile)
183 m_szSettings = szFile;
189 Q_ASSERT(!szFile.isEmpty());
192 qCritical(log) <<
"The load file is empty";
195 QSettings set(szFile, QSettings::IniFormat);
201 Q_ASSERT(!szFile.isEmpty());
204 qCritical(log) <<
"The load file is empty";
207 QSettings set(szFile, QSettings::IniFormat);
227 m_Menu.setIcon(m_pPlugin->Icon());
232 m_pActionSettings =
new QAction(QIcon::fromTheme(
"system-settings"),
233 tr(
"Settings"), &m_Menu);
234 if(m_pActionSettings) {
235 bool check = connect(m_pActionSettings, SIGNAL(triggered()),
236 this, SLOT(slotSettings()));
247void COperate::slotSettings()
250 if(QDialog::Accepted == nRet)
261 auto pPlugin = pPara;
264 bool check = connect(pPlugin, SIGNAL(sigShowProtocolPrefixChanged()),
265 this, SLOT(slotUpdateName()));
267 check = connect(pPlugin, SIGNAL(sigSHowIpPortInNameChanged()),
268 this, SLOT(slotUpdateName()));
274void COperate::slotUpdateName()
279QObject* COperate::createObject(
const QString& className, QObject* parent)
283#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
284 QMetaType::fromName(className.toStdString().c_str()).id();
286 QMetaType::type(className.toStdString().c_str());
288 if(QMetaType::UnknownType == type)
290 qCritical(log) << className <<
" is QMetaType::UnknownType";
294#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
295 (QObject*)QMetaType(type).create();
297 (QObject*)QMetaType::create(type);
301 qCritical(log) <<
"QMetaType::create fail: " << type;
312 QObject *obj = createObject(className);
313 Q_ASSERT_X(obj,
"Connecter", QString(
"Create object failed: " + className).toStdString().c_str());
321 if(-1 == obj->metaObject()->indexOfMethod(
"SetContext(void*)"))
324 szErr =
"The class " + className +
" is not method SetContext. It must be SetContext(void*) method.";
325 qCritical(log) << szErr;
326 Q_ASSERT_X(
false,
"Connecter", szErr.toStdString().c_str());
328 obj->metaObject()->invokeMethod(obj,
"SetContext", Q_ARG(
void*, pContext));
330 if(obj->inherits(
"QDialog"))
332 QDialog* pDlg = qobject_cast<QDialog*>(obj);
333 pDlg->setAttribute(Qt::WA_DeleteOnClose);
335 pDlg, SLOT(reject()));
337 nRet = RC_SHOW_WINDOW(pDlg);
338 }
else if(obj->inherits(
"QWidget")) {
339 QWidget* pWdg = qobject_cast<QWidget*>(obj);
340 pWdg->setAttribute(Qt::WA_DeleteOnClose);
342 pWdg, SLOT(close()));
344 nRet = RC_SHOW_WINDOW(pWdg);
349 QMessageBox::StandardButtons buttons,
350 QMessageBox::StandardButton &nRet,
352 QString szCheckBoxContext)
354 QCheckBox* pBox =
nullptr;
355 QMessageBox msg(QMessageBox::Information,
356 szTitle, szMessage, buttons,
GetViewer());
357 if(!szCheckBoxContext.isEmpty())
359 pBox =
new QCheckBox(szCheckBoxContext);
361 pBox->setCheckable(
true);
362 msg.setCheckBox(pBox);
364 nRet = (QMessageBox::StandardButton)RC_SHOW_WINDOW(&msg);
366 checkBox = pBox->isChecked();
370 const QString &szMessage,
374 QString t = QInputDialog::getText(
nullptr,
380 if(ok && !t.isEmpty())
386 QClipboard* pClipboard = QApplication::clipboard();
390 pClipboard->setMimeData(data);
virtual QDialog * OnOpenDialogSettings(QWidget *parent=nullptr)=0
Open settgins dialog.
virtual int OpenDialogSettings(QWidget *parent=nullptr)
Open settings dialog.
virtual int Load(QSettings &set)
Load parameters.
virtual int Save(QSettings &set)
Save parameters.
void sigFinished()
Successful disconnection signal.
virtual const QIcon Icon() const
Icon.
virtual Q_INVOKABLE int Initial()
Initial parameters and resource.
virtual QWidget * GetViewer()=0
Get Viewer.
virtual void slotBlockShowWidget(const QString &className, int &nRet, void *pContext)
Blocks the background thread and displays the window in the foreground thread.
virtual const QString Protocol() const
Protocol.
virtual Q_INVOKABLE int SetGlobalParameters(CParameterPlugin *pPara)=0
Apply the global parameters of the plug-in.
virtual Q_INVOKABLE int Clean()
Clean parameters and resource.
virtual void slotSetClipboard(QMimeData *data)
Q_INVOKABLE CPlugin * GetPlugin() const
Get plugin.
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 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)
virtual const QString Description()
Description.
void sigUpdateParameters(COperate *pOperate)
Update parameters, notify application to save or show parameters.
virtual const QString Id()
Identity.
void sigUpdateName(const QString &szName)
virtual const QString GetTypeName() const
Get type name.
virtual QMenu * GetMenu(QWidget *parent=nullptr)
Get menu.
Global parameters of plugins.
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 DisplayName() const
The plugin display name.
virtual const QString Protocol() const =0
Plugin Protocol.
virtual const QString Description() const =0
Plugin description.