[pkg-fso-commits] [SCM] FSO frameworkd Debian packaging branch, debian, updated. upstream/0.9.5.5-717-g0f98819

Sebastian Krzyszkowiak seba.dos1 at gmail.com
Sat Aug 6 08:17:36 UTC 2011


The following commit has been merged in the debian branch:
commit ae7914102051b02c958481f317f770ee51d6f054
Author: Sebastian Krzyszkowiak <seba.dos1 at gmail.com>
Date:   Fri Jul 31 21:04:24 2009 +0200

    opimd: add GenericDomain

diff --git a/framework/subsystems/opimd/helpers.py b/framework/subsystems/opimd/helpers.py
index f941886..7c412db 100644
--- a/framework/subsystems/opimd/helpers.py
+++ b/framework/subsystems/opimd/helpers.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# -*- coding: utf-8 -*-
 """
 Open PIM Daemon
 
@@ -96,6 +97,7 @@ class AmbiguousKey( DBusException ):
 #----------------------------------------------------------------------------#
     """Raised when a given message field name is present more than once and it's unclear which to modify"""
     _dbus_error_name = "org.freesmartphone.PIM.AmbiguousKey"
+
 #----------------------------------------------------------------------------#
 class InvalidCallID( DBusException ):
 #----------------------------------------------------------------------------#
@@ -108,4 +110,14 @@ class NoMoreCalls( DBusException ):
     """Raised when there are no more calls to be listed"""
     _dbus_error_name = "org.freesmartphone.PIM.NoMoreCalls"
 
+#----------------------------------------------------------------------------#
+class InvalidCallID( DBusException ):
+#----------------------------------------------------------------------------#
+    """Raised when a submitted call ID is invalid / out of range"""
+    _dbus_error_name = "org.freesmartphone.PIM.InvalidCallID"
 
+#----------------------------------------------------------------------------#
+class NoMoreCalls( DBusException ):
+#----------------------------------------------------------------------------#
+    """Raised when there are no more calls to be listed"""
+    _dbus_error_name = "org.freesmartphone.PIM.NoMore"
diff --git a/framework/subsystems/opimd/pimd_contacts.py b/framework/subsystems/opimd/pimd_generic.py
similarity index 67%
copy from framework/subsystems/opimd/pimd_contacts.py
copy to framework/subsystems/opimd/pimd_generic.py
index e06767e..6e1066c 100644
--- a/framework/subsystems/opimd/pimd_contacts.py
+++ b/framework/subsystems/opimd/pimd_generic.py
@@ -3,15 +3,15 @@
 """
 Open PIM Daemon
 
-(C) 2008 by Soeren Apel <abraxa at dar-clan.de>
+(C) 2008 Soeren Apel <abraxa at dar-clan.de>
 (C) 2008 Openmoko, Inc.
 (C) 2009 Michael 'Mickey' Lauer <mlauer at vanille-media.de>
 (C) 2009 Sebastian Krzyszkowiak <seba.dos1 at gmail.com>
 GPLv2 or later
 
-Contacts Domain Plugin
+Generic Domain
 
-Establishes the 'contacts' PIM domain and handles all related requests
+From this domain class others inherit.
 """
 
 from dbus.service import FallbackObject as DBusFBObject
@@ -34,19 +34,19 @@ from framework.config import config, busmap
 
 #----------------------------------------------------------------------------#
 
-_DOMAIN_NAME = "Contacts"
+_DOMAIN_NAME = "Generic"
 
-_DBUS_PATH_CONTACTS = DBUS_PATH_BASE_FSO + '/' + _DOMAIN_NAME
-_DIN_CONTACTS_BASE = DIN_BASE_FSO
+_DBUS_PATH_DOMAIN = DBUS_PATH_BASE_FSO + '/' + _DOMAIN_NAME
+_DIN_DOMAIN_BASE = DIN_BASE_FSO
 
-_DBUS_PATH_QUERIES = _DBUS_PATH_CONTACTS + '/Queries'
+_DBUS_PATH_QUERIES = _DBUS_PATH_DOMAIN + '/Queries'
 
-_DIN_CONTACTS = _DIN_CONTACTS_BASE + '.' + 'Contacts'
-_DIN_ENTRY = _DIN_CONTACTS_BASE + '.' + 'Contact'
-_DIN_QUERY = _DIN_CONTACTS_BASE + '.' + 'ContactQuery'
+_DIN_ENTRIES = _DIN_DOMAIN_BASE + '.' + 'Entries'
+_DIN_ENTRY = _DIN_DOMAIN_BASE + '.' + 'Entry'
+_DIN_QUERY = _DIN_DOMAIN_BASE + '.' + 'EntryQuery'
 
 #----------------------------------------------------------------------------#
-class ContactQueryMatcher(object):
+class QueryMatcher(object):
 #----------------------------------------------------------------------------#
     query_obj = None
 
@@ -58,23 +58,23 @@ class ContactQueryMatcher(object):
         self.query_obj = query
 
 
-    def match(self, contacts):
-        """Tries to match a given set of contacts to the current query
+    def match(self, entries):
+        """Tries to match a given set of entries to the current query
 
-        @param contacts List of Contact objects
-        @return List of contact IDs that match"""
+        @param entries List of Entry objects
+        @return List of entry IDs that match"""
 
         assert(self.query_obj, "Query object is empty, cannot match!")
 
         matches = []
         results = []
 
-        # Match all contacts
-        for (contact_id, contact) in enumerate(contacts):
-            if contact:
-                match = contact.match_query(self.query_obj)
+        # Match all entires
+        for (entry_id, entry) in enumerate(entries):
+            if entry:
+                match = entry.match_query(self.query_obj)
                 if match > 0.0:
-                    matches.append((match, contact_id))
+                    matches.append((match, entry_id))
 
         result_count = len(matches)
         # Sort matches by relevance and return the best hits
@@ -87,7 +87,7 @@ class ContactQueryMatcher(object):
                 if limit > result_count:
                     limit = result_count
 
-            # Append the contact IDs to the result list in the order of the sorted list
+            # Append the entry IDs to the result list in the order of the sorted list
             for i in range(limit):
                 results.append(matches[i][1])
 
@@ -96,15 +96,15 @@ class ContactQueryMatcher(object):
 
 
 #----------------------------------------------------------------------------#
-class Contact():
+class Entry():
 #----------------------------------------------------------------------------#
-    """Represents one single contact with all the data fields it consists of.
+    """Represents one single entry with all the data fields it consists of.
 
     _fields[n] = [field_name, field_value, value_used_for_comparison, source]
 
     Best way to explain the usage of _fields and _field_idx is by example:
     _fields[3] = ["EMail", "foo at bar.com", "", "CSV-Contacts"]
-    _fields[4] = ["EMail", "moo at cow.com", "", "LDAP-Contacts"]
+    _fields[4] = ["EMail", "moo at cow.com", "", "SQLite-Messages"]
     _field_idx["EMail"] = [3, 4]"""
 
     _fields = None
@@ -112,9 +112,9 @@ class Contact():
     _used_backends = None
 
     def __init__(self, path):
-        """Creates a new Contact instance
+        """Creates a new entry instance
 
-        @param path Path of the contact itself"""
+        @param path Path of the entry itself"""
 
         self._fields = []
         self._field_idx = {}
@@ -178,28 +178,28 @@ class Contact():
                 self._field_idx[field_name] = [field_idx]
 
 
-    def import_fields(self, contact_data, backend_name):
-        """Adds an array of contact data fields to this contact
+    def import_fields(self, entry_data, backend_name):
+        """Adds an array of entry data fields to this entry
 
-        @param contact_data Contact data; format: ((Key,Value), (Key,Value), ...)
+        @param entry_data entry data; format: {Key:Value, Key:Value, ...}
         @param backend_name Name of the backend to which those fields belong"""
 
         if backend_name!='':
             if not backend_name in self._used_backends:
                 self._used_backends.append(backend_name)
 
-        for field_name in contact_data:
+        for field_name in entry_data:
             try:
                 if field_name.startswith('_'):
                     raise KeyError
                 for field in self._field_idx[field_name]:
                     if self._fields[field][3]==backend_name:
-                        self._fields[field][1]=contact_data[field_name]
+                        self._fields[field][1]=entry_data[field_name]
                     else:
-                        self._fields.append([field_name, contact_data[field_name], '', backend_name])
+                        self._fields.append([field_name, entry_data[field_name], '', backend_name])
                         self._field_idx[field_name].append(len(self._fields)-1)
             except KeyError:
-                field_value = contact_data[field_name]
+                field_value = entry_data[field_name]
 
                 # We only generate compare values for specific fields
                 compare_value = ""
@@ -281,11 +281,11 @@ class Contact():
 
 
     def get_content(self):
-        """Creates and returns a complete representation of the contact
+        """Creates and returns a complete representation of the entry
         @note Backend information is omitted.
         @note Fields that have more than one occurence are concatenated using a separation character of ','.
 
-        @return Contact data, in {Field_name:Field_value} notation"""
+        @return entry data, in {Field_name:Field_value} notation"""
 
         fields = self.get_fields(self._field_idx)
         content = {}
@@ -294,18 +294,17 @@ class Contact():
                 content[field] = fields[field]
         return content
 
