ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/DashInterface/DashInterface.cpp
(Generate patch)

Comparing DashInterface/DashInterface.cpp (file contents):
Revision 41 by douglas, 2008-03-06T02:41:40-08:00 vs.
Revision 46 by douglas, 2008-03-06T19:47:57-08:00

# Line 23 | Line 23
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  
# Line 34 | Line 33 | class DashInterface
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          }
53  
54          void Mode_(bool change = false)
55          {
56 +                if (mode != Menu)
57 +                {
58 +                        char when[16];
59 +
60 +                        std::strftime(when, sizeof (when), "%l:%M:%S %p %Z", std::localtime(now));
61 +
62 +                        display.Set(2, 0, when);
63 +                }
64 +
65                  switch (mode)
66                  {
67                  case Uname:
# Line 63 | Line 72 | class DashInterface
72                                  int position(audacious.GetPlaylistPosition());
73                                  std::string artist(Filter(audacious.GetTupleFieldData(_B("artist"), position)));
74  
75 <                                display.Set(0, 1, artist.size() > 20 ? artist.erase(20) : artist.append(20 - artist.size(), ' '));
75 >                                artist.resize(20, ' ');
76 >                                display.Set(0, 1, artist);
77  
78                                  std::string title(Filter(audacious.GetTupleFieldData(_B("title"), position)));
79  
80 <                                display.Set(0, 2, title.size() > 20 ? title.erase(20) : title.append(20 - title.size(), ' '));
80 >                                title.resize(20, ' ');
81 >                                display.Set(0, 2, title);
82  
83                                  int played(audacious.GetOutputTime() / 1000);
84                                  int left(audacious.GetPlaylistTime(position) / 1000 - played);
# Line 75 | Line 86 | class DashInterface
86  
87                                  ::asprintf(&times, "%2i:%02i -%2i:%02i", played / 60, played % 60, left / 60, left % 60);
88  
89 <                                display.Set(0, 3, times + std::string(20 - std::strlen(times), ' '));
89 >                                std::string times_(times);
90  
91                                  std::free(times);
92 +
93 +                                times_.resize(20, ' ');
94 +                                display.Set(0, 3, times_);
95                          }
96                          else
97                          {
# Line 97 | Line 111 | class DashInterface
111                          return;
112                  case Menu:
113                          if (change)
114 <                                level = Top;
114 >                        {
115 >                                display.SetCursorPosition(19, 0);
116 >                                display.SetCursorStyle(Display::InvertingBlinkingBlock);
117 >
118 >                                append = true;
119 >                                list = new TopList(display, audacious, append);
120 >
121 >                                list->Render();
122 >                        }
123                  }
124          }
125  
# Line 113 | Line 135 | class DashInterface
135                          Pcre::RegEx::Match match(version(os.release));
136                          std::string name(os.sysname + _B(" ") + match[1] + match[2] + match[3]);
137  
138 <                        display.Set(0, 1, name.append(20 - name.size(), ' '));
138 >                        name.resize(20, ' ');
139 >                        display.Set(0, 1, name);
140                  }
141  
142                  int mib[] = { CTL_KERN, KERN_BOOTTIME };
# Line 142 | Line 165 | class DashInterface
165  
166                          std::string then(when);
167  
145                        then.append(17 - std::strlen(when), ' ');
146
168                          std::free(when);
169  
170 +                        then.resize(17, ' ');
171 +
172                          if (change)
173                                  display.Set(0, 2, _B("up ") + then);
174                          else
# Line 164 | Line 187 | class DashInterface
187  
188                          ::asprintf(&load, "%.2f, %.2f, %.2f", averages[0], averages[1] , averages[2]);
189  
190 <                        display.Set(0, 3, load + std::string(20 - std::strlen(load), ' '));
190 >                        std::string load_(load);
191  
192                          std::free(load);
193 +
194 +                        load_.resize(20, ' ');
195 +                        display.Set(0, 3, load_);
196                  }
197          }
198  
# Line 219 | Line 245 | update:                        Mode_(change);
245                                  switch (activity)
246                                  {
247                                  case Display::UpPress:
248 +                                        return (--*list).Render();
249                                  case Display::DownPress:
250 +                                        return (++*list).Render();
251                                  case Display::LeftPress:
252 +                                        list = list->Left();
253 +
254 +                                        goto render;
255                                  case Display::RightPress:
256 +                                        list = list->Right();
257 +
258 +                                        goto render;
259                                  case Display::EnterPress:
260 <                                        return;
260 >                                        list = list->Enter();
261 >
262 > render:                         if (list != NULL)
263 >                                                return list->Render();
264 >
265 >                                        goto exit;
266                                  case Display::ExitPress:
267 <                                        mode = previous;
267 >                                        delete list;
268  
269 + exit:                           mode = previous;
270 +
271 +                                        display.SetCursorStyle(Display::NoCursor);
272                                          display.Set(0, 0, _B("  "));
273                                          display.Set(18, 0, _B("  "));
274  
# Line 242 | Line 284 | public:
284                  _synchronized (displayLock)
285                  {
286                          display.Clear();
287 +                        display.SetCursorStyle(Display::NoCursor);
288                          display.SetBacklight(100);
289                          display.Set(2, 0, _B("--:--:-- -- ---"));
290  
# Line 270 | Line 313 | public:
313                          {
314                                  now = Timing::GetTimeOfDay();
315  
273                                if (mode != Menu)
274                                {
275                                        char when[16];
276
277                                        std::strftime(when, sizeof (when), "%l:%M:%S %p %Z", std::localtime(now));
278
279                                        display.Set(2, 0, when);
280                                }
281
316                                  if (audacious.IsRunning() && audacious.IsPlaying())
317                                          if (audacious.IsPaused())
318                                          {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines