Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Discover
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Plasma
Discover
Commits
10fab95e
Commit
10fab95e
authored
Jan 12, 2018
by
Aleix Pol Gonzalez
🐧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
List backends without sources in the Sources page
BUG: 388751
parent
d3724cd8
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
162 additions
and
159 deletions
+162
-159
discover/qml/SourcesPage.qml
discover/qml/SourcesPage.qml
+92
-77
libdiscover/ActionsModel.cpp
libdiscover/ActionsModel.cpp
+2
-2
libdiscover/ActionsModel.h
libdiscover/ActionsModel.h
+5
-5
libdiscover/CMakeLists.txt
libdiscover/CMakeLists.txt
+1
-0
libdiscover/backends/DummyBackend/DummySourcesBackend.cpp
libdiscover/backends/DummyBackend/DummySourcesBackend.cpp
+3
-6
libdiscover/backends/DummyBackend/DummySourcesBackend.h
libdiscover/backends/DummyBackend/DummySourcesBackend.h
+0
-1
libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp
...iscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp
+0
-1
libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h
libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h
+0
-1
libdiscover/backends/PackageKitBackend/PackageKitSourcesBackend.cpp
...r/backends/PackageKitBackend/PackageKitSourcesBackend.cpp
+0
-7
libdiscover/backends/PackageKitBackend/PackageKitSourcesBackend.h
...ver/backends/PackageKitBackend/PackageKitSourcesBackend.h
+0
-1
libdiscover/resources/AbstractResourcesBackend.h
libdiscover/resources/AbstractResourcesBackend.h
+1
-0
libdiscover/resources/AbstractSourcesBackend.h
libdiscover/resources/AbstractSourcesBackend.h
+1
-4
libdiscover/resources/SourcesModel.cpp
libdiscover/resources/SourcesModel.cpp
+48
-38
libdiscover/resources/SourcesModel.h
libdiscover/resources/SourcesModel.h
+9
-16
No files found.
discover/qml/SourcesPage.qml
View file @
10fab95e
...
...
@@ -14,24 +14,6 @@ DiscoverPage {
title
:
i18n
(
"
Settings
"
)
property
string
search
:
""
readonly
property
var
fu
:
Instantiator
{
model
:
SourcesModel
delegate
:
QtObject
{
readonly
property
var
sourcesModel
:
sourceBackend
.
sources
readonly
property
var
a
:
Connections
{
target
:
sourceBackend
onPassiveMessage
:
window
.
showPassiveNotification
(
message
)
}
}
onObjectAdded
:
{
everySourceModel
.
addSourceModel
(
object
.
sourcesModel
)
}
onObjectRemoved
:
{
everySourceModel
.
removeSourceModel
(
object
.
sourcesModel
)
}
}
header
:
QQC2.ToolBar
{
anchors
{
right
:
parent
.
right
...
...
@@ -66,15 +48,17 @@ DiscoverPage {
id
:
sourcesView
model
:
QSortFilterProxyModel
{
filterRegExp
:
new
RegExp
(
page
.
search
,
'
i
'
)
sourceModel
:
KConcatenateRowsProxyModel
{
id
:
everySourceModel
}
sourceModel
:
SourcesModel
}
currentIndex
:
-
1
section
{
property
:
"
statusTip
"
delegate
:
RowLayout
{
Component
{
id
:
sourceBackendDelegate
RowLayout
{
id
:
backendItem
readonly
property
QtObject
backend
:
sourcesBackend
readonly
property
bool
isDefault
:
ResourcesModel
.
currentApplicationBackend
==
resourcesBackend
anchors
{
right
:
parent
.
right
left
:
parent
.
left
...
...
@@ -82,32 +66,44 @@ DiscoverPage {
Kirigami.Heading
{
Layout.fillWidth
:
true
leftPadding
:
Kirigami
.
Units
.
largeSpacing
text
:
settingsButton
.
isDefault
?
i18n
(
"
%1 (Default)
"
,
section
)
:
section
text
:
backendItem
.
isDefault
?
i18n
(
"
%1 (Default)
"
,
resourcesBackend
.
displayName
)
:
resourcesBackend
.
displayName
}
Button
{
id
:
settingsButton
Layout.rightMargin
:
Kirigami
.
Units
.
smallSpacing
iconName
:
"
preferences-other
"
readonly
property
QtObject
backend
:
SourcesModel
.
backendForSection
(
section
)
readonly
property
bool
isDefault
:
ResourcesModel
.
currentApplicationBackend
==
settingsButton
.
backend
.
resourcesBackend
visible
:
backend
AddSourceDialog
{
id
:
addSourceDialog
source
:
settingsButton
.
backend
Connections
{
target
:
backend
onPassiveMessage
:
window
.
showPassiveNotification
(
message
)
}
visible
:
resourcesBackend
&&
resourcesBackend
.
hasApplications
Component
{
id
:
dialogComponent
AddSourceDialog
{
source
:
backendItem
.
backend
onVisibleChanged
:
if
(
!
visible
)
{
destroy
()
}
}
}
menu
:
Menu
{
id
:
settingsMenu
MenuItem
{
enabled
:
!
settingsButton
.
isDefault
enabled
:
!
backendItem
.
isDefault
text
:
i18n
(
"
Make default
"
)
onTriggered
:
ResourcesModel
.
currentApplicationBackend
=
settingsButton
.
backend
.
resourcesBackend
onTriggered
:
ResourcesModel
.
currentApplicationBackend
=
backendItem
.
backend
.
resourcesBackend
}
MenuItem
{
text
:
i18n
(
"
Add Source
"
)
visible
:
backendItem
.
backend
onTriggered
:
addSourceDialog
.
open
()
onTriggered
:
{
var
addSourceDialog
=
dialogComponent
.
createObject
()
addSourceDialog
.
open
()
}
}
MenuSeparator
{
...
...
@@ -117,10 +113,10 @@ DiscoverPage {
Instantiator
{
id
:
backendActionsInst
model
:
ActionsModel
{
actions
:
settingsButton
.
backend
?
settingsButton
.
backend
.
actions
:
null
actions
:
backendItem
.
backend
?
backendItem
.
backend
.
actions
:
undefined
}
delegate
:
MenuItem
{
action
:
ActionBridge
{
action
:
model
.
action
}
action
:
ActionBridge
{
action
:
action
}
}
onObjectAdded
:
{
settingsMenu
.
insertItem
(
index
,
object
)
...
...
@@ -134,49 +130,68 @@ DiscoverPage {
}
}
delegate
:
Kirigami.SwipeListItem
{
Layout.fillWidth
:
true
enabled
:
display
.
length
>
0
highlighted
:
ListView
.
isCurrentItem
onClicked
:
Navigation
.
openApplicationListSource
(
model
.
display
)
readonly
property
string
backendName
:
model
.
statusTip
readonly
property
variant
modelIndex
:
sourcesView
.
model
.
index
(
model
.
index
,
0
)
Keys.onReturnPressed
:
clicked
()
actions
:
[
Kirigami.Action
{
enabled
:
display
.
length
>
0
iconName
:
"
view-filter
"
tooltip
:
i18n
(
"
Browse the origin's resources
"
)
onTriggered
:
Navigation
.
openApplicationListSource
(
model
.
display
)
},
Kirigami.Action
{
iconName
:
"
edit-delete
"
tooltip
:
i18n
(
"
Delete the origin
"
)
onTriggered
:
{
var
backend
=
sourcesView
.
model
.
data
(
modelIndex
,
AbstractSourcesBackend
.
SourcesBackend
)
if
(
!
backend
.
removeSource
(
model
.
display
))
{
window
.
showPassiveNotification
(
i18n
(
"
Failed to remove the source '%1'
"
,
model
.
display
))
delegate
:
ConditionalLoader
{
anchors
{
right
:
parent
.
right
left
:
parent
.
left
}
readonly
property
variant
resourcesBackend
:
model
.
resourcesBackend
readonly
property
variant
sourcesBackend
:
model
.
sourcesBackend
readonly
property
variant
display
:
model
.
display
readonly
property
variant
checked
:
model
.
checked
readonly
property
variant
statusTip
:
model
.
statusTip
readonly
property
variant
toolTip
:
model
.
toolTip
readonly
property
variant
modelIndex
:
sourcesView
.
model
.
index
(
index
,
0
)
condition
:
resourcesBackend
!=
null
componentTrue
:
sourceBackendDelegate
componentFalse
:
sourceDelegate
}
Component
{
id
:
sourceDelegate
Kirigami.SwipeListItem
{
Layout.fillWidth
:
true
enabled
:
display
.
length
>
0
highlighted
:
ListView
.
isCurrentItem
onClicked
:
Navigation
.
openApplicationListSource
(
display
)
Keys.onReturnPressed
:
clicked
()
actions
:
[
Kirigami.Action
{
enabled
:
display
.
length
>
0
iconName
:
"
view-filter
"
tooltip
:
i18n
(
"
Browse the origin's resources
"
)
onTriggered
:
Navigation
.
openApplicationListSource
(
display
)
},
Kirigami.Action
{
iconName
:
"
edit-delete
"
tooltip
:
i18n
(
"
Delete the origin
"
)
onTriggered
:
{
var
backend
=
sb
if
(
!
backend
.
removeSource
(
display
))
{
window
.
showPassiveNotification
(
i18n
(
"
Failed to remove the source '%1'
"
,
display
))
}
}
}
}
]
]
RowLayout
{
CheckBox
{
id
:
enabledBox
readonly
property
variant
modelChecked
:
sourcesView
.
model
.
data
(
modelIndex
,
Qt
.
CheckStateRole
)
checked
:
modelChecked
!=
Qt
.
Unchecked
enabled
:
modelChecked
!==
undefined
onClicked
:
{
model
.
checked
=
checkedState
RowLayout
{
CheckBox
{
id
:
enabledBox
readonly
property
variant
modelChecked
:
sourcesView
.
model
.
data
(
modelIndex
,
Qt
.
CheckStateRole
)
checked
:
modelChecked
!=
Qt
.
Unchecked
enabled
:
modelChecked
!==
undefined
onClicked
:
{
sourcesView
.
model
.
setData
(
modelIndex
,
checkedState
,
Qt
.
CheckStateRole
)
}
}
QQC2.Label
{
text
:
display
+
"
- <i>
"
+
toolTip
+
"
</i>
"
elide
:
Text
.
ElideRight
Layout.fillWidth
:
true
}
}
QQC2.Label
{
text
:
model
.
display
+
"
- <i>
"
+
model
.
toolTip
+
"
</i>
"
elide
:
Text
.
ElideRight
Layout.fillWidth
:
true
}
}
}
...
...
@@ -200,7 +215,7 @@ DiscoverPage {
text
:
name
}
InstallApplicationButton
{
application
:
model
.
application
application
:
application
}
}
}
...
...
libdiscover/ActionsModel.cpp
View file @
10fab95e
...
...
@@ -48,7 +48,7 @@ int ActionsModel::rowCount(const QModelIndex& parent) const
return
parent
.
isValid
()
?
0
:
m_filteredActions
.
count
();
}
void
ActionsModel
::
setActions
(
const
Q
List
<
QAction
*>
&
actions
)
void
ActionsModel
::
setActions
(
const
Q
Variant
&
actions
)
{
if
(
m_actions
==
actions
)
{
return
;
...
...
@@ -61,7 +61,7 @@ void ActionsModel::setActions(const QList<QAction*>& actions)
void
ActionsModel
::
reload
()
{
QList
<
QAction
*>
actions
=
m_actions
;
QList
<
QAction
*>
actions
=
m_actions
.
value
<
QList
<
QAction
*>>
()
;
if
(
m_priority
>=
0
)
{
actions
=
kFilter
<
QList
<
QAction
*>>
(
actions
,
[
this
](
QAction
*
action
){
return
action
->
priority
()
==
m_priority
;
});
}
...
...
libdiscover/ActionsModel.h
View file @
10fab95e
...
...
@@ -30,7 +30,7 @@ class QAction;
class
DISCOVERCOMMON_EXPORT
ActionsModel
:
public
QAbstractListModel
{
Q_OBJECT
Q_PROPERTY
(
Q
List
<
QAction
*>
actions
READ
actions
WRITE
setActions
NOTIFY
actionsChanged
)
Q_PROPERTY
(
Q
Variant
actions
READ
actions
WRITE
setActions
NOTIFY
actionsChanged
)
Q_PROPERTY
(
int
filterPriority
READ
filterPriority
WRITE
setFilterPriority
)
public:
explicit
ActionsModel
(
QObject
*
parent
=
nullptr
);
...
...
@@ -42,16 +42,16 @@ class DISCOVERCOMMON_EXPORT ActionsModel : public QAbstractListModel
void
setFilterPriority
(
int
p
);
int
filterPriority
()
const
;
void
setActions
(
const
Q
List
<
QAction
*>
&
actions
);
Q
List
<
QAction
*>
actions
()
const
{
return
m_actions
;
}
void
setActions
(
const
Q
Variant
&
actions
);
Q
Variant
actions
()
const
{
return
m_actions
;
}
Q_SIGNALS:
void
actionsChanged
(
const
Q
List
<
QAction
*>
&
actions
);
void
actionsChanged
(
const
Q
Variant
&
actions
);
private:
void
reload
();
Q
List
<
QAction
*>
m_actions
;
Q
Variant
m_actions
;
QList
<
QAction
*>
m_filteredActions
;
int
m_priority
;
};
...
...
libdiscover/CMakeLists.txt
View file @
10fab95e
...
...
@@ -51,6 +51,7 @@ LINK_PUBLIC
Qt5::Qml
Qt5::Widgets
KF5::I18n
KF5::ItemModels
LINK_PRIVATE
Qt5::Xml
Qt5::DBus
...
...
libdiscover/backends/DummyBackend/DummySourcesBackend.cpp
View file @
10fab95e
...
...
@@ -27,15 +27,11 @@ DummySourcesBackend::DummySourcesBackend(AbstractResourcesBackend * parent)
,
m_sources
(
new
QStandardItemModel
(
this
))
,
m_testAction
(
new
QAction
(
QIcon
::
fromTheme
(
QStringLiteral
(
"kalgebra"
)),
QStringLiteral
(
"DummyAction"
),
this
))
{
QHash
<
int
,
QByteArray
>
roles
=
m_sources
->
roleNames
();
roles
.
insert
(
AbstractSourcesBackend
::
SourcesBackend
,
"sourcesBackend"
);
roles
.
insert
(
Qt
::
CheckStateRole
,
"checked"
);
m_sources
->
setItemRoleNames
(
roles
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
addSource
(
QStringLiteral
(
"DummySource%1"
).
arg
(
i
));
connect
(
m_testAction
,
&
QAction
::
triggered
,
[](){
qDebug
()
<<
"action triggered!"
;
});
connect
(
m_sources
,
&
QStandardItemModel
::
itemChanged
,
this
,
[](
QStandardItem
*
item
)
{
qDebug
()
<<
"DummySource changed"
<<
item
<<
item
->
checkState
();
});
}
QAbstractItemModel
*
DummySourcesBackend
::
sources
()
...
...
@@ -47,8 +43,9 @@ bool DummySourcesBackend::addSource(const QString& id)
{
QStandardItem
*
it
=
new
QStandardItem
(
id
);
it
->
setData
(
QVariant
(
id
+
QLatin1Char
(
' '
)
+
id
),
Qt
::
ToolTipRole
);
it
->
setData
(
name
(),
AbstractSourcesBackend
::
SectionRole
);
it
->
setData
(
QVariant
::
fromValue
<
QObject
*>
(
this
),
AbstractSourcesBackend
::
SourcesBackend
);
it
->
setCheckable
(
true
);
it
->
setCheckState
(
Qt
::
Checked
);
m_sources
->
appendRow
(
it
);
return
true
;
}
...
...
libdiscover/backends/DummyBackend/DummySourcesBackend.h
View file @
10fab95e
...
...
@@ -32,7 +32,6 @@ public:
QAbstractItemModel
*
sources
()
override
;
bool
addSource
(
const
QString
&
id
)
override
;
bool
removeSource
(
const
QString
&
id
)
override
;
QString
name
()
const
override
{
return
QStringLiteral
(
"Dummy"
);
}
QString
idDescription
()
override
{
return
QStringLiteral
(
"Random weird text"
);
}
QList
<
QAction
*>
actions
()
const
override
;
...
...
libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.cpp
View file @
10fab95e
...
...
@@ -208,7 +208,6 @@ void FlatpakSourcesBackend::addRemote(FlatpakRemote *remote, FlatpakInstallation
FlatpakSourceItem
*
it
=
new
FlatpakSourceItem
(
id
);
it
->
setCheckState
(
flatpak_remote_get_disabled
(
remote
)
?
Qt
::
Unchecked
:
Qt
::
Checked
);
it
->
setData
(
title
.
isEmpty
()
?
id
:
title
,
Qt
::
ToolTipRole
);
it
->
setData
(
name
(),
AbstractSourcesBackend
::
SectionRole
);
it
->
setData
(
QVariant
::
fromValue
<
QObject
*>
(
this
),
AbstractSourcesBackend
::
SourcesBackend
);
it
->
setFlatpakInstallation
(
installation
);
...
...
libdiscover/backends/FlatpakBackend/FlatpakSourcesBackend.h
View file @
10fab95e
...
...
@@ -38,7 +38,6 @@ public:
QAbstractItemModel
*
sources
()
override
;
bool
addSource
(
const
QString
&
id
)
override
;
bool
removeSource
(
const
QString
&
id
)
override
;
QString
name
()
const
override
{
return
QStringLiteral
(
"Flatpak"
);
}
QString
idDescription
()
override
;
QList
<
QAction
*>
actions
()
const
override
;
...
...
libdiscover/backends/PackageKitBackend/PackageKitSourcesBackend.cpp
View file @
10fab95e
...
...
@@ -105,11 +105,6 @@ PackageKitSourcesBackend::PackageKitSourcesBackend(AbstractResourcesBackend* par
m_actions
+=
createActionForService
(
service
,
this
);
}
QString
PackageKitSourcesBackend
::
name
()
const
{
return
resourcesBackend
()
->
displayName
();
}
QString
PackageKitSourcesBackend
::
idDescription
()
{
return
i18n
(
"Repository URL:"
);
...
...
@@ -134,8 +129,6 @@ void PackageKitSourcesBackend::addRepositoryDetails(const QString &id, const QSt
item
=
new
QStandardItem
(
id
);
add
=
true
;
}
item
->
setData
(
description
,
Qt
::
ToolTipRole
);
item
->
setData
(
name
(),
AbstractSourcesBackend
::
SectionRole
);
item
->
setCheckState
(
enabled
?
Qt
::
Checked
:
Qt
::
Unchecked
);
if
(
add
)
...
...
libdiscover/backends/PackageKitBackend/PackageKitSourcesBackend.h
View file @
10fab95e
...
...
@@ -33,7 +33,6 @@ class PackageKitSourcesBackend : public AbstractSourcesBackend
public:
PackageKitSourcesBackend
(
AbstractResourcesBackend
*
parent
);
QString
name
()
const
override
;
QString
idDescription
()
override
;
bool
addSource
(
const
QString
&
id
)
override
;
...
...
libdiscover/resources/AbstractResourcesBackend.h
View file @
10fab95e
...
...
@@ -77,6 +77,7 @@ class DISCOVERCOMMON_EXPORT AbstractResourcesBackend : public QObject
Q_PROPERTY
(
int
updatesCount
READ
updatesCount
NOTIFY
updatesCountChanged
)
Q_PROPERTY
(
bool
hasSecurityUpdates
READ
hasSecurityUpdates
NOTIFY
updatesCountChanged
)
Q_PROPERTY
(
bool
isFetching
READ
isFetching
NOTIFY
fetchingChanged
)
Q_PROPERTY
(
bool
hasApplications
READ
hasApplications
CONSTANT
)
public:
/**
* Constructs an AbstractResourcesBackend
...
...
libdiscover/resources/AbstractSourcesBackend.h
View file @
10fab95e
...
...
@@ -33,7 +33,6 @@ class DISCOVERCOMMON_EXPORT AbstractSourcesBackend : public QObject
Q_OBJECT
Q_PROPERTY
(
AbstractResourcesBackend
*
resourcesBackend
READ
resourcesBackend
CONSTANT
)
Q_PROPERTY
(
QAbstractItemModel
*
sources
READ
sources
CONSTANT
)
Q_PROPERTY
(
QString
name
READ
name
CONSTANT
)
Q_PROPERTY
(
QString
idDescription
READ
idDescription
CONSTANT
)
Q_PROPERTY
(
QList
<
QAction
*>
actions
READ
actions
CONSTANT
)
public:
...
...
@@ -41,12 +40,10 @@ class DISCOVERCOMMON_EXPORT AbstractSourcesBackend : public QObject
~
AbstractSourcesBackend
()
override
;
enum
Roles
{
SectionRole
=
Qt
::
StatusTipRole
,
SourcesBackend
SourcesBackend
=
Qt
::
UserRole
};
Q_ENUM
(
Roles
)
virtual
QString
name
()
const
=
0
;
virtual
QString
idDescription
()
=
0
;
Q_SCRIPTABLE
virtual
bool
addSource
(
const
QString
&
id
)
=
0
;
...
...
libdiscover/resources/SourcesModel.cpp
View file @
10fab95e
...
...
@@ -22,30 +22,58 @@
#include <QtGlobal>
#include <QDebug>
#include <QAction>
#include "resources/AbstractResourcesBackend.h"
#include "resources/AbstractSourcesBackend.h"
Q_GLOBAL_STATIC
(
SourcesModel
,
s_sources
)
class
SourceBackendModel
:
public
QAbstractListModel
{
Q_OBJECT
public:
SourceBackendModel
(
AbstractResourcesBackend
*
backend
,
QObject
*
parent
)
:
QAbstractListModel
(
parent
),
m_backend
(
backend
)
{}
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
override
{
if
(
!
index
.
isValid
())
return
{};
switch
(
role
)
{
case
SourcesModel
::
ResourcesBackend
:
return
QVariant
::
fromValue
<
QObject
*>
(
m_backend
);
case
SourcesModel
::
SourcesBackend
:
return
QVariant
::
fromValue
<
QObject
*>
(
m_sources
);
}
return
{};
}
int
rowCount
(
const
QModelIndex
&
parent
)
const
override
{
return
parent
.
isValid
()
?
0
:
1
;
}
AbstractSourcesBackend
*
m_sources
=
nullptr
;
private:
AbstractResourcesBackend
*
m_backend
;
};
SourcesModel
::
SourcesModel
(
QObject
*
parent
)
:
QAbstractList
Model
(
parent
)
:
KConcatenateRowsProxy
Model
(
parent
)
{}
SourcesModel
::~
SourcesModel
()
=
default
;
QHash
<
int
,
QByteArray
>
SourcesModel
::
roleNames
()
const
SourcesModel
*
SourcesModel
::
global
()
{
return
{
{
SourceBackend
,
"sourceBackend"
}
}
;
return
s_sources
;
}
SourcesModel
*
SourcesModel
::
global
()
QHash
<
int
,
QByteArray
>
SourcesModel
::
roleNames
()
const
{
return
s_sources
;
QHash
<
int
,
QByteArray
>
roles
=
KConcatenateRowsProxyModel
::
roleNames
();
roles
.
insert
(
SourcesBackend
,
"sourcesBackend"
);
roles
.
insert
(
ResourcesBackend
,
"resourcesBackend"
);
return
roles
;
}
static
bool
ensureModel
(
const
QList
<
QByteArray
>
&
roles
)
{
static
QList
<
QByteArray
>
required
=
{
"sourcesBackend"
,
"display"
,
"checked"
};
for
(
const
auto
&
role
:
r
oles
)
{
static
auto
required
=
{
"display"
,
"checked"
};
for
(
const
auto
&
role
:
r
equired
)
{
if
(
!
roles
.
contains
(
role
))
return
false
;
}
...
...
@@ -54,43 +82,25 @@ static bool ensureModel(const QList<QByteArray> &roles)
void
SourcesModel
::
addSourcesBackend
(
AbstractSourcesBackend
*
sources
)
{
if
(
m_sources
.
contains
(
sources
))
auto
b
=
addBackend
(
qobject_cast
<
AbstractResourcesBackend
*>
(
sources
->
parent
()));
if
(
!
b
)
return
;
b
->
m_sources
=
sources
;
Q_ASSERT
(
ensureModel
(
sources
->
sources
()
->
roleNames
().
values
()));
beginInsertRows
(
QModelIndex
(),
m_sources
.
size
(),
m_sources
.
size
());
m_sources
+=
sources
;
endInsertRows
();
emit
sourcesChanged
();
addSourceModel
(
sources
->
sources
());
}
QVariant
SourcesModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
SourceBackendModel
*
SourcesModel
::
addBackend
(
AbstractResourcesBackend
*
backend
)
{
if
(
!
index
.
isValid
()
||
index
.
row
()
>=
m_sources
.
count
())
{
return
QVariant
();
}
switch
(
role
)
{
case
SourceBackend
:
return
QVariant
::
fromValue
<
QObject
*>
(
m_sources
[
index
.
row
()]);
}
Q_ASSERT
(
backend
);
if
(
backend
->
dynamicPropertyNames
().
contains
(
"InSourcesModel"
))
return
nullptr
;
backend
->
setProperty
(
"InSourcesModel"
,
1
);
return
QVariant
();
auto
b
=
new
SourceBackendModel
(
backend
,
this
);
addSourceModel
(
b
);
return
b
;
}
int
SourcesModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
return
parent
.
isValid
()
?
0
:
m_sources
.
count
();
}
QObject
*
SourcesModel
::
backendForSection
(
const
QString
&
status
)
const
{
AbstractSourcesBackend
*
ret
=
nullptr
;
for
(
AbstractSourcesBackend
*
b
:
m_sources
)
{
if
(
b
->
name
()
==
status
)
{
ret
=
b
;
break
;
}
}
return
ret
;
}
#include "SourcesModel.moc"
libdiscover/resources/SourcesModel.h
View file @
10fab95e
...
...
@@ -23,37 +23,30 @@
#include <QAbstractListModel>
#include <QSet>
#include <
QtQml/QQmlListProperty
>
#include <
KConcatenateRowsProxyModel
>
#include "discovercommon_export.h"
class
QAction
;
class
AbstractSourcesBackend
;
class
DISCOVERCOMMON_EXPORT
SourcesModel
:
public
QAbstractListModel
class
AbstractResourcesBackend
;
class
SourceBackendModel
;
class
DISCOVERCOMMON_EXPORT
SourcesModel
:
public
KConcatenateRowsProxyModel
{
Q_OBJECT
Q_PROPERTY
(
int
count
READ
rowCount
NOTIFY
sourcesChanged
)
public:
enum
Roles
{
SourceBackend
=
Qt
::
UserRole
+
1
SourcesBackend
=
Qt
::
UserRole
+
1
,
ResourcesBackend
};
explicit
SourcesModel
(
QObject
*
parent
=
nullptr
);
~
SourcesModel
()
override
;
static
SourcesModel
*
global
();
QVariant
data
(
const
QModelIndex
&
index
,
int
role
=
Qt
::
DisplayRole
)
const
override
;
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
override
;
void
addSourcesBackend
(
AbstractSourcesBackend
*
sources
);
QHash
<
int
,
QByteArray
>
roleNames
()
const
override
;
public
Q_SLOTS
:
QObject
*
backendForSection
(
const
QString
&
status
)
const
;
Q_SIGNALS:
void
sourcesChanged
();
private:
QList
<
AbstractSourcesBackend
*>
m_sources
;
SourceBackendModel
*
addBackend
(
AbstractResourcesBackend
*
backend
);
void
addSourcesBackend
(
AbstractSourcesBackend
*
sources
);
};
#endif // SOURCESMODEL_H
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