diff options
author | svntobi <svntobi@cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f> | 2007-09-09 23:51:48 +0000 |
---|---|---|
committer | svntobi <svntobi@cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f> | 2007-09-09 23:51:48 +0000 |
commit | 54a81935b17db6a192e51ccbb0c0521dc58ee282 (patch) | |
tree | 69e547754082a8e96da7370c6f4380da3d2da1d1 | |
parent | 3ec475ea9846e02414684de3b5943d7c3e7dd2ea (diff) | |
download | vdr-plugin-menuorg-54a81935b17db6a192e51ccbb0c0521dc58ee282.tar.gz vdr-plugin-menuorg-54a81935b17db6a192e51ccbb0c0521dc58ee282.tar.bz2 |
Changed a lot !!!
git-svn-id: file:///home/tobias/sandbox/vdr/--/vdr-pkg/vdr-pkg/menuorg/trunk@6139 cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | sources.mk | 44 | ||||
-rw-r--r-- | src/ChildLock.cpp (renamed from src/childlock.cpp) | 4 | ||||
-rw-r--r-- | src/ChildLock.h (renamed from src/childlock.h) | 0 | ||||
-rw-r--r-- | src/CommandMenuNode.cpp (renamed from src/commandmenunode.cpp) | 13 | ||||
-rw-r--r-- | src/CommandMenuNode.h (renamed from src/commandmenunode.h) | 3 | ||||
-rw-r--r-- | src/FlatMenuSetup.cpp (renamed from src/menusetup.cpp) | 27 | ||||
-rw-r--r-- | src/FlatMenuSetup.h (renamed from src/menusetup.h) | 6 | ||||
-rw-r--r-- | src/IChildLockService.h (renamed from src/childlockservice.h) | 0 | ||||
-rw-r--r-- | src/IMenuNodeProcessor.h (renamed from src/imenunodeprocessor.h) | 4 | ||||
-rw-r--r-- | src/MainMenuItemsProvider.cpp (renamed from src/mainmenuitemsprovider.cpp) | 54 | ||||
-rw-r--r-- | src/MainMenuItemsProvider.h (renamed from src/mainmenuitemsprovider.h) | 16 | ||||
-rw-r--r-- | src/MenuConfigurationRepository.cpp | 192 | ||||
-rw-r--r-- | src/MenuConfigurationRepository.h (renamed from src/menuconfiguration.h) | 34 | ||||
-rw-r--r-- | src/MenuEditMenusFactory.cpp | 76 | ||||
-rw-r--r-- | src/MenuEditMenusFactory.h | 56 | ||||
-rw-r--r-- | src/MenuItemDefinitionFactory.cpp | 66 | ||||
-rw-r--r-- | src/MenuItemDefinitionFactory.h | 55 | ||||
-rw-r--r-- | src/MenuItemSetup.cpp (renamed from src/menuitemsetup.cpp) | 4 | ||||
-rw-r--r-- | src/MenuItemSetup.h (renamed from src/menuitemsetup.h) | 2 | ||||
-rw-r--r-- | src/MenuNode.cpp (renamed from src/linemenunode.cpp) | 28 | ||||
-rw-r--r-- | src/MenuNode.h (renamed from src/menunode.h) | 18 | ||||
-rw-r--r-- | src/MenuOrgPlugin.cpp (renamed from src/menuorg.cpp) | 32 | ||||
-rw-r--r-- | src/MenuOrgPlugin.h (renamed from src/menuorg.h) | 8 | ||||
-rw-r--r-- | src/MenuSetupItemsFactory.cpp | 75 | ||||
-rw-r--r-- | src/MenuSetupItemsFactory.h | 52 | ||||
-rw-r--r-- | src/OsdItemDefinition.cpp (renamed from src/osditemdefinition.cpp) | 2 | ||||
-rw-r--r-- | src/OsdItemDefinition.h (renamed from src/osditemdefinition.h) | 0 | ||||
-rw-r--r-- | src/OsdLineItem.cpp (renamed from src/osdlineitem.cpp) | 4 | ||||
-rw-r--r-- | src/OsdLineItem.h (renamed from src/osdlineitem.h) | 4 | ||||
-rw-r--r-- | src/OsdXmlItem.cpp (renamed from src/osdxmlitem.cpp) | 2 | ||||
-rw-r--r-- | src/OsdXmlItem.h (renamed from src/osdxmlitem.h) | 0 | ||||
-rw-r--r-- | src/PluginConfiguration.cpp (renamed from src/pluginconfiguration.cpp) | 4 | ||||
-rw-r--r-- | src/PluginConfiguration.h (renamed from src/pluginconfiguration.h) | 0 | ||||
-rw-r--r-- | src/PluginCreator.cpp (renamed from src/plugincreator.cpp) | 4 | ||||
-rw-r--r-- | src/PluginItemDefinition.cpp (renamed from src/pluginitemdefinition.cpp) | 8 | ||||
-rw-r--r-- | src/PluginItemDefinition.h (renamed from src/pluginitemdefinition.h) | 5 | ||||
-rw-r--r-- | src/PluginMenuNode.cpp | 106 | ||||
-rw-r--r-- | src/PluginMenuNode.h (renamed from src/pluginmenunode.h) | 16 | ||||
-rw-r--r-- | src/PluginSetup.cpp (renamed from src/pluginsetup.cpp) | 26 | ||||
-rw-r--r-- | src/PluginSetup.h (renamed from src/pluginsetup.h) | 6 | ||||
-rw-r--r-- | src/RecursiveMenuSetup.cpp | 284 | ||||
-rw-r--r-- | src/RecursiveMenuSetup.h | 44 | ||||
-rw-r--r-- | src/SeparatorMenuNode.cpp (renamed from src/menunode.cpp) | 56 | ||||
-rw-r--r-- | src/SeparatorMenuNode.h (renamed from src/linemenunode.h) | 17 | ||||
-rw-r--r-- | src/SubMenuNode.cpp (renamed from src/submenunode.cpp) | 38 | ||||
-rw-r--r-- | src/SubMenuNode.h (renamed from src/submenunode.h) | 8 | ||||
-rw-r--r-- | src/SystemMenuNode.cpp (renamed from src/systemmenunode.cpp) | 40 | ||||
-rw-r--r-- | src/SystemMenuNode.h (renamed from src/systemmenunode.h) | 16 | ||||
-rw-r--r-- | src/VdrState.cpp | 68 | ||||
-rw-r--r-- | src/VdrState.h | 47 | ||||
-rw-r--r-- | src/XmlConfigurationFactory.cpp | 92 | ||||
-rw-r--r-- | src/XmlConfigurationFactory.h | 55 | ||||
-rw-r--r-- | src/menuconfiguration.cpp | 261 | ||||
-rw-r--r-- | src/pluginmenunode.cpp | 66 |
55 files changed, 1354 insertions, 795 deletions
@@ -4,3 +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!) - Enable / Disable in OSD-Setup +- When leaving a sub menu position the selection to the menu entry (requires the patch to be changed) @@ -1,23 +1,27 @@ SRCS = \ - src/childlock.cpp \ - src/commandmenunode.cpp \ - src/mainmenuitemsprovider.cpp \ - src/menuconfiguration.cpp \ - src/menunode.cpp \ - src/menuorg.cpp \ - src/osditemdefinition.cpp \ - src/pluginconfiguration.cpp \ - src/plugincreator.cpp \ - src/pluginitemdefinition.cpp \ - src/pluginmenunode.cpp \ - src/pluginsetup.cpp \ + src/ChildLock.cpp \ + src/CommandMenuNode.cpp \ + src/MainMenuItemsProvider.cpp \ + src/MenuConfigurationRepository.cpp \ + src/MenuNode.cpp \ + src/MenuOrgPlugin.cpp \ + src/OsdItemDefinition.cpp \ + src/PluginConfiguration.cpp \ + src/PluginCreator.cpp \ + src/PluginItemDefinition.cpp \ + src/PluginMenuNode.cpp \ + src/PluginSetup.cpp \ src/RecursiveMenuSetup.cpp \ - src/submenunode.cpp \ - src/systemmenunode.cpp \ + src/SubMenuNode.cpp \ + src/SystemMenuNode.cpp \ src/i18n.cpp \ - src/menusetup.cpp \ - src/menuitemsetup.cpp \ - src/osdxmlitem.cpp \ - src/osdlineitem.cpp \ - src/linemenunode.cpp \ -# src/XmlConfigBuilder.cpp \ + src/FlatMenuSetup.cpp \ + src/MenuItemSetup.cpp \ + src/OsdXmlItem.cpp \ + src/OsdLineItem.cpp \ + src/SeparatorMenuNode.cpp \ + src/XmlConfigurationFactory.cpp \ + src/VdrState.cpp \ + src/MenuItemDefinitionFactory.cpp \ + src/MenuSetupItemsFactory.cpp \ + src/MenuEditMenusFactory.cpp \ diff --git a/src/childlock.cpp b/src/ChildLock.cpp index dbd2db2..35a8496 100644 --- a/src/childlock.cpp +++ b/src/ChildLock.cpp @@ -20,9 +20,9 @@ * */ -#include "childlock.h" +#include "ChildLock.h" #include <vdr/plugin.h> -#include "childlockservice.h" +#include "IChildLockService.h" IChildLockService* ChildLock::_childLockService = NULL; diff --git a/src/childlock.h b/src/ChildLock.h index f129b67..f129b67 100644 --- a/src/childlock.h +++ b/src/ChildLock.h diff --git a/src/commandmenunode.cpp b/src/CommandMenuNode.cpp index 1727a67..217c6c3 100644 --- a/src/commandmenunode.cpp +++ b/src/CommandMenuNode.cpp @@ -20,13 +20,11 @@ * */ -#include "commandmenunode.h" -#include <vdr/osdbase.h> +#include "CommandMenuNode.h" #include <vdr/interface.h> #include <vdr/menu.h> -#include "osditemdefinition.h" -#include "childlock.h" -#include "imenunodeprocessor.h" +#include "ChildLock.h" +#include "IMenuNodeProcessor.h" using namespace std; @@ -37,6 +35,11 @@ CommandMenuNode::CommandMenuNode(string text, string command, bool confirm) _confirm = confirm; } +CommandMenuNode* CommandMenuNode::Clone() +{ + return new CommandMenuNode(*this); +} + cOsdMenu* CommandMenuNode::Execute() { bool confirmed = true; diff --git a/src/commandmenunode.h b/src/CommandMenuNode.h index 9168e06..2607337 100644 --- a/src/commandmenunode.h +++ b/src/CommandMenuNode.h @@ -23,7 +23,7 @@ #ifndef ___COMMANDMENUNODE_H #define ___COMMANDMENUNODE_H -#include "menunode.h" +#include "MenuNode.h" #include <string> class IMenuNodeProcessor; @@ -45,6 +45,7 @@ class CommandMenuNode: public MenuNode virtual void Process(IMenuNodeProcessor* menuNodeProcessor); bool IsHidden(); cOsdMenu* Execute(); + CommandMenuNode* Clone(); private: std::string ExecuteCommand(); diff --git a/src/menusetup.cpp b/src/FlatMenuSetup.cpp index 1f7372b..fdeda81 100644 --- a/src/menusetup.cpp +++ b/src/FlatMenuSetup.cpp @@ -20,10 +20,10 @@ * */ -#include "menusetup.h" -#include "menuconfiguration.h" -#include "menuitemsetup.h" -#include "osdxmlitem.h" +#include "FlatMenuSetup.h" +#include "MenuConfigurationRepository.h" +#include "MenuItemSetup.h" +#include "OsdXmlItem.h" #include <vdr/menu.h> #include <vdr/interface.h> #include <libxml++/libxml++.h> @@ -32,11 +32,12 @@ using namespace xmlpp; using namespace std; -cMenuOrgSetup::cMenuOrgSetup(MenuConfiguration& menuConfiguration, bool flatMenuSetup) +cMenuOrgSetup::cMenuOrgSetup(MenuConfigurationRepository& menuConfiguration, bool flatMenuSetup) :cOsdMenu(tr("Menu Setup")),_menuConfiguration(menuConfiguration) { _flatMenuSetup = flatMenuSetup; - CreateMenuItems(_menuConfiguration.Configuration(), 0); + // todo + //CreateMenuItems(_menuConfiguration.Configuration(), 0); } void cMenuOrgSetup::CreateMenuItems(const Element* menuRoot, int iCount) @@ -99,28 +100,28 @@ eOSState cMenuOrgSetup::ProcessKey(eKeys Key) case kRed: DrawButton(); break; - + case kGreen: { cOsdXmlItem *item = (cOsdXmlItem*) Get(Current()); state = AddSubMenu(new cMenuItemSetup(item)); } break; - + case kYellow: DrawButton(); break; - + case kBlue: DrawButton(); break; - + case kUp: case kDown: case kLeft: DrawButton(); break; - + case kOk: if (Interface->Confirm(tr("Apply Changes?"))) { @@ -128,11 +129,11 @@ eOSState cMenuOrgSetup::ProcessKey(eKeys Key) } return osEnd; break; - + case kBack : return osBack; break; - + default: DrawButton(); break; diff --git a/src/menusetup.h b/src/FlatMenuSetup.h index 8fd64e7..be991f3 100644 --- a/src/menusetup.h +++ b/src/FlatMenuSetup.h @@ -28,16 +28,16 @@ namespace xmlpp { class Element; } -class MenuConfiguration; +class MenuConfigurationRepository; class cMenuOrgSetup : public cOsdMenu { private: - MenuConfiguration& _menuConfiguration; + MenuConfigurationRepository& _menuConfiguration; bool _flatMenuSetup; public: - cMenuOrgSetup(MenuConfiguration& menuConfiguration, bool flatMenuSetup); + cMenuOrgSetup(MenuConfigurationRepository& menuConfiguration, bool flatMenuSetup); virtual eOSState ProcessKey(eKeys Key); private: diff --git a/src/childlockservice.h b/src/IChildLockService.h index f677f72..f677f72 100644 --- a/src/childlockservice.h +++ b/src/IChildLockService.h diff --git a/src/imenunodeprocessor.h b/src/IMenuNodeProcessor.h index 5d3657d..e0ddab8 100644 --- a/src/imenunodeprocessor.h +++ b/src/IMenuNodeProcessor.h @@ -27,7 +27,7 @@ class SystemMenuNode; class PluginMenuNode; class SubMenuNode; class CommandMenuNode; -class LineMenuNode; +class SeparatorMenuNode; class IMenuNodeProcessor { @@ -37,7 +37,7 @@ class IMenuNodeProcessor virtual void ProcessPluginMenuNode(PluginMenuNode* node) = 0; virtual void ProcessSubMenuNode(SubMenuNode* node) = 0; virtual void ProcessCommandMenuNode(CommandMenuNode* node) = 0; - virtual void ProcessLineMenuNode(LineMenuNode* node) = 0; + virtual void ProcessSeparatorMenuNode(SeparatorMenuNode* node) = 0; }; #endif diff --git a/src/mainmenuitemsprovider.cpp b/src/MainMenuItemsProvider.cpp index 35c22d1..13fab09 100644 --- a/src/mainmenuitemsprovider.cpp +++ b/src/MainMenuItemsProvider.cpp @@ -20,28 +20,19 @@ * */ -#include "mainmenuitemsprovider.h" -#include "submenunode.h" -#include "systemmenunode.h" -#include "pluginmenunode.h" -#include "commandmenunode.h" -#include "linemenunode.h" -#include <vdr/plugin.h> -#include "childlock.h" -#include "menuconfiguration.h" -#include "osditemdefinition.h" -#include "pluginitemdefinition.h" -#include "osdlineitem.h" - -MainMenuItemsProvider::MainMenuItemsProvider(MenuConfiguration& menuConfiguration) - :_menuConfiguration(menuConfiguration) +#include "MainMenuItemsProvider.h" +#include "SubMenuNode.h" +#include "MenuConfigurationRepository.h" +#include "MenuItemDefinitionFactory.h" + +MainMenuItemsProvider::MainMenuItemsProvider(MenuConfigurationRepository& menuConfigurationRepository) + :_menuConfigurationRepository(menuConfigurationRepository) { EnterRootMenu(); } MainMenuItemsProvider::~MainMenuItemsProvider() { - delete _rootMenu; ResetMainMenuItemsList(); } @@ -54,8 +45,7 @@ MenuItemDefinitions* MainMenuItemsProvider::MainMenuItems() { if (!(*i)->IsHidden()) { - (*i)->Process(this); - _currentMainMenuItems.push_back(_createdMenuItemDefinition); + _currentMainMenuItems.push_back(MenuItemDefinitionFactory::CreateFromMenuNode(*i)); } } @@ -64,7 +54,6 @@ MenuItemDefinitions* MainMenuItemsProvider::MainMenuItems() void MainMenuItemsProvider::ResetMainMenuItemsList() { - for( MenuItemDefinitions::iterator i = _currentMainMenuItems.begin(); i != _currentMainMenuItems.end(); i++) { @@ -75,15 +64,15 @@ void MainMenuItemsProvider::ResetMainMenuItemsList() void MainMenuItemsProvider::EnterRootMenu() { - _currentMenu = _rootMenu = _menuConfiguration.MenuTree();; + _currentMenu = _menuConfigurationRepository.Load(); + // TODO; Handling of unloadable config file should not be done here } void MainMenuItemsProvider::EnterSubMenu(cOsdItem* item) { - int itemIndex = IndexOfCustomOsdItem(item); - if (itemIndex >= 0) + if (MenuNode* menuNode = MenuNodeMatchingOsdItem(item)) { - _currentMenu = _currentMenu->Childs()->at(itemIndex); + menuNode->Process(this); } } @@ -102,48 +91,43 @@ bool MainMenuItemsProvider::LeaveSubMenu() cOsdMenu* MainMenuItemsProvider::Execute(cOsdItem* item) { - int itemIndex = IndexOfCustomOsdItem(item); - if (itemIndex >= 0) + if (MenuNode* menuNode = MenuNodeMatchingOsdItem(item)) { - return _currentMenu->Childs()->at(itemIndex)->Execute(); + return menuNode->Execute(); } return NULL; } -int MainMenuItemsProvider::IndexOfCustomOsdItem(cOsdItem* item) +MenuNode* MainMenuItemsProvider::MenuNodeMatchingOsdItem(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 _currentMenu->Childs()->at(itemIndex); } } - return -1; + return NULL; } void MainMenuItemsProvider::ProcessCommandMenuNode(CommandMenuNode* node) { - _createdMenuItemDefinition = new OsdItemDefinition(new cOsdItem(node->Text().c_str(), osUser2)); } void MainMenuItemsProvider::ProcessPluginMenuNode(PluginMenuNode* node) { - _createdMenuItemDefinition = new PluginItemDefinition(node->Title().c_str(), node->PluginIndex()); } void MainMenuItemsProvider::ProcessSubMenuNode(SubMenuNode* node) { - _createdMenuItemDefinition = new OsdItemDefinition(new cOsdItem(node->Text().c_str(), osUser1)); + _currentMenu = node; } void MainMenuItemsProvider::ProcessSystemMenuNode(SystemMenuNode* node) { - _createdMenuItemDefinition = new OsdItemDefinition(new cOsdItem(tr(node->Text().c_str()), node->State())); } -void MainMenuItemsProvider::ProcessLineMenuNode(LineMenuNode* node) +void MainMenuItemsProvider::ProcessSeparatorMenuNode(SeparatorMenuNode* node) { - _createdMenuItemDefinition = new OsdItemDefinition(new cOsdLineItem(node->Text().c_str())); } diff --git a/src/mainmenuitemsprovider.h b/src/MainMenuItemsProvider.h index fa7e93e..91845be 100644 --- a/src/mainmenuitemsprovider.h +++ b/src/MainMenuItemsProvider.h @@ -24,22 +24,20 @@ #define ___MAINMENUITEMSPROVIDER_H #include <vdr/mainmenuitemsprovider.h> -#include "imenunodeprocessor.h" +#include "IMenuNodeProcessor.h" class MenuNode; -class MenuConfiguration; +class MenuConfigurationRepository; class MainMenuItemsProvider: public IMainMenuItemsProvider, public IMenuNodeProcessor { private: - MenuNode* _rootMenu; - MenuNode* _currentMenu; + SubMenuNode* _currentMenu; MenuItemDefinitions _currentMainMenuItems; - MenuConfiguration& _menuConfiguration; - IMenuItemDefinition* _createdMenuItemDefinition; + MenuConfigurationRepository& _menuConfigurationRepository; public: - MainMenuItemsProvider(MenuConfiguration& menuConfiguration); + MainMenuItemsProvider(MenuConfigurationRepository& menuConfigurationRepository); ~MainMenuItemsProvider(); // IMenuNodeProcessor @@ -54,11 +52,11 @@ class MainMenuItemsProvider: public IMainMenuItemsProvider, public IMenuNodeProc void ProcessPluginMenuNode(PluginMenuNode* node); void ProcessSubMenuNode(SubMenuNode* node); void ProcessCommandMenuNode(CommandMenuNode* node); - void ProcessLineMenuNode(LineMenuNode* node); + void ProcessSeparatorMenuNode(SeparatorMenuNode* node); private: void ResetMainMenuItemsList(); - int IndexOfCustomOsdItem(cOsdItem* item); + MenuNode* MenuNodeMatchingOsdItem(cOsdItem* item); }; #endif diff --git a/src/MenuConfigurationRepository.cpp b/src/MenuConfigurationRepository.cpp new file mode 100644 index 0000000..647bc88 --- /dev/null +++ b/src/MenuConfigurationRepository.cpp @@ -0,0 +1,192 @@ +/* + * 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$ + * + */ + +#include "MenuConfigurationRepository.h" +#include <exception> +#include <iostream> +#include <sys/types.h> +#include <sys/stat.h> +#include <libxml++/libxml++.h> +#include <glibmm/convert.h> +#include "SystemMenuNode.h" +#include "SubMenuNode.h" +#include "PluginMenuNode.h" +#include "CommandMenuNode.h" +#include "SeparatorMenuNode.h" +#include "XmlConfigurationFactory.h" + +using namespace xmlpp; +using namespace std; + +const string MenuConfigurationRepository::_dtd = + "<!ELEMENT menus ((menu | system | plugin | command | separator)+)>\n" + "<!ELEMENT menu ((menu | system | plugin | command | separator)+)>\n" + "<!ATTLIST menu name CDATA #REQUIRED>\n" + "<!ELEMENT system EMPTY>\n" + "<!ATTLIST system\n" + " name CDATA #REQUIRED\n" + " title CDATA #IMPLIED>\n" + "<!ELEMENT plugin EMPTY>\n" + "<!ATTLIST plugin\n" + " name CDATA #REQUIRED\n" + " title CDATA #IMPLIED>\n" + "<!ELEMENT command EMPTY>\n" + "<!ATTLIST command\n" + " name CDATA #REQUIRED\n" + " execute CDATA #REQUIRED\n" + " confirm (yes|no) #IMPLIED>" + "<!ELEMENT separator EMPTY>\n" + "<!ATTLIST separator\n" + " title CDATA #IMPLIED>\n"; + +MenuConfigurationRepository::MenuConfigurationRepository(string menuFileName) +{ + _configurationFileName = menuFileName; + _cachedMenuConfiguration = NULL; + _lastConfigFileModificationTime = 0; +} + +MenuConfigurationRepository::~MenuConfigurationRepository() +{ + delete _cachedMenuConfiguration; +} + +SubMenuNode* MenuConfigurationRepository::Load() +{ + if (ConfigFileHasBeenChange()) + { + try + { + dsyslog("loading menuorg config file from %s", _configurationFileName.c_str()); + + DomParser _parser; + + _parser.set_substitute_entities(); + _parser.parse_file(_configurationFileName); + + DtdValidator validator; + validator.parse_memory(_dtd); + + Document *document = _parser.get_document(); + validator.validate( document ); + + if (document) + { + _lastConfigFileModificationTime = CurrentConfigFileModificationTime(); + delete _cachedMenuConfiguration; + _cachedMenuConfiguration = new SubMenuNode("root"); + CreateMenuTree(document->get_root_node(), _cachedMenuConfiguration); + } + + } + catch(const std::exception& ex) + { + cerr << "menuorg: Exception caught when parsing xml configuration: " << ex.what(); + esyslog("Exception caught when parsing xml configuration. See stderr output for details."); + } + } + return _cachedMenuConfiguration; +} + +void MenuConfigurationRepository::Save(SubMenuNode& menuConfiguration) +{ + Document* doc = XmlConfigurationFactory::CreateXmlConfig(&menuConfiguration); + doc->write_to_file_formatted(_configurationFileName); +} + +bool MenuConfigurationRepository::ConfigFileHasBeenChange() +{ + return (CurrentConfigFileModificationTime() != _lastConfigFileModificationTime); +} + +time_t MenuConfigurationRepository::CurrentConfigFileModificationTime() +{ + struct stat fileState; + if (stat(_configurationFileName.c_str(), &fileState) == 0) + { + return fileState.st_mtim.tv_sec; + } + return 0; +} + +void MenuConfigurationRepository::CreateMenuTree(const Element* menuRoot, SubMenuNode* menuNode) +{ + Node::NodeList children = menuRoot->get_children(); + for (Node::NodeList::iterator i = children.begin(); i != children.end(); i++) + { + const Element* childElement = dynamic_cast<const Element*>(*i); + + if (childElement) + { + string type = childElement->get_name(); + string name = GetAttributeValue(childElement, "name", ""); + + if ( type == "menu") + { + SubMenuNode* subMenu = new SubMenuNode(name); + subMenu->AddToParent(menuNode); + CreateMenuTree(childElement, subMenu); + } + else if (type == "system") + { + menuNode->AddChild(new SystemMenuNode(VdrState::ByName(name), GetTitle(childElement, ""))); + } + else if (type == "plugin") + { + menuNode->AddChild(new PluginMenuNode(name, GetTitle(childElement, ""))); + } + else if (type == "command") + { + string execute = childElement->get_attribute("execute")->get_value(); + bool confirm = GetAttributeValue(childElement, "confirm", "false") == "yes"; + menuNode->AddChild(new CommandMenuNode(name, execute, confirm)); + } + else if (type == "separator") + { + menuNode->AddChild(new SeparatorMenuNode(GetTitle(childElement, ""))); + } + } + } +} + +string MenuConfigurationRepository::UnicodeToLocaleOrIso8859(Glib::ustring unicodeString) +{ + try + { + return Glib::locale_from_utf8(unicodeString); + } + catch (Glib::ConvertError) + { + return Glib::convert_with_fallback(unicodeString, "ISO8859-15", "UTF-8"); + } +} + +string MenuConfigurationRepository::GetTitle(const Element* node, string defaultValue) +{ + return GetAttributeValue(node, "title", defaultValue); +} + +string MenuConfigurationRepository::GetAttributeValue(const Element* node, string name, string defaultValue) +{ + const Attribute* attribute = node->get_attribute(name); + return attribute ? (string) UnicodeToLocaleOrIso8859(attribute->get_value()) : defaultValue; +} diff --git a/src/menuconfiguration.h b/src/MenuConfigurationRepository.h index 42359c2..0e6f4f5 100644 --- a/src/menuconfiguration.h +++ b/src/MenuConfigurationRepository.h @@ -25,39 +25,33 @@ #include <string> #include <vector> -#include <vdr/osdbase.h> -#include <libxml++/libxml++.h> #include <glibmm/ustring.h> namespace xmlpp { class Element; } class MenuNode; -class cPlugin; +class SubMenuNode; -class MenuConfiguration +class MenuConfigurationRepository { private: static const std::string _dtd; - bool _unconfiguredPluginsShouldBeIncluded; - std::vector<std::string> _configuredPlugins; - xmlpp::Element* _configuration; - xmlpp::DomParser _parser; + std::string _configurationFileName; + time_t _lastConfigFileModificationTime; + SubMenuNode* _cachedMenuConfiguration; public: - MenuConfiguration(std::string menuFileName, bool unconfiguredPluginsShouldBeIncluded); - MenuNode* MenuTree(); - xmlpp::Element* Configuration(); + MenuConfigurationRepository(std::string menuFileName); + ~MenuConfigurationRepository(); + SubMenuNode* Load(); + void Save(SubMenuNode& menuConfiguration); private: - void CreateMenuTree(const xmlpp::Element* menuRoot, MenuNode* menuNode); - eOSState MenuTextToVdrState(std::string menuText); - bool FindPluginByName(std::string name, cPlugin*& plugin, int& pluginIndex); - MenuNode* AddSubMenuNode(std::string name, MenuNode* menu); - void AddSystemMenuNode(std::string name, std::string title, MenuNode* menu); - void AddPluginMenuNode(std::string pluginName, std::string title, MenuNode* menu); - void AddUnconfiguredPlugins(MenuNode* menu); - void AddCommandMenuNode(std::string name, std::string command, bool confirm, MenuNode* menu); - void AddLineMenuNode(std::string text, MenuNode* menu); + bool ConfigFileHasBeenChange(); + time_t CurrentConfigFileModificationTime(); + void CreateMenuTree(const xmlpp::Element* menuRoot, SubMenuNode* menuNode); std::string UnicodeToLocaleOrIso8859(Glib::ustring unicodeString); + std::string GetTitle(const xmlpp::Element* node, std::string defaultValue); + std::string GetAttributeValue(const xmlpp::Element* node, std::string name, std::string defaultValue); }; #endif diff --git a/src/MenuEditMenusFactory.cpp b/src/MenuEditMenusFactory.cpp new file mode 100644 index 0000000..745b56f --- /dev/null +++ b/src/MenuEditMenusFactory.cpp @@ -0,0 +1,76 @@ +/* + * 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: childlock.cpp 5951 2007-08-24 05:45:20Z svntcreutz $ + * + */ + +#include "MenuEditMenusFactory.h" +#include "CommandMenuNode.h" +#include "PluginMenuNode.h" +#include "SystemMenuNode.h" +#include "SubMenuNode.h" +#include "SeparatorMenuNode.h" +#include <vdr/osdbase.h> +#include "RecursiveMenuSetup.h" + +cOsdMenu* MenuEditMenusFactory::Create(MenuNode& menuNode, bool openSubmenuInsteadOfEditing) +{ + cOsdMenu* menu = NULL; + MenuEditMenusFactory editMenusFactory(menu, openSubmenuInsteadOfEditing); + menuNode.Process(&editMenusFactory); + return menu; +} + +void MenuEditMenusFactory::ProcessSystemMenuNode(SystemMenuNode* node) +{ + _menu = new cOsdMenu("Edit System Menu Node"); +} + +void MenuEditMenusFactory::ProcessPluginMenuNode(PluginMenuNode* node) +{ + _menu = new cOsdMenu("Edit Plugin Menu Node"); +} + +void MenuEditMenusFactory::ProcessSubMenuNode(SubMenuNode* node) +{ + if (_openSubmenuInsteadOfEditing) + { + _menu = new RecursiveMenuSetup(NULL, node); + } + else + { + _menu = new cOsdMenu("Edit Sub Menu Node"); + } +} + +void MenuEditMenusFactory::ProcessCommandMenuNode(CommandMenuNode* node) +{ + _menu = new cOsdMenu("Edit Command Menu Node"); +} + +void MenuEditMenusFactory::ProcessSeparatorMenuNode(SeparatorMenuNode* nod) +{ + _menu = new cOsdMenu("Edit Separator Menu Node"); +} + +MenuEditMenusFactory::MenuEditMenusFactory(cOsdMenu*& menu, bool openSubmenuInsteadOfEditing) + :_menu(menu) +{ + _openSubmenuInsteadOfEditing = openSubmenuInsteadOfEditing; +} diff --git a/src/MenuEditMenusFactory.h b/src/MenuEditMenusFactory.h new file mode 100644 index 0000000..4188162 --- /dev/null +++ b/src/MenuEditMenusFactory.h @@ -0,0 +1,56 @@ +/* + * 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 ___MENUEDITMENUSFACTORY_H_ +#define ___MENUEDITMENUSFACTORY_H_ + +#include "IMenuNodeProcessor.h" + +class SubMenuNode; +class SystemMenuNode; +class PluginMenuNode; +class CommandMenuNode; +class SeparatorMenuNode; +class MenuNode; +class cOsdMenu; + +class MenuEditMenusFactory: IMenuNodeProcessor +{ + private: + cOsdMenu*& _menu; + bool _openSubmenuInsteadOfEditing; + + public: + static cOsdMenu* Create(MenuNode& menuNode, bool openSubmenuInsteadOfEditing); + + // IMenuNodeProcessor + void ProcessSystemMenuNode(SystemMenuNode* node); + void ProcessPluginMenuNode(PluginMenuNode* node); + void ProcessSubMenuNode(SubMenuNode* node); + void ProcessCommandMenuNode(CommandMenuNode* node); + void ProcessSeparatorMenuNode(SeparatorMenuNode* node); + + private: + MenuEditMenusFactory(cOsdMenu*& menu, bool openSubmenuInsteadOfEditing); +}; + +#endif diff --git a/src/MenuItemDefinitionFactory.cpp b/src/MenuItemDefinitionFactory.cpp new file mode 100644 index 0000000..d7667de --- /dev/null +++ b/src/MenuItemDefinitionFactory.cpp @@ -0,0 +1,66 @@ +/* + * 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: mainmenuitemsprovider.cpp 6133 2007-09-05 00:00:12Z svntobi $ + * + */ + +#include "MenuItemDefinitionFactory.h" +#include "SubMenuNode.h" +#include "SystemMenuNode.h" +#include "PluginMenuNode.h" +#include "CommandMenuNode.h" +#include "SeparatorMenuNode.h" +#include "OsdItemDefinition.h" +#include "PluginItemDefinition.h" +#include "OsdLineItem.h" +#include <string> + +using namespace std; + +IMenuItemDefinition* MenuItemDefinitionFactory::CreateFromMenuNode(MenuNode* menuNode) +{ + MenuItemDefinitionFactory* factory = new MenuItemDefinitionFactory(); + menuNode->Process(factory); + return factory->_createdMenuItemDefinition; +} + +void MenuItemDefinitionFactory::ProcessSystemMenuNode(SystemMenuNode* node) +{ + _createdMenuItemDefinition = new OsdItemDefinition(new cOsdItem(node->DisplayText().c_str(), node->State().OSState())); +} + +void MenuItemDefinitionFactory::ProcessPluginMenuNode(PluginMenuNode* node) +{ + _createdMenuItemDefinition = new PluginItemDefinition(node->DisplayText(), node->PluginIndex()); +} + +void MenuItemDefinitionFactory::ProcessSubMenuNode(SubMenuNode* node) +{ + _createdMenuItemDefinition = new OsdItemDefinition(new cOsdItem(node->Text().c_str(), osUser1)); +} + +void MenuItemDefinitionFactory::ProcessCommandMenuNode(CommandMenuNode* node) +{ + _createdMenuItemDefinition = new OsdItemDefinition(new cOsdItem(node->Text().c_str(), osUser2)); +} + +void MenuItemDefinitionFactory::ProcessSeparatorMenuNode(SeparatorMenuNode* node) +{ + _createdMenuItemDefinition = new OsdItemDefinition(new cOsdSeparatorItem(node->DisplayText().c_str())); +} diff --git a/src/MenuItemDefinitionFactory.h b/src/MenuItemDefinitionFactory.h new file mode 100644 index 0000000..1e0ad5f --- /dev/null +++ b/src/MenuItemDefinitionFactory.h @@ -0,0 +1,55 @@ +/* + * 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 MENUITEMDEFINITIONFACTORY_H_ +#define MENUITEMDEFINITIONFACTORY_H_ + +#include <vdr/mainmenuitemsprovider.h> +#include "IMenuNodeProcessor.h" + +class MenuNode; +class SystemMenuNode; +class PluginMenuNode; +class SubMenuNode; +class CommandMenuNode; +class SeparatorMenuNode; + +class MenuItemDefinitionFactory: IMenuNodeProcessor +{ + private: + IMenuItemDefinition* _createdMenuItemDefinition; + + public: + static IMenuItemDefinition* CreateFromMenuNode(MenuNode* menuNode); + + // IMenuNodeProcessor + void ProcessSystemMenuNode(SystemMenuNode* node); + void ProcessPluginMenuNode(PluginMenuNode* node); + void ProcessSubMenuNode(SubMenuNode* node); + void ProcessCommandMenuNode(CommandMenuNode* node); + void ProcessSeparatorMenuNode(SeparatorMenuNode* node); + + private: + MenuItemDefinitionFactory(){}; +}; + +#endif diff --git a/src/menuitemsetup.cpp b/src/MenuItemSetup.cpp index 27583a7..6059a47 100644 --- a/src/menuitemsetup.cpp +++ b/src/MenuItemSetup.cpp @@ -21,8 +21,8 @@ */ #include <iostream> -#include "menuitemsetup.h" -#include "osdxmlitem.h" +#include "MenuItemSetup.h" +#include "OsdXmlItem.h" cMenuItemSetup::cMenuItemSetup(cOsdXmlItem* osdXmlItem) :cOsdMenu(tr("Item Setup")) diff --git a/src/menuitemsetup.h b/src/MenuItemSetup.h index 7ecf373..b58b33b 100644 --- a/src/menuitemsetup.h +++ b/src/MenuItemSetup.h @@ -24,7 +24,7 @@ #define ___MENUITEMSETUP_H #include <vdr/menu.h> -#include "osdxmlitem.h" +#include "OsdXmlItem.h" class cMenuItemSetup : public cOsdMenu { diff --git a/src/linemenunode.cpp b/src/MenuNode.cpp index dcf2eee..e0b8e1c 100644 --- a/src/linemenunode.cpp +++ b/src/MenuNode.cpp @@ -20,23 +20,31 @@ * */ -#include "linemenunode.h" -#include "imenunodeprocessor.h" +#include "MenuNode.h" +#include "SubMenuNode.h" -using namespace std; +MenuNode::MenuNode() +{ + _parent = NULL; +} -LineMenuNode::LineMenuNode(std::string text) +SubMenuNode* MenuNode::Parent() { - _text = text; + return _parent; } -void LineMenuNode::Process(IMenuNodeProcessor* menuNodeProcessor) +void MenuNode::AddToParent(SubMenuNode* parent) { - menuNodeProcessor->ProcessLineMenuNode(this); + parent->Childs()->push_back(this); + _parent = parent; } -string LineMenuNode::Text() +cOsdMenu* MenuNode::Execute() { - return _text; + return NULL; +} -}
\ No newline at end of file +bool MenuNode::IsHidden() +{ + return false; +} diff --git a/src/menunode.h b/src/MenuNode.h index a51f61c..727c5bb 100644 --- a/src/menunode.h +++ b/src/MenuNode.h @@ -29,25 +29,23 @@ class IMenuItemDefinition; class MenuNode; class cOsdMenu; class IMenuNodeProcessor; +class SubMenuNode; typedef std::vector<MenuNode*> MenuNodeList; +class SubMenuNode; + class MenuNode { private: - MenuNode* _parent; - MenuNodeList _childs; - - protected: - void SetParent(MenuNode* parent); + SubMenuNode* _parent; public: MenuNode(); - virtual ~MenuNode(); - MenuNode* Parent(); - MenuNodeList* Childs(); - MenuNode* AddChild(MenuNode* child); - virtual bool IsLeaf(); + virtual ~MenuNode() {}; + virtual MenuNode* Clone() = 0; + SubMenuNode* Parent(); + virtual void AddToParent(SubMenuNode* parent); virtual void Process(IMenuNodeProcessor* menuNodeProcessor) = 0; virtual cOsdMenu* Execute(); virtual bool IsHidden(); diff --git a/src/menuorg.cpp b/src/MenuOrgPlugin.cpp index d06994c..038fe4e 100644 --- a/src/menuorg.cpp +++ b/src/MenuOrgPlugin.cpp @@ -29,12 +29,12 @@ #include <string> #include <getopt.h> #include "version.h" -#include "menuorg.h" -#include "menusetup.h" -#include "menuconfiguration.h" -#include "mainmenuitemsprovider.h" +#include "MenuOrgPlugin.h" +#include "FlatMenuSetup.h" +#include "MenuConfigurationRepository.h" +#include "MainMenuItemsProvider.h" #include "i18n.h" -#include "pluginsetup.h" +#include "PluginSetup.h" using namespace std; @@ -50,7 +50,7 @@ MenuOrgPlugin::MenuOrgPlugin(void) MenuOrgPlugin::~MenuOrgPlugin() { delete _subMenuProvider; - delete _menuConfiguration; + delete _menuConfigurationRepository; } const char* MenuOrgPlugin::Version(void) @@ -108,29 +108,28 @@ bool MenuOrgPlugin::ProcessArgs(int argc, char *argv[]) bool MenuOrgPlugin::Initialize(void) { - if (_configFile.empty()) - { - _configFile = (string) ConfigDirectory() + "/menuorg.xml"; - } + RegisterI18n(Phrases); - _menuConfiguration = new MenuConfiguration(_configFile, _pluginConfiguration.UnconfiguredPluginsInluded()); - // TODO need handling of unloadable config File here!!! + if (_configFile.empty()) + { + _configFile = (string) ConfigDirectory() + "/menuorg.xml"; + } - _subMenuProvider = new MainMenuItemsProvider(*_menuConfiguration); + _menuConfigurationRepository = new MenuConfigurationRepository(_configFile); - RegisterI18n(Phrases); + _subMenuProvider = new MainMenuItemsProvider(*_menuConfigurationRepository); return true; } cOsdObject *MenuOrgPlugin::MainMenuAction(void) { - return new cMenuOrgSetup(*_menuConfiguration, _pluginConfiguration.MenuSetupStyle()); + return new cMenuOrgSetup(*_menuConfigurationRepository, _pluginConfiguration.MenuSetupStyle()); } cMenuSetupPage *MenuOrgPlugin::SetupMenu(void) { - return new PluginSetup(_pluginConfiguration, *_menuConfiguration); + return new PluginSetup(_pluginConfiguration, *_menuConfigurationRepository); } bool MenuOrgPlugin::SetupParse(const char *Name, const char *Value) @@ -151,7 +150,6 @@ bool MenuOrgPlugin::Service(const char *Id, void *Data) } else { - // TODO; Handling of unloadable config file should not be done here Skins.Message(mtError, tr("Failed to load MenuOrg's config file!")); } } diff --git a/src/menuorg.h b/src/MenuOrgPlugin.h index 3ce939d..6418e10 100644 --- a/src/menuorg.h +++ b/src/MenuOrgPlugin.h @@ -25,10 +25,10 @@ #include <vdr/plugin.h> #include <string> -#include "pluginconfiguration.h" +#include "PluginConfiguration.h" class MainMenuItemsProvider; -class MenuConfiguration; +class MenuConfigurationRepository; class MenuOrgPlugin : public cPlugin { @@ -36,7 +36,7 @@ class MenuOrgPlugin : public cPlugin MainMenuItemsProvider* _subMenuProvider; std::string _configFile; PluginConfiguration _pluginConfiguration; - MenuConfiguration* _menuConfiguration; + MenuConfigurationRepository* _menuConfigurationRepository; public: MenuOrgPlugin(void); @@ -52,7 +52,7 @@ class MenuOrgPlugin : public cPlugin virtual bool SetupParse(const char* Name, const char* Value); virtual bool Service(const char* Id, void* Data = NULL); }; - + extern "C" void* VDRPluginCreator(); #endif diff --git a/src/MenuSetupItemsFactory.cpp b/src/MenuSetupItemsFactory.cpp new file mode 100644 index 0000000..6d608f7 --- /dev/null +++ b/src/MenuSetupItemsFactory.cpp @@ -0,0 +1,75 @@ +/* + * 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: childlock.cpp 5951 2007-08-24 05:45:20Z svntcreutz $ + * + */ + +#include "MenuSetupItemsFactory.h" +#include "SubMenuNode.h" +#include "SystemMenuNode.h" +#include "PluginMenuNode.h" +#include "CommandMenuNode.h" +#include "SeparatorMenuNode.h" +#include <string> +#include <vdr/osdbase.h> + +using namespace std; + +MenuSetupItemsFactory::MenuSetupItemsFactory(cOsdMenu* osdMenu) +{ + _osdMenu = osdMenu; +} + +void MenuSetupItemsFactory::SetupItems(SubMenuNode& rootMenu) +{ + for (MenuNodeList::iterator i = rootMenu.Childs()->begin(); i != rootMenu.Childs()->end(); i++) + { + (*i)->Process(this); + } +} + +void MenuSetupItemsFactory::ProcessSystemMenuNode(SystemMenuNode* node) +{ + string text = "(S) " + node->State().Name(); + _osdMenu->Add(new cOsdItem(text.c_str())); +} + +void MenuSetupItemsFactory::ProcessPluginMenuNode(PluginMenuNode* node) +{ + string text = "(P) " + node->PluginName(); + _osdMenu->Add(new cOsdItem(text.c_str())); +} + +void MenuSetupItemsFactory::ProcessSubMenuNode(SubMenuNode* node) +{ + string text = "(M) " + node->Text(); + _osdMenu->Add(new cOsdItem(text.c_str())); +} + +void MenuSetupItemsFactory::ProcessCommandMenuNode(CommandMenuNode* node) +{ + string text = "(C) " + node->Text(); + _osdMenu->Add(new cOsdItem(text.c_str())); +} + +void MenuSetupItemsFactory::ProcessSeparatorMenuNode(SeparatorMenuNode* node) +{ + string text = (string) "(-) " + node->DisplayText(); + _osdMenu->Add(new cOsdItem(text.c_str())); +} diff --git a/src/MenuSetupItemsFactory.h b/src/MenuSetupItemsFactory.h new file mode 100644 index 0000000..c4f36a8 --- /dev/null +++ b/src/MenuSetupItemsFactory.h @@ -0,0 +1,52 @@ +/* + * 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 ___MENUSETUPITEMSFACTORY_H_ +#define ___MENUSETUPITEMSFACTORY_H_ + +#include "IMenuNodeProcessor.h" + +class SubMenuNode; +class SystemMenuNode; +class PluginMenuNode; +class CommandMenuNode; +class SeparatorMenuNode; +class cOsdMenu; + +class MenuSetupItemsFactory: IMenuNodeProcessor +{ + private: + cOsdMenu* _osdMenu; + + public: + MenuSetupItemsFactory(cOsdMenu* osdMenu); + void SetupItems(SubMenuNode& rootMenu); + + // IMenuNodeProcessor + void ProcessSystemMenuNode(SystemMenuNode* node); + void ProcessPluginMenuNode(PluginMenuNode* node); + void ProcessSubMenuNode(SubMenuNode* node); + void ProcessCommandMenuNode(CommandMenuNode* node); + void ProcessSeparatorMenuNode(SeparatorMenuNode* node); +}; + +#endif diff --git a/src/osditemdefinition.cpp b/src/OsdItemDefinition.cpp index f28334b..9be51ee 100644 --- a/src/osditemdefinition.cpp +++ b/src/OsdItemDefinition.cpp @@ -20,7 +20,7 @@ * */ -#include "osditemdefinition.h" +#include "OsdItemDefinition.h" OsdItemDefinition::OsdItemDefinition(cOsdItem* osdItem) { diff --git a/src/osditemdefinition.h b/src/OsdItemDefinition.h index 0c4bad7..0c4bad7 100644 --- a/src/osditemdefinition.h +++ b/src/OsdItemDefinition.h diff --git a/src/osdlineitem.cpp b/src/OsdLineItem.cpp index a3e8461..f0600df 100644 --- a/src/osdlineitem.cpp +++ b/src/OsdLineItem.cpp @@ -20,9 +20,9 @@ * */ -#include "osdlineitem.h" +#include "OsdLineItem.h" -cOsdLineItem::cOsdLineItem(const char *Text) +cOsdSeparatorItem::cOsdSeparatorItem(const char *Text) { SetSelectable(false); SetText(Text); diff --git a/src/osdlineitem.h b/src/OsdLineItem.h index 4fb6cb6..85ce6bf 100644 --- a/src/osdlineitem.h +++ b/src/OsdLineItem.h @@ -25,10 +25,10 @@ #include <vdr/osdbase.h> -class cOsdLineItem : public cOsdItem +class cOsdSeparatorItem : public cOsdItem { public: - cOsdLineItem(const char *Text); + cOsdSeparatorItem(const char *Text); }; #endif diff --git a/src/osdxmlitem.cpp b/src/OsdXmlItem.cpp index 77e99f1..1606ec3 100644 --- a/src/osdxmlitem.cpp +++ b/src/OsdXmlItem.cpp @@ -23,7 +23,7 @@ #include <string> #include <vdr/menu.h> #include <libxml++/libxml++.h> -#include "osdxmlitem.h" +#include "OsdXmlItem.h" using namespace std; using namespace xmlpp; diff --git a/src/osdxmlitem.h b/src/OsdXmlItem.h index 1167f3d..1167f3d 100644 --- a/src/osdxmlitem.h +++ b/src/OsdXmlItem.h diff --git a/src/pluginconfiguration.cpp b/src/PluginConfiguration.cpp index 681d010..14f33d6 100644 --- a/src/pluginconfiguration.cpp +++ b/src/PluginConfiguration.cpp @@ -20,7 +20,7 @@ * */ -#include "pluginconfiguration.h" +#include "PluginConfiguration.h" #include <stdlib.h> #include <strings.h> @@ -36,7 +36,7 @@ PluginConfiguration::PluginConfiguration() bool PluginConfiguration::CustomMenuActive() { - return _customMenuActive; + return _customMenuActive; } bool PluginConfiguration::UnconfiguredPluginsInluded() diff --git a/src/pluginconfiguration.h b/src/PluginConfiguration.h index b90d6b0..b90d6b0 100644 --- a/src/pluginconfiguration.h +++ b/src/PluginConfiguration.h diff --git a/src/plugincreator.cpp b/src/PluginCreator.cpp index bffc72b..e845f56 100644 --- a/src/plugincreator.cpp +++ b/src/PluginCreator.cpp @@ -16,11 +16,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id:$ + * $Id$ * */ -#include "menuorg.h" +#include "MenuOrgPlugin.h" extern "C" void *VDRPluginCreator() { diff --git a/src/pluginitemdefinition.cpp b/src/PluginItemDefinition.cpp index f74a04d..baf09bd 100644 --- a/src/pluginitemdefinition.cpp +++ b/src/PluginItemDefinition.cpp @@ -20,9 +20,11 @@ * */ -#include "pluginitemdefinition.h" +#include "PluginItemDefinition.h" -PluginItemDefinition::PluginItemDefinition(const char* mainMenuEntry, int pluginIndex) +using namespace std; + +PluginItemDefinition::PluginItemDefinition(string mainMenuEntry, int pluginIndex) { _mainMenuEntry = mainMenuEntry; _pluginIndex = pluginIndex; @@ -45,7 +47,7 @@ cOsdItem* PluginItemDefinition::CustomOsdItem() const char* PluginItemDefinition::PluginMenuEntry() { - return _mainMenuEntry; + return _mainMenuEntry.c_str(); } int PluginItemDefinition::PluginIndex() diff --git a/src/pluginitemdefinition.h b/src/PluginItemDefinition.h index 75ad0a3..8a4be57 100644 --- a/src/pluginitemdefinition.h +++ b/src/PluginItemDefinition.h @@ -24,15 +24,16 @@ #define ___PLUGINITEMDEFINITION_H #include <vdr/mainmenuitemsprovider.h> +#include <string> class PluginItemDefinition: public IMenuItemDefinition { private: - const char* _mainMenuEntry; + std::string _mainMenuEntry; int _pluginIndex; public: - PluginItemDefinition(const char* mainMenuEntry, int pluginIndex); + PluginItemDefinition(std::string mainMenuEntry, int pluginIndex); virtual bool IsCustomOsdItem(); virtual bool IsPluginItem(); virtual cOsdItem* CustomOsdItem(); diff --git a/src/PluginMenuNode.cpp b/src/PluginMenuNode.cpp new file mode 100644 index 0000000..26f01c2 --- /dev/null +++ b/src/PluginMenuNode.cpp @@ -0,0 +1,106 @@ +/* + * 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$ + * + */ + +#include "PluginMenuNode.h" +#include <vdr/plugin.h> +#include "ChildLock.h" +#include "IMenuNodeProcessor.h" + +using namespace std; + +PluginMenuNode::PluginMenuNode(string pluginName, string customTitle) +{ + _customTitle = customTitle; + _pluginName = pluginName; + + if (!FindPluginByName(pluginName, _plugin, _pluginIndex)) + { + _plugin = NULL; + _pluginIndex = -1; + } + +} + +PluginMenuNode* PluginMenuNode::Clone() +{ + return new PluginMenuNode(*this); +} + +string PluginMenuNode::CustomTitle() +{ + return _customTitle; +} + +string PluginMenuNode::PluginName() +{ + return _pluginName; +} + +bool PluginMenuNode::IsHidden() +{ + return (!HasMainMenuEntry()) || ChildLock::IsPluginHidden(_plugin); +} + +bool PluginMenuNode::HasMainMenuEntry() +{ + return (_plugin && _plugin->MainMenuEntry()); +} + +void PluginMenuNode::Process(IMenuNodeProcessor* menuNodeProcessor) +{ + menuNodeProcessor->ProcessPluginMenuNode(this); +} + +int PluginMenuNode::PluginIndex() +{ + return _pluginIndex; +} + +bool PluginMenuNode::FindPluginByName(string name, cPlugin*& plugin, int& pluginIndex) +{ + int i = 0; + + while (cPlugin *currentPlugin = cPluginManager::GetPlugin(i)) + { + if (name == currentPlugin->Name()) + { + plugin = currentPlugin; + pluginIndex = i; + return true; + } + i++; + } + + return false; +} + +string PluginMenuNode::DisplayText() +{ + if (_customTitle.empty() && HasMainMenuEntry()) + { + return _plugin->MainMenuEntry(); + } + else + { + return _customTitle; + } +} diff --git a/src/pluginmenunode.h b/src/PluginMenuNode.h index fa89c13..0f7effd 100644 --- a/src/pluginmenunode.h +++ b/src/PluginMenuNode.h @@ -24,7 +24,7 @@ #define ___PLUGINMENUNODE_H #include <string> -#include "menunode.h" +#include "MenuNode.h" class cPlugin; class IMenuNodeProcessor; @@ -34,20 +34,24 @@ class PluginMenuNode: public MenuNode private: cPlugin* _plugin; int _pluginIndex; - std::string _title; + std::string _customTitle; + std::string _pluginName; public: - PluginMenuNode(cPlugin* plugin, int pluginIndex, std::string title = ""); - cPlugin* Plugin(); + PluginMenuNode(std::string pluginName, std::string customTitle = ""); + std::string CustomTitle(); + std::string PluginName(); int PluginIndex(); - std::string Title(); + std::string DisplayText(); // MenuNode - virtual void Process(IMenuNodeProcessor* menuNodeProcessor); + void Process(IMenuNodeProcessor* menuNodeProcessor); bool IsHidden(); + PluginMenuNode* Clone(); private: bool HasMainMenuEntry(); + bool FindPluginByName(std::string name, cPlugin*& plugin, int& pluginIndex); }; #endif diff --git a/src/pluginsetup.cpp b/src/PluginSetup.cpp index 54d2a72..a82a3c1 100644 --- a/src/pluginsetup.cpp +++ b/src/PluginSetup.cpp @@ -22,13 +22,13 @@ #include <iostream> #include <vdr/menu.h> -#include "menuorg.h" -#include "pluginsetup.h" -#include "menusetup.h" +#include "MenuOrgPlugin.h" +#include "PluginSetup.h" +#include "FlatMenuSetup.h" #include "RecursiveMenuSetup.h" -#include "menuconfiguration.h" +#include "MenuConfigurationRepository.h" -PluginSetup::PluginSetup(PluginConfiguration& pluginConfiguration, MenuConfiguration& menuConfiguration) +PluginSetup::PluginSetup(PluginConfiguration& pluginConfiguration, MenuConfigurationRepository& menuConfiguration) :_pluginConfiguration(pluginConfiguration), _menuConfiguration(menuConfiguration) { CreateMenuItems(); @@ -57,14 +57,14 @@ eOSState PluginSetup::ProcessKey(eKeys Key) switch(state) { case osUser1: - if (_pluginConfiguration.MenuSetupStyle() == 0 ) - { - return AddSubMenu(new cMenuOrgSetup(_menuConfiguration, _pluginConfiguration._menuSetupStyle)); - } - else - { - return AddSubMenu(new RecursiveMenuSetup(*_menuConfiguration.MenuTree())); - } + if (_pluginConfiguration.MenuSetupStyle() == 0 ) + { + return AddSubMenu(new cMenuOrgSetup(_menuConfiguration, _pluginConfiguration._menuSetupStyle)); + } + else + { + return AddSubMenu(new RecursiveMenuSetup(&_menuConfiguration)); + } case osContinue: if(NORMALKEY(Key)==kUp || NORMALKEY(Key)==kDown) diff --git a/src/pluginsetup.h b/src/PluginSetup.h index 99ff705..6b97d94 100644 --- a/src/pluginsetup.h +++ b/src/PluginSetup.h @@ -26,7 +26,7 @@ #include <vdr/menu.h> class PluginConfiguration; -class MenuConfiguration; +class MenuConfigurationRepository; class PluginSetup : public cMenuSetupPage { @@ -36,10 +36,10 @@ class PluginSetup : public cMenuSetupPage int _newHideMainMenuEntry; int _newMenuSetupStyle; PluginConfiguration& _pluginConfiguration; - MenuConfiguration& _menuConfiguration; + MenuConfigurationRepository& _menuConfiguration; public: - PluginSetup(PluginConfiguration& pluginConfiguration, MenuConfiguration& menuConfiguration); + PluginSetup(PluginConfiguration& pluginConfiguration, MenuConfigurationRepository& menuConfiguration); virtual eOSState ProcessKey(eKeys Key); protected: diff --git a/src/RecursiveMenuSetup.cpp b/src/RecursiveMenuSetup.cpp index 02d5a7e..b31d2d8 100644 --- a/src/RecursiveMenuSetup.cpp +++ b/src/RecursiveMenuSetup.cpp @@ -21,250 +21,164 @@ */ #include "RecursiveMenuSetup.h" -#include "menunode.h" -#include <string> -#include "commandmenunode.h" -#include "pluginmenunode.h" -#include "systemmenunode.h" -#include "submenunode.h" -#include "linemenunode.h" -#include <vdr/interface.h> +#include "SubMenuNode.h" +#include "MenuConfigurationRepository.h" +#include "MenuSetupItemsFactory.h" +#include "MenuEditMenusFactory.h" -using namespace std; - -class MenuSetupItemsFactory: IMenuNodeProcessor +RecursiveMenuSetup::RecursiveMenuSetup(MenuConfigurationRepository* menuConfigurationRepository, SubMenuNode* rootMenuNode) + :cOsdMenu(tr("Menu Configuration")), _menuConfigurationRepository(menuConfigurationRepository) { -private: - cOsdMenu* _osdMenu; - -public: - MenuSetupItemsFactory(cOsdMenu* osdMenu) - { - _osdMenu = osdMenu; - } - - void SetupItems(MenuNode& rootMenu) - { - for (MenuNodeList::iterator i = rootMenu.Childs()->begin(); i != rootMenu.Childs()->end(); i++) - { - (*i)->Process(this); - } - } - - // IMenuNodeProcessor - void ProcessSystemMenuNode(SystemMenuNode* node) - { - string text = "(C) " + node->Text(); - _osdMenu->Add(new cOsdItem(text.c_str())); - } - - void ProcessPluginMenuNode(PluginMenuNode* node) - { - string text = "(P) " + node->Title(); - _osdMenu->Add(new cOsdItem(text.c_str())); - } - - void ProcessSubMenuNode(SubMenuNode* node) + _moving = false; + if (rootMenuNode) { - string text = "(M) " + node->Text(); - _osdMenu->Add(new cOsdItem(text.c_str())); + _currentRootMenuNode = rootMenuNode; + _menuConfiguration = NULL; } - - void ProcessCommandMenuNode(CommandMenuNode* node) + else { - string text = "(S) " + node->Text(); - _osdMenu->Add(new cOsdItem(text.c_str())); + _currentRootMenuNode = _menuConfiguration = menuConfigurationRepository->Load()->Clone(); } - - void ProcessLineMenuNode(LineMenuNode* node) - { - string text = (string) "(L) " + "------------------"; - _osdMenu->Add(new cOsdItem(text.c_str())); - } -}; - -class MenuEditMenusFactory: IMenuNodeProcessor -{ -private: - cOsdMenu*& _menu; - -public: - static cOsdMenu* Create(MenuNode& menuNode) - { - cOsdMenu* menu = NULL; - MenuEditMenusFactory editMenusFactory(menu); - menuNode.Process(&editMenusFactory); - return menu; - } - - // IMenuNodeProcessor - void ProcessSystemMenuNode(SystemMenuNode* node) - { - _menu = new cOsdMenu("Edit System Menu Node"); - } - - void ProcessPluginMenuNode(PluginMenuNode* node) - { - _menu = new cOsdMenu("Edit Plugin Menu Node"); - } - - void ProcessSubMenuNode(SubMenuNode* node) - { - _menu = new cOsdMenu("Edit Sub Menu Node"); - } - - void ProcessCommandMenuNode(CommandMenuNode* node) - { - _menu = new cOsdMenu("Edit Command Menu Node"); - } - - void ProcessLineMenuNode(LineMenuNode* nod) - { - _menu = NULL; - } - -private: - MenuEditMenusFactory(cOsdMenu*& menu) - :_menu(menu) - { - } -}; - -RecursiveMenuSetup::RecursiveMenuSetup(MenuNode& rootMenu) - :cOsdMenu(tr("Menu Configuration")), _rootMenu(rootMenu) -{ - _moving = false; - CreateMenuItems(); - ShowHelp(); + CreateMenuItems(); + ShowHelp(); } RecursiveMenuSetup::~RecursiveMenuSetup() { + delete _menuConfiguration; } void RecursiveMenuSetup::CreateMenuItems() { - MenuSetupItemsFactory menuItemSetupFactory(this); - menuItemSetupFactory.SetupItems(_rootMenu); + MenuSetupItemsFactory menuItemSetupFactory(this); + menuItemSetupFactory.SetupItems(*_currentRootMenuNode); } eOSState RecursiveMenuSetup::ProcessKey(eKeys Key) { - - if (_moving && ((Key == kUp) || (Key == kDown))) - { - return MoveCurrentItem(Key == kUp); + // Catch keys that should not be processed by the base class + if (_moving) + { + if ((Key == kUp) || (Key == kDown)) + { + return MoveCurrentItem(Key == kUp); + } } - eOSState state = cOsdMenu::ProcessKey(Key); + // Process keys in base class + eOSState state = cOsdMenu::ProcessKey(Key); if(HasSubMenu()) { + return state; } + if ((state == osBack) || (state == osEnd)) + { + if (!_currentRootMenuNode->Parent()) + { + _menuConfigurationRepository->Save(*_currentRootMenuNode); + } + } + + // Process unprocessed keys if ((state == osUnknown) && SelectedItem()) { - switch(Key) + if (_moving) { - case kOk: - if (_moving) - { - StopMoving(); - return osContinue; - } - else - { - return ShowSubOrEditMenuForSelectedItem(); - } - break; - case kRed: - if (!_moving) StartMoving(); - break; - case kBlue: - return ShowEditMenuForSelectedItem(); - default: - break; + switch(Key) + { + case kOk: + StopMoving(); + return osContinue; + default: + break; + } + } + else + { + switch(Key) + { + case kOk: + return ShowEditMenuForSelectedItem(true); + case kRed: + StartMoving(); + break; + case kBlue: + return ShowEditMenuForSelectedItem(false); + default: + break; + } } } + return state; } void RecursiveMenuSetup::StartMoving() { - _moving = true; - SetStatus("Move with Up/Down and confirm with OK"); - SetHelp(NULL); + _moving = true; + SetStatus("Move with Up/Down and confirm with OK"); + SetHelp(NULL); } void RecursiveMenuSetup::StopMoving() { - _moving = false; - SetStatus(NULL); - ShowHelp(); + _moving = false; + SetStatus(NULL); + ShowHelp(); } eOSState RecursiveMenuSetup::MoveCurrentItem(bool moveUp) { - int oldPos = Current(); - int newPos = Current(); + int oldPos = Current(); + int newPos = Current(); - MenuNode* node = _rootMenu.Childs()->at(oldPos); + MenuNode* node = _currentRootMenuNode->Childs()->at(oldPos); - if ((oldPos > 0) && (oldPos < Count())) - { - if (moveUp) - { - newPos = oldPos - 1; - } - else - { - newPos = oldPos + 1; - } + if ((oldPos > 0) && moveUp) + { + newPos = oldPos - 1; + } + else if ((oldPos < Count() - 1) && !moveUp) + { + newPos = oldPos + 1; + } - _rootMenu.Childs()->erase(_rootMenu.Childs()->begin() + oldPos); - _rootMenu.Childs()->insert(_rootMenu.Childs()->begin() + newPos, node); + if (oldPos != newPos) + { + _currentRootMenuNode->Childs()->erase(_currentRootMenuNode->Childs()->begin() + oldPos); + _currentRootMenuNode->Childs()->insert(_currentRootMenuNode->Childs()->begin() + newPos, node); - Clear(); - CreateMenuItems(); - SetCurrent(Get(newPos)); - Display(); + Clear(); + CreateMenuItems(); + SetCurrent(Get(newPos)); + Display(); } - return osContinue; + return osContinue; } void RecursiveMenuSetup::ShowHelp() { - SetHelp("Move", "Delete", "New", "Edit"); + SetHelp("Move", "Delete", "New", "Edit"); } -eOSState RecursiveMenuSetup::ShowEditMenuForSelectedItem() +eOSState RecursiveMenuSetup::ShowEditMenuForSelectedItem(bool openSubmenuInsteadOfEditing) { - cOsdMenu* editMenu = MenuEditMenusFactory::Create(*SelectedItem()); - if (editMenu) - { - return AddSubMenu(editMenu); - } - else - { - return osContinue; - } + cOsdMenu* editMenu = MenuEditMenusFactory::Create(*SelectedItem(), openSubmenuInsteadOfEditing); + if (editMenu) + { + return AddSubMenu(editMenu); + } + else + { + return osContinue; + } } MenuNode* RecursiveMenuSetup::SelectedItem() { - return _rootMenu.Childs()->at(Current()); -} - -eOSState RecursiveMenuSetup::ShowSubOrEditMenuForSelectedItem() -{ - if (!SelectedItem()->IsLeaf()) - { - return AddSubMenu(new RecursiveMenuSetup(*SelectedItem())); - } - else - { - return ShowEditMenuForSelectedItem(); - } + return _currentRootMenuNode->Childs()->at(Current()); } diff --git a/src/RecursiveMenuSetup.h b/src/RecursiveMenuSetup.h index b09d6e2..8817ed4 100644 --- a/src/RecursiveMenuSetup.h +++ b/src/RecursiveMenuSetup.h @@ -24,32 +24,34 @@ #define ___RECURSIVEMENUSETUP_H_ #include <vdr/menu.h> -#include "imenunodeprocessor.h" +#include "IMenuNodeProcessor.h" +class MenuConfigurationRepository; class MenuNode; class RecursiveMenuSetup: public cOsdMenu { - private: - MenuNode& _rootMenu; - bool _moving; - - public: - RecursiveMenuSetup(MenuNode& rootMenu); - ~RecursiveMenuSetup(); - - // cOsdMenu - eOSState ProcessKey(eKeys Key); - - private: - void CreateMenuItems(); - void ShowHelp(); - void StartMoving(); - void StopMoving(); - eOSState MoveCurrentItem(bool moveUp); - eOSState ShowEditMenuForSelectedItem(); - eOSState ShowSubOrEditMenuForSelectedItem(); - MenuNode* SelectedItem(); + private: + MenuConfigurationRepository* _menuConfigurationRepository; + SubMenuNode* _menuConfiguration; + SubMenuNode* _currentRootMenuNode; + bool _moving; + + public: + RecursiveMenuSetup(MenuConfigurationRepository* menuConfigurationRepository, SubMenuNode* rootMenuNode = NULL); + ~RecursiveMenuSetup(); + + // cOsdMenu + eOSState ProcessKey(eKeys Key); + + private: + void CreateMenuItems(); + void ShowHelp(); + void StartMoving(); + void StopMoving(); + eOSState MoveCurrentItem(bool moveUp); + eOSState ShowEditMenuForSelectedItem(bool openSubmenuInsteadOfEditing); + MenuNode* SelectedItem(); }; #endif diff --git a/src/menunode.cpp b/src/SeparatorMenuNode.cpp index b50a6cf..da881d9 100644 --- a/src/menunode.cpp +++ b/src/SeparatorMenuNode.cpp @@ -20,55 +20,39 @@ * */ -#include "menunode.h" +#include "SeparatorMenuNode.h" +#include "IMenuNodeProcessor.h" -MenuNode::MenuNode() -{ - _parent = NULL; -} +using namespace std; -MenuNode::~MenuNode() +SeparatorMenuNode::SeparatorMenuNode(string customTitle) { - while (!_childs.empty()) - { - delete _childs.back(); - _childs.pop_back(); - } + _customTitle = customTitle; } -MenuNode* MenuNode::Parent() +SeparatorMenuNode* SeparatorMenuNode::Clone() { - return _parent; + return new SeparatorMenuNode(*this); } -MenuNodeList* MenuNode::Childs() +void SeparatorMenuNode::Process(IMenuNodeProcessor* menuNodeProcessor) { - return &_childs; + menuNodeProcessor->ProcessSeparatorMenuNode(this); } -MenuNode* MenuNode::AddChild(MenuNode* child) +string SeparatorMenuNode::CustomTitle() { - _childs.push_back(child); - child->SetParent(this); - return child; + return _customTitle; } -bool MenuNode::IsLeaf() +string SeparatorMenuNode::DisplayText() { - return true; -} - -void MenuNode::SetParent(MenuNode* parent) -{ - _parent = parent; -} - -cOsdMenu* MenuNode::Execute() -{ - return NULL; -} - -bool MenuNode::IsHidden() -{ - return false; + if (_customTitle.empty()) + { + return "----------------------------------"; + } + else + { + return _customTitle; + } } diff --git a/src/linemenunode.h b/src/SeparatorMenuNode.h index 69af41c..c140eb4 100644 --- a/src/linemenunode.h +++ b/src/SeparatorMenuNode.h @@ -20,24 +20,27 @@ * */ -#ifndef ___LINEMENUNODE_H -#define ___LINEMENUNODE_H +#ifndef ___SEPARATORMENUNODE_H +#define ___SEPARATORMENUNODE_H -#include "menunode.h" +#include "MenuNode.h" #include <string> class IMenuNodeProcessor; -class LineMenuNode: public MenuNode +class SeparatorMenuNode: public MenuNode { private: - std::string _text; + std::string _customTitle; public: - LineMenuNode(std::string text); - std::string Text(); + SeparatorMenuNode(std::string customTitle); + std::string CustomTitle(); + std::string DisplayText(); // MenuNode virtual void Process(IMenuNodeProcessor* menuNodeProcessor); + SeparatorMenuNode* Clone(); }; + #endif diff --git a/src/submenunode.cpp b/src/SubMenuNode.cpp index 95a15d2..664b009 100644 --- a/src/submenunode.cpp +++ b/src/SubMenuNode.cpp @@ -20,11 +20,9 @@ * */ -#include "submenunode.h" -#include <vdr/osdbase.h> -#include "osditemdefinition.h" -#include "childlock.h" -#include "imenunodeprocessor.h" +#include "SubMenuNode.h" +#include "ChildLock.h" +#include "IMenuNodeProcessor.h" using namespace std; @@ -33,9 +31,35 @@ SubMenuNode::SubMenuNode(string text) _text = text; } -bool SubMenuNode::IsLeaf() +SubMenuNode::~SubMenuNode() { - return false; + while (!_childs.empty()) + { + delete _childs.back(); + _childs.pop_back(); + } +} + +SubMenuNode* SubMenuNode::Clone() +{ + SubMenuNode* clone = new SubMenuNode(*this); + clone->Childs()->clear(); + for (MenuNodeList::iterator i = _childs.begin(); i != _childs.end(); i++) + { + (*i)->Clone()->AddToParent(clone); + } + return clone; +} + +MenuNodeList* SubMenuNode::Childs() +{ + return &_childs; +} + +MenuNode* SubMenuNode::AddChild(MenuNode* child) +{ + child->AddToParent(this); + return child; } string SubMenuNode::Text() diff --git a/src/submenunode.h b/src/SubMenuNode.h index 5ad1c6b..aa2299b 100644 --- a/src/submenunode.h +++ b/src/SubMenuNode.h @@ -23,7 +23,7 @@ #ifndef ___SUBMENUNODE_H #define ___SUBMENUNODE_H -#include "menunode.h" +#include "MenuNode.h" #include <string> class IMenuNodeProcessor; @@ -32,15 +32,19 @@ class SubMenuNode: public MenuNode { private: std::string _text; + MenuNodeList _childs; public: SubMenuNode(std::string text); + virtual ~SubMenuNode(); std::string Text(); // MenuNode - bool IsLeaf(); + SubMenuNode* Clone(); virtual void Process(IMenuNodeProcessor* menuNodeProcessor); bool IsHidden(); + MenuNode* AddChild(MenuNode* child); + MenuNodeList* Childs(); }; #endif diff --git a/src/systemmenunode.cpp b/src/SystemMenuNode.cpp index 4eb080b..23766fa 100644 --- a/src/systemmenunode.cpp +++ b/src/SystemMenuNode.cpp @@ -20,23 +20,27 @@ * */ -#include "systemmenunode.h" -#include <vdr/mainmenuitemsprovider.h> -#include "osditemdefinition.h" -#include "childlock.h" -#include "imenunodeprocessor.h" +#include "SystemMenuNode.h" +#include "ChildLock.h" +#include "IMenuNodeProcessor.h" +#include <vdr/i18n.h> using namespace std; -SystemMenuNode::SystemMenuNode(eOSState state, string text) +SystemMenuNode::SystemMenuNode(VdrState state, string customTitle) + :_state(state) { - _text = text; - _state = state; + _customTitle = customTitle; +} + +SystemMenuNode* SystemMenuNode::Clone() +{ + return new SystemMenuNode(*this); } bool SystemMenuNode::IsHidden() { - return ChildLock::IsMenuHidden(_text.c_str()); + return ChildLock::IsMenuHidden(_state.Name().c_str()); } void SystemMenuNode::Process(IMenuNodeProcessor* menuNodeProcessor) @@ -44,12 +48,24 @@ void SystemMenuNode::Process(IMenuNodeProcessor* menuNodeProcessor) menuNodeProcessor->ProcessSystemMenuNode(this); } -eOSState SystemMenuNode::State() +VdrState SystemMenuNode::State() { return _state; } -string SystemMenuNode::Text() +string SystemMenuNode::CustomTitle() +{ + return _customTitle; +} + +string SystemMenuNode::DisplayText() { - return _text; + if (_customTitle.empty()) + { + return tr(_state.Name().c_str()); + } + else + { + return _customTitle; + } } diff --git a/src/systemmenunode.h b/src/SystemMenuNode.h index 8b14f2d..6e7b5cd 100644 --- a/src/systemmenunode.h +++ b/src/SystemMenuNode.h @@ -23,25 +23,27 @@ #ifndef ___SYSTEMMENUNODE_H #define ___SYSTEMMENUNODE_H -#include "menunode.h" +#include "MenuNode.h" #include <string> -#include <vdr/osdbase.h> +#include "VdrState.h" class IMenuNodeProcessor; class SystemMenuNode: public MenuNode { private: - std::string _text; - eOSState _state; + std::string _customTitle; + VdrState _state; public: - SystemMenuNode(eOSState state, std::string text); + SystemMenuNode(VdrState state, std::string customTitle); - std::string Text(); - eOSState State(); + std::string CustomTitle(); + VdrState State(); + std::string DisplayText(); // MenuNode + SystemMenuNode* Clone(); virtual void Process(IMenuNodeProcessor* menuNodeProcessor); bool IsHidden(); }; diff --git a/src/VdrState.cpp b/src/VdrState.cpp new file mode 100644 index 0000000..eaf9b1c --- /dev/null +++ b/src/VdrState.cpp @@ -0,0 +1,68 @@ +/* + * 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: childlock.cpp 5951 2007-08-24 05:45:20Z svntcreutz $ + * + */ + +#include "VdrState.h" + +using namespace std; + +list<VdrState> VdrState::_availableStates(VdrState::InitializeAvailableStates()); + +VdrState::VdrState(eOSState state, string name) +{ + _state = state; + _name = name; +} + +list<VdrState> VdrState::InitializeAvailableStates() +{ + list<VdrState> states; + states.push_back(VdrState(osSchedule, "Schedule")); + states.push_back(VdrState(osRecordings, "Recordings")); + states.push_back(VdrState(osChannels, "Channels")); + states.push_back(VdrState(osTimers, "Timers")); + states.push_back(VdrState(osCommands, "Commands")); + states.push_back(VdrState(osSetup, "Setup")); + return states; +} + +VdrState VdrState::ByName(std::string name) +{ + for (list<VdrState>::iterator i = _availableStates.begin(); i != _availableStates.end(); i++) + { + if ((*i).Name() == name) + { + return *i; + } + } + + throw "unknown state identifier: " + name; +} + +string VdrState::Name() +{ + return _name; +} + +eOSState VdrState::OSState() +{ + return _state; +} diff --git a/src/VdrState.h b/src/VdrState.h new file mode 100644 index 0000000..081b7c5 --- /dev/null +++ b/src/VdrState.h @@ -0,0 +1,47 @@ +/* + * 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 ___VDRSTATE_H_ +#define ___VDRSTATE_H_ + +#include <string> +#include <list> +#include <vdr/osdbase.h> + +class VdrState +{ + private: + static std::list<VdrState> _availableStates; + eOSState _state; + std::string _name; + + private: + VdrState(eOSState state, std::string name); + static std::list<VdrState> InitializeAvailableStates(); + + public: + static VdrState ByName(std::string name); + eOSState OSState(); + std::string Name(); +}; + +#endif diff --git a/src/XmlConfigurationFactory.cpp b/src/XmlConfigurationFactory.cpp new file mode 100644 index 0000000..65d081f --- /dev/null +++ b/src/XmlConfigurationFactory.cpp @@ -0,0 +1,92 @@ +/* + * 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: commandmenunode.h 6123 2007-09-04 21:31:19Z svntcreutz $ + * + */ + +#include "XmlConfigurationFactory.h" +#include <libxml++/libxml++.h> +#include "SystemMenuNode.h" +#include "PluginMenuNode.h" +#include "SubMenuNode.h" +#include "CommandMenuNode.h" +#include "SeparatorMenuNode.h" + +using namespace xmlpp; + +Document* XmlConfigurationFactory::CreateXmlConfig(SubMenuNode* node) +{ + Document* doc = new Document(); + XmlConfigurationFactory xmlMenuNodeFactory(doc->create_root_node("menus")); + for (MenuNodeList::iterator i = node->Childs()->begin(); i != node->Childs()->end(); i++) + { + (*i)->Process(&xmlMenuNodeFactory); + } + return doc; +} + +void XmlConfigurationFactory::ProcessSystemMenuNode(SystemMenuNode* node) +{ + Element* systemNode = _parent->add_child("system"); + systemNode->set_attribute("name", node->State().Name()); + if (!node->CustomTitle().empty()) + { + systemNode->set_attribute("title", node->CustomTitle()); + } +} + +void XmlConfigurationFactory::ProcessPluginMenuNode(PluginMenuNode* node) +{ + Element* pluginNode = _parent->add_child("plugin"); + pluginNode->set_attribute("name", node->PluginName()); + if (!node->CustomTitle().empty()) + { + pluginNode->set_attribute("title", node->CustomTitle()); + } +} + +void XmlConfigurationFactory::ProcessSubMenuNode(SubMenuNode* node) +{ + Element* menuNode = _parent->add_child("menu"); + menuNode->set_attribute("name", node->Text()); + XmlConfigurationFactory subMenuFactory(menuNode); + for (MenuNodeList::iterator i = node->Childs()->begin(); i != node->Childs()->end(); i++) + { + (*i)->Process(&subMenuFactory); + } +} + +void XmlConfigurationFactory::ProcessCommandMenuNode(CommandMenuNode* node) +{ + Element* commandNode = _parent->add_child("command"); + commandNode->set_attribute("name", node->Text()); + commandNode->set_attribute("execute", node->Command()); + commandNode->set_attribute("confirm", node->ShouldConfirm() ? "yes" : "no"); +} + +void XmlConfigurationFactory::ProcessSeparatorMenuNode(SeparatorMenuNode* node) +{ + Element* separatorNode = _parent->add_child("separator"); + separatorNode->set_attribute("title", node->CustomTitle()); +} + +XmlConfigurationFactory::XmlConfigurationFactory(Element* parent) +{ + _parent = parent; +} diff --git a/src/XmlConfigurationFactory.h b/src/XmlConfigurationFactory.h new file mode 100644 index 0000000..7f1dc6e --- /dev/null +++ b/src/XmlConfigurationFactory.h @@ -0,0 +1,55 @@ +/* + * 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 ___XMLCONFIGURATIONFACTORY_H_ +#define ___XMLCONFIGURATIONFACTORY_H_ + +#include "IMenuNodeProcessor.h" + +namespace xmlpp { class Element; }; +namespace xmlpp { class Document; }; +class SystemMenuNode; +class PluginMenuNode; +class SubMenuNode; +class CommandMenuNode; +class SeparatorMenuNode; + +class XmlConfigurationFactory: public IMenuNodeProcessor +{ + private: + xmlpp::Element* _parent; + + public: + static xmlpp::Document* CreateXmlConfig(SubMenuNode* node); + + // IMenuNodeProcessor + void ProcessSystemMenuNode(SystemMenuNode* node); + void ProcessPluginMenuNode(PluginMenuNode* node); + void ProcessSubMenuNode(SubMenuNode* node); + void ProcessCommandMenuNode(CommandMenuNode* node); + void ProcessSeparatorMenuNode(SeparatorMenuNode* node); + + private: + XmlConfigurationFactory(xmlpp::Element* parent); +}; + +#endif diff --git a/src/menuconfiguration.cpp b/src/menuconfiguration.cpp deleted file mode 100644 index 6e462cf..0000000 --- a/src/menuconfiguration.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/* - * 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$ - * - */ - -#include "menuconfiguration.h" -#include <exception> -#include <iostream> -#include <vdr/plugin.h> -#include <glibmm/convert.h> -#include "systemmenunode.h" -#include "submenunode.h" -#include "pluginmenunode.h" -#include "commandmenunode.h" -#include "linemenunode.h" - -using namespace xmlpp; -using namespace std; - -const string MenuConfiguration::_dtd = - "<!ELEMENT menus ((menu | system | plugin | command | line)+)>\n" - "<!ELEMENT menu ((menu | system | plugin | command | line)+)>\n" - "<!ATTLIST menu name CDATA #REQUIRED>\n" - "<!ELEMENT system EMPTY>\n" - "<!ATTLIST system\n" - " name CDATA #REQUIRED\n" - " title CDATA #IMPLIED>\n" - "<!ELEMENT plugin EMPTY>\n" - "<!ATTLIST plugin\n" - " name CDATA #REQUIRED\n" - " title CDATA #IMPLIED>\n" - "<!ELEMENT command EMPTY>\n" - "<!ATTLIST command\n" - " name CDATA #REQUIRED\n" - " execute CDATA #REQUIRED\n" - " confirm (yes|no) #IMPLIED>" - "<!ELEMENT line EMPTY>\n" - "<!ATTLIST line\n" - " title CDATA #IMPLIED>\n"; - -MenuConfiguration::MenuConfiguration(string menuFileName, bool unconfiguredPluginsShouldBeIncluded) -{ - _configuration = NULL; - _unconfiguredPluginsShouldBeIncluded = unconfiguredPluginsShouldBeIncluded; - - try - { - dsyslog("loading menuorg config file from %s", menuFileName.c_str()); - - _parser.set_substitute_entities(); - _parser.parse_file(menuFileName); - - DtdValidator validator; - validator.parse_memory(_dtd); - - Document *pDoc = _parser.get_document(); - validator.validate( pDoc ); - - _configuration = _parser.get_document()->get_root_node(); - - } - catch(const std::exception& ex) - { - cerr << "menuorg: Exception caught when parsing xml configuration: " << ex.what(); - esyslog("Exception caught when parsing xml configuration. See stderr output for details."); - } -} - -Element* MenuConfiguration::Configuration() -{ - return _configuration; -} - -MenuNode* MenuConfiguration::MenuTree() -{ - if (_configuration) - { - MenuNode* menuRoot = new SubMenuNode("root"); - CreateMenuTree(_configuration, menuRoot); - - if(_unconfiguredPluginsShouldBeIncluded) - AddUnconfiguredPlugins(menuRoot); - - return menuRoot; - } - else - { - return NULL; - } -} - -void MenuConfiguration::CreateMenuTree(const Element* menuRoot, MenuNode* menuNode) -{ - Node::NodeList children = menuRoot->get_children(); - for (Node::NodeList::iterator i = children.begin(); i != children.end(); i++) - { - const Element* childElement = dynamic_cast<const Element*>(*i); - - if (childElement) - { - const Attribute* nameAttribute = childElement->get_attribute("name"); - string name = nameAttribute ? (string) UnicodeToLocaleOrIso8859(nameAttribute->get_value()) : ""; - - string type = childElement->get_name(); - - if ( type == "menu") - { - MenuNode* subMenu = AddSubMenuNode(name, menuNode); - CreateMenuTree(childElement, subMenu); - } - else if (type == "system") - { - const Attribute* titleAttribute = childElement->get_attribute("title"); - string title = titleAttribute ? (string) UnicodeToLocaleOrIso8859(titleAttribute->get_value()) : name; - AddSystemMenuNode(name, title, menuNode); - } - else if (type == "plugin") - { - const Attribute* titleAttribute = childElement->get_attribute("title"); - string title = titleAttribute ? (string) UnicodeToLocaleOrIso8859(titleAttribute->get_value()) : name; - AddPluginMenuNode(name, title, menuNode); - } - else if (type == "command") - { - string execute = childElement->get_attribute("execute")->get_value(); - const Attribute* confirmAttribute = childElement->get_attribute("confirm"); - bool confirm = confirmAttribute ? (confirmAttribute->get_value() == "yes") : false; - AddCommandMenuNode(name, execute, confirm, menuNode); - } - else if (type == "line") - { - const Attribute* titleAttribute = childElement->get_attribute("title"); - string title = titleAttribute ? (string) UnicodeToLocaleOrIso8859(titleAttribute->get_value()) : "-----------------------------------"; - AddLineMenuNode(title, menuNode); - } - } - } -} - -MenuNode* MenuConfiguration::AddSubMenuNode(string name, MenuNode* menu) -{ - return menu->AddChild(new SubMenuNode(name)); -} - -void MenuConfiguration::AddSystemMenuNode(string name, string title, MenuNode* menu) -{ - menu->AddChild(new SystemMenuNode(MenuTextToVdrState(name), title)); -} - -void MenuConfiguration::AddPluginMenuNode(string pluginName, string title, MenuNode* menu) -{ - int pluginIndex; - cPlugin* plugin; - - if (FindPluginByName(pluginName, plugin, pluginIndex)) - { - _configuredPlugins.push_back(pluginName); - menu->AddChild(new PluginMenuNode(plugin, pluginIndex, title)); - } -} - -eOSState MenuConfiguration::MenuTextToVdrState(string menuText) -{ - if (menuText == "Schedule") - { - return osSchedule; - } - else if (menuText == "Channels") - { - return osChannels; - } - else if (menuText == "Timers") - { - return osTimers; - } - else if (menuText == "Recordings") - { - return osRecordings; - } - else if (menuText == "Setup") - { - return osSetup; - } - else if (menuText == "Commands") - { - return osCommands; - } - else - return osContinue; -} - -bool MenuConfiguration::FindPluginByName(string name, cPlugin*& plugin, int& pluginIndex) -{ - int i = 0; - - while (cPlugin *currentPlugin = cPluginManager::GetPlugin(i)) - { - if (name == currentPlugin->Name()) - { - plugin = currentPlugin; - pluginIndex = i; - return true; - } - i++; - } - - return false; -} - -void MenuConfiguration::AddUnconfiguredPlugins(MenuNode* menu) -{ - int i = 0; - - while (cPlugin *plugin = cPluginManager::GetPlugin(i)) - { - if (find(_configuredPlugins.begin(), _configuredPlugins.end(), plugin->Name()) == _configuredPlugins.end()) - { - menu->AddChild(new PluginMenuNode(plugin, i)); - } - i++; - } -} - -void MenuConfiguration::AddCommandMenuNode(string name, string command, bool confirm, MenuNode* menu) -{ - menu->AddChild(new CommandMenuNode(name, command, confirm)); -} - -void MenuConfiguration::AddLineMenuNode(string text, MenuNode* menu) -{ - menu->AddChild(new LineMenuNode(text)); -} - -string MenuConfiguration::UnicodeToLocaleOrIso8859(Glib::ustring unicodeString) -{ - try - { - return Glib::locale_from_utf8(unicodeString); - } - catch (Glib::ConvertError) - { - return Glib::convert_with_fallback(unicodeString, "ISO8859-2", "UTF-8"); - } -} diff --git a/src/pluginmenunode.cpp b/src/pluginmenunode.cpp deleted file mode 100644 index af45efe..0000000 --- a/src/pluginmenunode.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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$ - * - */ - -#include <string> -#include "pluginmenunode.h" -#include <vdr/mainmenuitemsprovider.h> -#include <vdr/plugin.h> -#include "pluginitemdefinition.h" -#include "childlock.h" -#include "imenunodeprocessor.h" - -using namespace std; - -PluginMenuNode::PluginMenuNode(cPlugin* plugin, int pluginIndex, string title) -{ - _plugin = plugin; - _pluginIndex = pluginIndex; - _title = title; -} - -bool PluginMenuNode::IsHidden() -{ - return (!HasMainMenuEntry()) || ChildLock::IsPluginHidden(_plugin); -} - -bool PluginMenuNode::HasMainMenuEntry() -{ - return (_plugin->MainMenuEntry() != NULL); -} - -cPlugin* PluginMenuNode::Plugin() -{ - return _plugin; -} - -void PluginMenuNode::Process(IMenuNodeProcessor* menuNodeProcessor) -{ - menuNodeProcessor->ProcessPluginMenuNode(this); -} - -int PluginMenuNode::PluginIndex(){ - return _pluginIndex; -} - -std::string PluginMenuNode::Title(){ - return _title; -} |