From 9c02bbf596ecabe00fb8280f953265560012ff36 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 17 Jun 2010 16:41:49 +0200 Subject: 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. --- src/media_library.cpp | 7 +++++++ src/mpdpp.cpp | 9 ++++++--- src/mpdpp.h | 2 ++ src/tag_editor.cpp | 2 ++ 4 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/media_library.cpp b/src/media_library.cpp index 97d95b0b..d4cc92d3 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -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(); Albums->Refresh(); diff --git a/src/mpdpp.cpp b/src/mpdpp.cpp index 4e1b06c2..f215115e 100644 --- a/src/mpdpp.cpp +++ b/src/mpdpp.cpp @@ -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() diff --git a/src/mpdpp.h b/src/mpdpp.h index dec867e3..b9c0512d 100644 --- a/src/mpdpp.h +++ b/src/mpdpp.h @@ -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; diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 25ba9737..a2099c6d 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -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(); } else -- cgit v1.2.3