summaryrefslogtreecommitdiff
path: root/src/clock.cpp
diff options
context:
space:
mode:
authorAndrzej Rybczak <electricityispower@gmail.com>2009-02-13 17:24:06 +0100
committerAndrzej Rybczak <electricityispower@gmail.com>2009-02-13 17:24:06 +0100
commit8ba72bc78ae92d1ed5b4cdfb81e4879680362961 (patch)
tree18bcc32991a8a8dc6872d7c8dc45eb58d229bd46 /src/clock.cpp
parent29301aefd5a9dae4163c29db37a069eef8004cc8 (diff)
separate some code from ncmpcpp.cpp
Diffstat (limited to 'src/clock.cpp')
-rw-r--r--src/clock.cpp85
1 files changed, 71 insertions, 14 deletions
diff --git a/src/clock.cpp b/src/clock.cpp
index 22d7ecff..88f549de 100644
--- a/src/clock.cpp
+++ b/src/clock.cpp
@@ -21,12 +21,17 @@
/// NOTICE: Major part of this code is ported from ncmpc's clock screen
#include "clock.h"
-#include "display.h"
-#include "global.h"
#ifdef ENABLE_CLOCK
+#include "display.h"
+#include "global.h"
#include "settings.h"
+#include "status_checker.h"
+
+using namespace Global;
+
+Scrollpad *Global::wClock;
namespace
{
@@ -52,14 +57,47 @@ namespace
}
}
-void InitClock()
+namespace Clock
+{
+ const size_t width = Config.clock_display_seconds ? 60 : 40;
+ const size_t height = 8;
+}
+
+void Clock::Init()
+{
+ wClock = new Scrollpad((COLS-width)/2, (LINES-height)/2, width, height-1, "", Config.main_color, Border(Config.main_color));
+ wClock->SetTimeout(ncmpcpp_window_timeout);
+}
+
+void Clock::Resize()
+{
+ if (width <= size_t(COLS) && height <= main_height)
+ {
+ wClock->MoveTo((COLS-width)/2, (LINES-height)/2);
+ if (current_screen == csClock)
+ {
+ mPlaylist->Hide();
+ Prepare();
+ wClock->Display();
+ }
+ }
+}
+
+void Clock::Prepare()
{
for (int i = 0; i < 5; i++)
older[i] = newer[i] = next[i] = 0;
}
-void Display::Clock(Window &w, const tm *time)
+void Clock::Update()
{
+ if (width > size_t(COLS) || height > main_height)
+ return;
+
+ time_t rawtime;
+ time(&rawtime);
+ tm *time = localtime(&rawtime);
+
mask = 0;
set(time->tm_sec % 10, 0);
set(time->tm_sec / 10, 4);
@@ -72,9 +110,9 @@ void Display::Clock(Window &w, const tm *time)
char buf[54];
strftime(buf, 64, "%x", time);
- attron(COLOR_PAIR(Global::Config.main_color));
- mvprintw(w.GetStartY()+w.GetHeight(), w.GetStartX()+(w.GetWidth()-strlen(buf))/2, "%s", buf);
- attroff(COLOR_PAIR(Global::Config.main_color));
+ attron(COLOR_PAIR(Config.main_color));
+ mvprintw(wCurrent->GetStartY()+wCurrent->GetHeight(), wCurrent->GetStartX()+(wCurrent->GetWidth()-strlen(buf))/2, "%s", buf);
+ attroff(COLOR_PAIR(Config.main_color));
refresh();
for (int k = 0; k < 6; k++)
@@ -83,7 +121,7 @@ void Display::Clock(Window &w, const tm *time)
next[k] = 0;
for (int s = 1; s >= 0; s--)
{
- w.Reverse(s);
+ wCurrent->Reverse(s);
for (int i = 0; i < 6; i++)
{
long a = (newer[i] ^ older[i]) & (s ? newer : older)[i];
@@ -96,10 +134,10 @@ void Display::Clock(Window &w, const tm *time)
{
if (!(a & (t << 1)))
{
- w.GotoXY(2*j+2, i);
+ wCurrent->GotoXY(2*j+2, i);
}
if (Global::Config.clock_display_seconds || j < 18)
- w << " ";
+ *wCurrent << " ";
}
}
}
@@ -108,13 +146,32 @@ void Display::Clock(Window &w, const tm *time)
older[i] = newer[i];
}
}
- if (!s)
- {
- w.Refresh();
- }
}
}
}
+void Clock::SwitchTo()
+{
+ if (width > size_t(COLS) || height > main_height)
+ {
+ ShowMessage("Screen is too small to display clock!");
+ }
+ else if (
+ current_screen != csClock
+# ifdef HAVE_TAGLIB_H
+ && current_screen != csTinyTagEditor
+# endif // HAVE_TAGLIB_H
+ )
+ {
+ CLEAR_FIND_HISTORY;
+ wCurrent = wClock;
+ mPlaylist->Hide();
+ current_screen = csClock;
+ redraw_header = 1;
+ Clock::Prepare();
+ wCurrent->Display();
+ }
+}
+
#endif // ENABLE_CLOCK