def editEmuCmd(self):
        # Maybe there is autoconfig support
        preconfiguredEmulator = None
        emulatorPath = ''
        dialog = xbmcgui.Dialog()

        if self.selectedRomCollection.name == 'Linux' \
                or self.selectedRomCollection.name == 'Macintosh' \
                or self.selectedRomCollection.name == 'Windows':
            emulatorPath = self.editTextProperty(CONTROL_BUTTON_EMUCMD,
                                                 util.localize(32624))
        else:
            autoconfig = EmulatorAutoconfig(util.getEmuAutoConfigPath())

            emulist = []

            log.info(
                u"Running on {0}. Trying to find emulator per autoconfig.".
                format(util.current_os))
            emulators = autoconfig.findEmulators(
                util.current_os, self.selectedRomCollection.name, True)

            for emulator in emulators:
                if emulator.isInstalled:
                    emulist.append(util.localize(32202) % emulator.name)
                else:
                    emulist.append(emulator.name)

            # Ask the user which emulator they want
            if len(emulist) > 0:
                emuIndex = dialog.select(util.localize(32203), emulist)
                try:
                    if (emuIndex >= 0):
                        preconfiguredEmulator = emulators[emuIndex]
                except IndexError:
                    log.info("No Emulator selected.")
                    preconfiguredEmulator = None

            if preconfiguredEmulator:
                emulatorPath = preconfiguredEmulator.emuCmd
                self.selectedRomCollection.emulatorParams = preconfiguredEmulator.emuParams
                control = self.getControlById(CONTROL_BUTTON_PARAMS)
                control.setLabel(self.selectedRomCollection.emulatorParams)
            else:
                emulatorPath = dialog.browse(
                    1, '%s ' % self.selectedRomCollection.name +
                    util.localize(32139), 'files')
                if emulatorPath == '':
                    return

        self.selectedRomCollection.emulatorCmd = emulatorPath
        control = self.getControlById(CONTROL_BUTTON_EMUCMD)
        control.setLabel(emulatorPath)
	def onClick(self, controlID):
		log.info("onClick")

		if controlID == CONTROL_BUTTON_EXIT:  # Close window button
			log.info("close")
			self.close()
		# OK
		elif controlID == CONTROL_BUTTON_SAVE:
			log.info("save")
			# Store selectedRomCollection
			if self.selectedRomCollection is not None:
				self.updateSelectedRomCollection()
				self.romCollections[self.selectedRomCollection.id] = self.selectedRomCollection

			configWriter = ConfigXmlWriter(False)
			success, message = configWriter.writeRomCollections(self.romCollections, True)

			if not success:
				xbmcgui.Dialog().ok(util.localize(32021), message)
			self.close()

		# Cancel
		elif controlID == CONTROL_BUTTON_CANCEL:
			self.close()
		# Rom Collection list
		elif self.selectedControlId in (CONTROL_BUTTON_RC_DOWN, CONTROL_BUTTON_RC_UP):
			if self.selectedRomCollection is not None:
				# Save current values to selected Rom Collection
				self.updateSelectedRomCollection()
				# Store previous selectedRomCollections state
				self.romCollections[self.selectedRomCollection.id] = self.selectedRomCollection

			# HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
			xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
			self.updateRomCollectionControls()

		# Media Path
		elif self.selectedControlId in (CONTROL_BUTTON_MEDIA_DOWN, CONTROL_BUTTON_MEDIA_UP):
			# HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
			xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
			self.updateMediaPathControls()

		elif controlID == CONTROL_BUTTON_GAMECLIENT:
			success, gameclient = helper.selectlibretrocore(self.selectedRomCollection.name)
			if success:
				self.selectedRomCollection.gameclient = gameclient

			control = self.getControlById(CONTROL_BUTTON_GAMECLIENT)
			if gameclient == "":
				control.setLabel("None")
			else:
				control.setLabel(gameclient)

		elif controlID == CONTROL_BUTTON_EMUCMD:

			# Maybe there is autoconfig support
			preconfiguredEmulator = None
			emulatorPath = ''
			dialog = xbmcgui.Dialog()

			if self.selectedRomCollection.name == 'Linux' \
			or self.selectedRomCollection.name == 'Macintosh' \
			or self.selectedRomCollection.name == 'Windows':
				emulatorPath = self.editTextProperty(CONTROL_BUTTON_EMUCMD, util.localize(32624))
			else:
				autoconfig = EmulatorAutoconfig(util.getEmuAutoConfigPath())

				emulist = []

				log.info(u"Running on {0}. Trying to find emulator per autoconfig.".format(self.current_os))
				emulators = autoconfig.findEmulators(self.current_os, self.selectedRomCollection.name, True)

				for emulator in emulators:
					if emulator.isInstalled:
						emulist.append(util.localize(32202) % emulator.name)
					else:
						emulist.append(emulator.name)

				# Ask the user which emulator they want
				if len(emulist) > 0:
					emuIndex = dialog.select(util.localize(32203), emulist)
					try:
						if(emuIndex >= 0):
							preconfiguredEmulator = emulators[emuIndex]
					except IndexError:
						log.info("No Emulator selected.")
						preconfiguredEmulator = None

				if preconfiguredEmulator:
					emulatorPath = preconfiguredEmulator.emuCmd
					self.selectedRomCollection.emulatorParams = preconfiguredEmulator.emuParams
					control = self.getControlById(CONTROL_BUTTON_PARAMS)
					control.setLabel(self.selectedRomCollection.emulatorParams)
				else:
					emulatorPath = dialog.browse(1, '%s ' % self.selectedRomCollection.name + util.localize(32139), 'files')
					if emulatorPath == '':
						return

			self.selectedRomCollection.emulatorCmd = emulatorPath
			control = self.getControlById(CONTROL_BUTTON_EMUCMD)
			control.setLabel(emulatorPath)

		elif controlID == CONTROL_BUTTON_PARAMS:
			emulatorParams = self.editTextProperty(CONTROL_BUTTON_PARAMS, util.localize(32625))
			self.selectedRomCollection.emulatorParams = emulatorParams

		elif controlID == CONTROL_BUTTON_ROMPATH:
			self.editRomPath()

		elif controlID == CONTROL_BUTTON_FILEMASK:
			self.editRomFileMask()

		elif controlID == CONTROL_BUTTON_MEDIAPATH:
			self.editMediaPath()

		elif controlID == CONTROL_BUTTON_MEDIAFILEMASK:
			self.editMediaFileMask()

		elif controlID == CONTROL_BUTTON_ADDMEDIAPATH:
			self.addMediaPath()

		elif controlID == CONTROL_BUTTON_REMOVEMEDIAPATH:
			self.removeMediaPath()

		elif controlID == CONTROL_BUTTON_MAXFOLDERDEPTH:
			maxFolderDepth = self.editTextProperty(CONTROL_BUTTON_MAXFOLDERDEPTH, util.localize(32610))
			self.selectedRomCollection.maxFolderDepth = maxFolderDepth

		elif controlID == CONTROL_BUTTON_DISKINDICATOR:
			diskIndicator = self.editTextProperty(CONTROL_BUTTON_DISKINDICATOR, util.localize(32611))
			self.selectedRomCollection.diskPrefix = diskIndicator

		elif controlID == CONTROL_BUTTON_SAVESTATEPATH:
			saveStatePathComplete = self.editPathWithFileMask(CONTROL_BUTTON_SAVESTATEPATH, '%s ' % self.selectedRomCollection.name + util.localize(32629), CONTROL_BUTTON_SAVESTATEMASK)
			if saveStatePathComplete != '':
				self.selectedRomCollection.saveStatePath = saveStatePathComplete

		elif controlID == CONTROL_BUTTON_SAVESTATEMASK:
			self.selectedRomCollection.saveStatePath = self.editFilemask(CONTROL_BUTTON_SAVESTATEMASK, util.localize(32630), self.selectedRomCollection.saveStatePath)

		elif controlID == CONTROL_BUTTON_SAVESTATEPARAMS:
			saveStateParams = self.editTextProperty(CONTROL_BUTTON_SAVESTATEPARAMS, util.localize(32631))
			self.selectedRomCollection.saveStateParams = saveStateParams

		elif controlID == CONTROL_BUTTON_PRECMD:
			preCmd = self.editTextProperty(CONTROL_BUTTON_PRECMD, util.localize(32632))
			self.selectedRomCollection.preCmd = preCmd
			log.info("OnClick: precmd = {0}".format(self.selectedRomCollection.preCmd))

		elif controlID == CONTROL_BUTTON_POSTCMD:
			postCmd = self.editTextProperty(CONTROL_BUTTON_POSTCMD, util.localize(32633))
			self.selectedRomCollection.postCmd = postCmd
	def onClick(self, controlID):
		
		Logutil.log('onClick', util.LOG_LEVEL_INFO)
		
		if (controlID == CONTROL_BUTTON_EXIT): # Close window button
			Logutil.log('close', util.LOG_LEVEL_INFO)
			self.close()
		#OK
		elif (controlID == CONTROL_BUTTON_SAVE):
			Logutil.log('save', util.LOG_LEVEL_INFO)
			#store selectedRomCollection
			if(self.selectedRomCollection != None):
				self.updateSelectedRomCollection()
				self.romCollections[self.selectedRomCollection.id] = self.selectedRomCollection
						
			configWriter = ConfigXmlWriter(False)
			success, message = configWriter.writeRomCollections(self.romCollections, True)
			
			if not success:
				xbmcgui.Dialog().ok(util.localize(32021), message)
			self.close()
			
		#Cancel
		elif (controlID == CONTROL_BUTTON_CANCEL):
			self.close()
		#Rom Collection list
		elif(self.selectedControlId in (CONTROL_BUTTON_RC_DOWN, CONTROL_BUTTON_RC_UP)):
			if(self.selectedRomCollection != None):
				#save current values to selected Rom Collection
				self.updateSelectedRomCollection()
				#store previous selectedRomCollections state
				self.romCollections[self.selectedRomCollection.id] = self.selectedRomCollection
			
			#HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
			xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
			self.updateRomCollectionControls()
		
		#Media Path
		elif(self.selectedControlId in (CONTROL_BUTTON_MEDIA_DOWN, CONTROL_BUTTON_MEDIA_UP)):
			#HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
			xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
			self.updateMediaPathControls()
			
			
		elif (controlID == CONTROL_BUTTON_GAMECLIENT):
			success, gameclient = helper.selectlibretrocore(self.selectedRomCollection.name)
			if success:
				self.selectedRomCollection.gameclient = gameclient
						
			control = self.getControlById(CONTROL_BUTTON_GAMECLIENT)
			if(gameclient == ""):			
				control.setLabel("None")
			else:
				control.setLabel(gameclient)
			
		elif (controlID == CONTROL_BUTTON_EMUCMD):
			
			#maybe there is autoconfig support
			preconfiguredEmulator = None
			emulatorPath = ''
			dialog = xbmcgui.Dialog()
			
			if (self.selectedRomCollection.name == 'Linux' or self.selectedRomCollection.name == 'Macintosh' or self.selectedRomCollection.name == 'Windows'):
				emulatorPath = self.editTextProperty(CONTROL_BUTTON_EMUCMD, util.localize(32624))
			else:
				if(xbmc.getCondVisibility('System.Platform.Android')):
					
					autoconfig = EmulatorAutoconfig(util.getEmuAutoConfigPath())
					
					Logutil.log('Running on Android. Trying to find emulator per autoconfig.', util.LOG_LEVEL_INFO)
					emulators = autoconfig.findEmulators('Android', self.selectedRomCollection.name, True)
					emulist = []
					if(emulators):
						for emulator in emulators:
							if(emulator.isInstalled):
								emulist.append(util.localize(32202) %emulator.name)
							else:
								emulist.append(emulator.name)
					if(len(emulist) > 0):
						emuIndex = dialog.select(util.localize(32203), emulist)
						Logutil.log('emuIndex: ' +str(emuIndex), util.LOG_LEVEL_INFO)
						if(emuIndex == -1):
							Logutil.log('No Emulator selected.', util.LOG_LEVEL_INFO)
						else:
							preconfiguredEmulator = emulators[emuIndex]
						
				if(preconfiguredEmulator):
					emulatorPath = preconfiguredEmulator.emuCmd					
					self.selectedRomCollection.emulatorParams = preconfiguredEmulator.emuParams
					control = self.getControlById(CONTROL_BUTTON_PARAMS)
					control.setLabel(self.selectedRomCollection.emulatorParams)
				else:										
					emulatorPath = dialog.browse(1, '%s ' %self.selectedRomCollection.name +util.localize(32139), 'files')
					if(emulatorPath == ''):
						return
							
			self.selectedRomCollection.emulatorCmd = emulatorPath
			control = self.getControlById(CONTROL_BUTTON_EMUCMD)
			control.setLabel(emulatorPath)
			
		elif (controlID == CONTROL_BUTTON_PARAMS):
			emulatorParams = self.editTextProperty(CONTROL_BUTTON_PARAMS, util.localize(32625))
			self.selectedRomCollection.emulatorParams = emulatorParams
			
		elif (controlID == CONTROL_BUTTON_ROMPATH):
			self.editRomPath()
			
		elif (controlID == CONTROL_BUTTON_FILEMASK):
			self.editRomFileMask()
			
		elif (controlID == CONTROL_BUTTON_MEDIAPATH):
			self.editMediaPath()
		
		elif (controlID == CONTROL_BUTTON_MEDIAFILEMASK):
			self.editMediaFileMask()
		
		elif (controlID == CONTROL_BUTTON_ADDMEDIAPATH):
			self.addMediaPath()
			
		elif (controlID == CONTROL_BUTTON_REMOVEMEDIAPATH):
			self.removeMediaPath()
			
		elif (controlID == CONTROL_BUTTON_MAXFOLDERDEPTH):
			maxFolderDepth = self.editTextProperty(CONTROL_BUTTON_MAXFOLDERDEPTH, util.localize(32610))
			self.selectedRomCollection.maxFolderDepth = maxFolderDepth
			
		elif (controlID == CONTROL_BUTTON_DISKINDICATOR):
			diskIndicator = self.editTextProperty(CONTROL_BUTTON_DISKINDICATOR, util.localize(32611))
			self.selectedRomCollection.diskPrefix = diskIndicator
						
		elif (controlID == CONTROL_BUTTON_SAVESTATEPATH):
			saveStatePathComplete = self.editPathWithFileMask(CONTROL_BUTTON_SAVESTATEPATH, '%s ' %self.selectedRomCollection.name +util.localize(32629), CONTROL_BUTTON_SAVESTATEMASK)
			if(saveStatePathComplete != ''):
				self.selectedRomCollection.saveStatePath = saveStatePathComplete
				
		elif (controlID == CONTROL_BUTTON_SAVESTATEMASK):
			self.selectedRomCollection.saveStatePath = self.editFilemask(CONTROL_BUTTON_SAVESTATEMASK, util.localize(32630), self.selectedRomCollection.saveStatePath)
			
		elif (controlID == CONTROL_BUTTON_SAVESTATEPARAMS):
			saveStateParams = self.editTextProperty(CONTROL_BUTTON_SAVESTATEPARAMS, util.localize(32631))
			self.selectedRomCollection.saveStateParams = saveStateParams
		
		elif (controlID == CONTROL_BUTTON_PRECMD):
			preCmd = self.editTextProperty(CONTROL_BUTTON_PRECMD, util.localize(32632))
			self.selectedRomCollection.preCmd = preCmd
			Logutil.log('OnClick: precmd = ' +self.selectedRomCollection.preCmd, util.LOG_LEVEL_INFO)
			
			
		elif (controlID == CONTROL_BUTTON_POSTCMD):
			postCmd = self.editTextProperty(CONTROL_BUTTON_POSTCMD, util.localize(32633))
			self.selectedRomCollection.postCmd = postCmd
    def onClick(self, controlID):

        Logutil.log('onClick', util.LOG_LEVEL_INFO)

        if (controlID == CONTROL_BUTTON_EXIT):  # Close window button
            Logutil.log('close', util.LOG_LEVEL_INFO)
            self.close()
        #OK
        elif (controlID == CONTROL_BUTTON_SAVE):
            Logutil.log('save', util.LOG_LEVEL_INFO)
            #store selectedRomCollection
            if (self.selectedRomCollection != None):
                self.updateSelectedRomCollection()
                self.romCollections[
                    self.selectedRomCollection.id] = self.selectedRomCollection

            configWriter = ConfigXmlWriter(False)
            success, message = configWriter.writeRomCollections(
                self.romCollections, True)

            if not success:
                xbmcgui.Dialog().ok(util.localize(32021), message)
            self.close()

        #Cancel
        elif (controlID == CONTROL_BUTTON_CANCEL):
            self.close()
        #Rom Collection list
        elif (self.selectedControlId
              in (CONTROL_BUTTON_RC_DOWN, CONTROL_BUTTON_RC_UP)):
            if (self.selectedRomCollection != None):
                #save current values to selected Rom Collection
                self.updateSelectedRomCollection()
                #store previous selectedRomCollections state
                self.romCollections[
                    self.selectedRomCollection.id] = self.selectedRomCollection

            #HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
            xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
            self.updateRomCollectionControls()

        #Media Path
        elif (self.selectedControlId
              in (CONTROL_BUTTON_MEDIA_DOWN, CONTROL_BUTTON_MEDIA_UP)):
            #HACK: add a little wait time as XBMC needs some ms to execute the MoveUp/MoveDown actions from the skin
            xbmc.sleep(util.WAITTIME_UPDATECONTROLS)
            self.updateMediaPathControls()

        elif (controlID == CONTROL_BUTTON_GAMECLIENT):
            success, gameclient = helper.selectlibretrocore(
                self.selectedRomCollection.name)
            if success:
                self.selectedRomCollection.gameclient = gameclient

            control = self.getControlById(CONTROL_BUTTON_GAMECLIENT)
            if (gameclient == ""):
                control.setLabel("None")
            else:
                control.setLabel(gameclient)

        elif (controlID == CONTROL_BUTTON_EMUCMD):

            #maybe there is autoconfig support
            preconfiguredEmulator = None
            emulatorPath = ''
            dialog = xbmcgui.Dialog()

            if (self.selectedRomCollection.name == 'Linux'
                    or self.selectedRomCollection.name == 'Macintosh'
                    or self.selectedRomCollection.name == 'Windows'):
                emulatorPath = self.editTextProperty(CONTROL_BUTTON_EMUCMD,
                                                     util.localize(32624))
            else:
                if (xbmc.getCondVisibility('System.Platform.Android')):

                    autoconfig = EmulatorAutoconfig(
                        util.getEmuAutoConfigPath())

                    Logutil.log(
                        'Running on Android. Trying to find emulator per autoconfig.',
                        util.LOG_LEVEL_INFO)
                    emulators = autoconfig.findEmulators(
                        'Android', self.selectedRomCollection.name, True)
                    emulist = []
                    if (emulators):
                        for emulator in emulators:
                            if (emulator.isInstalled):
                                emulist.append(
                                    util.localize(32202) % emulator.name)
                            else:
                                emulist.append(emulator.name)
                    if (len(emulist) > 0):
                        emuIndex = dialog.select(util.localize(32203), emulist)
                        Logutil.log('emuIndex: ' + str(emuIndex),
                                    util.LOG_LEVEL_INFO)
                        if (emuIndex == -1):
                            Logutil.log('No Emulator selected.',
                                        util.LOG_LEVEL_INFO)
                        else:
                            preconfiguredEmulator = emulators[emuIndex]

                if (preconfiguredEmulator):
                    emulatorPath = preconfiguredEmulator.emuCmd
                    self.selectedRomCollection.emulatorParams = preconfiguredEmulator.emuParams
                    control = self.getControlById(CONTROL_BUTTON_PARAMS)
                    control.setLabel(self.selectedRomCollection.emulatorParams)
                else:
                    emulatorPath = dialog.browse(
                        1, '%s ' % self.selectedRomCollection.name +
                        util.localize(32139), 'files')
                    if (emulatorPath == ''):
                        return

            self.selectedRomCollection.emulatorCmd = emulatorPath
            control = self.getControlById(CONTROL_BUTTON_EMUCMD)
            control.setLabel(emulatorPath)

        elif (controlID == CONTROL_BUTTON_PARAMS):
            emulatorParams = self.editTextProperty(CONTROL_BUTTON_PARAMS,
                                                   util.localize(32625))
            self.selectedRomCollection.emulatorParams = emulatorParams

        elif (controlID == CONTROL_BUTTON_ROMPATH):
            self.editRomPath()

        elif (controlID == CONTROL_BUTTON_FILEMASK):
            self.editRomFileMask()

        elif (controlID == CONTROL_BUTTON_MEDIAPATH):
            self.editMediaPath()

        elif (controlID == CONTROL_BUTTON_MEDIAFILEMASK):
            self.editMediaFileMask()

        elif (controlID == CONTROL_BUTTON_ADDMEDIAPATH):
            self.addMediaPath()

        elif (controlID == CONTROL_BUTTON_REMOVEMEDIAPATH):
            self.removeMediaPath()

        elif (controlID == CONTROL_BUTTON_MAXFOLDERDEPTH):
            maxFolderDepth = self.editTextProperty(
                CONTROL_BUTTON_MAXFOLDERDEPTH, util.localize(32610))
            self.selectedRomCollection.maxFolderDepth = maxFolderDepth

        elif (controlID == CONTROL_BUTTON_DISKINDICATOR):
            diskIndicator = self.editTextProperty(CONTROL_BUTTON_DISKINDICATOR,
                                                  util.localize(32611))
            self.selectedRomCollection.diskPrefix = diskIndicator

        elif (controlID == CONTROL_BUTTON_SAVESTATEPATH):
            saveStatePathComplete = self.editPathWithFileMask(
                CONTROL_BUTTON_SAVESTATEPATH,
                '%s ' % self.selectedRomCollection.name + util.localize(32629),
                CONTROL_BUTTON_SAVESTATEMASK)
            if (saveStatePathComplete != ''):
                self.selectedRomCollection.saveStatePath = saveStatePathComplete

        elif (controlID == CONTROL_BUTTON_SAVESTATEMASK):
            self.selectedRomCollection.saveStatePath = self.editFilemask(
                CONTROL_BUTTON_SAVESTATEMASK, util.localize(32630),
                self.selectedRomCollection.saveStatePath)

        elif (controlID == CONTROL_BUTTON_SAVESTATEPARAMS):
            saveStateParams = self.editTextProperty(
                CONTROL_BUTTON_SAVESTATEPARAMS, util.localize(32631))
            self.selectedRomCollection.saveStateParams = saveStateParams

        elif (controlID == CONTROL_BUTTON_PRECMD):
            preCmd = self.editTextProperty(CONTROL_BUTTON_PRECMD,
                                           util.localize(32632))
            self.selectedRomCollection.preCmd = preCmd
            Logutil.log(
                'OnClick: precmd = ' + self.selectedRomCollection.preCmd,
                util.LOG_LEVEL_INFO)

        elif (controlID == CONTROL_BUTTON_POSTCMD):
            postCmd = self.editTextProperty(CONTROL_BUTTON_POSTCMD,
                                            util.localize(32633))
            self.selectedRomCollection.postCmd = postCmd