From 6806bf6669107500f618eb0ba2371eeb7df2f2fd Mon Sep 17 00:00:00 2001 From: craig Date: Tue, 24 Jan 2012 21:59:37 +0000 Subject: [PATCH] Improve playqueue handling when we have 1000s of entries. --- ChangeLog | 27 ++++++++++++++------------- gui/mainwindow.cpp | 31 ++++++++++++++++++++++++++----- gui/mainwindow.h | 3 +++ models/playqueuemodel.cpp | 8 ++++++-- models/playqueueproxymodel.cpp | 3 ++- models/playqueueproxymodel.h | 4 ++++ mpd/mpdconnection.cpp | 5 +++++ 7 files changed, 60 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0a9a7f486..db79b03e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,18 +1,19 @@ 0.3.0 ----- -1. Basic copy to/from device support - USB mass storage (UMS) and MTP support - only. MTP is *very* slow. (KDE only) -2. When refreshing library/albums, only affect parts of the model that have - changed. (Previously the whole model was replaced). -3. When changing name of playlist, show the original name in the line-edit. -4. Fix adding songs with spaces in their filenames to stored playlists -5. When we recieve an updated signal frmo MPD, refresh library view. -6. When disaplying songs of various artists albums, show as 'track number - - artist - song' -7. German translation - thanks to Lutz Lüttke -8. Rename 'Update Database' action to 'Refresh', as the curent view is now also - refreshed. -9. When determining cache filename, replace slashes with underscores. + 1. Basic copy to/from device support - USB mass storage (UMS) and MTP support + only. MTP is *very* slow. (KDE only) + 2. When refreshing library/albums, only affect parts of the model that have + changed. (Previously the whole model was replaced). + 3. When changing name of playlist, show the original name in the line-edit. + 4. Fix adding songs with spaces in their filenames to stored playlists + 5. When we recieve an updated signal frmo MPD, refresh library view. + 6. When disaplying songs of various artists albums, show as 'track number - + artist - song' + 7. German translation - thanks to Lutz Lüttke + 8. Rename 'Update Database' action to 'Refresh', as the curent view is now also + refreshed. + 9. When determining cache filename, replace slashes with underscores. +10. Improve playqueue handling when we have 1000s of entries. 0.2.1 ----- diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index b936987cc..aee837129 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -83,6 +84,7 @@ #include "timeslider.h" #include "mpris.h" #include "dockmanager.h" +#include "debugtimer.h" enum Tabs { @@ -240,7 +242,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), nowPlayingFactor(0), draggingPositionSlider(false), dock(0), - mpris(0) + mpris(0), + playlistSearchTimer(0) { loaded=0; trayItem = 0; @@ -688,6 +691,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), playQueueProxyModel.setSourceModel(&playQueueModel); playQueue->setModel(&playQueueProxyModel); + playQueueProxyModel.setFilterKeyColumn(-1); playQueue->setAcceptDrops(true); playQueue->setDropIndicatorShown(true); playQueue->addAction(removeFromPlaylistAction); @@ -1104,16 +1108,33 @@ void MainWindow::decreaseVolume() void MainWindow::searchPlaylist() { - if (searchPlaylistLineEdit->text().isEmpty()) { - playQueueProxyModel.setFilterRegExp(""); - return; + if (!playlistSearchTimer) { + playlistSearchTimer=new QTimer(this); + connect(playlistSearchTimer, SIGNAL(timeout()), SLOT(realSearchPlaylist())); } + playlistSearchTimer->start(500); +} - playQueueProxyModel.setFilterRegExp(searchPlaylistLineEdit->text()); +void MainWindow::realSearchPlaylist() +{ + if (playlistSearchTimer) { + playlistSearchTimer->stop(); + } + QString text=searchPlaylistLineEdit->text().trimmed(); + if (text.length()<4) { + playQueueProxyModel.setEnabled(false); + if (!playQueueProxyModel.filterRegExp().isEmpty()) { + playQueueProxyModel.setFilterRegExp(QString()); + } + } else if (text!=playQueueProxyModel.filterRegExp().pattern()) { + playQueueProxyModel.setEnabled(true); + playQueueProxyModel.setFilterRegExp(text); + } } void MainWindow::updatePlaylist(const QList &songs) { + TF_DEBUG QList selectedSongIds; qint32 firstSelectedSongId = -1; qint32 firstSelectedRow = -1; diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 93ced81b2..f0f8a6a75 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -75,6 +75,7 @@ class QThread; class QAbstractItemView; class DockManager; class Mpris; +class QTimer; class DeleteKeyEventHandler : public QObject { @@ -223,6 +224,7 @@ private Q_SLOTS: void decreaseVolume(); void setPosition(); void searchPlaylist(); + void realSearchPlaylist(); void updatePlaylist(const QList &songs); void updateCurrentSong(const Song &song); void updateStats(); @@ -366,6 +368,7 @@ private: QThread *mpdThread; DockManager *dock; Mpris *mpris; + QTimer *playlistSearchTimer; friend class VolumeSliderEventHandler; friend class CoverEventHandler; friend class LibraryPage; diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index 7a7513587..94df9dfed 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -39,6 +39,7 @@ #include "mpdstats.h" #include "mpdstatus.h" #include "streamfetcher.h" +#include "debugtimer.h" static QStringList reverseList(const QStringList &orig) { @@ -390,14 +391,17 @@ void PlayQueueModel::updateCurrentSong(quint32 id) void PlayQueueModel::clear() { + beginResetModel(); songs=QList(); - reset(); + endResetModel(); } void PlayQueueModel::updatePlaylist(const QList &songs) { + TF_DEBUG + beginResetModel(); this->songs = songs; - reset(); + endResetModel(); } /** diff --git a/models/playqueueproxymodel.cpp b/models/playqueueproxymodel.cpp index 4e7bead02..0c26ca055 100644 --- a/models/playqueueproxymodel.cpp +++ b/models/playqueueproxymodel.cpp @@ -34,11 +34,12 @@ PlayQueueProxyModel::PlayQueueProxyModel(QObject *parent) : QSortFilterProxyMode setFilterCaseSensitivity(Qt::CaseInsensitive); //setSortCaseSensitivity(Qt::CaseInsensitive); //setSortLocaleAware(true); + enabled=false; } bool PlayQueueProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - if (filterRegExp().isEmpty()) { + if (!enabled) { return true; } diff --git a/models/playqueueproxymodel.h b/models/playqueueproxymodel.h index 91290d1c5..074c1b67c 100644 --- a/models/playqueueproxymodel.h +++ b/models/playqueueproxymodel.h @@ -39,6 +39,10 @@ public: QMimeData *mimeData(const QModelIndexList &indexes) const; bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + void setEnabled(bool e) { enabled=e; } + +private: + bool enabled; }; #endif diff --git a/mpd/mpdconnection.cpp b/mpd/mpdconnection.cpp index cbe100c6e..2a16e4913 100644 --- a/mpd/mpdconnection.cpp +++ b/mpd/mpdconnection.cpp @@ -31,6 +31,7 @@ #include #endif #include +#include "debugtimer.h" //#undef qDebug //#define qDebug qWarning @@ -661,6 +662,7 @@ void MPDConnection::update() */ void MPDConnection::listAllInfo(const QDateTime &dbUpdate) { + TF_DEBUG emit updatingLibrary(); Response response=sendCommand("listallinfo"); if(response.ok) { @@ -676,6 +678,7 @@ void MPDConnection::listAllInfo(const QDateTime &dbUpdate) */ void MPDConnection::listAll() { + TF_DEBUG emit updatingFileList(); Response response=sendCommand("listall"); if(response.ok) { @@ -694,6 +697,7 @@ void MPDConnection::listPlaylist() void MPDConnection::listPlaylists() { + TF_DEBUG Response response=sendCommand("listplaylists"); if(response.ok) { emit playlistsRetrieved(MPDParseUtils::parsePlaylists(response.data)); @@ -702,6 +706,7 @@ void MPDConnection::listPlaylists() void MPDConnection::playlistInfo(const QString &name) { + TF_DEBUG QByteArray data = "listplaylistinfo "; data += encodeName(name); Response response=sendCommand(data);