diff options
Diffstat (limited to 'src')
-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 |
8 files changed, 176 insertions, 7 deletions
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 |