browser: refresh browser on database update properly
This commit is contained in:
@@ -718,10 +718,9 @@ void DeleteBrowserItems::run()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myBrowser->isLocal())
|
if (!myBrowser->isLocal())
|
||||||
myBrowser->getDirectory(myBrowser->currentDirectory());
|
|
||||||
else
|
|
||||||
Mpd.UpdateDirectory(myBrowser->currentDirectory());
|
Mpd.UpdateDirectory(myBrowser->currentDirectory());
|
||||||
|
myBrowser->requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeleteStoredPlaylist::canBeRun() const
|
bool DeleteStoredPlaylist::canBeRun() const
|
||||||
@@ -1443,7 +1442,7 @@ void EditDirectoryName::run()
|
|||||||
Statusbar::printf(msg, wideShorten(new_dir, COLS-const_strlen(msg)));
|
Statusbar::printf(msg, wideShorten(new_dir, COLS-const_strlen(msg)));
|
||||||
if (!myBrowser->isLocal())
|
if (!myBrowser->isLocal())
|
||||||
Mpd.UpdateDirectory(getSharedDirectory(old_dir, new_dir));
|
Mpd.UpdateDirectory(getSharedDirectory(old_dir, new_dir));
|
||||||
myBrowser->getDirectory(myBrowser->currentDirectory());
|
myBrowser->requestUpdate();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -71,7 +71,11 @@ bool browserEntryMatcher(const boost::regex &rx, const MPD::Item &item, bool fil
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Browser::Browser() : m_local_browser(false), m_scroll_beginning(0), m_current_directory("/")
|
Browser::Browser()
|
||||||
|
: m_update_request(true)
|
||||||
|
, m_local_browser(false)
|
||||||
|
, m_scroll_beginning(0)
|
||||||
|
, m_current_directory("/")
|
||||||
{
|
{
|
||||||
w = NC::Menu<MPD::Item>(0, MainStartY, COLS, MainHeight, Config.browser_display_mode == DisplayMode::Columns && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, NC::Border());
|
w = NC::Menu<MPD::Item>(0, MainStartY, COLS, MainHeight, Config.browser_display_mode == DisplayMode::Columns && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, NC::Border());
|
||||||
w.setHighlightColor(Config.main_highlight_color);
|
w.setHighlightColor(Config.main_highlight_color);
|
||||||
@@ -117,6 +121,38 @@ std::wstring Browser::title()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Browser::update()
|
||||||
|
{
|
||||||
|
if (m_update_request)
|
||||||
|
{
|
||||||
|
m_update_request = false;
|
||||||
|
bool directory_changed = false;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
getDirectory(m_current_directory);
|
||||||
|
w.refresh();
|
||||||
|
}
|
||||||
|
catch (MPD::ServerError &err)
|
||||||
|
{
|
||||||
|
// If current directory doesn't exist, try getting its
|
||||||
|
// parent until we either succeed or reach the root.
|
||||||
|
if (err.code() == MPD_SERVER_ERROR_NO_EXIST)
|
||||||
|
{
|
||||||
|
m_current_directory = getParentDirectory(m_current_directory);
|
||||||
|
directory_changed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (w.empty() && !inRootDirectory());
|
||||||
|
if (directory_changed)
|
||||||
|
drawHeader();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Browser::enterPressed()
|
void Browser::enterPressed()
|
||||||
{
|
{
|
||||||
if (w.empty())
|
if (w.empty())
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ struct Browser: Screen<NC::Menu<MPD::Item>>, HasSongs, Searchable, Tabbable
|
|||||||
virtual std::wstring title() OVERRIDE;
|
virtual std::wstring title() OVERRIDE;
|
||||||
virtual ScreenType type() OVERRIDE { return ScreenType::Browser; }
|
virtual ScreenType type() OVERRIDE { return ScreenType::Browser; }
|
||||||
|
|
||||||
virtual void update() OVERRIDE { }
|
virtual void update() OVERRIDE;
|
||||||
|
|
||||||
virtual void enterPressed() OVERRIDE;
|
virtual void enterPressed() OVERRIDE;
|
||||||
virtual void spacePressed() OVERRIDE;
|
virtual void spacePressed() OVERRIDE;
|
||||||
@@ -59,6 +59,8 @@ struct Browser: Screen<NC::Menu<MPD::Item>>, HasSongs, Searchable, Tabbable
|
|||||||
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
|
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
|
||||||
|
|
||||||
// private members
|
// private members
|
||||||
|
void requestUpdate() { m_update_request = true; }
|
||||||
|
|
||||||
bool inRootDirectory();
|
bool inRootDirectory();
|
||||||
bool isParentDirectory(const MPD::Item &item);
|
bool isParentDirectory(const MPD::Item &item);
|
||||||
const std::string ¤tDirectory();
|
const std::string ¤tDirectory();
|
||||||
@@ -75,6 +77,7 @@ protected:
|
|||||||
virtual bool isLockable() OVERRIDE { return true; }
|
virtual bool isLockable() OVERRIDE { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool m_update_request;
|
||||||
bool m_local_browser;
|
bool m_local_browser;
|
||||||
size_t m_scroll_beginning;
|
size_t m_scroll_beginning;
|
||||||
std::string m_current_directory;
|
std::string m_current_directory;
|
||||||
|
|||||||
@@ -69,6 +69,26 @@ bool fetchItemSong(MPD::SongIterator::State &state)
|
|||||||
|
|
||||||
namespace MPD {
|
namespace MPD {
|
||||||
|
|
||||||
|
void checkConnectionErrors(mpd_connection *conn)
|
||||||
|
{
|
||||||
|
mpd_error code = mpd_connection_get_error(conn);
|
||||||
|
if (code != MPD_ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
std::string msg = mpd_connection_get_error_message(conn);
|
||||||
|
if (code == MPD_ERROR_SERVER)
|
||||||
|
{
|
||||||
|
mpd_server_error server_code = mpd_connection_get_server_error(conn);
|
||||||
|
bool clearable = mpd_connection_clear_error(conn);
|
||||||
|
throw ServerError(server_code, msg, clearable);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool clearable = mpd_connection_clear_error(conn);
|
||||||
|
throw ClientError(code, msg, clearable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Connection::Connection() : m_connection(nullptr),
|
Connection::Connection() : m_connection(nullptr),
|
||||||
m_command_list_active(false),
|
m_command_list_active(false),
|
||||||
m_idle(false),
|
m_idle(false),
|
||||||
@@ -817,22 +837,7 @@ void Connection::prechecksNoCommandsList()
|
|||||||
|
|
||||||
void Connection::checkErrors() const
|
void Connection::checkErrors() const
|
||||||
{
|
{
|
||||||
mpd_error code = mpd_connection_get_error(m_connection.get());
|
checkConnectionErrors(m_connection.get());
|
||||||
if (code != MPD_ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
std::string msg = mpd_connection_get_error_message(m_connection.get());
|
|
||||||
if (code == MPD_ERROR_SERVER)
|
|
||||||
{
|
|
||||||
mpd_server_error server_code = mpd_connection_get_server_error(m_connection.get());
|
|
||||||
bool clearable = mpd_connection_clear_error(m_connection.get());
|
|
||||||
throw ServerError(server_code, msg, clearable);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool clearable = mpd_connection_clear_error(m_connection.get());
|
|
||||||
throw ClientError(code, msg, clearable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/mpdpp.h
11
src/mpdpp.h
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
namespace MPD {
|
namespace MPD {
|
||||||
|
|
||||||
|
void checkConnectionErrors(mpd_connection *conn);
|
||||||
|
|
||||||
enum PlayerState { psUnknown, psStop, psPlay, psPause };
|
enum PlayerState { psUnknown, psStop, psPlay, psPause };
|
||||||
enum ReplayGainMode { rgmOff, rgmTrack, rgmAlbum };
|
enum ReplayGainMode { rgmOff, rgmTrack, rgmAlbum };
|
||||||
|
|
||||||
@@ -398,10 +400,17 @@ struct Iterator: std::iterator<std::input_iterator_tag, ObjectT>
|
|||||||
// get the first element
|
// get the first element
|
||||||
++*this;
|
++*this;
|
||||||
}
|
}
|
||||||
|
~Iterator()
|
||||||
|
{
|
||||||
|
if (m_state)
|
||||||
|
checkConnectionErrors(m_state->connection());
|
||||||
|
}
|
||||||
|
|
||||||
void finish()
|
void finish()
|
||||||
{
|
{
|
||||||
// change the iterator into end iterator
|
assert(m_state);
|
||||||
|
// check errors and change the iterator into end iterator
|
||||||
|
checkConnectionErrors(m_state->connection());
|
||||||
m_state = nullptr;
|
m_state = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -450,19 +450,12 @@ void Status::Changes::storedPlaylists()
|
|||||||
myPlaylistEditor->requestPlaylistsUpdate();
|
myPlaylistEditor->requestPlaylistsUpdate();
|
||||||
myPlaylistEditor->requestContentsUpdate();
|
myPlaylistEditor->requestContentsUpdate();
|
||||||
if (!myBrowser->isLocal() && myBrowser->inRootDirectory())
|
if (!myBrowser->isLocal() && myBrowser->inRootDirectory())
|
||||||
{
|
myBrowser->requestUpdate();
|
||||||
myBrowser->getDirectory("/");
|
|
||||||
if (isVisible(myBrowser))
|
|
||||||
myBrowser->refresh();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Status::Changes::database()
|
void Status::Changes::database()
|
||||||
{
|
{
|
||||||
if (isVisible(myBrowser))
|
myBrowser->requestUpdate();
|
||||||
myBrowser->getDirectory(myBrowser->currentDirectory());
|
|
||||||
else
|
|
||||||
myBrowser->main().clear();
|
|
||||||
# ifdef HAVE_TAGLIB_H
|
# ifdef HAVE_TAGLIB_H
|
||||||
myTagEditor->Dirs->clear();
|
myTagEditor->Dirs->clear();
|
||||||
# endif // HAVE_TAGLIB_H
|
# endif // HAVE_TAGLIB_H
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ void TinyTagEditor::enterPressed()
|
|||||||
if (m_previous_screen == myPlaylist)
|
if (m_previous_screen == myPlaylist)
|
||||||
myPlaylist->main().current()->value() = itsEdited;
|
myPlaylist->main().current()->value() = itsEdited;
|
||||||
else if (m_previous_screen == myBrowser)
|
else if (m_previous_screen == myBrowser)
|
||||||
myBrowser->getDirectory(myBrowser->currentDirectory());
|
myBrowser->requestUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user