28 class FtpSyncHandler(SyncHandler): |
29 class FtpSyncHandler(SyncHandler): |
29 """ |
30 """ |
30 Class implementing a synchronization handler using FTP. |
31 Class implementing a synchronization handler using FTP. |
31 |
32 |
32 @signal syncStatus(type_, message) emitted to indicate the synchronization |
33 @signal syncStatus(type_, message) emitted to indicate the synchronization |
33 status (string one of "bookmarks", "history", "passwords", "useragents" or |
34 status (string one of "bookmarks", "history", "passwords", |
34 "speeddial", string) |
35 "useragents" or "speeddial", string) |
35 @signal syncError(message) emitted for a general error with the error message (string) |
36 @signal syncError(message) emitted for a general error with the error |
36 @signal syncMessage(message) emitted to send a message about synchronization (string) |
37 message (string) |
37 @signal syncFinished(type_, done, download) emitted after a synchronization has |
38 @signal syncMessage(message) emitted to send a message about |
38 finished (string one of "bookmarks", "history", "passwords", "useragents" or |
39 synchronization (string) |
39 "speeddial", boolean, boolean) |
40 @signal syncFinished(type_, done, download) emitted after a |
|
41 synchronization has finished (string one of "bookmarks", "history", |
|
42 "passwords", "useragents" or "speeddial", boolean, boolean) |
40 """ |
43 """ |
41 syncStatus = pyqtSignal(str, str) |
44 syncStatus = pyqtSignal(str, str) |
42 syncError = pyqtSignal(str) |
45 syncError = pyqtSignal(str) |
43 syncMessage = pyqtSignal(str) |
46 syncMessage = pyqtSignal(str) |
44 syncFinished = pyqtSignal(str, bool, bool) |
47 syncFinished = pyqtSignal(str, bool, bool) |
164 # silently ignore parser errors |
169 # silently ignore parser errors |
165 urlInfo = None |
170 urlInfo = None |
166 |
171 |
167 if urlInfo and urlInfo.isValid() and urlInfo.isFile(): |
172 if urlInfo and urlInfo.isValid() and urlInfo.isFile(): |
168 if urlInfo.name() in self._remoteFiles.values(): |
173 if urlInfo.name() in self._remoteFiles.values(): |
169 self.__remoteFilesFound[urlInfo.name()] = urlInfo.lastModified() |
174 self.__remoteFilesFound[urlInfo.name()] = \ |
|
175 urlInfo.lastModified() |
170 |
176 |
171 QCoreApplication.processEvents() |
177 QCoreApplication.processEvents() |
172 |
178 |
173 def __downloadFile(self, type_, fileName, timestamp): |
179 def __downloadFile(self, type_, fileName, timestamp): |
174 """ |
180 """ |
175 Private method to downlaod the given file. |
181 Private method to downlaod the given file. |
176 |
182 |
177 @param type_ type of the synchronization event (string one |
183 @param type_ type of the synchronization event (string one |
178 of "bookmarks", "history", "passwords", "useragents" or "speeddial") |
184 of "bookmarks", "history", "passwords", "useragents" or |
|
185 "speeddial") |
179 @param fileName name of the file to be downloaded (string) |
186 @param fileName name of the file to be downloaded (string) |
180 @param timestamp time stamp in seconds of the file to be downloaded (int) |
187 @param timestamp time stamp in seconds of the file to be downloaded |
|
188 (integer) |
181 """ |
189 """ |
182 self.syncStatus.emit(type_, self._messages[type_]["RemoteExists"]) |
190 self.syncStatus.emit(type_, self._messages[type_]["RemoteExists"]) |
183 buffer = io.BytesIO() |
191 buffer = io.BytesIO() |
184 try: |
192 try: |
185 self.__ftp.retrbinary( |
193 self.__ftp.retrbinary( |
237 def __initialSyncFile(self, type_, fileName): |
246 def __initialSyncFile(self, type_, fileName): |
238 """ |
247 """ |
239 Private method to do the initial synchronization of the given file. |
248 Private method to do the initial synchronization of the given file. |
240 |
249 |
241 @param type_ type of the synchronization event (string one |
250 @param type_ type of the synchronization event (string one |
242 of "bookmarks", "history", "passwords", "useragents" or "speeddial") |
251 of "bookmarks", "history", "passwords", "useragents" or |
|
252 "speeddial") |
243 @param fileName name of the file to be synchronized (string) |
253 @param fileName name of the file to be synchronized (string) |
244 """ |
254 """ |
245 if not self.__forceUpload and \ |
255 if not self.__forceUpload and \ |
246 self._remoteFiles[type_] in self.__remoteFilesFound: |
256 self._remoteFiles[type_] in self.__remoteFilesFound: |
247 if QFileInfo(fileName).lastModified() < \ |
257 if QFileInfo(fileName).lastModified() < \ |
248 self.__remoteFilesFound[self._remoteFiles[type_]]: |
258 self.__remoteFilesFound[self._remoteFiles[type_]]: |
249 self.__downloadFile(type_, fileName, |
259 self.__downloadFile( |
250 self.__remoteFilesFound[self._remoteFiles[type_]].toTime_t()) |
260 type_, fileName, |
|
261 self.__remoteFilesFound[self._remoteFiles[type_]] |
|
262 .toTime_t()) |
251 else: |
263 else: |
252 self.syncStatus.emit(type_, self.trUtf8("No synchronization required.")) |
264 self.syncStatus.emit( |
|
265 type_, self.trUtf8("No synchronization required.")) |
253 self.syncFinished.emit(type_, True, True) |
266 self.syncFinished.emit(type_, True, True) |
254 else: |
267 else: |
255 if self._remoteFiles[type_] not in self.__remoteFilesFound: |
268 if self._remoteFiles[type_] not in self.__remoteFilesFound: |
256 self.syncStatus.emit(type_, self._messages[type_]["RemoteMissing"]) |
269 self.syncStatus.emit( |
|
270 type_, self._messages[type_]["RemoteMissing"]) |
257 else: |
271 else: |
258 self.syncStatus.emit(type_, self._messages[type_]["LocalNewer"]) |
272 self.syncStatus.emit( |
|
273 type_, self._messages[type_]["LocalNewer"]) |
259 self.__uploadFile(type_, fileName) |
274 self.__uploadFile(type_, fileName) |
260 |
275 |
261 def __initialSync(self): |
276 def __initialSync(self): |
262 """ |
277 """ |
263 Private slot to do the initial synchronization. |
278 Private slot to do the initial synchronization. |
264 """ |
279 """ |
265 # Bookmarks |
280 # Bookmarks |
266 if Preferences.getHelp("SyncBookmarks"): |
281 if Preferences.getHelp("SyncBookmarks"): |
267 self.__initialSyncFile("bookmarks", |
282 self.__initialSyncFile( |
268 Helpviewer.HelpWindow.HelpWindow.bookmarksManager().getFileName()) |
283 "bookmarks", |
|
284 Helpviewer.HelpWindow.HelpWindow.bookmarksManager() |
|
285 .getFileName()) |
269 |
286 |
270 # History |
287 # History |
271 if Preferences.getHelp("SyncHistory"): |
288 if Preferences.getHelp("SyncHistory"): |
272 self.__initialSyncFile("history", |
289 self.__initialSyncFile( |
273 Helpviewer.HelpWindow.HelpWindow.historyManager().getFileName()) |
290 "history", |
|
291 Helpviewer.HelpWindow.HelpWindow.historyManager() |
|
292 .getFileName()) |
274 |
293 |
275 # Passwords |
294 # Passwords |
276 if Preferences.getHelp("SyncPasswords"): |
295 if Preferences.getHelp("SyncPasswords"): |
277 self.__initialSyncFile("passwords", |
296 self.__initialSyncFile( |
278 Helpviewer.HelpWindow.HelpWindow.passwordManager().getFileName()) |
297 "passwords", |
|
298 Helpviewer.HelpWindow.HelpWindow.passwordManager() |
|
299 .getFileName()) |
279 |
300 |
280 # User Agent Settings |
301 # User Agent Settings |
281 if Preferences.getHelp("SyncUserAgents"): |
302 if Preferences.getHelp("SyncUserAgents"): |
282 self.__initialSyncFile("useragents", |
303 self.__initialSyncFile( |
283 Helpviewer.HelpWindow.HelpWindow.userAgentsManager().getFileName()) |
304 "useragents", |
|
305 Helpviewer.HelpWindow.HelpWindow.userAgentsManager() |
|
306 .getFileName()) |
284 |
307 |
285 # Speed Dial Settings |
308 # Speed Dial Settings |
286 if Preferences.getHelp("SyncSpeedDial"): |
309 if Preferences.getHelp("SyncSpeedDial"): |
287 self.__initialSyncFile("speeddial", |
310 self.__initialSyncFile( |
|
311 "speeddial", |
288 Helpviewer.HelpWindow.HelpWindow.speedDial().getFileName()) |
312 Helpviewer.HelpWindow.HelpWindow.speedDial().getFileName()) |
289 |
313 |
290 self.__forceUpload = False |
314 self.__forceUpload = False |
291 |
315 |
292 def __syncFile(self, type_, fileName): |
316 def __syncFile(self, type_, fileName): |
293 """ |
317 """ |
294 Private method to synchronize the given file. |
318 Private method to synchronize the given file. |
295 |
319 |
296 @param type_ type of the synchronization event (string one |
320 @param type_ type of the synchronization event (string one |
297 of "bookmarks", "history", "passwords", "useragents" or "speeddial") |
321 of "bookmarks", "history", "passwords", "useragents" or |
|
322 "speeddial") |
298 @param fileName name of the file to be synchronized (string) |
323 @param fileName name of the file to be synchronized (string) |
299 """ |
324 """ |
300 if self.__state == "initializing": |
325 if self.__state == "initializing": |
301 return |
326 return |
302 |
327 |
304 if self.__connected: |
329 if self.__connected: |
305 self.__idleTimeout() |
330 self.__idleTimeout() |
306 if not self.__connected or self.__ftp.sock is None: |
331 if not self.__connected or self.__ftp.sock is None: |
307 ok = self.__connectAndLogin() |
332 ok = self.__connectAndLogin() |
308 if not ok: |
333 if not ok: |
309 self.syncStatus.emit(type_, self.trUtf8("Cannot log in to FTP host.")) |
334 self.syncStatus.emit( |
|
335 type_, self.trUtf8("Cannot log in to FTP host.")) |
310 return |
336 return |
311 |
337 |
312 # upload the changed file |
338 # upload the changed file |
313 self.__state = "uploading" |
339 self.__state = "uploading" |
314 self.syncStatus.emit(type_, self._messages[type_]["Uploading"]) |
340 self.syncStatus.emit(type_, self._messages[type_]["Uploading"]) |
315 if self.__uploadFile(type_, fileName): |
341 if self.__uploadFile(type_, fileName): |
316 self.syncStatus.emit(type_, self.trUtf8("Synchronization finished.")) |
342 self.syncStatus.emit( |
|
343 type_, self.trUtf8("Synchronization finished.")) |
317 self.__state = "idle" |
344 self.__state = "idle" |
318 |
345 |
319 def syncBookmarks(self): |
346 def syncBookmarks(self): |
320 """ |
347 """ |
321 Public method to synchronize the bookmarks. |
348 Public method to synchronize the bookmarks. |