# -*- coding: utf-8 -*-
from Plugins.Bp.geminimain.gLocale import _
from Plugins.Bp.geminimain.GeminiDef import *

from Plugins.Bp.geminimain.gTools import libgeminimain, cleanexit, pathExists, pathRemove, gLoadPixmap, isHDRes, gPluginPath
from Plugins.Bp.geminimain.WidgetConfig import gConfigWindow, gConfigSelection, gConfigOnOff, CONFIGSEPERATOR
from Plugins.Bp.geminimain.lib.libjukebox import Cjukebox
from Plugins.Bp.geminimain.Cjukeboxevent import cjukeboxevent
from Plugins.Bp.geminimain.WidgetVariableList import WidgetVariableList
from Plugins.Bp.geminimain.WidgetBackGround import WidgetBackground, confBackground
from Plugins.Bp.geminimain.plugin import cgevent, dbusNotifier, geventNotifier
from Plugins.Bp.geminimain.FileBrowser import *

from enigma import eTimer, eServiceReference, eActionMap
from Screens.Screen import Screen
from Screens.MessageBox import MessageBox
from Components.ActionMap import NumberActionMap, ActionMap
from Screens.ChoiceBox import ChoiceBox
from Components.config import config, NoSave, getConfigListEntry, ConfigText, ConfigInteger
from Components.Console import Console
from Components.Label import Label
from Components.Pixmap import MultiPixmap
from Components.Sources.StaticText import StaticText
from Components.Sources.Progress import Progress

from skin import loadSkin
loadSkin(gPluginPath + "geminijukebox/skin.xml")

from equalizer import Cequalizer

class JukeBoxSummary(Screen):
	def __init__(self, session, parent):
		Screen.__init__(self, session, parent = parent)
		self.skinName = ["Jukebox_Summary"]

class JukeBoxSummarySupport:
	def __init__(self):
		pass

	def createSummary(self):
		return JukeBoxSummary


#----------------------------------------------------------------------------------------

