Skip to content

Commit

Permalink
Move context items out of the OnContext and OnPopup functions one by …
Browse files Browse the repository at this point in the history
…one... this one is AddRemove from favourites
  • Loading branch information
Fice committed Feb 15, 2013
1 parent 4550bf5 commit db41923
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 31 deletions.
10 changes: 10 additions & 0 deletions XBMC.xcodeproj/project.pbxproj
Expand Up @@ -1074,6 +1074,7 @@
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>"; };
0E5EF36A16CD9CAF000A0264 /* FavoriteContextItems.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FavoriteContextItems.h; path = contextitems/FavoriteContextItems.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>"; };
Expand Down Expand Up @@ -3376,6 +3377,14 @@
name = "System Libs and Frameworks";
sourceTree = "<group>";
};
0E5EF36716CD9C91000A0264 /* contextitems */ = {
isa = PBXGroup;
children = (
0E5EF36A16CD9CAF000A0264 /* FavoriteContextItems.h */,
);
name = contextitems;
sourceTree = "<group>";
};
18B49FF01152BEEB001AF8A6 /* addons */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -4732,6 +4741,7 @@
18B49FF01152BEEB001AF8A6 /* addons */,
E38E147F0D25F9F900618676 /* cdrip */,
EC720A91155091CA00FFD782 /* commons */,
0E5EF36716CD9C91000A0264 /* contextitems */,
E38E149A0D25F9F900618676 /* cores */,
4313773012D647BB00680C15 /* dbwrappers */,
C84828E7156CFD5E005A996F /* epg */,
Expand Down
7 changes: 6 additions & 1 deletion xbmc/GUIContextMenuManager.cpp
Expand Up @@ -22,6 +22,7 @@
#include "addons/Addon.h"
#include "addons/AddonManager.h"
#include "addons/ContextItemAddon.h"
#include "contextitems/FavoriteContextItems.h"
#include "Util.h"
#include "addons/IAddon.h"
#include <functional>
Expand All @@ -39,8 +40,12 @@ GUIContextMenuManager& GUIContextMenuManager::Get()
GUIContextMenuManager::GUIContextMenuManager()
: m_vecContextMenus()
{
////////////
//Core Context Items
////////////

//Add core context items
//general stuff
m_vecContextMenus.push_back(CMAddRemoveFavorite());



Expand Down
54 changes: 54 additions & 0 deletions xbmc/contextitems/FavoriteContextItems.h
@@ -0,0 +1,54 @@
#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 "IGUIContextItem.h"
#include "Favourites.h"

class CMAddRemoveFavorite : public IGUIContextItem
{
public:
virtual CStdString getLabel(const CFileItemPtr item)
{

if (CFavourites::IsFavourite(item.get(), 0)
return g_localizeStrings.Get(14077); // Remove Favourite
else
return g_localizeStrings.Get(14076); // Add To Favourites;
}

virtual unsigned int getMsgId() const { return CONTEXT_BUTTON_ADD_FAVOURITE; }


virtual bool isVisible(const CFileItemPtr item) const
{
return !item->IsParentFolder() && !item->GetPath().Equals("add") && !item->GetPath().Equals("newplaylist://") &&
!item->GetPath().Left(19).Equals("newsmartplaylist://") && !item->GetPath().Left(9).Equals("newtag://");
}

protected:
virtual bool execute(const CFileItemPtr item) {
CFavourites::AddOrRemove(item.get(), 0);

return true;
}

};

31 changes: 1 addition & 30 deletions xbmc/windows/GUIMediaWindow.cpp
Expand Up @@ -1565,40 +1565,11 @@ void CGUIMediaWindow::GetContextButtons(int itemNumber, CContextButtons &buttons

if (item->GetProperty("pluginreplacecontextitems").asBoolean())
return;

// TODO: FAVOURITES Conditions on masterlock and localisation
if (!item->IsParentFolder() && !item->GetPath().Equals("add") && !item->GetPath().Equals("newplaylist://") &&
!item->GetPath().Left(19).Equals("newsmartplaylist://") && !item->GetPath().Left(9).Equals("newtag://"))
{
if (CFavourites::IsFavourite(item.get(), GetID()))
buttons.Add(CONTEXT_BUTTON_ADD_FAVOURITE, 14077); // Remove Favourite
else
buttons.Add(CONTEXT_BUTTON_ADD_FAVOURITE, 14076); // Add To Favourites;
}
}

bool CGUIMediaWindow::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
{
switch (button)
{
case CONTEXT_BUTTON_ADD_FAVOURITE:
{
CFileItemPtr item = m_vecItems->Get(itemNumber);
CFavourites::AddOrRemove(item.get(), GetID());
return true;
}
case CONTEXT_BUTTON_PLUGIN_SETTINGS:
{
CURL plugin(m_vecItems->Get(itemNumber)->GetPath());
ADDON::AddonPtr addon;
if (CAddonMgr::Get().GetAddon(plugin.GetHostName(), addon))
if (CGUIDialogAddonSettings::ShowAndGetInput(addon))
Refresh();
return true;
}
default:
break;
}

ContextItemPtr context_item = GUIContextMenuManager::Get().GetContextItemByID(button);
if(context_item==0)
return false;
Expand Down

0 comments on commit db41923

Please sign in to comment.