Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Working Context Item Addons

Added rudimentary logging and error handling in ContextItemAddon Ctor

Added copy_if to Util.h

Added String 'Context Item'
  • Loading branch information...
commit a438fd9bed3226a40387f418aa286012ce20f1dd 1 parent 32f6e62
Fice authored
View
18 XBMC.xcodeproj/project.pbxproj
@@ -25,6 +25,9 @@
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
+ 0E04BF8E1632C82B002700F6 /* ContextItemAddon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0E04BF8C1632C82A002700F6 /* ContextItemAddon.cpp */; };
+ 0E04BF901632C85B002700F6 /* GUIContextMenuManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0E04BF8F1632C85B002700F6 /* GUIContextMenuManager.cpp */; };
+ 0E04BF941632C875002700F6 /* IGUIContextItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0E04BF921632C875002700F6 /* IGUIContextItem.cpp */; };
183FDF8A11AF0B0500B81E9C /* PluginSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 183FDF8811AF0B0500B81E9C /* PluginSource.cpp */; };
18404DA61396C31B00863BBA /* SlingboxLib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 18404DA51396C31B00863BBA /* SlingboxLib.a */; };
1840B74D13993D8A007C848B /* JSONVariantParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1840B74B13993D8A007C848B /* JSONVariantParser.cpp */; };
@@ -1065,6 +1068,12 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
+ 0E04BF8C1632C82A002700F6 /* ContextItemAddon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContextItemAddon.cpp; sourceTree = "<group>"; };
+ 0E04BF8D1632C82B002700F6 /* ContextItemAddon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContextItemAddon.h; sourceTree = "<group>"; };
+ 0E04BF8F1632C85B002700F6 /* GUIContextMenuManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GUIContextMenuManager.cpp; sourceTree = "<group>"; };
+ 0E04BF911632C862002700F6 /* GUIContextMenuManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GUIContextMenuManager.h; sourceTree = "<group>"; };
+ 0E04BF921632C875002700F6 /* IGUIContextItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IGUIContextItem.cpp; sourceTree = "<group>"; };
+ 0E04BF931632C875002700F6 /* IGUIContextItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGUIContextItem.h; sourceTree = "<group>"; };
18308CB41303370800AA309E /* stat_utf8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stat_utf8.h; sourceTree = "<group>"; };
18308CB51303370800AA309E /* stdio_utf8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stdio_utf8.h; sourceTree = "<group>"; };
183FDF8811AF0B0500B81E9C /* PluginSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginSource.cpp; sourceTree = "<group>"; };
@@ -3391,6 +3400,8 @@
F52BFFD9115D5574004B1D66 /* AddonStatusHandler.h */,
18B700DF13A6A5750009C1AF /* AddonVersion.cpp */,
18B700E013A6A5750009C1AF /* AddonVersion.h */,
+ 0E04BF8C1632C82A002700F6 /* ContextItemAddon.cpp */,
+ 0E04BF8D1632C82B002700F6 /* ContextItemAddon.h */,
18B49FF61152BFA5001AF8A6 /* DllAddon.h */,
18B7C38612942090009E7A26 /* GUIDialogAddonInfo.cpp */,
18B7C38712942090009E7A26 /* GUIDialogAddonInfo.h */,
@@ -4772,6 +4783,8 @@
E38E16910D25F9FA00618676 /* Favourites.h */,
E38E16920D25F9FA00618676 /* FileItem.cpp */,
E38E16930D25F9FA00618676 /* FileItem.h */,
+ 0E04BF8F1632C85B002700F6 /* GUIContextMenuManager.cpp */,
+ 0E04BF911632C862002700F6 /* GUIContextMenuManager.h */,
E38E1E3E0D25F9FD00618676 /* GUIInfoManager.cpp */,
E38E1E3F0D25F9FD00618676 /* GUIInfoManager.h */,
E38E17EE0D25F9FA00618676 /* GUILargeTextureManager.cpp */,
@@ -4783,6 +4796,8 @@
E38E17F80D25F9FA00618676 /* GUIViewControl.h */,
E38E17F90D25F9FA00618676 /* GUIViewState.cpp */,
E38E17FA0D25F9FA00618676 /* GUIViewState.h */,
+ 0E04BF921632C875002700F6 /* IGUIContextItem.cpp */,
+ 0E04BF931632C875002700F6 /* IGUIContextItem.h */,
E38E184F0D25F9FA00618676 /* IProgressCallback.h */,
E38E18580D25F9FA00618676 /* LangInfo.cpp */,
E38E18590D25F9FA00618676 /* LangInfo.h */,
@@ -7724,6 +7739,9 @@
DFB02DEA16629DBA00F37752 /* PyContext.cpp in Sources */,
DF07252E168734D7008DCAAD /* karaokevideobackground.cpp in Sources */,
DF072534168734ED008DCAAD /* FFmpegVideoDecoder.cpp in Sources */,
+ 0E04BF8E1632C82B002700F6 /* ContextItemAddon.cpp in Sources */,
+ 0E04BF901632C85B002700F6 /* GUIContextMenuManager.cpp in Sources */,
+ 0E04BF941632C875002700F6 /* IGUIContextItem.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
6 language/English/strings.po
@@ -10401,7 +10401,11 @@ msgctxt "#24023"
msgid "Add-on disabled"
msgstr ""
-#empty strings from id 24024 to 24026
+msgctxt "#24024"
+msgid "Context Item"
+msgstr ""
+
+#empty strings from id 24025 to 24026
msgctxt "#24027"
msgid "Weather"
View
106 xbmc/GUIContextMenuManager.cpp
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2005-2012 Team XBMC
+ * http://www.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 "GUIContextMenuManager.h"
+#include "addons/Addon.h"
+#include "addons/AddonManager.h"
+#include "addons/ContextItemAddon.h"
+#include "Util.h"
+#include "List.h"
+#include "IAddon.h"
+#include <functional>
+
+
+GUIContextMenuManager& GUIContextMenuManager::Get()
+{
+ static GUIContextMenuManager contextManager;
+ return contextManager;
+}
+
+GUIContextMenuManager::GUIContextMenuManager()
+: m_vecContextMenus()
+{
+
+ //Add core context items
+
+
+
+ //Add context items from addons
+ ADDON::VECADDONS addons;
+ if(ADDON::CAddonMgr::Get().GetAddons(ADDON::ADDON_CONTEXT, addons))
+ {
+ m_vecContextMenus.reserve(addons.size());
+
+ for(ADDON::IVECADDONS i = addons.begin(); i!=addons.end(); ++i)
+ {
+ ContextItemPtr ptr(boost::shared_polymorphic_downcast<ADDON::CContextItemAddon>(*i));
+ RegisterContextItem(ptr);
+ }
+ }
+}
+
+bool GUIContextMenuManager::RegisterContextItem(ContextItemPtr cm)
+{
+ ContextItemPtr item = GetContextItemByID(cm->getMsgID());
+ if(item==0)
+ {
+ m_vecContextMenus.push_back(cm);
+ }
+ else
+ {
+ *item = *cm; //Item might be updated, so replace!
+ }
+ return true;
+}
+
+bool GUIContextMenuManager::UnregisterContextItem(ContextItemPtr cm)
+{
+ contextIter it = remove_if(m_vecContextMenus.begin(),
+ m_vecContextMenus.end(),
+ std::bind2nd(IGUIContextItem::IDFinder(), cm->getMsgID())
+ );
+ if(it!=m_vecContextMenus.end())
+ {
+ m_vecContextMenus.erase(it, m_vecContextMenus.end());
+ return true;
+ }
+ return false;
+}
+
+
+ContextItemPtr GUIContextMenuManager::GetContextItemByID(const unsigned int ID)
+{
+ contextIter it = find_if(m_vecContextMenus.begin(),
+ m_vecContextMenus.end(),
+ std::bind2nd(IGUIContextItem::IDFinder(), ID)
+ );
+ if(it==m_vecContextMenus.end())
+ return ContextItemPtr();
+ return *it;
+}
+
+void GUIContextMenuManager::GetVisibleContextItems(int context/*TODO: */, const CGUIListItem * const item, std::list<ContextItemPtr> &visible)
+{
+ copy_if (m_vecContextMenus.begin(),
+ m_vecContextMenus.end(),
+ back_inserter(visible),
+ std::bind2nd(IGUIContextItem::ContextVisiblePredicate(), item)
+ );
+}
View
55 xbmc/GUIContextMenuManager.h
@@ -0,0 +1,55 @@
+/*!
+\file GUIContextMenuManager.h
+\brief
+*/
+
+#ifndef GUICONTEXTMANAGER_H_
+#define GUICONTEXTMANAGER_H_
+
+/*
+ * Copyright (C) 2005-2012 Team XBMC
+ * http://www.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 "IGUIContextItem.h"
+#include "boost/shared_ptr.hpp"
+#include <list>
+#include <boost/noncopyable.hpp>
+
+class GUIContextMenuManager : boost::noncopyable
+{
+public:
+ static GUIContextMenuManager& Get();
+
+
+
+ bool RegisterContextItem(ContextItemPtr cm);
+ bool UnregisterContextItem(ContextItemPtr cm);
+ ContextItemPtr GetContextItemByID(const unsigned int ID);
+ void GetVisibleContextItems(int context, const CGUIListItem *item, std::list<ContextItemPtr> &visible);
+protected:
+ GUIContextMenuManager();
+
+ typedef std::vector<ContextItemPtr>::iterator contextIter;
+ std::vector<ContextItemPtr> m_vecContextMenus;
+};
+
+
+#endif
+
+
+
View
44 xbmc/IGUIContextItem.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2005-2012 Team XBMC
+ * http://www.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 "IGUIContextItem.h"
+
+
+
+
+bool IGUIContextItem::ContextVisiblePredicate::operator()(const ContextItemPtr& item, const CGUIListItem *listItem) const
+{
+ return item->isVisible(listItem);
+}
+
+
+bool IGUIContextItem::IDFinder::operator()(const ContextItemPtr& item, unsigned int id) const
+{
+ return item->getMsgID()==id;
+}
+
+
+
+
+
+
+
+
+
View
72 xbmc/IGUIContextItem.h
@@ -0,0 +1,72 @@
+/*!
+\file GUIContextMenuManager.h
+\brief
+*/
+#pragma once
+
+/*
+ * Copyright (C) 2005-2012 Team XBMC
+ * http://www.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 "boost/shared_ptr.hpp"
+#include "utils/StringUtils.h"
+#include "guilib/GUIListItem.h"
+#include <functional>
+
+class IGUIContextItem;
+typedef boost::shared_ptr<IGUIContextItem> ContextItemPtr;
+
+class IGUIContextItem
+{
+public:
+ virtual unsigned int getMsgID() const =0;
+ virtual CStdString getLabel() const =0;
+ virtual bool isVisible(const CGUIListItem *item) const=0;
+ virtual ~IGUIContextItem() {}
+ bool operator()(const CGUIListItem *item) {
+ if(!isVisible(item))
+ return false;
+ return execute();
+ }
+
+ struct ContextVisiblePredicate : std::binary_function<ContextItemPtr, const CGUIListItem* const, bool>
+ {
+ bool operator()(const ContextItemPtr& item, const CGUIListItem * const listItem) const;
+ };
+
+ struct IDFinder : std::binary_function<ContextItemPtr, unsigned int, bool>
+ {
+ bool operator()(const ContextItemPtr& item, unsigned int id) const;
+ };
+
+
+protected:
+ virtual bool execute()=0;
+
+};
+
+typedef boost::shared_ptr<IGUIContextItem> ContextItemPtr;
+
+
+
+
+
+
+
+
View
16 xbmc/Util.h
@@ -53,6 +53,22 @@ struct sortstringbyname
}
};
+/** Taken from: Efficte STL - 50 Specific Ways to improve your use of the standard template library
+ * Item: 37
+ **/
+template< typename Inputlterator, typename Outputlterator, typename Predicate>
+Outputlterator copy_if( Inputlterator begin, Inputlterator end,
+ Outputlterator destBegin, Predicate p)
+{
+ while (begin != end)
+ {
+ if (p(*begin))
+ *destBegin++ = *begin;
+ ++begin;
+ }
+ return destBegin;
+}
+
class CUtil
{
public:
View
3  xbmc/addons/Addon.cpp
@@ -77,6 +77,7 @@ static const TypeMapping types[] =
{"xbmc.python.lyrics", ADDON_SCRIPT_LYRICS, 24013, "DefaultAddonLyrics.png" },
{"xbmc.python.library", ADDON_SCRIPT_LIBRARY, 24014, "" },
{"xbmc.python.module", ADDON_SCRIPT_MODULE, 0, "" },
+ {"xbmc.context", ADDON_CONTEXT, 24024, "" }, //TODO: Context: add default image
{"xbmc.gui.skin", ADDON_SKIN, 166, "DefaultAddonSkin.png" },
{"xbmc.gui.webinterface", ADDON_WEB_INTERFACE, 199, "DefaultAddonWebSkin.png" },
{"xbmc.addon.repository", ADDON_REPOSITORY, 24011, "DefaultAddonRepository.png" },
@@ -361,6 +362,7 @@ void CAddon::BuildLibName(const cp_extension_t *extension)
case ADDON_SCRIPT_SUBTITLES:
case ADDON_PLUGIN:
case ADDON_SERVICE:
+ case ADDON_CONTEXT:
ext = ADDON_PYTHON_EXT;
break;
default:
@@ -392,6 +394,7 @@ void CAddon::BuildLibName(const cp_extension_t *extension)
case ADDON_PVRDLL:
case ADDON_PLUGIN:
case ADDON_SERVICE:
+ case ADDON_CONTEXT:
{
CStdString temp = CAddonMgr::Get().GetExtValue(extension->configuration, "@library");
m_strLibName = temp;
View
16 xbmc/addons/AddonManager.cpp
@@ -47,9 +47,11 @@
#include "Repository.h"
#include "Skin.h"
#include "Service.h"
+#include "ContextItemAddon.h"
#include "pvr/PVRManager.h"
#include "pvr/addons/PVRClients.h"
#include "Util.h"
+#include "GUIDialogContextMenu.h"
using namespace std;
using namespace PVR;
@@ -166,6 +168,8 @@ AddonPtr CAddonMgr::Factory(const cp_extension_t *props)
return AddonPtr(new CAddonLibrary(props));
case ADDON_REPOSITORY:
return AddonPtr(new CRepository(props));
+ case ADDON_CONTEXT:
+ return AddonPtr(new CContextItemAddon(props));
default:
break;
}
@@ -205,6 +209,7 @@ bool CAddonMgr::CheckUserDirs(const cp_cfg_element_t *settings)
CAddonMgr::CAddonMgr()
{
m_cpluff = NULL;
+ m_iCurrentContextId = CONTEXT_BUTTON_FIRST_CONTEXT_PLUGIN;
}
CAddonMgr::~CAddonMgr()
@@ -558,6 +563,15 @@ void CAddonMgr::RemoveAddon(const CStdString& ID)
NotifyObservers(ObservableMessageAddons);
}
}
+
+unsigned int CAddonMgr::GetMsgIdForContextAddon(CStdString AddonID) {
+ CSingleLock lock(m_critSection);
+ unsigned int& id = m_contextMsgAssign[AddonID];
+ if(id==0) {
+ id = m_iCurrentContextId++;
+ }
+ return id;
+}
const char *CAddonMgr::GetTranslatedString(const cp_cfg_element_t *root, const char *tag)
{
@@ -617,6 +631,8 @@ AddonPtr CAddonMgr::AddonFromProps(AddonProps& addonProps)
return AddonPtr(new CPVRClient(addonProps));
case ADDON_REPOSITORY:
return AddonPtr(new CRepository(addonProps));
+ case ADDON_CONTEXT:
+ return AddonPtr(new CContextItemAddon(addonProps));
default:
break;
}
View
5 xbmc/addons/AddonManager.h
@@ -114,6 +114,8 @@ namespace ADDON
static AddonPtr AddonFromProps(AddonProps& props);
void FindAddons();
void RemoveAddon(const CStdString& ID);
+
+ unsigned int GetMsgIdForContextAddon(CStdString AddonID);
/* libcpluff */
CStdString GetExtValue(cp_cfg_element_t *base, const char *path);
@@ -203,6 +205,9 @@ namespace ADDON
CAddonMgr const& operator=(CAddonMgr const&);
virtual ~CAddonMgr();
+ std::map<CStdString, unsigned int> m_contextMsgAssign;
+ unsigned int m_iCurrentContextId;
+
static std::map<TYPE, IAddonMgrCallback*> m_managers;
CCriticalSection m_critSection;
CAddonDatabase m_database;
View
103 xbmc/addons/ContextItemAddon.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2005-2012 Team XBMC
+ * http://www.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 "ContextItemAddon.h"
+#include "AddonManager.h"
+#include "GUIInfoManager.h"
+#include "utils/log.h"
+#ifdef HAS_PYTHON
+#include "interfaces/python/XBPython.h"
+#endif
+#include <boost/lexical_cast.hpp>
+
+using namespace std;
+
+namespace ADDON
+{
+
+CContextItemAddon::CContextItemAddon(const cp_extension_t *ext)
+ : CAddon(ext), m_bTrueOnNullId(false)
+{
+
+ m_id = CAddonMgr::Get().GetMsgIdForContextAddon(ID());
+
+ m_label = CAddonMgr::Get().GetTranslatedString(ext->configuration, "label");
+ if(m_label.empty())
+ {
+ m_label = Name();
+ CLog::Log(LOGDEBUG, "ADDON: %s - failed to load label attribute, falling back to addon name %s.", ID().c_str(), Name().c_str());
+ }
+
+ CStdString visible = CAddonMgr::Get().GetExtValue(ext->configuration, "@visible");
+ if(visible.empty())
+ {
+ m_bTrueOnNullId = true;
+ m_VisibleId = 0;
+ }
+ else
+ {
+ m_VisibleId = g_infoManager.Register(visible, 0, this);
+ if(!m_VisibleId)
+ CLog::Log(LOGDEBUG, "ADDON: %s - Failed to load visibility expression: %s. Context item will not be visible", ID().c_str(), visible.c_str());
+ }
+}
+
+
+CContextItemAddon::CContextItemAddon(const AddonProps &props)
+ : CAddon(props), m_bTrueOnNullId(false)
+{
+ //TODO: find out how to get the visible and label values!
+
+}
+
+CContextItemAddon::~CContextItemAddon()
+{
+ //TODO:
+ //either implement this unregister function
+ //g_infoManager.Unregister(m_VisibleId);
+ //or make sure that the IAddon* member variable of the CInfoBool class isn't used
+ //after this item is destroyed (e.g. use shared_ptr!)
+}
+
+CStdString CContextItemAddon::getLabel() const
+{
+ return m_label;
+}
+
+bool CContextItemAddon::isVisible(const CGUIListItem *item) const
+{
+ if(!Enabled())
+ return false;
+ if(!m_VisibleId)
+ return m_bTrueOnNullId;
+ return g_infoManager.GetBoolValue(m_VisibleId, item);
+}
+
+ //TODO: handle non-python addons
+bool CContextItemAddon::execute()
+{
+
+#ifdef HAS_PYTHON
+ return (g_pythonParser.evalFile(LibPath(), this->shared_from_this()) != -1);
+#endif
+ return false;
+}
+
+
+}
View
51 xbmc/addons/ContextItemAddon.h
@@ -0,0 +1,51 @@
+#pragma once
+/*
+ * Copyright (C) 2005-2012 Team XBMC
+ * http://www.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 "Addon.h"
+#include "../IGUIContextItem.h"
+#include "GUIListItem.h"
+
+namespace ADDON
+{
+
+ //TODO. listen to language changes, because we than have to reload the label!
+
+ //TODO: handle other addon types than python once that's possible!
+ class CContextItemAddon : public CAddon, public IGUIContextItem
+ {
+ public:
+
+
+ CContextItemAddon(const cp_extension_t *ext);
+ CContextItemAddon(const AddonProps &props);
+ virtual ~CContextItemAddon();
+
+ virtual unsigned int getMsgID() const { return m_id; }
+ virtual CStdString getLabel() const;
+ virtual bool isVisible(const CGUIListItem *item) const;
+ protected:
+ virtual bool execute();
+ unsigned int m_VisibleId;
+ unsigned int m_id;
+ CStdString m_label;
+ bool m_bTrueOnNullId;
+ };
+ typedef boost::shared_ptr<CContextItemAddon> ContextAddonPtr;
+}
View
1  xbmc/addons/IAddon.h
@@ -50,6 +50,7 @@ namespace ADDON
ADDON_REPOSITORY,
ADDON_WEB_INTERFACE,
ADDON_SERVICE,
+ ADDON_CONTEXT,
ADDON_VIDEO, // virtual addon types
ADDON_AUDIO,
ADDON_IMAGE,
View
15 xbmc/dialogs/GUIDialogContextMenu.cpp
@@ -42,6 +42,7 @@
#include "TextureCache.h"
#include "video/windows/GUIWindowVideoBase.h"
#include "URL.h"
+#include "GUIContextMenuManager.h"
#ifdef _WIN32
#include "WIN32Util.h"
@@ -70,6 +71,11 @@ void CContextButtons::Add(unsigned int button, int label)
push_back(pair<unsigned int, CStdString>(button, g_localizeStrings.Get(label)));
}
+std::pair<unsigned int, CStdString> ConvertFromContextItem::operator()(ContextItemPtr& input)
+{
+ return std::pair<unsigned int, CStdString>(input->getMsgID(), input->getLabel());
+}
+
CGUIDialogContextMenu::CGUIDialogContextMenu(void)
: CGUIDialog(WINDOW_DIALOG_CONTEXT_MENU, "DialogContextMenu.xml")
{
@@ -376,6 +382,10 @@ void CGUIDialogContextMenu::GetContextButtons(const CStdString &type, const CFil
}
if (share && !g_passwordManager.bMasterUser && item->m_iHasLock == 1)
buttons.Add(CONTEXT_BUTTON_REACTIVATE_LOCK, 12353);
+
+ std::list<ContextItemPtr> additional_context_items;
+ GUIContextMenuManager::Get().GetVisibleContextItems(0, &*item, additional_context_items);
+ std::transform(additional_context_items.begin(), additional_context_items.end(), back_inserter(buttons), ConvertFromContextItem());
}
bool CGUIDialogContextMenu::OnContextButton(const CStdString &type, const CFileItemPtr item, CONTEXT_BUTTON button)
@@ -637,7 +647,10 @@ bool CGUIDialogContextMenu::OnContextButton(const CStdString &type, const CFileI
default:
break;
}
- return false;
+ ContextItemPtr context_item = GUIContextMenuManager::Get().GetContextItemByID(button);
+ if(context_item==0)
+ return false;
+ return (*context_item)(&*item); //execute our context item logic
}
CMediaSource *CGUIDialogContextMenu::GetShare(const CStdString &type, const CFileItem *item)
View
20 xbmc/dialogs/GUIDialogContextMenu.h
@@ -21,6 +21,7 @@
*/
#include "guilib/GUIDialog.h"
+#include "GUIContextMenuManager.h"
class CMediaSource;
@@ -126,16 +127,9 @@ enum CONTEXT_BUTTON { CONTEXT_BUTTON_CANCELLED = 0,
CONTEXT_BUTTON_RECORD_ITEM,
CONTEXT_BUTTON_TAGS_ADD_ITEMS,
CONTEXT_BUTTON_TAGS_REMOVE_ITEMS,
- CONTEXT_BUTTON_USER1,
- CONTEXT_BUTTON_USER2,
- CONTEXT_BUTTON_USER3,
- CONTEXT_BUTTON_USER4,
- CONTEXT_BUTTON_USER5,
- CONTEXT_BUTTON_USER6,
- CONTEXT_BUTTON_USER7,
- CONTEXT_BUTTON_USER8,
- CONTEXT_BUTTON_USER9,
- CONTEXT_BUTTON_USER10
+ CONTEXT_BUTTON_FIRST_CONTEXT_PLUGIN //NOTE: this has to be the last in this enum,
+ //because this one, and the ones higher will be used by context plugins
+
};
class CContextButtons : public std::vector< std::pair<unsigned int, CStdString> >
@@ -145,6 +139,12 @@ class CContextButtons : public std::vector< std::pair<unsigned int, CStdString>
void Add(unsigned int, int label);
};
+class ConvertFromContextItem
+{
+public:
+ std::pair<unsigned int, CStdString> operator()(ContextItemPtr& input);
+};
+
class CGUIDialogContextMenu :
public CGUIDialog
{
View
32 xbmc/windows/GUIMediaWindow.cpp
@@ -1563,22 +1563,6 @@ void CGUIMediaWindow::GetContextButtons(int itemNumber, CContextButtons &buttons
if (!item)
return;
- // user added buttons
- CStdString label;
- CStdString action;
- for (int i = CONTEXT_BUTTON_USER1; i <= CONTEXT_BUTTON_USER10; i++)
- {
- label.Format("contextmenulabel(%i)", i - CONTEXT_BUTTON_USER1);
- if (item->GetProperty(label).empty())
- break;
-
- action.Format("contextmenuaction(%i)", i - CONTEXT_BUTTON_USER1);
- if (item->GetProperty(action).empty())
- break;
-
- buttons.Add((CONTEXT_BUTTON)i, item->GetProperty(label).asString());
- }
-
if (item->GetProperty("pluginreplacecontextitems").asBoolean())
return;
@@ -1612,22 +1596,6 @@ bool CGUIMediaWindow::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
Refresh();
return true;
}
- case CONTEXT_BUTTON_USER1:
- case CONTEXT_BUTTON_USER2:
- case CONTEXT_BUTTON_USER3:
- case CONTEXT_BUTTON_USER4:
- case CONTEXT_BUTTON_USER5:
- case CONTEXT_BUTTON_USER6:
- case CONTEXT_BUTTON_USER7:
- case CONTEXT_BUTTON_USER8:
- case CONTEXT_BUTTON_USER9:
- case CONTEXT_BUTTON_USER10:
- {
- CStdString action;
- action.Format("contextmenuaction(%i)", button - CONTEXT_BUTTON_USER1);
- CApplicationMessenger::Get().ExecBuiltIn(m_vecItems->Get(itemNumber)->GetProperty(action).asString());
- return true;
- }
default:
break;
}

0 comments on commit a438fd9

Please sign in to comment.
Something went wrong with that request. Please try again.