maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N900 (https://talk.maemo.org/forumdisplay.php?f=44)
-   -   [HOW TO] Assign Ringtone by Caller-group for N900 (https://talk.maemo.org/showthread.php?t=52646)

9000 2010-05-14 14:45

Re: [HOW TO] Assign Ringtone by Caller-group for N900
 
LOL, you got a real fast phone app! I don't have that problem.

Let me see if there's a way to delay the ring...

9000 2010-05-14 14:55

Re: [HOW TO] Assign Ringtone by Caller-group for N900
 
Strange....while I've tested the script under all loading condition, it can still pickup the correct ringtone to play. I can't seem to reproduce the race condition you've experienced.

Let me check the dbus documentation again.

9000 2010-05-18 02:32

Re: [HOW TO] Assign Ringtone by Caller-group for N900
 
1 Attachment(s)
Though I still couldn't reproduce Matan's race condition, but may be running a compiled version would help. Anyway.

I made a slight modification to the script, including call-blocking function. I know there's already pycallblocker around for use, but I think some people would like it to be incorporated into one.

I'm still working on pelago's suggestion on using contact list and making UI(my weakest part), but for the time being just edit the script if you need to use it. ^^

Code:

#! /usr/bin/env python2.5
#
# callergroup - Assign Ringtone By Caller-Group for N900 v0.0.2
# By 9000 @ maemo.org/phonehk.com 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. 2) Block calls
# CHANGELOG: 18-May-2010: Add blocking function
#
# Usage:
# 1) 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/.
#
# 2) 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
#
# 3) 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)
#
# 4) Customize the telephone number and ringtone file name in the CUSTOMIZATION section below
#
# 5) 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')

# Call blocking:
        elif callernumber in blocklist:
                print 'Caller from '+callernumber+' blocked'
                bus = dbus.SystemBus()
                callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
                smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
                smsiface.Release()

# 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')

# ---CUSTOMIZATION--- #

# The telephone numbers to block
blocklist = ["11709394","53540997"]

# 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 telephone numbers to the groups
group_info = {        '77777777':'GroupA',
                '88888888':'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

Patola 2010-06-07 21:53

Re: [HOW TO] Assign Ringtone by Caller-group for N900
 
Bump this thread! Has anyone tried it with PR1.2? I hope this script rapidly evolves to a 'ringtone by contact group' app!

rmarcus 2010-06-11 02:18

Re: [HOW TO] Assign Ringtone by Caller-group for N900
 
Quote:

Originally Posted by Patola (Post 704374)
Bump this thread! Has anyone tried it with PR1.2? I hope this script rapidly evolves to a 'ringtone by contact group' app!

Me too!!! Pleeeeeeeeeeease!!!:(

9000 2010-06-11 02:27

Re: [HOW TO] Assign Ringtone by Caller-group for N900
 
I used PR1.2 from start so I guess it'd work for your PR1.2 as well.

Just that if you've real fast CPU (or real slow phone app) there's race condition as described by other posters above.

I wish I had time to improve the script. Any suggestion is welcome. ^^

colakang 2010-06-11 03:43

Re: [HOW TO] Assign Ringtone by Caller-group for N900
 
i suggest you use a variable to record the default ringtone info.
becase use DBUS object to detect info should be slow.
sorry for my poor english.

9000 2010-06-11 04:12

Re: [HOW TO] Assign Ringtone by Caller-group for N900
 
Quote:

Originally Posted by colakang (Post 709815)
i suggest you use a variable to record the default ringtone info.
becase use DBUS object to detect info should be slow.
sorry for my poor english.

Thanks! Actually I'd rather put it on hold rather than race with it....suggestion to hold the phone call is also welcome. ^^

excelar8 2010-06-11 04:49

Re: [HOW TO] Assign Ringtone by Caller-group for N900
 
mp3 ringtones (and alarm tones) have crackling sounds with the n900 anyways, haven't you guys noticed this problem?

https://bugs.maemo.org/show_bug.cgi?id=6784

9000 2010-06-11 06:16

Re: [HOW TO] Assign Ringtone by Caller-group for N900
 
No.

You may open a new thread for this. Specify clearly the firmware version you're using would help.


All times are GMT. The time now is 21:03.

vBulletin® Version 3.8.8