Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History improvements #2996

Merged
merged 40 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
09a13b6
Make better use of history root view
poelzi Aug 4, 2020
d52f3f2
Order history in descending order (newest on top)
poelzi Aug 4, 2020
c4d09cd
Group history by year
poelzi Aug 5, 2020
b6754e2
Implement requested changes.
poelzi Aug 12, 2020
a5815cf
Better handle nested models in library features
poelzi Sep 20, 2020
d351d9d
Delete empty histroy playlists on start
poelzi Sep 20, 2020
cc209c1
Use / to seperate same date history entries.
poelzi Sep 20, 2020
164d49d
fix crash when index is obsolete due rebuilding of the model
poelzi Sep 20, 2020
2654c71
use # seperator for history extra counter
poelzi Sep 26, 2020
7971acb
Fix formatting issues from review
poelzi Oct 8, 2020
8aba0cf
fix formatting and use const where possible
poelzi Oct 8, 2020
a0608a9
use older lookup method for sibilings
poelzi Oct 8, 2020
e895dc9
fix formatting
poelzi Oct 8, 2020
f6781be
Remove transaction from playlist removeal
poelzi Oct 9, 2020
dac5abc
fix build warning on ubuntu
poelzi Oct 9, 2020
b31cf4b
simplify code
poelzi Nov 4, 2020
f9d3f02
Properly open all submenus when using selectIndex on features
poelzi Nov 4, 2020
7e00694
Add functions to scroll to the correct child on the sidebar
poelzi Nov 25, 2020
e2abe3f
Use new child selection method for join with previous
poelzi Nov 26, 2020
7f68512
Restore expansion code
poelzi Nov 26, 2020
a8a93f0
Cleanup child selection code
poelzi Nov 26, 2020
b53d9c9
Fix memory leak in selection model
poelzi Nov 26, 2020
b1a512b
Fix join with previous criteria logic
poelzi Nov 26, 2020
d133c4b
Fix foorloop clazy warning
poelzi Nov 27, 2020
a64f89e
Remove lambda due false positive of clazy
poelzi Nov 27, 2020
4d50c71
Make playlist cleanup more versatile.
poelzi Nov 27, 2020
8e79b0b
Use constant for indicating invalid playlist id
poelzi Nov 27, 2020
87d238c
Try to select a sibiling on the same level as the deleted entry
poelzi Nov 27, 2020
22223b6
Name cleanup. Don't select on root item
poelzi Nov 27, 2020
54a2edf
eager return in error case
poelzi Nov 27, 2020
b86cbdc
simplify slotDeletePlaylist()
poelzi Nov 27, 2020
83cc92b
simplify code
poelzi Nov 28, 2020
0ce9b4d
Speedup playlist deletion logic
poelzi Nov 29, 2020
7dca1bd
Always show start new playlist and focus on change
poelzi Nov 29, 2020
966e627
Move transaction outside of DAO
poelzi Nov 29, 2020
3a52a4d
Print info instead of debug when transaction failed
poelzi Nov 29, 2020
b68a20c
Don't double log on errors
poelzi Nov 29, 2020
a05573b
use constexpr when possible. Clearify join wording
poelzi Dec 1, 2020
6cabebd
Don't activate when not expected.
poelzi Dec 1, 2020
4d69a40
use QChar instead of StringLiteral
poelzi Dec 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/library/dao/playlistdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "library/trackcollection.h"
#include "track/track.h"
#include "util/compatibility.h"
#include "util/db/fwdsqlquery.h"
#include "util/math.h"

PlaylistDAO::PlaylistDAO()
Expand Down Expand Up @@ -227,6 +228,53 @@ void PlaylistDAO::deletePlaylist(const int playlistId) {
}
}

