Commit e19a783e authored by Alexander Stippich's avatar Alexander Stippich
Browse files

rework undo logic

parent 4cbdb6b6
......@@ -54,8 +54,6 @@ public:
bool mRepeatPlay = false;
bool mForceUndo = false;
QList<int> mRandomPositions = {0, 0, 0};
};
......@@ -365,7 +363,6 @@ void MediaPlayList::move(int from, int to, int n)
void MediaPlayList::enqueueRestoredEntries(const QVariantList &newEntries)
{
enqueueCommon();
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newEntries.size() - 1);
for (auto &oneData : newEntries) {
auto trackData = oneData.toStringList();
......@@ -432,7 +429,6 @@ void MediaPlayList::enqueueRestoredEntries(const QVariantList &newEntries)
void MediaPlayList::enqueueFilesList(const ElisaUtils::EntryDataList &newEntries, ElisaUtils::PlayListEntryType databaseIdType)
{
qCDebug(orgKdeElisaPlayList()) << "MediaPlayList::enqueueFilesList";
enqueueCommon();
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newEntries.size() - 1);
for (const auto &oneTrackUrl : newEntries) {
......@@ -490,7 +486,6 @@ void MediaPlayList::enqueueFilesList(const ElisaUtils::EntryDataList &newEntries
void MediaPlayList::enqueueTracksListById(const ElisaUtils::EntryDataList &newEntries, ElisaUtils::PlayListEntryType type)
{
qCDebug(orgKdeElisaPlayList()) << "MediaPlayList::enqueueTracksListById" << newEntries.size() << type;
enqueueCommon();
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newEntries.size() - 1);
for (const auto &newTrack : newEntries) {
......@@ -515,7 +510,6 @@ void MediaPlayList::enqueueTracksListById(const ElisaUtils::EntryDataList &newEn
void MediaPlayList::enqueueOneEntry(const ElisaUtils::EntryData &entryData, ElisaUtils::PlayListEntryType type)
{
qCDebug(orgKdeElisaPlayList()) << "MediaPlayList::enqueueOneEntry" << std::get<0>(entryData) << std::get<1>(entryData) << type;
enqueueCommon();
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size());
d->mData.push_back(MediaPlayListEntry{std::get<0>(entryData).databaseId(), std::get<1>(entryData), type});
......@@ -531,7 +525,6 @@ void MediaPlayList::enqueueOneEntry(const ElisaUtils::EntryData &entryData, Elis
void MediaPlayList::enqueueMultipleEntries(const ElisaUtils::EntryDataList &entriesData, ElisaUtils::PlayListEntryType type)
{
qCDebug(orgKdeElisaPlayList()) << "MediaPlayList::enqueueMultipleEntries" << entriesData.size() << type;
enqueueCommon();
beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + entriesData.size() - 1);
for (const auto &entryData : entriesData) {
......@@ -575,7 +568,7 @@ void MediaPlayList::clearPlayList(bool prepareUndo)
d->mCurrentTrack = QPersistentModelIndex{};
notifyCurrentTrackChanged();
displayOrHideUndoInline(true);
Q_EMIT displayUndoInline();
Q_EMIT tracksCountChanged();
Q_EMIT remainingTracksChanged();
Q_EMIT persistentStateChanged();
......@@ -631,15 +624,9 @@ void MediaPlayList::undoClearPlayList()
Q_EMIT persistentStateChanged();
Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole});
displayOrHideUndoInline(false);
Q_EMIT undoClearPlayListPlayer();
}
void MediaPlayList::enqueueCommon()
{
displayOrHideUndoInline(false);
}
void MediaPlayList::copyD()
{
dOld->mData = d->mData;
......@@ -688,14 +675,12 @@ void MediaPlayList::enqueue(const ElisaUtils::EntryData &newEntry,
ElisaUtils::PlayListEnqueueTriggerPlay triggerPlay)
{
if (enqueueMode == ElisaUtils::ReplacePlayList) {
if(d->mData.size()>0){
d->mForceUndo = true;
if (d->mData.size() == 0) {
Q_EMIT hideUndoInline();
}
clearPlayList();
}
enqueueCommon();
switch (databaseIdType)
{
case ElisaUtils::Album:
......@@ -723,10 +708,6 @@ void MediaPlayList::enqueue(const ElisaUtils::EntryData &newEntry,
if (triggerPlay == ElisaUtils::TriggerPlay) {
Q_EMIT ensurePlay();
}
if (enqueueMode == ElisaUtils::ReplacePlayList) {
d->mForceUndo = false;
}
}
void MediaPlayList::enqueue(const ElisaUtils::EntryDataList &newEntries,
......@@ -739,14 +720,12 @@ void MediaPlayList::enqueue(const ElisaUtils::EntryDataList &newEntries,
}
if (enqueueMode == ElisaUtils::ReplacePlayList) {
if(d->mData.size()>0){
d->mForceUndo = true;
if (d->mData.size() == 0) {
Q_EMIT hideUndoInline();
}
clearPlayList();
}
enqueueCommon();
switch (databaseIdType)
{
case ElisaUtils::Track:
......@@ -770,10 +749,6 @@ void MediaPlayList::enqueue(const ElisaUtils::EntryDataList &newEntries,
if (triggerPlay == ElisaUtils::TriggerPlay) {
Q_EMIT ensurePlay();
}
if (enqueueMode == ElisaUtils::ReplacePlayList) {
d->mForceUndo = false;
}
}
bool MediaPlayList::savePlaylist(const QUrl &fileName)
......@@ -1128,17 +1103,6 @@ void MediaPlayList::setRepeatPlay(bool value)
}
}
void MediaPlayList::displayOrHideUndoInline(bool value)
{
if(value){
Q_EMIT displayUndoInline();
}else {
if(!d->mForceUndo){
Q_EMIT hideUndoInline();
}
}
}
void MediaPlayList::skipNextTrack()
{
if (!d->mCurrentTrack.isValid()) {
......
......@@ -289,7 +289,6 @@ private Q_SLOTS:
void loadPlayListLoadFailed();
private:
void displayOrHideUndoInline(bool value);
void clearPlayList(bool prepareUndo);
......@@ -309,8 +308,6 @@ private:
void enqueueMultipleEntries(const ElisaUtils::EntryDataList &entriesData, ElisaUtils::PlayListEntryType type);
void enqueueCommon();
void copyD();
std::unique_ptr<MediaPlayListPrivate> d;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment