# MovieSelectionMerlinContextMenu
#
# Coded by dre (c) 2015 - 2016
# Support: www.dreambox-tools.info
# E-Mail: dre@dreambox-tools.info
#
# This module is open source but it is NOT free software.
#
# This module may only be distributed to and executed on hardware which
# is licensed by Dream Multimedia GmbH.
# In other words:
# It's NOT allowed to distribute any parts of this module or its source code in ANY way
# to hardware which is NOT licensed by Dream Multimedia GmbH.
# It's NOT allowed to execute this module and its source code or even parts of it in ANY way
# on hardware which is NOT licensed by Dream Multimedia GmbH.
#
# If you want to use or modify the code or parts of it,
# you have to keep MY license and inform me about the modifications by mail.

from __future__ import absolute_import
from Screens.Screen import Screen
from Components.config import config, ConfigSubsection, ConfigText, ConfigInteger, ConfigLocations, ConfigSet, ConfigYesNo
from Components.MovieList import MovieList
from Components.Sources.List import List
from Plugins.Plugin import PluginDescriptor
from Screens.MerlinContextMenu import MerlinContextMenu
from Screens.MerlinContextMenu import MerlinContextMenuSummary
from Screens.MovieSelection import MovieContextMenu
from Tools.BoundFunction import boundFunction
from Tools.LoadPixmap import LoadPixmap

