View Single Post
Posts: 236 | Thanked: 223 times | Joined on Oct 2009 @ NE UK
#12
I suggested a really impractical brain-dead approach to creating this functionality in: http://talk.maemo.org/showthread.php...340#post456340

Just for fun, I actually tried to do this in an even *less* sensible manner than using python methods to talk to dbus - by executing dbus-monitor from within perl and parsing it's output (after setting the silent profile on the phone.)

Code:
#!/usr/bin/perl

# listen for incoming calls
$dbus_mon_cmd = "/usr/bin/dbus-monitor "
   . "--system \"type='signal',path="
   . "'/com/nokia/csd/call',interface='com.nokia.csd.Call'\"";
# map incoming numbers to ringtones
%tones = (
        # gf number
        '077XXXXXX' => '/home/user/MyDocs/.sounds/harp.wav',
        # boss's number
        '01XXXXXXX' => '/home/user/MyDocs/.sounds/parp.wav',
        'default' => '/home/user/MyDocs/.sounds/mystery.wav',
);

# play a file in media player via dbus.
sub pf($) {
        ($f) = @_;
        $pf_cmd = "dbus-send --print-reply "
 . "--dest=com.nokia.mediaplayer "
 . "/com/nokia/mediaplayer com.nokia.mediaplayer"
 . ".mime_open string:\"file:///$f\"";
        system("$pf_cmd &");
}

# start listening on dbus
open(DBUS, "$dbus_mon_cmd|") or die "couldn't read output from dbus-monitor: $!";

$debug=0;

while(<DBUS>) {
        print if($debug);

        # find the incoming number. 
        if(/string\s"(\d*)"/) {
                $num = $1;
                print "$num is calling..\n";
                if($num =~ /^\d+$/ and ($tones{$num})) {
                        # play corresponding tone
                        pf($tones{$num});
                } else {
                        pf($tones{'default'});
                }

        }
}
This doesn't work, I'm sorry to say, because the phone app seems to block media player, even in silent profile. So the configured tone plays, but only after I answered the phone or hung up (haha).

If there's some way of getting around this (a more direct way of playing the ringtone, or removing the phone app's block, ...) and a way of stopping the file playing when you answer, hang up, or lose the call, then it might work.

N.B. I'm not suggesting this as a viable actual solution! It's just for fun..


My preferred non-braindead, non-hacky solution would be for Nokia to open up the phone UI(!) (maybe the contacts infrastructure - I don't know about their status) and/or provide a simple, clean, and extensively documented framework to use the underlying API.


If this were done, I don't think it would take very long for this functionality to arrive.