#!/bin/sh /usr/share/dpatch/dpatch-run ## cmdsubmenu patch - version 0.1 ## ## 2003-10-08: Version 0.1 - Albu at vdrportal.de ## http://vdrportal.de/board/thread.php?threadid=6319 ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Adds submenus within the commands and recording commands menu. ## DP: To create a submenu entry, prefix the name by one ore more "-". @DPATCH@ diff -ru vdr-1.2.5orig/config.c vdr-1.2.5/config.c --- vdr-1.2.5orig/config.c Sun Aug 24 13:00:24 2003 +++ vdr-1.2.5/config.c Wed Oct 8 22:22:33 2003 @@ -27,18 +27,29 @@ { title = command = NULL; confirm = false; + nIndent = 0; + childs = NULL; } cCommand::~cCommand() { free(title); free(command); + delete childs; } bool cCommand::Parse(const char *s) { const char *p = strchr(s, ':'); if (p) { + nIndent = 0; +#ifdef CMD_SUBMENUS + while (*s == '-') + { + nIndent++; + s++; + } +#endif // CMD_SUBMENUS int l = p - s; if (l > 0) { title = MALLOC(char, l + 1); @@ -83,6 +94,76 @@ esyslog("ERROR: can't open pipe for command '%s'", cmd); free(cmdbuf); return result; +} + +int cCommand::getIndent () +{ + return nIndent; +} + +void cCommand::setIndent (int nNewIndent) +{ + nIndent = nNewIndent; +} + +bool cCommand::hasChilds () +{ + if (!childs) + { + return false; + } + return (childs->Count () > 0); +} + +int cCommand::getChildCount () +{ + if (!childs) + { + return false; + } + return childs->Count (); +} + +void cCommand::addChild (cCommand *newChild) +{ + if (!childs) + { + childs = new cCommands (); + } + childs->Add (newChild); +} + + +cCommands *cCommand::getChilds () +{ + return childs; +} + +// --- cCommands ------------------------------------------------------- + +void cCommands::Add(cListObject *Object, cListObject *After = NULL) +{ + cCommand *c = (cCommand *) Object; + cCommand *cParent; + int nIndent; + int nIndex; + + if (!c) + { + return; + } + nIndent = c->getIndent (); + // isyslog ("nIndent %d %s\n", nIndent, c->Title ()); + for (nIndex = Count () - 1; nIndex >= 0; nIndex--) + { + cParent = (cCommand *) Get (nIndex); + if (cParent->getIndent () < nIndent) + { + cParent->addChild (c); + return; + } + } + cConfig::Add (Object, After); } // -- cSVDRPhost ------------------------------------------------------------- diff -ru vdr-1.2.5orig/config.h vdr-1.2.5/config.h --- vdr-1.2.5orig/config.h Wed Sep 17 18:08:56 2003 +++ vdr-1.2.5/config.h Wed Oct 8 21:42:56 2003 @@ -32,11 +32,15 @@ #define MaxFileName 256 +class cCommands; + class cCommand : public cListObject { private: char *title; char *command; bool confirm; + int nIndent; + cCommands *childs; static char *result; public: cCommand(void); @@ -45,6 +49,12 @@ const char *Title(void) { return title; } bool Confirm(void) { return confirm; } const char *Execute(const char *Parameters = NULL); + int getIndent (); + void setIndent (int nNewIndent); + bool hasChilds (); + int getChildCount (); + cCommands *getChilds (); + void addChild (cCommand *newChild); }; typedef uint32_t in_addr_t; //XXX from /usr/include/netinet/in.h (apparently this is not defined on systems with glibc < 2.2) @@ -156,7 +166,11 @@ } }; -class cCommands : public cConfig {}; +class cCommands : public cConfig +{ + public: + void Add(cListObject *Object, cListObject *After = NULL); +}; class cSVDRPhosts : public cConfig { public: diff -ru vdr-1.2.5orig/menu.c vdr-1.2.5/menu.c --- vdr-1.2.5orig/menu.c Sun Sep 14 12:49:28 2003 +++ vdr-1.2.5/menu.c Wed Oct 8 22:22:35 2003 @@ -1518,6 +1519,16 @@ if (command) { char *buffer = NULL; bool confirmed = true; +#ifdef CMD_SUBMENUS + if (command->hasChilds ()) + { + cMenuCommands *menu; + eOSState state = AddSubMenu(menu = new cMenuCommands(command->Title (), command->getChilds (), parameters)); + return osContinue; + } + else + { +#endif // CMD_SUBMENUS if (command->Confirm()) { asprintf(&buffer, "%s?", command->Title()); confirmed = Interface->Confirm(buffer); @@ -1533,7 +1544,11 @@ return AddSubMenu(new cMenuText(command->Title(), Result, fontFix)); return osEnd; } +#ifdef CMD_SUBMENUS } +#endif // CMD_SUBMENUS + + } return osContinue; } diff -ru vdr-1.2.5orig/tools.h vdr-1.2.5/tools.h --- vdr-1.2.5orig/tools.h Sun Dec 15 15:59:53 2002 +++ vdr-1.2.5/tools.h Wed Oct 8 21:38:58 2003 @@ -158,7 +158,7 @@ cListBase(void); public: virtual ~cListBase(); - void Add(cListObject *Object, cListObject *After = NULL); + virtual void Add(cListObject *Object, cListObject *After = NULL); void Ins(cListObject *Object, cListObject *Before = NULL); void Del(cListObject *Object, bool DeleteObject = true); virtual void Move(int From, int To);