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;
37 +
"_" + QString::number((
int)
GetPlugin()->Type());
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())
114CStats *COperate::GetStats()
119COperate::SecurityLevel COperate::GetSecurityLevel()
121 return SecurityLevel::No;
124QString COperate::GetSecurityLevelString()
126 return GetSecurityLevelString(GetSecurityLevel());
129QString COperate::GetSecurityLevelString(SecurityLevel level)
132 case SecurityLevel::No:
134 case SecurityLevel::Secure:
136 case SecurityLevel::NonSecureAuthentication:
137 return tr(
"Non-secure authentication over a secure channel");
138 case SecurityLevel::Normal:
139 return tr(
"Channel is secure.");
140 case SecurityLevel::SecureAuthentication:
141 return tr(
"There is security verification, not a secure channel.");
142 case SecurityLevel::Risky:
150QColor COperate::GetSecurityLevelColor()
152 return GetSecurityLevelColor(GetSecurityLevel());
155QColor COperate::GetSecurityLevelColor(SecurityLevel level)
158 case SecurityLevel::Secure:
159 return Qt::GlobalColor::green;
160 case SecurityLevel::NonSecureAuthentication:
161 return Qt::GlobalColor::blue;
162 case SecurityLevel::Normal:
163 return Qt::GlobalColor::yellow;
164 case SecurityLevel::SecureAuthentication:
165 return Qt::GlobalColor::darkRed;
166 case SecurityLevel::Risky:
167 return Qt::GlobalColor::red;
174QString COperate::GetSettingsFile()
176 if(m_szSettings.isEmpty())
178 m_szSettings = RabbitCommon::CDir::Instance()->GetDirUserData()
186int COperate::SetSettingsFile(
const QString &szFile)
188 m_szSettings = szFile;
194 Q_ASSERT(!szFile.isEmpty());
197 qCritical(log) <<
"The load file is empty";
200 QSettings set(szFile, QSettings::IniFormat);
206 Q_ASSERT(!szFile.isEmpty());
209 qCritical(log) <<
"The load file is empty";
212 QSettings set(szFile, QSettings::IniFormat);
232 m_Menu.setIcon(m_pPlugin->Icon());
237 m_pActionSettings =
new QAction(QIcon::fromTheme(
"system-settings"),
238 tr(
"Settings"), &m_Menu);
239 if(m_pActionSettings) {
240 bool check = connect(m_pActionSettings, SIGNAL(triggered()),
241 this, SLOT(slotSettings()));
252void COperate::slotSettings()
255 if(QDialog::Accepted == nRet)
266 auto pPlugin = pPara;
269 bool check = connect(pPlugin, SIGNAL(sigShowProtocolPrefixChanged()),
270 this, SLOT(slotUpdateName()));
272 check = connect(pPlugin, SIGNAL(sigSHowIpPortInNameChanged()),
273 this, SLOT(slotUpdateName()));
279void COperate::slotUpdateName()
284QObject* COperate::createObject(
const QString& className, QObject* parent)
288#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
289 QMetaType::fromName(className.toStdString().c_str()).id();
291 QMetaType::type(className.toStdString().c_str());
293 if(QMetaType::UnknownType == type)
295 qCritical(log) << className <<
" is QMetaType::UnknownType";
299#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
300 (QObject*)QMetaType(type).create();
302 (QObject*)QMetaType::create(type);
306 qCritical(log) <<
"QMetaType::create fail: " << type;
317 QObject *obj = createObject(className);
318 Q_ASSERT_X(obj,
"Connecter", QString(
"Create object failed: " + className).toStdString().c_str());
326 if(-1 == obj->metaObject()->indexOfMethod(
"SetContext(void*)"))
329 szErr =
"The class " + className +
" is not method SetContext. It must be SetContext(void*) method.";
330 qCritical(log) << szErr;
331 Q_ASSERT_X(
false,
"Connecter", szErr.toStdString().c_str());
333 obj->metaObject()->invokeMethod(obj,
"SetContext", Q_ARG(
void*, pContext));
335 if(obj->inherits(
"QDialog"))
337 QDialog* pDlg = qobject_cast<QDialog*>(obj);
338 pDlg->setAttribute(Qt::WA_DeleteOnClose);
340 pDlg, SLOT(reject()));
342 nRet = RC_SHOW_WINDOW(pDlg);
343 }
else if(obj->inherits(
"QWidget")) {
344 QWidget* pWdg = qobject_cast<QWidget*>(obj);
345 pWdg->setAttribute(Qt::WA_DeleteOnClose);
347 pWdg, SLOT(close()));
349 nRet = RC_SHOW_WINDOW(pWdg);
354 QMessageBox::StandardButtons buttons,
355 QMessageBox::StandardButton &nRet,
357 QString szCheckBoxContext)
359 QCheckBox* pBox =
nullptr;
360 QMessageBox msg(QMessageBox::Information,
361 szTitle, szMessage, buttons,
GetViewer());
362 if(!szCheckBoxContext.isEmpty())
364 pBox =
new QCheckBox(szCheckBoxContext);
366 pBox->setCheckable(
true);
367 msg.setCheckBox(pBox);
369 nRet = (QMessageBox::StandardButton)RC_SHOW_WINDOW(&msg);
371 checkBox = pBox->isChecked();
375 const QString &szMessage,
379 QString t = QInputDialog::getText(
nullptr,
385 if(ok && !t.isEmpty())
391 QClipboard* pClipboard = QApplication::clipboard();
395 pClipboard->setMimeData(data);
virtual QDialog * OnOpenDialogSettings(QWidget *parent=nullptr)=0
得到设置对话框
virtual int OpenDialogSettings(QWidget *parent=nullptr)
打开设置对话框
virtual int Load(QSettings &set)
加载参数
virtual int Save(QSettings &set)
保存参数
void sigFinished()
断开连接成功信号。仅由插件触发
virtual const QIcon Icon() const
Icon
virtual Q_INVOKABLE int Initial()
Initial parameters and resource
virtual QWidget * GetViewer()=0
得到显示视图
virtual void slotBlockShowWidget(const QString &className, int &nRet, void *pContext)
阻塞后台线程,并在前台线程中显示窗口。
virtual const QString Protocol() const
Protocol
virtual Q_INVOKABLE int SetGlobalParameters(CParameterPlugin *pPara)=0
应用插件全局参数
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())
阻塞后台线程,并在前台线程中显示消息对话框(QMessageBox)
virtual const QString Description()
Description
void sigUpdateParameters(COperate *pOperate)
更新参数,通知应用程序保存或显示参数
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
virtual const QString Name() const =0
插件名,这个名一定要与工程名(${PROJECT_NAME})相同。 翻译文件(${PROJECT_NAME}_*.ts))名与其相关。
virtual const QString DisplayName() const
在界面上显示的名称
virtual const QString Protocol() const =0
协议
virtual const QString Description() const =0
描述