Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
juk
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
KDE
juk
Commits
516a69f9
Commit
516a69f9
authored
Jan 18, 2018
by
Michael Pyne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor and extract SearchPlaylist's playlist item sync code.
And use it for DynamicPlaylist now as well.
parent
39523ee3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
38 deletions
+51
-38
dynamicplaylist.cpp
dynamicplaylist.cpp
+5
-16
dynamicplaylist.h
dynamicplaylist.h
+0
-3
playlist.cpp
playlist.cpp
+35
-0
playlist.h
playlist.h
+10
-1
searchplaylist.cpp
searchplaylist.cpp
+1
-18
No files found.
dynamicplaylist.cpp
View file @
516a69f9
...
...
@@ -151,7 +151,11 @@ void DynamicPlaylist::updateItems()
if
(
m_siblings
!=
siblings
)
{
m_siblings
=
siblings
;
slotUpdateItems
();
this
->
synchronizeItemsTo
(
siblings
);
if
(
m_synchronizePlaying
)
{
synchronizePlayingItems
(
m_playlists
,
true
);
}
}
}
...
...
@@ -174,19 +178,4 @@ void DynamicPlaylist::checkUpdateItems()
m_dirty
=
false
;
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
void
DynamicPlaylist
::
slotUpdateItems
()
{
// This should be optimized to check to see which items are already in the
// list and just adding those and removing the ones that aren't.
clear
();
createItems
(
m_siblings
);
if
(
m_synchronizePlaying
)
synchronizePlayingItems
(
m_playlists
,
true
);
}
// vim: set et sw=4 tw=0 sta:
dynamicplaylist.h
View file @
516a69f9
...
...
@@ -99,9 +99,6 @@ private:
*/
void
checkUpdateItems
();
private
slots
:
void
slotUpdateItems
();
private:
QList
<
PlaylistObserver
*>
m_observers
;
PlaylistItemList
m_siblings
;
...
...
playlist.cpp
View file @
516a69f9
...
...
@@ -35,6 +35,7 @@
#include <QCursor>
#include <QDir>
#include <QDirIterator>
#include <QHash>
#include <QToolTip>
#include <QFile>
#include <QFileDialog>
...
...
@@ -51,6 +52,7 @@
#include <QPixmap>
#include <QStackedWidget>
#include <QScrollBar>
#include <id3v1genres.h>
#include <time.h>
...
...
@@ -937,6 +939,39 @@ void Playlist::removeFromDisk(const PlaylistItemList &items)
}
}
void
Playlist
::
synchronizeItemsTo
(
const
PlaylistItemList
&
itemList
)
{
const
auto
&
existingItems
=
items
();
if
(
qAbs
(
itemList
.
count
()
-
existingItems
.
count
())
>
qMax
(
itemList
.
count
(),
existingItems
.
count
())
/
2
)
{
// Large imbalance in list sizes, just clear all and add without
// figuring out the diff also
clearItems
(
existingItems
);
createItems
(
itemList
);
return
;
}
// Determine differences between existing playlist items and patch up
QHash
<
CollectionListItem
*
,
PlaylistItem
*>
oldItems
;
oldItems
.
reserve
(
qMax
(
existingItems
.
count
(),
itemList
.
count
()));
for
(
const
auto
&
item
:
existingItems
)
{
oldItems
.
insert
(
item
->
collectionItem
(),
item
);
}
PlaylistItemList
newItems
;
for
(
const
auto
&
item
:
itemList
)
{
if
(
oldItems
.
remove
(
item
->
collectionItem
())
==
0
)
{
newItems
.
append
(
item
->
collectionItem
());
}
}
clearItems
(
PlaylistItemList
(
oldItems
.
values
()));
createItems
(
newItems
);
}
void
Playlist
::
dragEnterEvent
(
QDragEnterEvent
*
e
)
{
if
(
CoverDrag
::
isCover
(
e
->
mimeData
()))
{
...
...
playlist.h
View file @
516a69f9
...
...
@@ -414,6 +414,15 @@ protected:
*/
void
removeFromDisk
(
const
PlaylistItemList
&
items
);
/**
* Adds and removes items from this Playlist as necessary to ensure that
* the same items are present in this Playlist as in @p itemList.
*
* No ordering guarantees are imposed, just that the playlist will have the
* same items as in the given list afterwards.
*/
void
synchronizeItemsTo
(
const
PlaylistItemList
&
itemList
);
// the following are all reimplemented from base classes
virtual
bool
eventFilter
(
QObject
*
watched
,
QEvent
*
e
);
...
...
@@ -437,7 +446,7 @@ protected:
virtual
void
addColumn
(
const
QString
&
label
,
int
width
=
-
1
);
/**
* Do some fin
i
al initialization of created items. Notably ensure that they
* Do some final initialization of created items. Notably ensure that they
* are shown or hidden based on the contents of the current PlaylistSearch.
*
* This is called by the PlaylistItem constructor.
...
...
searchplaylist.cpp
View file @
516a69f9
...
...
@@ -55,25 +55,8 @@ void SearchPlaylist::updateItems()
// Here we don't simply use "clear" since that would involve a call to
// items() which would in turn call this method...
PlaylistItemList
l
=
Playlist
::
items
();
QHash
<
CollectionListItem
*
,
PlaylistItem
*>
oldItems
;
oldItems
.
reserve
(
503
);
foreach
(
PlaylistItem
*
item
,
l
)
oldItems
.
insert
(
item
->
collectionItem
(),
item
);
m_search
.
search
();
PlaylistItemList
matched
=
m_search
.
matchedItems
();
PlaylistItemList
newItems
;
foreach
(
PlaylistItem
*
item
,
matched
)
{
if
(
oldItems
.
remove
(
item
->
collectionItem
())
==
0
)
newItems
.
append
(
item
->
collectionItem
());
}
clearItems
(
PlaylistItemList
(
oldItems
.
values
()));
createItems
(
newItems
);
synchronizeItemsTo
(
m_search
.
matchedItems
());
if
(
synchronizePlaying
())
{
qCDebug
(
JUK_LOG
)
<<
"synchronizing playing"
;
...
...
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