# MobLRC PyS60 Client - Mobile Linux Remote Control PyS60 Client
# Copyright (C) 2006 PoisoneR
# Author: PoisoneR
# License: GPL
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Todo
# smenq proramata edin put i podawa komanda
# return song name and artist
# login password
# volume repeat command some times, w dict-a da ima list i da se izpulnqwat wsi4ki elementi
# start program if it is not
# proper quit
# choose better port than 7777
# log with date from now() function, all print messages to have date
__author__ = "PoisoneR"
__version__ = "0.1.1"
__copyright__ = "(c) 2006 PoisoneR <poisonerbg@gmail.com>"
__projecthome__ = "http://moblrc.sourceforge.net"
# Todo
# reciving current song
# listen sus select, i send ednowremmeno
# shortcut keys
from socket import socket, AF_INET, SOCK_STREAM
import e32
import appuifw
from os import path
PORT = 7777
class client:
def __init__(self):
self.confFile = u'c:\\moblrc.conf'
self.getHost()
def newHost(self):
self.hostname = appuifw.query(u'Type hostname with your MobLRC server', 'text')
self.saveHost()
def connect(self):
if (self.hostname == ''):
self.newHost()
if (self.hostname == u''):
self.newHost()
self.sockobj = socket(AF_INET, SOCK_STREAM)
self.sockobj.connect((self.hostname, PORT))
self.readsocks = [self.sockobj]
self.writesocks = [self.sockobj]
appuifw.note(u'Connected', 'info')
def getHost(self):
if path.exists(self.confFile):
f = open(self.confFile, 'r')
self.hostname = f.readline()
f.close()
else:
return False
if self.hostname == '':
return False
else:
return True
def saveHost(self):
# problem here cant save it
f = open(self.confFile, 'w')
f.write(self.hostname)
f.close()
def loop(self):
done = False
while not done:
#cmd = appuifw.query(u'Type your command', 'text')
cmd = appuifw.popup_menu(self.menu, u'Send command')
cmd = self.commands[cmd]
data = self.send(cmd)
appuifw.note(u'Command sent:' + data, 'info')
if cmd == 'quit':
done = True
break
def send(self, cmd):
self.sockobj.send(cmd)
data = self.sockobj.recv(1024)
return data
def disconnect(self):
self.sockobj.close()
def __del__(self):
self.disconnect()
class amarok:
def __init__(self):
self.prev = ['aV', u'Prev']
self.pause = ['aA', u'Pause']
self.play = ['aP', u'Play']
self.stop = ['aS', u'Stop']
self.next = ['aN', u'Next']
self.mute = ['aM', u'Mute']
self.volUp = ['aU', u'Volume Up']
self.volDown = ['aD', u'Volume DOwn']
self.quit = ['aQ', u'Quit']
class MobLRCApp:
def __init__(self):
self.lock = e32.Ao_lock()
appuifw.app.title = u'MobLRC'
self.text = appuifw.Text()
self.text.style = appuifw.STYLE_BOLD
self.text.color = (0, 64, 204)
self.text.font = u'albi17b'
self.exitFlag = False
self.amarok = amarok()
# can be added fast forward and fast rewind
self.menu = [(u'Control Amarok', ((u'Play [1]', self.handlePlay),
(u'Pause [2]', self.handlePause),
(u'Stop [3]', self.handleStop),
(u'Previous song [4]', self.handlePrev),
(u'Volume Up [5]', self.handleVolUp),
(u'Next song [6]', self.handleNext),
(u'Volume Down [8]', self.handleVolDown),
(u'Mute On/Off[0]', self.handleMute),
(u'Quit', self.handleQuit) )),
(u'Change host', self.handleConnect),
(u'About', self.handleClose),
(u'Exit', self.handleClose)
]
appuifw.app.menu = []
self.amarokApp = appuifw.Text(u'Amarok')
self.kaffeineApp = appuifw.Text(u'Kaffeine')
appuifw.app.set_tabs([u'Amarok', u'Kaffeine'], self.handleTab)
appuifw.app.body = self.amarokApp
self.connect()
def connect(self):
try:
self.client = client()
self.client.connect()
except:
appuifw.note(u'Cannot connect to server. Is it running?', 'info')
# must be error, intstead info
def handleTab(self, index):
global lb
if index == 0:
appuifw.app.body = self.amarokApp
elif index == 1:
appuifw.app.body = self.kaffeineApp
def loop(self):
try:
#self.lock.wait()
while not self.exitFlag:
self.refresh()
self.lock.wait()
finally:
self.handleClose()
def close(self):
appuifw.app.menu = []
appuifw.app.body = None
appuifw.app.exit_key_handler = None
appuifw.app.title = u'Closing...'
def abort(self):
# Exit-key hanler.
self.exitFlag = True
self.lock.signal()
def refresh(self):
#currentItem = self.getCurrentItem()
#appuifw.app.body = appuifw.Listbox(self.list, self.load)
appuifw.app.menu = self.menu
def execCmd(self, cmdlist):
output = self.client.send(cmdlist[0])
appuifw.note(cmdlist[1] + output, 'info')
def handlePrev(self):
self.execCmd(self.amarok.prev)
def handlePlay(self):
self.execCmd(self.amarok.play)
def handlePause(self):
self.execCmd(self.amarok.pause)
def handleStop(self):
self.execCmd(self.amarok.stop)
def handleNext(self):
self.execCmd(self.amarok.next)
def handleMute(self):
self.execCmd(self.amarok.mute)
def handleVolUp(self):
self.execCmd(self.amarok.volUp)
def handleVolDown(self):
self.execCmd(self.amarok.volDown)
def handleQuit(self):
self.execCmd(self.amarok.quit)
def handleClose(self):
self.client.disconnect()
self.close()
self.abort()
appuifw.app.set_exit()
def handleConnect(self):
self.connect()
def handleTest(self):
print u'Test print'
def getCurrentItem(self):
current = appuifw.app.body.current()
return self.list[current]
def getCurrentId(self):
return appuifw.app.body.current()
def main():
app = MobLRCApp()
try:
app.loop()
finally:
app.close()
if __name__ == '__main__':
main()