vdr 2.7.3
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
11cPictureEntry::cPictureEntry(const char *Name, const cPictureEntry *Parent, bool IsDirectory)
12{
13 name = strdup(Name);
14 parent = Parent;
16 entries = NULL;
17}
18
20{
21 free(name);
22 delete entries;
23}
24
25int 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
39{
40 return parent ? *AddDirectory(parent->Path(), name) : name;
41}
42
43void 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)
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
67{
68 Load();
69 return entries;
70}
71
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
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
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
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}
void Add(cListObject *Object, cListObject *After=NULL)
Definition tools.c:2168
void Sort(void)
Definition tools.c:2292
Definition tools.h:631
const T * Prev(const T *Object) const
Definition tools.h:647
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
Definition tools.h:643
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:650
const T * Last(void) const
Returns the last element in this list, or NULL if the list is empty.
Definition tools.h:645
const cPictureEntry * FirstPicture(void) const
Definition entry.c:72
void Load(void) const
Definition entry.c:43
const cPictureEntry * LastPicture(void) const
Definition entry.c:89
const cPictureEntry * PrevPicture(const cPictureEntry *This=NULL) const
Definition entry.c:106
const cPictureEntry * parent
Definition entry.h:17
const cPictureEntry * Parent(void) const
Definition entry.h:26
const cPictureEntry * NextPicture(const cPictureEntry *This=NULL) const
Definition entry.c:125
bool IsDirectory(void) const
Definition entry.h:27
const char * Name(void) const
Definition entry.h:25
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater",...
Definition entry.c:25
virtual ~cPictureEntry()
Definition entry.c:19
cList< cPictureEntry > * entries
Definition entry.h:19
const cList< cPictureEntry > * Entries(void) const
Definition entry.c:66
cString Path(void) const
Definition entry.c:38
cPictureEntry(const char *Name, const cPictureEntry *Parent, bool IsDirectory)
Definition entry.c:11
bool isDirectory
Definition entry.h:18
char * name
Definition entry.h:16
struct dirent * Next(void)
Definition tools.c:1601
bool Ok(void)
Definition tools.h:459
cString AddDirectory(const char *DirName, const char *FileName)
Definition tools.c:407
#define LOG_ERROR_STR(s)
Definition tools.h:40