Skip to content

Commit 2555dd8

Browse files
committed
Plugin: load plugin with file
1 parent f262d38 commit 2555dd8

9 files changed

Lines changed: 76 additions & 49 deletions

Src/FrmManagePlugins.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int CFrmManagePlugins::Accept()
7272
m_pPara->m_WhiteList.Clear();
7373
m_pPara->m_BlackList.Clear();
7474
for(int i = 0; i < m_pModelFilter->rowCount(); i++) {
75-
QString szPath = m_pModelFilter->item(i, ColumnNo::Path)->text();
75+
QString szPath = m_pModelFilter->item(i, ColumnNo::File)->text();
7676
if(szPath.isEmpty()) continue;
7777
auto pWhitelist = m_pModelFilter->item(i, ColumnNo::Whitelist);
7878
if(pWhitelist->checkState() == Qt::Checked)
@@ -117,18 +117,18 @@ int CFrmManagePlugins::FindPlugins(QDir dir, QStringList filters, bool bAdd)
117117
foreach (auto fileName, files) {
118118
QString szPath = dir.absoluteFilePath(fileName);
119119
if(!bAdd) {
120-
RemoveItem(szPath);
120+
RemoveItem(fileName);
121121
continue;
122122
}
123-
auto pFind = m_pModelFilter->findItems(szPath, Qt::MatchExactly, ColumnNo::Path);
123+
auto pFind = m_pModelFilter->findItems(szPath, Qt::MatchExactly, ColumnNo::File);
124124
if(!pFind.isEmpty()) continue;
125125

126126
QPluginLoader loader(szPath);
127127
QObject *plugin = loader.instance();
128128
if(plugin) {
129129
CPlugin* p = qobject_cast<CPlugin*>(plugin);
130130
if(p)
131-
AddItem(p, szPath);
131+
AddItem(p, fileName);
132132
loader.unload();
133133
}
134134
}
@@ -170,7 +170,7 @@ int CFrmManagePlugins::AddItem(CPlugin* plugin, const QString& szPath)
170170

171171
int CFrmManagePlugins::RemoveItem(const QString &szPath)
172172
{
173-
auto pFind = m_pModelFilter->findItems(szPath, Qt::MatchExactly, ColumnNo::Path);
173+
auto pFind = m_pModelFilter->findItems(szPath, Qt::MatchExactly, ColumnNo::File);
174174
if(pFind.isEmpty()) return 0;
175175
foreach(auto item, pFind) {
176176
m_pModelFilter->removeRow(item->index().row());
@@ -253,7 +253,7 @@ int CFrmManagePlugins::SetFilterHeader()
253253
m_pModelFilter->setHorizontalHeaderItem(ColumnNo::Blacklist, pBlacklist);
254254
m_pModelFilter->setHorizontalHeaderItem(ColumnNo::Name, new QStandardItem(tr("Name")));
255255
m_pModelFilter->setHorizontalHeaderItem(ColumnNo::Type, new QStandardItem(tr("Type")));
256-
m_pModelFilter->setHorizontalHeaderItem(ColumnNo::Path, new QStandardItem(tr("Path")));
256+
m_pModelFilter->setHorizontalHeaderItem(ColumnNo::File, new QStandardItem(tr("File")));
257257

258258
if(qobject_cast<CCheckBoxHeader*>(ui->tvFilter->horizontalHeader()))
259259
return 0;
@@ -270,7 +270,7 @@ int CFrmManagePlugins::SetFilterHeader()
270270
switch(state)
271271
{
272272
case Qt::PartiallyChecked: {
273-
QString szPath = m_pModelFilter->item(row, ColumnNo::Path)->text();
273+
QString szPath = m_pModelFilter->item(row, ColumnNo::File)->text();
274274
if(ColumnNo::Whitelist == index) {
275275
if(m_pPara->m_WhiteList.contains(szPath))
276276
item->setCheckState(Qt::Checked);

Src/FrmManagePlugins.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private slots:
4343
Blacklist,
4444
Name,
4545
Type,
46-
Path
46+
File
4747
};
4848
CParameterPlugin* m_pPara;
4949
QStandardItemModel* m_pModelPluginPath;

Src/Manager.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@ int CManager::LoadPlugins()
168168
}
169169
}//*/
170170

171-
if(m_pParameter->GetOnlyLoadInWhitelist()) {
172-
m_pParameter->m_WhiteList.OnProcess([this](const QString& szPath) -> int{
173-
return LoadPlugin(szPath);
174-
});
175-
return 0;
176-
}
177-
178171
QStringList lstPaths;
179172
if(m_pParameter->GetEnableSetPluginsPath()) {
180173
lstPaths = m_pParameter->GetPluginsPath();
@@ -183,6 +176,22 @@ int CManager::LoadPlugins()
183176
lstPaths << RabbitCommon::CDir::Instance()->GetDirPlugins();
184177
if(lstPaths.isEmpty())
185178
qWarning(log) << "The plugins path is empty. please set it from: `Menu` -> `Tools` -> `Settings` -> `Load Plugins`";
179+
180+
if(m_pParameter->GetOnlyLoadInWhitelist()) {
181+
m_pParameter->m_WhiteList.OnProcess([this, lstPaths](const QString& szPath) -> int{
182+
QFileInfo fi(szPath);
183+
if(fi.isAbsolute())
184+
return LoadPlugin(szPath);
185+
foreach (auto d, lstPaths) {
186+
if(d.isEmpty()) continue;
187+
QString szFile = d + QDir::separator() + szPath;
188+
return LoadPlugin(szFile);
189+
}
190+
return -1;
191+
});
192+
return 0;
193+
}
194+
186195
foreach (auto szPath, lstPaths) {
187196
//QString szPath = RabbitCommon::CDir::Instance()->GetDirPlugins();
188197

@@ -235,8 +244,9 @@ int CManager::FindPlugins(QDir dir, QStringList filters)
235244

236245
foreach (fileName, files) {
237246
QString szPlugins = dir.absoluteFilePath(fileName);
238-
if(m_pParameter && !m_pParameter->m_WhiteList.contains(szPlugins)
239-
&& m_pParameter->m_BlackList.contains(szPlugins)) {
247+
if(m_pParameter
248+
&& (!m_pParameter->m_WhiteList.contains(szPlugins) || !m_pParameter->m_WhiteList.contains(fileName))
249+
&& (m_pParameter->m_BlackList.contains(szPlugins) || m_pParameter->m_BlackList.contains(fileName))) {
240250
qInfo(log) << "Filter:" << szPlugins << "in blacklist";
241251
continue;
242252
}
@@ -256,6 +266,7 @@ int CManager::FindPlugins(QDir dir, QStringList filters)
256266

257267
int CManager::LoadPlugin(const QString &szPath)
258268
{
269+
int nRet = -1;
259270
QPluginLoader loader(szPath);
260271
QObject *plugin = loader.instance();
261272
if (plugin) {
@@ -270,6 +281,7 @@ int CManager::LoadPlugin(const QString &szPath)
270281
}
271282
else
272283
qWarning(log) << "The plugin [" << p->Name() << "] is exist.";
284+
return 0;
273285
} else
274286
qCritical(log) << "The plugin is not \"CPlugin\":" << szPath;
275287
} else {
@@ -279,7 +291,7 @@ int CManager::LoadPlugin(const QString &szPath)
279291
szMsg += "; Error: " + loader.errorString();
280292
qCritical(log) << szMsg.toStdString().c_str();
281293
}
282-
return 0;
294+
return nRet;
283295
}
284296

285297
int CManager::AppendPlugin(CPlugin *p)

Src/Manager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ class PLUGIN_EXPORT CManager : public QObject
176176

177177
private:
178178
int LoadPlugins();
179+
/*!
180+
* \brief LoadPlugin
181+
* \param szPath: must be absolute.
182+
* \return
183+
*/
179184
int LoadPlugin(const QString& szPath);
180185
int FindPlugins(QDir dir, QStringList filters);
181186
int AppendPlugin(CPlugin* plugin);

Src/ParameterCompone/ParameterPluginUI.ui

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>550</width>
10-
<height>542</height>
10+
<height>600</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -158,7 +158,7 @@
158158
<item row="6" column="0">
159159
<widget class="QGroupBox" name="groupBox">
160160
<property name="sizePolicy">
161-
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
161+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
162162
<horstretch>0</horstretch>
163163
<verstretch>0</verstretch>
164164
</sizepolicy>
@@ -170,7 +170,7 @@
170170
<item row="2" column="0">
171171
<widget class="QGroupBox" name="gpEncryptKey">
172172
<property name="sizePolicy">
173-
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
173+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
174174
<horstretch>0</horstretch>
175175
<verstretch>0</verstretch>
176176
</sizepolicy>
@@ -220,6 +220,12 @@
220220
<layout class="QHBoxLayout" name="horizontalLayout_2">
221221
<item>
222222
<widget class="QLabel" name="label_3">
223+
<property name="sizePolicy">
224+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
225+
<horstretch>0</horstretch>
226+
<verstretch>0</verstretch>
227+
</sizepolicy>
228+
</property>
223229
<property name="text">
224230
<string>Prompt type:</string>
225231
</property>
@@ -228,7 +234,7 @@
228234
<item>
229235
<widget class="QRadioButton" name="rbPromptNo">
230236
<property name="sizePolicy">
231-
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
237+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
232238
<horstretch>0</horstretch>
233239
<verstretch>0</verstretch>
234240
</sizepolicy>

Src/Resource/Translations/Plugin_zh_CN.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@
289289
</message>
290290
<message>
291291
<location filename="../../FrmManagePlugins.cpp" line="256"/>
292-
<source>Path</source>
293-
<translation>路径</translation>
292+
<source>File</source>
293+
<translation>文件</translation>
294294
</message>
295295
<message>
296296
<location filename="../../FrmManagePlugins.cpp" line="184"/>
@@ -385,23 +385,23 @@ Some features are limited.
385385
<translation>总是显示</translation>
386386
</message>
387387
<message>
388-
<location filename="../../Manager.cpp" line="208"/>
388+
<location filename="../../Manager.cpp" line="217"/>
389389
<source>Plugins</source>
390390
<translation>插件</translation>
391391
</message>
392392
<message>
393-
<location filename="../../Manager.cpp" line="303"/>
394-
<location filename="../../Manager.cpp" line="564"/>
393+
<location filename="../../Manager.cpp" line="315"/>
394+
<location filename="../../Manager.cpp" line="576"/>
395395
<source>Version:</source>
396396
<translation>版本:</translation>
397397
</message>
398398
<message>
399-
<location filename="../../Manager.cpp" line="506"/>
399+
<location filename="../../Manager.cpp" line="518"/>
400400
<source>Terminal</source>
401401
<translation>终端</translation>
402402
</message>
403403
<message>
404-
<location filename="../../Manager.cpp" line="569"/>
404+
<location filename="../../Manager.cpp" line="581"/>
405405
<source>Dependency libraries:</source>
406406
<translation>依赖库:</translation>
407407
</message>
@@ -754,7 +754,7 @@ Some features are limited.
754754
<translation>允许使用系统用户作为用户</translation>
755755
</message>
756756
<message>
757-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="280"/>
757+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="286"/>
758758
<source>Store password with system credential manager</source>
759759
<translation>使用系统凭据管理器存储密码</translation>
760760
</message>
@@ -826,17 +826,17 @@ Some features are limited.
826826
<translation>加密密钥:</translation>
827827
</message>
828828
<message>
829-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="224"/>
829+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="230"/>
830830
<source>Prompt type:</source>
831831
<translation>提示类型</translation>
832832
</message>
833833
<message>
834-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="237"/>
834+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="243"/>
835835
<source>No</source>
836836
<translation>不</translation>
837837
</message>
838838
<message>
839-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="250"/>
839+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="256"/>
840840
<source>First</source>
841841
<translation>第一次</translation>
842842
</message>
@@ -846,12 +846,12 @@ Some features are limited.
846846
<translation>密码</translation>
847847
</message>
848848
<message>
849-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="264"/>
849+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="270"/>
850850
<source>Enable save password</source>
851851
<translation>允许保存密码</translation>
852852
</message>
853853
<message>
854-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="271"/>
854+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="277"/>
855855
<location filename="../../ParameterCompone/ParameterPluginUI.cpp" line="24"/>
856856
<source>Enable view password</source>
857857
<translation>允许查看密码</translation>

Src/Resource/Translations/Plugin_zh_TW.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@
289289
</message>
290290
<message>
291291
<location filename="../../FrmManagePlugins.cpp" line="256"/>
292-
<source>Path</source>
293-
<translation>路徑</translation>
292+
<source>File</source>
293+
<translation>文件</translation>
294294
</message>
295295
<message>
296296
<location filename="../../FrmManagePlugins.cpp" line="184"/>
@@ -385,23 +385,23 @@ Some features are limited.
385385
<translation>總是顯示</translation>
386386
</message>
387387
<message>
388-
<location filename="../../Manager.cpp" line="208"/>
388+
<location filename="../../Manager.cpp" line="217"/>
389389
<source>Plugins</source>
390390
<translation>插件</translation>
391391
</message>
392392
<message>
393-
<location filename="../../Manager.cpp" line="303"/>
394-
<location filename="../../Manager.cpp" line="564"/>
393+
<location filename="../../Manager.cpp" line="315"/>
394+
<location filename="../../Manager.cpp" line="576"/>
395395
<source>Version:</source>
396396
<translation>版本:</translation>
397397
</message>
398398
<message>
399-
<location filename="../../Manager.cpp" line="506"/>
399+
<location filename="../../Manager.cpp" line="518"/>
400400
<source>Terminal</source>
401401
<translation>終端</translation>
402402
</message>
403403
<message>
404-
<location filename="../../Manager.cpp" line="569"/>
404+
<location filename="../../Manager.cpp" line="581"/>
405405
<source>Dependency libraries:</source>
406406
<translation>依賴庫:</translation>
407407
</message>
@@ -754,7 +754,7 @@ Some features are limited.
754754
<translation>允許使用系統用戶作為用戶</translation>
755755
</message>
756756
<message>
757-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="280"/>
757+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="286"/>
758758
<source>Store password with system credential manager</source>
759759
<translation>使用系統憑據管理器存儲密碼</translation>
760760
</message>
@@ -826,17 +826,17 @@ Some features are limited.
826826
<translation>加密密鑰:</translation>
827827
</message>
828828
<message>
829-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="224"/>
829+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="230"/>
830830
<source>Prompt type:</source>
831831
<translation>提示類型</translation>
832832
</message>
833833
<message>
834-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="237"/>
834+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="243"/>
835835
<source>No</source>
836836
<translation>不</translation>
837837
</message>
838838
<message>
839-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="250"/>
839+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="256"/>
840840
<source>First</source>
841841
<translation>第一次</translation>
842842
</message>
@@ -846,12 +846,12 @@ Some features are limited.
846846
<translation>密碼</translation>
847847
</message>
848848
<message>
849-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="264"/>
849+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="270"/>
850850
<source>Enable save password</source>
851851
<translation>允許保存密碼</translation>
852852
</message>
853853
<message>
854-
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="271"/>
854+
<location filename="../../ParameterCompone/ParameterPluginUI.ui" line="277"/>
855855
<location filename="../../ParameterCompone/ParameterPluginUI.cpp" line="24"/>
856856
<source>Enable view password</source>
857857
<translation>允許查看密碼</translation>

share/applications/io.github.KangLin.RabbitRemoteControl.Service.Configure.desktop.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
1+
# https://specifications.freedesktop.org/menu-spec/latest/index.html
22

3+
# https://specifications.freedesktop.org/desktop-entry-spec/latest/
4+
# https://specifications.freedesktop.org/desktop-entry-spec/latest/recognized-keys.html
35
[Desktop Entry]
46
Type=Application
57
Icon=@APP_ID@

share/applications/io.github.KangLin.RabbitRemoteControl.desktop.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ StartupNotify=true
2828
StartupWMClass=RabbitRemoteControl
2929

3030
X-Flatpak=@APP_ID@
31+
#X-Flatpak-Sandbox=true # 标识应用在沙箱中运行
32+
#X-Flatpak-Permissions=--socket=wayland --share=network
3133

3234
# https://specifications.freedesktop.org/menu-spec/latest/apa.html
3335
Categories=Network;Utility;P2P;Qt;RemoteAccess;AudioVideo;Video;Audio;Player

0 commit comments

Comments
 (0)