media library: add data fetch delay after position changes

This commit is contained in:
Andrzej Rybczak
2014-08-30 15:38:33 +02:00
parent a959d5c0a6
commit a9c1e3811b
3 changed files with 23 additions and 3 deletions

View File

@@ -2784,11 +2784,16 @@ void listsChangeFinisher()
if (myScreen->activeWindow() == &myLibrary->Tags)
{
myLibrary->Albums.clear();
myLibrary->Albums.refresh();
myLibrary->Songs.clear();
myLibrary->Songs.refresh();
myLibrary->updateTimer();
}
else if (myScreen->activeWindow() == &myLibrary->Albums)
{
myLibrary->Songs.clear();
myLibrary->Songs.refresh();
myLibrary->updateTimer();
}
else if (myScreen->isActiveWindow(myPlaylistEditor->Playlists))
{

View File

@@ -45,7 +45,9 @@ using Global::myScreen;
MediaLibrary *myLibrary;
namespace {//
namespace {
const auto fetch_delay = boost::posix_time::milliseconds(500);
bool hasTwoColumns;
size_t itsLeftColStartX;
@@ -144,6 +146,7 @@ public:
}
MediaLibrary::MediaLibrary()
: m_timer(boost::posix_time::from_time_t(0))
{
hasTwoColumns = 0;
itsLeftColWidth = COLS/3-1;
@@ -336,7 +339,9 @@ void MediaLibrary::update()
Tags.refresh();
}
if ((!Tags.empty() && Albums.reallyEmpty()) || m_albums_update_request)
if (!Tags.empty()
&& ((Albums.reallyEmpty() && Global::Timer - m_timer > fetch_delay) || m_albums_update_request)
)
{
Albums.clearSearchResults();
m_albums_update_request = false;
@@ -382,7 +387,9 @@ void MediaLibrary::update()
}
}
if ((!Albums.empty() && Songs.reallyEmpty()) || m_songs_update_request)
if (!Albums.empty()
&& ((Songs.reallyEmpty() && Global::Timer - m_timer > fetch_delay) || m_songs_update_request)
)
{
Songs.clearSearchResults();
m_songs_update_request = false;
@@ -851,6 +858,11 @@ void MediaLibrary::nextColumn()
/***********************************************************************/
void MediaLibrary::updateTimer()
{
m_timer = Global::Timer;
}
void MediaLibrary::toggleColumnsMode()
{
hasTwoColumns = !hasTwoColumns;

View File

@@ -69,6 +69,7 @@ struct MediaLibrary: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Sea
virtual void nextColumn() OVERRIDE;
// private members
void updateTimer();
void toggleColumnsMode();
int Columns();
void LocateSong(const MPD::Song &);
@@ -143,6 +144,8 @@ private:
bool m_tags_update_request;
bool m_albums_update_request;
bool m_songs_update_request;
boost::posix_time::ptime m_timer;
};
extern MediaLibrary *myLibrary;