From 72a19f0bae9d637cd115d9f418001528c9d490da Mon Sep 17 00:00:00 2001 From: Morten Mjelva Date: Mon, 19 Apr 2010 19:42:37 +0200 Subject: [PATCH] added Account and AccountManager class --- src/client/__init__.py | 2 + src/client/account.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++ src/client/accountmgr.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 0 deletions(-) create mode 100644 src/client/account.py create mode 100644 src/client/accountmgr.py diff --git a/src/client/__init__.py b/src/client/__init__.py index 909f667..a598ab4 100644 --- a/src/client/__init__.py +++ b/src/client/__init__.py @@ -19,6 +19,8 @@ from telepathy.client.interfacefactory import InterfaceFactory from telepathy.client.managerregistry import ManagerRegistry +from telepathy.client.accountmgr import AccountManager +from telepathy.client.account import Account from telepathy.client.connmgr import ConnectionManager from telepathy.client.conn import Connection from telepathy.client.channel import Channel diff --git a/src/client/account.py b/src/client/account.py new file mode 100644 index 0000000..33a3dc4 --- /dev/null +++ b/src/client/account.py @@ -0,0 +1,51 @@ +# telepathy-python - Base classes defining the interfaces of the Telepathy framework +# +# Copyright (C) 2005, 2006 Collabora Limited +# Copyright (C) 2005, 2006 Nokia Corporation +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import dbus + +from telepathy.client.interfacefactory import (InterfaceFactory, + default_error_handler, + ) +from telepathy.interfaces import ACCOUNT, ACCOUNT_MANAGER + +DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties' + +class Account(InterfaceFactory): + def __init__(self, object_path, bus=None, ready_handler=None, + error_handler=default_error_handler): + if not bus: + bus = dbus.Bus() + + self.service_name = 'org.freedesktop.Telepathy.AccountManager' + self.object_path = object_path + self._ready_handler = ready_handler + self.error_cb = error_handler + object = bus.get_object(self.service_name, self.object_path) + InterfaceFactory.__init__(self, object, ACCOUNT) + + self[DBUS_PROPERTIES].Get( + ACCOUNT, + 'Interfaces', + reply_handler=self.get_interfaces_cb, + error_handler=self.error_cb) + + def get_interfaces_cb(self, interfaces): + self.get_valid_interfaces().update(interfaces) + if self._ready_handler: + self._ready_handler(self) diff --git a/src/client/accountmgr.py b/src/client/accountmgr.py new file mode 100644 index 0000000..570016e --- /dev/null +++ b/src/client/accountmgr.py @@ -0,0 +1,51 @@ +# telepathy-python - Base classes defining the interfaces of the Telepathy framework +# +# Copyright (C) 2005, 2006 Collabora Limited +# Copyright (C) 2005, 2006 Nokia Corporation +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import dbus + +from telepathy.client.interfacefactory import (InterfaceFactory, + default_error_handler, + ) +from telepathy.interfaces import ACCOUNT_MANAGER + +DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties' + +class AccountManager(InterfaceFactory): + def __init__(self, bus=None, ready_handler=None, + error_handler=default_error_handler): + if not bus: + bus = dbus.Bus() + + self.service_name = 'org.freedesktop.Telepathy.AccountManager' + self.object_path = '/org/freedesktop/Telepathy/AccountManager' + self._ready_handler = ready_handler + self.error_cb = error_handler + object = bus.get_object(self.service_name, self.object_path) + InterfaceFactory.__init__(self, object, ACCOUNT_MANAGER) + + self[DBUS_PROPERTIES].Get( + ACCOUNT_MANAGER, + 'Interfaces', + reply_handler=self.get_interfaces_cb, + error_handler=self.error_cb) + + def get_interfaces_cb(self, interfaces): + self.get_valid_interfaces().update(interfaces) + if self._ready_handler: + self._ready_handler(self) -- 1.7.0.4