vdr
2.0.4
Main Page
Namespaces
Classes
Files
File List
File Members
PLUGINS
src
pictures
entry.c
Go to the documentation of this file.
1
/*
2
* entry.c: Data structure to handle still pictures
3
*
4
* See the README file for copyright information and how to reach the author.
5
*
6
* $Id: entry.c 2.1 2012/02/17 14:00:28 kls Exp $
7
*/
8
9
#include "
entry.h
"
10
11
cPictureEntry::cPictureEntry
(
const
char
*Name,
const
cPictureEntry
*Parent,
bool
IsDirectory)
12
{
13
name
= strdup(Name);
14
parent
=
Parent
;
15
isDirectory
=
IsDirectory
;
16
entries
= NULL;
17
}
18
19
cPictureEntry::~cPictureEntry
()
20
{
21
free(
name
);
22
delete
entries
;
23
}
24
25
int
cPictureEntry::Compare
(
const
cListObject
&ListObject)
const
26
{
27
cPictureEntry
*p = (
cPictureEntry
*)&ListObject;
28
if
(
IsDirectory
() && !p->
IsDirectory
())
29
return
-1;
30
if
(!
IsDirectory
() && p->
IsDirectory
())
31
return
+1;
32
if
(
IsDirectory
())
33
return
strcoll(
name
, p->
name
);
34
else
35
return
strcmp(
name
, p->
name
);
// correctly sorts dsc01234.jpg and dsc01234a.jpg in case pictures have been "squeezed in"
36
}
37
38
cString
cPictureEntry::Path
(
void
)
const
39
{
40
return
parent
? *
AddDirectory
(
parent
->
Path
(),
name
) :
name
;
41
}
42
43
void
cPictureEntry::Load
(
void
)
const
44
{
45
if
(
isDirectory
&& !
entries
) {
46
cString
Directory =
Path
();
47
cReadDir
d(Directory);
48
if
(d.
Ok
()) {
49
struct
dirent *e;
50
while
((e = d.
Next
()) != NULL) {
51
struct
stat ds;
52
if
(stat(
AddDirectory
(Directory, e->d_name), &ds) == 0) {
53
if
(!
entries
)
54
entries
=
new
cList<cPictureEntry>
;
55
entries
->
Add
(
new
cPictureEntry
(e->d_name,
this
, S_ISDIR(ds.st_mode)));
56
}
57
}
58
if
(
entries
)
59
entries
->
Sort
();
60
}
61
else
62
LOG_ERROR_STR
(*Directory);
63
}
64
}
65
66
const
cList<cPictureEntry>
*
cPictureEntry::Entries
(
void
)
const
67
{
68
Load
();
69
return
entries
;
70
}
71
72
const
cPictureEntry
*
cPictureEntry::FirstPicture
(
void
)
const
73
{
74
Load
();
75
if
(
entries
) {
76
for
(
cPictureEntry
*pe =
entries
->
First
(); pe; pe =
entries
->
Next
(pe)) {
77
if
(pe->IsDirectory()) {
78
const
cPictureEntry
*p = pe->
FirstPicture
();
79
if
(p)
80
return
p;
81
}
82
else
83
return
pe;
84
}
85
}
86
return
NULL;
87
}
88
89
const
cPictureEntry
*
cPictureEntry::LastPicture
(
void
)
const
90
{
91
Load
();
92
if
(
entries
) {
93
for
(
cPictureEntry
*pe =
entries
->
Last
(); pe; pe =
entries
->
Prev
(pe)) {
94
if
(pe->IsDirectory()) {
95
const
cPictureEntry
*p = pe->
LastPicture
();
96
if
(p)
97
return
p;
98
}
99
else
100
return
pe;
101
}
102
}
103
return
NULL;
104
}
105
106
const
cPictureEntry
*
cPictureEntry::PrevPicture
(
const
cPictureEntry
*This)
const
107
{
108
if
(This) {
109
const
cPictureEntry
*pe = (
cPictureEntry
*)
entries
->
Prev
(This);
110
if
(pe) {
111
if
(pe->
IsDirectory
()) {
112
const
cPictureEntry
*p = pe->
LastPicture
();
113
if
(p)
114
return
p;
115
return
PrevPicture
(pe);
116
}
117
return
pe;
118
}
119
}
120
if
(
parent
)
121
return
parent
->
PrevPicture
(
this
);
122
return
NULL;
123
}
124
125
const
cPictureEntry
*
cPictureEntry::NextPicture
(
const
cPictureEntry
*This)
const
126
{
127
if
(This) {
128
cPictureEntry
*pe = (
cPictureEntry
*)
entries
->
Next
(This);
129
if
(pe) {
130
if
(pe->
IsDirectory
()) {
131
const
cPictureEntry
*p = pe->
FirstPicture
();
132
if
(p)
133
return
p;
134
return
NextPicture
(pe);
135
}
136
return
pe;
137
}
138
}
139
else
if
(
IsDirectory
()) {
140
const
cPictureEntry
*p =
FirstPicture
();
141
if
(p)
142
return
p;
143
}
144
if
(
parent
)
145
return
parent
->
NextPicture
(
this
);
146
return
NULL;
147
}
148
Generated by
1.8.3.1