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
Multimedia
Elisa
Commits
50cae23c
Commit
50cae23c
authored
May 25, 2020
by
Matthieu Gallien
🎵
Browse files
allow to recursively enqueue content in Files browser
uses KIO::listRecursive
parent
c3dfad3e
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/models/filebrowsermodel.cpp
View file @
50cae23c
...
...
@@ -135,6 +135,12 @@ QVariant FileBrowserModel::data(const QModelIndex &index, int role) const
}
break
;
}
case
DataTypes
::
ColumnsRoles
::
FilePathRole
:
{
KFileItem
item
=
itemForIndex
(
index
);
result
=
item
.
url
();
break
;
}
default:
result
=
KDirModel
::
data
(
index
,
role
);
}
...
...
src/models/filebrowserproxymodel.cpp
View file @
50cae23c
...
...
@@ -9,18 +9,19 @@
#include "filebrowsermodel.h"
#include "mediaplaylistproxymodel.h"
#include "elisautils.h"
#include <QReadLocker>
#include <QDir>
#include <QtConcurrent>
#include "models/modelLogging.h"
#include <KIOWidgets/KDirLister>
#include "elisautils.h"
#include <KIO/ListJob>
#include <KIO/UDSEntry>
#include <KCoreAddons/KJob>
#include <stack>
FileBrowserProxyModel
::
FileBrowserProxyModel
(
QObject
*
parent
)
:
KDirSortFilterProxyModel
(
parent
)
{
setFilterCaseSensitivity
(
Qt
::
CaseInsensitive
);
mThreadPool
.
setMaxThreadCount
(
1
);
setSortFoldersFirst
(
true
);
sort
(
Qt
::
AscendingOrder
);
}
...
...
@@ -34,8 +35,6 @@ QString FileBrowserProxyModel::filterText() const
void
FileBrowserProxyModel
::
setFilterText
(
const
QString
&
filterText
)
{
QWriteLocker
writeLocker
(
&
mDataLock
);
if
(
mFilterText
==
filterText
)
return
;
...
...
@@ -45,54 +44,64 @@ void FileBrowserProxyModel::setFilterText(const QString &filterText)
mFilterExpression
.
setPatternOptions
(
QRegularExpression
::
CaseInsensitiveOption
);
mFilterExpression
.
optimize
();
invalidate
();
setFilterRegularExpression
(
mFilterExpression
);
setFilterRole
(
Qt
::
DisplayRole
);
Q_EMIT
filterTextChanged
(
mFilterText
);
}
bool
FileBrowserProxyModel
::
filterAcceptsRow
(
int
source_row
,
const
QModelIndex
&
source_parent
)
const
void
FileBrowserProxyModel
::
genericEnqueueToPlayList
(
QModelIndex
rootIndex
,
ElisaUtils
::
PlayListEnqueueMode
enqueueMode
,
ElisaUtils
::
PlayListEnqueueTriggerPlay
triggerPlay
)
{
bool
result
=
fals
e
;
bool
firstTime
=
tru
e
;
for
(
int
column
=
0
,
columnCount
=
sourceModel
()
->
columnCount
(
source_parent
);
column
<
columnCount
;
++
column
)
{
auto
currentIndex
=
sourceModel
()
->
index
(
source_row
,
column
,
source_parent
);
for
(
int
rowIndex
=
0
,
maxRowCount
=
rowCount
();
rowIndex
<
maxRowCount
;
++
rowIndex
)
{
auto
currentIndex
=
index
(
rowIndex
,
0
,
rootIndex
);
const
auto
rootUrl
=
data
(
currentIndex
,
DataTypes
::
FilePathRole
).
toUrl
();
const
auto
&
nameValue
=
sourceModel
()
->
data
(
currentIndex
,
Qt
::
DisplayRole
).
toString
(
);
auto
*
job
=
KIO
::
listRecursive
(
rootUrl
,
{
KIO
::
HideProgressInfo
}
);
if
(
mFilterExpression
.
match
(
nameValue
).
hasMatch
())
{
result
=
true
;
continue
;
}
connect
(
job
,
&
KJob
::
result
,
this
,
[](
KJob
*
)
{
});
if
(
result
)
{
continue
;
}
connect
(
job
,
&
KIO
::
ListJob
::
entries
,
this
,
[
rootUrl
,
this
,
&
enqueueMode
,
&
triggerPlay
,
&
firstTime
](
KIO
::
Job
*
job
,
const
KIO
::
UDSEntryList
&
list
)
{
Q_UNUSED
(
job
)
if
(
!
result
)
{
break
;
}
}
auto
allData
=
DataTypes
::
EntryDataList
{};
return
result
;
}
for
(
const
auto
&
oneEntry
:
list
)
{
if
(
oneEntry
.
isDir
())
{
continue
;
}
void
FileBrowserProxyModel
::
genericEnqueueToPlayList
(
QModelIndex
rootIndex
,
ElisaUtils
::
PlayListEnqueueMode
enqueueMode
,
ElisaUtils
::
PlayListEnqueueTriggerPlay
triggerPlay
)
{
QtConcurrent
::
run
(
&
mThreadPool
,
[
=
]
()
{
QReadLocker
locker
(
&
mDataLock
);
auto
allData
=
DataTypes
::
EntryDataList
{};
for
(
int
rowIndex
=
0
,
maxRowCount
=
rowCount
();
rowIndex
<
maxRowCount
;
++
rowIndex
)
{
auto
currentIndex
=
index
(
rowIndex
,
0
,
rootIndex
);
if
(
!
data
(
currentIndex
,
DataTypes
::
IsDirectoryRole
).
toBool
())
{
allData
.
push_back
(
DataTypes
::
EntryData
{
data
(
currentIndex
,
DataTypes
::
FullDataRole
).
value
<
DataTypes
::
MusicDataType
>
(),
data
(
currentIndex
,
Qt
::
DisplayRole
).
toString
(),
data
(
currentIndex
,
DataTypes
::
ResourceRole
).
toUrl
()});
auto
returnedPath
=
oneEntry
.
stringValue
(
KIO
::
UDSEntry
::
UDS_NAME
);
auto
fullPath
=
QStringLiteral
(
"%0/%1"
).
arg
(
rootUrl
.
toString
(),
returnedPath
);
auto
fullPathUrl
=
QUrl
{
fullPath
};
auto
mimeType
=
mMimeDatabase
.
mimeTypeForUrl
(
fullPathUrl
);
if
(
!
mimeType
.
name
().
startsWith
(
QLatin1String
(
"audio/"
)))
{
continue
;
}
allData
.
push_back
(
DataTypes
::
EntryData
{{{
DataTypes
::
ElementTypeRole
,
ElisaUtils
::
FileName
}},
fullPath
,
fullPathUrl
});
}
}
Q_EMIT
entriesToEnqueue
(
allData
,
enqueueMode
,
triggerPlay
);
});
if
(
!
firstTime
)
{
enqueueMode
=
ElisaUtils
::
PlayListEnqueueMode
::
AppendPlayList
;
triggerPlay
=
ElisaUtils
::
PlayListEnqueueTriggerPlay
::
DoNotTriggerPlay
;
}
if
(
!
allData
.
isEmpty
())
{
Q_EMIT
entriesToEnqueue
(
allData
,
enqueueMode
,
triggerPlay
);
firstTime
=
false
;
}
});
}
}
void
FileBrowserProxyModel
::
enqueueToPlayList
(
QModelIndex
rootIndex
)
...
...
src/models/filebrowserproxymodel.h
View file @
50cae23c
...
...
@@ -15,9 +15,8 @@
#include <KDirSortFilterProxyModel>
#include <QMimeDatabase>
#include <QRegularExpression>
#include <QReadWriteLock>
#include <QThreadPool>
#include <memory>
...
...
@@ -89,8 +88,6 @@ Q_SIGNALS:
protected:
bool
filterAcceptsRow
(
int
source_row
,
const
QModelIndex
&
source_parent
)
const
override
;
private:
void
genericEnqueueToPlayList
(
QModelIndex
rootIndex
,
...
...
@@ -105,14 +102,12 @@ private:
QRegularExpression
mFilterExpression
;
QReadWriteLock
mDataLock
;
QThreadPool
mThreadPool
;
MediaPlayListProxyModel
*
mPlayList
=
nullptr
;
bool
mFilterRating
=
false
;
QMimeDatabase
mMimeDatabase
;
};
#endif // FILEBROWSERPROXYMODEL_H
Write
Preview
Supports
Markdown
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