diff options
-rw-r--r-- | README | 28 | ||||
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | sources.mk | 1 | ||||
-rw-r--r-- | src/commandmenunode.cpp | 82 | ||||
-rw-r--r-- | src/commandmenunode.h | 45 | ||||
-rw-r--r-- | src/mainmenuitemsprovider.cpp | 32 | ||||
-rw-r--r-- | src/mainmenuitemsprovider.h | 2 | ||||
-rw-r--r-- | src/menuconfiguration.cpp | 14 | ||||
-rw-r--r-- | src/menuconfiguration.h | 1 | ||||
-rw-r--r-- | src/menunode.cpp | 5 | ||||
-rw-r--r-- | src/menunode.h | 2 | ||||
-rwxr-xr-x | vdr-patch/menuorg-0.1.diff | 34 |
12 files changed, 223 insertions, 24 deletions
@@ -60,15 +60,16 @@ Menu file format The menu configuration file, is a simple XML file and has to conform to it's syntax rules. The root node always is <menus>. -There are only three kinds of menu items described by the following XML tags: +There are only four kinds of menu items described by the following XML tags: - <system> : System menu items, like the channels list or the timers - <plugin> : Plug-in menu items - <menu> : A sub menu + <system> : System menu items, like the channels list or the timers + <plugin> : Plug-in menu items + <menu> : A sub menu + <command> : An external command to be excuted, similar to VDR's commands.conf -In the menu hierarchy <system> and <plug-in> are leaf nodes, whereas <menu> is -an internal node. <menu> may contain any number of <system>, <plugin> or <menu> -nodes. +In the menu hierarchy <system>, <plug-in> and <command> are leaf nodes, whereas +<menu> is an internal node. <menu> may contain any number of <system>, <plugin>, +<command> or <menu> nodes. Each node is described by a name attribute. For <system> nodes, the following names are possible: @@ -82,8 +83,16 @@ names are possible: The name of a <plugin> node describes the plug-ins name, not it's main menu text. -With the name attribute in <menu> nodes, the main menu title of this sub menu -will be set. +With the name attribute in <menu> or <command> nodes, the main menu title of this +sub menu or command will be set. + +Besides the name attribute, a <command> also requires the "execute" attribute, +which is the command to be executed and an optional "confirm" attribute. +With confirm="yes", you will be asked to press OK before executing the command +or abort with any other key. + +e.g.: + <command name="Free Disk Space" execute="df -h" confirm="yes" /> <system> items not configured in the menu configuration will not be visible in VDR's OSD. Plug-ins that are not configured in the xml file, will be shown @@ -120,5 +129,6 @@ e.g.: <system name="Commands" /> <plug-in name="sysinfo" /> <plug-in name="femon" /> + <command name="CPU-Info" confirm="yes" execute="cat /proc/cpuinfo" /> </menu> </menus> @@ -4,5 +4,4 @@ Some Stuff that whe would integrade in future version: - Setup OSD for managing the submenu - reload the config file when opening mainmenu (only when menu configuration has been changed - checking timestamp of xml!) - alternate titles for plugins -- command handling like the setup plugin - Enable / Disable in OSD-Setup @@ -1,4 +1,5 @@ SRCS = \ + src/commandmenunode.cpp \ src/mainmenuitemsprovider.cpp \ src/menuconfiguration.cpp \ src/menunode.cpp \ diff --git a/src/commandmenunode.cpp b/src/commandmenunode.cpp new file mode 100644 index 0000000..ff44bef --- /dev/null +++ b/src/commandmenunode.cpp @@ -0,0 +1,82 @@ +/* + * vdr-menuorg - A plugin for the Linux Video Disk Recorder + * Copyright (C) 2007 Thomas Creutz, Tobias Grimm + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id: submenunode.cpp 5835 2007-08-19 21:45:51Z svntcreutz $ + * + */ + +#include "commandmenunode.h" +#include <vdr/osdbase.h> +#include <vdr/interface.h> +#include <vdr/menu.h> +#include "osditemdefinition.h" + +using namespace std; + +CommandMenuNode::CommandMenuNode(string text, string command, bool confirm) +{ + _text = text; + _command = command; + _confirm = confirm; +} + +IMenuItemDefinition* CommandMenuNode::CreateMenuItemDefinition() +{ + return new OsdItemDefinition(new cOsdItem(_text.c_str(), osUser2)); +} + +cOsdMenu* CommandMenuNode::Execute() +{ + bool confirmed = true; + if (_confirm) + { + confirmed = Interface->Confirm((_text + '?').c_str()); + } + if (confirmed) + { + Skins.Message(mtStatus, (_text + "...").c_str()); + string result = ExecuteCommand(); + Skins.Message(mtStatus, NULL); + if (!result.empty()) + { + return new cMenuText(_text.c_str(), result.c_str(), fontFix); + } + } + return NULL; +} + +string CommandMenuNode::ExecuteCommand() +{ + string result; + dsyslog("executing command '%s'", _command.c_str()); + cPipe pipe; + if (pipe.Open(_command.c_str(), "r")) + { + int c; + while ((c = fgetc(pipe)) != EOF) + { + result += (char) c; + } + pipe.Close(); + } + else + { + esyslog("ERROR: can't open pipe for command '%s'", _command.c_str()); + } + return result; +} diff --git a/src/commandmenunode.h b/src/commandmenunode.h new file mode 100644 index 0000000..55906e3 --- /dev/null +++ b/src/commandmenunode.h @@ -0,0 +1,45 @@ +/* + * vdr-menuorg - A plugin for the Linux Video Disk Recorder + * Copyright (C) 2007 Thomas Creutz, Tobias Grimm + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id:$ + * + */ + +#ifndef ___COMMANDMENUNODE_H +#define ___COMMANDMENUNODE_H + +#include "menunode.h" +#include <string> + +class CommandMenuNode: public MenuNode +{ + private: + std::string _text; + std::string _command; + bool _confirm; + + public: + CommandMenuNode(std::string text, std::string _command, bool confirm); + IMenuItemDefinition* CreateMenuItemDefinition(); + cOsdMenu* Execute(); + + private: + std::string ExecuteCommand(); +}; + +#endif diff --git a/src/mainmenuitemsprovider.cpp b/src/mainmenuitemsprovider.cpp index 8cb5469..31a1744 100644 --- a/src/mainmenuitemsprovider.cpp +++ b/src/mainmenuitemsprovider.cpp @@ -68,14 +68,10 @@ void MainMenuItemsProvider::EnterRootMenu() void MainMenuItemsProvider::EnterSubMenu(cOsdItem* item) { - for(unsigned int itemIndex=0; itemIndex < _currentMainMenuItems.size(); itemIndex++) + int itemIndex = IndexOfCustomOsdItem(item); + if (itemIndex >= 0) { - IMenuItemDefinition* menuItem = _currentMainMenuItems.at(itemIndex); - if (menuItem->IsCustomOsdItem() && (menuItem->CustomOsdItem() == item)) - { - _currentMenu = _currentMenu->Childs().at(itemIndex); - break; - } + _currentMenu = _currentMenu->Childs().at(itemIndex); } } @@ -91,3 +87,25 @@ bool MainMenuItemsProvider::LeaveSubMenu() return false; } } + +cOsdMenu* MainMenuItemsProvider::Execute(cOsdItem* item) +{ + int itemIndex = IndexOfCustomOsdItem(item); + if (itemIndex >= 0) + { + return _currentMenu->Childs().at(itemIndex)->Execute(); + } +} + +int MainMenuItemsProvider::IndexOfCustomOsdItem(cOsdItem* item) +{ + for(unsigned int itemIndex=0; itemIndex < _currentMainMenuItems.size(); itemIndex++) + { + IMenuItemDefinition* menuItem = _currentMainMenuItems.at(itemIndex); + if (menuItem->IsCustomOsdItem() && (menuItem->CustomOsdItem() == item)) + { + return itemIndex; + } + } + return -1; +} diff --git a/src/mainmenuitemsprovider.h b/src/mainmenuitemsprovider.h index 0c6b254..e7ae029 100644 --- a/src/mainmenuitemsprovider.h +++ b/src/mainmenuitemsprovider.h @@ -41,9 +41,11 @@ class MainMenuItemsProvider: public IMainMenuItemsProvider virtual void EnterRootMenu(); virtual void EnterSubMenu(cOsdItem* item); virtual bool LeaveSubMenu(); + virtual cOsdMenu* Execute(cOsdItem* item); private: void ResetMainMenuItemsList(); + int IndexOfCustomOsdItem(cOsdItem* item); }; #endif diff --git a/src/menuconfiguration.cpp b/src/menuconfiguration.cpp index b95c330..8143c00 100644 --- a/src/menuconfiguration.cpp +++ b/src/menuconfiguration.cpp @@ -28,6 +28,7 @@ #include "systemmenunode.h" #include "submenunode.h" #include "pluginmenunode.h" +#include "commandmenunode.h" using namespace xmlpp; using namespace std; @@ -110,6 +111,14 @@ void MenuConfiguration::ParseElement(const Element* element, MenuNode* menuNode) { AddPluginMenuNode(name, menuNode); } + else if (type == "command") + { + string execute = childElement->get_attribute("execute")->get_value(); + const xmlpp::Attribute* confirmAttribute = childElement->get_attribute("confirm"); + bool confirm = confirmAttribute ? (confirmAttribute->get_value() == "yes") : false; + + AddPluginMenuNode(name, execute, confirm, menuNode); + } } } } @@ -204,3 +213,8 @@ void MenuConfiguration::AddUnconfiguredPlugins(MenuNode* menu) i++; } } + +void MenuConfiguration::AddPluginMenuNode(string name, string command, bool confirm, MenuNode* menu) +{ + menu->AddChild(new CommandMenuNode(name, command, confirm)); +} diff --git a/src/menuconfiguration.h b/src/menuconfiguration.h index 5518e4e..4fd7c7c 100644 --- a/src/menuconfiguration.h +++ b/src/menuconfiguration.h @@ -47,6 +47,7 @@ class MenuConfiguration void AddSystemMenuNode(std::string name, MenuNode* menu); void AddPluginMenuNode(std::string pluginName, MenuNode* menu); void AddUnconfiguredPlugins(MenuNode* menu); + void AddPluginMenuNode(std::string name, std::string command, bool confirm, MenuNode* menu); }; #endif diff --git a/src/menunode.cpp b/src/menunode.cpp index 0552484..24e4f76 100644 --- a/src/menunode.cpp +++ b/src/menunode.cpp @@ -62,3 +62,8 @@ IMenuItemDefinition* MenuNode::CreateMenuItemDefinition() { return NULL; } + +cOsdMenu* MenuNode::Execute() +{ + return NULL; +} diff --git a/src/menunode.h b/src/menunode.h index 59c2e33..bac509e 100644 --- a/src/menunode.h +++ b/src/menunode.h @@ -27,6 +27,7 @@ class IMenuItemDefinition; class MenuNode; +class cOsdMenu; typedef std::vector<MenuNode*> MenuNodeList; @@ -46,6 +47,7 @@ class MenuNode MenuNodeList& Childs(); MenuNode* AddChild(MenuNode* child); virtual IMenuItemDefinition* CreateMenuItemDefinition(); + virtual cOsdMenu* Execute(); }; #endif diff --git a/vdr-patch/menuorg-0.1.diff b/vdr-patch/menuorg-0.1.diff index 406d860..9bc15dd 100755 --- a/vdr-patch/menuorg-0.1.diff +++ b/vdr-patch/menuorg-0.1.diff @@ -1,7 +1,7 @@ diff -Nur vdr-1.4.7/mainmenuitemsprovider.h vdr-1.4.7.patched/mainmenuitemsprovider.h --- vdr-1.4.7/mainmenuitemsprovider.h 1970-01-01 01:00:00.000000000 +0100 -+++ vdr-1.4.7.patched/mainmenuitemsprovider.h 2007-08-19 21:28:32.000000000 +0200 -@@ -0,0 +1,55 @@ ++++ vdr-1.4.7.patched/mainmenuitemsprovider.h 2007-08-21 01:08:25.000000000 +0200 +@@ -0,0 +1,57 @@ +/* + * vdr-menuorg - A plugin for the Linux Video Disk Recorder + * Copyright (C) 2007 Thomas Creutz, Tobias Grimm @@ -30,6 +30,7 @@ diff -Nur vdr-1.4.7/mainmenuitemsprovider.h vdr-1.4.7.patched/mainmenuitemsprovi +#include <vector> + +class cOsdItem; ++class cOsdMenu; + +class IMenuItemDefinition +{ @@ -54,12 +55,13 @@ diff -Nur vdr-1.4.7/mainmenuitemsprovider.h vdr-1.4.7.patched/mainmenuitemsprovi + virtual void EnterRootMenu() = 0; + virtual void EnterSubMenu(cOsdItem* item) = 0; + virtual bool LeaveSubMenu() = 0; ++ virtual cOsdMenu* Execute(cOsdItem* item) = 0; +}; + +#endif //__MAINMENUITEMSPROVIDER_H diff -Nur vdr-1.4.7/menu.c vdr-1.4.7.patched/menu.c --- vdr-1.4.7/menu.c 2006-12-02 12:12:02.000000000 +0100 -+++ vdr-1.4.7.patched/menu.c 2007-08-19 21:28:32.000000000 +0200 ++++ vdr-1.4.7.patched/menu.c 2007-08-21 01:08:25.000000000 +0200 @@ -28,6 +28,7 @@ #include "timers.h" #include "transfer.h" @@ -113,7 +115,7 @@ diff -Nur vdr-1.4.7/menu.c vdr-1.4.7.patched/menu.c Update(true); Display(); -@@ -2966,6 +2991,32 @@ +@@ -2966,6 +2991,41 @@ state = osEnd; } break; @@ -135,7 +137,7 @@ diff -Nur vdr-1.4.7/menu.c vdr-1.4.7.patched/menu.c + } + } + break; -+ case osUser1: { ++ case osUser1: { + if (MenuOrgPatch::IsCustomMenuAvailable()) { + MenuOrgPatch::EnterSubMenu(Get(Current())); + Set(); @@ -143,13 +145,22 @@ diff -Nur vdr-1.4.7/menu.c vdr-1.4.7.patched/menu.c + } + } + break; ++ case osUser2: { ++ if (MenuOrgPatch::IsCustomMenuAvailable()) { ++ cOsdMenu* osdMenu = MenuOrgPatch::Execute(Get(Current())); ++ if (osdMenu) ++ return AddSubMenu(osdMenu); ++ return osEnd; ++ } ++ } ++ break; default: switch (Key) { case kRecord: case kRed: if (!HadSubMenu) diff -Nur vdr-1.4.7/menuorgpatch.h vdr-1.4.7.patched/menuorgpatch.h --- vdr-1.4.7/menuorgpatch.h 1970-01-01 01:00:00.000000000 +0100 -+++ vdr-1.4.7.patched/menuorgpatch.h 2007-08-19 21:28:32.000000000 +0200 -@@ -0,0 +1,91 @@ ++++ vdr-1.4.7.patched/menuorgpatch.h 2007-08-21 01:08:25.000000000 +0200 +@@ -0,0 +1,100 @@ +/* + * vdr-menuorg - A plugin for the Linux Video Disk Recorder + * Copyright (C) 2007 Thomas Creutz, Tobias Grimm @@ -236,6 +247,15 @@ diff -Nur vdr-1.4.7/menuorgpatch.h vdr-1.4.7.patched/menuorgpatch.h + } + return NULL; + } ++ ++ static cOsdMenu* Execute(cOsdItem* item) ++ { ++ if (MainMenuItemsProvider()) ++ { ++ return MainMenuItemsProvider()->Execute(item); ++ } ++ return NULL; ++ } +}; + +IMainMenuItemsProvider* MenuOrgPatch::_mainMenuItemsProvider = NULL; |