+    def attempt_merge(self, entry_fields, backend_name):
+        """Attempts to merge the given entry into the entry list and returns its ID
 
-    def attempt_merge(self, contact_fields, backend_name):
-        """Attempts to merge the given contact into the contact list and returns its ID
-
-        @param contact_fields Contact data; format: ((Key,Value), (Key,Value), ...)
-        @param backend_name Backend that owns the contact data
+        @param entry_fields entry data; format: {Key:Value, Key:Value, ...}
+        @param backend_name Backend that owns the entry data
         @return True on successful merge, False otherwise"""
 
         duplicated = True
-        for field_name in contact_fields:
+        for field_name in entry_fields:
             try:
-                if self[field_name]!=contact_fields[field_name]:
+                if self[field_name]!=entry_fields[field_name]:
                     duplicated = False
                     break
             except KeyError:
@@ -313,38 +312,13 @@ class Contact():
                 break
 
         if duplicated:
-            return True # That contacts exists, so we doesn't have to do anything to have it merged.
-
-        # Don't merge if we already have data from $backend_name as one backend can't contain two mergeable contacts
-        if backend_name in self._used_backends:
-            return False
-
-        merge = [1, 0]
-        for field_name in contact_fields:
-            if not field_name.startswith('_'):
-                if field_name!='Path':
-                    field_value=contact_fields[field_name]
-                    try:
-                        if self[field_name]!=field_value:
-                            merge[0] = 0
-                            break
-                        else:
-                            merge[1] = 1
-                    except KeyError:
-                        pass
-
-        if merge[0]:
-            if merge[1]:
-                self.import_fields(contact_fields, backend_name)
-                return True
-            else:
-                return False
+            return True # That entry exists, so we doesn't have to do anything to have it merged.
         else:
-            return False
+            return False # TODO: implement merging!
 
 
     def incorporates_data_from(self, backend_name):
-        """Determines whether this contact entry has data from a specific backend saved
+        """Determines whether this entry has data from a specific backend saved
 
         @param backend_name Name of backend to look for
         @return True if we have data belonging to that backend, False otherwise"""
@@ -353,7 +327,7 @@ class Contact():
 
 
     def match_query(self, query_obj):
-        """Checks whether this contact matches the given query
+        """Checks whether this entry matches the given query
 
         @param query_obj Dict containing key/value pairs of the required matches
         @return Accuracy of the match, ranging from 0.0 (no match) to 1.0 (complete match)"""
@@ -370,7 +344,7 @@ class Contact():
             matcher = re.compile(field_value)
             seq2_len = len(field_value)
 
-            # Check if field value(s) of this contact match(es) the query field
+            # Check if field value(s) of this entry match(es) the query field
             try:
                 field_ids = self._field_idx[field_name]
 
@@ -395,10 +369,10 @@ class Contact():
                         field_match = float(match_len) / len(comp_value)
 
                     if field_match > best_field_match: best_field_match = field_match
-                    logger.debug("Contacts: Field match for %s / %s: %f", comp_value, field_value, field_match)
+                    logger.debug("%s: Field match for %s / %s: %f", _DOMAIN_NAME, comp_value, field_value, field_match)
 
             except KeyError:
-                # Contact has no data for this field contained in the query, so this entry cannot match
+                # entry has no data for this field contained in the query, so this entry cannot match
                 return 0.0
 
             # Aggregate the field match value into the overall match
@@ -416,33 +390,33 @@ class Contact():
 #----------------------------------------------------------------------------#
 class SingleQueryHandler(object):
 #----------------------------------------------------------------------------#
-    _contacts = None
+    _entries = None
     query = None      # The query this handler is processing
     entries = None
     cursors = None    # The next entry we'll serve, depending on the client calling us
 
-    def __init__(self, query, contacts, dbus_sender):
+    def __init__(self, query, entries, dbus_sender):
         """Creates a new SingleQueryHandler instance
 
         @param query Query to evaluate
-        @param contacts Set of Contact objects to use
+        @param entries Set of Entry objects to use
         @param dbus_sender Sender's unique name on the bus"""
 
         self.query = query
         self.sanitize_query()
 
-        matcher = ContactQueryMatcher(self.query)
+        matcher = QueryMatcher(self.query)
 
-        self._contacts = contacts
-        self.entries = matcher.match(self._contacts)
+        self._entries = entries
+        self.entries = matcher.match(self._entries)
         self.cursors = {}
 
-        # TODO Register with all contacts to receive updates
+        # TODO Register with all entries to receive updates
 
 
     def dispose(self):
-        """Unregisters from all contact entries to allow this instance to be eaten by GC"""
-        # TODO Unregister from all contacts
+        """Unregisters from all entries to allow this instance to be eaten by GC"""
+        # TODO Unregister from all entries
         pass
 
 
