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 QString szMsg =
"There is not parameters! "
267 "please first create parameters, "
268 "then call SetParameter() in the ";
269 szMsg += metaObject()->className() + QString(
"::")
270 + metaObject()->className();
271 szMsg += QString(
"() or ") + metaObject()->className()
272 + QString(
"::") +
"Initial()";
273 szMsg +=
" to set the parameters pointer. "
274 "Default set CParameterClient for the parameters of operate "
275 "(CParameterOperate or its derived classes) "
276 "See CManager::CreateOperate. "
277 "If you are sure the parameter of operate "
278 "does not need CParameterClient. "
279 "Please overload the SetGlobalParameters() in the ";
280 szMsg += QString(metaObject()->className()) +
" . don't set it";
281 qCritical(log) << szMsg.toStdString().c_str();
282 Q_ASSERT_X(
false, Q_FUNC_INFO, szMsg.toStdString().c_str());
287void COperate::slotUpdateName()
292QObject* COperate::createObject(
const QString& className, QObject* parent)
296#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
297 QMetaType::fromName(className.toStdString().c_str()).id();
299 QMetaType::type(className.toStdString().c_str());
301 if(QMetaType::UnknownType == type)
303 qCritical(log) << className <<
" is QMetaType::UnknownType";
307#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
308 (QObject*)QMetaType(type).create();
310 (QObject*)QMetaType::create(type);
314 qCritical(log) <<
"QMetaType::create fail: " << type;
325 QObject *obj = createObject(className);
326 Q_ASSERT_X(obj,
"Connecter", QString(
"Create object failed: " + className).toStdString().c_str());
334 if(-1 == obj->metaObject()->indexOfMethod(
"SetContext(void*)"))
337 szErr =
"The class " + className +
" is not method SetContext. It must be SetContext(void*) method.";
338 qCritical(log) << szErr;
339 Q_ASSERT_X(
false,
"Connecter", szErr.toStdString().c_str());
341 obj->metaObject()->invokeMethod(obj,
"SetContext", Q_ARG(
void*, pContext));
343 if(obj->inherits(
"QDialog"))
345 QDialog* pDlg = qobject_cast<QDialog*>(obj);
346 pDlg->setAttribute(Qt::WA_DeleteOnClose);
348 pDlg, SLOT(reject()));
350 nRet = RC_SHOW_WINDOW(pDlg);
351 }
else if(obj->inherits(
"QWidget")) {
352 QWidget* pWdg = qobject_cast<QWidget*>(obj);
353 pWdg->setAttribute(Qt::WA_DeleteOnClose);
355 pWdg, SLOT(close()));
357 nRet = RC_SHOW_WINDOW(pWdg);
362 QMessageBox::StandardButtons buttons,
363 QMessageBox::StandardButton &nRet,
365 QString szCheckBoxContext)
367 QCheckBox* pBox =
nullptr;
368 QMessageBox msg(QMessageBox::Information,
369 szTitle, szMessage, buttons,
GetViewer());
370 if(!szCheckBoxContext.isEmpty())
372 pBox =
new QCheckBox(szCheckBoxContext);
374 pBox->setCheckable(
true);
375 msg.setCheckBox(pBox);
377 nRet = (QMessageBox::StandardButton)RC_SHOW_WINDOW(&msg);
379 checkBox = pBox->isChecked();
383 const QString &szMessage,
387 QString t = QInputDialog::getText(
nullptr,
393 if(ok && !t.isEmpty())
399 QClipboard* pClipboard = QApplication::clipboard();
403 pClipboard->setMimeData(data);
virtual QDialog * OnOpenDialogSettings(QWidget *parent=nullptr)=0
得到设置对话框
virtual int OpenDialogSettings(QWidget *parent=nullptr)
打开设置对话框
void sigFinished()
断开连接成功信号。仅由插件触发
virtual const QIcon Icon() const
Icon
virtual int Save(QSettings &set)=0
保存参数
virtual int Load(QSettings &set)=0
加载参数
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
描述