~ubuntu-branches/ubuntu/precise/pymsn/precise

« back to all changes in this revision

Viewing changes to pymsn/service/AddressBook/scenario/contacts/mobile_contact_add.py

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville, Sjoerd Simons, Laurent Bigonville, Jonny Lamb
  • Date: 2008-01-17 18:23:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080117182314-lwymmpnk2ut3rvr1
Tags: 0.3.1-0ubuntu1
[ Sjoerd Simons ]
* debian/rules: remove dh_python, it's no longer needed

[ Laurent Bigonville ]
* New upstream release (0.3.1)
* debian/control:
  - Add myself as an Uploaders
  - Add python:Provides for binary package
  - Add python-ctypes and python-crypto to build-deps/deps
* debian/rules: remove binary-install rule
* Add watch file
* remove pycompat file, not needed anymore
* Modify Maintainer value to match the DebianMaintainerField
  specification.

[ Jonny Lamb ]
* Added python-adns to build-deps/deps.
* Added python-pyopenssl to build-deps/deps.
* Updated copyright.
* Upped Standards-Version to 3.7.3.
* Added "XS-Dm-Upload-Allowed: yes" under the request of Sjoerd Simons.
* Added myself to Uploaders.
* Added Homepage to control.
* Added Vcs-Bzr to control.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Copyright (C) 2007 Johann Prieur <johann.prieur@gmail.com>
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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
 
18
#
 
19
from pymsn.service.AddressBook.scenario.base import BaseScenario
 
20
from pymsn.service.AddressBook.scenario.base import Scenario
 
21
 
 
22
from pymsn.service.description.AB import ContactPhoneType
 
23
 
 
24
__all__ = ['MobileContactAddScenario']
 
25
 
 
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.
 
30
 
 
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)
 
35
        self.__ab = ab
 
36
 
 
37
        self.__phone_number = phone_number
 
38
        self.__contact_info = contact_info
 
39
 
 
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)
 
45
    
 
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)
 
51
 
 
52
    def execute(self):
 
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,),
 
58
                             self.__scenario,
 
59
                             self.__contact_info,
 
60
                             {})
 
61
 
 
62
    def __contact_add_callback(self, stuff):
 
63
        self._callback(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)
 
68
 
 
69
    def __contact_add_errback(self, reason):
 
70
        # TODO : analyse the reason, and maybe call execute again
 
71
        # instead of transmitting it via _errback.
 
72
        self._errback(reason)
 
73
 
 
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..
 
77
        pass
 
78
 
 
79
    def __find_all_errback(self, reason):
 
80
        self._errback(reason)