@@ -451,7 +425,7 @@ class SingleQueryHandler(object):
 
         # For get_result_and_advance():
         # Make sure the _result_fields list has no whitespaces, e.g. "a, b, c" should be "a,b,c"
-        # Reasoning: Contact.get_fields() has no fuzzy matching for performance reasons
+        # Reasoning: entry.get_fields() has no fuzzy matching for performance reasons
         # Also, we remove any empty list elements created by e.g. "a, b, c,"
         try:
             field_list = self.query['_result_fields']
@@ -494,11 +468,11 @@ class SingleQueryHandler(object):
         self.cursors[dbus_sender] += num_entries
 
 
-    def get_contact_path(self, dbus_sender):
-        """Determines the Path of the next contact that the cursor points at and advances to the next result entry
+    def get_entry_path(self, dbus_sender):
+        """Determines the Path of the next entry that the cursor points at and advances to the next result entry
 
         @param dbus_sender Sender's unique name on the bus
-        @return Path of the contact"""
+        @return Path of the entry"""
 
         # If the sender is not in the list of cursors it just means that it is starting to iterate
         if not self.cursors.has_key(dbus_sender): self.cursors[dbus_sender] = 0
@@ -507,17 +481,17 @@ class SingleQueryHandler(object):
         try:
             result = self.entries[self.cursors[dbus_sender]]
         except IndexError:
-            raise NoMoreContacts( "All results have been submitted" )
+            raise NoMoreEntries( "All results have been submitted" )
 
-        contact_id = self.entries[self.cursors[dbus_sender]]
-        contact = self._contacts[contact_id]
+        entry_id = self.entries[self.cursors[dbus_sender]]
+        entry = self._entries[entry_id]
         self.cursors[dbus_sender] += 1
 
-        return contact['Path']
+        return entry['Path']
 
 
     def get_result(self, dbus_sender):
-        """Extracts the requested fields from the next contact entry in the result set and advances the cursor
+        """Extracts the requested fields from the next entry in the result set and advances the cursor
 
         @param dbus_sender Sender's unique name on the bus
         @return Dict containing field_name/field_value pairs"""
@@ -529,18 +503,18 @@ class SingleQueryHandler(object):
         try:
             result = self.entries[self.cursors[dbus_sender]]
         except IndexError:
-            raise NoMoreContacts( "All results have been submitted" )
+            raise NoMoreEntries( "All results have been submitted" )
 
-        contact_id = self.entries[self.cursors[dbus_sender]]
-        contact = self._contacts[contact_id]
+        entry_id = self.entries[self.cursors[dbus_sender]]
+        entry = self._entries[entry_id]
         self.cursors[dbus_sender] += 1
 
         try:
             fields = self.query['_result_fields']
             field_list = fields.split(',')
-            result = contact.get_fields(field_list)
+            result = entry.get_fields(field_list)
         except KeyError:
-            result = contact.get_content()
+            result = entry.get_content()
 
         return result
 
@@ -559,28 +533,28 @@ class SingleQueryHandler(object):
             try:
                 entry = self.get_result(dbus_sender)
                 result.append(entry)
-            except NoMoreContacts:
+            except NoMoreEntries:
                 """Don't want to raise an error in that case"""
                 break
 
         return result
 
 
-    def check_new_contact(self, contact_id):
-        """Checks whether a newly added contact matches this so it can signal clients
+    def check_new_entry(self, entry_id):
+        """Checks whether a newly added entry matches this so it can signal clients
 
-        @param contact_id Contact ID of the contact that was added
-        @return True if contact matches this query, False otherwise
+        @param entry_id entry ID of the entry that was added
+        @return True if entry matches this query, False otherwise
 
         @todo Currently this messes up the order of the result set if a specific order was desired"""
 
         result = False
 
-        matcher = ContactQueryMatcher(self.query)
-        if matcher.single_contact_matches():
-            self.entries = matcher.match(self._contacts)
+        matcher = QueryMatcher(self.query)
+        if matcher.single_entry_matches():
+            self.entries = matcher.match(self._entries)
 
-            # TODO Register with the new contact to receive changes
+            # TODO Register with the new entry to receive changes
 
             # We *should* reset all cursors *if* the result set is ordered, however
             # in order to prevent confusion, this is left for the client to do.
@@ -598,17 +572,17 @@ class SingleQueryHandler(object):
 class QueryManager(DBusFBObject):
 #----------------------------------------------------------------------------#
     _queries = None
-    _contacts = None
+    _entries = None
     _next_query_id = None
 
     # Note: _queries must be a dict so we can remove queries without messing up query IDs
 
-    def __init__(self, contacts):
+    def __init__(self, entries):
         """Creates a new QueryManager instance
 
