#!/bin/sh /usr/share/dpatch/dpatch-run ## cmdsubmenu patch - version 0.2 ## ## 2003-10-08: Version 0.1 - Albu at vdrportal.de ## http://vdrportal.de/board/thread.php?threadid=6319 ## ## 2003-10-09: Version 0.2 - Tobias Grimm ## Added Define CMD_SUBMENUS in Makefile ## ## 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@ --- vdr-1.2.6.orig/Makefile Thu Oct 9 11:42:01 2003 +++ vdr-1.2.6/Makefile Thu Oct 9 01:57:24 2003 @@ -51,6 +53,7 @@ DEFINES += -DREMOTE_$(REMOTE) +DEFINES += -DCMD_SUBMENUS DEFINES += -D_GNU_SOURCE DEFINES += -DVIDEODIR=\"$(VIDEODIR)\" --- vdr-1.2.6.orig/config.c Thu Oct 9 11:42:01 2003 +++ vdr-1.2.6/config.c Thu Oct 9 00:14:17 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 ------------------------------------------------------------- --- vdr-1.2.6.orig/config.h Thu Oct 9 11:42:01 2003 +++ vdr-1.2.6/config.h Thu Oct 9 01:28:20 2003 @@ -33,11 +33,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); @@ -46,6 +50,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) @@ -222,7 +232,11 @@ } }; -class cCommands : public cConfig {}; +class cCommands : public cConfig +{ + public: + virtual void Add(cListObject *Object, cListObject *After = NULL); +}; class cSVDRPhosts : public cConfig { public: --- vdr-1.2.6.orig/menu.c Thu Oct 9 11:42:01 2003 +++ vdr-1.2.6/menu.c Thu Oct 9 01:39:01 2003 @@ -28,6 +28,8 @@ #include "timers.h" #include "transfer.h" #include "videodir.h" + +/* #include "dvbsub.h" */ #include //TK @@ -1744,6 +1745,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); @@ -1759,7 +1770,11 @@ return AddSubMenu(new cMenuText(command->Title(), Result, fontFix)); return osEnd; } +#ifdef CMD_SUBMENUS } +#endif // CMD_SUBMENUS + + } return osContinue; } --- vdr-1.2.6.orig/tools.h Thu Oct 9 11:42:01 2003 +++ vdr-1.2.6/tools.h Thu Oct 9 00:14:17 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);