media library/tag editor: block idle while doing hierarchical searches

idle should be blocked in such cases since it would be enabled and
disabled a few times by each mpd command, which makes no sense and
slows down the whole process.
This commit is contained in:
Andrzej Rybczak
2010-06-17 16:41:49 +02:00
parent 10cea746e9
commit 9c02bbf596
4 changed files with 17 additions and 3 deletions

View File

@@ -201,6 +201,10 @@ void MediaLibrary::Update()
if (!hasTwoColumns && !Artists->Empty() && Albums->Empty() && Songs->Empty())
{
// idle has to be blocked for now since it would be enabled and
// disabled a few times by each mpd command, which makes no sense
// and slows down the whole process.
Mpd.BlockIdle(1);
Albums->Reset();
MPD::TagList list;
locale_to_utf(Artists->Current());
@@ -239,6 +243,7 @@ void MediaLibrary::Update()
Albums->AddOption(SearchConstraints("", AllTracksMarker));
}
Albums->Refresh();
Mpd.BlockIdle(0);
}
else if (hasTwoColumns && Albums->Empty())
{
@@ -246,6 +251,7 @@ void MediaLibrary::Update()
MPD::TagList artists;
*Albums << XY(0, 0) << "Fetching albums...";
Albums->Window::Refresh();
Mpd.BlockIdle(1);
Mpd.GetList(artists, Config.media_lib_primary_tag);
for (MPD::TagList::iterator i = artists.begin(); i != artists.end(); ++i)
{
@@ -289,6 +295,7 @@ void MediaLibrary::Update()
}
}
}
Mpd.BlockIdle(0);
if (!Albums->Empty())
Albums->Sort<SearchConstraintsSorting>();
Albums->Refresh();

View File

@@ -142,18 +142,21 @@ void MPD::Connection::SetErrorHandler(ErrorHandler handler, void *data)
void MPD::Connection::GoIdle()
{
if (supportsIdle && !isIdle && mpd_send_idle(itsConnection))
if (supportsIdle && !itsIdleBlocked && !isIdle && mpd_send_idle(itsConnection))
isIdle = 1;
}
int MPD::Connection::GoBusy()
{
int flags = 0;
if (isIdle && mpd_send_noidle(itsConnection))
{
isIdle = 0;
return mpd_recv_idle(itsConnection, 1);
if (hasData)
flags = mpd_recv_idle(itsConnection, 1);
mpd_response_finish(itsConnection);
}
return 0;
return flags;
}
void MPD::Connection::UpdateStatus()

View File

@@ -95,6 +95,7 @@ namespace MPD
unsigned Version() const;
void SetIdleEnabled(bool val) { isIdleEnabled = val; }
void BlockIdle(bool val) { itsIdleBlocked = val; }
bool SupportsIdle() const { return supportsIdle; }
void OrderDataFetching() { hasData = 1; }
int GetFD() const { return itsFD; }
@@ -227,6 +228,7 @@ namespace MPD
int itsFD;
bool isIdle;
bool isIdleEnabled;
bool itsIdleBlocked;
bool supportsIdle;
bool hasData;

View File

@@ -232,6 +232,7 @@ void TagEditor::Update()
{
*Albums << XY(0, 0) << "Fetching albums...";
Albums->Window::Refresh();
Mpd.BlockIdle(1); // for the same reason as in media library
Mpd.GetList(list, MPD_TAG_ALBUM);
for (MPD::TagList::const_iterator it = list.begin(); it != list.end(); ++it)
{
@@ -246,6 +247,7 @@ void TagEditor::Update()
}
MPD::FreeSongList(l);
}
Mpd.BlockIdle(0);
Albums->Sort<CaseInsensitiveSorting>();
}
else