diff options
-rw-r--r-- | sources.mk | 2 | ||||
-rw-r--r-- | src/RecursiveMenuSetup.cpp | 270 | ||||
-rw-r--r-- | src/RecursiveMenuSetup.h | 55 | ||||
-rw-r--r-- | src/mainmenuitemsprovider.cpp | 8 | ||||
-rw-r--r-- | src/menuitemsetup.cpp | 2 | ||||
-rw-r--r-- | src/menunode.cpp | 9 | ||||
-rw-r--r-- | src/menunode.h | 5 | ||||
-rw-r--r-- | src/menuorg.cpp | 6 | ||||
-rw-r--r-- | src/pluginmenunode.cpp | 2 | ||||
-rw-r--r-- | src/pluginsetup.cpp | 12 | ||||
-rw-r--r-- | src/submenunode.cpp | 5 | ||||
-rw-r--r-- | src/submenunode.h | 1 |
12 files changed, 364 insertions, 13 deletions
@@ -11,6 +11,7 @@ SRCS = \ src/pluginitemdefinition.cpp \ src/pluginmenunode.cpp \ src/pluginsetup.cpp \ + src/RecursiveMenuSetup.cpp \ src/submenunode.cpp \ src/systemmenunode.cpp \ src/i18n.cpp \ @@ -19,3 +20,4 @@ SRCS = \ src/osdxmlitem.cpp \ src/osdlineitem.cpp \ src/linemenunode.cpp \ +# src/XmlConfigBuilder.cpp \ diff --git a/src/RecursiveMenuSetup.cpp b/src/RecursiveMenuSetup.cpp new file mode 100644 index 0000000..02d5a7e --- /dev/null +++ b/src/RecursiveMenuSetup.cpp @@ -0,0 +1,270 @@ +/* + * 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: menusetup.cpp 6104 2007-08-28 22:38:14Z svntcreutz $ + * + */ + +#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> + +using namespace std; + +class MenuSetupItemsFactory: IMenuNodeProcessor +{ +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) + { + string text = "(M) " + node->Text(); + _osdMenu->Add(new cOsdItem(text.c_str())); + } + + void ProcessCommandMenuNode(CommandMenuNode* node) + { + string text = "(S) " + node->Text(); + _osdMenu->Add(new cOsdItem(text.c_str())); + } + + 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(); +} + +RecursiveMenuSetup::~RecursiveMenuSetup() +{ +} + +void RecursiveMenuSetup::CreateMenuItems() +{ + MenuSetupItemsFactory menuItemSetupFactory(this); + menuItemSetupFactory.SetupItems(_rootMenu); +} + +eOSState RecursiveMenuSetup::ProcessKey(eKeys Key) +{ + + if (_moving && ((Key == kUp) || (Key == kDown))) + { + return MoveCurrentItem(Key == kUp); + } + + eOSState state = cOsdMenu::ProcessKey(Key); + + if(HasSubMenu()) + { + return state; + } + + if ((state == osUnknown) && SelectedItem()) + { + switch(Key) + { + case kOk: + if (_moving) + { + StopMoving(); + return osContinue; + } + else + { + return ShowSubOrEditMenuForSelectedItem(); + } + break; + case kRed: + if (!_moving) StartMoving(); + break; + case kBlue: + return ShowEditMenuForSelectedItem(); + default: + break; + } + } + return state; +} + +void RecursiveMenuSetup::StartMoving() +{ + _moving = true; + SetStatus("Move with Up/Down and confirm with OK"); + SetHelp(NULL); +} + +void RecursiveMenuSetup::StopMoving() +{ + _moving = false; + SetStatus(NULL); + ShowHelp(); +} + +eOSState RecursiveMenuSetup::MoveCurrentItem(bool moveUp) +{ + int oldPos = Current(); + int newPos = Current(); + + MenuNode* node = _rootMenu.Childs()->at(oldPos); + + if ((oldPos > 0) && (oldPos < Count())) + { + if (moveUp) + { + newPos = oldPos - 1; + } + else + { + newPos = oldPos + 1; + } + + _rootMenu.Childs()->erase(_rootMenu.Childs()->begin() + oldPos); + _rootMenu.Childs()->insert(_rootMenu.Childs()->begin() + newPos, node); + + Clear(); + CreateMenuItems(); + SetCurrent(Get(newPos)); + Display(); + } + + return osContinue; +} + +void RecursiveMenuSetup::ShowHelp() +{ + SetHelp("Move", "Delete", "New", "Edit"); +} + +eOSState RecursiveMenuSetup::ShowEditMenuForSelectedItem() +{ + cOsdMenu* editMenu = MenuEditMenusFactory::Create(*SelectedItem()); + 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(); + } +} diff --git a/src/RecursiveMenuSetup.h b/src/RecursiveMenuSetup.h new file mode 100644 index 0000000..b09d6e2 --- /dev/null +++ b/src/RecursiveMenuSetup.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 ___RECURSIVEMENUSETUP_H_ +#define ___RECURSIVEMENUSETUP_H_ + +#include <vdr/menu.h> +#include "imenunodeprocessor.h" + +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(); +}; + +#endif diff --git a/src/mainmenuitemsprovider.cpp b/src/mainmenuitemsprovider.cpp index ee62f3e..35c22d1 100644 --- a/src/mainmenuitemsprovider.cpp +++ b/src/mainmenuitemsprovider.cpp @@ -49,8 +49,8 @@ MenuItemDefinitions* MainMenuItemsProvider::MainMenuItems() { ResetMainMenuItemsList(); - for (MenuNodeList::iterator i = _currentMenu->Childs().begin(); - i != _currentMenu->Childs().end(); i++) + for (MenuNodeList::iterator i = _currentMenu->Childs()->begin(); + i != _currentMenu->Childs()->end(); i++) { if (!(*i)->IsHidden()) { @@ -83,7 +83,7 @@ void MainMenuItemsProvider::EnterSubMenu(cOsdItem* item) int itemIndex = IndexOfCustomOsdItem(item); if (itemIndex >= 0) { - _currentMenu = _currentMenu->Childs().at(itemIndex); + _currentMenu = _currentMenu->Childs()->at(itemIndex); } } @@ -105,7 +105,7 @@ cOsdMenu* MainMenuItemsProvider::Execute(cOsdItem* item) int itemIndex = IndexOfCustomOsdItem(item); if (itemIndex >= 0) { - return _currentMenu->Childs().at(itemIndex)->Execute(); + return _currentMenu->Childs()->at(itemIndex)->Execute(); } return NULL; } diff --git a/src/menuitemsetup.cpp b/src/menuitemsetup.cpp index c63aa1c..27583a7 100644 --- a/src/menuitemsetup.cpp +++ b/src/menuitemsetup.cpp @@ -56,7 +56,7 @@ cMenuItemSetup::~cMenuItemSetup() void cMenuItemSetup::CreateMenuItems(void) { esyslog("menuorg: _newItemType=%d", _newItemType); - esyslog("menuorg: _newTitle=%s", &_newTitle); + esyslog("menuorg: _newTitle=%s", _newTitle); Clear(); diff --git a/src/menunode.cpp b/src/menunode.cpp index 26ce3fc..b50a6cf 100644 --- a/src/menunode.cpp +++ b/src/menunode.cpp @@ -41,9 +41,9 @@ MenuNode* MenuNode::Parent() return _parent; } -MenuNodeList& MenuNode::Childs() +MenuNodeList* MenuNode::Childs() { - return _childs; + return &_childs; } MenuNode* MenuNode::AddChild(MenuNode* child) @@ -53,6 +53,11 @@ MenuNode* MenuNode::AddChild(MenuNode* child) return child; } +bool MenuNode::IsLeaf() +{ + return true; +} + void MenuNode::SetParent(MenuNode* parent) { _parent = parent; diff --git a/src/menunode.h b/src/menunode.h index 9d699f0..a51f61c 100644 --- a/src/menunode.h +++ b/src/menunode.h @@ -36,7 +36,7 @@ class MenuNode { private: MenuNode* _parent; - MenuNodeList _childs; + MenuNodeList _childs; protected: void SetParent(MenuNode* parent); @@ -45,8 +45,9 @@ class MenuNode MenuNode(); virtual ~MenuNode(); MenuNode* Parent(); - MenuNodeList& Childs(); + MenuNodeList* Childs(); MenuNode* AddChild(MenuNode* child); + virtual bool IsLeaf(); virtual void Process(IMenuNodeProcessor* menuNodeProcessor) = 0; virtual cOsdMenu* Execute(); virtual bool IsHidden(); diff --git a/src/menuorg.cpp b/src/menuorg.cpp index 94b3c34..d06994c 100644 --- a/src/menuorg.cpp +++ b/src/menuorg.cpp @@ -108,7 +108,11 @@ bool MenuOrgPlugin::ProcessArgs(int argc, char *argv[]) bool MenuOrgPlugin::Initialize(void) { - _configFile = (string) ConfigDirectory() + "/menuorg.xml"; + if (_configFile.empty()) + { + _configFile = (string) ConfigDirectory() + "/menuorg.xml"; + } + _menuConfiguration = new MenuConfiguration(_configFile, _pluginConfiguration.UnconfiguredPluginsInluded()); // TODO need handling of unloadable config File here!!! diff --git a/src/pluginmenunode.cpp b/src/pluginmenunode.cpp index 4b17a42..af45efe 100644 --- a/src/pluginmenunode.cpp +++ b/src/pluginmenunode.cpp @@ -62,5 +62,5 @@ int PluginMenuNode::PluginIndex(){ } std::string PluginMenuNode::Title(){ - return NULL; + return _title; } diff --git a/src/pluginsetup.cpp b/src/pluginsetup.cpp index cb4461e..54d2a72 100644 --- a/src/pluginsetup.cpp +++ b/src/pluginsetup.cpp @@ -25,6 +25,8 @@ #include "menuorg.h" #include "pluginsetup.h" #include "menusetup.h" +#include "RecursiveMenuSetup.h" +#include "menuconfiguration.h" PluginSetup::PluginSetup(PluginConfiguration& pluginConfiguration, MenuConfiguration& menuConfiguration) :_pluginConfiguration(pluginConfiguration), _menuConfiguration(menuConfiguration) @@ -55,8 +57,14 @@ eOSState PluginSetup::ProcessKey(eKeys Key) switch(state) { case osUser1: - return AddSubMenu(new cMenuOrgSetup(_menuConfiguration, _pluginConfiguration._menuSetupStyle)); - break; + if (_pluginConfiguration.MenuSetupStyle() == 0 ) + { + return AddSubMenu(new cMenuOrgSetup(_menuConfiguration, _pluginConfiguration._menuSetupStyle)); + } + else + { + return AddSubMenu(new RecursiveMenuSetup(*_menuConfiguration.MenuTree())); + } case osContinue: if(NORMALKEY(Key)==kUp || NORMALKEY(Key)==kDown) diff --git a/src/submenunode.cpp b/src/submenunode.cpp index 27b7526..95a15d2 100644 --- a/src/submenunode.cpp +++ b/src/submenunode.cpp @@ -33,6 +33,11 @@ SubMenuNode::SubMenuNode(string text) _text = text; } +bool SubMenuNode::IsLeaf() +{ + return false; +} + string SubMenuNode::Text() { return _text; diff --git a/src/submenunode.h b/src/submenunode.h index 0c00739..5ad1c6b 100644 --- a/src/submenunode.h +++ b/src/submenunode.h @@ -38,6 +38,7 @@ class SubMenuNode: public MenuNode std::string Text(); // MenuNode + bool IsLeaf(); virtual void Process(IMenuNodeProcessor* menuNodeProcessor); bool IsHidden(); }; |