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::MusicItem::MusicItem(Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : audacious(audacious), append(append), library(library) |
20 |
> |
{ |
21 |
> |
} |
22 |
> |
|
23 |
> |
MenuList::MenuList(MenuList *parent, Display &display, size_t size) : parent(parent), display(display), cursor(0), list(size) |
24 |
> |
{ |
25 |
> |
} |
26 |
> |
|
27 |
> |
MenuList::MenuList(MenuList *parent) : parent(parent), display(parent->display), cursor(0), list(1) |
28 |
|
{ |
29 |
|
} |
30 |
|
|
32 |
|
{ |
33 |
|
_foreach (std::vector<MenuItem *>, item, list) |
34 |
|
delete *item; |
35 |
+ |
|
36 |
+ |
if (parent != NULL && parent != this) |
37 |
+ |
delete parent; |
38 |
|
} |
39 |
|
|
40 |
|
MenuList *MenuList::Enter() |
41 |
|
{ |
42 |
< |
return list[state.item]->Select(); |
42 |
> |
return Select(list[state.item]); |
43 |
|
} |
44 |
|
|
45 |
|
MenuList *MenuList::Right() |
47 |
|
MenuItem *item(list[state.item]); |
48 |
|
|
49 |
|
if (dynamic_cast<SubItem *>(item)) |
50 |
< |
return item->Select(); |
50 |
> |
return Select(item); |
51 |
|
|
52 |
|
return this; |
53 |
|
} |
54 |
|
|
55 |
|
MenuList *MenuList::Left() |
56 |
|
{ |
57 |
+ |
MenuList *parent(this->parent); |
58 |
+ |
|
59 |
+ |
if (parent != this) |
60 |
+ |
{ |
61 |
+ |
this->parent = NULL; |
62 |
+ |
|
63 |
+ |
delete this; |
64 |
+ |
} |
65 |
+ |
|
66 |
|
return parent; |
67 |
|
} |
68 |
|
|
69 |
|
void MenuList::Render() |
70 |
|
{ |
71 |
+ |
display.SetCursorPosition(19, cursor); |
72 |
+ |
|
73 |
+ |
size_t size(list.size()); |
74 |
+ |
|
75 |
|
if (this != previous || state != old) |
76 |
|
{ |
77 |
< |
# define Cursor(index) (state.cursor == index ? _B("\x1f") : _B(" ")) |
77 |
> |
display.Set(0, 0, (state.top != 0 ? '\x1a' : ' ')); |
78 |
> |
display.Set(0, 1, '\x12'); |
79 |
> |
display.Set(0, 2, '\x13'); |
80 |
> |
display.Set(0, 3, (state.bottom < size ? '\x1b' : ' ')); |
81 |
> |
|
82 |
> |
_forall (size_t, index, state.top, state.bottom) |
83 |
> |
if (index < size) |
84 |
> |
{ |
85 |
> |
MenuItem *item(list[index]); |
86 |
> |
std::string value(*item); |
87 |
> |
|
88 |
> |
value.resize(18, ' '); |
89 |
> |
|
90 |
> |
if (BoolItem *item_ = dynamic_cast<BoolItem *>(item)) |
91 |
> |
value += (*item_ ? '\x94' : '\xcf'); |
92 |
> |
else if (dynamic_cast<SubItem *>(item)) |
93 |
> |
value += '\x10'; |
94 |
> |
else |
95 |
> |
value += ' '; |
96 |
|
|
97 |
< |
display.Set(0, 0, (state.bottom != 0 ? '\x1a' : ' ') + Cursor(0)); |
98 |
< |
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'; |
97 |
> |
display.Set(1, _index, value); |
98 |
> |
} |
99 |
|
else |
100 |
< |
value += ' '; |
100 |
> |
display.Set(1, _index, std::string(19, ' ')); |
101 |
|
|
102 |
< |
display.Set(2, _index, value); |
77 |
< |
} |
102 |
> |
previous = this; |
103 |
|
} |
104 |
|
else |
105 |
< |
{ |
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) |
105 |
> |
_forall (size_t, index, state.top, size < state.bottom ? size : state.bottom) |
106 |
|
if (BoolItem *item = dynamic_cast<BoolItem *>(list[index])) |
107 |
|
display.Set(19, _index, (*item ? _B("\x94") : _B("\xcf"))); |
90 |
– |
} |
108 |
|
} |
109 |
|
|
110 |
|
MenuList &MenuList::operator ++() |
111 |
|
{ |
112 |
+ |
old = state; |
113 |
+ |
|
114 |
|
size_t next(state.item + 1); |
115 |
|
|
116 |
|
if (next != list.size()) |
118 |
|
if (next == state.bottom) |
119 |
|
++state.top, ++state.bottom; |
120 |
|
else |
121 |
< |
++state.cursor; |
121 |
> |
++cursor; |
122 |
|
|
123 |
|
state.item = next; |
124 |
|
} |
128 |
|
|
129 |
|
MenuList &MenuList::operator --() |
130 |
|
{ |
131 |
+ |
old = state; |
132 |
+ |
|
133 |
|
if (state.item != 0) |
134 |
|
if (state.item-- == state.top) |
135 |
|
--state.top, --state.bottom; |
136 |
|
else |
137 |
< |
--state.cursor; |
137 |
> |
--cursor; |
138 |
|
|
139 |
|
return *this; |
140 |
|
} |
152 |
|
|
153 |
|
TopList::AppendItem::operator std::string() const |
154 |
|
{ |
155 |
< |
return _B("Append"); |
155 |
> |
return _B("Playlist Append"); |
156 |
|
} |
157 |
|
|
158 |
|
TopList::AppendItem::operator bool() const |
182 |
|
return audacious.IsRunning() ? audacious.IsShuffle() : false; |
183 |
|
} |
184 |
|
|
185 |
< |
TopList::MusicItem::MusicItem(MenuList *list, Audacious::Audacious &audacious) : MenuItem(list), audacious(audacious) |
185 |
> |
TopList::MusicItem::MusicItem(MenuList *list, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuItem(list), MenuList::MusicItem(audacious, append, library) |
186 |
|
{ |
187 |
|
} |
188 |
|
|
189 |
|
MenuList *TopList::MusicItem::Select() |
190 |
|
{ |
191 |
< |
return NULL; |
191 |
> |
return new ArtistList(list, audacious, append, library); |
192 |
|
} |
193 |
|
|
194 |
|
TopList::MusicItem::operator std::string() const |
196 |
|
return _B("Music"); |
197 |
|
} |
198 |
|
|
199 |
< |
TopList::TopList(Audacious::Audacious &audacious, Display &display, bool &append) : MenuList(this, display, 3) |
199 |
> |
TopList::TopList(Display &display, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuList(this, display, 3) |
200 |
|
{ |
201 |
|
previous = NULL; |
202 |
|
list[0] = new AppendItem(this, append); |
203 |
|
list[1] = new ShuffleItem(this, audacious); |
204 |
< |
list[2] = new MusicItem(this, audacious); |
204 |
> |
list[2] = new MusicItem(this, audacious, append, library); |
205 |
> |
} |
206 |
> |
|
207 |
> |
ArtistList::ArtistList(MenuList *parent, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuList(parent) |
208 |
> |
{ |
209 |
> |
list[0] = new AllItem(this, audacious, append, library); |
210 |
> |
} |
211 |
> |
|
212 |
> |
ArtistList::AllItem::AllItem(MenuList *list, Audacious::Audacious &audacious, bool &append, MusicLibrary::Library &library) : MenuItem(list), MusicItem(audacious, append, library) |
213 |
> |
{ |
214 |
> |
} |
215 |
> |
|
216 |
> |
MenuList *ArtistList::AllItem::Select() |
217 |
> |
{ |
218 |
> |
_L<std::string> songs; |
219 |
> |
|
220 |
> |
_foreach (const _L<MusicLibrary::Song>, song, library.GetSongs()) |
221 |
> |
songs.push_back(song->GetPath()); |
222 |
> |
|
223 |
> |
if (audacious.IsRunning()) |
224 |
> |
audacious.Playlist(songs, append); |
225 |
> |
|
226 |
> |
return NULL; |
227 |
> |
} |
228 |
> |
|
229 |
> |
ArtistList::AllItem::operator std::string() const |
230 |
> |
{ |
231 |
> |
return _B("All Artists"); |
232 |
|
} |