diff options
-rw-r--r-- | sources.mk | 1 | ||||
-rw-r--r-- | src/childlock.cpp | 93 | ||||
-rw-r--r-- | src/childlock.h | 44 | ||||
-rw-r--r-- | src/childlockservice.h | 53 | ||||
-rw-r--r-- | src/mainmenuitemsprovider.cpp | 11 | ||||
-rw-r--r-- | src/menuconfiguration.cpp | 49 | ||||
-rw-r--r-- | src/menuconfiguration.h | 7 |
7 files changed, 234 insertions, 24 deletions
@@ -1,4 +1,5 @@ SRCS = \ + src/childlock.cpp \ src/commandmenunode.cpp \ src/mainmenuitemsprovider.cpp \ src/menuconfiguration.cpp \ diff --git a/src/childlock.cpp b/src/childlock.cpp new file mode 100644 index 0000000..3ca7d69 --- /dev/null +++ b/src/childlock.cpp @@ -0,0 +1,93 @@ +/* + * 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 "childlock.h" +#include <vdr/plugin.h> +#include "childlockservice.h" + +IChildLockService* ChildLock::_childLockService = NULL; +bool ChildLock::IsMenuProtected(const char* MenuName) +{ + if (IChildLockService* childLockService = ChildLockService()) + { + return childLockService->IsMenuProtected(MenuName); + } + else + { + return false; + } +} + +bool ChildLock::IsPluginProtected(cPlugin* Plugin) +{ + if (IChildLockService* childLockService = ChildLockService()) + { + return childLockService->IsPluginProtected(Plugin); + } + else + { + return false; + } +} + +bool ChildLock::IsMenuHidden(const char* MenuName) +{ + if (IChildLockService* childLockService = ChildLockService()) + { + return childLockService->IsMenuHidden(MenuName); + } + else + { + return false; + } +} + +bool ChildLock::IsPluginHidden(cPlugin* Plugin) +{ + if (IChildLockService* childLockService = ChildLockService()) + { + return childLockService->IsPluginHidden(Plugin); + } + else + { + return false; + } +} + +IChildLockService* ChildLock::ChildLockService() +{ + if (!_childLockService) + { + IChildLockService* childLockService; + + if (cPluginManager::CallFirstService(CHILDLOCKSERVICEID, &childLockService)) + { + _childLockService = childLockService; + } + else + { + _childLockService = NULL; + } + } + + return _childLockService; +} diff --git a/src/childlock.h b/src/childlock.h new file mode 100644 index 0000000..d586f73 --- /dev/null +++ b/src/childlock.h @@ -0,0 +1,44 @@ +/* + * 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 ___CHILDLOCK_H +#define ___CHILDLOCK_H + +class IChildLockService; +class cPlugin; + +class ChildLock +{ + private: + static IChildLockService* _childLockService; + + public: + static bool IsMenuProtected(const char* MenuName); + static bool IsPluginProtected(cPlugin* Plugin); + static bool IsMenuHidden(const char* MenuName); + static bool IsPluginHidden(cPlugin* Plugin); + + private: + static IChildLockService* ChildLockService(); +}; + +#endif diff --git a/src/childlockservice.h b/src/childlockservice.h new file mode 100644 index 0000000..28a3ca4 --- /dev/null +++ b/src/childlockservice.h @@ -0,0 +1,53 @@ +/* + * 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 ___CHILDLOCKSERVICE_H +#define ___CHILDLOCKSERVICE_H + +#include <vdr/keys.h> + +class cChannel; +class cRecording; +class cPlugin; +class cTimer; +class cEvent; +class cOsdObject; + +#define CHILDLOCKSERVICEID "ChildLockService-v0.1::ChildLockService" + +class IChildLockService +{ + public: + virtual ~IChildLockService() {}; + virtual bool IsUnlocked() = 0; + + virtual bool IsMenuProtected(const char* MenuName) = 0; + virtual bool IsChannelProtected(const cChannel* Channel) = 0; + virtual bool IsRecordingProtected(const cRecording* Recording, const char* Name, const char* Base, bool isDirectory) = 0; + virtual bool IsPluginProtected(cPlugin* Plugin) = 0; + + virtual bool IsMenuHidden(const char* MenuName) = 0; + virtual bool IsPluginHidden(cPlugin* Plugin) = 0; + virtual bool IsRecordingHidden(const cRecording* Recording, const char* Name, const char* Base, bool isDirectory) = 0; +}; + +#endif diff --git a/src/mainmenuitemsprovider.cpp b/src/mainmenuitemsprovider.cpp index 31a1744..916034f 100644 --- a/src/mainmenuitemsprovider.cpp +++ b/src/mainmenuitemsprovider.cpp @@ -25,6 +25,7 @@ #include "systemmenunode.h" #include "pluginmenunode.h" #include <vdr/plugin.h> +#include "childlock.h" MainMenuItemsProvider::MainMenuItemsProvider(MenuNode* rootMenu) { @@ -71,7 +72,10 @@ void MainMenuItemsProvider::EnterSubMenu(cOsdItem* item) int itemIndex = IndexOfCustomOsdItem(item); if (itemIndex >= 0) { - _currentMenu = _currentMenu->Childs().at(itemIndex); + if (!ChildLock::IsMenuProtected(item->Text())) + { + _currentMenu = _currentMenu->Childs().at(itemIndex); + } } } @@ -93,7 +97,10 @@ cOsdMenu* MainMenuItemsProvider::Execute(cOsdItem* item) int itemIndex = IndexOfCustomOsdItem(item); if (itemIndex >= 0) { - return _currentMenu->Childs().at(itemIndex)->Execute(); + if (!ChildLock::IsMenuProtected(item->Text())) + { + return _currentMenu->Childs().at(itemIndex)->Execute(); + } } } diff --git a/src/menuconfiguration.cpp b/src/menuconfiguration.cpp index 8badb41..5a84966 100644 --- a/src/menuconfiguration.cpp +++ b/src/menuconfiguration.cpp @@ -29,6 +29,7 @@ #include "submenunode.h" #include "pluginmenunode.h" #include "commandmenunode.h" +#include "childlock.h" using namespace xmlpp; using namespace std; @@ -114,7 +115,7 @@ void MenuConfiguration::ParseElement(const Element* element, MenuNode* menuNode) string execute = childElement->get_attribute("execute")->get_value(); const xmlpp::Attribute* confirmAttribute = childElement->get_attribute("confirm"); bool confirm = confirmAttribute ? (confirmAttribute->get_value() == "yes") : false; - AddPluginMenuNode(name, execute, confirm, menuNode); + AddCommandMenuNode(name, execute, confirm, menuNode); } } } @@ -127,18 +128,21 @@ MenuNode* MenuConfiguration::AddSubMenuNode(string name, MenuNode* menu) void MenuConfiguration::AddSystemMenuNode(string name, MenuNode* menu) { - menu->AddChild(new SystemMenuNode(name, MenuTextToVdrState(name))); + if (!ChildLock::IsMenuHidden(name.c_str())) + { + menu->AddChild(new SystemMenuNode(name, MenuTextToVdrState(name))); + } } void MenuConfiguration::AddPluginMenuNode(string pluginName, MenuNode* menu) { - const char* pluginMainMenuEntry; int pluginIndex; + cPlugin* plugin; - if (FindPluginByName(pluginName, &pluginMainMenuEntry, pluginIndex)) + if (FindPluginByName(pluginName, plugin, pluginIndex)) { _configuredPlugins.push_back(pluginName); - menu->AddChild(new PluginMenuNode(pluginMainMenuEntry, pluginIndex)); + AddPluginMenuNode(plugin, pluginIndex, menu); } } @@ -172,20 +176,17 @@ eOSState MenuConfiguration::MenuTextToVdrState(string menuText) return osContinue; } -bool MenuConfiguration::FindPluginByName(string name, const char** mainMenuEntry, int& pluginIndex) +bool MenuConfiguration::FindPluginByName(string name, cPlugin*& plugin, int& pluginIndex) { int i = 0; - while (cPlugin *plugin = cPluginManager::GetPlugin(i)) + while (cPlugin *currentPlugin = cPluginManager::GetPlugin(i)) { - if (name == plugin->Name()) + if (name == currentPlugin->Name()) { - if (const char *item = plugin->MainMenuEntry()) - { - pluginIndex = i; - *mainMenuEntry = item; - return true; - } + plugin = currentPlugin; + pluginIndex = i; + return true; } i++; } @@ -199,18 +200,26 @@ void MenuConfiguration::AddUnconfiguredPlugins(MenuNode* menu) while (cPlugin *plugin = cPluginManager::GetPlugin(i)) { - if (const char *item = plugin->MainMenuEntry()) + if (find(_configuredPlugins.begin(), _configuredPlugins.end(), plugin->Name()) == _configuredPlugins.end()) { - if (find(_configuredPlugins.begin(), _configuredPlugins.end(), plugin->Name()) == _configuredPlugins.end()) - { - menu->AddChild(new PluginMenuNode(item, i)); - } + AddPluginMenuNode(plugin, i, menu); } i++; } } -void MenuConfiguration::AddPluginMenuNode(string name, string command, bool confirm, MenuNode* menu) +void MenuConfiguration::AddCommandMenuNode(string name, string command, bool confirm, MenuNode* menu) { menu->AddChild(new CommandMenuNode(name, command, confirm)); } + +void MenuConfiguration::AddPluginMenuNode(cPlugin* plugin, int pluginIndex, MenuNode* menu) +{ + if (const char *item = plugin->MainMenuEntry()) + { + if (!ChildLock::IsPluginHidden(plugin)) + { + menu->AddChild(new PluginMenuNode(item, pluginIndex)); + } + } +} diff --git a/src/menuconfiguration.h b/src/menuconfiguration.h index 4fd7c7c..f5c7cf5 100644 --- a/src/menuconfiguration.h +++ b/src/menuconfiguration.h @@ -28,7 +28,9 @@ #include <vdr/osdbase.h> namespace xmlpp { class Element; } + class MenuNode; +class cPlugin; class MenuConfiguration { @@ -42,12 +44,13 @@ class MenuConfiguration private: void ParseElement(const xmlpp::Element* a_node, MenuNode* menuNode); eOSState MenuTextToVdrState(std::string menuText); - bool FindPluginByName(std::string name, const char** mainMenuEntry, int& pluginIndex); + bool FindPluginByName(std::string name, cPlugin*& plugin, int& pluginIndex); MenuNode* AddSubMenuNode(std::string name, MenuNode* menu); void AddSystemMenuNode(std::string name, MenuNode* menu); void AddPluginMenuNode(std::string pluginName, MenuNode* menu); + void AddPluginMenuNode(cPlugin* plugin, int pluginIndex, MenuNode* menu); void AddUnconfiguredPlugins(MenuNode* menu); - void AddPluginMenuNode(std::string name, std::string command, bool confirm, MenuNode* menu); + void AddCommandMenuNode(std::string name, std::string command, bool confirm, MenuNode* menu); }; #endif |