Пример #1
0
        def syncContacts(simc):
            for c in simc:
                SIMContacts[c.get_number()] = (c.get_name(), c.get_group())
            changes =[]

            if SIM_PC:
                for number, (name, group) in SIMContacts.iteritems():
                    contact = Contact (name, number, group=group)
                    if number not in DBContacts:
                        changes.append(self.cmanager.add_contact(contact))
                    else:
                        if name != DBContacts[number][0]:
                            ### TODO
                            # contact.name = name
                            # Any way to refresh info to the treeview
                            log.msg('SIM Conflict with Number %s' % number)

            if PC_SIM:
                for number, (name, group) in DBContacts.iteritems():
                    contact = Contact (name, number, group=group)
                    if number not in SIMContacts:
                        self.add_contact(contact, True)
                        contact.group = 'SIM'
                        changes.append(contact)
                    else:
                        if name != SIMContacts[number][0]: # Modify!
                            self.edit_contact(contact)
                            log.msg('DB Conflict with Number %s' % number)

            return changes
 def test_add_contact(self):
     contact = Contact('Peter', '+3453453452')
     c1 = self.mana.add_contact(contact)
     self.assertEqual(contact, self.mana.get_contact_by_id(c1.get_index()))
     contact2 = Contact('John', '+45364563345')
     c2 = self.mana.add_contact(contact2)
     self.assertEqual(contact2, self.mana.get_contact_by_id(c2.get_index()))
Пример #3
0
def process_contact_match(match):
    """I process a contact match and return a C{Contact} object out of it"""
    from vmc.common.persistent import Contact
    name = from_ucs2(match.group('name'))
    number = from_ucs2(match.group('number'))
    index = int(match.group('id'))
    return Contact(name, number, index=index)
Пример #4
0
 def next(self):
     row = self.reader.next()
     name, number = row
     name = unicode(name, self.encoding)
     try:
         index = self.free_ids.popleft()
         return Contact(name, number, index=index)
     except IndexError:
         raise StopIteration
 def test_add_contact_in_db(self):
     c = Contact("Paul", "+34673435676")
     def process_contact(contact):
         d2 = self.phonebook.get_contacts()
         d2.addCallback(lambda contacts: self.assertIn(contact, contacts))
         d2.addCallback(lambda _: self.phonebook.delete_contact(contact))
         return d2
     
     d = self.phonebook.add_contact(c, sim=False)
     d.addCallback(process_contact)
     return d
 def test_add_contact_in_sim(self):
     c = Contact("Peter", "+34673434321")
     def process_contact(contact):
         d2 = self.phonebook.get_contacts()
         d2.addCallback(lambda contacts: self.assertIn(contact, contacts))
         d2.addCallback(lambda _: self.phonebook.delete_contact(contact))
         return d2
     
     d = self.phonebook.add_contact(c, sim=True)
     d.addCallback(process_contact)
     return d
 def test_find_contact_in_sim_by_number(self):
     c = Contact("Lucy", "+34673432239")
     def process_contact(contact):
         d2 = self.phonebook.find_contact(number="+34673432239")
         d2.addCallback(lambda contacts: self.assertIn(contact, contacts))
         d2.addCallback(lambda _: self.phonebook.delete_contact(contact))
         return d2
     
     d = self.phonebook.add_contact(c, sim=True)
     d.addCallback(process_contact)
     return d
 def test_find_contact_in_db_by_number(self):
     c = Contact("Jaume", "+34633223422")
     def process_contact(contact):
         d2 = self.phonebook.find_contact(number='+34633223422')
         d2.addCallback(lambda contacts: self.assertIn(contact, contacts))
         d2.addCallback(lambda _: self.phonebook.delete_contact(contact))
         return d2
     
     d = self.phonebook.add_contact(c, sim=False)
     d.addCallback(process_contact)
     return d
 def test_find_contact_in_db_by_name(self):
     c = Contact("Aitor", "+34673232322")
     def process_contact(contact):
         d2 = self.phonebook.find_contact("Ai")
         d2.addCallback(lambda contacts: self.assertIn(contact, contacts))
         d2.addCallback(lambda _: self.phonebook.delete_contact(contact))
         return d2
     
     d = self.phonebook.add_contact(c, sim=False)
     d.addCallback(process_contact)
     return d
    def test_get_contacts(self):
        """
        Test that get_contacts works
        
        We add a couple of contacts and they must appear in get_contacts resp
        """
        contact = Contact("Vodafone", "+34670979779", 3)
        contact2 = Contact("Vodafoonz", "+34670923432", 4)
        self.sconn.add_contact(contact)
        self.sconn.add_contact(contact2)

        def get_contacts_cb(contacts):
            self.failUnlessIn(contact, contacts)
            self.failUnlessIn(contact2, contacts)

            d = self.sconn.delete_contact(contact.index)
            d.addCallback(lambda _: self.sconn.delete_contact(contact2.index))
            return d

        d = self.sconn.get_contacts()
        d.addCallback(get_contacts_cb)
        return d
