Helpviewer/Sync/SyncHandler.py

changeset 1701
9eee32bac32e
parent 1700
40c911b8c0dd
child 2302
f29e9405c851
equal deleted inserted replaced
1700:40c911b8c0dd 1701:9eee32bac32e
156 """ 156 """
157 Public method to shut down the handler. 157 Public method to shut down the handler.
158 """ 158 """
159 raise NotImplementedError 159 raise NotImplementedError
160 160
161 def readFile(self, fileName): 161 def readFile(self, fileName, type_):
162 """ 162 """
163 Public method to read a file. 163 Public method to read a file.
164 164
165 If encrypted synchronization is enabled, the data will be encrypted using 165 If encrypted synchronization is enabled, the data will be encrypted using
166 the relevant encryption key. 166 the relevant encryption key.
167 167
168 @param fileName name of the file to be read (string) 168 @param fileName name of the file to be read (string)
169 @param type_ type of the synchronization event (string one
170 of "bookmarks", "history", "passwords", "useragents" or "speeddial")
169 @return data of the file, optionally encrypted (QByteArray) 171 @return data of the file, optionally encrypted (QByteArray)
170 """ 172 """
171 if os.path.exists(fileName): 173 if os.path.exists(fileName):
172 try: 174 try:
173 inputFile = open(fileName, "rb") 175 inputFile = open(fileName, "rb")
174 data = inputFile.read() 176 data = inputFile.read()
175 inputFile.close() 177 inputFile.close()
176 except IOError: 178 except IOError:
177 return QByteArray() 179 return QByteArray()
178 180
179 if Preferences.getHelp("SyncEncryptData"): 181 if Preferences.getHelp("SyncEncryptData") and \
182 (not Preferences.getHelp("SyncEncryptPasswordsOnly") or \
183 (Preferences.getHelp("SyncEncryptPasswordsOnly") and \
184 type_ == "passwords")):
180 key = Preferences.getHelp("SyncEncryptionKey") 185 key = Preferences.getHelp("SyncEncryptionKey")
181 if not key: 186 if not key:
182 return QByteArray() 187 return QByteArray()
183 188
184 data, ok = dataEncrypt(data, key, 189 data, ok = dataEncrypt(data, key,
189 194
190 return QByteArray(data) 195 return QByteArray(data)
191 196
192 return QByteArray() 197 return QByteArray()
193 198
194 def writeFile(self, data, fileName, timestamp=0): 199 def writeFile(self, data, fileName, type_, timestamp=0):
195 """ 200 """
196 Public method to write the data to a file. 201 Public method to write the data to a file.
197 202
198 If encrypted synchronization is enabled, the data will be decrypted using 203 If encrypted synchronization is enabled, the data will be decrypted using
199 the relevant encryption key. 204 the relevant encryption key.
200 205
201 @param data data to be written and optionally decrypted (QByteArray) 206 @param data data to be written and optionally decrypted (QByteArray)
202 @param fileName name of the file the data is to be written to (string) 207 @param fileName name of the file the data is to be written to (string)
208 @param type_ type of the synchronization event (string one
209 of "bookmarks", "history", "passwords", "useragents" or "speeddial")
203 @param timestamp timestamp to be given to the file (int) 210 @param timestamp timestamp to be given to the file (int)
204 @return tuple giving a success flag and an error string (boolean, string) 211 @return tuple giving a success flag and an error string (boolean, string)
205 """ 212 """
206 data = bytes(data) 213 data = bytes(data)
207 214
208 if Preferences.getHelp("SyncEncryptData"): 215 if Preferences.getHelp("SyncEncryptData") and \
216 (not Preferences.getHelp("SyncEncryptPasswordsOnly") or \
217 (Preferences.getHelp("SyncEncryptPasswordsOnly") and type_ == "passwords")):
209 key = Preferences.getHelp("SyncEncryptionKey") 218 key = Preferences.getHelp("SyncEncryptionKey")
210 if not key: 219 if not key:
211 return False, self.trUtf8("Invalid encryption key given.") 220 return False, self.trUtf8("Invalid encryption key given.")
212 221
213 data, ok = dataDecrypt(data, key, 222 data, ok = dataDecrypt(data, key,

eric ide

mercurial