Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/control
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/control	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/control	(revision 8763)
@@ -0,0 +1,11 @@
+Package: enigma2-plugin-swapepg-epgrefresh
+Version: 2.6
+Description: Plugin to refresh EPG Data when Reciever is inactive for Swapstick
+Section: infos
+Priority: optional
+Maintainer: AAF Forum
+Architecture: sh4
+OE: Plugin to refresh EPG Data when Reciever is inactive for Swapstick
+Homepage: http://www.aaf-digital.info
+Depends:
+Source: http://www.aaf-digital.info
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/postinst
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/postinst	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/postinst	(revision 8763)
@@ -0,0 +1,7 @@
+#!/bin/sh
+TMP=/tmp/.epg
+echo "successfully installed"
+echo "syncing disk"
+echo "please reboot your box so that the extension will be mounted..."
+sync
+exit 0
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/postrm
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/postrm	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/postrm	(revision 8763)
@@ -0,0 +1,9 @@
+#!/bin/sh
+TMP=/tmp/.epg
+
+rm -rf /var/swap/extensions/EPGRefresh
+
+echo "successfully removed"
+echo "syncing disk"
+sync
+exit 0
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/preinst
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/preinst	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/preinst	(revision 8763)
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+TMP=/tmp/.epg
+echo "syncing disk"
+sync
+
+model=`cat /etc/model`
+echo""
+echo "Checking your Boxtype...."
+echo "Some Plugins will not work correctly on your $model!"
+echo ""
+if [ "$model" = "" ]; then
+	echo "Sorry! This Plugin is not available for your $model because it will not work correctly!!!"
+	echo "Aborting installation..."
+	exit 1
+else
+	echo "Boxtype: $model OK"
+fi
+
+echo "checking swapstick"
+if [ ! -d /var/swap/extensions/ ]; then
+  echo "--------------------------"
+	echo "no swapstick found...."
+	echo "--------------------------"
+	exit 1
+fi
+echo "swapstick found...."
+echo "installing EPG Refresh Plugin to swapstick..."
+echo "checking OS"
+if  [ `cat /etc/motd | grep AAF | grep M | grep rev | wc -l` -eq 0 ]; then                      
+	echo ---------------------------
+	echo DONT USE this IPK Package!!
+	echo ---
+	echo Only for AAF Image!!
+	echo ---------------------------
+	exit 1
+fi
+exit 0
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/prerm
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/prerm	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/CONTROL/prerm	(revision 8763)
@@ -0,0 +1,6 @@
+#!/bin/sh
+TMP=/tmp/.epg
+echo "syncing disk"
+sync
+echo "removing EPG Refresh from swapstick"
+exit 0
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefresh.py
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefresh.py	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefresh.py	(revision 8763)
@@ -0,0 +1,324 @@
+# -*- coding: UTF-8 -*-
+# To check if in Standby
+import Screens.Standby
+
+# eServiceReference
+from enigma import eServiceReference, eServiceCenter
+
+# ...
+from ServiceReference import ServiceReference
+
+# Timer
+from EPGRefreshTimer import epgrefreshtimer, EPGRefreshTimerEntry, checkTimespan
+
+# To calculate next timer execution
+from time import time
+
+# Plugin Config
+from xml.etree.cElementTree import parse as cet_parse
+from Tools.XMLTools import stringToXML
+from os import path as path
+
+# We want a list of unique services
+from EPGRefreshService import EPGRefreshService
+
+# Configuration
+from Components.config import config
+
+# Path to configuration
+CONFIG = "/etc/enigma2/epgrefresh.xml"
+
+class EPGRefresh:
+	"""Simple Class to refresh EPGData"""
+
+	def __init__(self):
+		# Initialize
+		self.services = (set(), set())
+		self.previousService = None
+		self.forcedScan = False
+		self.session = None
+		self.beginOfTimespan = 0
+
+		# Mtime of configuration files
+		self.configMtime = -1
+
+		# Read in Configuration
+		self.readConfiguration()
+
+	def readConfiguration(self):
+		# Check if file exists
+		if not path.exists(CONFIG):
+			return
+
+		# Check if file did not change
+		mtime = path.getmtime(CONFIG)
+		if mtime == self.configMtime:
+			return
+
+		# Keep mtime
+		self.configMtime = mtime
+
+		# Empty out list
+		self.services[0].clear()
+		self.services[1].clear()
+
+		# Open file
+		configuration= cet_parse(CONFIG).getroot()
+
+		# Add References
+		for service in configuration.findall("service"):
+			value = service.text
+			if value:
+				# strip all after last : (custom name)
+				pos = value.rfind(':')
+				if pos != -1:
+					value = value[:pos+1]
+
+				duration = service.get('duration', None)
+				duration = duration and int(duration)
+
+				self.services[0].add(EPGRefreshService(value, duration))
+		for bouquet in configuration.findall("bouquet"):
+			value = bouquet.text
+			if value:
+				duration = bouquet.get('duration', None)
+				duration = duration and int(duration)
+				self.services[1].add(EPGRefreshService(value, duration))
+
+	def buildConfiguration(self):
+		list = ['<?xml version="1.0" ?>\n<epgrefresh>\n\n']
+
+		for service in self.services[0]:
+			ref = ServiceReference(service.sref)
+			list.extend([' <!-- ', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), ' -->\n'])
+			list.append(' <service')
+			if service.duration is not None:
+				list.extend([' duration="', str(service.duration), '"'])
+			list.extend(['>', stringToXML(service.sref), '</service>\n'])
+		for bouquet in self.services[1]:
+			ref = ServiceReference(bouquet.sref)
+			list.extend([' <!-- ', stringToXML(ref.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')), ' -->\n'])
+			list.append(' <bouquet')
+			if bouquet.duration is not None:
+				list.extend([' duration="', str(bouquet.duration), '"'])
+			list.extend(['>', stringToXML(bouquet.sref), '</bouquet>\n'])
+
+		list.append('\n</epgrefresh>')
+
+		return list
+
+	def saveConfiguration(self):
+		file = open(CONFIG, 'w')
+		file.writelines(self.buildConfiguration())
+
+		file.close()
+
+	def forceRefresh(self, session = None):
+		print "[EPGRefresh] Forcing start of EPGRefresh"
+		if self.session is None:
+			if session is not None:
+				self.session = session
+			else:
+				return False
+
+		self.forcedScan = True
+		self.prepareRefresh()
+		return True
+
+	def start(self, session = None):
+		if session is not None:
+			self.session = session
+
+		epgrefreshtimer.setRefreshTimer(self.createWaitTimer)
+
+	def stop(self):
+		print "[EPGRefresh] Stopping Timer"
+		epgrefreshtimer.clear()
+
+	def prepareRefresh(self):
+		print "[EPGRefresh] About to start refreshing EPG"
+
+		# Keep service
+		self.previousService =  self.session.nav.getCurrentlyPlayingServiceReference()
+
+		# Maybe read in configuration
+		try:
+			self.readConfiguration()
+		except Exception, e:
+			print "[EPGRefresh] Error occured while reading in configuration:", e
+
+		# This will hold services which are not explicitely in our list
+		additionalServices = []
+		additionalBouquets = []
+
+		# See if we are supposed to read in autotimer services
+		if config.plugins.epgrefresh.inherit_autotimer.value:
+			removeInstance = False
+			try:
+				# Import Instance
+				from Plugins.Extensions.AutoTimer.plugin import autotimer
+
+				if autotimer is None:
+					removeInstance = True
+					# Create an instance
+					from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer
+					autotimer = AutoTimer()
+
+				# Read in configuration
+				autotimer.readXml()
+			except Exception, e:
+				print "[EPGRefresh] Could not inherit AutoTimer Services:", e
+			else:
+				# Fetch services
+				for timer in autotimer.getEnabledTimerList():
+					additionalServices.extend([EPGRefreshService(x, None) for x in timer.services])
+					additionalBouquets.extend([EPGRefreshService(x, None) for x in timer.bouquets])
+			finally:
+				# Remove instance if there wasn't one before
+				if removeInstance:
+					autotimer = None
+
+		serviceHandler = eServiceCenter.getInstance()
+		for bouquet in self.services[1].union(additionalBouquets):
+			myref = eServiceReference(bouquet.sref)
+			list = serviceHandler.list(myref)
+			if list is not None:
+				while 1:
+					s = list.getNext()
+					# TODO: I wonder if its sane to assume we get services here (and not just new lists)
+					if s.valid():
+						additionalServices.append(EPGRefreshService(s.toString(), None))
+					else:
+						break
+		del additionalBouquets[:]
+
+		scanServices = []
+		channelIdList = []
+		for scanservice in self.services[0].union(additionalServices):
+			service = eServiceReference(scanservice.sref)
+			if not service.valid() \
+				or (service.flags & (eServiceReference.isMarker|eServiceReference.isDirectory)):
+
+				continue
+
+			channelID = '%08x%04x%04x' % (
+				service.getUnsignedData(4), # NAMESPACE
+				service.getUnsignedData(2), # TSID
+				service.getUnsignedData(3), # ONID
+			)
+
+			if channelID not in channelIdList:
+				scanServices.append(scanservice)
+				channelIdList.append(channelID)
+		del additionalServices[:]
+
+		# Debug
+		#print "[EPGRefresh] Services we're going to scan:", ', '.join([repr(x) for x in scanServices])
+
+		self.scanServices = scanServices
+		self.refresh()
+
+	def cleanUp(self):
+		config.plugins.epgrefresh.lastscan.value = int(time())
+		config.plugins.epgrefresh.lastscan.save()
+
+		# Eventually force autotimer to parse epg
+		if config.plugins.epgrefresh.parse_autotimer.value:
+			removeInstance = False
+			try:
+				# Import Instance
+				from Plugins.Extensions.AutoTimer.plugin import autotimer
+
+				if autotimer is None:
+					removeInstance = True
+					# Create an instance
+					from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer
+					autotimer = AutoTimer()
+
+				# Parse EPG
+				autotimer.parseEPG()
+			except Exception, e:
+				print "[EPGRefresh] Could not start AutoTimer:", e
+			finally:
+				# Remove instance if there wasn't one before
+				if removeInstance:
+					autotimer = None
+
+		# shutdown if we're supposed to go to deepstandby and not recording
+		if not self.forcedScan and config.plugins.epgrefresh.afterevent.value \
+			and not Screens.Standby.inTryQuitMainloop:
+
+			self.session.open(
+				Screens.Standby.TryQuitMainloop,
+				1
+			)
+
+		self.forcedScan = False
+		epgrefreshtimer.cleanup()
+
+		# Zap back
+		if self.previousService is not None or Screens.Standby.inStandby:
+			self.session.nav.playService(self.previousService)
+
+	def refresh(self):
+		if self.forcedScan:
+			self.nextService()
+		else:
+			# Abort if a scan finished later than our begin of timespan
+			if self.beginOfTimespan < config.plugins.epgrefresh.lastscan.value:
+				return
+			if config.plugins.epgrefresh.force.value \
+				or (Screens.Standby.inStandby and \
+					not self.session.nav.RecordTimer.isRecording()):
+
+				self.nextService()
+			# We don't follow our rules here - If the Box is still in Standby and not recording we won't reach this line
+			else:
+				if not checkTimespan(
+					config.plugins.epgrefresh.begin.value,
+					config.plugins.epgrefresh.end.value):
+
+					print "[EPGRefresh] Gone out of timespan while refreshing, sorry!"
+					self.cleanUp()
+				else:
+					print "[EPGRefresh] Box no longer in Standby or Recording started, rescheduling"
+
+					# Recheck later
+					epgrefreshtimer.add(EPGRefreshTimerEntry(
+							time() + config.plugins.epgrefresh.delay_standby.value*60,
+							self.refresh,
+							nocheck = True)
+					)
+
+	def createWaitTimer(self):
+		self.beginOfTimespan = time()
+
+		# Add wait timer to epgrefreshtimer
+		epgrefreshtimer.add(EPGRefreshTimerEntry(time() + 30, self.prepareRefresh))
+
+	def nextService(self):
+		# Debug
+		print "[EPGRefresh] Maybe zap to next service"
+
+		try:
+			# Get next reference
+			service = self.scanServices.pop(0)
+		except IndexError:
+			# Debug
+			print "[EPGRefresh] Done refreshing EPG"
+
+			# Clean up
+			self.cleanUp()
+		else:
+			# Play next service
+			self.session.nav.playService(eServiceReference(service.sref))
+
+			# Start Timer
+			delay = service.duration or config.plugins.epgrefresh.interval.value
+			epgrefreshtimer.add(EPGRefreshTimerEntry(
+				time() + delay*60,
+				self.refresh,
+				nocheck = True)
+			)
+
+epgrefresh = EPGRefresh()
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshChannelEditor.py
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshChannelEditor.py	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshChannelEditor.py	(revision 8763)
@@ -0,0 +1,232 @@
+# -*- coding: UTF-8 -*-
+# for localized messages
+from . import _
+
+# GUI (Screens)
+from Screens.Screen import Screen
+from Components.ConfigList import ConfigListScreen
+from Screens.ChannelSelection import SimpleChannelSelection
+
+# GUI (Summary)
+from Screens.Setup import SetupSummary
+
+# GUI (Components)
+from Components.ActionMap import ActionMap
+from Components.Button import Button
+
+# Configuration
+from Components.config import getConfigListEntry, ConfigSelection, \
+	NoSave
+
+from EPGRefreshService import EPGRefreshService
+
+# Show ServiceName instead of ServiceReference
+from ServiceReference import ServiceReference
+
+from enigma import getDesktop
+
+class SimpleBouquetSelection(SimpleChannelSelection):
+	def __init__(self, session, title):
+		SimpleChannelSelection.__init__(self, session, title)
+		self.skinName = "SimpleChannelSelection"
+
+	def channelSelected(self): # just return selected service
+		ref = self.getCurrentSelection()
+		if (ref.flags & 7) == 7:
+			self.close(ref)
+		else:
+			# We return the currently active path here
+			# Asking the user if this is what he wants might be better though
+			self.close(self.servicePath[-1])
+
+class EPGRefreshServiceEditor(Screen, ConfigListScreen):
+	"""Edit Services to be refreshed by EPGRefresh"""
+
+	skin = """<screen name="EPGRefreshServiceEditor" title="Edit Services to refresh" position="75,150" size="565,245">
+		<widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
+		<ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+		<ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+		<ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+		<ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+		<widget name="key_red" position="5,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_green" position="145,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_yellow" position="285,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_blue" position="425,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+	</screen>"""
+	
+	skinKS = """<screen name="EPGRefreshServiceEditor" title="Edit Services to refresh" position="230,150" size="565,245">
+		<widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
+		<ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+		<ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+		<ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+		<ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+		<widget name="key_red" position="5,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_green" position="145,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_yellow" position="285,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_blue" position="425,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+	</screen>"""
+	
+	skinHD = """<screen name="EPGRefreshServiceEditor" title="Edit Services to refresh" position="358,220" size="565,245">
+		<widget name="config" position="5,5" size="555,200" scrollbarMode="showOnDemand" />
+		<ePixmap position="5,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+		<ePixmap position="145,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+		<ePixmap position="285,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+		<ePixmap position="425,205" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+		<widget name="key_red" position="5,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_green" position="145,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_yellow" position="285,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_blue" position="425,205" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+	</screen>"""
+
+	def __init__(self, session, services):
+		try:
+			skin_w = getDesktop(0).size().width()
+			print "DESKTOPsize is",skin_w
+			if skin_w == 1280:
+				self.skin = EPGRefreshServiceEditor.skinHD
+			elif skin_w == 1024:
+				self.skin = EPGRefreshServiceEditor.skinKS
+			else:
+				self.skin = EPGRefreshServiceEditor.skin
+		except:
+			print "DESKTOPsize not detected"
+			self.skin = EPGRefreshServiceEditor.skin
+		Screen.__init__(self, session)
+
+		# Summary
+		self.setup_title = _("EPGRefresh Services")
+		self.onChangedEntry = []
+
+		# We need to copy the list to be able to ignore changes
+		self.services = (
+			services[0][:],
+			services[1][:]
+		)
+
+		self.typeSelection = NoSave(ConfigSelection(choices = [
+			("channels", _("Channels")),
+			("bouquets", _("Bouquets"))]
+		))
+		self.typeSelection.addNotifier(self.refresh, initial_call = False)
+
+		self.reloadList()
+
+		ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
+
+		# Initialize Buttons
+		self["key_red"] = Button(_("Cancel"))
+		self["key_green"] = Button(_("OK"))
+		self["key_yellow"] = Button(_("delete"))
+		self["key_blue"] = Button(_("New"))
+
+		# Define Actions
+		self["actions"] = ActionMap(["SetupActions", "ColorActions"],
+			{
+				"cancel": self.cancel,
+				"save": self.save,
+				"yellow": self.removeService,
+				"blue": self.newService
+			}
+		)
+
+		# Trigger change
+		self.changed()
+
+		self.onLayoutFinish.append(self.setCustomTitle)
+
+	def setCustomTitle(self):
+		self.setTitle(_("Edit Services to refresh"))
+
+	def saveCurrent(self):
+		del self.services[self.idx][:]
+
+		# Warning, accessing a ConfigListEntry directly might be considered evil!
+
+		myl = self["config"].getList()
+		myl.pop(0)
+		for item in myl:
+			self.services[self.idx].append(item[1].value)
+
+	def refresh(self, value):
+		self.saveCurrent()
+
+		self.reloadList()
+		self["config"].setList(self.list)
+
+	def reloadList(self):
+		self.list = [
+			getConfigListEntry(_("Editing"), self.typeSelection)
+		]
+
+		if self.typeSelection.value == "channels":
+			self.idx = 0
+		else: # self.typeSelection.value == "bouquets":
+			self.idx = 1
+
+		self.list.extend([
+			getConfigListEntry(_("Refreshing"), NoSave(ConfigSelection(choices = [(x, ServiceReference(x.sref).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''))])))
+				for x in self.services[self.idx]
+		])
+
+	def changed(self):
+		for x in self.onChangedEntry:
+			try:
+				x()
+			except Exception:
+				pass
+
+	def getCurrentEntry(self):
+		cur = self["config"].getCurrent()
+		if cur:
+			return cur[0]
+		return ""
+
+	def getCurrentValue(self):
+		cur = self["config"].getCurrent()
+		if cur:
+			return str(cur[1].getText())
+		return ""
+
+	def createSummary(self):
+		return SetupSummary
+
+	def removeService(self):
+		cur = self["config"].getCurrent()
+		if cur:
+			list = self["config"].getList()
+			list.remove(cur)
+			self["config"].setList(list)
+
+	def newService(self):
+		if self.typeSelection.value == "channels":
+			self.session.openWithCallback(
+				self.finishedServiceSelection,
+				SimpleChannelSelection,
+				_("Select channel to refresh")
+			)
+		else: # self.typeSelection.value == "bouquets":
+			self.session.openWithCallback(
+				self.finishedServiceSelection,
+				SimpleBouquetSelection,
+				_("Select bouquet to refresh")
+			)
+
+	def finishedServiceSelection(self, *args):
+		if args:
+			list = self["config"].getList()
+			list.append(getConfigListEntry(
+				_("Refreshing"),
+				NoSave(ConfigSelection(choices = [(
+					EPGRefreshService(str(args[0].toString()), None),
+					ServiceReference(args[0]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')
+				)]))
+			))
+			self["config"].setList(list)
+
+	def cancel(self):
+		self.close(None)
+
+	def save(self):
+		self.saveCurrent()
+
+		self.close(self.services)
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshConfiguration.py
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshConfiguration.py	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshConfiguration.py	(revision 8763)
@@ -0,0 +1,185 @@
+# for localized messages
+from . import _
+
+# GUI (Screens)
+from Screens.Screen import Screen
+from Components.ConfigList import ConfigListScreen
+from EPGRefreshChannelEditor import EPGRefreshServiceEditor
+
+# GUI (Summary)
+from Screens.Setup import SetupSummary
+
+# GUI (Components)
+from Components.ActionMap import ActionMap
+from Components.Button import Button
+
+# Configuration
+from Components.config import config, getConfigListEntry
+
+from EPGRefresh import epgrefresh
+
+from enigma import getDesktop
+
+class EPGRefreshConfiguration(Screen, ConfigListScreen):
+	"""Configuration of EPGRefresh"""
+
+	skin = """<screen name="EPGRefreshConfiguration" title="Configure EPGRefresh" position="75,155" size="565,280">
+		<widget name="config" position="5,5" size="555,225" scrollbarMode="showOnDemand" />
+		<ePixmap position="0,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+		<ePixmap position="140,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+		<ePixmap position="280,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+		<ePixmap position="420,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+		<widget name="key_red" position="0,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_green" position="140,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_yellow" position="280,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_blue" position="420,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+	</screen>"""
+	
+	skinKS = """<screen name="EPGRefreshConfiguration" title="Configure EPGRefresh" position="230,155" size="565,280">
+		<widget name="config" position="5,5" size="555,225" scrollbarMode="showOnDemand" />
+		<ePixmap position="0,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+		<ePixmap position="140,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+		<ePixmap position="280,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+		<ePixmap position="420,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+		<widget name="key_red" position="0,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_green" position="140,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_yellow" position="280,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_blue" position="420,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+	</screen>"""
+	
+	skinHD = """<screen name="EPGRefreshConfiguration" title="Configure EPGRefresh" position="358,220" size="565,280">
+		<widget name="config" position="5,5" size="555,225" scrollbarMode="showOnDemand" />
+		<ePixmap position="0,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+		<ePixmap position="140,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+		<ePixmap position="280,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+		<ePixmap position="420,235" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+		<widget name="key_red" position="0,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_green" position="140,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_yellow" position="280,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+		<widget name="key_blue" position="420,235" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
+	</screen>"""
+
+	def __init__(self, session):
+		try:
+			skin_w = getDesktop(0).size().width()
+			print "DESKTOPsize is",skin_w
+			if skin_w == 1280:
+				self.skin = EPGRefreshConfiguration.skinHD
+			elif skin_w == 1024:
+				self.skin = EPGRefreshConfiguration.skinKS
+			else:
+				self.skin = EPGRefreshConfiguration.skin
+		except:
+			print "DESKTOPsize not detected"
+			self.skin = EPGRefreshConfiguration.skin
+		Screen.__init__(self, session)
+
+		# Summary
+		self.setup_title = _("EPGRefresh Configuration")
+		self.onChangedEntry = []
+
+		# Although EPGRefresh keeps services in a Set we prefer a list
+		self.services = (
+			[x for x in epgrefresh.services[0]],
+			[x for x in epgrefresh.services[1]]
+		)
+
+		self.list = [
+			getConfigListEntry(_("Refresh automatically"), config.plugins.epgrefresh.enabled),
+			getConfigListEntry(_("Wakeup from Deep-Standby to refresh EPG"), config.plugins.epgrefresh.wakeup),
+			getConfigListEntry(_("Time to stay on service (in m)"), config.plugins.epgrefresh.interval),
+			getConfigListEntry(_("Refresh EPG after"), config.plugins.epgrefresh.begin),
+			getConfigListEntry(_("Refresh EPG before"), config.plugins.epgrefresh.end),
+			getConfigListEntry(_("Delay when not in Standby (in m)"), config.plugins.epgrefresh.delay_standby),
+			getConfigListEntry(_("Force scan even if reciever is in use"), config.plugins.epgrefresh.force),
+			getConfigListEntry(_("Inherit Services from AutoTimer if available"), config.plugins.epgrefresh.inherit_autotimer),
+			getConfigListEntry(_("Make AutoTimer parse EPG if available"), config.plugins.epgrefresh.parse_autotimer),
+			getConfigListEntry(_("Shutdown after refresh"), config.plugins.epgrefresh.afterevent),
+		]
+
+		ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
+
+		# Initialize Buttons
+		self["key_red"] = Button(_("Cancel"))
+		self["key_green"] = Button(_("OK"))
+		self["key_yellow"] = Button(_("Refresh now"))
+		self["key_blue"] = Button(_("Edit Services"))
+
+		# Define Actions
+		self["actions"] = ActionMap(["SetupActions", "ColorActions"],
+			{
+				"cancel": self.keyCancel,
+				"save": self.keySave,
+				"yellow": self.forceRefresh,
+				"blue": self.editServices
+			}
+		)
+
+		# Trigger change
+		self.changed()
+
+		self.onLayoutFinish.append(self.setCustomTitle)
+
+	def setCustomTitle(self):
+		self.setTitle(_("Configure EPGRefresh"))
+
+	def forceRefresh(self):
+		epgrefresh.services = (set(self.services[0]), set(self.services[1]))
+		epgrefresh.forceRefresh(self.session)
+
+	def editServices(self):
+		self.session.openWithCallback(
+			self.editServicesCallback,
+			EPGRefreshServiceEditor,
+			self.services
+		)
+
+	def editServicesCallback(self, ret):
+		if ret:
+			self.services = ret
+
+	def changed(self):
+		for x in self.onChangedEntry:
+			try:
+				x()
+			except Exception:
+				pass
+
+	def getCurrentEntry(self):
+		return self["config"].getCurrent()[0]
+
+	def getCurrentValue(self):
+		return str(self["config"].getCurrent()[1].getText())
+
+	def createSummary(self):
+		return SetupSummary
+
+	def cancelConfirm(self, result):
+		if not result:
+			return
+
+		for x in self["config"].list:
+			x[1].cancel()
+
+		self.close(self.session)
+
+	def keyCancel(self):
+		if self["config"].isChanged():
+			from Screens.MessageBox import MessageBox
+
+			self.session.openWithCallback(
+				self.cancelConfirm,
+				MessageBox,
+				_("Really close without saving settings?")
+			)
+		else:
+			self.close(self.session)
+
+	def keySave(self):
+		epgrefresh.services = (set(self.services[0]), set(self.services[1]))
+		epgrefresh.saveConfiguration()
+
+		for x in self["config"].list:
+			x[1].save()
+
+		self.close(self.session)
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshResource.py
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshResource.py	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshResource.py	(revision 8763)
@@ -0,0 +1,118 @@
+from twisted.web import http, resource
+from EPGRefresh import epgrefresh
+from EPGRefreshService import EPGRefreshService
+from enigma import eServiceReference
+
+class EPGRefreshStartRefreshResource(resource.Resource):
+	def render(self, req):
+		state = False
+
+		if epgrefresh.forceRefresh():
+			output = "initiated refresh"
+			state = True
+		else:
+			output = "could not initiate refresh"
+
+		req.setResponseCode(http.OK)
+		req.setHeader('Content-type', 'application; xhtml+xml')
+		req.setHeader('charset', 'UTF-8')
+
+		return """<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
+			<e2simplexmlresult>
+				<e2state>%s</e2state>
+				<e2statetext>%s</e2statetext>
+			</e2simplexmlresult>
+			""" % ('true' if state else 'false', output)
+
+class EPGRefreshAddRemoveServiceResource(resource.Resource):
+	TYPE_ADD = 0
+	TYPE_DEL = 1
+
+	def __init__(self, type):
+		assert(type in (self.TYPE_ADD, self.TYPE_DEL))
+		self.type = type
+
+	def render(self, req):
+		do_add = self.type == self.TYPE_ADD
+		state = False
+
+		if 'sref' in req.args:
+			sref = req.args["sref"][0]
+			if do_add:
+				# strip all after last : (custom name)
+				pos = sref.rfind(':')
+				if pos != -1:
+					sref = sref[:pos+1]
+
+			duration = req.args.get("duration", None)
+			try:
+				duration = duration and int(duration)
+			except ValueError, ve:
+				output = 'invalid value for "duration": ' + str(duration)
+			else:
+				epgservice = EPGRefreshService(sref, duration)
+
+				if sref:
+					ref = eServiceReference(str(sref))
+					if not ref.valid():
+						output = 'invalid value for "sref": ' + str(sref)
+					elif (ref.flags & 7) == 7:
+						# bouquet
+						if epgservice in epgrefresh.services[1]:
+							if do_add:
+								output = "bouquet already in list"
+							else:
+								epgrefresh.services[1].remove(epgservice)
+								output = "bouquet removed from list"
+								state = True
+						else:
+							if do_add:
+								epgrefresh.services[1].add(epgservice)
+								output = "bouquet added to list"
+								state = True
+							else:
+								output = "bouquet not in list"
+					else:
+						# assume service
+						if epgservice in epgrefresh.services[0]:
+							if do_add:
+								output = "service already in list"
+							else:
+								epgrefresh.services[0].remove(epgservice)
+								output = "service removed from list"
+								state = True
+						else:
+							if do_add:
+								epgrefresh.services[0].add(epgservice)
+								output = "service added to list"
+								state = True
+							else:
+								output = "service not in list"
+
+					# save if list changed
+					if state:
+						epgrefresh.saveConfiguration()
+				else:
+					output = 'invalid value for "sref": ' + str(sref)
+		else:
+			output = 'missing argument "sref"'
+
+		req.setResponseCode(http.OK)
+		req.setHeader('Content-type', 'application; xhtml+xml')
+		req.setHeader('charset', 'UTF-8')
+		
+		return """<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
+			<e2simplexmlresult>
+				<e2state>%s</e2state>
+				<e2statetext>%s</e2statetext>
+			</e2simplexmlresult>
+			""" % ('true' if state else 'false', output)
+
+class EPGRefreshListServicesResource(resource.Resource):
+	def render(self, req):
+		# show xml
+		req.setResponseCode(http.OK)
+		req.setHeader('Content-type', 'application; xhtml+xml')
+		req.setHeader('charset', 'UTF-8')
+		return ''.join(epgrefresh.buildConfiguration())
+
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshService.py
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshService.py	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshService.py	(revision 8763)
@@ -0,0 +1,25 @@
+class EPGRefreshService(object):
+	def __init__(self, sref, duration):
+		self.sref = str(sref)
+		self.duration = duration
+
+	def __eq__(self, other):
+		if hasattr(other, 'sref'):
+			return self.sref == other.sref
+		return False
+
+	def __hash__(self):
+		return self.sref.__hash__()
+
+	def __str__(self):
+		return self.sref
+
+	def __repr__(self):
+		return ''.join((
+			'<EPGRefreshService (',
+			', '.join((
+				self.sref,
+				str(self.duration or '?'),
+			)),
+			')>'
+		))
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshTimer.py
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshTimer.py	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/EPGRefreshTimer.py	(revision 8763)
@@ -0,0 +1,165 @@
+# To check if in Standby
+import Screens.Standby
+
+# Base Class
+import timer
+
+# To see if in Timespan and to determine begin of timespan
+from time import localtime, mktime, time, strftime
+
+# Config
+from Components.config import config
+
+def checkTimespan(begin, end):
+	# Get current time
+	time = localtime()
+
+	# Check if we span a day
+	if begin[0] > end[0] or (begin[0] == end[0] and begin[1] >= end[1]):
+		# Check if begin of event is later than our timespan starts
+		if time.tm_hour > begin[0] or (time.tm_hour == begin[0] and time.tm_min >= begin[1]):
+			# If so, event is in our timespan
+			return True
+		# Check if begin of event is earlier than our timespan end
+		if time.tm_hour < end[0] or (time.tm_hour == end[0] and time.tm_min <= end[1]):
+			# If so, event is in our timespan
+			return True
+		return False
+	else:
+		# Check if event begins earlier than our timespan starts
+		if time.tm_hour < begin[0] or (time.tm_hour == begin[0] and time.tm_min < begin[1]):
+			# Its out of our timespan then
+			return False
+		# Check if event begins later than our timespan ends
+		if time.tm_hour > end[0] or (time.tm_hour == end[0] and time.tm_min > end[1]):
+			# Its out of our timespan then
+			return False
+		return True
+
+class EPGRefreshTimerEntry(timer.TimerEntry):
+	"""TimerEntry ..."""
+	def __init__(self, begin, tocall, nocheck = False):
+		timer.TimerEntry.__init__(self, int(begin), int(begin))
+
+		self.function = tocall
+		self.nocheck = nocheck
+		if nocheck:
+			self.state = self.StatePrepared
+
+	def getNextActivation(self):
+		# We delay our activation so we won't rush into reprocessing a repeating one
+		return self.begin+1
+
+	def activate(self):
+		if self.state == self.StateWaiting:
+			# Check if in timespan
+			if checkTimespan(config.plugins.epgrefresh.begin.value, config.plugins.epgrefresh.end.value):
+				print "[EPGRefresh] In Timespan, will check if we're in Standby and have no Recordings running next"
+				# Do we realy want to check nav?
+				from NavigationInstance import instance
+				if config.plugins.epgrefresh.force.value or (Screens.Standby.inStandby and instance is not None and not instance.RecordTimer.isRecording()):
+					return True
+				else:
+					print "[EPGRefresh] Box still in use, rescheduling"
+
+					# Recheck later
+					self.begin = time() + config.plugins.epgrefresh.delay_standby.value*60
+					return False
+			else:
+				print "[EPGRefresh] Not in timespan, ending timer"
+				self.state = self.StateEnded
+				return False
+		elif self.state == self.StateRunning:
+			self.function()
+
+		return True
+
+	def resetState(self):
+		self.state = self.StateWaiting
+		self.cancelled = False
+		self.timeChanged()
+
+	def timeChanged(self):
+		if self.nocheck and self.state < self.StateRunning:
+			self.state = self.StatePrepared
+
+	def shouldSkip(self):
+		return False
+
+	def __repr__(self):
+		return ''.join((
+				"<EPGRefreshTimerEntry (",
+				', '.join((
+					strftime("%c", localtime(self.begin)),
+					str(self.repeated),
+					str(self.function)
+				)),
+				")>"
+			))
+
+class EPGRefreshTimer(timer.Timer):
+	def __init__(self):
+		timer.Timer.__init__(self)
+
+	def remove(self, entry):
+		print "[EPGRefresh] Timer removed " + str(entry)
+
+		# avoid re-enqueuing
+		entry.repeated = False
+
+		# abort timer.
+		# this sets the end time to current time, so timer will be stopped.
+		entry.abort()
+
+		if entry.state != entry.StateEnded:
+			self.timeChanged(entry)
+
+		print "state: ", entry.state
+		print "in processed: ", entry in self.processed_timers
+		print "in running: ", entry in self.timer_list
+		# now the timer should be in the processed_timers list. remove it from there.
+		self.processed_timers.remove(entry)
+
+	def setRefreshTimer(self, tocall):
+		# Add refresh Timer
+		now = localtime()
+		# XXX: basic workaround if the clock is not yet set
+		year = 2009
+		if now.tm_year > 2009:
+			year = now.tm_year
+		begin = mktime(
+			(year, now.tm_mon, now.tm_mday,
+			config.plugins.epgrefresh.begin.value[0],
+			config.plugins.epgrefresh.begin.value[1],
+			0, now.tm_wday, now.tm_yday, now.tm_isdst)
+		)
+
+		# If the last scan was finished before our timespan begins/began and
+		# timespan began in the past fire the timer once (timer wouldn't do so
+		# by itself)
+		if config.plugins.epgrefresh.lastscan.value < begin and begin < time():
+			tocall()
+
+		refreshTimer = EPGRefreshTimerEntry(begin, tocall, nocheck = True)
+
+		i = 0
+		while i < 7:
+			refreshTimer.setRepeated(i)
+			i += 1
+
+		# We can be sure that whenever this function is called the timer list
+		# was wiped, so just add a new timer
+		self.addTimerEntry(refreshTimer)
+
+	def add(self, entry):
+		entry.timeChanged()
+		print "[EPGRefresh] Timer added " + str(entry)
+		self.addTimerEntry(entry)
+
+	def clear(self):
+		self.timer_list = []
+
+	def isActive(self):
+		return len(self.timer_list) > 0
+
+epgrefreshtimer = EPGRefreshTimer()
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/LICENSE
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/LICENSE	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/LICENSE	(revision 8763)
@@ -0,0 +1,12 @@
+All Files of this Software are licensed under the Creative Commons 
+Attribution-NonCommercial-ShareAlike 3.0 Unported 
+License if not stated otherwise in a Files Head. To view a copy of this license, visit
+http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
+Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
+
+Alternatively, this plugin may be distributed and executed on hardware which
+is licensed by Dream Multimedia GmbH.
+
+This plugin is NOT free software. It is open source, you are allowed to
+modify it (if you keep the license), but it may not be commercially 
+distributed other than under the conditions noted above.
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/__init__.py
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/__init__.py	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/__init__.py	(revision 8763)
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+from Components.Language import language
+from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
+from os import environ as os_environ
+import gettext
+
+def localeInit():
+	lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
+	os_environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
+	gettext.bindtextdomain("EPGRefresh", resolveFilename(SCOPE_PLUGINS, "Extensions/EPGRefresh/locale"))
+
+def _(txt):
+	t = gettext.dgettext("EPGRefresh", txt)
+	if t == txt:
+		print "[EPGRefresh] fallback to default translation for", txt
+		t = gettext.gettext(txt)
+	return t
+
+localeInit()
+language.addCallback(localeInit)
+
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/maintainer.info
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/maintainer.info	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/maintainer.info	(revision 8763)
@@ -0,0 +1,2 @@
+moritz.venn@freaque.net
+EPGRefresh
Index: /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/plugin.py
===================================================================
--- /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/plugin.py	(revision 8763)
+++ /ipk/source.sh4/swapepg_epgrefresh_2_6/var/swap/extensions/EPGRefresh/plugin.py	(revision 8763)
@@ -0,0 +1,148 @@
+# for localized messages
+from . import _
+
+# Config
+from Components.config import config, ConfigYesNo, ConfigNumber, \
+	ConfigSubsection, ConfigClock
+
+# Calculate default begin/end
+from time import time, localtime, mktime
+now = localtime()
+begin = mktime((
+	now.tm_year, now.tm_mon, now.tm_mday, 20, 15, \
+	0, now.tm_wday, now.tm_yday, now.tm_isdst)
+)
+end = mktime((
+	now.tm_year, now.tm_mon, now.tm_mday, 06, 30, \
+	0, now.tm_wday, now.tm_yday, now.tm_isdst)
+)
+
+config.plugins.epgrefresh = ConfigSubsection()
+config.plugins.epgrefresh.enabled = ConfigYesNo(default = False)
+config.plugins.epgrefresh.begin = ConfigClock(default = int(begin))
+config.plugins.epgrefresh.end = ConfigClock(default = int(end))
+config.plugins.epgrefresh.interval = ConfigNumber(default = 2)
+config.plugins.epgrefresh.delay_standby = ConfigNumber(default = 10)
+config.plugins.epgrefresh.inherit_autotimer = ConfigYesNo(default = False)
+config.plugins.epgrefresh.afterevent = ConfigYesNo(default = False)
+config.plugins.epgrefresh.force = ConfigYesNo(default = False)
+config.plugins.epgrefresh.wakeup = ConfigYesNo(default = False)
+config.plugins.epgrefresh.lastscan = ConfigNumber(default = 0)
+config.plugins.epgrefresh.parse_autotimer = ConfigYesNo(default = False)
+
+del now, begin, end
+
+# Plugin
+from EPGRefresh import epgrefresh
+from EPGRefreshConfiguration import EPGRefreshConfiguration
+from EPGRefreshService import EPGRefreshService
+
+# Plugin definition
+from Plugins.Plugin import PluginDescriptor
+
+def standbyQuestionCallback(session, res = None):
+	if res:
+		from Screens.Standby import Standby
+		session.open(Standby)
+
+# Autostart
+def autostart(reason, **kwargs):
+	if reason == 0 and kwargs.has_key("session"):
+		session = kwargs["session"]
+		epgrefresh.session = session
+
+		if config.plugins.epgrefresh.enabled.value:
+			if config.plugins.epgrefresh.wakeup.value:
+				now = localtime()
+				begin = int(mktime(
+					(now.tm_year, now.tm_mon, now.tm_mday,
+					config.plugins.epgrefresh.begin.value[0],
+					config.plugins.epgrefresh.begin.value[1],
+					0, now.tm_wday, now.tm_yday, now.tm_isdst)
+				))
+				# booted +- 10min from begin of timespan
+				if abs(time() - begin) < 600:
+					from Screens.MessageBox import MessageBox
+					from Tools.Notifications import AddNotificationWithCallback
+					from Tools.BoundFunction import boundFunction
+					# XXX: we use a notification because this will be suppressed otherwise
+					AddNotificationWithCallback(
+						boundFunction(standbyQuestionCallback, session),
+						MessageBox,
+						_("This might have been an automated bootup to refresh the EPG. For this to happen it is recommmended to put the receiver to Standby.\nDo you want to do this now?"),
+						timeout = 15
+					)
+
+			epgrefresh.start(session)
+
+	elif reason == 1:
+		epgrefresh.stop()
+
+def getNextWakeup():
+	# Return invalid time if not automatically refreshing
+	if not config.plugins.epgrefresh.enabled.value or \
+		not config.plugins.epgrefresh.wakeup.value:
+
+		return -1
+
+	now = localtime()
+	begin = int(mktime(
+		(now.tm_year, now.tm_mon, now.tm_mday,
+		config.plugins.epgrefresh.begin.value[0],
+		config.plugins.epgrefresh.begin.value[1],
+		0, now.tm_wday, now.tm_yday, now.tm_isdst)
+	))
+	# todays timespan has not yet begun
+	if begin > time():
+		return begin
+	# otherwise add 1 day
+	return begin+86400
+
+# Mainfunction
+def main(session, **kwargs):
+	epgrefresh.stop()
+	session.openWithCallback(
+		doneConfiguring,
+		EPGRefreshConfiguration
+	)
+
+def doneConfiguring(session, **kwargs):
+	if config.plugins.epgrefresh.enabled.value:
+		epgrefresh.start(session)
+
+# Eventinfo
+def eventinfo(session, servicelist, **kwargs):
+	ref = session.nav.getCurrentlyPlayingServiceReference()
+	if not ref:
+		return
+	sref = ref.toString()
+	# strip all after last :
+	pos = sref.rfind(':')
+	if pos != -1:
+		sref = sref[:pos+1]
+
+	epgrefresh.services[0].add(EPGRefreshService(str(sref), None))
+
+def Plugins(**kwargs):
+	return [
+		PluginDescriptor(
+			name = "EPGRefresh",
+			where = [
+				PluginDescriptor.WHERE_AUTOSTART,
+				PluginDescriptor.WHERE_SESSIONSTART
+			],
+			fnc = autostart,
+			wakeupfnc = getNextWakeup
+		),
+		PluginDescriptor(
+			name = "EPGRefresh",
+			description = _("Automated EPGRefresher"),
+			where = PluginDescriptor.WHERE_PLUGINMENU,
+			fnc = main
+		),
+		PluginDescriptor(
+			name = _("Add to EPGRefresh"),
+			where = PluginDescriptor.WHERE_EVENTINFO,
+			fnc = eventinfo
+		),
+	]
