Reply
Thread Tools
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#1
This script is made in response to all those "IT CAN'T BE DONE" posts. Consider this as a demonstration rather than an application. However, if you've a pressing needs of caller-group ringtones, you may use the script (with caution).

Hope this help.

Code:
#! /usr/bin/env python2.5
# callergroup - Assign Ringtone By Caller-Group for N900 v0.0.1
# By 9000 @ maemo.org 14-May-2010
# 
# ATTENTION: Use the script at your own risk. You're responsible for any damage that'd cause by using this script.
#
# LIMITATION: Lots. Like lacking fancy UI,  insufficient format support (WAV only), etc. 
#
# FEATURE: 1) Assign different ringtones to caller-groups you defined. 
#
# Usage: 
# (Move your default ringtone to /home/user/.local/share/sounds/callergroup/ , I choose Gradient.acc.wav in this example)
# mkdir -p /home/user/.local/share/sounds/callergroup/
# mv /home/user/.local/share/sounds/Gradient.acc.wav /home/user/.local/share/sounds/callergroup/.
#
# (Symlink your default ringtone back to /home/user/.local/share/sounds/ , Gradient.aac.wav in this example)
# ln -sf /home/user/.local/share/sounds/callergroup/Gradient.aac.wav /home/user/.local/share/sounds/Gradient.aac.wav
#
# (Copy any wav files you'd like to set for the groups. I use ringtone_for_group_X.wav in this example)
# cp /media/mmc1/ringtone/*.wav /home/user/.local/share/sounds/callergroup/. (just an example)
#
# (Run the script)
# /usr/bin/python ./callergroup.py
# 


import gobject, dbus
import time
import os
from dbus.mainloop.glib import DBusGMainLoop

def handle_call(obj_path, callernumber):
	global blocklist
	print 'Calling from '+callernumber+'...'

# Caller group found:
	if callernumber in group_info:
		assigned_group = group_info[callernumber]
		group_ring = group_ringtones[assigned_group]
		print 'Caller belongs to Group:'+assigned_group+', ringtone assigned:'+group_ring+'.wav'
		bus = dbus.SessionBus()
		profiled = bus.get_object('com.nokia.profiled', '/com/nokia/profiled')
		proxy = dbus.Interface(profiled, 'com.nokia.profiled')
		system_ring = os.path.basename(proxy.get_value('general','ringing.alert.tone'))
		os.system('ln -sf /home/user/.local/share/sounds/callergroup/'+group_ring+'.wav /home/user/.local/share/sounds/'+system_ring+'.wav')
# Default:
	else:
		print 'Caller has no assigned group'
		bus = dbus.SessionBus()
		profiled = bus.get_object('com.nokia.profiled', '/com/nokia/profiled')
		proxy = dbus.Interface(profiled, 'com.nokia.profiled')
		system_ring = os.path.basename(proxy.get_value('general','ringing.alert.tone'))
		os.system('ln -sf /home/user/.local/share/sounds/callergroup/'+system_ring+'.wav /home/user/.local/share/sounds/'+system_ring+'.wav')

# ---Customize the following arrays yourself--- #

# Change the name of the ringtones for the corresponding groups
group_ringtones = {	'GroupA':'ringtone_for_group_a',
			'GroupB':'ringtone_for_group_b',
			'GroupC':'ringtone_for_group_c',
			}

# Associate the numbers to the groups
group_info = {	'23820000':'GroupA',
		'28020021':'GroupB',
		'12345678':'GroupB',
		'87654321':'GroupC',
		}

# ---End of Customization--- #

DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(handle_call, path='/com/nokia/csd/call', dbus_interface='com.nokia.csd.Call', signal_name='Coming')
gobject.MainLoop().run()
Source reference:
http://maemocentral.com/2010/02/22/h...s-on-the-n900/
http://www.maemoers.com/archiver/tid-2364.html

Last edited by 9000; 2010-06-11 at 01:50.
 

The Following 20 Users Say Thank You to 9000 For This Useful Post:
Posts: 433 | Thanked: 274 times | Joined on Jan 2010
#2
system_ring = os.path.basename(proxy.get_value('general','ringin g.alert.tone'))

haven't tried this but I'm guessing that is a rogue space embedded in the above line?
 
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#3
Originally Posted by Pigro View Post
system_ring = os.path.basename(proxy.get_value('general','ringin g.alert.tone'))