Пример #11
0
def process_contact_match(match):
    """I process a contact match and return a C{Contact} object out of it"""
    from vmc.common.persistent import Contact

    _name = match.group('name')
    if check_if_ucs2(_name):
        name = from_ucs2(_name)
    else:
        name = _name.decode('utf8','ignore').rstrip('\x1f')

    number = from_ucs2(match.group('number'))
    index = int(match.group('id'))
    return Contact(name, number, index=index)
 def test_edit_contact(self):
     c = Contact("James", "+34673434222")
     def process_contact(contact):
         contact.name = 'John'
         d2 = self.phonebook.edit_contact(contact)
         d2.addCallback(lambda contactback:
                        self.assertEqual(contactback.name, 'John'))
         d2.addCallback(lambda _: self.phonebook.delete_contact(contact))
         return d2
     
     d = self.phonebook.add_contact(c, sim=True)
     d.addCallback(process_contact)
     return d
    def test_find_contact(self):
        """
        Test finding a contact
        """
        contact = Contact("Vodafone", "+34670979779", 1)
        pattern = "Vodafo"
        self.sconn.add_contact(contact)
        d = self.sconn.find_contacts(pattern)

        def process_contact(contact_found):
            self.assertEqual(contact, contact_found[0])
            return self.sconn.delete_contact(contact.index)

        d.addCallback(process_contact)
        return d
    def test_delete_contact(self):
        """
        Test deleting a contact
        """
        contact = Contact("Vodafoo", "+3467456654", 2)
        d = self.sconn.add_contact(contact)

        def callback(ignored):
            self.sconn.delete_contact(contact.index)
            d2 = self.sconn.get_used_contact_ids()
            d2.addCallback(lambda val: self.failIfIn(contact.index, val))
            return self.sconn.delete_contact(contact.index)

        d.addCallback(callback)
        return d
    def test_add_contact_with_index(self):
        """
        Test adding a contact specifying an index
        """
        contact = Contact("Vodafone", "+34670979779", 1)
        d = self.sconn.add_contact(contact)

        def process_contact_bak(ignored):
            d2 = self.sconn.get_contact_by_index(contact.index)
            d2.addCallback(
                lambda contact_bak2: self.assertEqual(contact, contact_bak2))
            return self.sconn.delete_contact(contact.index)

        d.addCallback(process_contact_bak)
        return d
Пример #16
0
    def on_add_contact_ok_button_clicked(self, widget):
        if not self.name_entry.isvalid() or not self.number_entry.isvalid():
            return

        name = self.name_entry.get_text()
        number = self.number_entry.get_text()
        save_in_sim = self.view['mobile_radio_button'].get_active()

        phonebook = get_phonebook(self.parent_ctrl.model.get_sconn())
        contact = Contact(name, number)

        def add_callback(contact):
            # add it to the treeview model
            model = self.parent_ctrl.view['contacts_treeview'].get_model()
            model.add_contact(contact)
            self._hide_me()

        d = phonebook.add_contact(contact, sim=save_in_sim)
        d.addCallback(add_callback)
Пример #17
0
    def on_add_contact_ok_button_clicked(self, widget):
        if not self.name_entry.isvalid() or not self.number_entry.isvalid():
            return

        name = self.name_entry.get_text()
        number = self.number_entry.get_text()
        group = self.group_entry.get_text() or 'default'

        phonebook = get_phonebook(self.parent_ctrl.model.get_sconn())
        contact = Contact(name, number, group=group)

        def add_callback(contact):
            # add it to the treeview model
            model = self.parent_ctrl.view['contacts_treeview'].get_model()
            model.add_contact(contact)
            self._hide_me()

        d = phonebook.add_contact(contact, sim=False)
        d.addCallback(add_callback)
Пример #18
0
    def hw_process_contact_match(self, match):
        """I process a contact match and return a C{Contact} object out of it"""
        from vmc.common.persistent import Contact
        if int(match.group('raw')) == 0:
            name = match.group('name').decode('utf8', 'ignore').rstrip('\x1f')
        else:
            encoding = match.group('name')[:2]
            hexbytes = match.group('name')[2:]
            if encoding == '80':  # example '80058300440586FF'
                name = unpack_ucs2_bytes_in_ts31101_80(hexbytes)
            elif encoding == '81':  # example '810602A46563746F72FF'
                name = unpack_ucs2_bytes_in_ts31101_81(hexbytes)
            elif encoding == '82':  # example '820505302D82D32D31'
                name = unpack_ucs2_bytes_in_ts31101_82(hexbytes)
            else:
                name = "Unsupported encoding"

        number = from_ucs2(match.group('number'))
        index = int(match.group('id'))

        return Contact(name, number, index=index)
 def test_delete_contact(self):
     contact = Contact(pack('Paul'), '+45364563345')
     c1 = self.mana.add_contact(contact)
     self.mana.delete_contact_by_id(c1.get_index())
     self.assertRaises(KeyError, self.mana.get_contact_by_id,
                       c1.get_index())
 def test_find_contact(self):
     contact = Contact('Pepito', '+3453423423423')
     c1 = self.mana.add_contact(contact)
     resp = list(self.mana.find_contacts('Pe'))
     self.failUnlessIn(c1, resp)