4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
< |
#include <foreach.hpp> |
7 |
> |
#include <iostream> |
8 |
|
|
9 |
< |
#include <sqlite3.h> |
9 |
> |
#include <foreach.hpp> |
10 |
|
|
11 |
|
#include "MenuList.hpp" |
12 |
|
|
16 |
|
{ |
17 |
|
} |
18 |
|
|
19 |
< |
MenuList::MenuList(MenuList *parent, Display &display, size_t size) : parent(parent), display(display), list(size) |
19 |
> |
MenuList::MenuList(MenuList *parent, Display &display, size_t size) : parent(parent), display(display), cursor(0), list(size) |
20 |
> |
{ |
21 |
> |
} |
22 |
> |
|
23 |
> |
MenuList::MenuList(MenuList *parent) : parent(parent), display(parent->display), cursor(0), list(1) |
24 |
|
{ |
25 |
|
} |
26 |
|
|
28 |
|
{ |
29 |
|
_foreach (std::vector<MenuItem *>, item, list) |
30 |
|
delete *item; |
31 |
+ |
|
32 |
+ |
if (parent != NULL && parent != this) |
33 |
+ |
delete parent; |
34 |
|
} |
35 |
|
|
36 |
|
MenuList *MenuList::Enter() |
50 |
|
|
51 |
|
MenuList *MenuList::Left() |
52 |
|
{ |
53 |
+ |
MenuList *parent(this->parent); |
54 |
+ |
|
55 |
+ |
if (parent != this) |
56 |
+ |
{ |
57 |
+ |
this->parent = NULL; |
58 |
+ |
|
59 |
+ |
delete this; |
60 |
+ |
} |
61 |
+ |
|
62 |
|
return parent; |
63 |
|
} |
64 |
|
|
65 |
|
void MenuList::Render() |
66 |
|
{ |
67 |
+ |
display.SetCursorPosition(19, cursor); |
68 |
+ |
|
69 |
+ |
size_t size(list.size()); |
70 |
+ |
|
71 |
|
if (this != previous || state != old) |
72 |
|
{ |
73 |
< |
# define Cursor(index) (state.cursor == index ? _B("\x1f") : _B(" ")) |
73 |
> |
display.Set(0, 0, (state.top != 0 ? '\x1a' : ' ')); |
74 |
> |
display.Set(0, 1, '\x12'); |
75 |
> |
display.Set(0, 2, '\x13'); |
76 |
> |
display.Set(0, 3, (state.bottom < size ? '\x1b' : ' ')); |
77 |
> |
|
78 |
> |
_forall (size_t, index, state.top, state.bottom) |
79 |
> |
if (index < size) |
80 |
> |
{ |
81 |
> |
MenuItem *item(list[index]); |
82 |
> |
std::string value(*item); |
83 |
> |
|
84 |
> |
value.resize(18, ' '); |
85 |
> |
|
86 |
> |
if (BoolItem *item_ = dynamic_cast<BoolItem *>(item)) |
87 |
> |
value += (*item_ ? '\x94' : '\xcf'); |
88 |
> |
else if (dynamic_cast<SubItem *>(item)) |
89 |
> |
value += '\x10'; |
90 |
> |
else |
91 |
> |
value += ' '; |
92 |
|
|
93 |
< |
display.Set(0, 0, (state.bottom != 0 ? '\x1a' : ' ') + Cursor(0)); |
94 |
< |
display.Set(0, 1, '\x12' + Cursor(1)); |
57 |
< |
display.Set(0, 2, '\x13' + Cursor(2)); |
58 |
< |
display.Set(0, 3, (state.top < list.size() ? '\x1b' : ' ') + Cursor(3)); |
59 |
< |
|
60 |
< |
# undef Cursor |
61 |
< |
|
62 |
< |
_forall (size_t, index, state.bottom, state.top) |
63 |
< |
{ |
64 |
< |
MenuItem *item(list[index]); |
65 |
< |
std::string value(*item); |
66 |
< |
|
67 |
< |
value.resize(17, ' '); |
68 |
< |
|
69 |
< |
if (BoolItem *item_ = dynamic_cast<BoolItem *>(item)) |
70 |
< |
value += (*item_ ? '\x94' : '\xcf'); |
71 |
< |
else if (dynamic_cast<SubItem *>(item)) |
72 |
< |
value += '\x10'; |
93 |
> |
display.Set(1, _index, value); |
94 |
> |
} |
95 |
|
else |
96 |
< |
value += ' '; |
75 |
< |
|
76 |
< |
display.Set(2, _index, value); |
77 |
< |
} |
96 |
> |
display.Set(1, _index, std::string(19, ' ')); |
97 |
|
} |
98 |
|
else |
99 |
< |
{ |
81 |
< |
if (state.cursor != old.cursor) |
82 |
< |
{ |
83 |
< |
display.Set(1, old.cursor, _B(" ")); |
84 |
< |
display.Set(1, state.cursor, _B("\x1f")); |
85 |
< |
} |
86 |
< |
|
87 |
< |
_forall (size_t, index, state.bottom, state.top) |
99 |
> |
_forall (size_t, index, state.top, size < state.bottom ? size : state.bottom) |
100 |
|
if (BoolItem *item = dynamic_cast<BoolItem *>(list[index])) |
101 |
|
display.Set(19, _index, (*item ? _B("\x94") : _B("\xcf"))); |
90 |
– |
} |
102 |
|
} |
103 |
|
|
104 |
|
MenuList &MenuList::operator ++() |
105 |
|
{ |
106 |
+ |
old = state; |
107 |
+ |
|
108 |
|
size_t next(state.item + 1); |
109 |
|
|
110 |
|
if (next != list.size()) |
112 |
|
if (next == state.bottom) |
113 |
|
++state.top, ++state.bottom; |
114 |
|
else |
115 |
< |
++state.cursor; |
115 |
> |
++cursor; |
116 |
|
|
117 |
|
state.item = next; |
118 |
|
} |
122 |
|
|
123 |
|
MenuList &MenuList::operator --() |
124 |
|
{ |
125 |
+ |
old = state; |
126 |
+ |
|
127 |
|
if (state.item != 0) |
128 |
|
if (state.item-- == state.top) |
129 |
|
--state.top, --state.bottom; |
130 |
|
else |
131 |
< |
--state.cursor; |
131 |
> |
--cursor; |
132 |
|
|
133 |
|
return *this; |
134 |
|
} |
146 |
|
|
147 |
|
TopList::AppendItem::operator std::string() const |
148 |
|
{ |
149 |
< |
return _B("Append"); |
149 |
> |
return _B("Playlist Append"); |
150 |
|
} |
151 |
|
|
152 |
|
TopList::AppendItem::operator bool() const |
176 |
|
return audacious.IsRunning() ? audacious.IsShuffle() : false; |
177 |
|
} |
178 |
|
|
179 |
< |
TopList::TopList(Audacious::Audacious &audacious, Display &display, bool &append) : MenuList(this, display, 3) |
179 |
> |
TopList::MusicItem::MusicItem(MenuList *list, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuItem(list), audacious(audacious), append(append), library(library) |
180 |
> |
{ |
181 |
> |
} |
182 |
> |
|
183 |
> |
MenuList *TopList::MusicItem::Select() |
184 |
> |
{ |
185 |
> |
return new ArtistList(list, audacious, append, library); |
186 |
> |
} |
187 |
> |
|
188 |
> |
TopList::MusicItem::operator std::string() const |
189 |
> |
{ |
190 |
> |
return _B("Music"); |
191 |
> |
} |
192 |
> |
|
193 |
> |
TopList::TopList(Display &display, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuList(this, display, 3) |
194 |
|
{ |
195 |
|
previous = NULL; |
196 |
|
list[0] = new AppendItem(this, append); |
197 |
|
list[1] = new ShuffleItem(this, audacious); |
198 |
+ |
list[2] = new MusicItem(this, audacious, append, library); |
199 |
+ |
} |
200 |
+ |
|
201 |
+ |
ArtistList::ArtistList(MenuList *parent, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuList(parent) |
202 |
+ |
{ |
203 |
+ |
list[0] = new AllItem(this, audacious, append, library); |
204 |
+ |
} |
205 |
+ |
|
206 |
+ |
ArtistList::AllItem::AllItem(MenuList *list, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuItem(list), audacious(audacious), append(append), library(library) |
207 |
+ |
{ |
208 |
+ |
} |
209 |
+ |
|
210 |
+ |
MenuList *ArtistList::AllItem::Select() |
211 |
+ |
{ |
212 |
+ |
std::cerr << _B("All Artists!") << std::endl; |
213 |
+ |
|
214 |
+ |
return list; |
215 |
+ |
} |
216 |
+ |
|
217 |
+ |
ArtistList::AllItem::operator std::string() const |
218 |
+ |
{ |
219 |
+ |
return _B("All Artists"); |
220 |
|
} |