-        @param contacts Set of Contact objects to use"""
+        @param entries Set of entry objects to use"""
 
-        self._contacts = contacts
+        self._entries = entries
         self._queries = {}
         self._next_query_id = 0
 
@@ -616,7 +590,7 @@ class QueryManager(DBusFBObject):
         DBusFBObject.__init__( self, conn=busmap["opimd"], object_path=_DBUS_PATH_QUERIES )
 
         # Still necessary?
-        self.interface = _DIN_CONTACTS
+        self.interface = _DIN_ENTRIES
         self.path = _DBUS_PATH_QUERIES
 
 
@@ -627,7 +601,7 @@ class QueryManager(DBusFBObject):
         @param dbus_sender Sender's unique name on the bus
         @return dbus path of the query result"""
 
-        query_handler = SingleQueryHandler(query, self._contacts, dbus_sender)
+        query_handler = SingleQueryHandler(query, self._entries, dbus_sender)
 
         query_id = self._next_query_id
         self._next_query_id += 1
@@ -637,17 +611,17 @@ class QueryManager(DBusFBObject):
         return _DBUS_PATH_QUERIES + '/' + str(query_id)
 
 
-    def check_new_contact(self, contact_id):
-        """Checks whether a newly added contact matches one or more queries so they can signal clients
+    def check_new_entry(self, entry_id):
+        """Checks whether a newly added entry matches one or more queries so they can signal clients
 
-        @param contact_id Contact ID of the contact that was added"""
+        @param entry_id entry ID of the entry that was added"""
 
         for (query_id, query_handler) in self._queries.items():
-            if query_handler.check_new_contact(contact_id):
-                contact = self._contacts[contact_id]
-                contact_path = contact['Path']
-                # TODO Figure out how relative signals really work
-                # self.ContactAdded(query_id, contact_path)
+            if query_handler.check_new_entry(call_id):
+                entry = self._entries[entry_id]
+                entry_path = entry['Path']
+                # TODO: make it working! :)
+                # self.callAdded(query_id, call_path)
 
     def check_query_id_ok( self, num_id ):
         """
@@ -681,11 +655,11 @@ class QueryManager(DBusFBObject):
 
 
     @dbus_method(_DIN_QUERY, "", "s", rel_path_keyword="rel_path", sender_keyword="sender")
-    def GetContactPath(self, rel_path, sender):
+    def GetEntryPath(self, rel_path, sender):
         num_id = int(rel_path[1:])
         self.check_query_id_ok( num_id )
 
-        return self._queries[num_id].get_contact_path(sender)
+        return self._queries[num_id].get_entry_path(sender)
 
 
     @dbus_method(_DIN_QUERY, "", "a{sv}", rel_path_keyword="rel_path", sender_keyword="sender")
@@ -715,27 +689,28 @@ class QueryManager(DBusFBObject):
         self._queries.__delitem__(num_id)
 
 #----------------------------------------------------------------------------#
-class ContactDomain(Domain):
+class GenericDomain(Domain):
 #----------------------------------------------------------------------------#
     name = _DOMAIN_NAME
 
+    _dbus_path = _DBUS_PATH_DOMAIN
     _backends = None
-    _contacts = None
+    _entries = None
     query_manager = None
 
     def __init__(self):
-        """Creates a new ContactDomain instance"""
+        """Creates a new GenericDomain instance"""
 
         self._backends = {}
-        self._contacts = []
-        self.query_manager = QueryManager(self._contacts)
+        self._entries = []
+        self.query_manager = QueryManager(self._entries)
 
         # Initialize the D-Bus-Interface
-        super(ContactDomain, self).__init__( conn=busmap["opimd"], object_path=_DBUS_PATH_CONTACTS )
+        super(GenericDomain, self).__init__( conn=busmap["opimd"], object_path=self._dbus_path )
 
-        # Keep frameworkd happy, pyneo won't care
-        self.interface = _DIN_CONTACTS
-        self.path = _DBUS_PATH_CONTACTS
+        # Keep frameworkd happy
+        self.interface = _DIN_ENTRIES
+        self.path = _DBUS_PATH_ENTRIES
 
 
     def get_dbus_objects(self):
@@ -754,66 +729,64 @@ class ContactDomain(Domain):
         self._backends[backend.name] = backend
 
 
-    def register_contact(self, backend, contact_data):
-        """Merges/inserts the given contact into the contact list and returns its ID
+    def register_entry(self, backend, entry_data):
+        """Merges/inserts the given entry into the entry list and returns its ID
 
         @param backend Backend objects that requests the registration
-        @param contact_data Contact data; format: [Key:Value, Key:Value, ...]"""
+        @param entry_data entry data; format: {Key:Value, Key:Value, ...}"""
 
-        contact_id = -1
+        entry_id = -1
         merged = 0
 
