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 qInfo(log) <<
"Load configure file:" << szFile;
201 QSettings set(szFile, QSettings::IniFormat);
207 Q_ASSERT(!szFile.isEmpty());
210 qCritical(log) <<
"The load file is empty";
213 qInfo(log) <<
"Save configure file:" << szFile;
214 QSettings set(szFile, QSettings::IniFormat);
220 m_Menu.setIcon(m_pPlugin->Icon());
225 m_pActionSettings =
new QAction(QIcon::fromTheme(
"system-settings"),
226 tr(
"Settings"), &m_Menu);
227 if(m_pActionSettings) {
228 bool check = connect(m_pActionSettings, SIGNAL(triggered()),
229 this, SLOT(slotSettings()));
240void COperate::slotSettings()
243 if(QDialog::Accepted == nRet)
254 QString szMsg =
"There is not parameters! "
255 "please first create parameters, "
256 "then call SetParameter() in the ";
257 szMsg += metaObject()->className() + QString(
"::")
258 + metaObject()->className();
259 szMsg += QString(
"() or ") + metaObject()->className()
260 + QString(
"::") +
"Initial()";
261 szMsg +=
" to set the parameters pointer. "
262 "Default set CParameterClient for the parameters of operate "
263 "(CParameterOperate or its derived classes) "
264 "See CManager::CreateOperate. "
265 "If you are sure the parameter of operate "
266 "does not need CParameterClient. "
267 "Please overload the SetGlobalParameters() in the ";
268 szMsg += QString(metaObject()->className()) +
" . don't set it";
269 qCritical(log) << szMsg.toStdString().c_str();
270 Q_ASSERT_X(
false, Q_FUNC_INFO, szMsg.toStdString().c_str());
275void COperate::slotUpdateName()
280QObject* COperate::createObject(
const QString& className, QObject* parent)
284#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
285 QMetaType::fromName(className.toStdString().c_str()).id();
287 QMetaType::type(className.toStdString().c_str());
289 if(QMetaType::UnknownType == type)
291 qCritical(log) << className <<
" is QMetaType::UnknownType";
295#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
296 (QObject*)QMetaType(type).create();
298 (QObject*)QMetaType::create(type);
302 qCritical(log) <<
"QMetaType::create fail: " << type;
313 QObject *obj = createObject(className);
314 Q_ASSERT_X(obj,
"Connecter", QString(
"Create object failed: " + className).toStdString().c_str());
322 if(-1 == obj->metaObject()->indexOfMethod(
"SetContext(void*)"))
325 szErr =
"The class " + className +
" is not method SetContext. It must be SetContext(void*) method.";
326 qCritical(log) << szErr;
327 Q_ASSERT_X(
false,
"Connecter", szErr.toStdString().c_str());
329 obj->metaObject()->invokeMethod(obj,
"SetContext", Q_ARG(
void*, pContext));
331 if(obj->inherits(
"QDialog"))
333 QDialog* pDlg = qobject_cast<QDialog*>(obj);
334 pDlg->setAttribute(Qt::WA_DeleteOnClose);
336 pDlg, SLOT(reject()));
338 nRet = RC_SHOW_WINDOW(pDlg);
339 }
else if(obj->inherits(
"QWidget")) {
340 QWidget* pWdg = qobject_cast<QWidget*>(obj);
341 pWdg->setAttribute(Qt::WA_DeleteOnClose);
343 pWdg, SLOT(close()));
345 nRet = RC_SHOW_WINDOW(pWdg);
350 QMessageBox::StandardButtons buttons,
351 QMessageBox::StandardButton &nRet,
353 QString szCheckBoxContext)
355 QCheckBox* pBox =
nullptr;
356 QMessageBox msg(QMessageBox::Information,
357 szTitle, szMessage, buttons,
GetViewer());
358 if(!szCheckBoxContext.isEmpty())
360 pBox =
new QCheckBox(szCheckBoxContext);
362 pBox->setCheckable(
true);
363 msg.setCheckBox(pBox);
365 nRet = (QMessageBox::StandardButton)RC_SHOW_WINDOW(&msg);
367 checkBox = pBox->isChecked();
371 const QString &szMessage,
375 QString t = QInputDialog::getText(
nullptr,
381 if(ok && !t.isEmpty())
387 QClipboard* pClipboard = QApplication::clipboard();
391 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 Load(QSettings &set)=0
加载参数
virtual Q_INVOKABLE int Initial()
Initial parameters and resource
virtual int Save(QSettings &set)=0
保存参数
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
描述