Skip to content
Permalink
Browse files

move favourites context menus to favourites module

  • Loading branch information...
tamland committed Apr 15, 2017
1 parent 77caaa1 commit b790c8ee8638706058daee43e65a86054659daef
@@ -24,6 +24,7 @@
#include "addons/ContextMenuAddon.h"
#include "addons/ContextMenus.h"
#include "addons/IAddon.h"
#include "favourites/ContextMenus.h"
#include "music/ContextMenus.h"
#include "pvr/PVRContextMenus.h"
#include "video/ContextMenus.h"
@@ -18,14 +18,10 @@
*
*/

#include "FileItem.h"
#include "ServiceBroker.h"
#include "dialogs/GUIDialogFavourites.h"
#include "storage/MediaManager.h"
#include "utils/URIUtils.h"

#include "ContextMenus.h"


namespace CONTEXTMENU
{

@@ -57,41 +53,4 @@ namespace CONTEXTMENU
return g_mediaManager.Eject(item->GetPath());
}

bool CFavouriteContextMenuAction::IsVisible(const CFileItem& item) const
{
return URIUtils::IsProtocol(item.GetPath(), "favourites");
}

bool CFavouriteContextMenuAction::Execute(const CFileItemPtr& item) const
{
CFileItemList items;
CServiceBroker::GetFavouritesService().GetAll(items);
for (const auto& favourite : items)
{
if (favourite->GetPath() == item->GetPath())
{
if (DoExecute(items, favourite))
return CServiceBroker::GetFavouritesService().Save(items);
}
}
return false;
}

bool CRemoveFavourite::DoExecute(CFileItemList &items, const CFileItemPtr& item) const
{
int iBefore = items.Size();
items.Remove(item.get());
return items.Size() == iBefore - 1;
}

bool CRenameFavourite::DoExecute(CFileItemList&, const CFileItemPtr& item) const
{
return CGUIDialogFavourites::ChooseAndSetNewName(item);
}

bool CChooseThumbnailForFavourite::DoExecute(CFileItemList&, const CFileItemPtr& item) const
{
return CGUIDialogFavourites::ChooseAndSetNewThumbnail(item);
}

} // namespace CONTEXTMENU
@@ -39,39 +39,4 @@ struct CEjectDrive : CStaticContextMenuAction
bool Execute(const CFileItemPtr& item) const override;
};

class CFavouriteContextMenuAction : public CStaticContextMenuAction
{
public:
explicit CFavouriteContextMenuAction(uint32_t label) : CStaticContextMenuAction(label) {}
bool IsVisible(const CFileItem& item) const override;
bool Execute(const CFileItemPtr& item) const override;
protected:
virtual ~CFavouriteContextMenuAction() = default;
virtual bool DoExecute(CFileItemList& items, const CFileItemPtr& item) const = 0;
};

class CRemoveFavourite : public CFavouriteContextMenuAction
{
public:
CRemoveFavourite() : CFavouriteContextMenuAction(15015) {} // Remove
protected:
bool DoExecute(CFileItemList& items, const CFileItemPtr& item) const override;
};

class CRenameFavourite : public CFavouriteContextMenuAction
{
public:
CRenameFavourite() : CFavouriteContextMenuAction(118) {} // Rename
protected:
bool DoExecute(CFileItemList& items, const CFileItemPtr& item) const override;
};

class CChooseThumbnailForFavourite : public CFavouriteContextMenuAction
{
public:
CChooseThumbnailForFavourite() : CFavouriteContextMenuAction(20019) {} // Choose thumbnail
protected:
bool DoExecute(CFileItemList& items, const CFileItemPtr& item) const override;
};

}
@@ -1,5 +1,7 @@
set(SOURCES FavouritesService.cpp)
set(SOURCES ContextMenus.cpp
FavouritesService.cpp)

set(HEADERS FavouritesService.h)
set(HEADERS ContextMenus.h
FavouritesService)

core_add_library(favourites)
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2016 Team Kodi
* http://kodi.tv
*
* 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 "FileItem.h"
#include "ServiceBroker.h"
#include "dialogs/GUIDialogFavourites.h"
#include "utils/URIUtils.h"

#include "ContextMenus.h"


namespace CONTEXTMENU
{
bool CFavouriteContextMenuAction::IsVisible(const CFileItem& item) const
{
return URIUtils::IsProtocol(item.GetPath(), "favourites");
}

bool CFavouriteContextMenuAction::Execute(const CFileItemPtr& item) const
{
CFileItemList items;
CServiceBroker::GetFavouritesService().GetAll(items);
for (const auto& favourite : items)
{
if (favourite->GetPath() == item->GetPath())
{
if (DoExecute(items, favourite))
return CServiceBroker::GetFavouritesService().Save(items);
}
}
return false;
}

bool CRemoveFavourite::DoExecute(CFileItemList &items, const CFileItemPtr& item) const
{
int iBefore = items.Size();
items.Remove(item.get());
return items.Size() == iBefore - 1;
}

bool CRenameFavourite::DoExecute(CFileItemList&, const CFileItemPtr& item) const
{
return CGUIDialogFavourites::ChooseAndSetNewName(item);
}

bool CChooseThumbnailForFavourite::DoExecute(CFileItemList&, const CFileItemPtr& item) const
{
return CGUIDialogFavourites::ChooseAndSetNewThumbnail(item);
}

} // namespace CONTEXTMENU
@@ -0,0 +1,63 @@
#pragma once
/*
* Copyright (C) 2016 Team Kodi
* http://kodi.tv
*
* 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 "ContextMenuItem.h"


namespace CONTEXTMENU
{

class CFavouriteContextMenuAction : public CStaticContextMenuAction
{
public:
explicit CFavouriteContextMenuAction(uint32_t label) : CStaticContextMenuAction(label) {}
bool IsVisible(const CFileItem& item) const override;
bool Execute(const CFileItemPtr& item) const override;
protected:
virtual ~CFavouriteContextMenuAction() = default;
virtual bool DoExecute(CFileItemList& items, const CFileItemPtr& item) const = 0;
};

class CRemoveFavourite : public CFavouriteContextMenuAction
{
public:
CRemoveFavourite() : CFavouriteContextMenuAction(15015) {} // Remove
protected:
bool DoExecute(CFileItemList& items, const CFileItemPtr& item) const override;
};

class CRenameFavourite : public CFavouriteContextMenuAction
{
public:
CRenameFavourite() : CFavouriteContextMenuAction(118) {} // Rename
protected:
bool DoExecute(CFileItemList& items, const CFileItemPtr& item) const override;
};

class CChooseThumbnailForFavourite : public CFavouriteContextMenuAction
{
public:
CChooseThumbnailForFavourite() : CFavouriteContextMenuAction(20019) {} // Choose thumbnail
protected:
bool DoExecute(CFileItemList& items, const CFileItemPtr& item) const override;
};

}

0 comments on commit b790c8e

Please sign in to comment.
You can’t perform that action at this time.