summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac7
-rw-r--r--src/actions.cpp7
-rw-r--r--src/clock.cpp17
-rw-r--r--src/global.cpp2
-rw-r--r--src/global.h5
-rw-r--r--src/ncmpcpp.cpp13
-rw-r--r--src/playlist.cpp18
-rw-r--r--src/playlist.h6
-rw-r--r--src/server_info.cpp7
-rw-r--r--src/server_info.h2
-rw-r--r--src/settings.cpp10
-rw-r--r--src/settings.h6
-rw-r--r--src/status.cpp19
-rw-r--r--src/statusbar.cpp16
-rw-r--r--src/statusbar.h10
-rw-r--r--src/visualizer.cpp5
-rw-r--r--src/visualizer.h3
17 files changed, 75 insertions, 78 deletions
diff --git a/configure.ac b/configure.ac
index 3cf11b29..d64ec02d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -139,6 +139,13 @@ AC_CHECK_LIB(boost_locale$BOOST_LIB_SUFFIX, main, LDFLAGS="$LDFLAGS -lboost_loca
AC_MSG_ERROR([no boost.locale library found])
)
+dnl =================================
+dnl = checking for boost.posix_time =
+dnl =================================
+AC_CHECK_HEADERS([boost/date_time/posix_time/posix_time.hpp], ,
+ AC_MSG_ERROR(boost/date_time/posix_time/posix_time.hpp is missing)
+)
+
dnl ============================
dnl = checking for boost.regex =
dnl ============================
diff --git a/src/actions.cpp b/src/actions.cpp
index 0902f430..138aaefb 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -2593,7 +2593,7 @@ void seek()
Statusbar::lock();
unsigned songpos = Status::State::elapsedTime();
- timeval t = Timer;
+ auto t = Timer;
int old_timeout = wFooter->getTimeout();
wFooter->setTimeout(500);
@@ -2605,9 +2605,10 @@ void seek()
while (true)
{
Status::trace();
- myPlaylist->UpdateTimer();
- unsigned howmuch = Config.incremental_seeking ? (Timer.tv_sec-t.tv_sec)/2+Config.seek_time : Config.seek_time;
+ unsigned howmuch = Config.incremental_seeking
+ ? (Timer-t).seconds()/2+Config.seek_time
+ : Config.seek_time;
Key input = Key::read(*wFooter);
auto k = Bindings.get(input);
diff --git a/src/clock.cpp b/src/clock.cpp
index 8c6131e8..78867e6c 100644
--- a/src/clock.cpp
+++ b/src/clock.cpp
@@ -25,7 +25,6 @@
#ifdef ENABLE_CLOCK
#include <cstring>
-#include <sys/time.h>
#include "global.h"
#include "playlist.h"
@@ -115,20 +114,20 @@ void Clock::update()
myPlaylist->switchTo();
}
- std::tm *time = std::localtime(&Global::Timer.tv_sec);
+ auto time = boost::posix_time::to_tm(Global::Timer);
mask = 0;
- Set(time->tm_sec % 10, 0);
- Set(time->tm_sec / 10, 4);
- Set(time->tm_min % 10, 10);
- Set(time->tm_min / 10, 14);
- Set(time->tm_hour % 10, 20);
- Set(time->tm_hour / 10, 24);
+ Set(time.tm_sec % 10, 0);
+ Set(time.tm_sec / 10, 4);
+ Set(time.tm_min % 10, 10);
+ Set(time.tm_min / 10, 14);
+ Set(time.tm_hour % 10, 20);
+ Set(time.tm_hour / 10, 24);
Set(10, 7);
Set(10, 17);
char buf[64];
- std::strftime(buf, 64, "%x", time);
+ std::strftime(buf, 64, "%x", &time);
attron(COLOR_PAIR(int(Config.main_color)));
mvprintw(w.getStarty()+w.getHeight(), w.getStartX()+(w.getWidth()-strlen(buf))/2, "%s", buf);
attroff(COLOR_PAIR(int(Config.main_color)));
diff --git a/src/global.cpp b/src/global.cpp
index be5d1beb..2cc86bf0 100644
--- a/src/global.cpp
+++ b/src/global.cpp
@@ -36,6 +36,6 @@ bool ShowMessages = false;
bool SeekingInProgress = false;
std::string VolumeState;
-timeval Timer;
+boost::posix_time::ptime Timer;
}
diff --git a/src/global.h b/src/global.h
index dea63812..7b3dc73d 100644
--- a/src/global.h
+++ b/src/global.h
@@ -21,8 +21,7 @@
#ifndef NCMPCPP_GLOBAL_H
#define NCMPCPP_GLOBAL_H
-#include <sys/time.h>
-
+#include <boost/date_time/posix_time/posix_time.hpp>
#include "mpdpp.h"
#include "screen.h"
@@ -57,7 +56,7 @@ extern bool SeekingInProgress;
extern std::string VolumeState;
// global timer
-extern timeval Timer;
+extern boost::posix_time::ptime Timer;
}
diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp
index b31d5aed..e6dd2cfb 100644
--- a/src/ncmpcpp.cpp
+++ b/src/ncmpcpp.cpp
@@ -22,7 +22,6 @@
#include <clocale>
#include <csignal>
#include <cstring>
-#include <sys/time.h>
#include <boost/locale.hpp>
#include <iostream>
@@ -160,15 +159,14 @@ int main(int argc, char **argv)
wFooter->setGetStringHelper(Statusbar::Helpers::getString);
// initialize global timer
- gettimeofday(&Timer, 0);
+ Timer = boost::posix_time::microsec_clock::local_time();
// go to playlist
myPlaylist->switchTo();
- myPlaylist->UpdateTimer();
// local variables
Key input(0, Key::Standard);
- timeval past = { 0, 0 };
+ boost::posix_time::ptime past = boost::posix_time::from_time_t(0);
// local variables end
mouseinterval(0);
@@ -237,14 +235,13 @@ int main(int argc, char **argv)
}
// header stuff
- if (((Timer.tv_sec == past.tv_sec && Timer.tv_usec >= past.tv_usec+500000) || Timer.tv_sec > past.tv_sec)
- && (myScreen == myPlaylist || myScreen == myBrowser || myScreen == myLyrics)
+ if ((myScreen == myPlaylist || myScreen == myBrowser || myScreen == myLyrics)
+ && (Timer - past > boost::posix_time::milliseconds(500))
)
{
drawHeader();
past = Timer;
}
- // header stuff end
if (input != Key::noOp)
myScreen->refreshWindow();
@@ -272,7 +269,7 @@ int main(int argc, char **argv)
# ifdef ENABLE_VISUALIZER
// visualizer sets timeout to 40ms, but since only it needs such small
- // value, we should restore defalt one after switching to another screen.
+ // value, we should restore default one after switching to another screen.
if (wFooter->getTimeout() < 500
&& !(myScreen == myVisualizer || myLockedScreen == myVisualizer || myInactiveScreen == myVisualizer)
)
diff --git a/src/playlist.cpp b/src/playlist.cpp
index 0775e7a7..6d05cbd7 100644
--- a/src/playlist.cpp
+++ b/src/playlist.cpp
@@ -97,6 +97,17 @@ std::wstring Playlist::title()
return result;
}
+void Playlist::update()
+{
+ if (Config.playlist_disable_highlight_delay.time_duration::seconds() > 0
+ && w.isHighlighted()
+ && Global::Timer - itsTimer > Config.playlist_disable_highlight_delay)
+ {
+ w.setHighlighting(false);
+ w.refresh();
+ }
+}
+
void Playlist::enterPressed()
{
if (!w.empty())
@@ -260,12 +271,7 @@ void Playlist::Reverse()
void Playlist::EnableHighlighting()
{
w.setHighlighting(true);
- UpdateTimer();
-}
-
-void Playlist::UpdateTimer()
-{
- std::time(&itsTimer);
+ itsTimer = Global::Timer;
}
std::string Playlist::TotalLength()
diff --git a/src/playlist.h b/src/playlist.h
index 851aa642..2ce02e57 100644
--- a/src/playlist.h
+++ b/src/playlist.h
@@ -38,7 +38,7 @@ struct Playlist: Screen<NC::Menu<MPD::Song>>, Filterable, HasSongs, Searchable,
virtual std::wstring title() OVERRIDE;
virtual ScreenType type() OVERRIDE { return ScreenType::Playlist; }
- virtual void update() OVERRIDE { }
+ virtual void update() OVERRIDE;
virtual void enterPressed() OVERRIDE;
virtual void spacePressed() OVERRIDE;
@@ -71,8 +71,6 @@ struct Playlist: Screen<NC::Menu<MPD::Song>>, Filterable, HasSongs, Searchable,
void Reverse();
void EnableHighlighting();
- void UpdateTimer();
- time_t Timer() const { return itsTimer; }
void SetSelectedItemsPriority(int prio);
@@ -101,7 +99,7 @@ private:
size_t itsRemainingTime;
size_t itsScrollBegin;
- time_t itsTimer;
+ boost::posix_time::ptime itsTimer;
MPD::Status m_status;
unsigned m_old_playlist_version;
diff --git a/src/server_info.cpp b/src/server_info.cpp
index bb433727..bccf70f4 100644
--- a/src/server_info.cpp
+++ b/src/server_info.cpp
@@ -18,7 +18,6 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#include <sys/time.h>
#include <iomanip>
#include "global.h"
@@ -75,10 +74,10 @@ std::wstring ServerInfo::title()
void ServerInfo::update()
{
- static timeval past = { 0, 0 };
- if (Global::Timer.tv_sec <= past.tv_sec)
+ Statusbar::printf("%1%, %2%", Global::Timer, m_timer);
+ if (Global::Timer - m_timer < boost::posix_time::seconds(1))
return;
- past = Global::Timer;
+ m_timer = Global::Timer;
MPD::Statistics stats = Mpd.getStatistics();
if (stats.empty())
diff --git a/src/server_info.h b/src/server_info.h
index 3b9d9338..26313aaa 100644
--- a/src/server_info.h
+++ b/src/server_info.h
@@ -48,6 +48,8 @@ protected:
private:
void SetDimensions();
+ boost::posix_time::ptime m_timer;
+
MPD::StringList itsURLHandlers;
MPD::StringList itsTagTypes;
diff --git a/src/settings.cpp b/src/settings.cpp
index 9a12c97f..f8475721 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -188,13 +188,13 @@ void Configuration::SetDefaults()
crossfade_time = 5;
seek_time = 1;
volume_change_step = 1;
- playlist_disable_highlight_delay = 5;
+ playlist_disable_highlight_delay = boost::posix_time::seconds(5);
message_delay_time = 4;
lyrics_db = 0;
regex_type = boost::regex::literal | boost::regex::icase;
lines_scrolled = 2;
search_engine_default_search_mode = 0;
- visualizer_sync_interval = 30;
+ visualizer_sync_interval = boost::posix_time::seconds(30);
locked_screen_width_part = 0.5;
selected_item_prefix_length = 0;
selected_item_suffix_length = 0;
@@ -212,6 +212,7 @@ void Configuration::SetDefaults()
}
Configuration::Configuration()
+: playlist_disable_highlight_delay(0), visualizer_sync_interval(0)
{
# ifdef WIN32
ncmpcpp_directory = GetHomeDirectory() + "ncmpcpp/";
@@ -338,8 +339,7 @@ void Configuration::Read()
}
else if (name == "playlist_disable_highlight_delay")
{
- if (boost::lexical_cast<int>(v) >= 0)
- playlist_disable_highlight_delay = boost::lexical_cast<int>(v);
+ playlist_disable_highlight_delay = boost::posix_time::seconds(boost::lexical_cast<int>(v));
}
else if (name == "message_delay_time")
{
@@ -762,7 +762,7 @@ void Configuration::Read()
{
unsigned interval = boost::lexical_cast<unsigned>(v);
if (interval)
- visualizer_sync_interval = interval;
+ visualizer_sync_interval = boost::posix_time::seconds(interval);
}
else if (name == "browser_sort_mode")
{
diff --git a/src/settings.h b/src/settings.h
index c8d77014..976d4beb 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -21,6 +21,7 @@
#ifndef NCMPCPP_SETTINGS_H
#define NCMPCPP_SETTINGS_H
+#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/regex.hpp>
#include <cassert>
#include <vector>
@@ -171,7 +172,6 @@ struct Configuration
int crossfade_time;
int seek_time;
int volume_change_step;
- int playlist_disable_highlight_delay;
int message_delay_time;
int lyrics_db;
@@ -179,7 +179,9 @@ struct Configuration
unsigned lines_scrolled;
unsigned search_engine_default_search_mode;
- unsigned visualizer_sync_interval;
+
+ boost::posix_time::seconds playlist_disable_highlight_delay;
+ boost::posix_time::seconds visualizer_sync_interval;
double locked_screen_width_part;
diff --git a/src/status.cpp b/src/status.cpp
index 60abbf1f..865a3b5e 100644
--- a/src/status.cpp
+++ b/src/status.cpp
@@ -18,8 +18,6 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#include <sys/time.h>
-
#include "browser.h"
#include "charset.h"
#include "global.h"
@@ -49,7 +47,7 @@ using Global::VolumeState;
namespace {//
-timeval past = { 0, 0 };
+boost::posix_time::ptime past = boost::posix_time::from_time_t(0);
size_t playing_song_scroll_begin = 0;
size_t first_line_scroll_begin = 0;
@@ -135,10 +133,11 @@ void Status::handleServerError(MPD::ServerError &e)
void Status::trace()
{
- gettimeofday(&Timer, 0);
+ Timer = boost::posix_time::microsec_clock::local_time();
if (Mpd.Connected())
{
- if (State::player() == MPD::psPlay && Global::Timer.tv_sec > past.tv_sec)
+ if (State::player() == MPD::psPlay
+ && Global::Timer - past > boost::posix_time::seconds(1))
{
// update elapsed time/bitrate of the current song
Status::Changes::elapsedTime(true);
@@ -147,16 +146,6 @@ void Status::trace()
}
applyToVisibleWindows(&BaseScreen::update);
-
- if (isVisible(myPlaylist)
- && Timer.tv_sec == myPlaylist->Timer()+Config.playlist_disable_highlight_delay
- && myPlaylist->main().isHighlighted()
- && Config.playlist_disable_highlight_delay)
- {
- myPlaylist->main().setHighlighting(false);
- myPlaylist->main().refresh();
- }
-
Statusbar::tryRedraw();
Mpd.idle();
diff --git a/src/statusbar.cpp b/src/statusbar.cpp
index 959d7e03..655c8011 100644
--- a/src/statusbar.cpp
+++ b/src/statusbar.cpp
@@ -30,8 +30,8 @@ using Global::wFooter;
namespace {//
-timeval statusbarLockTime;
-int statusbarLockDelay = -1;
+boost::posix_time::ptime statusbarLockTime;
+boost::posix_time::seconds statusbarLockDelay(-1);
bool statusbarBlockUpdate = false;
bool progressbarBlockUpdate = false;
@@ -97,7 +97,7 @@ void Statusbar::lock()
void Statusbar::unlock()
{
statusbarAllowUnlock = true;
- if (statusbarLockDelay < 0)
+ if (statusbarLockDelay.is_negative())
{
if (Config.statusbar_visibility)
statusbarBlockUpdate = false;
@@ -122,10 +122,10 @@ bool Statusbar::isUnlocked()
void Statusbar::tryRedraw()
{
using Global::Timer;
- if (statusbarLockDelay > 0
- && Timer.tv_sec >= statusbarLockTime.tv_sec+statusbarLockDelay)
+ if (statusbarLockDelay > boost::posix_time::seconds(0)
+ && Timer - statusbarLockTime > statusbarLockDelay)
{
- statusbarLockDelay = -1;
+ statusbarLockDelay = boost::posix_time::seconds(-1);
if (Config.statusbar_visibility)
statusbarBlockUpdate = !statusbarAllowUnlock;
@@ -149,12 +149,12 @@ NC::Window &Statusbar::put()
return *wFooter;
}
-void Statusbar::print(int time, const std::string &message)
+void Statusbar::print(int delay, const std::string &message)
{
if (statusbarAllowUnlock)
{
statusbarLockTime = Global::Timer;
- statusbarLockDelay = time;
+ statusbarLockDelay = boost::posix_time::seconds(delay);
if (Config.statusbar_visibility)
statusbarBlockUpdate = true;
else
diff --git a/src/statusbar.h b/src/statusbar.h
index 810076e3..a1d25479 100644
--- a/src/statusbar.h
+++ b/src/statusbar.h
@@ -94,7 +94,7 @@ private:
}
/// displays message in statusbar for a given period of time
-void print(int time, const std::string &message);
+void print(int delay, const std::string& message);
/// displays message in statusbar for period of time set in configuration file
inline void print(const std::string &message)
@@ -118,14 +118,14 @@ void printf(FormatT &&fmt, ArgT &&arg, Args&&... args)
/// displays formatted message in statusbar for a given period of time
template <typename FormatT>
-void printf(int time, FormatT &&fmt)
+void printf(int delay, FormatT &&fmt)
{
- print(time, boost::format(std::forward<FormatT>(fmt)).str());
+ print(delay, boost::format(std::forward<FormatT>(fmt)).str());
}
template <typename FormatT, typename ArgT, typename... Args>
-void printf(int time, FormatT &&fmt, ArgT &&arg, Args&&... args)
+void printf(int delay, FormatT &&fmt, ArgT &&arg, Args&&... args)
{
- printf(time, boost::format(std::forward<FormatT>(fmt)) % std::forward<ArgT>(arg),
+ printf(delay, boost::format(std::forward<FormatT>(fmt)) % std::forward<ArgT>(arg),
std::forward<Args>(args)...
);
}
diff --git a/src/visualizer.cpp b/src/visualizer.cpp
index 6b19be4f..e405e367 100644
--- a/src/visualizer.cpp
+++ b/src/visualizer.cpp
@@ -28,8 +28,6 @@
#include <fstream>
#include <limits>
#include <fcntl.h>
-#include <sys/time.h>
-#include <unistd.h>
#include "global.h"
#include "settings.h"
@@ -64,7 +62,6 @@ void Visualizer::switchTo()
SwitchTo::execute(this);
w.clear();
SetFD();
- m_timer = { 0, 0 };
if (m_fifo >= 0)
Global::wFooter->setTimeout(WindowTimeout);
drawHeader();
@@ -95,7 +92,7 @@ void Visualizer::update()
if (data < 0) // no data available in fifo
return;
- if (m_output_id != -1 && Global::Timer.tv_sec > m_timer.tv_sec+Config.visualizer_sync_interval)
+ if (m_output_id != -1 && Global::Timer - m_timer > Config.visualizer_sync_interval)
{
Mpd.DisableOutput(m_output_id);
usleep(50000);
diff --git a/src/visualizer.h b/src/visualizer.h
index f90fe354..3a9a8573 100644
--- a/src/visualizer.h
+++ b/src/visualizer.h
@@ -25,6 +25,7 @@
#ifdef ENABLE_VISUALIZER
+#include <boost/date_time/posix_time/posix_time_types.hpp>
#include "interfaces.h"
#include "screen.h"
#include "window.h"
@@ -69,7 +70,7 @@ private:
# endif // HAVE_FFTW3_H
int m_output_id;
- timeval m_timer;
+ boost::posix_time::ptime m_timer;
int m_fifo;
unsigned m_samples;