autotimer,pluginsort: allow mphelp localization
[enigma2-plugins.git] / dreamirc / src / plugin.py
1 from enigma import *
2 from Screens.Screen import Screen
3 from Screens.VirtualKeyBoard import VirtualKeyBoard
4
5 from Components.Pixmap import Pixmap
6 from Components.ActionMap import HelpableActionMap, ActionMap, NumberActionMap
7 from Components.ScrollLabel import ScrollLabel
8 from Components.Input import Input
9 from Components.Label import Label
10 from Components.HTMLComponent import *
11 from Components.GUIComponent import *
12 from Plugins.Plugin import PluginDescriptor
13
14 from Tools.NumericalTextInput import *
15 from Tools.Directories import *
16
17 #from socket import socket
18
19 import e2reactor
20
21 from twisted.internet import reactor
22 from twisted.internet import protocol
23 from twisted.python import log
24 from twisted.internet.defer import *
25
26 from e2chat import *
27 from e2account import *
28 from e2support import *
29 from dreamIRCTools import *
30 from dreamIRCSetup import *
31 from protocols import irc
32 import ircsupport
33
34 import os 
35 import string
36 import time
37 import datetime
38 import sys
39 x=0
40 y=0
41
42 class dreamIRCMainMenu(Screen):
43
44         from enigma import getDesktop
45         desk = getDesktop(0)
46         global x,y
47         x= int(desk.size().width())
48         y= int(desk.size().height())
49         print "[dreamIRC] mainscreen: current desktop size: %dx%d" % (x,y)
50
51         if (y>=720):
52                 skin = """
53                         <screen position="80,80" size="1120,600"  title="dreamIRC" >
54                                 <widget name="buddy" position="940,35" size="170,450" font="Regular;14" />
55                                 <widget name="chat" position="10,35" size="920,460" font="Regular;14" />
56                                 <widget name="input" position="10,550" size="830,20" font="Regular;16" />
57                                 <widget name="chat.desc" position="10,10" size="460,20" font="Regular;16" />
58                                 <widget name="buddy.desc" position="940,10" size="120,20" font="Regular;16" />
59                                 <widget name="input.desc" position="10,520" size="360,18" font="Regular;16" />
60                                 <widget name="red.pic" position="910,511" size="15,15" pixmap="skin_default/buttons/button_red.png" transparent="1" alphatest="on"/>
61                                 <widget name="green.pic" position="910,531" size="15,15" pixmap="skin_default/buttons/button_green.png" transparent="1" alphatest="on"/>
62                                 <widget name="yellow.pic" position="910,551" size="15,15" pixmap="skin_default/buttons/button_yellow.png" transparent="1" alphatest="on"/>
63                                 <widget name="blue.pic" position="910,571" size="15,15" pixmap="skin_default/buttons/button_blue.png" transparent="1" alphatest="on"/>
64                                 <widget name="disconnect.desc" position="940,510" size="110,20" font="Regular;16" />
65                                 <widget name="connect.desc" position="940,530" size="110,20" font="Regular;16" />
66                                 <widget name="settings.desc" position="940,550" size="110,20" font="Regular;16" />
67                                 <widget name="blue.desc" position="940,570" size="180,20" font="Regular;16" />                                
68                         </screen>"""
69         else:   
70                 skin = """
71                         <screen position="60,80" size="600,450"  title="dreamIRC" >
72                                 <widget name="buddy" position="480,35" size="120,310" font="Regular;14" />
73                                 <widget name="chat" position="10,35" size="460,310" font="Regular;14" />
74                                 <widget name="input" position="10,400" size="360,20" font="Regular;16" />
75                                 <widget name="chat.desc" position="10,10" size="460,20" font="Regular;16" />
76                                 <widget name="buddy.desc" position="480,10" size="120,20" font="Regular;16" />
77                                 <widget name="input.desc" position="10,370" size="360,18" font="Regular;16" />
78                                 <widget name="red.pic" position="470,362" size="15,15" pixmap="skin_default/buttons/button_red.png" transparent="1" alphatest="on"/>
79                                 <widget name="green.pic" position="470,382" size="15,15" pixmap="skin_default/buttons/button_green.png" transparent="1" alphatest="on"/>
80                                 <widget name="yellow.pic" position="470,402" size="15,15" pixmap="skin_default/buttons/button_yellow.png" transparent="1" alphatest="on"/>
81                                 <widget name="blue.pic" position="470,422" size="15,15" pixmap="skin_default/buttons/button_blue.png" transparent="1" alphatest="on"/>
82                                 <widget name="disconnect.desc" position="490,360" size="110,20" font="Regular;16" />
83                                 <widget name="connect.desc" position="490,380" size="110,20" font="Regular;16" />
84                                 <widget name="settings.desc" position="490,400" size="110,20" font="Regular;16" />
85                                 <widget name="blue.desc" position="490,420" size="110,20" font="Regular;16" />
86                         </screen>"""
87                 
88         
89         def __init__(self, session, args = 0):
90                 global x,y
91                 self.skin = dreamIRCMainMenu.skin
92                 Screen.__init__(self, session)
93
94                 self.menu = args
95                 self.pipe=MessagePipe()
96                 self.account = AccountManager(self.session)
97
98                 self.list = []
99                 self.menuList = []
100                 
101                 self.connected = False
102
103                 self["buddy"] = BuddyWindow("")
104                 self["chat"] = ChatWindow("")
105                 self["input"] = Input("")
106
107                 self["buddy.desc"] = Label(_("User Online"))
108                 self["input.desc"] = Label(_("Type your text here and press OK to send:"))
109                 self["chat.desc"] = ChanName(_("ChatBox"))
110                 self["connect.desc"] = Label(_("Connect"))
111                 self["disconnect.desc"] = Label(_("Disconnect"))
112                 self["settings.desc"] = Label(_("Settings"))
113                 if y>=720:
114                                 self["blue.desc"] = Label(_("virtual Keyboard"))
115                 else:
116                                 self["blue.desc"] = Label(_("virtual Keyb."))                           
117                 self["green.pic"] = Pixmap()
118                 self["red.pic"] = Pixmap()
119                 self["yellow.pic"] = Pixmap()
120                 self["blue.pic"] = Pixmap()
121                 
122                 self["actions"] = NumberActionMap(["dreamIRCActions", "InputBoxActions", "InputAsciiActions", "KeyboardInputActions"],
123                 {
124                         "gotAsciiCode": self.gotAsciiCode,
125                         "red": self.redPressed,
126                         "green": self.greenPressed,
127                         "yellow": self.yellowPressed,
128                         "blue": self.bluePressed,
129                         "ok": self.go,
130                         "cancel": self.closePlugin,
131                         "back": self.closePlugin,
132                         "right": self.keyRight,
133                         "left": self.keyLeft,
134                         "up": self["chat"].pageUp,
135                         "down": self["chat"].pageDown,
136                         "buddyUp": self["buddy"].pageUp,
137                         "buddyDown": self["buddy"].pageDown,
138                         "home": self.keyHome,                
139                         "end": self.keyEnd,
140                         "delete": self.keyDelete,
141                         "deleteForward": self.keyDeleteForward,
142                         "deleteBackward": self.keyDeleteBackward,
143                         "tab": self.keyTab,
144                         "1": self.keyNumberGlobal,
145                         "2": self.keyNumberGlobal,
146                         "3": self.keyNumberGlobal,
147                         "4": self.keyNumberGlobal,
148                         "5": self.keyNumberGlobal,
149                         "6": self.keyNumberGlobal,
150                         "7": self.keyNumberGlobal,
151                         "8": self.keyNumberGlobal,
152                         "9": self.keyNumberGlobal,
153                         "0": self.keyNumberGlobal            
154                 }, -1)
155                 rcinput = eRCInput.getInstance()
156                 rcinput.setKeyboardMode(rcinput.kmAscii)
157                 
158                 self.checkStatus()
159
160         def gotAsciiCode(self):
161                 self["input"].handleAscii(getPrevAsciiCode())
162         
163         def keyUp(self):
164                 self["input"].up()
165         
166         def keyDown(self):
167                 self["input"].down()
168         
169         def keyLeft(self):
170                 self["input"].left()
171         
172         def keyRight(self):
173                 self["input"].right()
174         
175         def keyTab(self):
176                 self["input"].tab()
177         
178         def keyHome(self):
179                 self["input"].home()
180         
181         def keyEnd(self):
182                 self["input"].end()
183
184         def keyNumberGlobal(self, number):
185                 print "You pressed number " + str(number)
186                 self["input"].number(number)
187                 
188         def keyDelete(self):
189                 self["input"].delete()
190         
191         def keyDeleteForward(self):
192                 self["input"].delete()
193         
194         def keyDeleteBackward(self):
195                 self["input"].left()
196                 self["input"].delete()
197                 
198         def closePlugin(self):
199                 rcinput = eRCInput.getInstance()
200                 rcinput.setKeyboardMode(rcinput.kmNone)
201                 self.close(None)
202                 
203         def greenPressed(self):
204                 if self.checkStatus()==0:
205                         self.pipe.add("connecting... pls wait...")
206                         self.account = AccountManager(self.session)    #reload accounts :)
207                         self.account.startConnect()
208                         self["disconnect.desc"].show()
209                         self["red.pic"].show()
210
211         def redPressed(self):
212                 if self.checkStatus()==1:
213                         self.pipe.add("disconnecting... pls wait...")
214                         self.pipe.addOutText("/QUIT")
215                         try:
216                                 timestamp = time.strftime("%Y%m%d_%H%M%S", time.localtime(time.time()))
217                                 fp = file("/var/log/dreamIRC.log", 'r')
218                                 fp.close()
219                                 os.rename("/var/log/dreamIRC.log", "/var/log/dreamIRC_%s.log"%timestamp)
220                         except IOError:
221                                 print "--- nothing to remove---"
222                         self.pipe.clear()
223                         self.pipe.add(" -- not connected.. pls press green to connect!!\n")
224                         self.pipe.clearBuddyList()
225                         self.pipe.resetDesc()
226                         self["disconnect.desc"].hide()
227                         self["red.pic"].hide()
228
229         def checkStatus(self):
230                 status = self.account.getConnectionInfo()
231                 if status[0]==1 or len(self["buddy"].getText())>1:
232                         self["disconnect.desc"].show()
233                         self["red.pic"].show()
234                         status[0]=1
235                 elif status[0]==0:
236                         self["disconnect.desc"].hide()
237                         self["red.pic"].hide()
238                 return status[0]
239         
240         def bluePressed(self):
241                 self.checkStatus()
242                 self.session.openWithCallback(self.VirtualKeyBoardTextEntry, VirtualKeyBoard, title = (_("Enter your text here:")), text = "")
243                 
244         def yellowPressed(self):
245                 self.checkStatus()
246                 self.session.openWithCallback(self.resetKeyboard,dreamIRCSetupScreen)
247                 
248         def resetKeyboard(self):
249                 rcinput = eRCInput.getInstance()
250                 rcinput.setKeyboardMode(rcinput.kmAscii)
251                 
252         def go(self):
253                 if self.checkStatus()==1:
254 #                       self.pipe.debug(" TEXT = %s   - laenge = %d  !!!!" % (self["input"].getText(),len(self["input"].getText())))
255                         if (len(self["input"].getText()) >= 1):
256                                 self.pipe.addOutText(self["input"].getText())
257                                 self.clearInput()
258                         
259         def clearInput(self):
260                 self["input"].setText("")
261                         
262         def VirtualKeyBoardTextEntry(self, callback = None):
263                 if callback is not None and len(callback):
264                         print " TEXT = %s   - laenge = %d  !!!!" % (callback,len(callback))
265                         self.pipe.addOutText(callback)
266
267 def main(session, **kwargs):
268         session.open(dreamIRCMainMenu)
269
270 def Plugins(**kwargs):
271         return PluginDescriptor(
272                 name="dreamIRC",
273                 description="dreamIRC Client for Enigma2",
274                 icon="plugin.png",
275                 where=[ PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_PLUGINMENU ],
276                 fnc=main)