Changing some references to GC Dialer in the code
[gc-dialer] / src / dialcentral / maemo_backend.py
1 #!/usr/bin/python
2
3 # DialCentral - Front end for Google's Grand Central service.
4 # Copyright (C) 2008  Eric Warnke ericew AT gmail DOT com
5
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
10
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Lesser General Public License for more details.
15
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
20
21 """
22 Maemo Contacts Support
23 """
24
25
26 import warnings
27
28 try:
29         import abook
30 except ImportError:
31         abook = None
32
33 try:
34         import evolution.ebook as ebook
35 except ImportError:
36         ebook = None
37
38
39 class MaemoAddressBook(object):
40         """
41         @note Combined the factory and the addressbook for "simplicity" and "cutting down" the number of allocations/deallocations
42         """
43
44         def __init__(self, contextName, context):
45                 if not self.is_supported():
46                         return
47                 
48                 abook.init_with_name(contextName, context)
49                 self._book = abook.all_group_get()
50         
51         @classmethod
52         def is_supported(cls):
53                 return abook is not None and ebook is not None
54
55         def get_addressbooks(self):
56                 """
57                 @returns Iterable of (Address Book Factory, Book Id, Book Name)
58                 """
59                 if not self.is_supported():
60                         return
61
62                 yield self, "", ""
63         
64         def open_addressbook(self, bookId):
65                 return self
66
67         @staticmethod
68         def contact_source_short_name(contactId):
69                 return "M"
70
71         @staticmethod
72         def factory_name():
73                 return "Maemo"
74
75         def get_contacts(self):
76                 """
77                 @returns Iterable of (contact id, contact name)
78                 """
79                 if not self.is_supported():
80                         return
81                 pass
82         
83         def get_contact_details(self, contactId):
84                 """
85                 @returns Iterable of (Phone Type, Phone Number)
86                 """
87                 pass
88
89
90 def print_maemobooks():
91         """
92         Included here for debugging.
93
94         Either insert it into the code or launch python with the "-i" flag
95         """
96         if not MaemoAddressBook.is_supported():
97                 print "No GMail Support"
98                 return
99
100         mab = MaemoAddressBook()
101         for book in mab.get_addressbooks():
102                 mab = mab.open_addressbook(book[1])
103                 print book
104                 for contact in mab.get_contacts():
105                         print "\t", contact
106                         for details in mab.get_contact_details(contact[0]):
107                                 print "\t\t", details
108         print mab._gmailContacts
109