23 |
|
#include <sys/sysctl.h> |
24 |
|
#include <sys/utsname.h> |
25 |
|
|
26 |
– |
#include <sqlite3.h> |
27 |
– |
|
26 |
|
#include "Display.hpp" |
27 |
+ |
#include "MenuList.hpp" |
28 |
|
|
29 |
|
bool debug(false); |
30 |
|
|
33 |
|
enum Mode { Uname, Music, English, Metric, Nautical, Menu } mode, previous; |
34 |
|
enum { Running, Audio }; |
35 |
|
enum { Stopped, Paused, Playing } audio; |
37 |
– |
enum Level { Top, Artist, Album, Song } level; |
36 |
|
Timing::Time now; |
37 |
|
IConv::IConv ascii; |
38 |
|
Display display; |
39 |
|
Pthreads::ThreadMutex displayLock; |
40 |
|
Audacious::Audacious audacious; |
41 |
|
//GPS::GPS gps; |
42 |
+ |
MenuList *list; |
43 |
+ |
bool append; |
44 |
|
|
45 |
|
inline std::string Filter(const std::string input) |
46 |
|
{ |
47 |
|
std::string output(ascii.Convert(input)); |
48 |
|
|
49 |
< |
std::replace(output.begin(), output.end(), '~', char(206)); |
49 |
> |
std::replace(output.begin(), output.end(), '~', '\xce'); |
50 |
|
|
51 |
|
return output; |
52 |
|
} |
63 |
|
int position(audacious.GetPlaylistPosition()); |
64 |
|
std::string artist(Filter(audacious.GetTupleFieldData(_B("artist"), position))); |
65 |
|
|
66 |
< |
display.Set(0, 1, artist.size() > 20 ? artist.erase(20) : artist.append(20 - artist.size(), ' ')); |
66 |
> |
artist.resize(20, ' '); |
67 |
> |
display.Set(0, 1, artist); |
68 |
|
|
69 |
|
std::string title(Filter(audacious.GetTupleFieldData(_B("title"), position))); |
70 |
|
|
71 |
< |
display.Set(0, 2, title.size() > 20 ? title.erase(20) : title.append(20 - title.size(), ' ')); |
71 |
> |
title.resize(20, ' '); |
72 |
> |
display.Set(0, 2, title); |
73 |
|
|
74 |
|
int played(audacious.GetOutputTime() / 1000); |
75 |
|
int left(audacious.GetPlaylistTime(position) / 1000 - played); |
77 |
|
|
78 |
|
::asprintf(×, "%2i:%02i -%2i:%02i", played / 60, played % 60, left / 60, left % 60); |
79 |
|
|
80 |
< |
display.Set(0, 3, times + std::string(20 - std::strlen(times), ' ')); |
80 |
> |
std::string times_(times); |
81 |
|
|
82 |
|
std::free(times); |
83 |
+ |
|
84 |
+ |
times_.resize(20, ' '); |
85 |
+ |
display.Set(0, 3, times_); |
86 |
|
} |
87 |
|
else |
88 |
|
{ |
102 |
|
return; |
103 |
|
case Menu: |
104 |
|
if (change) |
105 |
< |
level = Top; |
105 |
> |
{ |
106 |
> |
display.SetCursorStyle(Display::InvertingBlinkingBlock); |
107 |
> |
|
108 |
> |
append = true; |
109 |
> |
list = new TopList(display, audacious, append); |
110 |
> |
|
111 |
> |
list->Render(); |
112 |
> |
} |
113 |
|
} |
114 |
|
} |
115 |
|
|
125 |
|
Pcre::RegEx::Match match(version(os.release)); |
126 |
|
std::string name(os.sysname + _B(" ") + match[1] + match[2] + match[3]); |
127 |
|
|
128 |
< |
display.Set(0, 1, name.append(20 - name.size(), ' ')); |
128 |
> |
name.resize(20, ' '); |
129 |
> |
display.Set(0, 1, name); |
130 |
|
} |
131 |
|
|
132 |
|
int mib[] = { CTL_KERN, KERN_BOOTTIME }; |
155 |
|
|
156 |
|
std::string then(when); |
157 |
|
|
145 |
– |
then.append(17 - std::strlen(when), ' '); |
146 |
– |
|
158 |
|
std::free(when); |
159 |
|
|
160 |
+ |
then.resize(17, ' '); |
161 |
+ |
|
162 |
|
if (change) |
163 |
|
display.Set(0, 2, _B("up ") + then); |
164 |
|
else |
177 |
|
|
178 |
|
::asprintf(&load, "%.2f, %.2f, %.2f", averages[0], averages[1] , averages[2]); |
179 |
|
|
180 |
< |
display.Set(0, 3, load + std::string(20 - std::strlen(load), ' ')); |
180 |
> |
std::string load_(load); |
181 |
|
|
182 |
|
std::free(load); |
183 |
+ |
|
184 |
+ |
load_.resize(20, ' '); |
185 |
+ |
display.Set(0, 3, load_); |
186 |
|
} |
187 |
|
} |
188 |
|
|
235 |
|
switch (activity) |
236 |
|
{ |
237 |
|
case Display::UpPress: |
238 |
+ |
return (++*list).Render(); |
239 |
|
case Display::DownPress: |
240 |
+ |
return (--*list).Render(); |
241 |
|
case Display::LeftPress: |
242 |
+ |
list = list->Left(); |
243 |
+ |
|
244 |
+ |
goto render; |
245 |
|
case Display::RightPress: |
246 |
+ |
list = list->Right(); |
247 |
+ |
|
248 |
+ |
goto render; |
249 |
|
case Display::EnterPress: |
250 |
< |
return; |
250 |
> |
list = list->Enter(); |
251 |
> |
|
252 |
> |
render: if (list != NULL) |
253 |
> |
return list->Render(); |
254 |
> |
|
255 |
> |
goto exit; |
256 |
|
case Display::ExitPress: |
257 |
< |
mode = previous; |
257 |
> |
delete list; |
258 |
> |
|
259 |
> |
exit: mode = previous; |
260 |
|
|
261 |
+ |
display.SetCursorStyle(Display::NoCursor); |
262 |
|
display.Set(0, 0, _B(" ")); |
263 |
|
display.Set(18, 0, _B(" ")); |
264 |
|
|