148
148
bottom_swipe_page = self.get_contact_list_page()
149
149
bottom_swipe_page.revel_bottom_edge_page()
150
150
return self.get_contact_edit_page()
153
DBUS_NAME_PIM = 'com.canonical.pim'
154
DBUS_IFACE_ADDRESS_BOOK = 'com.canonical.pim.AddressBook'
155
DBUS_IFACE_ADDRESS_BOOKVIEW = 'com.canonical.pim.AddressBookView'
156
DBUS_OBJECT_ADDRESS_BOOK = '/com/canonical/pim/AddressBook'
159
class ContactsDbusService(object):
163
self.addr_iface = None
164
self.bus = dbus.SessionBus()
165
self.addr = self.bus.get_object(
166
DBUS_NAME_PIM, DBUS_OBJECT_ADDRESS_BOOK)
167
self.addr_iface = dbus.Interface(
168
self.addr, dbus_interface=DBUS_IFACE_ADDRESS_BOOK)
170
def query_contacts(self, fields='', query='', sources=[]):
171
view_path = self.addr_iface.query(fields, query, [])
172
view = self.bus.get_object(
173
DBUS_NAME_PIM, view_path)
174
view_iface = dbus.Interface(
175
view, dbus_interface=DBUS_IFACE_ADDRESS_BOOKVIEW)
176
contacts = view_iface.contactsDetails([], 0, -1)
180
def update_contact(self, vcard):
181
return self.addr_iface.updateContacts([vcard])
183
def create_contact(self, vcard):
184
return self.addr_iface.createContact(vcard, "")
186
def delete_contact(self, ids):
187
return self.addr_iface.removeContacts(ids)
189
def get_vcard_uid(self, vcard):
191
Return the UID of the provided vcard
192
:param vcard: vcard formatted data
193
:return: uid value from vcard, else None
195
uid_pattern = re.compile(r'^UID:(?P<uid>\S*)\r?$',
196
re.MULTILINE | re.IGNORECASE)
198
match = uid_pattern.search(vcard)
200
uid = match.group('uid')
203
def get_vcard_cell(self, vcard):
205
Return the mobile number of the provided vcard
206
:param vcard: vcard formatted data
207
:return: mobile number from vcard, else None
209
cell_pattern = re.compile(r'^.*TYPE=CELL,HOME:(?P<cell>\S*)\r?$',
210
re.MULTILINE | re.IGNORECASE)
212
match = cell_pattern.search(vcard)
214
cell = match.group('cell')
217
def delete_all_contacts(self):
219
Delete all contacts using the dbus service
222
contacts = self.query_contacts()
223
for contact in contacts:
224
uid = self.get_vcard_uid(contact)
227
self.delete_contact(uids)