-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlaylistWindow.cpp
More file actions
180 lines (161 loc) · 4.21 KB
/
PlaylistWindow.cpp
File metadata and controls
180 lines (161 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <string>
#include <cstring>
#include "Color.h"
#include "ncurses.h"
#include "Player.h"
#include "PlaylistController.h"
#include "PlaylistWindow.h"
using std::string;
extern PlaylistController plc;
extern string* strinput(const char* prepend = "");
template<typename... T>
static void dispmsg( WINDOW* win, const char* fmt, T... args) {
int rows, cols;
getmaxyx ( win, rows, cols );
mvwprintw( win, rows-1, 0, fmt, args... );
}
PlaylistWindow::PlaylistWindow(WINDOW* w, Color& cm, Player& p) :
Window(w,cm), player(&p) {
if(plc.size()) {
selection = plc.getselection()->begin();
selectionoffset = 0;
}
}
void PlaylistWindow::command(const string& s) {
}
void PlaylistWindow::control(const int c) {
string *s, *f;
switch (c) {
case '\n':
// This is a bit of a mess =/
s = strinput();
if(s->length()) {
f = strinput();
if(f->length()) {
addshow(*s,*f);
}
}
delete(s);delete(f); // strinput() uses new
break;
case KEY_LEFT:
case 'u':
selection->unwatch();
plc.getselection()->change();
break;
case KEY_UP:
if(plc.size() && selection != plc.getselection()->begin()) {
--selection;
--selectionoffset;
}
break;
case KEY_RIGHT:
case 'p':
if(plc.size()) {
player->play(selection->file);
selection->watch();
plc.getselection()->change();
}
case 'r':
case KEY_DOWN:
if(plc.size() && selection != plc.getselection()->end()-1) {
++selection;
++selectionoffset;
}
break;
case 'd':
del();
break;
case 'w':
selection->watch();
plc.getselection()->change();
break;
case '/':
s = strinput("/");
{
auto i = selection;
for(; i < plc.getselection()->end(); ++i) {
if( i->print().find(*s) != std::string::npos) {
selection = i;
drawit();
break;
}
}
if(i == plc.getselection()->end()) {
dispmsg(stdscr, "Could not find \"%s\"", s->c_str());
}
}
delete(s);
break;
default:
break;
}
}
void PlaylistWindow::del() {
string* s = strinput("Are you sure you want to delete this item? [y/N] ");
if(s->length()) {
if(*s == "y" || *s == "Y") {
plc.getselection()->deleteselection(selection);
delete(s);
selection = plc.getselection()->begin();
auto i = selection + selectionoffset, j = plc.getselection()->end();
selection = (i < j) ? i : j-1;
}
}
}
void PlaylistWindow::drawit() {
werase(window);
unsigned int row = 3, rows, cols, count = 0;
getmaxyx(window,rows,cols);
drawheaders(cols);
if(!plc.empty()) {
size_t offset = 0;
if(plc.getselection()->size() > rows) {
size_t center = (rows-row)/2;
if(selectionoffset > center) {
offset = selectionoffset - center;
}
if(plc.getselection()->size() - offset < (rows-row)) {
offset -= (rows-row) - (plc.getselection()->size() - offset);
}
count = offset;
}
for(auto i = plc.getselection()->begin() + offset;
i < plc.getselection()->end() && row < rows; ++i, ++row) {
if(selection == i) {
wattr_on ( window, COLOR_PAIR(colormanager->find("red")), NULL);
mvwprintw( window, row, 0, "%d\t%s", ++count, i->print().c_str());
mvwprintw( window, row, cols - 3, "[%d]", i->getwatched());
wattr_off( window, COLOR_PAIR(colormanager->find("red")), NULL);
}
else {
mvwprintw( window, row, 0, "%d\t%s", ++count, i->print().c_str());
mvwprintw( window, row, cols - 3, "[%d]", i->getwatched());
}
}
}
wrefresh(window);
}
void PlaylistWindow::drawheaders(unsigned int cols) {
mvwhline ( window, 0, 0, ACS_HLINE, cols);
mvwprintw( window, 1, 0, "#\tName");
mvwprintw( window, 1, cols - strlen("Watched"), "Watched");
mvwhline ( window, 2, 0, ACS_HLINE, cols);
}
void PlaylistWindow::selected() {
// Find the first unwatched in this session of watching
// That is, the first show that we have watched less than the prior shows
if( !plc.empty() ) {
selection = plc.getselection()->first();
selectionoffset = selection - plc.getselection()->begin();
}
}
void PlaylistWindow::addshow(string& name, string& file, showtype type) {
if(plc.size()) {
Show s(file,name,type);
plc.getselection()->add(s);
if(plc.getselection()->size() == 1) {
selectionoffset = 0;
}
selection = plc.getselection()->begin() + selectionoffset;
}
}