vdr  2.2.0
PLUGINS/src/pictures/menu.c
Go to the documentation of this file.
1 /*
2  * menu.c: A menu for still pictures
3  *
4  * See the README file for copyright information and how to reach the author.
5  *
6  * $Id: menu.c 3.0 2008/01/13 11:35:18 kls Exp $
7  */
8 
9 #include "menu.h"
10 #include <vdr/tools.h>
11 #include "entry.h"
12 #include "player.h"
13 
14 char PictureDirectory[PATH_MAX] = "";
15 
16 static bool PathStartsWith(const char *Path, const char *Name)
17 {
18  if (Path && Name) {
19  while (*Name) {
20  if (*Path++ != *Name++)
21  return false;
22  }
23  if (*Path && *Path != '/')
24  return false;
25  return true;
26  }
27  return false;
28 }
29 
30 static const char *NextLevel(const char *Path)
31 {
32  if (Path) {
33  const char *p = strchr(Path, '/');
34  return p ? p + 1 : NULL;
35  }
36  return Path;
37 }
38 
40 
41 cPictureMenu::cPictureMenu(const cPictureEntry *PictureEntry, const char *Path)
42 :cOsdMenu(tr("Pictures"))
43 {
44  pictureEntry = PictureEntry;
45  if (!pictureEntry)
47  if (pictureEntry->Parent()) {
48  if (!pictureEntry->Parent()->Parent())
49  SetTitle(pictureEntry->Name()); // Year
50  else
51  SetTitle(cString::sprintf("%s: %s", pictureEntry->Parent()->Name(), *HandleUnderscores(pictureEntry->Name()))); // Year/Description
52  }
53  Set(Path);
54 }
55 
57 {
60 }
61 
62 void cPictureMenu::Set(const char *Path)
63 {
64  Clear();
66  if (l) {
67  for (const cPictureEntry *e = l->First(); e; e = l->Next(e)) {
68  cString Name = HandleUnderscores(e->Name());
69  if (!e->IsDirectory())
70  Name.Truncate(-4); // don't display the ".mpg" extension
71  Add(new cOsdItem(HandleUnderscores(Name)), PathStartsWith(Path, e->Name()));
72  }
73  }
74  SetHelp(Count() ? trVDR("Button$Play") : NULL, NULL, NULL, cPictureControl::Active() ? trVDR("Button$Stop") : NULL);
75  if (Current() >= 0) {
76  const char *p = NextLevel(Path);
77  if (p)
78  SelectItem(p);
79  }
80 }
81 
82 eOSState cPictureMenu::SelectItem(const char *Path, bool SlideShow)
83 {
84  cOsdItem *Item = Get(Current());
85  if (Item) {
87  if (l) {
88  cPictureEntry *pe = l->Get(Current());
89  if (pe) {
90  if (SlideShow) {
92  pictures = NULL; // cPictureControl takes ownership
93  return osEnd;
94  }
95  if (pe->IsDirectory())
96  return AddSubMenu(new cPictureMenu(pe, Path));
97  else if (!Path) {
99  pictures = NULL; // cPictureControl takes ownership
100  return osEnd;
101  }
102  }
103  }
104  }
105  return osContinue;
106 }
107 
109 {
110  eOSState state = cOsdMenu::ProcessKey(Key);
111  if (state == osUnknown) {
112  switch (Key) {
113  case kRed:
114  case kPlay: return SelectItem(NULL, true);
115  case kBlue:
116  case kStop: if (cPictureControl::Active())
117  return osStopReplay;
118  break;
119  case kOk: return SelectItem();
120  default: break;
121  }
122  }
123  return state;
124 }
125 
127 {
128  return new cPictureMenu(NULL, cPictureControl::LastDisplayed());
129 }
const cPictureEntry * pictureEntry
static const char * NextLevel(const char *Path)
cPictureMenu(const cPictureEntry *PictureEntry, const char *Path=NULL)
static cPictureEntry * pictures
void Add(cOsdItem *Item, bool Current=false, cOsdItem *After=NULL)
Definition: osdbase.c:209
const char * Name(void) const
Definition: entry.h:25
static cString sprintf(const char *fmt,...) __attribute__((format(printf
Definition: tools.c:1080
cString & Truncate(int Index)
Truncate the string at the given Index (if Index is < 0 it is counted from the end of the string)...
Definition: tools.c:1064
virtual void Clear(void)
Definition: osdbase.c:319
char PictureDirectory[PATH_MAX]
cOsdItem * Get(int Index) const
Definition: tools.h:491
Definition: keys.h:33
Definition: keys.h:27
int Current(void) const
Definition: osdbase.h:138
int Count(void) const
Definition: tools.h:485
void Set(const char *Path)
bool IsDirectory(void) const
Definition: entry.h:27
eOSState
Definition: osdbase.h:18
const cList< cPictureEntry > * Entries(void) const
Definition: entry.c:66
virtual eOSState ProcessKey(eKeys Key)
virtual eOSState ProcessKey(eKeys Key)
Definition: osdbase.c:568
T * Next(const T *object) const
Definition: tools.h:495
static const char * LastDisplayed(void)
Definition: osdbase.h:35
eOSState SelectItem(const char *Path=NULL, bool SlideShow=false)
const cPictureEntry * Parent(void) const
Definition: entry.h:26
Definition: keys.h:20
cString HandleUnderscores(const char *s)
static void Launch(cControl *Control)
Definition: player.c:79
T * First(void) const
Definition: tools.h:492
#define tr(s)
Definition: i18n.h:85
static cPictureMenu * CreatePictureMenu(void)
void DELETENULL(T *&p)
Definition: tools.h:48
void SetHelp(const char *Red, const char *Green=NULL, const char *Yellow=NULL, const char *Blue=NULL)
Definition: osdbase.c:185
static bool PathStartsWith(const char *Path, const char *Name)
Definition: keys.h:31
Definition: keys.h:24
void SetTitle(const char *Title)
Definition: osdbase.c:170
eOSState AddSubMenu(cOsdMenu *SubMenu)
Definition: osdbase.c:549
eKeys
Definition: keys.h:16
Definition: tools.h:168