summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsvntobi <svntobi@cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f>2007-09-02 00:39:06 +0000
committersvntobi <svntobi@cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f>2007-09-02 00:39:06 +0000
commite41621d535a6948b191396f9063f6bd17bb9e381 (patch)
treec0a918b22de1a874ebdf42fc1a5b82f806eb0a34 /src
parent024b9daf038ab85fe5d64b46d9d8dc0f172b4537 (diff)
downloadvdr-plugin-menuorg-e41621d535a6948b191396f9063f6bd17bb9e381.tar.gz
vdr-plugin-menuorg-e41621d535a6948b191396f9063f6bd17bb9e381.tar.bz2
Added Double Dispatch / Visitor Pattern to MenuNode in preparation of menu structure setup.
git-svn-id: file:///home/tobias/sandbox/vdr/--/vdr-pkg/vdr-pkg/menuorg/trunk@6120 cd0d6b48-d4f9-0310-940f-ab8c4eb44d3f
Diffstat (limited to 'src')
-rw-r--r--src/commandmenunode.cpp26
-rw-r--r--src/commandmenunode.h17
-rw-r--r--src/imenunodeprocessor.h41
-rw-r--r--src/mainmenuitemsprovider.cpp27
-rw-r--r--src/mainmenuitemsprovider.h28
-rw-r--r--src/menuconfiguration.cpp2
-rw-r--r--src/menunode.cpp5
-rw-r--r--src/menunode.h3
-rw-r--r--src/pluginmenunode.cpp25
-rw-r--r--src/pluginmenunode.h14
-rw-r--r--src/pluginsetup.cpp20
-rw-r--r--src/submenunode.cpp14
-rw-r--r--src/submenunode.h11
-rw-r--r--src/systemmenunode.cpp23
-rw-r--r--src/systemmenunode.h13
15 files changed, 210 insertions, 59 deletions
diff --git a/src/commandmenunode.cpp b/src/commandmenunode.cpp
index ed4328e..b5756ac 100644
--- a/src/commandmenunode.cpp
+++ b/src/commandmenunode.cpp
@@ -26,6 +26,7 @@
#include <vdr/menu.h>
#include "osditemdefinition.h"
#include "childlock.h"
+#include "imenunodeprocessor.h"
using namespace std;
@@ -36,11 +37,6 @@ CommandMenuNode::CommandMenuNode(string text, string command, bool confirm)
_confirm = confirm;
}
-IMenuItemDefinition* CommandMenuNode::CreateMenuItemDefinition()
-{
- return new OsdItemDefinition(new cOsdItem(_text.c_str(), osUser2));
-}
-
cOsdMenu* CommandMenuNode::Execute()
{
bool confirmed = true;
@@ -86,3 +82,23 @@ bool CommandMenuNode::IsHidden()
{
return ChildLock::IsMenuHidden(_text.c_str());
}
+
+void CommandMenuNode::Process(IMenuNodeProcessor* menuNodeProcessor)
+{
+ menuNodeProcessor->ProcessCommandMenuNode(this);
+}
+
+string CommandMenuNode::Command()
+{
+ return _command;
+}
+
+bool CommandMenuNode::ShouldConfirm()
+{
+ return _confirm;
+}
+
+string CommandMenuNode::Text()
+{
+ return _text;
+}
diff --git a/src/commandmenunode.h b/src/commandmenunode.h
index 913591c..c80ea2d 100644
--- a/src/commandmenunode.h
+++ b/src/commandmenunode.h
@@ -26,20 +26,27 @@
#include "menunode.h"
#include <string>
+class IMenuNodeProcessor;
+
class CommandMenuNode: public MenuNode
{
- private:
+ private:
std::string _text;
std::string _command;
bool _confirm;
- public:
+ public:
CommandMenuNode(std::string text, std::string _command, bool confirm);
- IMenuItemDefinition* CreateMenuItemDefinition();
- cOsdMenu* Execute();
+ std::string Text();
+ std::string Command();
+ bool ShouldConfirm();
+
+ // MenuNode
+ virtual void Process(IMenuNodeProcessor* menuNodeProcessor);
bool IsHidden();
+ cOsdMenu* Execute();
- private:
+ private:
std::string ExecuteCommand();
};
diff --git a/src/imenunodeprocessor.h b/src/imenunodeprocessor.h
new file mode 100644
index 0000000..641cc88
--- /dev/null
+++ b/src/imenunodeprocessor.h
@@ -0,0 +1,41 @@
+/*
+ * 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 ___IMENUNODEPROCESSOR_H_
+#define ___IMENUNODEPROCESSOR_H_
+
+class SystemMenuNode;
+class PluginMenuNode;
+class SubMenuNode;
+class CommandMenuNode;
+
+class IMenuNodeProcessor
+{
+public:
+ virtual ~IMenuNodeProcessor() {};
+ virtual void ProcessSystemMenuNode(SystemMenuNode* node) = 0;
+ virtual void ProcessPluginMenuNode(PluginMenuNode* node) = 0;
+ virtual void ProcessSubMenuNode(SubMenuNode* node) = 0;
+ virtual void ProcessCommandMenuNode(CommandMenuNode* node) = 0;
+};
+
+#endif
diff --git a/src/mainmenuitemsprovider.cpp b/src/mainmenuitemsprovider.cpp
index 05fb021..9480fe6 100644
--- a/src/mainmenuitemsprovider.cpp
+++ b/src/mainmenuitemsprovider.cpp
@@ -24,9 +24,12 @@
#include "submenunode.h"
#include "systemmenunode.h"
#include "pluginmenunode.h"
+#include "commandmenunode.h"
#include <vdr/plugin.h>
#include "childlock.h"
#include "menuconfiguration.h"
+#include "osditemdefinition.h"
+#include "pluginitemdefinition.h"
MainMenuItemsProvider::MainMenuItemsProvider(MenuConfiguration& menuConfiguration)
:_menuConfiguration(menuConfiguration)
@@ -49,7 +52,8 @@ MenuItemDefinitions* MainMenuItemsProvider::MainMenuItems()
{
if (!(*i)->IsHidden())
{
- _currentMainMenuItems.push_back((*i)->CreateMenuItemDefinition());
+ (*i)->Process(this);
+ _currentMainMenuItems.push_back(_createdMenuItemDefinition);
}
}
@@ -116,3 +120,24 @@ int MainMenuItemsProvider::IndexOfCustomOsdItem(cOsdItem* item)
}
return -1;
}
+
+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));
+}
+
+void MainMenuItemsProvider::ProcessSystemMenuNode(SystemMenuNode* node)
+{
+ _createdMenuItemDefinition = new OsdItemDefinition(new cOsdItem(tr(node->Text().c_str()), node->State()));
+
+}
diff --git a/src/mainmenuitemsprovider.h b/src/mainmenuitemsprovider.h
index 46f4748..8d61ac0 100644
--- a/src/mainmenuitemsprovider.h
+++ b/src/mainmenuitemsprovider.h
@@ -24,28 +24,38 @@
#define ___MAINMENUITEMSPROVIDER_H
#include <vdr/mainmenuitemsprovider.h>
+#include "imenunodeprocessor.h"
class MenuNode;
class MenuConfiguration;
-class MainMenuItemsProvider: public IMainMenuItemsProvider
+class MainMenuItemsProvider: public IMainMenuItemsProvider, public IMenuNodeProcessor
{
- private:
+ private:
MenuNode* _rootMenu;
MenuNode* _currentMenu;
MenuItemDefinitions _currentMainMenuItems;
MenuConfiguration& _menuConfiguration;
+ IMenuItemDefinition* _createdMenuItemDefinition;
- public:
+ public:
MainMenuItemsProvider(MenuConfiguration& menuConfiguration);
~MainMenuItemsProvider();
- virtual MenuItemDefinitions* MainMenuItems();
- virtual void EnterRootMenu();
- virtual void EnterSubMenu(cOsdItem* item);
- virtual bool LeaveSubMenu();
- virtual cOsdMenu* Execute(cOsdItem* item);
- private:
+ // IMenuNodeProcessor
+ MenuItemDefinitions* MainMenuItems();
+ void EnterRootMenu();
+ void EnterSubMenu(cOsdItem* item);
+ bool LeaveSubMenu();
+ cOsdMenu* Execute(cOsdItem* item);
+
+ // IMenuNodeProcessor
+ void ProcessSystemMenuNode(SystemMenuNode* node);
+ void ProcessPluginMenuNode(PluginMenuNode* node);
+ void ProcessSubMenuNode(SubMenuNode* node);
+ void ProcessCommandMenuNode(CommandMenuNode* node);
+
+ private:
void ResetMainMenuItemsList();
int IndexOfCustomOsdItem(cOsdItem* item);
};
diff --git a/src/menuconfiguration.cpp b/src/menuconfiguration.cpp
index e426f16..7ba7957 100644
--- a/src/menuconfiguration.cpp
+++ b/src/menuconfiguration.cpp
@@ -88,7 +88,7 @@ MenuNode* MenuConfiguration::MenuTree()
{
if (_configuration)
{
- MenuNode* menuRoot = new MenuNode();
+ MenuNode* menuRoot = new SubMenuNode("root");
CreateMenuTree(_configuration, menuRoot);
if(_unconfiguredPluginsShouldBeIncluded)
diff --git a/src/menunode.cpp b/src/menunode.cpp
index 60cdbc2..26ce3fc 100644
--- a/src/menunode.cpp
+++ b/src/menunode.cpp
@@ -58,11 +58,6 @@ void MenuNode::SetParent(MenuNode* parent)
_parent = parent;
}
-IMenuItemDefinition* MenuNode::CreateMenuItemDefinition()
-{
- return NULL;
-}
-
cOsdMenu* MenuNode::Execute()
{
return NULL;
diff --git a/src/menunode.h b/src/menunode.h
index eff60d8..9d699f0 100644
--- a/src/menunode.h
+++ b/src/menunode.h
@@ -28,6 +28,7 @@
class IMenuItemDefinition;
class MenuNode;
class cOsdMenu;
+class IMenuNodeProcessor;
typedef std::vector<MenuNode*> MenuNodeList;
@@ -46,7 +47,7 @@ class MenuNode
MenuNode* Parent();
MenuNodeList& Childs();
MenuNode* AddChild(MenuNode* child);
- virtual IMenuItemDefinition* CreateMenuItemDefinition();
+ virtual void Process(IMenuNodeProcessor* menuNodeProcessor) = 0;
virtual cOsdMenu* Execute();
virtual bool IsHidden();
};
diff --git a/src/pluginmenunode.cpp b/src/pluginmenunode.cpp
index 1e8bc5f..4b17a42 100644
--- a/src/pluginmenunode.cpp
+++ b/src/pluginmenunode.cpp
@@ -26,6 +26,7 @@
#include <vdr/plugin.h>
#include "pluginitemdefinition.h"
#include "childlock.h"
+#include "imenunodeprocessor.h"
using namespace std;
@@ -36,12 +37,6 @@ PluginMenuNode::PluginMenuNode(cPlugin* plugin, int pluginIndex, string title)
_title = title;
}
-IMenuItemDefinition* PluginMenuNode::CreateMenuItemDefinition()
-{
- const char* mainMenuEntry = _title.empty() ? _plugin->MainMenuEntry() : _title.c_str();
- return new PluginItemDefinition(mainMenuEntry, _pluginIndex);
-}
-
bool PluginMenuNode::IsHidden()
{
return (!HasMainMenuEntry()) || ChildLock::IsPluginHidden(_plugin);
@@ -51,3 +46,21 @@ 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 NULL;
+}
diff --git a/src/pluginmenunode.h b/src/pluginmenunode.h
index 2b982c4..592a547 100644
--- a/src/pluginmenunode.h
+++ b/src/pluginmenunode.h
@@ -27,20 +27,26 @@
#include "menunode.h"
class cPlugin;
+class IMenuNodeProcessor;
class PluginMenuNode: public MenuNode
{
- private:
+ private:
cPlugin* _plugin;
int _pluginIndex;
std::string _title;
- public:
+ public:
PluginMenuNode(cPlugin* plugin, int pluginIndex, std::string title = "");
- IMenuItemDefinition* CreateMenuItemDefinition();
+ cPlugin* Plugin();
+ int PluginIndex();
+ std::string Title();
+
+ // MenuNode
+ virtual void Process(IMenuNodeProcessor* menuNodeProcessor);
bool IsHidden();
- private:
+ private:
bool HasMainMenuEntry();
};
diff --git a/src/pluginsetup.cpp b/src/pluginsetup.cpp
index ed676f0..cb4461e 100644
--- a/src/pluginsetup.cpp
+++ b/src/pluginsetup.cpp
@@ -34,10 +34,14 @@ PluginSetup::PluginSetup(PluginConfiguration& pluginConfiguration, MenuConfigura
void PluginSetup::Store(void)
{
- SetupStore(PluginConfiguration::SetupName::CustomMenuActive, _pluginConfiguration._customMenuActive = _newCustomMenuActive);
- SetupStore(PluginConfiguration::SetupName::UnconfiguredPluginsIncluded, _pluginConfiguration._unconfiguredPluginsIncluded = _newUnconfiguredPluginsIncluded);
- SetupStore(PluginConfiguration::SetupName::HideMainMenuEntry, _pluginConfiguration._hideMainMenuEntry = _newHideMainMenuEntry);
- SetupStore(PluginConfiguration::SetupName::MenuSetupStyle, _pluginConfiguration._menuSetupStyle = _newMenuSetupStyle);
+ SetupStore(PluginConfiguration::SetupName::CustomMenuActive,
+ _pluginConfiguration._customMenuActive = _newCustomMenuActive);
+ SetupStore(PluginConfiguration::SetupName::UnconfiguredPluginsIncluded,
+ _pluginConfiguration._unconfiguredPluginsIncluded = _newUnconfiguredPluginsIncluded);
+ SetupStore(PluginConfiguration::SetupName::HideMainMenuEntry,
+ _pluginConfiguration._hideMainMenuEntry = _newHideMainMenuEntry);
+ SetupStore(PluginConfiguration::SetupName::MenuSetupStyle,
+ _pluginConfiguration._menuSetupStyle = _newMenuSetupStyle);
}
eOSState PluginSetup::ProcessKey(eKeys Key)
@@ -79,8 +83,8 @@ eOSState PluginSetup::ProcessKey(eKeys Key)
void PluginSetup::CreateMenuItems()
{
Add(new cMenuEditBoolItem(tr("Enable custom menu"), &_newCustomMenuActive));
- Add(new cMenuEditBoolItem(tr("Include unconfigured Plugins"), &_newUnconfiguredPluginsIncluded));
- Add(new cMenuEditBoolItem(tr("Hide MainMenu Entry"), &_newHideMainMenuEntry));
- Add(new cMenuEditBoolItem(tr("Menusetup Style"), &_newMenuSetupStyle, tr("MenuBased"),tr("Flat")));
- Add(new cOsdItem(tr("Configure Menu"), osUser1));
+ Add(new cMenuEditBoolItem(tr("Include unconfigured plugins"), &_newUnconfiguredPluginsIncluded));
+ Add(new cMenuEditBoolItem(tr("Hide main menu entry"), &_newHideMainMenuEntry));
+ Add(new cMenuEditBoolItem(tr("Menu setup style"), &_newMenuSetupStyle, tr("MenuBased"), tr("Flat")));
+ Add(new cOsdItem(tr("Configure menu"), osUser1));
}
diff --git a/src/submenunode.cpp b/src/submenunode.cpp
index eb423b8..27b7526 100644
--- a/src/submenunode.cpp
+++ b/src/submenunode.cpp
@@ -24,18 +24,26 @@
#include <vdr/osdbase.h>
#include "osditemdefinition.h"
#include "childlock.h"
+#include "imenunodeprocessor.h"
-SubMenuNode::SubMenuNode(std::string text)
+using namespace std;
+
+SubMenuNode::SubMenuNode(string text)
{
_text = text;
}
-IMenuItemDefinition* SubMenuNode::CreateMenuItemDefinition()
+string SubMenuNode::Text()
{
- return new OsdItemDefinition(new cOsdItem(_text.c_str(), osUser1));
+ return _text;
}
bool SubMenuNode::IsHidden()
{
return ChildLock::IsMenuHidden(_text.c_str());
}
+
+void SubMenuNode::Process(IMenuNodeProcessor* menuNodeProcessor)
+{
+ menuNodeProcessor->ProcessSubMenuNode(this);
+}
diff --git a/src/submenunode.h b/src/submenunode.h
index 2197265..646af2b 100644
--- a/src/submenunode.h
+++ b/src/submenunode.h
@@ -26,14 +26,19 @@
#include "menunode.h"
#include <string>
+class IMenuNodeProcessor;
+
class SubMenuNode: public MenuNode
{
- private:
+ private:
std::string _text;
- public:
+ public:
SubMenuNode(std::string text);
- IMenuItemDefinition* CreateMenuItemDefinition();
+ std::string Text();
+
+ // MenuNode
+ virtual void Process(IMenuNodeProcessor* menuNodeProcessor);
bool IsHidden();
};
diff --git a/src/systemmenunode.cpp b/src/systemmenunode.cpp
index 8098960..c095703 100644
--- a/src/systemmenunode.cpp
+++ b/src/systemmenunode.cpp
@@ -24,19 +24,32 @@
#include <vdr/mainmenuitemsprovider.h>
#include "osditemdefinition.h"
#include "childlock.h"
+#include "imenunodeprocessor.h"
-SystemMenuNode::SystemMenuNode(eOSState state, std::string text)
+using namespace std;
+
+SystemMenuNode::SystemMenuNode(eOSState state, string text)
{
_text = text;
_state = state;
}
-IMenuItemDefinition* SystemMenuNode::CreateMenuItemDefinition()
+bool SystemMenuNode::IsHidden()
{
- return new OsdItemDefinition(new cOsdItem(tr(_text.c_str()), _state));
+ return ChildLock::IsMenuHidden(_text.c_str());
}
-bool SystemMenuNode::IsHidden()
+void SystemMenuNode::Process(IMenuNodeProcessor* menuNodeProcessor)
{
- return ChildLock::IsMenuHidden(_text.c_str());
+ menuNodeProcessor->ProcessSystemMenuNode(this);
+}
+
+eOSState SystemMenuNode::State()
+{
+ return _state;
+}
+
+string SystemMenuNode::Text()
+{
+ return _text;
}
diff --git a/src/systemmenunode.h b/src/systemmenunode.h
index 5e09cf5..79e8928 100644
--- a/src/systemmenunode.h
+++ b/src/systemmenunode.h
@@ -27,15 +27,22 @@
#include <string>
#include <vdr/osdbase.h>
+class IMenuNodeProcessor;
+
class SystemMenuNode: public MenuNode
{
- private:
+ private:
std::string _text;
eOSState _state;
- public:
+ public:
SystemMenuNode(eOSState state, std::string text);
- IMenuItemDefinition* CreateMenuItemDefinition();
+
+ std::string Text();
+ eOSState State();
+
+ // MenuNode
+ virtual void Process(IMenuNodeProcessor* menuNodeProcessor);
bool IsHidden();
};