class JukeBox(JukeBoxSummarySupport, WidgetVariableList):
	GMEDIASCAN = "/usr/bin/gMediaScan"
	#GMEDIASCAN = "/root/bin/gMediaScan"
	TMPPLAYLIST="/tmp/.playlist"
	#Status und Pixmap
	STAT_STOP=0
	STAT_PLAY=1
	STAT_PAUSE=2
	STAT_REV=3
	STAT_FF=4
	#Picture
	noCover = gLoadPixmap("geminijukebox/icon_noCover.png")
	dirPic = gLoadPixmap("geminijukebox/folder.png")

	ALLOW_SUSPEND = True
	ENABLE_RESUME_SUPPORT = True

	def __init__(self, session, name=None, setPath=None):
		WidgetVariableList.__init__ (self, session, _("Jukebox"), icon="geminijukebox/icon_jukebox.png", LinesProEntry=4, ListIcon=(100,100), showMenuPix=True, NameRed=_("Rewind"), NameGreen=_("Play"), NameYellow=_("Pause / Resume"), NameBlue=_("Forward"))
		self.skinName = []
		if isHDRes == 1:
			self.skinName.append("Jukebox-XD")
		elif isHDRes == 2:
			self.skinName.append("Jukebox-HD")
		self.skinName.append("Jukebox-SD")
			
		self["TimeStr"] = StaticText()
		self["NameStr"] = StaticText()
		self["Progress"] = Progress()
		self["StatusPixmap"] = MultiPixmap()
		self["LoopPixmap"] = MultiPixmap()
		self["RandomPixmap"] = MultiPixmap()
		self["ScanPixmap"] = MultiPixmap()
		self["TitleStr"] = StaticText(_("Title") + ": ")

		self.path =  setPath or cgevent.getConfig("Jukebox_lastpath","/")
		self.lastpath = self.path
		self.path = self.path[:self.path.rfind('/')]
		if self.path == "":
			self.path = "/"
			
		extension = self.path.split('.')
		extension = extension[-1].upper()
		self.__Playlisttyp=None
		if extension == "M3U" or extension == "PLS":
			self.__Playlisttyp = extension
			self.lastpath = self.path[:self.path.rfind('/')]

		self.__hidelist, self.__permlist = readDMconf()

		self.ListTimer = eTimer()
		self.ListTimer_conn = self.ListTimer.timeout.connect(self.__UpdateEntry)
		
		self.Console = Console()
		self.__gSoundisRunning=False

		from Plugins.Bp.geminimain.lib import libgtools
		self.libgtools = libgtools
		
		self.__libjukebox = Cjukebox()
		self.__libjukebox.callback = self.__newPlayerEvent

		JukeBoxSummarySupport.__init__(self)
		
		self.__CurrDevice = "hw:0,0"
		for x in self.libgtools.getAudioDevice():
			if x[2]=="BCM ALSA driver - BCM PCM":
				self.__CurrDevice = x[1]
		self.__DMMAlsaDevice = self.__CurrDevice

		self.__currRunning = None
		self.__firstTitle = ""
		self.__randomOn = 0
		self.__loop = 0
		self.__lastservice = self.session.nav.getCurrentlyPlayingServiceReference()
		self.session.nav.stopService()
		self.Background = self.session.instantiateDialog(WidgetBackground, self.__SwitchShowHide, self.__lastservice)
		
		self["NumberActions"] = NumberActionMap(["NumberActions", "InputAsciiActions"],
		{
			"1": self.keyNumberGlobal,
			"2": self.keyNumberGlobal,
			"3": self.keyNumberGlobal,
			"4": self.keyNumberGlobal,
			"5": self.keyNumberGlobal,
			"6": self.keyNumberGlobal,
			"7": self.keyNumberGlobal,
			"8": self.keyNumberGlobal,
			"9": self.keyNumberGlobal,
		}, -2)
		
		self["jbactions"] = ActionMap(["gActions"],
		{
			"nextBouquet": self.nextTitle,
			"prevBouquet": self.prevTitle,
			"historyBack": self.historyBack,
			"historyNext": self.historyNext
		}, -2)
		
		geventNotifier.append((EVENT_QBCALLBACK, self.__QBCallback))
		self.__slot = eActionMap.getInstance().bindAction('', -0x1FFFFFFF, self.__keyPressed)
		self.onLayoutFinish.append(self.__readConfig)

	def KeyExit(self):
		self.__slot = None
		geventNotifier.remove((EVENT_QBCALLBACK, self.__QBCallback))
		self.Background.Exit()
		self.__saveLastPath()
		
		if self.Console is not None:
			if len(self.Console.appContainers):
				for name in self.Console.appContainers.keys():
					self.Console.kill(name)
		
		del self.libgtools
		self.__libjukebox.stop()
		del self.__libjukebox
		cjukeboxevent.clean()
		self.session.nav.playService(self.__lastservice)
		self.close()
		cleanexit(__name__)
		
	def __keyPressed(self, key=None, flag=None):
		if flag is not None and flag==1:
			if key==128:#stop
				self.__firstTitle = ""
				self.__libjukebox.stop()
			elif key==207:#pause
				self.KeyYellow()
			elif key==113 and self.__CurrDevice != self.__DMMAlsaDevice:#mute
				self.__libjukebox.mute()
			elif key==114 and self.__CurrDevice != self.__DMMAlsaDevice:#volume-
				self.__libjukebox.setVolume("-")
			elif key==115 and self.__CurrDevice != self.__DMMAlsaDevice:#volume+
				self.__libjukebox.setVolume("+")
		return 0

	def __newPlayerEvent(self, func, value):
		#print "newPlayerEvent___________________________",func,value
		cjukeboxevent.JBEvent(func,value)
		if func==cjukeboxevent.JUKEBOX_STATUS:
			if value=="PAUSED":
				self["StatusPixmap"].setPixmapNum(self.STAT_PAUSE)
			elif value=="PLAYING":
				self["StatusPixmap"].setPixmapNum(self.STAT_PLAY)
			elif value=="EOF":
				sel = self.getCurrentEntry()
				if self.__currRunning is not None and sel and  self.__currRunning != sel and sel[3][B_FILTER] & FILTER_SOUND:
					self.__playFile()
					return
				self.nextTitle()
			elif value=="STOPPED":
				self.__stopFile()
			elif value=="SEEKFF":
				self["StatusPixmap"].setPixmapNum(self.STAT_FF)
			elif value=="SEEKREV":
				self["StatusPixmap"].setPixmapNum(self.STAT_REV)
		elif func==cjukeboxevent.JUKEBOX_TIME_URL:
			val = value.split(' ',2)
			if len(val)==3:
				#state = int(val[0])
				totaltime = int(val[0])
				playtime = int(val[1])
				
				if self.__currRunning is None:
					self.__searchCurrRunning(val[2],False)
					self.__setNameStr()
					
				if totaltime > 0 and playtime >= 0:
					prozvalue = playtime*100/totaltime
					if prozvalue >= 0 and prozvalue <= 100:
						self["Progress"].setValue(prozvalue)
						if self.__timeInvers == 1:
							self["TimeStr"].setText("-"+libgeminimain.getHumanDate(1,totaltime - playtime))
						else:
							self["TimeStr"].setText(libgeminimain.getHumanDate(1,playtime))
						return
			self["Progress"].setValue(0)
			self["TimeStr"].setText("")
		elif func==cjukeboxevent.JUKEBOX_ERROR:
			self.Background.lockKeys(True)
			self.session.openWithCallback(self.__QBCallback, MessageBox, value, MessageBox.TYPE_INFO, timeout = 5)

	def __SwitchShowHide(self,val):
		if val == True and self.shown:
			self.hide()
		else:
			self.show()
			
	def __searchCurrRunning(self, filename, setIndex):
		count=0
		for x in self.GetList():
			if x[3][B_FULL] == filename:
				if setIndex:
					self.SetIndex(count)
				self.__currRunning = self.getCurrentEntry()
				break
			count+=1
			
	def KeyLeft(self):
		if self.shown:
			WidgetVariableList.KeyLeft(self)
		else:
			self.Background.PipPrevService()
		
	def KeyRight(self):
		if self.shown:
			WidgetVariableList.KeyRight(self)
		else:
			self.Background.PipNextService()
	
	def keyNumberGlobal(self, number):
		if self.shown == False:
			self.Background.keyNumberGlobal(number)
		
	def __fillListe(self):
		llist = []
		index = 0
		scount = 0
		count = 0

		if self.__Playlisttyp is not None:
			self.__startConsole(MI_SCANPLAYLIST,None)
			flist = libgeminimain.getPyList(GETPLAYLIST,(self.path, self.lastpath, self.__Playlisttyp, "/root/.geminicache"))
		else:
			self.__startConsole(MI_SCANDIR,None)
			flist = libgeminimain.getPyList(GETFILELIST,(self.path, (FILTER_SOUND | FILTER_PL), SORT_NAME, 0,0,0))
		
		if self.__randomOn:
			#print "______________________________self.__randomOn"
			from random import shuffle
			ranlist = list(flist)
			shuffle(ranlist)
			flist = sorted(ranlist, key=lambda x:(x[B_MODE]), reverse=False)

		for x in flist:
			if x[B_NAME] in self.__hidelist:
				continue
			if x[B_FULL] == self.lastpath:
				index = count
			
			pic = None
			if x[B_FILTER] & FILTER_GOUP:
				pic = None
			elif x[B_FILTER] & (FILTER_DIR | FILTER_PL):
				pic = self.dirPic
			elif x[B_FILTER] & FILTER_SOUND:
				pic = self.noCover
				scount += 1
				
			taglist = []
			x[B_STATUS] = 0
			if pathExists(x[B_CFILE]+".txt"):
				taglist = readCacheInfos(x[B_CFILE]+".txt")
				if len(taglist)==7:
					x[B_STATUS] |= STATUS_INFO
			if pathExists(x[B_CFILE]+".png"):
				x[B_STATUS] |= STATUS_PICTURE
				pic = gLoadPixmap(x[B_CFILE]+".png", cached=False)

			llist.append((createInfoString(taglist, x), pic, None, x, taglist))
			count += 1

		self.setTitle(_("Path") + ": " + self.path + " (" + str(scount) +")")
		self.SetList(llist)
		self.SetIndex(index)
		
	def selectionChanged(self):
		self.ListTimer.start(300,True)
		
	def __UpdateEntry(self):
		sel = self.getCurrentEntry()
		if sel and sel[3]:
			pic = sel[1]
			taglist = sel[4]
			if not sel[3][B_STATUS] & STATUS_INFO:
				if pathExists(sel[3][B_CFILE]+".txt"):
					taglist = readCacheInfos(sel[3][B_CFILE]+".txt")
					if len(taglist)==7:
						sel[3][B_STATUS] |= STATUS_INFO
			if not sel[3][B_STATUS] & STATUS_PICTURE:
				if pathExists(sel[3][B_CFILE]+".png"):
					sel[3][B_STATUS] |= STATUS_PICTURE
					pic = gLoadPixmap(sel[3][B_CFILE]+".png", cached=False)
			
			if pic != sel[1] or taglist != sel[4]:
				list = (createInfoString(taglist, sel[3]), pic, None,sel[3],taglist)
				self.editEntry(self.GetIndex(),list)
	
	def historyBack(self):
		self.__menuCallback((None,7))
		
	def historyNext(self):
		self.__menuCallback((None,8))

	def KeyMenu(self):
		menu = []
		if self.__gSoundisRunning == False:
			menu.append((_("Rescan Folder"),3))
			menu.append((_("Rescan File"),4))
		if self.__randomOn==0:
			menu.append(("%s (%s)" %(_("Play title randomly"),_("enable")),7))
		else:
			menu.append(("%s (%s)" %(_("Play title randomly"),_("disable")),7))
		if self.__loop==0:
			menu.append(("%s (%s)" %(_("Play title as a loop"),_("enable")),8))
		else:
			menu.append(("%s (%s)" %(_("Play title as a loop"),_("disable")),8))
		menu.append(("--", ""))
		menu.append((_("Equalizer"), 9))
		menu.append((_("Setup"),1))
		menu.append((_("Setup Background"), 2))
		menu.append((_("Quickbutton extension"), 5))
		menu.append(("--", ""))
		#Playback on the device
		for x in self.libgtools.getAudioDevice():
			issel=""
			if x[1]==self.__CurrDevice:
				issel="(*) "
			menu.append((_("%sPlayback on device '%s'") %(issel,x[2]), 6, x[1]))

			
		self.Background.lockKeys(True)
		self.session.openWithCallback(self.__menuCallback, ChoiceBox, title="", keys=[ "1", "2", "3", "4", "--", "5", "6", "7","green","--"], list=menu)
		
	def __menuCallback(self, what=None):
		self.Background.lockKeys(False)
		if what is None:
			return
		elif what[1] == 1: # Background Settings
			self.Background.lockKeys(True)
			self.session.openWithCallback(self.__readConfig, JukeboxSetup)
		elif what[1] == 2: # Background Settings
			self.session.open(confBackground, self.Background)
		elif what[1] == 3:# Rescan Ordner
			self.__startConsole(MI_RESCANDIR,None)
		elif what[1] == 4:# Rescan File
			sel = self.getCurrentEntry()
			if sel and sel[3]:
				self.__startConsole(MI_SCANSOUND, sel[3])
		elif what[1] == 5: # Webbrowser
			self.Background.lockKeys(True)
			from Plugins.Bp.geminimain.plugin import InfoBarPlugins
			InfoBarPlugins.quickSelectGlobal(cgevent.InfobarInstance,cgevent.getConfig("Jukebox_Quickbtn", "green_long"), True)
		elif what[1] == 6:
			self.__CurrDevice=what[2]
			if self.__currRunning is not None:
				self.__playFile()
		elif what[1] == 7:
			if self.__randomOn==0:
				self.__randomOn=1
			else:
				self.__randomOn=0
			self["RandomPixmap"].setPixmapNum(self.__randomOn)
			self.__fillListe()
		elif what[1] == 8:
			if self.__loop==0:
				self.__loop=1
			else:
				self.__loop=0
			self["LoopPixmap"].setPixmapNum(self.__loop)
		elif what[1] == 9:
			if self.__useEqualizer==0:
				self.Background.lockKeys(True)
				self.session.openWithCallback(self.__callBackEqualizerMess, MessageBox, _("Use equalizer") + "?", MessageBox.TYPE_YESNO)
			else:
				self.Background.lockKeys(True)
				self.session.openWithCallback(self.__callBackEqualizer, Cequalizer, self.__EqualizerValue, self.__libjukebox)
	
	def __callBackEqualizerMess(self,val=None):
		if val:
			self.__useEqualizer = 1
			cgevent.setConfig("Jukebox_useEqualizer", self.__useEqualizer)
			self.session.openWithCallback(self.__callBackEqualizer, Cequalizer, self.__EqualizerValue, self.__libjukebox)
		else:
			self.Background.lockKeys(False)
			
	def __callBackEqualizer(self,val=None):
		self.Background.lockKeys(False)
		if val is not None:
			self.__EqualizerValue = val
			cgevent.setConfig("Jukebox_Equalizer", self.__EqualizerValue)
			self.__libjukebox.setEqualizer(self.__EqualizerValue)
		
	def __QBCallback(self,val=None):
		self.Background.lockKeys(False)
			
	def __callbackWebbrowser(self, val=None):
		self.KeyMenu()

	def __saveLastPath(self):
		sel = self.getCurrentEntry()
		if sel and sel[3]:
			if sel[3][B_FILTER]  & FILTER_GOUP:
				cgevent.setConfig("Jukebox_lastpath", self.path + "/..")
			else:
				cgevent.setConfig("Jukebox_lastpath", sel[3][B_FULL])

	def __readConfig(self, isSetup=False):
		self.Background.lockKeys(False)
		self.__useInetPicture = cgevent.getConfig("Jukebox_useInetPicture", 1)
		self.__timeInvers = cgevent.getConfig("Jukebox_timeInvers", 0)
		self.__jumptime = cgevent.getConfig("Jukebox_jumptime", 5)
		self.__useEqualizer = cgevent.getConfig("Jukebox_useEqualizer", 0)
		self.__EqualizerValue = cgevent.getConfig("Jukebox_Equalizer", "24,24,24,24,24,24,24,24,24,24")
		if isSetup==False:
			self.__fillListe()