class MovieSelectionMerlinContextMenu(MovieContextMenu, Screen, MerlinContextMenu):
	def __init__(self, session, csel, service):
		Screen.__init__(self, session)
		self.csel = csel
		self.service = service
		
		self.getContextMenuList()
	
		MerlinContextMenu.__init__(self, self.service, self.contextMenuList, "Movielist menu")
		self.skinName = "MerlinContextMenu"
		
	def createSummary(self):
		return MerlinContextMenuSummary
		
	def getContextMenuList(self):
		
		# Dr.Best selection mode
		if self.csel and self.csel["list"].getSelectionMode():
			if self.csel["list"].getSelectionMode() == 1: # Dr.Best delete mode
				self.contextMenuList = [(_("cancel delete mode..."), "", boundFunction(self.switchSelectionMode,0), ["folder","item"], None, self.MENUITEM)]
			else: # Dr.Best moveTo mode
				self.contextMenuList = [(_("cancel move mode..."), "", boundFunction(self.switchSelectionMode,0), ["folder","item"], None, self.MENUITEM)]
			if len(self.csel["list"].getSelectionList()) > 0:
				if self.csel["list"].getSelectionMode() == 1: # Dr.Best delete mode
					self.contextMenuList.append((_("delete all selected movies..."), "", self.deleteMovies, ["folder","item"], None, self.MENUITEM))
				else: # Dr.Best moveTo mode
					self.contextMenuList.append((_("move all selected movies..."), "", self.moveToMovies, ["folder","item"], None, self.MENUITEM))

			return
		
		self.contextMenuList = [
			[_("Move & delete"), _("Functionalities to move and delete movies"), self.enterMenu, ["folder","item"], "moveanddelete", self.CATEGORY],
			[_("Movielist layout"), _("Movielist layout options"), self.enterMenu, ["folder","item"], "movielistlayout", self.CATEGORY],
			[_("Sort order"), _("Sort options for movies"), self.enterMenu, ["folder","item"], "sortorder", self.CATEGORY],
			[_("list style default"), "", boundFunction(self.listType, MovieList.LISTTYPE_ORIGINAL), ["folder","item"], "movielistlayout", self.MENUITEM],
			[_("list style compact with description"), "", boundFunction(self.listType, MovieList.LISTTYPE_COMPACT_DESCRIPTION), ["folder","item"], "movielistlayout", self.MENUITEM],
			[_("list style compact"), "", boundFunction(self.listType, MovieList.LISTTYPE_COMPACT), ["folder","item"], "movielistlayout", self.MENUITEM],
			[_("list style Merlin2 single line"), "", boundFunction(self.listType, MovieList.LISTTYPE_MINIMAL_MERLIN), ["folder","item"], "movielistlayout", self.MENUITEM],
			[_("list style single line"), "", boundFunction(self.listType, MovieList.LISTTYPE_MINIMAL), ["folder","item"], "movielistlayout", self.MENUITEM],
			[_("mark as seen..."), "", boundFunction(self.setMovieStatus, 1), ["item"], None, self.MENUITEM],
			[_("mark as unseen..."), "", boundFunction(self.setMovieStatus, 0), ["item"], None, self.MENUITEM],
			[_("delete..."), "", self.delete, ["folder","item"], "moveanddelete", self.MENUITEM],
			[_("activate delete mode..."), "", boundFunction(self.switchSelectionMode,1), ["folder","item"], "moveanddelete", self.MENUITEM],
			[_("move..."), "", self.moveTo, ["item"], "moveanddelete", self.MENUITEM],
			[_("activate move mode..."), "", boundFunction(self.switchSelectionMode,2), ["folder","item"], "moveanddelete", self.MENUITEM]			
			]

		# Dr.Best: sort by date desc/asc
		if config.movielist.moviesort.value == MovieList.SORT_ALPHANUMERIC:
			#menu.append((_("sort by date"), boundFunction(self.sortBy, MovieList.SORT_RECORDED)))
			self.contextMenuList.append((_("sort by date desc"), "", boundFunction(self.sortBy, MovieList.SORT_DATE_DESC), ["folder","item"], "sortorder", self.MENUITEM))
			self.contextMenuList.append((_("sort by date asc"), "", boundFunction(self.sortBy, MovieList.SORT_DATE_ASC), ["folder","item"], "sortorder", self.MENUITEM))
		else:
			self.contextMenuList.append((_("alphabetic sort"), "", boundFunction(self.sortBy, MovieList.SORT_ALPHANUMERIC), ["folder","item"], "sortorder", self.MENUITEM))
			if config.movielist.moviesort.value == MovieList.SORT_DATE_DESC:
				self.contextMenuList.append((_("sort by date asc"), "", boundFunction(self.sortBy, MovieList.SORT_DATE_ASC), ["folder","item"], "sortorder", self.MENUITEM))
			else:
				self.contextMenuList.append((_("sort by date desc"), "", boundFunction(self.sortBy, MovieList.SORT_DATE_DESC), ["folder","item"], "sortorder", self.MENUITEM))
			
		if config.movielist.description.value == MovieList.SHOW_DESCRIPTION:
			self.contextMenuList.append((_("hide extended description"), "", boundFunction(self.showDescription, MovieList.HIDE_DESCRIPTION), ["folder","item"], "movielistlayout", self.MENUITEM))
		else:
			self.contextMenuList.append((_("show extended description"), "", boundFunction(self.showDescription, MovieList.SHOW_DESCRIPTION), ["folder","item"], "movielistlayout", self.MENUITEM))

		if config.merlin2.showfoldersinmovielist.value:
			self.contextMenuList.append((_("hide folders in movielist"), "", boundFunction(self.showFolders, False), ["folder","item"], "movielistlayout", self.MENUITEM))
		else:
			self.contextMenuList.append((_("show folders in movielist"), "", boundFunction(self.showFolders, True), ["folder","item"], "movielistlayout", self.MENUITEM))

		# Dr.Best: color status in movielist
		if config.merlin2.showcolorstatusinmovielist.value:
			self.contextMenuList.append((_("hide movie color status in movielist"), "", boundFunction(self.showStatusColor, False), ["folder","item"], "movielistlayout", self.MENUITEM))
		else:
			self.contextMenuList.append((_("show movie color status in movielist"), "", boundFunction(self.showStatusColor, True), ["folder","item"], "movielistlayout", self.MENUITEM))
		
		#dre	
		if config.merlin2.showcoverinmovielist.value:
			self.contextMenuList.append((_("hide movie cover in movielist"), "", boundFunction(self.showMovieCover, False), ["folder","item"], "movielistlayout", self.MENUITEM))
		else:
			self.contextMenuList.append((_("show movie cover in movielist"), "", boundFunction(self.showMovieCover, True), ["folder","item"], "movielistlayout", self.MENUITEM))
			
		self.addPluginMenu("Plugins for movielist")
		self.addPlugins([(PluginDescriptor.WHERE_MOVIELIST,["item"]),(PluginDescriptor.WHERE_MOVIELISTFOLDER,["folder"])])	
		
	

