Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
f6e552e5
Commit
f6e552e5
authored
Apr 16, 2015
by
Hugo Beauzée-Luyssen
Browse files
Folders: Add a folders() method, to list subfolders
parent
c0f81606
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/IFolder.h
View file @
f6e552e5
...
...
@@ -12,5 +12,6 @@ public:
virtual
const
std
::
string
&
path
()
=
0
;
// This will only returns the files in this immediate folder
virtual
std
::
vector
<
FilePtr
>
files
()
=
0
;
virtual
std
::
vector
<
FolderPtr
>
folders
()
=
0
;
virtual
FolderPtr
parent
()
=
0
;
};
src/Folder.cpp
View file @
f6e552e5
...
...
@@ -76,6 +76,13 @@ std::vector<FilePtr> Folder::files()
return
sqlite
::
Tools
::
fetchAll
<
File
,
IFile
>
(
m_dbConection
,
req
,
m_id
);
}
std
::
vector
<
FolderPtr
>
Folder
::
folders
()
{
static
const
std
::
string
req
=
"SELECT * FROM "
+
policy
::
FolderTable
::
Name
+
" WHERE id_parent = ?"
;
return
sqlite
::
Tools
::
fetchAll
<
Folder
,
IFolder
>
(
m_dbConection
,
req
,
m_id
);
}
FolderPtr
Folder
::
parent
()
{
//FIXME: use path to be able to fetch from cache?
...
...
src/Folder.h
View file @
f6e552e5
...
...
@@ -39,6 +39,7 @@ public:
virtual
unsigned
int
id
()
const
override
;
virtual
const
std
::
string
&
path
()
override
;
virtual
std
::
vector
<
FilePtr
>
files
()
override
;
virtual
std
::
vector
<
FolderPtr
>
folders
()
override
;
virtual
FolderPtr
parent
()
override
;
private:
...
...
test/Folders.cpp
View file @
f6e552e5
...
...
@@ -197,3 +197,31 @@ TEST_F( Folders, AbsolutePath )
auto
f
=
ml
->
addFolder
(
"."
);
ASSERT_NE
(
f
->
path
(),
"."
);
}
TEST_F
(
Folders
,
ListFolders
)
{
auto
f
=
ml
->
addFolder
(
"."
);
auto
subFolders
=
f
->
folders
();
ASSERT_EQ
(
1u
,
subFolders
.
size
()
);
auto
subFolder
=
subFolders
[
0
];
auto
subFiles
=
subFolder
->
files
();
ASSERT_EQ
(
1u
,
subFiles
.
size
()
);
auto
file
=
subFiles
[
0
];
ASSERT_EQ
(
std
::
string
{
mock
::
FileSystemFactory
::
SubFolder
}
+
"subfile.mp4"
,
file
->
mrl
()
);
// Now again, without cache
SetUp
();
f
=
ml
->
folder
(
f
->
path
()
);
subFolders
=
f
->
folders
();
ASSERT_EQ
(
1u
,
subFolders
.
size
()
);
subFolder
=
subFolders
[
0
];
subFiles
=
subFolder
->
files
();
ASSERT_EQ
(
1u
,
subFiles
.
size
()
);
file
=
subFiles
[
0
];
ASSERT_EQ
(
std
::
string
{
mock
::
FileSystemFactory
::
SubFolder
}
+
"subfile.mp4"
,
file
->
mrl
()
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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