haven't tried this but I'm guessing that is a rogue space embedded in the above line?
Looks like it's inserted by the forum engine.

Thanks for pointing it out promptly.

Last edited by 9000; 2010-05-14 at 09:05.
 
pelago's Avatar
Posts: 2,121 | Thanked: 1,540 times | Joined on Mar 2008 @ Oxford, UK
#4
Thanks for this. For future reference, you might want to know that you can wrap code with [code] tags to make it appear nicer, keeping indents etc.
 
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#5
Originally Posted by pelago View Post
Thanks for this. For future reference, you might want to know that you can wrap code with [code] tags to make it appear nicer, keeping indents etc.
Oh! That's great! Thank you for the tips. Corrected.
 
pelago's Avatar
Posts: 2,121 | Thanked: 1,540 times | Joined on Mar 2008 @ Oxford, UK
#6
Can I just make sure I've got the general idea of your program correct, based on my inexpert reading of the code: The program runs continuously in the background. When it detects an incoming call, it quickly changes the system-defined ringtone using a symbolic link, based on a lookup of which phone number should be in which group. The actual playing of the tone is done by the phone app itself. Is that right?

I'm just wondering what happens if for some reason the phone app gets there first and starts playing a different ringtone, before your app gets a chance to change the symlink. Will the ringtone change half-way through?

Does your app impact battery life, if it is running in the background all the time?

Thinking about a potential GUI, obviously there would need to be a way to define groups (giving each a custom name would be nice), plus a way to pick a ringtone per group. Then there would need to be a way to associate a contact with each group. I wonder if there's a way to hook into the contacts framework to do this. Maybe the group could be stored as a Note field in the contact, or something like that.
 
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#7
Hi Pelago,

Originally Posted by pelago View Post
Can I just make sure I've got the general idea of your program correct, based on my inexpert reading of the code: The program runs continuously in the background. When it detects an incoming call, it quickly changes the system-defined ringtone using a symbolic link, based on a lookup of which phone number should be in which group. The actual playing of the tone is done by the phone app itself. Is that right?
Correct. As the phone will play the same clip for all calls. The program is then changing the pointer (aka symlink) of that clip according to the caller number, before the phone play that clip.

[/quote]
I'm just wondering what happens if for some reason the phone app gets there first and starts playing a different ringtone, before your app gets a chance to change the symlink. Will the ringtone change half-way through?
[/quote]

The script setup an event loop to pick up signal. I'm sure the race condition you've mention would happen. Anyone would suggest a better way to preempt the ringing would be welcome. ^^

Does your app impact battery life, if it is running in the background all the time?
It'd absolutely increase the load thus drain battery, but it's pretty lightweight. Any suggest to benchmark electricity consumption?

Thinking about a potential GUI, obviously there would need to be a way to define groups (giving each a custom name would be nice), plus a way to pick a ringtone per group. Then there would need to be a way to associate a contact with each group. I wonder if there's a way to hook into the contacts framework to do this. Maybe the group could be stored as a Note field in the contact, or something like that.
UI....but I'm not sure whether I'd continue its development. As I said, this script is served as a 'reply' to some negative comments against N900. A working program is better than thousands words. XD

However, creating extra column in each contact and have the program read that column to determine its ringtone is a very good idea. It doesn't require much effort to accomplish. May be I would enhance it a bit for that... later. ^^

Last edited by 9000; 2010-05-14 at 14:23.
 
Posts: 1,224 | Thanked: 1,763 times | Joined on Jul 2007
#8
Did you actually test this?
__________________
My repository

"N900 community support for the MeeGo-Harmattan" Is the new "Mer is Fremantle for N810".

No more Nokia devices for me.
 
Posts: 1,425 | Thanked: 983 times | Joined on May 2010 @ Hong Kong
#9
Originally Posted by Matan View Post
Did you actually test this?
Yes. If you want to try please read the instruction carefully. I didn't write code capturing errors.
 
Posts: 1,224 | Thanked: 1,763 times | Joined on Jul 2007
#10
Funny. When I tried this method, my script was always running too late, and the phone application played the previous ringtone.
__________________
My repository

"N900 community support for the MeeGo-Harmattan" Is the new "Mer is Fremantle for N810".

No more Nokia devices for me.
 
Reply


 
Forum Jump


All times are GMT. The time now is 06:18.