int PlaylistDAO::deleteAllPlaylistsWithFewerTracks(
PlaylistDAO::HiddenType type, int minNumberOfTracks) {
VERIFY_OR_DEBUG_ASSERT(minNumberOfTracks > 0) {
return 0; // nothing to do, probably unintended invocation
}

QSqlQuery query(m_database);
query.prepare(QStringLiteral(
"SELECT id FROM Playlists "
"WHERE (SELECT count(playlist_id) FROM PlaylistTracks WHERE "
"Playlists.ID = PlaylistTracks.playlist_id) < :length AND "
"Playlists.hidden = :hidden"));
query.bindValue(":hidden", static_cast<int>(type));
query.bindValue(":length", minNumberOfTracks);
if (!query.exec()) {
LOG_FAILED_QUERY(query);
return -1;
}

QStringList idStringList;
while (query.next()) {
idStringList.append(query.value(0).toString());
}
if (idStringList.isEmpty()) {
return 0;
}
QString idString = idStringList.join(",");

qInfo() << "Deleting" << idStringList.size() << "playlists of type" << type
<< "that contain fewer than" << minNumberOfTracks << "tracks";

auto deleteTracks = FwdSqlQuery(m_database,
poelzi marked this conversation as resolved.
Show resolved Hide resolved
QString("DELETE FROM PlaylistTracks WHERE playlist_id IN (%1)")
.arg(idString));
if (!deleteTracks.execPrepared()) {
return -1;
}

auto deletePlaylists = FwdSqlQuery(m_database,
QString("DELETE FROM Playlists WHERE id IN (%1)").arg(idString));
if (!deletePlaylists.execPrepared()) {
return -1;
}

return idStringList.length();
}

void PlaylistDAO::renamePlaylist(const int playlistId, const QString& newName) {
QSqlQuery query(m_database);
query.prepare(QStringLiteral(
Expand Down
4 changes: 4 additions & 0 deletions src/library/dao/playlistdao.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class PlaylistDAO : public QObject, public virtual DAO {
int createUniquePlaylist(QString* pName, const HiddenType type = PLHT_NOT_HIDDEN);
// Delete a playlist
void deletePlaylist(const int playlistId);
/// Delete Playlists with fewer entries then "length"
/// Needs to be called inside a transaction.
/// @return number of deleted playlists, -1 on error
int deleteAllPlaylistsWithFewerTracks(PlaylistDAO::HiddenType type, int minNumberOfTracks);
// Rename a playlist
void renamePlaylist(const int playlistId, const QString& newName);
// Lock or unlock a playlist
Expand Down
11 changes: 8 additions & 3 deletions src/library/queryutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ class ScopedTransaction {
return false;
}
bool result = m_database.commit();
qDebug() << "Committing transaction on"
<< m_database.connectionName()
<< "result:" << result;
if (result) {
qDebug() << "Committing transaction successfully on"
<< m_database.connectionName();
} else {
qInfo() << "Committing transaction failed on"
<< m_database.connectionName()
<< ":" << m_database.lastError();
}
m_active = false;
return result;
}
Expand Down
9 changes: 7 additions & 2 deletions src/library/sidebarmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,6 @@ bool SidebarModel::dragMoveAccept(const QModelIndex& index, const QUrl& url) {

// Translates an index from the child models to an index of the sidebar models
QModelIndex SidebarModel::translateSourceIndex(const QModelIndex& index) {
QModelIndex translatedIndex;

/* These method is called from the slot functions below.
* QObject::sender() return the object which emitted the signal
* handled by the slot functions.
Expand All @@ -388,6 +386,13 @@ QModelIndex SidebarModel::translateSourceIndex(const QModelIndex& index) {
return QModelIndex();
}

return translateIndex(index, model);
}

QModelIndex SidebarModel::translateIndex(
const QModelIndex& index, const QAbstractItemModel* model) {
QModelIndex translatedIndex;

if (index.isValid()) {
TreeItem* item = (TreeItem*)index.internalPointer();
translatedIndex = createIndex(index.row(), index.column(), item);
Expand Down
4 changes: 4 additions & 0 deletions src/library/sidebarmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class SidebarModel : public QAbstractItemModel {
bool dragMoveAccept(const QModelIndex& index, const QUrl& url);
bool hasChildren(const QModelIndex& parent = QModelIndex()) const override;
bool hasTrackTable(const QModelIndex& index) const;
QModelIndex translateChildIndex(const QModelIndex& index) {
return translateIndex(index, index.model());
}

public slots:
void pressed(const QModelIndex& index);
Expand Down Expand Up @@ -76,6 +79,7 @@ class SidebarModel : public QAbstractItemModel {

private:
QModelIndex translateSourceIndex(const QModelIndex& parent);
QModelIndex translateIndex(const QModelIndex& index, const QAbstractItemModel* model);
void featureRenamed(LibraryFeature*);
QList<LibraryFeature*> m_sFeatures;
unsigned int m_iDefaultSelectedIndex; /** Index of the item in the sidebar model to select at startup. */
Expand Down
Loading