From: Ed Page Date: Mon, 11 Apr 2011 23:02:42 +0000 (-0500) Subject: QtMobility Memory Corruption Reproduction: X-Git-Url: http://git.maemo.org/git/?p=gc-dialer;a=commitdiff_plain;h=e71ffb33c1f38de48b65dc2dedff6cd3f8e76e78 QtMobility Memory Corruption Reproduction: When running DC as root, a "operation cannot be performed" notification shows up and the contacts tab will display nothing. If you closed on that tab, then startup will hault. When using this script, one can get various issues like floating point exceptions. The best I can figure is a bug in QtMobility or PySide that is causing memory corruption, taking out large swathes of stuff with it --- diff --git a/hand_tests/qtcontacts.py b/hand_tests/qtcontacts.py new file mode 100644 index 0000000..ace8436 --- /dev/null +++ b/hand_tests/qtcontacts.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python + +from __future__ import with_statement +from __future__ import division + +import QtMobility.Contacts as QtContacts + + +class QtContactsAddressBook(object): + + def __init__(self, name, uri): + self._name = name + self._uri = uri + self._manager = QtContacts.QContactManager.fromUri(uri) + self._contacts = None + + @property + def name(self): + return self._name + + @property + def error(self): + return self._manager.error() + + def update_account(self, force = True): + if not force and self._contacts is not None: + return + self._contacts = dict(self._get_contacts()) + + def get_contacts(self): + if self._contacts is None: + self._contacts = dict(self._get_contacts()) + return self._contacts + + def _get_contacts(self): + contacts = self._manager.contacts() + for contact in contacts: + contactId = contact.localId() + contactName = contact.displayLabel() + phoneDetails = contact.details(QtContacts.QContactPhoneNumber().DefinitionName) + phones = [{"phoneType": "Phone", "phoneNumber": phone.value(QtContacts.QContactPhoneNumber().FieldNumber)} for phone in phoneDetails] + contactDetails = phones + if 0 < len(contactDetails): + yield str(contactId), { + "contactId": str(contactId), + "name": contactName, + "numbers": contactDetails, + } + + +class _QtContactsAddressBookFactory(object): + + def __init__(self): + self._availableManagers = {} + + availableMgrs = QtContacts.QContactManager.availableManagers() + availableMgrs.remove("invalid") + for managerName in availableMgrs: + params = {} + managerUri = QtContacts.QContactManager.buildUri(managerName, params) + self._availableManagers[managerName] = managerUri + + def get_addressbooks(self): + for name, uri in self._availableManagers.iteritems(): + book = QtContactsAddressBook(name, uri) + if book.error: + print "Could not load %r due to %r" % (name, book.error) + else: + yield book + + +class _EmptyAddressBookFactory(object): + + def get_addressbooks(self): + if False: + yield None + + +if QtContacts is not None: + QtContactsAddressBookFactory = _QtContactsAddressBookFactory +else: + QtContactsAddressBookFactory = _EmptyAddressBookFactory + print "QtContacts support not available" + + +if __name__ == "__main__": + factory = QtContactsAddressBookFactory() + books = factory.get_addressbooks() + for book in books: + print book.name + print book.get_contacts()