New:
[enigma2-plugins.git] / partnerbox / src / PartnerboxEPGSelection.py
1
2 #  Partnerbox E2
3 #
4 #  $Id$
5 #
6 #  Coded by Dr.Best (c) 2009
7 #  Support: www.dreambox-tools.info
8 #
9 #  This program is free software; you can redistribute it and/or
10 #  modify it under the terms of the GNU General Public License
11 #  as published by the Free Software Foundation; either version 2
12 #  of the License, or (at your option) any later version.
13 #
14 #  This program is distributed in the hope that it will be useful,
15 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #  GNU General Public License for more details.
18 #
19
20 from Screens.Screen import Screen
21 from Screens.MessageBox import MessageBox
22 from Components.config import config
23 from PartnerboxSetup import PartnerboxEntriesListConfigScreen
24 from Screens.EpgSelection import EPGSelection
25 from Tools.BoundFunction import boundFunction
26 from PartnerboxFunctions import  SetPartnerboxTimerlist, isInTimerList, sendPartnerBoxWebCommand
27 import PartnerboxFunctions as partnerboxfunctions
28
29 baseEPGSelection__init__ = None
30 baseEPGSelection_zapTo = None
31 baseonSelectionChanged = None
32 basetimerAdd = None
33 basefinishedAdd = None
34
35 def Partnerbox_EPGSelectionInit():
36         global baseEPGSelection__init__, baseEPGSelection_zapTo, baseonSelectionChanged, basetimerAdd, basefinishedAdd
37         if baseEPGSelection__init__ is None:
38                 baseEPGSelection__init__ = EPGSelection.__init__
39         if baseEPGSelection_zapTo is None:
40                 baseEPGSelection_zapTo = EPGSelection.zapTo
41         if baseonSelectionChanged is None:
42                 baseonSelectionChanged = EPGSelection.onSelectionChanged
43         if basetimerAdd is None:
44                 basetimerAdd = EPGSelection.timerAdd
45         if basefinishedAdd is None:
46                 basefinishedAdd = EPGSelection.finishedAdd
47         if partnerboxfunctions.remote_timer_list is None:
48                 partnerboxfunctions.remote_timer_list = []
49         EPGSelection.__init__ = Partnerbox_EPGSelection__init__
50         EPGSelection.zapTo = Partnerbox_EPGSelection_zapTo
51         EPGSelection.onSelectionChanged = Partnerbox_onSelectionChanged
52         EPGSelection.timerAdd = Partnerbox_timerAdd
53         EPGSelection.finishedAdd = Partnerbox_finishedAdd
54
55
56 def Partnerbox_EPGSelection__init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None, serviceChangeCB=None):
57
58         if int(config.plugins.Partnerbox.entriescount.value) >= 1:
59                 try: self.partnerboxentry = config.plugins.Partnerbox.Entries[0]
60                 except: self.partnerboxentry = None
61         baseEPGSelection__init__(self, session, service, zapFunc, eventid, bouquetChangeCB, serviceChangeCB)
62         try:self["key_red"].setText(config.plugins.Partnerbox.Entries[0].name.value)
63         except: pass
64         
65
66 def Partnerbox_EPGSelection_zapTo(self): # just used in multiepg
67         if not (self.zapFunc and self.key_red_choice == self.ZAP):
68                 self.session.openWithCallback(boundFunction(NewPartnerBoxSelected,self), PartnerboxEntriesListConfigScreen, 0)
69         else:
70                 baseEPGSelection_zapTo(self)
71
72 def NewPartnerBoxSelected(self, session, what, partnerboxentry = None):
73         if partnerboxentry is not None:
74                 self.partnerboxentry = partnerboxentry
75                 SetPartnerboxTimerlist(partnerboxentry)
76                 Partnerbox_onSelectionChanged(self)
77                 self["key_red"].setText(partnerboxentry.name.value)
78                 self["list"].l.invalidate()
79
80 def Partnerbox_onSelectionChanged(self):
81         baseonSelectionChanged(self)
82         CheckRemoteTimer(self)
83
84 def Partnerbox_timerAdd(self):
85         proceed = True
86         if self.key_green_choice == self.REMOVE_TIMER:
87                 cur = self["list"].getCurrent()
88                 event = cur[0]
89                 serviceref = cur[1]
90                 if event is not None:
91                         timerentry = isInTimerList(event.getBeginTime(), event.getDuration(),serviceref.ref.toString(), event.getEventId(), partnerboxfunctions.remote_timer_list)
92                         if timerentry is not None:
93                                 proceed = False
94                                 if int(self.partnerboxentry.enigma.value) == 0:
95                                         name = timerentry.name
96                                 else:
97                                         name = timerentry.description
98                                 self.session.openWithCallback(boundFunction(DeleteTimerConfirmed,self, timerentry), MessageBox, _("Do you really want to delete the timer \n%s ?") % name)
99         if proceed:basetimerAdd(self)
100
101 def Partnerbox_finishedAdd(self, answer):
102         basefinishedAdd(self,answer)
103         CheckRemoteTimer(self)
104
105 def CheckRemoteTimer(self):
106         if self.key_green_choice != self.REMOVE_TIMER:
107                 cur = self["list"].getCurrent()
108                 if cur is None:
109                         return
110                 event = cur[0]
111                 serviceref = cur[1]
112                 if event is not None:
113                         timerentry = isInTimerList(event.getBeginTime(), event.getDuration(),serviceref.ref.toString(),event.getEventId(), partnerboxfunctions.remote_timer_list)
114                         if timerentry is not None:
115                                 self["key_green"].setText(_("Remove timer"))
116                                 self.key_green_choice = self.REMOVE_TIMER
117
118 def DeleteTimerConfirmed (self, timerentry, answer):
119         if answer:
120                 ip = "%d.%d.%d.%d" % tuple(self.partnerboxentry.ip.value)
121                 port = self.partnerboxentry.port.value
122                 http = "http://%s:%d" % (ip,port)
123                 if int(self.partnerboxentry.enigma.value) == 0:
124                         sCommand = http + "/web/timerdelete?sRef=" + timerentry.servicereference + "&begin=" + ("%s"%(timerentry.timebegin)) + "&end=" +("%s"%(timerentry.timeend))
125                 else:
126                         sCommand = http + "/deleteTimerEvent?ref=" + timerentry.servicereference + "&start=" + ("%s"%(timerentry.timebegin)) + "&type=" +("%s"%(timerentry.type)) + "&force=yes"
127                 sendPartnerBoxWebCommand(sCommand, None,3, "root", self.partnerboxentry.password.value).addCallback(boundFunction(DeleteTimerCallback,self)).addErrback(boundFunction(DeleteTimerCallbackError,self))
128
129 def DeleteTimerCallback(self, callback = None):
130         SetPartnerboxTimerlist(self.partnerboxentry)
131         Partnerbox_onSelectionChanged(self)
132         self["list"].l.invalidate()
133
134 def DeleteTimerCallbackError(self, error = None):
135         if error is not None:
136                 self.session.open(MessageBox, str(error.getErrorMessage()),MessageBox.TYPE_INFO)
137