set SIGWINCH handler before initializing ncurses to avoid races
[ncmpcpp.git] / src / statusbar.h
bloba1d25479f5178da29b04a4e624cc9300aae709d8
1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef NCMPCPP_STATUSBAR_H
22 #define NCMPCPP_STATUSBAR_H
24 #include <boost/format.hpp>
25 #include "settings.h"
26 #include "gcc.h"
27 #include "interfaces.h"
28 #include "window.h"
30 namespace Progressbar {//
32 /// locks progressbar (usually used for seeking)
33 void lock();
35 /// unlocks progressbar (usually right after seeking is done)
36 void unlock();
38 /// @return true if progressbar is unlocked
39 bool isUnlocked();
41 /// draws progressbar
42 void draw(unsigned elapsed, unsigned time);
46 namespace Statusbar{//
48 /// locks statusbar (usually for prompting the user)
49 void lock();
51 /// unlocks statusbar (usually after prompting the user)
52 void unlock();
54 /// @return true if statusbar is unlocked
55 bool isUnlocked();
57 /// tries to clear current message put there using Statusbar::printf if there is any
58 void tryRedraw();
60 /// clears statusbar and move cursor to beginning of line
61 /// @return window object that represents statusbar
62 NC::Window &put();
64 namespace Helpers {//
66 /// called when statusbar window detects incoming idle notification
67 void mpd();
69 /// called each time user types another character while inside Window::getString
70 bool getString(const char *);
72 /// called each time user changes current filter (while being inside Window::getString)
73 struct ApplyFilterImmediately
75 template <typename StringT>
76 ApplyFilterImmediately(Filterable *f, StringT &&filter)
77 : m_f(f), m_s(std::forward<StringT>(filter)) { }
79 bool operator()(const char *s);
81 private:
82 Filterable *m_f;
83 std::string m_s;
86 struct TryExecuteImmediateCommand
88 bool operator()(const char *s);
90 private:
91 std::string m_s;
96 /// displays message in statusbar for a given period of time
97 void print(int delay, const std::string& message);
99 /// displays message in statusbar for period of time set in configuration file
100 inline void print(const std::string &message)
102 print(Config.message_delay_time, message);
105 /// displays formatted message in statusbar for period of time set in configuration file
106 template <typename FormatT>
107 void printf(FormatT &&fmt)
109 print(Config.message_delay_time, boost::format(std::forward<FormatT>(fmt)).str());
111 template <typename FormatT, typename ArgT, typename... Args>
112 void printf(FormatT &&fmt, ArgT &&arg, Args&&... args)
114 printf(boost::format(std::forward<FormatT>(fmt)) % std::forward<ArgT>(arg),
115 std::forward<Args>(args)...
119 /// displays formatted message in statusbar for a given period of time
120 template <typename FormatT>
121 void printf(int delay, FormatT &&fmt)
123 print(delay, boost::format(std::forward<FormatT>(fmt)).str());
125 template <typename FormatT, typename ArgT, typename... Args>
126 void printf(int delay, FormatT &&fmt, ArgT &&arg, Args&&... args)
128 printf(delay, boost::format(std::forward<FormatT>(fmt)) % std::forward<ArgT>(arg),
129 std::forward<Args>(args)...
135 #endif // NCMPCPP_STATUSBAR_H