diff options
Diffstat (limited to 'xbmc/addons/ContextItemAddon.cpp')
| -rw-r--r-- | xbmc/addons/ContextItemAddon.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/xbmc/addons/ContextItemAddon.cpp b/xbmc/addons/ContextItemAddon.cpp new file mode 100644 index 0000000..4222936 --- /dev/null +++ b/xbmc/addons/ContextItemAddon.cpp | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2013-2015 Team XBMC | ||
| 3 | * http://xbmc.org | ||
| 4 | * | ||
| 5 | * This Program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2, or (at your option) | ||
| 8 | * any later version. | ||
| 9 | * | ||
| 10 | * This Program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with XBMC; see the file COPYING. If not, see | ||
| 17 | * <http://www.gnu.org/licenses/>. | ||
| 18 | * | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include "ContextItemAddon.h" | ||
| 22 | #include "AddonManager.h" | ||
| 23 | #include "ContextMenuManager.h" | ||
| 24 | #include "dialogs/GUIDialogContextMenu.h" | ||
| 25 | #include "GUIInfoManager.h" | ||
| 26 | #include "interfaces/info/InfoBool.h" | ||
| 27 | #include "utils/log.h" | ||
| 28 | #include "utils/StringUtils.h" | ||
| 29 | #include "video/dialogs/GUIDialogVideoInfo.h" | ||
| 30 | #include <boost/lexical_cast.hpp> | ||
| 31 | |||
| 32 | using namespace std; | ||
| 33 | |||
| 34 | namespace ADDON | ||
| 35 | { | ||
| 36 | |||
| 37 | CContextItemAddon::CContextItemAddon(const AddonProps &props) | ||
| 38 | : CAddon(props) | ||
| 39 | { } | ||
| 40 | |||
| 41 | CContextItemAddon::~CContextItemAddon() | ||
| 42 | { } | ||
| 43 | |||
| 44 | CContextItemAddon::CContextItemAddon(const cp_extension_t *ext) | ||
| 45 | : CAddon(ext) | ||
| 46 | { | ||
| 47 | ELEMENTS items; | ||
| 48 | if (CAddonMgr::Get().GetExtElements(ext->configuration, "item", items)) | ||
| 49 | { | ||
| 50 | cp_cfg_element_t *item = items[0]; | ||
| 51 | |||
| 52 | m_label = CAddonMgr::Get().GetExtValue(item, "label"); | ||
| 53 | if (StringUtils::IsNaturalNumber(m_label)) | ||
| 54 | { | ||
| 55 | m_label = GetString(boost::lexical_cast<int>(m_label.c_str())); | ||
| 56 | ClearStrings(); | ||
| 57 | } | ||
| 58 | |||
| 59 | m_parent = CAddonMgr::Get().GetExtValue(item, "parent"); | ||
| 60 | |||
| 61 | string visible = CAddonMgr::Get().GetExtValue(item, "visible"); | ||
| 62 | if (visible.empty()) | ||
| 63 | visible = "false"; | ||
| 64 | |||
| 65 | m_visCondition = g_infoManager.Register(visible, 0); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | bool CContextItemAddon::OnPreInstall() | ||
| 70 | { | ||
| 71 | return CContextMenuManager::Get().Unregister(std::dynamic_pointer_cast<CContextItemAddon>(shared_from_this())); | ||
| 72 | } | ||
| 73 | |||
| 74 | void CContextItemAddon::OnPostInstall(bool restart, bool update) | ||
| 75 | { | ||
| 76 | if (restart) | ||
| 77 | { | ||
| 78 | // need to grab the local addon so we have the correct library path to run | ||
| 79 | AddonPtr localAddon; | ||
| 80 | if (CAddonMgr::Get().GetAddon(ID(), localAddon, ADDON_CONTEXT_ITEM)) | ||
| 81 | { | ||
| 82 | ContextItemAddonPtr contextItem = std::dynamic_pointer_cast<CContextItemAddon>(localAddon); | ||
| 83 | if (contextItem) | ||
| 84 | CContextMenuManager::Get().Register(contextItem); | ||
| 85 | } | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | void CContextItemAddon::OnPreUnInstall() | ||
| 90 | { | ||
| 91 | CContextMenuManager::Get().Unregister(std::dynamic_pointer_cast<CContextItemAddon>(shared_from_this())); | ||
| 92 | } | ||
| 93 | |||
| 94 | void CContextItemAddon::OnDisabled() | ||
| 95 | { | ||
| 96 | CContextMenuManager::Get().Unregister(std::dynamic_pointer_cast<CContextItemAddon>(shared_from_this())); | ||
| 97 | } | ||
| 98 | void CContextItemAddon::OnEnabled() | ||
| 99 | { | ||
| 100 | CContextMenuManager::Get().Register(std::dynamic_pointer_cast<CContextItemAddon>(shared_from_this())); | ||
| 101 | } | ||
| 102 | |||
| 103 | bool CContextItemAddon::IsVisible(const CFileItemPtr& item) const | ||
| 104 | { | ||
| 105 | return item && m_visCondition->Get(item.get()); | ||
| 106 | } | ||
| 107 | |||
| 108 | } | ||
