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
57ea9939
Commit
57ea9939
authored
Sep 08, 2016
by
Hugo Beauzée-Luyssen
Browse files
IMediaLibrary: Allow history to be cleared
parent
b4169b56
Changes
9
Hide whitespace changes
Inline
Side-by-side
include/medialibrary/IMediaLibrary.h
View file @
57ea9939
...
...
@@ -192,6 +192,15 @@ class IMediaLibrary
virtual
bool
addToHistory
(
const
std
::
string
&
mrl
)
=
0
;
virtual
std
::
vector
<
HistoryPtr
>
lastStreamsPlayed
()
const
=
0
;
virtual
std
::
vector
<
MediaPtr
>
lastMediaPlayed
()
const
=
0
;
/**
* @brief clearHistory will clear both streams history & media history.
* @return true in case of success, false otherwise. The database will stay untouched in case
* of failure.
*
* This will flush the entity cache, but will not edit any existing instance of a media entity,
* meaning any instance of media you're holding will outdated fields.
*/
virtual
bool
clearHistory
()
=
0
;
/**
* Search
...
...
src/History.cpp
View file @
57ea9939
...
...
@@ -88,6 +88,18 @@ std::vector<HistoryPtr> History::fetch( MediaLibraryPtr ml )
return
fetchAll
<
IHistoryEntry
>
(
ml
,
req
);
}
bool
History
::
clearStreams
(
MediaLibraryPtr
ml
)
{
static
const
std
::
string
req
=
"DROP TABLE "
+
policy
::
HistoryTable
::
Name
;
auto
dbConn
=
ml
->
getConn
();
if
(
sqlite
::
Tools
::
executeRequest
(
dbConn
,
req
)
==
false
)
return
false
;
DatabaseHelpers
<
History
,
policy
::
HistoryTable
>::
clear
();
if
(
createTable
(
dbConn
)
==
false
)
return
false
;
return
true
;
}
const
std
::
string
&
History
::
mrl
()
const
{
return
m_mrl
;
...
...
src/History.h
View file @
57ea9939
...
...
@@ -52,6 +52,7 @@ public:
static
bool
createTable
(
DBConnection
dbConnection
);
static
bool
insert
(
DBConnection
dbConn
,
const
std
::
string
&
mrl
);
static
std
::
vector
<
HistoryPtr
>
fetch
(
MediaLibraryPtr
ml
);
static
bool
clearStreams
(
MediaLibraryPtr
ml
);
virtual
const
std
::
string
&
mrl
()
const
override
;
virtual
unsigned
int
insertionDate
()
const
override
;
...
...
src/Media.cpp
View file @
57ea9939
...
...
@@ -549,4 +549,16 @@ std::vector<MediaPtr> Media::fetchHistory( MediaLibraryPtr ml )
return
fetchAll
<
IMedia
>
(
ml
,
req
);
}
bool
Media
::
clearHistory
(
MediaLibraryPtr
ml
)
{
auto
dbConn
=
ml
->
getConn
();
static
const
std
::
string
req
=
"UPDATE "
+
policy
::
MediaTable
::
Name
+
" SET "
"play_count = 0,"
"last_played_date = NULL,"
"progress = 0"
;
// Clear the entire cache since quite a few items are now containing invalid info.
clear
();
return
sqlite
::
Tools
::
executeUpdate
(
dbConn
,
req
);
}
}
src/Media.h
View file @
57ea9939
...
...
@@ -110,6 +110,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
static
std
::
vector
<
MediaPtr
>
listAll
(
MediaLibraryPtr
ml
,
Type
type
,
SortingCriteria
sort
,
bool
desc
);
static
std
::
vector
<
MediaPtr
>
search
(
MediaLibraryPtr
ml
,
const
std
::
string
&
title
);
static
std
::
vector
<
MediaPtr
>
fetchHistory
(
MediaLibraryPtr
ml
);
static
bool
clearHistory
(
MediaLibraryPtr
ml
);
private:
...
...
src/MediaLibrary.cpp
View file @
57ea9939
...
...
@@ -449,6 +449,17 @@ std::vector<MediaPtr> MediaLibrary::lastMediaPlayed() const
return
Media
::
fetchHistory
(
this
);
}
bool
MediaLibrary
::
clearHistory
()
{
auto
t
=
getConn
()
->
newTransaction
();
if
(
Media
::
clearHistory
(
this
)
==
false
)
return
false
;
if
(
History
::
clearStreams
(
this
)
==
false
)
return
false
;
t
->
commit
();
return
true
;
}
MediaSearchAggregate
MediaLibrary
::
searchMedia
(
const
std
::
string
&
title
)
const
{
if
(
validateSearchPattern
(
title
)
==
false
)
...
...
src/MediaLibrary.h
View file @
57ea9939
...
...
@@ -103,6 +103,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual
bool
addToHistory
(
const
std
::
string
&
mrl
)
override
;
virtual
std
::
vector
<
HistoryPtr
>
lastStreamsPlayed
()
const
override
;
virtual
std
::
vector
<
MediaPtr
>
lastMediaPlayed
()
const
override
;
virtual
bool
clearHistory
()
override
;
virtual
MediaSearchAggregate
searchMedia
(
const
std
::
string
&
title
)
const
override
;
virtual
std
::
vector
<
PlaylistPtr
>
searchPlaylists
(
const
std
::
string
&
name
)
const
override
;
...
...
test/unittest/HistoryTests.cpp
View file @
57ea9939
...
...
@@ -109,3 +109,20 @@ TEST_F( HistoryTest, ReinsertFavorited )
ASSERT_NE
(
date
,
item
->
insertionDate
()
);
ASSERT_TRUE
(
item
->
isFavorite
()
);
}
TEST_F
(
HistoryTest
,
ClearStreamHistory
)
{
ml
->
addToHistory
(
"f00"
);
ml
->
addToHistory
(
"bar"
);
auto
history
=
ml
->
lastStreamsPlayed
();
ASSERT_EQ
(
2u
,
history
.
size
()
);
ml
->
clearHistory
();
history
=
ml
->
lastStreamsPlayed
();
ASSERT_EQ
(
0u
,
history
.
size
()
);
Reload
();
history
=
ml
->
lastStreamsPlayed
();
ASSERT_EQ
(
0u
,
history
.
size
()
);
}
test/unittest/MediaTests.cpp
View file @
57ea9939
...
...
@@ -303,6 +303,29 @@ TEST_F( Medias, History )
ASSERT_EQ
(
m
->
id
(),
history
[
1
]
->
id
()
);
}
TEST_F
(
Medias
,
ClearHistory
)
{
auto
m
=
ml
->
addFile
(
"media.mkv"
);
auto
history
=
ml
->
lastMediaPlayed
();
ASSERT_EQ
(
0u
,
history
.
size
()
);
m
->
increasePlayCount
();
m
->
save
();
history
=
ml
->
lastMediaPlayed
();
ASSERT_EQ
(
1u
,
history
.
size
()
);
ASSERT_TRUE
(
ml
->
clearHistory
()
);
history
=
ml
->
lastMediaPlayed
();
ASSERT_EQ
(
0u
,
history
.
size
()
);
Reload
();
history
=
ml
->
lastMediaPlayed
();
ASSERT_EQ
(
0u
,
history
.
size
()
);
}
TEST_F
(
Medias
,
SetReleaseDate
)
{
auto
m
=
ml
->
addFile
(
"movie.mkv"
);
...
...
Hugo Beauzée-Luyssen
@chouquette
Mentioned in issue
#11 (closed)
·
Nov 15, 2016
Mentioned in issue
#11 (closed)
Mentioned in issue #11
Toggle commit list
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