4#include <QLoggingCategory>
6#include <QRegularExpression>
10#include "RabbitCommonTools.h"
11#include "RabbitCommonDir.h"
13static Q_LOGGING_CATEGORY(log,
"Operate")
18 , m_pActionSettings(
nullptr)
20 qDebug(log) << Q_FUNC_INFO;
21 if(QApplication::clipboard())
23 bool check = connect(QApplication::clipboard(), SIGNAL(dataChanged()),
24 this, SIGNAL(sigClipBoardChanged()));
31 qDebug(log) << Q_FUNC_INFO;
38 +
"_" + QString::number((
int)
GetPlugin()->Type());
39 static QRegularExpression exp(
"[-@:/#%!^&* \\.]");
40 szId = szId.replace(exp,
"_");
51 QString szDescription;
53 szDescription = tr(
"Name: ") +
Name() +
"\n";
56 szDescription += tr(
"Type:") +
GetTypeName() +
"\n";
59 szDescription += tr(
"Protocol: ") +
Protocol();
64 szDescription +=
"\n";
67 if(GetSecurityLevel() != SecurityLevel::No)
68 szDescription += tr(
"Security level: ") + GetSecurityLevelString() +
"\n";
92 int nRet = QDialog::Accepted;
100 p->setWindowIcon(this->
Icon());
101 p->setWindowTitle(tr(
"Set ") +
GetPlugin()->DisplayName());
102 p->setAttribute(Qt::WA_DeleteOnClose);
103 nRet = RC_SHOW_WINDOW(p);
105 qCritical(log) <<
"The Protocol [" <<
Protocol() <<
"] don't settings dialog";
112 if(m_Menu.actions().isEmpty())
117CStats *COperate::GetStats()
122COperate::SecurityLevel COperate::GetSecurityLevel()
124 return SecurityLevel::No;
127QString COperate::GetSecurityLevelString()
129 return GetSecurityLevelString(GetSecurityLevel());
132QString COperate::GetSecurityLevelString(SecurityLevel level)
135 case SecurityLevel::No:
137 case SecurityLevel::Secure:
139 case SecurityLevel::NonSecureAuthentication:
140 return tr(
"Non-secure authentication over a secure channel");
141 case SecurityLevel::Normal:
142 return tr(
"Channel is secure.");
143 case SecurityLevel::SecureAuthentication:
144 return tr(
"There is security verification, not a secure channel.");
145 case SecurityLevel::Risky:
153QColor COperate::GetSecurityLevelColor()
155 return GetSecurityLevelColor(GetSecurityLevel());
158QColor COperate::GetSecurityLevelColor(SecurityLevel level)
161 case SecurityLevel::Secure:
162 return Qt::GlobalColor::green;
163 case SecurityLevel::NonSecureAuthentication:
164 return Qt::GlobalColor::blue;
165 case SecurityLevel::Normal:
166 return Qt::GlobalColor::yellow;
167 case SecurityLevel::SecureAuthentication:
168 return Qt::GlobalColor::darkRed;
169 case SecurityLevel::Risky:
170 return Qt::GlobalColor::red;
177QString COperate::GetSettingsFile()
179 if(m_szSettings.isEmpty())
181 m_szSettings = RabbitCommon::CDir::Instance()->GetDirUserData()
185 static QRegularExpression exp(
"[-@:#%!^&* .]");
186 m_szSettings = m_szSettings.replace(exp,
"_");
191int COperate::SetSettingsFile(
const QString &szFile)
193 m_szSettings = szFile;
199 Q_ASSERT(!szFile.isEmpty());
202 qCritical(log) <<
"The load file is empty";
205 qInfo(log) <<
"Load configure file:" << szFile;
206 QSettings set(szFile, QSettings::IniFormat);
212 Q_ASSERT(!szFile.isEmpty());
215 qCritical(log) <<
"The load file is empty";
218 qInfo(log) <<
"Save configure file:" << szFile;
219 QSettings set(szFile, QSettings::IniFormat);
225 m_Menu.setIcon(m_pPlugin->Icon());
230 m_pActionSettings =
new QAction(QIcon::fromTheme(
"system-settings"),
231 tr(
"Settings"), &m_Menu);
232 if(m_pActionSettings) {
233 bool check = connect(m_pActionSettings, SIGNAL(triggered()),
234 this, SLOT(slotSettings()));
245void COperate::slotSettings()
248 if(QDialog::Accepted == nRet)
259 QString szMsg =
"There is not parameters! "
260 "please first create parameters, "
261 "then call SetParameter() in the ";
262 szMsg += metaObject()->className() + QString(
"::")
263 + metaObject()->className();
264 szMsg += QString(
"() or ") + metaObject()->className()
265 + QString(
"::") +
"Initial()";
266 szMsg +=
" to set the parameters pointer. "
267 "Default set CParameterClient for the parameters of operate "
268 "(CParameterOperate or its derived classes) "
269 "See CManager::CreateOperate. "
270 "If you are sure the parameter of operate "
271 "does not need CParameterClient. "
272 "Please overload the SetGlobalParameters() in the ";
273 szMsg += QString(metaObject()->className()) +
" . don't set it";
274 qCritical(log) << szMsg.toStdString().c_str();
275 Q_ASSERT_X(
false, Q_FUNC_INFO, szMsg.toStdString().c_str());
280void COperate::slotUpdateName()
285QObject* COperate::createObject(
const QString& className, QObject* parent)
289#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
290 QMetaType::fromName(className.toStdString().c_str()).id();
292 QMetaType::type(className.toStdString().c_str());
294 if(QMetaType::UnknownType == type)
296 qCritical(log) << className <<
" is QMetaType::UnknownType";
300#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
301 (QObject*)QMetaType(type).create();
303 (QObject*)QMetaType::create(type);
307 qCritical(log) <<
"QMetaType::create fail: " << type;
318 QObject *obj = createObject(className);
319 Q_ASSERT_X(obj,
"Connecter", QString(
"Create object failed: " + className).toStdString().c_str());
327 if(-1 == obj->metaObject()->indexOfMethod(
"SetContext(void*)"))
330 szErr =
"The class " + className +
" is not method SetContext. It must be SetContext(void*) method.";
331 qCritical(log) << szErr;
332 Q_ASSERT_X(
false,
"Connecter", szErr.toStdString().c_str());
334 obj->metaObject()->invokeMethod(obj,
"SetContext", Q_ARG(
void*, pContext));
336 if(obj->inherits(
"QDialog"))
338 QDialog* pDlg = qobject_cast<QDialog*>(obj);
339 pDlg->setAttribute(Qt::WA_DeleteOnClose);
341 pDlg, SLOT(reject()));
343 nRet = RC_SHOW_WINDOW(pDlg);
344 }
else if(obj->inherits(
"QWidget")) {
345 QWidget* pWdg = qobject_cast<QWidget*>(obj);
346 pWdg->setAttribute(Qt::WA_DeleteOnClose);
348 pWdg, SLOT(close()));
350 nRet = RC_SHOW_WINDOW(pWdg);
355 QMessageBox::StandardButtons buttons,
356 QMessageBox::StandardButton &nRet,
358 QString szCheckBoxContext)
360 QCheckBox* pBox =
nullptr;
361 QMessageBox msg(QMessageBox::Information,
362 szTitle, szMessage, buttons,
GetViewer());
363 if(!szCheckBoxContext.isEmpty())
365 pBox =
new QCheckBox(szCheckBoxContext);
367 pBox->setCheckable(
true);
368 msg.setCheckBox(pBox);
370 nRet = (QMessageBox::StandardButton)RC_SHOW_WINDOW(&msg);
372 checkBox = pBox->isChecked();
376 const QString &szMessage,
380 QString t = QInputDialog::getText(
nullptr,
386 if(ok && !t.isEmpty())
392 QClipboard* pClipboard = QApplication::clipboard();
396 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 Q_INVOKABLE int Initial()
Initial parameters and resource
virtual QWidget * GetViewer()=0
得到显示视图
virtual void slotBlockShowWidget(const QString &className, int &nRet, void *pContext)
阻塞后台线程,并在前台线程中显示窗口。
virtual Q_INVOKABLE int Load(QSettings &set)=0
加载参数
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 Q_INVOKABLE int Save(QSettings &set)=0
保存参数
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
描述