diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2010-01-17 12:08:03 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2010-01-17 12:08:03 +0100 |
commit | a503c6ab3f1763c98db5677a59d4d07bf8299025 (patch) | |
tree | 8c041b2e26b1453151f73927cdb3dacbe10b2f50 /config.c | |
parent | 61c1df70040cbb9215f9735be36cf414b039a2e6 (diff) | |
download | vdr-a503c6ab3f1763c98db5677a59d4d07bf8299025.tar.gz vdr-a503c6ab3f1763c98db5677a59d4d07bf8299025.tar.bz2 |
The "Edit timer" menu can now set the folder for the recording from a list of folders stored in "folders.conf"
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 146 |
1 files changed, 145 insertions, 1 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: config.c 2.6 2009/12/05 15:30:30 kls Exp $ + * $Id: config.c 2.7 2010/01/16 14:27:29 kls Exp $ */ #include "config.h" @@ -123,6 +123,150 @@ bool cSVDRPhost::Accepts(in_addr_t Address) return (Address & mask) == (addr.s_addr & mask); } +// --- cNestedItem ----------------------------------------------------------- + +cNestedItem::cNestedItem(const char *Text, bool WithSubItems) +{ + text = strdup(Text ? Text : ""); + subItems = WithSubItems ? new cList<cNestedItem> : NULL; +} + +cNestedItem::~cNestedItem() +{ + delete subItems; + free(text); +} + +int cNestedItem::Compare(const cListObject &ListObject) const +{ + return strcasecmp(text, ((cNestedItem *)&ListObject)->text); +} + +void cNestedItem::AddSubItem(cNestedItem *Item) +{ + if (!subItems) + subItems = new cList<cNestedItem>; + if (Item) + subItems->Add(Item); +} + +void cNestedItem::SetText(const char *Text) +{ + free(text); + text = strdup(Text ? Text : ""); +} + +void cNestedItem::SetSubItems(bool On) +{ + if (On && !subItems) + subItems = new cList<cNestedItem>; + else if (!On && subItems) { + delete subItems; + subItems = NULL; + } +} + +// --- cNestedItemList ------------------------------------------------------- + +cNestedItemList::cNestedItemList(void) +{ + fileName = NULL; +} + +cNestedItemList::~cNestedItemList() +{ + free(fileName); +} + +bool cNestedItemList::Parse(FILE *f, cList<cNestedItem> *List, int &Line) +{ + char *s; + cReadLine ReadLine; + while ((s = ReadLine.Read(f)) != NULL) { + Line++; + char *p = strchr(s, '#'); + if (p) + *p = 0; + s = skipspace(stripspace(s)); + if (!isempty(s)) { + if ((p = strchr(s, '{')) != NULL) { + *p = 0; + stripspace(s); + cNestedItem *Item = new cNestedItem(s, true); + List->Add(Item); + if (!Parse(f, Item->SubItems(), Line)) + return false; + } + else if (*s == '}') + break; + else + List->Add(new cNestedItem(s)); + } + } + return true; +} + +bool cNestedItemList::Write(FILE *f, cList<cNestedItem> *List, int Indent) +{ + for (cNestedItem *Item = List->First(); Item; Item = List->Next(Item)) { + if (Item->SubItems()) { + fprintf(f, "%*s%s {\n", Indent, "", Item->Text()); + Write(f, Item->SubItems(), Indent + 2); + fprintf(f, "%*s}\n", Indent + 2, ""); + } + else + fprintf(f, "%*s%s\n", Indent, "", Item->Text()); + } + return true; +} + +void cNestedItemList::Clear(void) +{ + free(fileName); + fileName = NULL; + cList<cNestedItem>::Clear(); +} + +bool cNestedItemList::Load(const char *FileName) +{ + cList<cNestedItem>::Clear(); + if (FileName) { + free(fileName); + fileName = strdup(FileName); + } + bool result = false; + if (fileName && access(fileName, F_OK) == 0) { + isyslog("loading %s", fileName); + FILE *f = fopen(fileName, "r"); + if (f) { + int Line = 0; + result = Parse(f, this, Line); + fclose(f); + } + else { + LOG_ERROR_STR(fileName); + result = false; + } + } + return result; +} + +bool cNestedItemList::Save(void) +{ + bool result = true; + cSafeFile f(fileName); + if (f.Open()) { + result = Write(f, this); + if (!f.Close()) + result = false; + } + else + result = false; + return result; +} + +cNestedItemList Folders; + // --- cCommands ------------------------------------------------------------- cCommands Commands; |