1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2007 Johann Prieur <johann.prieur@gmail.com>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
from pymsn.service.AddressBook.scenario.base import BaseScenario
20
from pymsn.service.AddressBook.scenario.base import Scenario
22
from pymsn.service.description.AB import ContactPhoneType
24
__all__ = ['MobileContactAddScenario']
26
class MobileContactAddScenario(BaseScenario):
27
def __init__(self, ab, callback, errback,
28
phone_number="", contact_info={}):
29
"""Adds a mobile contact and updates the address book.
31
@param ab: the adress book service
32
@param callback: tuple(callable, *args)
33
@param errback: tuple(callable, *args)"""
34
BaseScenario.__init__(self, Scenario.MOBILE_CONTACT_MSGR_API, callback, errback)
37
self.__phone_number = phone_number
38
self.__contact_info = contact_info
40
def __set_phone_number(self, phone_number):
41
self.__phone_number = phone_number
42
def __get_phone_number(self):
43
return self.__phone_number
44
phone_number = property(__get_phone_number, __set_phone_number)
46
def __set_contact_info(self, contact_info):
47
self.__contact_info = contact_info
48
def __get_contact_info(self):
49
return self.__contact_info
50
contact_info = property(__get_contact_info, __set_contact_info)
53
phones = self.__contact_info.get('phone', {})
54
phones[ContactPhoneType.MOBILE] = self.__phone_number
55
# self.__contact_info['phone'] = phones
56
self.__ab.ContactAdd((self.__contact_add_callback,),
57
(self.__contact_add_errback,),
62
def __contact_add_callback(self, stuff):
64
# TODO : get the cached lastchanged date to make a delta findall
65
# or directly call a sync scenario
66
self.__ab.FindAll(self.__scenario, True, None,
67
self.__find_all_callback, self.__find_all_errback)
69
def __contact_add_errback(self, reason):
70
# TODO : analyse the reason, and maybe call execute again
71
# instead of transmitting it via _errback.
74
def __find_all_callback(self):
75
# TODO : complete the contact list in the client, need to access to
76
# the local address book storage, not the service..
79
def __find_all_errback(self, reason):