#-------------------------------------------------------------------------------------

	def KeyOk(self):
		if self.shown:
			sel = self.getCurrentEntry()
			if sel and sel[3]:
				if sel[3][B_FILTER] & FILTER_DIR:
					self.__Playlisttyp = None
					self.lastpath = self.path
					self.path = sel[3][B_FULL]
					self.__fillListe()
				elif sel[3][B_FILTER] & FILTER_PL:
					self.__Playlisttyp = sel[3][B_EXT]
					self.lastpath = self.path
					self.path = sel[3][B_FULL]
					self.__fillListe()
				elif sel[3][B_FILTER] & FILTER_SOUND:
					self.__playFile(True)

	def KeyGreen(self):
		if self.__currRunning is not None:
			if self.__currRunning != self.getCurrentEntry():
				self.KeyOk()
		else:
			self.KeyOk()

	def KeyYellow(self):
		self.__libjukebox.pause()

	def KeyRed(self):
		self.KeyPrev()

	def KeyPrev(self):
		if self.__libjukebox.isSeeking()>0:
			self.__libjukebox.seek("0")
		else:
			self.__libjukebox.seek(str(-self.__jumptime))
		
	def KeyBlue(self):
		self.KeyNext()

	def KeyNext(self):
		if self.__libjukebox.isSeeking()>0:
			self.__libjukebox.seek("0")
		else:
			self.__libjukebox.seek(str(self.__jumptime))

	def nextTitle(self):
		self.__firstTitle = ""
		self.__testTitle = self.getCurrentEntry()
		self.__NextTitle()
		
	def __NextTitle(self):
		WidgetVariableList.KeyDown(self)
		sel = self.getCurrentEntry()
		if sel and sel[3]:
			if sel[3][B_FILTER] & FILTER_SOUND:
				self.__playFile()
			else:
				#if len(self.GetList())>2:
				if sel == self.__testTitle:
					self.__stopFile()
				else:
					self.__NextTitle()
				#else:
				#	print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	
	def prevTitle(self):
		self.__firstTitle = ""
		self.__testTitle = self.getCurrentEntry()
		self.__PrevTitle()
		
	def __PrevTitle(self):
		WidgetVariableList.KeyUp(self)
		sel = self.getCurrentEntry()
		if sel and sel[3]:
			if sel[3][B_FILTER] & FILTER_SOUND:
				self.__playFile()
			else:
				if len(self.GetList())>2:
					if sel == self.__testTitle:
						self.__stopFile()
					else:
						self.__PrevTitle()

	def __playFile(self, setFirstTitle=False):
		sel = self.getCurrentEntry()
		if sel and sel[3]:
			if self.__firstTitle == sel[3][B_FULL] and self.__loop < 1:
				#print "f=c_________________________________________"
				self.__libjukebox.stop()#Stopp erster Titel erreicht
				self.__firstTitle = ""
				self.__stopFile()
				return
			
			if setFirstTitle:
				self.__firstTitle = sel[3][B_FULL]

			self.__currRunning = sel[:]
			self.__setNameStr()
			
			notdmmalsa = int(self.__CurrDevice != self.__DMMAlsaDevice)
			if self.__useEqualizer>0:
				self.__libjukebox.start([sel[3][B_FULL], self.__CurrDevice, notdmmalsa,self.__EqualizerValue])
			else:
				if notdmmalsa:
					self.__libjukebox.start([sel[3][B_FULL], self.__CurrDevice, notdmmalsa])
				else:
					self.__libjukebox.start([sel[3][B_FULL], "", notdmmalsa])

	def __stopFile(self):
		self.__currRunning = None
		self["StatusPixmap"].setPixmapNum(self.STAT_STOP)
		self["Progress"].setValue(0)
		self["TimeStr"].setText("")
		self["NameStr"].setText("")

	def __setNameStr(self):
		if self.__currRunning is not None:
			text=self.__currRunning[3][B_NAME]
			if len(self.__currRunning[4])==7 and self.__currRunning[4][SOUND_TITLE] is not "":
				text = self.__currRunning[4][SOUND_TITLE]
				if self.__currRunning[4][SOUND_ARTIST] is not "":
					text += " - " + self.__currRunning[4][SOUND_ARTIST]
			self["NameStr"].setText(text)
		
