summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/ContextItemAddon.cpp
blob: 4222936df9ebe834dbbf58e89100cc893f9167aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 *      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 "ContextItemAddon.h"
#include "AddonManager.h"
#include "ContextMenuManager.h"
#include "dialogs/GUIDialogContextMenu.h"
#include "GUIInfoManager.h"
#include "interfaces/info/InfoBool.h"
#include "utils/log.h"
#include "utils/StringUtils.h"
#include "video/dialogs/GUIDialogVideoInfo.h"
#include <boost/lexical_cast.hpp>

using namespace std;

namespace ADDON
{

CContextItemAddon::CContextItemAddon(const AddonProps &props)
  : CAddon(props)
{ }

CContextItemAddon::~CContextItemAddon()
{ }

CContextItemAddon::CContextItemAddon(const cp_extension_t *ext)
  : CAddon(ext)
{
  ELEMENTS items;
  if (CAddonMgr::Get().GetExtElements(ext->configuration, "item", items))
  {
    cp_cfg_element_t *item = items[0];

    m_label = CAddonMgr::Get().GetExtValue(item, "label");
    if (StringUtils::IsNaturalNumber(m_label))
    {
      m_label = GetString(boost::lexical_cast<int>(m_label.c_str()));
      ClearStrings();
    }

    m_parent = CAddonMgr::Get().GetExtValue(item, "parent");

    string visible = CAddonMgr::Get().GetExtValue(item, "visible");
    if (visible.empty())
      visible = "false";

    m_visCondition = g_infoManager.Register(visible, 0);
  }
}

bool CContextItemAddon::OnPreInstall()
{
  return CContextMenuManager::Get().Unregister(std::dynamic_pointer_cast<CContextItemAddon>(shared_from_this()));
}

void CContextItemAddon::OnPostInstall(bool restart, bool update)
{
  if (restart)
  {
    // need to grab the local addon so we have the correct library path to run
    AddonPtr localAddon;
    if (CAddonMgr::Get().GetAddon(ID(), localAddon, ADDON_CONTEXT_ITEM))
    {
      ContextItemAddonPtr contextItem = std::dynamic_pointer_cast<CContextItemAddon>(localAddon);
      if (contextItem)
        CContextMenuManager::Get().Register(contextItem);
    }
  }
}

void CContextItemAddon::OnPreUnInstall()
{
  CContextMenuManager::Get().Unregister(std::dynamic_pointer_cast<CContextItemAddon>(shared_from_this()));
}

void CContextItemAddon::OnDisabled()
{
  CContextMenuManager::Get().Unregister(std::dynamic_pointer_cast<CContextItemAddon>(shared_from_this()));
}
void CContextItemAddon::OnEnabled()
{
  CContextMenuManager::Get().Register(std::dynamic_pointer_cast<CContextItemAddon>(shared_from_this()));
}

bool CContextItemAddon::IsVisible(const CFileItemPtr& item) const
{
  return item && m_visCondition->Get(item.get());
}

}