From c90b278939e7375f960f57af5091849c5e075b21 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/Makefile.am | 2 + src/client/__init__.py | 2 + src/client/account.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++ src/client/accountmgr.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 0 deletions(-) create mode 100644 src/client/account.py create mode 100644 src/client/accountmgr.py diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 7050c13..19e87fa 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -1,5 +1,7 @@ clientdir = $(pythondir)/telepathy/client client_PYTHON = \ + accountmgr.py \ + account.py \ channel.py \ connmgr.py \ conn.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..66bf260 --- /dev/null +++ b/src/client/account.py @@ -0,0 +1,48 @@ +# 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 + +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 = ACCOUNT_MANAGER + 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_IFACE].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..472099e --- /dev/null +++ b/src/client/accountmgr.py @@ -0,0 +1,48 @@ +# 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 + +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 = ACCOUNT_MANAGER + 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_IFACE].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