summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lyrics.cpp2
-rw-r--r--src/lyrics.h1
-rw-r--r--src/menu.h74
-rw-r--r--src/misc.cpp14
-rw-r--r--src/ncmpcpp.cpp4
-rw-r--r--src/scrollpad.cpp24
-rw-r--r--src/scrollpad.h3
-rw-r--r--src/settings.cpp2
-rw-r--r--src/settings.h2
-rw-r--r--src/status_checker.cpp14
-rw-r--r--src/tag_editor.cpp2
-rw-r--r--src/window.cpp140
-rw-r--r--src/window.h5
13 files changed, 111 insertions, 176 deletions
diff --git a/src/lyrics.cpp b/src/lyrics.cpp
index 2703bac1..3a7a62a6 100644
--- a/src/lyrics.cpp
+++ b/src/lyrics.cpp
@@ -19,6 +19,8 @@
***************************************************************************/
#include <sys/stat.h>
+#include <fstream>
+
#include "helpers.h"
#include "lyrics.h"
#include "settings.h"
diff --git a/src/lyrics.h b/src/lyrics.h
index 1d75cdd2..2d58f87c 100644
--- a/src/lyrics.h
+++ b/src/lyrics.h
@@ -23,7 +23,6 @@
#include "ncmpcpp.h"
-#include <fstream>
#ifdef HAVE_CURL_CURL_H
# include <pthread.h>
# include "curl/curl.h"
diff --git a/src/menu.h b/src/menu.h
index aae039ca..4a3a7b89 100644
--- a/src/menu.h
+++ b/src/menu.h
@@ -48,7 +48,7 @@ class Menu : public Window
typedef string (*ItemDisplayer) (const T &, void *, const Menu<T> *);
public:
- Menu(int startx, int starty, int width, int height, string title, Color color, Border border) : Window(startx, starty, width, height, title, color, border), itsItemDisplayer(0), itsItemDisplayerUserdata(0), itsSelectedPrefix("[.r]"), itsSelectedSuffix("[/r]"), itsStaticsNumber(0), itsBeginning(0), itsHighlight(0), itsHighlightColor(itsBaseColor), itsHighlightEnabled(1) { }
+ Menu(int, int, int, int, const string &, Color, Border);
Menu(const Menu &);
virtual ~Menu();
@@ -127,6 +127,19 @@ class Menu : public Window
};
template <class T>
+Menu<T>::Menu(int startx, int starty, int width, int height, const string &title, Color color, Border border) :
+ Window(startx, starty, width, height, title, color, border),
+ itsItemDisplayer(0),
+ itsItemDisplayerUserdata(0),
+ itsSelectedPrefix("[.r]"),
+ itsSelectedSuffix("[/r]"),
+ itsStaticsNumber(0),
+ itsBeginning(0),
+ itsHighlight(0),
+ itsHighlightColor(itsBaseColor),
+ itsHighlightEnabled(1) { }
+
+template <class T>
Menu<T>::Menu(const Menu &m) : Window(m)
{
for (T_const_iterator it = m.itsOptions.begin(); it != m.itsOptions.end(); it++)
@@ -355,7 +368,13 @@ void Menu<T>::Refresh(bool redraw_whole_window)
int ch = itsOptions[*it]->have_separator ? 0 : 32;
mvwhline(itsWindow,line, 0, ch, itsWidth);
- string option = DisplayOption(itsOptions[*it]->item);
+ string option;
+
+ if (itsOptions[*it]->selected)
+ option += itsSelectedPrefix;
+ option += DisplayOption(itsOptions[*it]->item);
+ if (itsOptions[*it]->selected)
+ option += itsSelectedSuffix;
int strlength = itsOptions[*it]->location != lLeft && BBEnabled ? Window::RealLength(option) : option.length();
@@ -386,10 +405,7 @@ void Menu<T>::Refresh(bool redraw_whole_window)
}
}
- if (itsOptions[*it]->selected)
- WriteXY(x, line, itsWidth, TO_WSTRING(itsSelectedPrefix + option + itsSelectedSuffix), 0);
- else
- WriteXY(x, line, itsWidth, TO_WSTRING(option), 0);
+ WriteXY(x, line, itsWidth, TO_WSTRING(option), 0);
if (!ch && (itsOptions[*it]->location == lCenter || itsOptions[*it]->location == lLeft))
{
@@ -415,7 +431,9 @@ void Menu<T>::Refresh(bool redraw_whole_window)
template <class T>
void Menu<T>::Go(Where where)
{
- if (Empty()) return;
+ if (Empty())
+ return;
+
int MaxHighlight = itsOptions.size()-1;
int MaxBeginning = itsOptions.size() < itsHeight ? 0 : itsOptions.size()-itsHeight;
int MaxCurrentHighlight = itsBeginning+itsHeight-1;
@@ -431,7 +449,9 @@ void Menu<T>::Go(Where where)
wscrl(itsWindow, -1);
}
if (itsHighlight == 0)
+ {
break;
+ }
else
{
NeedsRedraw.push_back(itsHighlight--);
@@ -439,10 +459,7 @@ void Menu<T>::Go(Where where)
}
if (is_static())
{
- if (itsHighlight == 0)
- Go(wDown);
- else
- Go(wUp);
+ itsHighlight == 0 ? Go(wDown) : Go(wUp);
}
break;
}
@@ -454,7 +471,9 @@ void Menu<T>::Go(Where where)
wscrl(itsWindow, 1);
}
if (itsHighlight == MaxHighlight)
+ {
break;
+ }
else
{
NeedsRedraw.push_back(itsHighlight++);
@@ -462,10 +481,7 @@ void Menu<T>::Go(Where where)
}
if (is_static())
{
- if (itsHighlight == MaxHighlight)
- Go(wUp);
- else
- Go(wDown);
+ itsHighlight == MaxHighlight ? Go(wUp) : Go(wDown);
}
break;
}
@@ -476,14 +492,12 @@ void Menu<T>::Go(Where where)
if (itsBeginning < 0)
{
itsBeginning = 0;
- if (itsHighlight < 0) itsHighlight = 0;
+ if (itsHighlight < 0)
+ itsHighlight = 0;
}
if (is_static())
{
- if (itsHighlight == 0)
- Go(wDown);
- else
- Go(wUp);
+ itsHighlight == 0 ? Go(wDown) : Go(wUp);
}
redraw_screen();
break;
@@ -495,14 +509,12 @@ void Menu<T>::Go(Where where)
if (itsBeginning > MaxBeginning)
{
itsBeginning = MaxBeginning;
- if (itsHighlight > MaxHighlight) itsHighlight = MaxHighlight;
+ if (itsHighlight > MaxHighlight)
+ itsHighlight = MaxHighlight;
}
if (is_static())
{
- if (itsHighlight == MaxHighlight)
- Go(wUp);
- else
- Go(wDown);
+ itsHighlight == MaxHighlight ? Go(wUp) : Go(wDown);
}
redraw_screen();
break;
@@ -513,10 +525,7 @@ void Menu<T>::Go(Where where)
itsBeginning = 0;
if (is_static())
{
- if (itsHighlight == 0)
- Go(wDown);
- else
- Go(wUp);
+ itsHighlight == 0 ? Go(wDown) : Go(wUp);
}
redraw_screen();
break;
@@ -527,10 +536,7 @@ void Menu<T>::Go(Where where)
itsBeginning = MaxBeginning;
if (is_static())
{
- if (itsHighlight == MaxHighlight)
- Go(wUp);
- else
- Go(wDown);
+ itsHighlight == MaxHighlight ? Go(wUp) : Go(wDown);
}
redraw_screen();
break;
@@ -698,7 +704,7 @@ bool Menu<T>::IsStatic(int option) const
template <class T>
Window * Menu<T>::EmptyClone() const
{
- return new Menu(GetStartX(),GetStartY(),GetWidth(),GetHeight(),itsTitle,itsBaseColor,itsBorder);
+ return new Menu(GetStartX(), GetStartY(), GetWidth(), GetHeight(), itsTitle, itsBaseColor, itsBorder);
}
template <class T>
diff --git a/src/misc.cpp b/src/misc.cpp
index eb931054..f16c5f89 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -21,8 +21,6 @@
#include <algorithm>
#include "misc.h"
-using std::stringstream;
-
int Abs(int num)
{
return (num < 0 ? -num : num);
@@ -38,17 +36,17 @@ int StrToInt(string str)
return atoi(str.c_str());
}
-string IntoStr(int liczba)
+string IntoStr(int l)
{
- stringstream ss;
- ss << liczba;
+ std::stringstream ss;
+ ss << l;
return ss.str();
}
-string IntoStr(double liczba, int precision)
+string IntoStr(double l, int precision)
{
- stringstream ss;
- ss << std::fixed << std::setprecision(precision) << liczba;
+ std::stringstream ss;
+ ss << std::fixed << std::setprecision(precision) << l;
return ss.str();
}
diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp
index 8c451c69..cdf78895 100644
--- a/src/ncmpcpp.cpp
+++ b/src/ncmpcpp.cpp
@@ -101,7 +101,6 @@ MPDConnection *Mpd;
time_t timer;
int now_playing = -1;
-int playing_song_scroll_begin = 0;
int browsed_dir_scroll_begin = 0;
int stats_scroll_begin = 0;
@@ -182,7 +181,7 @@ int main(int argc, char *argv[])
if (!ConnectToMPD())
return -1;
- setlocale(LC_ALL,"");
+ setlocale(LC_ALL, "");
initscr();
noecho();
cbreak();
@@ -476,7 +475,6 @@ int main(int argc, char *argv[])
Mpd->AddSearch(Config.media_lib_primary_tag, mLibArtists->GetOption());
Mpd->StartFieldSearch(MPD_TAG_ITEM_ALBUM);
Mpd->CommitSearch(list);
- //sort(list.begin(), list.end());
}
for (TagList::const_iterator it = list.begin(); it != list.end(); it++)
{
diff --git a/src/scrollpad.cpp b/src/scrollpad.cpp
index 58d918e9..67b4b04d 100644
--- a/src/scrollpad.cpp
+++ b/src/scrollpad.cpp
@@ -20,6 +20,18 @@
#include "scrollpad.h"
+Scrollpad::Scrollpad(int startx, int starty, int width, int height, const string &title, Color color, Border border) :
+ Window(startx, starty, width, height, title, color, border),
+ itsBeginning(0),
+ itsRealHeight(1),
+ itsXPos(0)
+{
+ delwin(itsWindow);
+ itsWindow = newpad(itsHeight, itsWidth);
+ SetColor(itsColor);
+ keypad(itsWindow, 1);
+}
+
Scrollpad::Scrollpad(const Scrollpad &s) : Window(s)
{
itsContent = s.itsContent;
@@ -126,12 +138,13 @@ void Scrollpad::Recreate()
itsWindow = newpad(itsRealHeight, itsWidth);
SetTimeout(itsWindowTimeout);
SetColor(itsBaseColor, itsBgColor);
+ keypad(itsWindow, 1);
Write(itsContent.c_str());
}
void Scrollpad::Refresh(bool)
{
- prefresh(itsWindow,itsBeginning,0,itsStartY,itsStartX,itsStartY+itsHeight-1,itsStartX+itsWidth);
+ prefresh(itsWindow, itsBeginning, 0, itsStartY, itsStartX, itsStartY+itsHeight-1, itsStartX+itsWidth);
}
void Scrollpad::Resize(int width, int height)
@@ -140,8 +153,8 @@ void Scrollpad::Resize(int width, int height)
{
delwin(itsWinBorder);
itsWinBorder = newpad(height, width);
- wattron(itsWinBorder,COLOR_PAIR(itsBorder));
- box(itsWinBorder,0,0);
+ wattron(itsWinBorder, COLOR_PAIR(itsBorder));
+ box(itsWinBorder, 0, 0);
width -= 2;
height -= 2;
}
@@ -215,14 +228,15 @@ void Scrollpad::Clear(bool clear_screen)
wclear(itsWindow);
delwin(itsWindow);
itsWindow = newpad(itsHeight, itsWidth);
- SetColor(itsColor, itsBgColor);
SetTimeout(itsWindowTimeout);
+ SetColor(itsColor, itsBgColor);
+ keypad(itsWindow, 1);
if (clear_screen)
Window::Clear();
}
Window * Scrollpad::EmptyClone() const
{
- return new Scrollpad(GetStartX(),GetStartY(),GetWidth(),GetHeight(),itsTitle,itsBaseColor,itsBorder);
+ return new Scrollpad(GetStartX(), GetStartY(), GetWidth(), GetHeight(), itsTitle, itsBaseColor, itsBorder);
}
diff --git a/src/scrollpad.h b/src/scrollpad.h
index ee3df27d..3291b3ca 100644
--- a/src/scrollpad.h
+++ b/src/scrollpad.h
@@ -26,7 +26,7 @@
class Scrollpad: public Window
{
public:
- Scrollpad(int startx, int starty, int width, int height, string title, Color color, Border border) : Window(startx, starty, width, height, title, color, border), itsBeginning(0), itsRealHeight(1), itsXPos(0) { delwin(itsWindow); itsWindow = newpad(itsHeight,itsWidth); }
+ Scrollpad(int, int, int, int, const string &, Color, Border);
Scrollpad(const Scrollpad &);
virtual ~Scrollpad() {}
virtual void Add(string);
@@ -36,6 +36,7 @@ class Scrollpad: public Window
virtual void Clear(bool clear_screen = 1);
virtual Window * Clone() const { return new Scrollpad(*this); }
virtual Window * EmptyClone() const;
+
protected:
virtual void Recreate();
string itsContent;
diff --git a/src/settings.cpp b/src/settings.cpp
index b83051ab..3ea23e00 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -19,6 +19,8 @@
***************************************************************************/
#include <sys/stat.h>
+#include <fstream>
+
#include "settings.h"
const string config_file = config_dir + "config";
diff --git a/src/settings.h b/src/settings.h
index c36cd684..dd6b646d 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -21,8 +21,6 @@
#ifndef HAVE_SETTINGS_H
#define HAVE_SETTINGS_H
-#include <fstream>
-
#include "libmpdclient.h"
#include "ncmpcpp.h"
diff --git a/src/status_checker.cpp b/src/status_checker.cpp
index 58732deb..048af7db 100644
--- a/src/status_checker.cpp
+++ b/src/status_checker.cpp
@@ -40,26 +40,13 @@ extern Menu<string> *mEditorDirs;
extern Window *wHeader;
extern Window *wFooter;
-extern SongList vSearched;
-
extern time_t timer;
extern int now_playing;
-extern int playing_song_scroll_begin;
-
extern int lock_statusbar_delay;
extern string browsed_dir;
-extern string player_state;
-extern string volume_state;
-extern string switch_state;
-
-extern string mpd_repeat;
-extern string mpd_random;
-extern string mpd_crossfade;
-extern string mpd_db_updating;
-
extern NcmpcppScreen current_screen;
extern NcmpcppScreen prev_screen;
@@ -80,6 +67,7 @@ bool repeat_one_allowed = 0;
long long playlist_old_id = -1;
int old_playing;
+int playing_song_scroll_begin = 0;
time_t time_of_statusbar_lock;
time_t now;
diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp
index cd40e01a..7f087f3d 100644
--- a/src/tag_editor.cpp
+++ b/src/tag_editor.cpp
@@ -22,6 +22,8 @@
#ifdef HAVE_TAGLIB_H
+#include <fstream>
+
#include "id3v2tag.h"
#include "textidentificationframe.h"
#include "mpegfile.h"
diff --git a/src/window.cpp b/src/window.cpp
index 17d433c3..cfa28201 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -20,7 +20,23 @@
#include "window.h"
-Window::Window(int startx, int starty, int width, int height, const string &title, Color color, Border border) : itsWindow(0), itsWinBorder(0), itsGetStringHelper(0), itsStartX(startx), itsStartY(starty), itsWidth(width), itsHeight(height), itsWindowTimeout(-1), BBEnabled(1), AutoRefreshEnabled(1), itsTitle(title), itsColor(color), itsBaseColor(color), itsBgColor(clDefault), itsBaseBgColor(clDefault), itsBorder(border)
+Window::Window(int startx, int starty, int width, int height, const string &title, Color color, Border border) :
+ itsWindow(0),
+ itsWinBorder(0),
+ itsGetStringHelper(0),
+ itsStartX(startx),
+ itsStartY(starty),
+ itsWidth(width),
+ itsHeight(height),
+ itsWindowTimeout(-1),
+ BBEnabled(1),
+ AutoRefreshEnabled(1),
+ itsTitle(title),
+ itsColor(color),
+ itsBaseColor(color),
+ itsBgColor(clDefault),
+ itsBaseBgColor(clDefault),
+ itsBorder(border)
{
if (itsStartX < 0) itsStartX = 0;
if (itsStartY < 0) itsStartY = 0;
@@ -28,8 +44,8 @@ Window::Window(int startx, int starty, int width, int height, const string &titl
if (itsBorder != brNone)
{
itsWinBorder = newpad(itsHeight, itsWidth);
- wattron(itsWinBorder,COLOR_PAIR(itsBorder));
- box(itsWinBorder,0,0);
+ wattron(itsWinBorder, COLOR_PAIR(itsBorder));
+ box(itsWinBorder, 0, 0);
itsStartX++;
itsStartY++;
itsWidth -= 2;
@@ -47,6 +63,7 @@ Window::Window(int startx, int starty, int width, int height, const string &titl
itsWindow = newwin(0, 0, 0, 0);
SetColor(itsColor);
+ keypad(itsWindow, 1);
}
Window::Window(const Window &w)
@@ -78,9 +95,9 @@ Window::~Window()
void Window::SetColor(Color col, Color background)
{
if (col != clDefault)
- wattron(itsWindow,COLOR_PAIR(background*8+col));
+ wattron(itsWindow, COLOR_PAIR(background*8+col));
else
- wattroff(itsWindow,COLOR_PAIR(itsColor));
+ wattroff(itsWindow, COLOR_PAIR(itsColor));
itsColor = col;
itsBgColor = background;
}
@@ -104,8 +121,8 @@ void Window::SetBorder(Border border)
}
else if (border != brNone && itsBorder == brNone)
{
- itsWinBorder = newpad(itsHeight,itsWidth);
- wattron(itsWinBorder,COLOR_PAIR(border));
+ itsWinBorder = newpad(itsHeight, itsWidth);
+ wattron(itsWinBorder, COLOR_PAIR(border));
box(itsWinBorder,0,0);
itsStartX++;
itsStartY++;
@@ -116,7 +133,7 @@ void Window::SetBorder(Border border)
else
{
wattron(itsWinBorder,COLOR_PAIR(border));
- box(itsWinBorder,0,0);
+ box(itsWinBorder, 0, 0);
}
itsBorder = border;
}
@@ -148,6 +165,7 @@ void Window::Recreate()
itsWindow = newwin(itsHeight, itsWidth, itsStartY, itsStartX);
SetTimeout(itsWindowTimeout);
SetColor(itsColor, itsBgColor);
+ keypad(itsWindow, 1);
}
void Window::MoveTo(int newx, int newy)
@@ -175,8 +193,8 @@ void Window::Resize(int width, int height)
{
delwin(itsWinBorder);
itsWinBorder = newpad(height, width);
- wattron(itsWinBorder,COLOR_PAIR(itsBorder));
- box(itsWinBorder,0,0);
+ wattron(itsWinBorder, COLOR_PAIR(itsBorder));
+ box(itsWinBorder, 0, 0);
width -= 2;
height -= 2;
}
@@ -195,7 +213,7 @@ void Window::ShowBorder() const
if (itsBorder != brNone)
{
refresh();
- prefresh(itsWinBorder,0,0,GetStartY(),GetStartX(),itsStartY+itsHeight,itsStartX+itsWidth);
+ prefresh(itsWinBorder, 0, 0, GetStartY(), GetStartX(), itsStartY+itsHeight, itsStartX+itsWidth);
}
if (!itsTitle.empty())
{
@@ -264,7 +282,7 @@ void Window::SetTimeout(int timeout)
void Window::ReadKey(int &input) const
{
- keypad(itsWindow, TRUE); input = wgetch(itsWindow); keypad(itsWindow, FALSE);
+ input = wgetch(itsWindow);
}
void Window::ReadKey() const
@@ -288,8 +306,7 @@ void Window::Write(int limit, const string &str, bool clrtoeol)
tmp += *it;
limit--;
}
-
- if (collect)
+ else
{
if (*it != '[')
{
@@ -361,8 +378,7 @@ void Window::Write(int limit, const wstring &str, bool clrtoeol)
tmp += *it;
limit -= wcwidth(*it);
}
-
- if (collect)
+ else
{
if (*it != '[')
{
@@ -419,21 +435,21 @@ void Window::Write(int limit, const wstring &str, bool clrtoeol)
void Window::WriteXY(int x, int y, int limit, const wstring &str, bool cleartoeol)
{
- wmove(itsWindow,y,x);
+ wmove(itsWindow, y, x);
Write(limit, str, cleartoeol);
}
#endif
void Window::WriteXY(int x, int y, int limit, const string &str, bool cleartoeol)
{
- wmove(itsWindow,y,x);
+ wmove(itsWindow, y, x);
Write(limit, str, cleartoeol);
}
string Window::GetString(const string &base, unsigned int length, int width) const
{
int input, beginning, maxbeginning, minx, x, y, maxx;
- getyx(itsWindow,y,x);
+ getyx(itsWindow, y, x);
minx = maxx = x;
width--;
@@ -443,7 +459,6 @@ string Window::GetString(const string &base, unsigned int length, int width) con
return "";
curs_set(1);
- keypad(itsWindow, 1);
wstring tmp = ToWString(base);
string tmp_in;
@@ -470,7 +485,7 @@ string Window::GetString(const string &base, unsigned int length, int width) con
if (itsGetStringHelper)
itsGetStringHelper();
- wmove(itsWindow,y,x);
+ wmove(itsWindow, y, x);
input = wgetch(itsWindow);
switch (input)
@@ -554,7 +569,6 @@ string Window::GetString(const string &base, unsigned int length, int width) con
}
}
while (input != 10);
- keypad(itsWindow, 0);
curs_set(0);
return ToString(tmp);
}
@@ -814,85 +828,3 @@ size_t Window::Length(const wstring &ws)
return length;
}
-/*int CountBBCodes(const string &str)
-{
- if (str.empty())
- return 0;
- bool collect = false;
- int length = 0;
- string color;
- for (string::const_iterator it = str.begin(); it != str.end(); it++)
- {
- if (*it != '[' && !collect);
- else
- collect = 1;
-
- if (collect)
- {
- if (*it != '[')
- {
- color += *it;
- length++;
- }
- else
- {
- length -= color.length();
- length++;
- color = *it;
- }
- }
-
- if (*it == ']' || it+1 == str.end())
- collect = 0;
-
- if (!collect)
- {
- if (!IsValidColor(color))
- length -= color.length();
- color.clear();
- }
- }
- return length;
-}
-
-int CountBBCodes(const wstring &str)
-{
- if (str.empty())
- return 0;
- bool collect = false;
- int length = 0;
- wstring color;
- for (wstring::const_iterator it = str.begin(); it != str.end(); it++)
- {
- if (*it != '[' && !collect);
- else
- collect = 1;
-
- if (collect)
- {
- if (*it != '[')
- {
- color += *it;
- length++;
- }
- else
- {
- length -= color.length();
- length++;
- color = *it;
- }
- }
-
- if (*it == ']' || it+1 == str.end())
- collect = 0;
-
- if (!collect)
- {
- if (!IsValidColor(ToString(color)))
- length -= color.length();
- color.clear();
- }
- }
- return length;
-}*/
-
diff --git a/src/window.h b/src/window.h
index c39baa27..2d926b1e 100644
--- a/src/window.h
+++ b/src/window.h
@@ -57,14 +57,9 @@ typedef void (*GetStringHelper)();
typedef std::pair<Color, Color> ColorPair;
typedef std::pair<int, int> Coordinates;
-//char * ToString(const wchar_t *);
-//wchar_t * ToWString(const char *);
string ToString(const wstring &);
wstring ToWString(const string &);
-//int CountBBCodes(const string &);
-//int CountBBCodes(const wstring &);
-
class Window
{
public: