Trees | Indices | Help |
|
---|
|
1 """ 2 Our own contact-entry-object. 3 4 This file is part of Pisi. 5 6 You should first read the corresponding Wiki side for development of contact modules: 7 U{https://projects.openmoko.org/plugins/wiki/index.php?ContactsAPI&id=156&type=g} 8 9 Besides the two classes for a Contact instance and an abstract synchronization module for contacts 10 you can find a method L{assembleID} in here, which should be used to assemble an ID for a contact 11 entry when loaded from the data source. This way, it is made sure, that all implementation use exactly 12 the same algorithm. (unfortunately, there is not option to have an additional attribute for this reason, 13 which is stored in all the data sources for the entry.) 14 15 Pisi is free software: you can redistribute it and/or modify 16 it under the terms of the GNU General Public License as published by 17 the Free Software Foundation, either version 3 of the License, or 18 (at your option) any later version. 19 20 Pisi is distributed in the hope that it will be useful, 21 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 GNU General Public License for more details. 24 25 You should have received a copy of the GNU General Public License 26 along with Pisi. If not, see <http://www.gnu.org/licenses/>. 27 """ 28 29 PHONE_PREFIX = "tel:" 30 31 import datetime 32 from pisiconstants import * 33 import pisiprogress 34 import pisiinterfaces 3537 """ 38 Holds information for a single contact instance. 39 """7241 """ 42 Initialize contact. 43 44 @param id: is the id the module uses to id the contact 45 @param attributes: a dictionary with attributes. 46 """ 47 pisiinterfaces.Syncable.__init__(self, id, attributes)4850 """ 51 Compares this entry with another one and checks, whether all attributes from this one have the same values in the other one and vice verse 52 53 @return: 0 if there is at least a single difference in attributes; 1 if all attributes are the same 54 """ 55 try: 56 for key in self.attributes.keys(): 57 if self.attributes[key] == None or self.attributes[key] == "": 58 # if attribute is there but not set, skip 59 continue 60 if not contactEntry.attributes[key] == self.attributes[key]: 61 return 0 62 63 for key in contactEntry.attributes.keys(): 64 if contactEntry.attributes[key] == None or contactEntry.attributes[key] == "": 65 # if attribute is there but not set, skip 66 continue 67 if not self.attributes[key] == contactEntry.attributes[key] : 68 return 0 69 except KeyError: 70 return 0 71 return 174 """ 75 Super class for all synchronization modules, which aim to synchronize contacts information. 76 77 Each Synchronization class implementing contact synchronization should inherit from this class. 78 @ivar _allContacts: Dictionary to hold all contact instance for the implementation. 79 @ivar _history: Keeps track of all changes applied to the container for this data source (for later write through) 80 """ 81168 16982 - def __init__(self, verbose, soft, modulesString, config, configsection, name = "unkown contact source"):83 """ 84 Constructor 85 86 Instance variables are initialized. 87 """ 88 pisiinterfaces.AbstractSynchronizationModule.__init__(self, verbose, soft, modulesString, config, configsection, name) 89 self._allContacts = self._allEntries 90 self._history = []9193 """ 94 Getter. 95 96 @return: The link to the instance variable L{_allContacts}. 97 """ 98 return self.allEntries()99101 """ 102 GETTER 103 104 @return: The link with the given ID. 105 """ 106 return self.getEntry(id)107109 """ 110 Remove all entries in repository 111 112 An entry in the history list (L{_history}) is appended for each entry in the contact list with action id for 'delete'. 113 Afterwards, the dictionary for all contacts (L{_allContacts}) is flushed. 114 """ 115 for id in self._allEntries.keys(): 116 self._history.append([ACTIONID_DELETE, id]) 117 pisiinterfaces.AbstractSynchronizationModule.flush(self) 118 self._allContacts = self._allEntries119121 """ 122 Saves a contact for later writing 123 124 One entry is added to the history list (L{_history}) with action id for 'add' and the new instance is stored in the contacts dictionary (L{_allContacts}). 125 """ 126 self.addEntry(contactInstance) 127 self._history.append([ACTIONID_ADD, contactInstance.getID()])128130 """ 131 Replaces an existing contact entry with a new one. 132 133 One entry is added to the history list (L{_history}) with action id for 'replace' and the old instance is replaced by the new one in the contacts dictionary (L{_allContacts}). 134 """ 135 pisiprogress.getCallback().verbose("We will replace contact %s" %(id)) 136 self.replaceEntry(id, updatedContact) 137 self._history.append([ACTIONID_MODIFY, id])138140 """ 141 Removes a contact entry 142 143 One entry is added to the history list (L{_history}) with action id for 'delete' and the instance is as well removed from the contacts dictionary (L{_allContacts}). 144 """ 145 pisiprogress.getCallback().verbose("We will delete contact %s" %(id)) 146 self.removeEntry(id) 147 self._history.append([ACTIONID_DELETE, id])148150 """ 151 Some sources do support prefixes in phone numbers (such as tel: or sip:), this supporting functions helps to add this information automatically 152 """ 153 for x in ['mobile', 'phone', 'officePhone']: 154 if atts.has_key(x) and atts[x] != None and atts[x].strip() != "": 155 atts[x] = PHONE_PREFIX + atts[x]156158 """ 159 Some sources do support prefixes in phone numbers (such as tel: or sip:), this supporting functions helps to remove this information automatically 160 """ 161 for x in ['mobile', 'phone', 'officePhone']: 162 if atts.has_key(x) and atts[x] != None: 163 if atts[x].startswith(PHONE_PREFIX): 164 try: 165 atts[x] = atts[x][len(PHONE_PREFIX):] 166 except IndexError: 167 atts[x] = None # this is really stupid - only "tel:" in there171 """ 172 Supporing function which makes sure that the given value can be concatenated with other strings. 173 """ 174 try: 175 return "" + st 176 except TypeError: 177 return replacement178180 """ 181 Common way of creating a unique ID for each contact. 182 183 Current implementation assembles one by using firstName and lastName. 184 """ 185 return "@" + _safeString(contactAtts['firstname']) + "@" + _safeString(contactAtts['lastname']) + "@"186
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Fri Apr 2 09:04:25 2010 | http://epydoc.sourceforge.net |