View Single Post
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: