From 67f2903c42289cb2971868928b7a5b210ce4ac65 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sun, 14 Sep 2014 13:32:40 +0200 Subject: [PATCH] settings: add option to disable data fetching delay in media library and playlist editor --- doc/config | 2 ++ doc/ncmpcpp.1 | 3 +++ src/media_library.cpp | 11 +++++------ src/media_library.h | 3 +++ src/playlist_editor.cpp | 9 ++++----- src/playlist_editor.h | 3 +++ src/settings.cpp | 3 +++ src/settings.h | 1 + 8 files changed, 24 insertions(+), 11 deletions(-) diff --git a/doc/config b/doc/config index f306d8c1..691ad86e 100644 --- a/doc/config +++ b/doc/config @@ -332,6 +332,8 @@ ## #user_interface = classic # +data_fetching_delay = yes +# ## Available values: artist, album_artist, date, genre, composer, performer. ## #media_library_primary_tag = artist diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index bbe1f5b0..6e8ef2f8 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -309,6 +309,9 @@ Type of currently used regular expressions. .B user_interface = classic/alternative Default user interface used by ncmpcpp at start. .TP +.B data_fetching_delay = yes/no +If enabled, there will be a 250ms delay between refreshing position in media library or playlist editor and fetching appropriate data from MPD. This limits data fetched from the server and is particularly useful if ncmpcpp is connected to a remote host. +.TP .B media_library_primary_tag = artist/date/genre/composer/performer Default tag type for leftmost column in media library. .TP diff --git a/src/media_library.cpp b/src/media_library.cpp index 2ec1acf9..496cc3a6 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -48,9 +48,6 @@ MediaLibrary *myLibrary; namespace { -const auto ml_wtimeout = 250; -const auto fetch_delay = boost::posix_time::milliseconds(ml_wtimeout); - bool hasTwoColumns; size_t itsLeftColStartX; size_t itsLeftColWidth; @@ -149,6 +146,8 @@ public: MediaLibrary::MediaLibrary() : m_timer(boost::posix_time::from_time_t(0)) +, m_window_timeout(Config.data_fetching_delay ? 250 : 500) +, m_fetching_delay(boost::posix_time::milliseconds(Config.data_fetching_delay ? 250 : -1)) { hasTwoColumns = 0; itsLeftColWidth = COLS/3-1; @@ -342,7 +341,7 @@ void MediaLibrary::update() } if (!Tags.empty() - && ((Albums.reallyEmpty() && Global::Timer - m_timer > fetch_delay) || m_albums_update_request) + && ((Albums.reallyEmpty() && Global::Timer - m_timer > m_fetching_delay) || m_albums_update_request) ) { Albums.clearSearchResults(); @@ -390,7 +389,7 @@ void MediaLibrary::update() } if (!Albums.empty() - && ((Songs.reallyEmpty() && Global::Timer - m_timer > fetch_delay) || m_songs_update_request) + && ((Songs.reallyEmpty() && Global::Timer - m_timer > m_fetching_delay) || m_songs_update_request) ) { Songs.clearSearchResults(); @@ -427,7 +426,7 @@ void MediaLibrary::update() int MediaLibrary::windowTimeout() { if (Albums.reallyEmpty() || Songs.reallyEmpty()) - return ml_wtimeout; + return m_window_timeout; else return Screen::windowTimeout(); } diff --git a/src/media_library.h b/src/media_library.h index 63ae0348..e9d0fe22 100644 --- a/src/media_library.h +++ b/src/media_library.h @@ -150,6 +150,9 @@ private: bool m_songs_update_request; boost::posix_time::ptime m_timer; + + const int m_window_timeout; + const boost::posix_time::time_duration m_fetching_delay; }; extern MediaLibrary *myLibrary; diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index 0e37fe18..73621ded 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -45,9 +45,6 @@ PlaylistEditor *myPlaylistEditor; namespace { -const int pe_timeout = 250; -const auto fetch_delay = boost::posix_time::milliseconds(pe_timeout); - size_t LeftColumnStartX; size_t LeftColumnWidth; size_t RightColumnStartX; @@ -61,6 +58,8 @@ bool SongEntryMatcher(const boost::regex &rx, const MPD::Song &s); PlaylistEditor::PlaylistEditor() : m_timer(boost::posix_time::from_time_t(0)) +, m_window_timeout(Config.data_fetching_delay ? 250 : 500) +, m_fetching_delay(boost::posix_time::milliseconds(Config.data_fetching_delay ? 250 : -1)) { LeftColumnWidth = COLS/3-1; RightColumnStartX = LeftColumnWidth+1; @@ -158,7 +157,7 @@ void PlaylistEditor::update() } if (!Playlists.empty() - && ((Content.reallyEmpty() && Global::Timer - m_timer > fetch_delay) || m_content_update_requested) + && ((Content.reallyEmpty() && Global::Timer - m_timer > m_fetching_delay) || m_content_update_requested) ) { m_content_update_requested = false; @@ -212,7 +211,7 @@ void PlaylistEditor::update() int PlaylistEditor::windowTimeout() { if (Content.reallyEmpty()) - return pe_timeout; + return m_window_timeout; else return Screen::windowTimeout(); } diff --git a/src/playlist_editor.h b/src/playlist_editor.h index 803cfe6f..ce5a9943 100644 --- a/src/playlist_editor.h +++ b/src/playlist_editor.h @@ -95,6 +95,9 @@ private: bool m_content_update_requested; boost::posix_time::ptime m_timer; + + const int m_window_timeout; + const boost::posix_time::time_duration m_fetching_delay; }; extern PlaylistEditor *myPlaylistEditor; diff --git a/src/settings.cpp b/src/settings.cpp index 4eca50b4..69d003bc 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -400,6 +400,9 @@ bool Configuration::read(const std::string &config_path) p.add("user_interface", assign_default( design, Design::Classic )); + p.add("data_fetching_delay", yes_no( + data_fetching_delay, true + )); p.add("media_library_primary_tag", option_parser::worker([this](std::string &&v) { if (v == "artist") media_lib_primary_tag = MPD_TAG_ARTIST; diff --git a/src/settings.h b/src/settings.h index ddb812ba..01959da8 100644 --- a/src/settings.h +++ b/src/settings.h @@ -153,6 +153,7 @@ struct Configuration bool mouse_list_scroll_whole_page; bool visualizer_use_wave; bool visualizer_in_stereo; + bool data_fetching_delay; bool media_library_sort_by_mtime; bool tag_editor_extended_numeration; bool discard_colors_if_item_is_selected;