This is my first time to use python and write a program for Symbian OS 3rd.
Random RingTone is a funny program for me and it's work fine in my N3250.
** Pure Python Program **
Here is the concept and full source code:
In pys60 1.4.1, we can only add a personal ringtone to each contact person.
So... the Basic concept:Code:contact.add_field('personal_ringtone', song)
when that guy call you again next time, then the phone uses the new personal ringtone.HTML Code:When Incoming Call Store the phone number for later use When the call finished Search within the contact list with the stored phone number if not in list ignore else take a random ringtone from E:\Sounds\Simple\ and add to the contact person
How to make it more Random:
We know that if no personal ringtone added to the contact person, the phone uese the default ringtone which is the profile ringtone.
so... we need to add a random ringtone to each contact person at the first time.
New flow:
Now, when any contact person call you, then it uses the new personal ringtone. Funny!!HTML Code:first time setup (only run at first time install) add a random ringtone to each contact personal Same as before: Incoming Call (use the new personal ringtone for that person) Store the phone number for later use when hangup Search within the contact list with the stored phone number if not in list ignore else take a random ringtone from E:\Sounds\Simple\ and add to the contact personal
Full source code share with you:
Code:import appuifw import e32 import telephone import contacts import os import random tele = '' whoid = 0 num = 0 def remove_all_ringtone(): db = contacts.open() idlist = db.keys() for id in idlist: try: contact = db[id] num = contact.find('personal_ringtone')[0].index contact.__delitem__(num) except IndexError: pass def add_all_random_ringtone(): db = contacts.open() idlist = db.keys() filesname = os.listdir('E:\Sounds\Simple') print 'List files' for id in idlist: try: contact = db[id] num = contact.find('personal_ringtone')[0].index except IndexError: num = random.randrange(0, len(filesname)-1) song = u'E:\\Sounds\\Simple\\' + filesname[num].decode('utf-8') contact.add_field('personal_ringtone', song) pass else: pass def handle_ringtone(): print 'handle_ringtone()' try: global whoid whoid = contacts.open().find(tele)[0].id print whoid except IndexError: print 'No record in the Contact DB!' pass else: print 'Have this number: ' + tele contact = contacts.open() print 'Open Contacts' filesname = os.listdir('E:\Sounds\Simple') print 'List files' try: global num num = contact[whoid].find('personal_ringtone')[0].index print 'personal ringtone found!' except IndexError: num = random.randrange(0, len(filesname)-1) song = u'E:\\Sounds\\Simple\\' + filesname[num].decode('utf-8') contact[whoid].add_field('personal_ringtone', song) print 'No personal ringtone! Add one!' pass else: contact[whoid].__delitem__(num) num = random.randrange(0, len(filesname)-1) song = u'E:\\Sounds\\Simple\\' + filesname[num].decode('utf-8') contact[whoid].add_field('personal_ringtone', song) print 'Remove old ringtone, add one!' def cb_calling(state): print unicode('0:' + str(state[0]) + ';1:' + str(state[1])) if (state[0]==telephone.EStatusRinging): global tele tele = str(state[1]) print 'Ring: ' + tele print "EStatusRinging.." if (state[0]==telephone.EStatusConnecting): print "EStatusConnecting.." if (state[0]==telephone.EStatusUnknown): print "EStatusUnknown.." if (state[0]==telephone.EStatusIdle): handle_ringtone() print "EStatusIdle.." if (state[0]==telephone.EStatusDialling): print "EStatusDialling.." if (state[0]==telephone.EStatusAnswering): print "EStatusAnswering.." if (state[0]==telephone.EStatusConnected): print "EStatusConnected.." if (state[0]==telephone.EStatusReconnectPending): print "EStatusReconnectPending.." if (state[0]==telephone.EStatusDisconnecting): print "EStatusDisconnecting.." if (state[0]==telephone.EStatusHold): print "EStatusHold.." if (state[0]==telephone.EStatusTransferring): print "EStatusTransferring.." if (state[0]==telephone.EStatusTransferAlerting): print "EStatusTransferAlerting.." def quit(): app_lock.signal() appuifw.app.title = u'Incoming call Test' appuifw.app.menu = [(u"Init Setup", add_all_random_ringtone), (u"Remove Setup", remove_all_ringtone), (u"Exit", quit)] appuifw.app.exit_key_handler= quit app_lock=e32.Ao_lock() telephone.call_state(cb_calling) app_lock.wait()
Usefull Links:
Bind an incoming call
http://discussion.forum.nokia.com/fo...d.php?t=120891
[PDF]Python For S60 1.4.1 document
http://sourceforge.net/projects/pys60

Reply With Quote



