vdr
2.0.2
Main Page
Namespaces
Classes
Files
File List
File Members
PLUGINS
src
pictures
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 2.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
39
cPictureEntry
*
cPictureMenu::pictures
= NULL;
40
41
cPictureMenu::cPictureMenu
(
const
cPictureEntry
*PictureEntry,
const
char
*Path)
42
:
cOsdMenu
(
tr
(
"Pictures"
))
43
{
44
pictureEntry
= PictureEntry;
45
if
(!
pictureEntry
)
46
pictureEntry
=
pictures
=
new
cPictureEntry
(
PictureDirectory
, NULL,
true
);
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
56
cPictureMenu::~cPictureMenu
()
57
{
58
if
(
pictures
&&
pictureEntry
&& !
pictureEntry
->
Parent
())
59
DELETENULL
(
pictures
);
60
}
61
62
void
cPictureMenu::Set
(
const
char
*Path)
63
{
64
Clear
();
65
const
cList<cPictureEntry>
*l =
pictureEntry
->
Entries
();
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) {
86
const
cList<cPictureEntry>
*l =
pictureEntry
->
Entries
();
87
if
(l) {
88
cPictureEntry
*pe = l->
Get
(
Current
());
89
if
(pe) {
90
if
(SlideShow) {
91
cControl::Launch
(
new
cPictureControl
(
pictures
, pe,
true
));
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) {
98
cControl::Launch
(
new
cPictureControl
(
pictures
, pe));
99
pictures
= NULL;
// cPictureControl takes ownership
100
return
osEnd
;
101
}
102
}
103
}
104
}
105
return
osContinue
;
106
}
107
108
eOSState
cPictureMenu::ProcessKey
(
eKeys
Key)
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
126
cPictureMenu
*
cPictureMenu::CreatePictureMenu
(
void
)
127
{
128
return
new
cPictureMenu
(NULL,
cPictureControl::LastDisplayed
());
129
}
130
Generated by
1.8.3.1