Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/screens/lyrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool saveLyrics(const std::string &filename, const std::string &lyrics)
return false;
}

boost::optional<std::string> downloadLyrics(
std::optional<std::string> downloadLyrics(
const MPD::Song &s,
std::shared_ptr<Shared<NC::Buffer>> shared_buffer,
std::shared_ptr<std::atomic<bool>> download_stopper,
Expand Down Expand Up @@ -172,7 +172,7 @@ boost::optional<std::string> downloadLyrics(
for (auto &fetcher : Config.lyrics_fetchers)
{
if (download_stopper && download_stopper->load())
return boost::none;
return std::nullopt;
fetcher_result = fetch_lyrics(fetcher);
if (fetcher_result.first)
break;
Expand All @@ -181,7 +181,7 @@ boost::optional<std::string> downloadLyrics(
else
fetcher_result = fetch_lyrics(current_fetcher);

boost::optional<std::string> result;
std::optional<std::string> result;
if (fetcher_result.first)
result = std::move(fetcher_result.second);
return result;
Expand Down Expand Up @@ -217,9 +217,9 @@ void Lyrics::update()
m_refresh_window = true;
}

if (m_worker.is_ready())
if (m_worker.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
{
auto lyrics = m_worker.get();
auto lyrics = m_worker.get();
if (lyrics)
{
w.clear();
Expand Down Expand Up @@ -290,8 +290,8 @@ void Lyrics::fetch(const MPD::Song &s)
{
m_download_stopper = std::make_shared<std::atomic<bool>>(false);
m_shared_buffer = std::make_shared<Shared<NC::Buffer>>();
m_worker = boost::async(
boost::launch::async,
m_worker = std::async(
std::launch::async,
std::bind(downloadLyrics,
m_song, m_shared_buffer, m_download_stopper, m_fetcher));
}
Expand Down Expand Up @@ -431,22 +431,22 @@ void Lyrics::fetchInBackground(const MPD::Song &s, bool notify_)
}
}

boost::optional<std::string> Lyrics::tryTakeConsumerMessage()
std::optional<std::string> Lyrics::tryTakeConsumerMessage()
{
boost::optional<std::string> result;
std::optional<std::string> result;
auto consumer = m_consumer_state.acquire();
if (consumer->message)
{
result = std::move(consumer->message);
consumer->message = boost::none;
consumer->message = std::nullopt;
}
return result;
}

void Lyrics::clearWorker()
{
m_shared_buffer.reset();
m_worker = boost::BOOST_THREAD_FUTURE<boost::optional<std::string>>();
m_worker = std::future<std::optional<std::string>>();
}

void Lyrics::stopDownload()
Expand Down
10 changes: 5 additions & 5 deletions src/screens/lyrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#define NCMPCPP_LYRICS_H

#include <atomic>
#include <boost/optional.hpp>
#include <boost/thread/future.hpp>
#include <optional>
#include <future>
#include <memory>
#include <queue>

Expand Down Expand Up @@ -56,7 +56,7 @@ struct Lyrics: Screen<NC::Scrollpad>, Tabbable
void toggleFetcher();

void fetchInBackground(const MPD::Song &s, bool notify_);
boost::optional<std::string> tryTakeConsumerMessage();
std::optional<std::string> tryTakeConsumerMessage();

private:
struct ConsumerState
Expand Down Expand Up @@ -85,7 +85,7 @@ struct Lyrics: Screen<NC::Scrollpad>, Tabbable

bool running;
std::queue<Song> songs;
boost::optional<std::string> message;
std::optional<std::string> message;
};

void clearWorker();
Expand All @@ -99,7 +99,7 @@ struct Lyrics: Screen<NC::Scrollpad>, Tabbable

MPD::Song m_song;
LyricsFetcher *m_fetcher;
boost::BOOST_THREAD_FUTURE<boost::optional<std::string>> m_worker;
std::future<std::optional<std::string>> m_worker;

Shared<ConsumerState> m_consumer_state;
};
Expand Down
Loading