Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
Cantor
Commits
f58c723c
Commit
f58c723c
authored
Jul 31, 2020
by
Alexander Semke
Browse files
Avoided duplicated looping over the plugin pathes and some minor code
style fixes in the panel plugin handler.
parent
d6766567
Pipeline
#28955
passed with stage
in 26 minutes and 2 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/lib/panelplugin.cpp
View file @
f58c723c
...
...
@@ -28,15 +28,14 @@ class Cantor::PanelPluginPrivate
public:
QString
name
;
QStringList
requiredExtensions
;
Session
*
session
;
QWidget
*
parentWidget
;
Session
*
session
=
nullptr
;
QWidget
*
parentWidget
=
nullptr
;
};
PanelPlugin
::
PanelPlugin
(
QObject
*
parent
)
:
QObject
(
parent
),
/* KXMLGUIClient(dynamic_cast<KXMLGUIClient*>(parent)),*/
d
(
new
PanelPluginPrivate
)
{
d
->
parentWidget
=
nullptr
;
d
->
session
=
nullptr
;
}
PanelPlugin
::~
PanelPlugin
()
...
...
@@ -46,7 +45,7 @@ PanelPlugin::~PanelPlugin()
void
PanelPlugin
::
setParentWidget
(
QWidget
*
widget
)
{
d
->
parentWidget
=
widget
;
d
->
parentWidget
=
widget
;
}
QWidget
*
PanelPlugin
::
parentWidget
()
...
...
@@ -56,8 +55,8 @@ QWidget* PanelPlugin::parentWidget()
void
PanelPlugin
::
setPluginInfo
(
const
KPluginMetaData
&
info
)
{
d
->
name
=
info
.
name
();
d
->
requiredExtensions
=
info
.
value
(
QStringLiteral
(
"RequiredExtensions"
)).
split
(
QLatin1Char
(
','
));
d
->
name
=
info
.
name
();
d
->
requiredExtensions
=
info
.
value
(
QStringLiteral
(
"RequiredExtensions"
)).
split
(
QLatin1Char
(
','
));
}
QStringList
PanelPlugin
::
requiredExtensions
()
...
...
@@ -87,7 +86,7 @@ void Cantor::PanelPlugin::restoreState(const Cantor::PanelPlugin::State& state)
d
->
session
=
state
.
session
;
}
Cantor
::
Session
*
Cantor
::
PanelPlugin
::
session
()
Cantor
::
Session
*
Cantor
::
PanelPlugin
::
session
()
{
return
d
->
session
;
}
...
...
src/lib/panelpluginhandler.cpp
View file @
f58c723c
...
...
@@ -23,12 +23,9 @@ using namespace Cantor;
#include <QDebug>
#include <QDir>
#include <KService>
#include <KServiceTypeTrader>
#include <KPluginMetaData>
#include "session.h"
#include "panelplugin.h"
#include "backend.h"
class
Cantor
::
PanelPluginHandlerPrivate
...
...
@@ -51,19 +48,15 @@ PanelPluginHandler::~PanelPluginHandler()
void
PanelPluginHandler
::
loadPlugins
()
{
QStringList
panelDirs
;
foreach
(
const
QString
&
dir
,
QCoreApplication
::
libraryPaths
())
{
panelDirs
<<
dir
+
QDir
::
separator
()
+
QLatin1String
(
"cantor/panels"
);
}
QPluginLoader
loader
;
foreach
(
const
QString
&
dir
,
panelDirs
){
for
(
const
QString
&
path
:
QCoreApplication
::
libraryPaths
())
{
const
QString
&
dir
=
path
+
QDir
::
separator
()
+
QLatin1String
(
"cantor/panels"
);
qDebug
()
<<
"dir: "
<<
dir
;
QStringList
panels
;
QDir
panelDir
=
QDir
(
dir
);
panels
=
panelDir
.
entryList
();
QPluginLoader
loader
;
const
QStringList
&
panels
=
panelDir
.
entryList
();
for
each
(
const
QString
&
panel
,
panels
)
for
(
const
QString
&
panel
:
panels
)
{
if
(
panel
==
QLatin1String
(
"."
)
||
panel
==
QLatin1String
(
".."
))
continue
;
...
...
@@ -80,11 +73,6 @@ void PanelPluginHandler::loadPlugins()
KPluginMetaData
info
(
loader
);
plugin
->
setPluginInfo
(
info
);
// This set session to null inside plugin
Cantor
::
PanelPlugin
::
State
emptyState
;
plugin
->
restoreState
(
emptyState
);
d
->
plugins
.
append
(
plugin
);
}
}
...
...
@@ -106,10 +94,10 @@ QList<PanelPlugin*> PanelPluginHandler::plugins(Session* session)
const
QStringList
&
extensions
=
session
->
backend
()
->
extensions
();
qDebug
()
<<
"loading panel plugins for session of type "
<<
session
->
backend
()
->
name
();
for
(
Cantor
::
PanelPlugin
*
plugin
:
d
->
plugins
)
for
(
auto
*
plugin
:
d
->
plugins
)
{
bool
supported
=
true
;
for
each
(
const
QString
&
req
,
plugin
->
requiredExtensions
()){
for
(
const
QString
&
req
:
plugin
->
requiredExtensions
()){
// FIXME: That req.isEmpty() is there just because Help Panel has req
// empty, returning FALSE when the comparison must to return TRUE.
supported
=
supported
&&
(
extensions
.
contains
(
req
)
||
req
.
isEmpty
());
...
...
@@ -132,9 +120,9 @@ QList<PanelPlugin*> PanelPluginHandler::plugins(Session* session)
QList
<
PanelPlugin
*>
PanelPluginHandler
::
activePluginsForSession
(
Session
*
session
,
const
PanelStates
&
previousPluginStates
)
{
QList
<
Cantor
::
PanelPlugin
*>
plugins
=
this
->
plugins
(
session
);
for
(
Cantor
::
PanelPlugin
*
plugin
:
plugins
)
for
(
auto
*
plugin
:
plugins
)
{
if
(
plugin
==
nullptr
)
if
(
!
plugin
)
{
qDebug
()
<<
"somethings wrong with plugin inside PanelPluginHandler"
;
continue
;
...
...
src/lib/panelpluginhandler.h
View file @
f58c723c
...
...
@@ -43,10 +43,10 @@ class CANTOR_EXPORT PanelPluginHandler : public QObject
~
PanelPluginHandler
()
override
;
QList
<
PanelPlugin
*>
allPlugins
();
QList
<
PanelPlugin
*>
plugins
(
Session
*
session
);
QList
<
PanelPlugin
*>
plugins
(
Session
*
);
using
PanelStates
=
QMap
<
QString
,
Cantor
::
PanelPlugin
::
State
>
;
QList
<
PanelPlugin
*>
activePluginsForSession
(
Session
*
session
,
const
PanelStates
&
previousPluginStates
);
QList
<
PanelPlugin
*>
activePluginsForSession
(
Session
*
,
const
PanelStates
&
);
void
loadPlugins
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment