Sophie

Sophie

distrib > Mandriva > 2007.1 > x86_64 > by-pkgid > fdddaca718fdaac56c6bff726f3554dd > files > 26

vdr-1.4.7-9mdv2007.1.src.rpm

#! /bin/sh /usr/share/dpatch/dpatch-run
## 03_cmdsubmenu.dpatch by Albu at vdrportal.de
## http://toms-cafe.de/vdr/download/vdr-cmdsubmenu-0.7-1.4.0.diff (applicable to VDR >= 1.3.36)
##
## 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 -Naur vdr-1.4.0/README.cmdsubmenu vdr-1.4.0-cmdsubmenu-0.7/README.cmdsubmenu
--- vdr-1.4.0/README.cmdsubmenu	1970-01-01 01:00:00.000000000 +0100
+++ vdr-1.4.0-cmdsubmenu-0.7/README.cmdsubmenu	2006-05-15 13:49:50.000000000 +0200
@@ -0,0 +1,54 @@
+CmdSubmenu patch for VDR
+------------------------
+
+With this patch the commands and recording commands menus can be organised
+hierarchically. To create a submenu entry, prefix the name by one ore more "-".
+
+
+Standard:
+
+description_1 : cmd_1
+description_2 : cmd_2
+
+
+A submenu with two entries:
+
+Submenu title ... : echo "submenu"
+-description_1 : cmd_1
+-description_2 : cmd_2
+
+The dummy command in the title row is necessary.
+
+
+* History
+
+  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 <tg@e-tobi.net>
+    - Added Define CMD_SUBMENUS in Makefile
+
+  2004-05-28: Version 0.3 - Thomas Günther <tom@toms-cafe.de>
+    - Fixed compilation with gcc-3.3.3
+    - Added new virtual method AddConfig in cConfig
+    - Redefining of method Add in cListBase to virtual no longer necessary
+    - Improved code in menu.c
+    http://toms-cafe.de/vdr/download/vdr-cmdsubmenu-0.3.diff
+
+  2004-12-20: Version 0.4 - Thomas Günther <tom@toms-cafe.de>
+    - Solved conflict with jumpplay patch 0.6
+    http://toms-cafe.de/vdr/download/vdr-cmdsubmenu-0.4.diff
+
+  2006-04-22: Version 0.5 - Thomas Günther <tom@toms-cafe.de>
+    - Added version define CMDSUBMENUVERSNUM
+    - Reformated to VDR style indentions
+    - Added description in README.cmdsubmenu
+    http://toms-cafe.de/vdr/download/vdr-cmdsubmenu-0.5-1.3.47.diff
+
+  2006-04-23: Version 0.6 - Thomas Günther <tom@toms-cafe.de>
+    - Fixed menus with more than one level
+    http://toms-cafe.de/vdr/download/vdr-cmdsubmenu-0.6-1.3.47.diff
+
+  2006-05-15: Version 0.7 - Thomas Günther <tom@toms-cafe.de>
+    - Fixed build with G++ 4.1 (extra qualification)
+    http://toms-cafe.de/vdr/download/vdr-cmdsubmenu-0.7-1.4.0.diff
diff -Naur vdr-1.4.0/config.c vdr-1.4.0-cmdsubmenu-0.7/config.c
--- vdr-1.4.0/config.c	2006-04-17 14:43:57.000000000 +0200
+++ vdr-1.4.0-cmdsubmenu-0.7/config.c	2006-05-15 13:45:23.000000000 +0200
@@ -28,18 +28,26 @@
 {
   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;
+     while (*s == '-') {
+           nIndent++;
+           s++;
+           }
      int l = p - s;
      if (l > 0) {
         title = MALLOC(char, l + 1);
@@ -86,6 +94,18 @@
   return result;
 }
 
+int cCommand::getChildCount(void)
+{
+  return childs ? childs->Count() : 0;
+}
+
+void cCommand::addChild(cCommand *newChild)
+{
+  if (!childs)
+     childs = new cCommands();
+  childs->AddConfig(newChild);
+}
+
 // -- cSVDRPhost -------------------------------------------------------------
 
 cSVDRPhost::cSVDRPhost(void)
@@ -125,6 +145,21 @@
 cCommands Commands;
 cCommands RecordingCommands;
 
+void cCommands::AddConfig(cCommand *Object)
+{
+  if (!Object)
+     return;
+  //isyslog ("Indent %d %s\n", Object->getIndent(), Object->Title());
+  for (int index = Count() - 1; index >= 0; index--) {
+      cCommand *parent = Get(index);
+      if (parent->getIndent() < Object->getIndent()) {
+         parent->addChild(Object);
+         return;
+         }
+      }
+  cConfig<cCommand>::Add(Object);
+}
+
 // -- cSVDRPhosts ------------------------------------------------------------
 
 cSVDRPhosts SVDRPhosts;
diff -Naur vdr-1.4.0/config.h vdr-1.4.0-cmdsubmenu-0.7/config.h
--- vdr-1.4.0/config.h	2006-04-29 11:24:07.000000000 +0200
+++ vdr-1.4.0-cmdsubmenu-0.7/config.h	2006-05-15 14:54:26.000000000 +0200
@@ -35,6 +35,8 @@
 // plugins to work with newer versions of the core VDR as long as no
 // VDR header files have changed.
 
+#define CMDSUBMENUVERSNUM 7
+
 #define MAXPRIORITY 99
 #define MAXLIFETIME 99
 
@@ -47,11 +49,15 @@
 #define MaxSkinName 16
 #define MaxThemeName 16
 
+class cCommands;
+
 class cCommand : public cListObject {
 private:
   char *title;
   char *command;
   bool confirm;
+  int nIndent;
+  cCommands *childs;
   static char *result;
 public:
   cCommand(void);
@@ -60,6 +66,12 @@
   const char *Title(void) { return title; }
   bool Confirm(void) { return confirm; }
   const char *Execute(const char *Parameters = NULL);
+  int getIndent(void) { return nIndent; }
+  void setIndent(int nNewIndent) { nIndent = nNewIndent; }
+  cCommands *getChilds(void) { return childs; }
+  int getChildCount(void);
+  bool hasChilds(void) { return getChildCount() > 0; }
+  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)
@@ -87,6 +99,7 @@
 public:
   cConfig(void) { fileName = NULL; }
   virtual ~cConfig() { free(fileName); }
+  virtual void AddConfig(T *Object) { cList<T>::Add(Object); }
   const char *FileName(void) { return fileName; }
   bool Load(const char *FileName = NULL, bool AllowComments = false, bool MustExist = false)
   {
@@ -116,7 +129,7 @@
                 if (!isempty(s)) {
                    T *l = new T;
                    if (l->Parse(s))
-                      Add(l);
+                      AddConfig(l);
                    else {
                       esyslog("ERROR: error in %s, line %d", fileName, line);
                       delete l;
@@ -158,7 +171,10 @@
   }
   };
 
-class cCommands : public cConfig<cCommand> {};
+class cCommands : public cConfig<cCommand> {
+public:
+  virtual void AddConfig(cCommand *Object);
+  };
 
 class cSVDRPhosts : public cConfig<cSVDRPhost> {
 public:
diff -Naur vdr-1.4.0/menu.c vdr-1.4.0-cmdsubmenu-0.7/menu.c
--- vdr-1.4.0/menu.c	2006-04-28 14:48:01.000000000 +0200
+++ vdr-1.4.0-cmdsubmenu-0.7/menu.c	2006-05-15 13:45:23.000000000 +0200
@@ -1522,6 +1522,10 @@
   if (command) {
      char *buffer = NULL;
      bool confirmed = true;
+     if (command->hasChilds()) {
+        AddSubMenu(new cMenuCommands(command->Title(), command->getChilds(), parameters));
+        return osContinue;
+        }
      if (command->Confirm()) {
         asprintf(&buffer, "%s?", command->Title());
         confirmed = Interface->Confirm(buffer);