#---------------------------------------------------------------------

	def __startConsole(self, func, file):
		if self.__gSoundisRunning == False:
			cmd=None
			if func==MI_SCANDIR or func==MI_RESCANDIR:
				cmd = "%s '%s' '%s' %d %d '%s'" %(self.GMEDIASCAN, self.path, "/root/.geminicache", self.__useInetPicture, func, "all")
			elif func==MI_SCANSOUND:
				cmd = "%s '%s' '%s' %d %d '%s'" %(self.GMEDIASCAN, file[B_NAME], file[B_CFILE], self.__useInetPicture, func, " ")
			elif func==MI_SCANPLAYLIST:
				cmd = "%s '%s' '%s' %d %d '%s'" %(self.GMEDIASCAN, self.lastpath, "/root/.geminicache", self.__useInetPicture, func, self.path)
				
			if cmd:
				self.__gSoundisRunning = True
				self["ScanPixmap"].setPixmapNum(1)
				self.Console.ePopen(cmd, self.__FinishedConsole)
			
	def __FinishedConsole(self, result, retval, extra_args = None):
		self.__gSoundisRunning = False
		self["ScanPixmap"].setPixmapNum(0)
	
#---------------------------------------------------------------------------------------------

class JukeboxSetup(gConfigWindow):
	def __init__(self, session):
					
		qbsmenu = [('red', _('red')), ('red_long', _('red') + ' ' + _('long')), ('green', _('green')), ('green_long', _('green') + ' ' + _('long')), ('yellow', _('yellow')), ('yellow_long', _('yellow') + ' ' + _('long')), ('blue', _('blue')), ('blue_long', _('blue') + ' ' + _('long')), ('console', _('CONSOLE (DMM Kbd)')), ('f1', _('F1 (DMM Kbd) / F2 (Kbd)')), ('f2', _('F2 (DMM Kbd) / F3 (Kbd)')), ('web', _('WEB (DMM Kbd) / F6 (Kbd)')), ('mail', _('MAIL (DMM Kbd) / / F7 (Kbd)')), ('pvr', _('PVR / Video / F8 (Kbd)')), ( 'pvr_long', _('PVR / Video / F8 (Kbd)') + ' ' + _('long')), ('radio', _('RADIO / F9 (Kbd)')), ('radio_long', _('RADIO / F9 (Kbd)') + ' ' + _('long')), ('m1', _('M1 (DMM Kbd) / F11 (Kbd)')), ('m2', _('M2 (DMM Kbd) / F10 (Kbd)')), ('text', _('TEXT')), ('text_long', _('TEXT') + ' ' + _('long')), ('help_long', _('HELP') + ' ' + _('long')), ('info', _('INFO')), ('info_long', _('INFO') + ' ' + _('long'))]
		
		config.bp.quickbtn = NoSave(gConfigSelection(default=str(cgevent.getConfig("Jukebox_Quickbtn", "green_long")), choices=qbsmenu))
		config.bp.inetpic = NoSave(gConfigOnOff(default=cgevent.getConfig("Jukebox_useInetPicture", 1)))
		config.bp.timeInvers = NoSave(gConfigOnOff(default=cgevent.getConfig("Jukebox_timeInvers", 0)))
		config.bp.equalizer = NoSave(gConfigOnOff(default=cgevent.getConfig("Jukebox_useEqualizer", 0)))
		config.bp.jumptime = NoSave(ConfigInteger(default=cgevent.getConfig("Jukebox_jumptime", 5), limits = [2,99]))
		
		list=[]
		list.append(getConfigListEntry(_("Use equalizer"), config.bp.equalizer))
		list.append(getConfigListEntry(_("Downloading cover from Internet"), config.bp.inetpic))
		list.append(getConfigListEntry(_("Show time inverted"), config.bp.timeInvers))
		list.append(getConfigListEntry(_("Skip ? seconds"), config.bp.jumptime))
		list.append(CONFIGSEPERATOR())
		list.append(getConfigListEntry(_("Quickbutton extension in Menu"), config.bp.quickbtn))
		
		gConfigWindow.__init__(self, session,list=list)
		
	def KeyGreen(self):
		cgevent.setConfig("Jukebox_Quickbtn", config.bp.quickbtn.value)
		cgevent.setConfig("Jukebox_useInetPicture", config.bp.inetpic.value)
		cgevent.setConfig("Jukebox_timeInvers", config.bp.timeInvers.value)
		cgevent.setConfig("Jukebox_useEqualizer", config.bp.equalizer.value)
		cgevent.setConfig("Jukebox_jumptime", config.bp.jumptime.value)
		self.KeyExit()

	def KeyExit(self):
		self.close(True)