-        # Check if the contact can be merged with one we already know of
-        if int(config.getValue('opimd', 'contacts_merging_enabled', default='1')):
-            for entry in self._contacts:
+        # Check if the entry can be merged with one we already know of
+        if int(config.getValue('opimd', name.lower()+'_merging_enabled', default='1')):
+            for entry in self._entries:
                 if entry:
-                    if entry.attempt_merge(contact_data, backend.name):
+                    if entry.attempt_merge(entry_data, backend.name):
 
                         # Find that entry's ID
-                        for (contact_idx, contact) in enumerate(self._contacts):
-                            if contact == entry: contact_id = contact_idx
+                        for (entry_idx, ent) in enumerate(self._entries):
+                            if ent == entry: entry_id = entry_idx
                             break
 
                         # Stop trying to merge
                         merged = 1
                         break
         if not merged:
-            # Merging failed, so create a new contact entry and append it to the list
-            contact_id = len(self._contacts)
+            # Merging failed, so create a new entry and append it to the list
+            entry_id = len(self._entries)
 
-            path = _DBUS_PATH_CONTACTS+ '/' + str(contact_id)
-            contact = Contact(path)
-            contact.import_fields(contact_data, backend.name)
+            path = self._dbus_path+ '/' + str(entry_id)
+            entry = Entry(path)
+            entry.import_fields(entry_data, backend.name)
 
-            self._contacts.append(contact)
+            self._entries.append(entry)
 
-            self.NewContact(path)
-
-        return contact_id
+            self.NewEntry(path)
 
+        return entry_id
 
     def enumerate_items(self, backend):
-        """Enumerates all contact data belonging to a specific backend
-
-        @param backend Backend object whose contacts should be enumerated
-        @return Lists of (field_name,field_value) tuples of all contacts that have data from this particular backend"""
+        """Enumerates all entry data belonging to a specific backend
 
-        for contact in self._contacts:
-            if contact:
-                if contact.incorporates_data_from(backend.name):
-                    yield contact.export_fields(backend.name)
+        @param backend Backend object whose entries should be enumerated
+        @return Lists of (field_name,field_value) tuples of all entries that have data from this particular backend"""
 
+        for entry in self._entries:
+            if entry:
+                if entry.incorporates_data_from(backend.name):
+                    yield entry.export_fields(backend.name)
 
-    @dbus_signal(_DIN_CONTACTS, "s")
-    def NewContact(self, path):
+    @dbus_signal(_DIN_ENTRIES, "s")
+    def NewEntry(self, path):
         pass
 
-    @dbus_method(_DIN_CONTACTS, "a{sv}", "s")
-    def Add(self, contact_data):
-        """Adds a contact to the list, assigning it to the default backend and saving it
+    @dbus_method(_DIN_ENTRIES, "a{sv}", "s")
+    def Add(self, entry_data):
+        """Adds a entry to the list, assigning it to the default backend and saving it
 
-        @param contact_data List of fields; format is [Key:Value, Key:Value, ...]
-        @return Path of the newly created d-bus contact object"""
+        @param entry_data List of fields; format is [Key:Value, Key:Value, ...]
+        @return Path of the newly created d-bus call object"""
 
         # We use the default backend for now
         backend = BackendManager.get_default_backend(_DOMAIN_NAME)
@@ -823,22 +796,23 @@ class ContactDomain(Domain):
             raise InvalidBackend( "Backend properties not including PIMB_CAN_ADD_ENTRY" )
 
         try:
-            contact_id = backend.add_contact(contact_data)
+            entry_id = backend.add_entry(entry_data)
         except AttributeError:
-            raise InvalidBackend( "Backend does not feature add_contact" )
+            raise InvalidBackend( "Backend does not feature add_entry" )
 
-        contact = self._contacts[contact_id]
-        result = contact['Path']
+        entry = self._entries[entry_id]
+        result = entry['Path']
 
-        # As we just added a new contact, we check it against all queries to see if it matches
+        # As we just added a new entry, we check it against all queries to see if it matches
         # XXX: I comment this out because it doesn't work : Charlie
-        # self.query_manager.check_new_contact(contact_id)
+        # TODO: uncomment it
+        # self.query_manager.check_new_entry(call_id)
 
         return result
 
-    @dbus_method(_DIN_CONTACTS, "a{sv}s", "s")
-    def GetSingleContactSingleField(self, query, field_name):
-        """Returns the first contact found for a query, making it real easy to query simple things
+    @dbus_method(_DIN_ENTRIES, "a{sv}s", "s")
+    def GetSingleEntrySingleField(self, query, field_name):
+        """Returns the first entry found for a query, making it real easy to query simple things
 
         @param query The query object
         @param field_name The name of the field to return
