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 40 by douglas, 2008-03-05T20:23:58-08:00 vs.
Revision 44 by douglas, 2008-03-06T15:21:03-08:00

# Line 4 | Line 4
4   //
5   // $Id$
6  
7 + #include <algorithm>
8   #include <iomanip>
9   #include <iostream>
10   #include <sstream>
11  
12   #include <foreach.hpp>
13   #include <hash.hpp>
14 + #include <iconv.hpp>
15   #include <regex.hpp>
16   #include <scopes.hpp>
17   #include <timing.hpp>
# Line 21 | Line 23
23   #include <sys/sysctl.h>
24   #include <sys/utsname.h>
25  
24 #include <sqlite3.h>
25
26   #include "Display.hpp"
27 + #include "MenuList.hpp"
28  
29   bool debug(false);
30  
31   class DashInterface
32   {
33 <        enum Mode { Uname, Music, English, Metric, Nautical, Menu } mode;
33 >        enum Mode { Uname, Music, English, Metric, Nautical, Menu } mode, previous;
34          enum { Running, Audio };
35          enum { Stopped, Paused, Playing } audio;
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(), '~', '\xce');
50 +
51 +                return output;
52 +        }
53  
54          void Mode_(bool change = false)
55          {
# Line 48 | Line 61 | class DashInterface
61                          if (audacious.IsRunning())
62                          {
63                                  int position(audacious.GetPlaylistPosition());
64 <                                std::string artist(audacious.GetTupleFieldData(_B("artist"), position));
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(audacious.GetTupleFieldData(_B("title"), position));
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);
# Line 62 | Line 77 | class DashInterface
77  
78                                  ::asprintf(&times, "%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                          {
# Line 77 | Line 95 | class DashInterface
95                  case English:
96                  case Metric:
97                  case Nautical:
98 <                case Menu:
98 >                        display.Set(0, 1, _B("STUB: GPS ") + (mode == English ? _B("English   ") : mode == Metric ? _B("Metric    ") : _B("Nautical  ")));
99 >                        display.Set(0, 2, std::string(20, ' '));
100 >                        display.Set(0, 3, std::string(20, ' '));
101 >
102                          return;
103 +                case Menu:
104 +                        if (change)
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  
# Line 94 | Line 125 | class DashInterface
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 };
# Line 123 | Line 155 | class DashInterface
155  
156                          std::string then(when);
157  
126                        then.append(17 - std::strlen(when), ' ');
127
158                          std::free(when);
159  
160 +                        then.resize(17, ' ');
161 +
162                          if (change)
163                                  display.Set(0, 2, _B("up ") + then);
164                          else
# Line 145 | Line 177 | class DashInterface
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  
# Line 169 | Line 204 | class DashInterface
204  
205                                          goto change;
206                                  case Display::LeftPress:
207 <                                        audacious.PlaylistPrevious();
207 >                                        if (audacious.IsRunning())
208 >                                                audacious.PlaylistPrevious();
209  
210                                          goto update;
211                                  case Display::RightPress:
212 <                                        audacious.PlaylistNext();
212 >                                        if (audacious.IsRunning())
213 >                                                audacious.PlaylistNext();
214  
215                                          goto update;
216                                  case Display::EnterPress:
217 <                                        std::cerr << _B("Menu") << std::endl;
181 <
217 >                                        previous = mode;
218                                          mode = Menu;
219  
220                                          goto change;
221                                  case Display::ExitPress:
222 <                                        audacious.PlayPause();
222 >                                        if (audacious.IsRunning())
223 >                                                audacious.PlayPause();
224  
225                                          goto update;
226                                  default:
# Line 195 | Line 232 | change:                        change = true;
232   update:                 Mode_(change);
233                          }
234                          else
235 <                                return;
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 >                                        list = list->Enter();
251 >
252 > render:                         if (list != NULL)
253 >                                                return list->Render();
254 >
255 >                                        goto exit;
256 >                                case Display::ExitPress:
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 >
265 >                                        Mode_(true);
266 >                                default:
267 >                                        return;
268 >                                }
269          }
270  
271   public:
272 <        DashInterface(const std::string &device) : mode(Uname), audio(Stopped), display(device, reinterpret_cast<Display::Callback>(::Buttons), this)
272 >        DashInterface(const std::string &device) : mode(Uname), audio(Stopped), ascii(_B("ASCII//TRANSLIT//IGNORE"), _B("UTF-8")), display(device, reinterpret_cast<Display::Callback>(::Buttons), this)
273          {
274                  _synchronized (displayLock)
275                  {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines