forked from xbmc/xbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
434 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd"> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<xs:element name="extension"> | ||
<xs:complexType> | ||
<xs:sequence> | ||
<xs:element name="item"> | ||
<xs:complexType> | ||
<xs:sequence> | ||
<xs:element name="label" type="xs:string"/> | ||
<xs:element name="visible" type="xs:string"/> | ||
<xs:element name="parent" type="xs:string"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:sequence> | ||
<xs:attribute name="point" type="xs:string" use="required"/> | ||
<xs:attribute name="id" type="simpleIdentifier"/> | ||
<xs:attribute name="name" type="xs:string"/> | ||
<xs:attribute name="library" type="xs:string" use="required"/> | ||
</xs:complexType> | ||
</xs:element> | ||
<xs:simpleType name="simpleIdentifier"> | ||
<xs:restriction base="xs:string"> | ||
<xs:pattern value="[^.]+"/> | ||
</xs:restriction> | ||
</xs:simpleType> | ||
</xs:schema> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright (C) 2013-2015 Team XBMC | ||
* http://xbmc.org | ||
* | ||
* 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, 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 XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "ContextMenuManager.h" | ||
#include "addons/Addon.h" | ||
#include "addons/AddonManager.h" | ||
#include "addons/ContextItemAddon.h" | ||
#include "addons/IAddon.h" | ||
#include "interfaces/generic/ScriptInvocationManager.h" | ||
#include "interfaces/python/ContextItemAddonInvoker.h" | ||
#include "interfaces/python/XBPython.h" | ||
#include "Util.h" | ||
#include "utils/log.h" | ||
#include "video/dialogs/GUIDialogVideoInfo.h" | ||
|
||
using namespace ADDON; | ||
|
||
typedef std::map<unsigned int, ContextItemAddonPtr>::value_type ValueType; | ||
|
||
|
||
CContextMenuManager::CContextMenuManager() | ||
: m_iCurrentContextId(CONTEXT_BUTTON_FIRST_ADDON) | ||
{ | ||
Init(); | ||
} | ||
|
||
CContextMenuManager& CContextMenuManager::Get() | ||
{ | ||
static CContextMenuManager mgr; | ||
return mgr; | ||
} | ||
|
||
void CContextMenuManager::Init() | ||
{ | ||
//Make sure we load all context items on first usage... | ||
VECADDONS addons; | ||
if (CAddonMgr::Get().GetAddons(ADDON_CONTEXT_ITEM, addons)) | ||
{ | ||
for (const auto& addon : addons) | ||
Register(std::static_pointer_cast<CContextItemAddon>(addon)); | ||
} | ||
} | ||
|
||
void CContextMenuManager::Register(const ContextItemAddonPtr& cm) | ||
{ | ||
if (!cm) | ||
return; | ||
m_contextAddons[m_iCurrentContextId++] = cm; | ||
} | ||
|
||
bool CContextMenuManager::Unregister(const ContextItemAddonPtr& cm) | ||
{ | ||
if (!cm) | ||
return false; | ||
|
||
auto it = std::find_if(m_contextAddons.begin(), m_contextAddons.end(), | ||
[&](const ValueType& value){ return value.second->ID() == cm->ID(); }); | ||
|
||
if (it != m_contextAddons.end()) | ||
{ | ||
m_contextAddons.erase(it); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
ContextItemAddonPtr CContextMenuManager::GetContextItemByID(unsigned int id) | ||
{ | ||
auto it = m_contextAddons.find(id); | ||
if (it != m_contextAddons.end()) | ||
return it->second; | ||
return ContextItemAddonPtr(); | ||
} | ||
|
||
void CContextMenuManager::AddVisibleItems(const CFileItemPtr& item, CContextButtons& list, const std::string& parent /* = "" */) | ||
{ | ||
if (!item) | ||
return; | ||
|
||
for (const auto& kv : m_contextAddons) | ||
{ | ||
if (kv.second->GetParent() == parent && kv.second->IsVisible(item)) | ||
list.push_back(std::make_pair(kv.first, kv.second->GetLabel())); | ||
} | ||
} | ||
|
||
bool CContextMenuManager::Execute(unsigned int id, const CFileItemPtr& item) | ||
{ | ||
if (!item) | ||
return false; | ||
|
||
const ContextItemAddonPtr addon = GetContextItemByID(id); | ||
if (!addon || !addon->IsVisible(item)) | ||
return false; | ||
|
||
LanguageInvokerPtr invoker(new CContextItemAddonInvoker(&g_pythonParser, item)); | ||
return (CScriptInvocationManager::Get().ExecuteAsync(addon->LibPath(), invoker, addon) != -1); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#pragma once | ||
/* | ||
* Copyright (C) 2013-2015 Team XBMC | ||
* http://xbmc.org | ||
* | ||
* 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, 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 XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include <map> | ||
#include "addons/ContextItemAddon.h" | ||
#include "dialogs/GUIDialogContextMenu.h" | ||
|
||
#define CONTEXT_MENU_GROUP_MANAGE "kodi.core.manage" | ||
|
||
class CContextMenuManager | ||
{ | ||
public: | ||
static CContextMenuManager& Get(); | ||
|
||
/*! | ||
* \brief Executes a context menu item. | ||
* \param id - id of the context button to execute. | ||
* \param item - the currently selected item. | ||
* \return true if executed successfully, false otherwise | ||
*/ | ||
bool Execute(unsigned int id, const CFileItemPtr& item); | ||
|
||
/*! | ||
* \brief Adds all registered context item to the list. | ||
* \param item - the currently selected item. | ||
* \param list - the context menu. | ||
* \param parent - the ID of the context menu. Empty string if the root menu. | ||
* CONTEXT_MENU_GROUP_MANAGE if the 'manage' submenu. | ||
*/ | ||
void AddVisibleItems(const CFileItemPtr& item, CContextButtons& list, const std::string& parent = ""); | ||
|
||
/*! | ||
* \brief Adds a context item to this manager. | ||
* NOTE: only 'enabled' context addons should be added. | ||
*/ | ||
void Register(const ADDON::ContextItemAddonPtr& cm); | ||
|
||
/*! | ||
* \brief Removes a context addon from this manager. | ||
*/ | ||
bool Unregister(const ADDON::ContextItemAddonPtr& cm); | ||
|
||
private: | ||
CContextMenuManager(); | ||
CContextMenuManager(const CContextMenuManager&); | ||
CContextMenuManager const& operator=(CContextMenuManager const&); | ||
virtual ~CContextMenuManager() {} | ||
|
||
void Init(); | ||
|
||
/*! | ||
* \brief Get a context menu item by its assigned id. | ||
* \param id - the button id of the context item. | ||
* \return the addon or NULL if no item with given id is registered. | ||
*/ | ||
ADDON::ContextItemAddonPtr GetContextItemByID(const unsigned int id); | ||
|
||
std::map<unsigned int, ADDON::ContextItemAddonPtr> m_contextAddons; | ||
unsigned int m_iCurrentContextId; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.