Reply
Thread Tools
Posts: 82 | Thanked: 214 times | Joined on Jan 2010 @ Cape town
#1
I remember seeing a post about this recently, but I can't seem to find it... Anyhow:

Having set up a SIP account for an internal SIP server on my N900, it was quite irritating to have to constantly disable it after leaving WiFi to stop the messages about not being able to connect. So, I wrote a quick script which allows mapping of IM accounts to connections.

I've hardly tested it, but it works for me, and it's a kludgey but good enough hack until this feature (hopefully) gets integrated.

The script:
Code:
#!/usr/bin/env python
import conic
import dbus
import gobject
import dbus.glib

accounts = {
"account": ["connection1", "connection2"],

}

loop = gobject.MainLoop()
bus = dbus.SessionBus()


def state(account, new):
    accountd = bus.get_object('org.freedesktop.Telepathy.AccountManager', account)
    iface = dbus.Interface(accountd, 'org.freedesktop.DBus.Properties')
    iface.Set("org.freedesktop.Telepathy.Account", "Enabled", new)

def connection_cb(connection, event):
    if event.get_status() == conic.STATUS_CONNECTED:
        iap_id = event.get_iap_id()
        for account in accounts:
            state(account, iap_id in accounts[account])

connection = conic.Connection()
connection.connect("connection-event", connection_cb)
connection.set_property("automatic-connection-events", True)

loop.run()
Configuration is simple, change the dictionary "accounts" with whatever details you want.

To list your accounts, use the command
Code:
/usr/bin/dbus-send --type=method_call --print-reply --dest=org.freedesktop.Telepathy.AccountManager /org/freedesktop/Telepathy/AccountManager org.freedesktop.DBus.Properties.Get string:org.freedesktop.Telepathy.AccountManager string:ValidAccounts
And for the connections, either use the name of the connection (for GPRS / 3G) or the unique identifier for WLAN. To get the identifier, run the following bit of Python:

Code:
import conic

iaps = conic.Connection().get_all_iaps()
for iap in iaps:
    print "%s - %s" % (iap.get_name(), iap.get_id())
For example, for me, I'd use the following to have my GMail account only enabled on WiFi:

Code:
accounts = {
"/org/freedesktop/Telepathy/Account/gabble/jabber/florenzi_40gmail_2ecom0": ["ffcd0203-51ae-4bde-9622-d0256937b11b"],
}
And then fire it up in the Terminal as a normal user. You need python-dbus and python-conic installed.

Hope this helps some people out, if people could also test it and report back that would be great. It shouldn't really take too long to write a simple GUI and package this up properly. Also, other things, like only on WiFi / only on GPRS should be quite easy to implement.
 

The Following 6 Users Say Thank You to cb22 For This Useful Post:
Posts: 292 | Thanked: 131 times | Joined on Dec 2009
#2
Originally Posted by cb22 View Post
Hope this helps some people out, if people could also test it and report back that would be great. It shouldn't really take too long to write a simple GUI and package this up properly. Also, other things, like only on WiFi / only on GPRS should be quite easy to implement.
cb22, thanks a lot for that. I'll try your solution as soon as I can. The "only on WiFi/ only on GPRS" idea seems really useful. Also, when you can, go ahead and package that as a GUI utility. A lot more people will be happier.
 
evad's Avatar
Posts: 354 | Thanked: 151 times | Joined on Mar 2008 @ London (UK) / Zielona Góra (PL)
#3
Originally Posted by cb22 View Post
Hope this helps some people out, if people could also test it and report back that would be great. It shouldn't really take too long to write a simple GUI and package this up properly. Also, other things, like only on WiFi / only on GPRS should be quite easy to implement.
I did give it a try, but it doesn't seem to work for me. First I checked my connections and accounts:

Code:
user@n900:~/MyDocs/Dev$ python list-connections.py 
adlnet-14 - 5d2108f0-a1ac-40db-bae0-6c17de4f86e5
Code:
user@n900:~/MyDocs/Dev$ /usr/bin/dbus-send --type=method_call --print-reply --dest=org.freedesktop.Telepathy.AccountManager /org/freedesktop/Telepathy/AccountManager org.freedesktop.DBus.Properties.Get string:org.freedesktop.Telepathy.AccountManager string:ValidAccounts
method return sender=:1.20 -> dest=:1.369 reply_serial=2
   variant       array [
         object path "/org/freedesktop/Telepathy/Account/sofiasip/sip/evad002_40sip_2eipfon_2epl0"
      ]
I just want to connect to that one SIP account while connected to adlnet-14, which is my home WiFi. So I've amended main script by adding:

Code:
accounts = {
"/org/freedesktop/Telepathy/Account/sofiasip/sip/evad002_40sip_2eipfon_2epl0": ["5d2108f0-a1ac-40db-bae0-6c17de4f86e5"],
}
Then I run the script as normal user:

Code:
user@n900:~/MyDocs/Dev$ python im-per-connection.py
And wait... but nothing happens, ie. despite being connected to adlnet-14 network (or manually re-triggering a connection), status for that SIP account doesn't change.

Any suggestions?
__________________
Dawid 'evad' Lorenz * http://dawid.lorenz.co
_______________________________________________
 
thp's Avatar
Posts: 1,391 | Thanked: 4,272 times | Joined on Sep 2007 @ Vienna, Austria
#4
This might not work due to bug 7729?
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 07:45.