vdr 2.6.8
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 4.1 2015/07/17 10:13:56 kls Exp $
7 */
8
9#include "menu.h"
10#include <vdr/tools.h>
11#include "entry.h"
12#include "player.h"
13
14char PictureDirectory[PATH_MAX] = "";
15
16static 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
30static 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
41cPictureMenu::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
61
62void 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
82eOSState cPictureMenu::SelectItem(const char *Path, bool SlideShow)
83{
84 cOsdItem *Item = Get(Current());
85 if (Item) {
87 if (l) {
88 const 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
static bool PathStartsWith(const char *Path, const char *Name)
static const char * NextLevel(const char *Path)
char PictureDirectory[PATH_MAX]
char PictureDirectory[PATH_MAX]
cString HandleUnderscores(const char *s)
static void Launch(cControl *Control)
Definition player.c:87
int Count(void) const
Definition tools.h:640
Definition tools.h:644
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
Definition tools.h:656
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
Definition tools.h:663
const cOsdItem * Get(int Index) const
Definition tools.h:653
void SetTitle(const char *Title)
Definition osdbase.c:174
int Current(void) const
Definition osdbase.h:138
eOSState AddSubMenu(cOsdMenu *SubMenu)
Definition osdbase.c:517
void Add(cOsdItem *Item, bool Current=false, cOsdItem *After=NULL)
Definition osdbase.c:213
void SetHelp(const char *Red, const char *Green=NULL, const char *Yellow=NULL, const char *Blue=NULL)
Definition osdbase.c:189
virtual void Clear(void)
Definition osdbase.c:329
virtual eOSState ProcessKey(eKeys Key)
Definition osdbase.c:536
static const char * LastDisplayed(void)
const cPictureEntry * Parent(void) const
Definition entry.h:26
bool IsDirectory(void) const
Definition entry.h:27
const char * Name(void) const
Definition entry.h:25
const cList< cPictureEntry > * Entries(void) const
Definition entry.c:66
static cPictureEntry * pictures
void Set(const char *Path)
eOSState SelectItem(const char *Path=NULL, bool SlideShow=false)
static cPictureMenu * CreatePictureMenu(void)
const cPictureEntry * pictureEntry
cPictureMenu(const cPictureEntry *PictureEntry, const char *Path=NULL)
virtual eOSState ProcessKey(eKeys Key)
static cString sprintf(const char *fmt,...) __attribute__((format(printf
Definition tools.c:1180
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:1164
#define tr(s)
Definition i18n.h:85
eKeys
Definition keys.h:16
@ kRed
Definition keys.h:24
@ kPlay
Definition keys.h:31
@ kStop
Definition keys.h:33
@ kBlue
Definition keys.h:27
@ kOk
Definition keys.h:20
eOSState
Definition osdbase.h:18
@ osStopReplay
Definition osdbase.h:31
@ osEnd
Definition osdbase.h:34
@ osContinue
Definition osdbase.h:19
@ osUnknown
Definition osdbase.h:18
void DELETENULL(T *&p)
Definition tools.h:49