@@ -846,15 +820,15 @@ class ContactDomain(Domain):
 
         result = ""
 
-        # Only return one contact
+        # Only return one entry
         query['_limit'] = 1
-        matcher = ContactQueryMatcher(query)
-        res = matcher.match(self._contacts)
+        matcher = QueryMatcher(query)
+        res = matcher.match(self._entries)
 
         # Copy all requested fields if we got a result
         if len(res) > 0:
-            contact = self._contacts[res[0]]
-            result = contact[field_name]
+            entry = self._entries[res[0]]
+            result = entry[field_name]
 
             # Merge results if we received multiple results
             if isinstance(result, list):
@@ -863,13 +837,13 @@ class ContactDomain(Domain):
         return result
 
 
-    @dbus_method(_DIN_CONTACTS, "a{sv}", "s", sender_keyword="sender")
+    @dbus_method(_DIN_ENTRIES, "a{sv}", "s", sender_keyword="sender")
     def Query(self, query, sender):
         """Processes a query and returns the dbus path of the resulting query object
 
         @param query Query
         @param sender Unique name of the query sender on the bus
-        @return dbus path of the query object, e.g. /org.pyneo.PIM/Contacts/Queries/4"""
+        @return dbus path of the query object, e.g. /org.freesmartphone.PIM/Entries/Queries/4"""
 
         return self.query_manager.process_query(query, sender)
 
@@ -878,30 +852,30 @@ class ContactDomain(Domain):
     def GetContent(self, rel_path):
         num_id = int(rel_path[1:])
 
-        # Make sure the requested contact exists
-        if num_id >= len(self._contacts) or self._contacts[num_id]==None:
-            raise InvalidContactID()
+        # Make sure the requested entry exists
+        if num_id >= len(self._entries) or self._entries[num_id]==None:
+            raise InvalidEntryID()
 
-        return self._contacts[num_id].get_content()
+        return self._entries[num_id].get_content()
 
     @dbus_method(_DIN_ENTRY, "", "as", rel_path_keyword="rel_path")
     def GetUsedBackends(self, rel_path):
         num_id = int(rel_path[1:])
                 
-        # Make sure the requested contact exists
-        if num_id >= len(self._contacts) or self._contacts[num_id]==None:
-            raise InvalidContactID()
+        # Make sure the requested entry exists
+        if num_id >= len(self._entries) or self._entries[num_id]==None:
+            raise InvalidEntryID()
         
-        return self._contacts[num_id]._used_backends
+        return self._entries[num_id]._used_backends
 
 
     @dbus_method(_DIN_ENTRY, "s", "a{sv}", rel_path_keyword="rel_path")
     def GetMultipleFields(self, field_list, rel_path):
         num_id = int(rel_path[1:])
 
-        # Make sure the requested contact exists
-        if num_id >= len(self._contacts) or self._contacts[num_id]==None:
-            raise InvalidContactID()
+        # Make sure the requested entry exists
+        if num_id >= len(self._entries) or self._entries[num_id]==None:
+            raise InvalidEntryID()
 
         # Break the string up into a list
         fields = field_list.split(',')
@@ -912,21 +886,21 @@ class ContactDomain(Domain):
             field_name = field_name.strip()
             if field_name: new_field_list.append(field_name)
 
-        return self._contacts[num_id].get_fields(new_field_list)
+        return self._entries[num_id].get_fields(new_field_list)
 
     @dbus_signal(_DIN_ENTRY, "", rel_path_keyword="rel_path")
-    def ContactDeleted(self, rel_path=None):
+    def EntryDeleted(self, rel_path=None):
         pass
 
     @dbus_method(_DIN_ENTRY, "", "", rel_path_keyword="rel_path")
     def Delete(self, rel_path):
         num_id = int(rel_path[1:])
 
-        # Make sure the requested contact exists
-        if num_id >= len(self._contacts) or self._contacts[num_id]==None:
-            raise InvalidContactID()
+        # Make sure the requested entry exists
+        if num_id >= len(self._entries) or self._entries[num_id]==None:
+            raise InvalidEntryID()
 
-        backends = self._contacts[num_id]._used_backends
+        backends = self._entries[num_id]._used_backends
 
         for backend_name in backends:
             backend = self._backends[backend_name]
@@ -934,21 +908,21 @@ class ContactDomain(Domain):
                 raise InvalidBackend( "Backend properties not including PIMB_CAN_DEL_ENTRY" )
 
             try:
-                backend.del_contact(self._contacts[num_id].export_fields(backend_name))
+                backend.del_entry(self._entries[num_id].export_fields(backend_name))
             except AttributeError:
-                raise InvalidBackend( "Backend does not feature del_contact" )
+                raise InvalidBackend( "Backend does not feature del_entry" )
 
-        #del self._contacts[num_id]
+        #del self._entries[num_id]
         # Experimental: it may introduce some bugs.
-        contact = self._contacts[num_id]
-        self._contacts[num_id] = None
-        del contact
+#        entry = self._entries[num_id]
+        self._entries[num_id] = None
+#        del entry
 
         # update Path fields, as IDs may be changed - UGLYYYY!!! */me spanks himself*
         # Not needed with that "experimental" code above.
-        #for id in range(0,len(self._contacts)):
-        #    path = _DBUS_PATH_CONTACTS+ '/' + str(id)
-        #    for field in self._contacts[id]._fields:
+        #for id in range(0,len(self._entries)):
+        #    path = _DBUS_PATH_ENTRIES+ '/' + str(id)
+        #    for field in self._entries[id]._fields:
         #        if field[0]=='Path':
         #            field[1]=path
 
@@ -957,61 +931,62 @@ class ContactDomain(Domain):
             if PIMB_NEEDS_SYNC in backend.properties:
                 backend.sync() # If backend needs - sync entries
 
-        self.ContactDeleted(rel_path=rel_path)
+        self.EntryDeleted(rel_path=rel_path)
 
     @dbus_signal(_DIN_ENTRY, "a{sv}", rel_path_keyword="rel_path")
-    def ContactUpdated(self, data, rel_path=None):
+    def EntryUpdated(self, data, rel_path=None):
         pass
 
     @dbus_method(_DIN_ENTRY, "a{sv}", "", rel_path_keyword="rel_path")
     def Update(self, data, rel_path):
         num_id = int(rel_path[1:])
 
-        # Make sure the requested contact exists
-        if num_id >= len(self._contacts) or self._contacts[num_id]==None:
-            raise InvalidContactID()
+        # Make sure the requested entry exists
+        if num_id >= len(self._entries) or self._entries[num_id]==None:
+            raise InvalidEntryID()
 
-        contact = self._contacts[num_id]
+        entryif = self._entries[num_id]
+        entry = entryif.get_fields(entryif._field_idx)
 
         default_backend = BackendManager.get_default_backend(_DOMAIN_NAME)
         
         # Search for backend in which we can store new fields
         backend = ''
-        if default_backend.name in contact._used_backends:
+        if default_backend.name in entryif._used_backends:
             backend = default_backend.name
         else:
-            for backend_name in contact._used_backends:
+            for backend_name in entryif._used_backends:
                 if PIMB_CAN_UPD_ENTRY_WITH_NEW_FIELD in self._backends[backend_name].properties:
                     backend = self._backends[backend_name]
                     break
 
-        # TODO: implement adding new data to backend, which doesn't incorporate contact data
+        # TODO: implement adding new data to backend, which doesn't incorporate entry data
         # For instance: we have SIM contact with Name and Phone. We want to add "Birthday" field.
-        # opimd should then try to add "Birthday" field to default backend and then merge contacts.
+        # opimd should then try to add "Birthday" field to default backend and then merge calls.
 
         for field_name in data:
-            if not field_name in contact._field_idx:
+            if not field_name in entryif._field_idx:
                 if backend!='':
-                    contact.import_fields({field_name:data[field_name]}, backend)
+                    entryif.import_fields({field_name:data[field_name]}, backend)
                 else:
                     raise InvalidBackend( "There is no backend which can store new field" )
             elif not field_name.startswith('_'):
-                for field_nr in contact._field_idx[field_name]:
-                    if contact[field_name]!=data[field_name]:
-                        contact._fields[field_nr][1]=data[field_name]
+                for field_nr in entryif._field_idx[field_name]:
+                    if entry[field_name]!=data[field_name]:
+                        entryif._fields[field_nr][1]=data[field_name]
 
-        for backend_name in contact._used_backends:
+        for backend_name in entryif._used_backends:
             backend = self._backends[backend_name]
             if not PIMB_CAN_UPD_ENTRY in backend.properties:
                 raise InvalidBackend( "Backend properties not including PIMB_CAN_UPD_ENTRY" )
             try:
-                backend.upd_contact(contact.export_fields(backend_name))
+                backend.upd_entry(entryif.export_fields(backend_name))
             except AttributeError:
-                raise InvalidBackend( "Backend does not feature upd_contact" )
+                raise InvalidBackend( "Backend does not feature upd_entry" )
 
             if PIMB_NEEDS_SYNC in backend.properties:
                 backend.sync() # If backend needs - sync entries
 
 
-        self.ContactUpdated(data, rel_path=rel_path)
+        self.EntryUpdated(data, rel_path=rel_path)
 

-- 
FSO frameworkd Debian packaging



More information about the pkg-fso-commits mailing list