29 "useragents" or "speeddial", string) |
29 "useragents" or "speeddial", string) |
30 @signal syncFinished(type_, done, download) emitted after a |
30 @signal syncFinished(type_, done, download) emitted after a |
31 synchronization has finished (string one of "bookmarks", "history", |
31 synchronization has finished (string one of "bookmarks", "history", |
32 "passwords", "useragents" or "speeddial", boolean, boolean) |
32 "passwords", "useragents" or "speeddial", boolean, boolean) |
33 """ |
33 """ |
|
34 |
34 syncError = pyqtSignal(str) |
35 syncError = pyqtSignal(str) |
35 syncMessage = pyqtSignal(str) |
36 syncMessage = pyqtSignal(str) |
36 syncStatus = pyqtSignal(str, str) |
37 syncStatus = pyqtSignal(str, str) |
37 syncFinished = pyqtSignal(str, bool, bool) |
38 syncFinished = pyqtSignal(str, bool, bool) |
38 |
39 |
39 def __init__(self, parent=None): |
40 def __init__(self, parent=None): |
40 """ |
41 """ |
41 Constructor |
42 Constructor |
42 |
43 |
43 @param parent reference to the parent object (QObject) |
44 @param parent reference to the parent object (QObject) |
44 """ |
45 """ |
45 super().__init__(parent) |
46 super().__init__(parent) |
46 |
47 |
47 self.__handler = None |
48 self.__handler = None |
48 |
49 |
49 def handler(self): |
50 def handler(self): |
50 """ |
51 """ |
51 Public method to get a reference to the sync handler object. |
52 Public method to get a reference to the sync handler object. |
52 |
53 |
53 @return reference to the sync handler object (SyncHandler) |
54 @return reference to the sync handler object (SyncHandler) |
54 """ |
55 """ |
55 return self.__handler |
56 return self.__handler |
56 |
57 |
57 def showSyncDialog(self): |
58 def showSyncDialog(self): |
58 """ |
59 """ |
59 Public method to show the synchronization dialog. |
60 Public method to show the synchronization dialog. |
60 """ |
61 """ |
61 from .SyncAssistantDialog import SyncAssistantDialog |
62 from .SyncAssistantDialog import SyncAssistantDialog |
|
63 |
62 dlg = SyncAssistantDialog() |
64 dlg = SyncAssistantDialog() |
63 dlg.exec() |
65 dlg.exec() |
64 |
66 |
65 def loadSettings(self, forceUpload=False): |
67 def loadSettings(self, forceUpload=False): |
66 """ |
68 """ |
67 Public method to load the settings. |
69 Public method to load the settings. |
68 |
70 |
69 @param forceUpload flag indicating a forced upload of the files |
71 @param forceUpload flag indicating a forced upload of the files |
70 (boolean) |
72 (boolean) |
71 """ |
73 """ |
72 if self.__handler is not None: |
74 if self.__handler is not None: |
73 self.__handler.syncError.disconnect(self.__syncError) |
75 self.__handler.syncError.disconnect(self.__syncError) |
74 self.__handler.syncFinished.disconnect(self.__syncFinished) |
76 self.__handler.syncFinished.disconnect(self.__syncFinished) |
75 self.__handler.syncStatus.disconnect(self.__syncStatus) |
77 self.__handler.syncStatus.disconnect(self.__syncStatus) |
76 self.__handler.syncMessage.disconnect(self.syncMessage) |
78 self.__handler.syncMessage.disconnect(self.syncMessage) |
77 self.__handler.shutdown() |
79 self.__handler.shutdown() |
78 |
80 |
79 if self.syncEnabled(): |
81 if self.syncEnabled(): |
80 from . import SyncGlobals |
82 from . import SyncGlobals |
81 if ( |
83 |
82 Preferences.getWebBrowser("SyncType") == |
84 if Preferences.getWebBrowser("SyncType") == SyncGlobals.SyncTypeFtp: |
83 SyncGlobals.SyncTypeFtp |
|
84 ): |
|
85 from .FtpSyncHandler import FtpSyncHandler |
85 from .FtpSyncHandler import FtpSyncHandler |
|
86 |
86 self.__handler = FtpSyncHandler(self) |
87 self.__handler = FtpSyncHandler(self) |
87 elif ( |
88 elif Preferences.getWebBrowser("SyncType") == SyncGlobals.SyncTypeDirectory: |
88 Preferences.getWebBrowser("SyncType") == |
|
89 SyncGlobals.SyncTypeDirectory |
|
90 ): |
|
91 from .DirectorySyncHandler import DirectorySyncHandler |
89 from .DirectorySyncHandler import DirectorySyncHandler |
|
90 |
92 self.__handler = DirectorySyncHandler(self) |
91 self.__handler = DirectorySyncHandler(self) |
93 self.__handler.syncError.connect(self.__syncError) |
92 self.__handler.syncError.connect(self.__syncError) |
94 self.__handler.syncFinished.connect(self.__syncFinished) |
93 self.__handler.syncFinished.connect(self.__syncFinished) |
95 self.__handler.syncStatus.connect(self.__syncStatus) |
94 self.__handler.syncStatus.connect(self.__syncStatus) |
96 self.__handler.syncMessage.connect(self.syncMessage) |
95 self.__handler.syncMessage.connect(self.syncMessage) |
97 |
96 |
98 self.__handler.initialLoadAndCheck(forceUpload=forceUpload) |
97 self.__handler.initialLoadAndCheck(forceUpload=forceUpload) |
99 |
98 |
100 # connect sync manager to bookmarks manager |
99 # connect sync manager to bookmarks manager |
101 if Preferences.getWebBrowser("SyncBookmarks"): |
100 if Preferences.getWebBrowser("SyncBookmarks"): |
102 ( |
101 ( |
103 WebBrowserWindow.bookmarksManager() |
102 WebBrowserWindow.bookmarksManager().bookmarksSaved.connect( |
104 .bookmarksSaved.connect(self.__syncBookmarks) |
103 self.__syncBookmarks |
105 ) |
104 ) |
106 else: |
105 ) |
107 with contextlib.suppress(TypeError): |
106 else: |
108 ( |
107 with contextlib.suppress(TypeError): |
109 WebBrowserWindow.bookmarksManager() |
108 ( |
110 .bookmarksSaved.disconnect(self.__syncBookmarks) |
109 WebBrowserWindow.bookmarksManager().bookmarksSaved.disconnect( |
111 ) |
110 self.__syncBookmarks |
112 |
111 ) |
|
112 ) |
|
113 |
113 # connect sync manager to history manager |
114 # connect sync manager to history manager |
114 if Preferences.getWebBrowser("SyncHistory"): |
115 if Preferences.getWebBrowser("SyncHistory"): |
115 ( |
116 ( |
116 WebBrowserWindow.historyManager().historySaved |
117 WebBrowserWindow.historyManager().historySaved.connect( |
117 .connect(self.__syncHistory) |
118 self.__syncHistory |
118 ) |
119 ) |
119 else: |
120 ) |
120 with contextlib.suppress(TypeError): |
121 else: |
121 ( |
122 with contextlib.suppress(TypeError): |
122 WebBrowserWindow.historyManager() |
123 ( |
123 .historySaved.disconnect(self.__syncHistory) |
124 WebBrowserWindow.historyManager().historySaved.disconnect( |
124 ) |
125 self.__syncHistory |
125 |
126 ) |
|
127 ) |
|
128 |
126 # connect sync manager to passwords manager |
129 # connect sync manager to passwords manager |
127 if Preferences.getWebBrowser("SyncPasswords"): |
130 if Preferences.getWebBrowser("SyncPasswords"): |
128 ( |
131 ( |
129 WebBrowserWindow.passwordManager() |
132 WebBrowserWindow.passwordManager().passwordsSaved.connect( |
130 .passwordsSaved.connect(self.__syncPasswords) |
133 self.__syncPasswords |
131 ) |
134 ) |
132 else: |
135 ) |
133 with contextlib.suppress(TypeError): |
136 else: |
134 ( |
137 with contextlib.suppress(TypeError): |
135 WebBrowserWindow.passwordManager() |
138 ( |
136 .passwordsSaved.disconnect(self.__syncPasswords) |
139 WebBrowserWindow.passwordManager().passwordsSaved.disconnect( |
137 ) |
140 self.__syncPasswords |
138 |
141 ) |
|
142 ) |
|
143 |
139 # connect sync manager to user agent manager |
144 # connect sync manager to user agent manager |
140 if Preferences.getWebBrowser("SyncUserAgents"): |
145 if Preferences.getWebBrowser("SyncUserAgents"): |
141 ( |
146 ( |
142 WebBrowserWindow.userAgentsManager() |
147 WebBrowserWindow.userAgentsManager().userAgentSettingsSaved.connect( |
143 .userAgentSettingsSaved.connect(self.__syncUserAgents) |
148 self.__syncUserAgents |
144 ) |
149 ) |
145 else: |
150 ) |
146 with contextlib.suppress(TypeError): |
151 else: |
147 ( |
152 with contextlib.suppress(TypeError): |
148 WebBrowserWindow.userAgentsManager() |
153 uam = WebBrowserWindow.userAgentsManager() |
149 .userAgentSettingsSaved.disconnect( |
154 uam.userAgentSettingsSaved.disconnect(self.__syncUserAgents) |
150 self.__syncUserAgents) |
155 |
151 ) |
|
152 |
|
153 # connect sync manager to speed dial |
156 # connect sync manager to speed dial |
154 if Preferences.getWebBrowser("SyncSpeedDial"): |
157 if Preferences.getWebBrowser("SyncSpeedDial"): |
155 ( |
158 ( |
156 WebBrowserWindow.speedDial() |
159 WebBrowserWindow.speedDial().speedDialSaved.connect( |
157 .speedDialSaved.connect(self.__syncSpeedDial) |
160 self.__syncSpeedDial |
158 ) |
161 ) |
159 else: |
162 ) |
160 with contextlib.suppress(TypeError): |
163 else: |
161 ( |
164 with contextlib.suppress(TypeError): |
162 WebBrowserWindow.speedDial() |
165 ( |
163 .speedDialSaved.disconnect(self.__syncSpeedDial) |
166 WebBrowserWindow.speedDial().speedDialSaved.disconnect( |
|
167 self.__syncSpeedDial |
|
168 ) |
164 ) |
169 ) |
165 else: |
170 else: |
166 self.__handler = None |
171 self.__handler = None |
167 |
172 |
168 with contextlib.suppress(TypeError): |
173 with contextlib.suppress(TypeError): |
169 ( |
174 ( |
170 WebBrowserWindow.bookmarksManager() |
175 WebBrowserWindow.bookmarksManager().bookmarksSaved.disconnect( |
171 .bookmarksSaved.disconnect(self.__syncBookmarks) |
176 self.__syncBookmarks |
172 ) |
177 ) |
173 with contextlib.suppress(TypeError): |
178 ) |
174 ( |
179 with contextlib.suppress(TypeError): |
175 WebBrowserWindow.historyManager().historySaved |
180 ( |
176 .disconnect(self.__syncHistory) |
181 WebBrowserWindow.historyManager().historySaved.disconnect( |
177 ) |
182 self.__syncHistory |
178 with contextlib.suppress(TypeError): |
183 ) |
179 ( |
184 ) |
180 WebBrowserWindow.passwordManager() |
185 with contextlib.suppress(TypeError): |
181 .passwordsSaved.disconnect(self.__syncPasswords) |
186 ( |
182 ) |
187 WebBrowserWindow.passwordManager().passwordsSaved.disconnect( |
183 with contextlib.suppress(TypeError): |
188 self.__syncPasswords |
184 ( |
189 ) |
185 WebBrowserWindow.userAgentsManager() |
190 ) |
186 .userAgentSettingsSaved.disconnect(self.__syncUserAgents) |
191 with contextlib.suppress(TypeError): |
187 ) |
192 uam = WebBrowserWindow.userAgentsManager() |
|
193 uam.userAgentSettingsSaved.disconnect(self.__syncUserAgents) |
188 with contextlib.suppress(TypeError): |
194 with contextlib.suppress(TypeError): |
189 WebBrowserWindow.speedDial().speedDialSaved.disconnect( |
195 WebBrowserWindow.speedDial().speedDialSaved.disconnect( |
190 self.__syncSpeedDial) |
196 self.__syncSpeedDial |
191 |
197 ) |
|
198 |
192 def syncEnabled(self): |
199 def syncEnabled(self): |
193 """ |
200 """ |
194 Public method to check, if synchronization is enabled. |
201 Public method to check, if synchronization is enabled. |
195 |
202 |
196 @return flag indicating enabled synchronization |
203 @return flag indicating enabled synchronization |
197 """ |
204 """ |
198 from . import SyncGlobals |
205 from . import SyncGlobals |
|
206 |
199 return ( |
207 return ( |
200 Preferences.getWebBrowser("SyncEnabled") and |
208 Preferences.getWebBrowser("SyncEnabled") |
201 Preferences.getWebBrowser("SyncType") != SyncGlobals.SyncTypeNone |
209 and Preferences.getWebBrowser("SyncType") != SyncGlobals.SyncTypeNone |
202 ) |
210 ) |
203 |
211 |
204 def __syncBookmarks(self): |
212 def __syncBookmarks(self): |
205 """ |
213 """ |
206 Private slot to synchronize the bookmarks. |
214 Private slot to synchronize the bookmarks. |
207 """ |
215 """ |
208 if self.__handler is not None: |
216 if self.__handler is not None: |
209 self.__handler.syncBookmarks() |
217 self.__handler.syncBookmarks() |
210 |
218 |
211 def __syncHistory(self): |
219 def __syncHistory(self): |
212 """ |
220 """ |
213 Private slot to synchronize the history. |
221 Private slot to synchronize the history. |
214 """ |
222 """ |
215 if self.__handler is not None: |
223 if self.__handler is not None: |
216 self.__handler.syncHistory() |
224 self.__handler.syncHistory() |
217 |
225 |
218 def __syncPasswords(self): |
226 def __syncPasswords(self): |
219 """ |
227 """ |
220 Private slot to synchronize the passwords. |
228 Private slot to synchronize the passwords. |
221 """ |
229 """ |
222 if self.__handler is not None: |
230 if self.__handler is not None: |
223 self.__handler.syncPasswords() |
231 self.__handler.syncPasswords() |
224 |
232 |
225 def __syncUserAgents(self): |
233 def __syncUserAgents(self): |
226 """ |
234 """ |
227 Private slot to synchronize the user agent settings. |
235 Private slot to synchronize the user agent settings. |
228 """ |
236 """ |
229 if self.__handler is not None: |
237 if self.__handler is not None: |
230 self.__handler.syncUserAgents() |
238 self.__handler.syncUserAgents() |
231 |
239 |
232 def __syncSpeedDial(self): |
240 def __syncSpeedDial(self): |
233 """ |
241 """ |
234 Private slot to synchronize the speed dial settings. |
242 Private slot to synchronize the speed dial settings. |
235 """ |
243 """ |
236 if self.__handler is not None: |
244 if self.__handler is not None: |
237 self.__handler.syncSpeedDial() |
245 self.__handler.syncSpeedDial() |
238 |
246 |
239 def __syncError(self, message): |
247 def __syncError(self, message): |
240 """ |
248 """ |
241 Private slot to handle general synchronization issues. |
249 Private slot to handle general synchronization issues. |
242 |
250 |
243 @param message error message (string) |
251 @param message error message (string) |
244 """ |
252 """ |
245 self.syncError.emit(message) |
253 self.syncError.emit(message) |
246 |
254 |
247 def __syncFinished(self, type_, status, download): |
255 def __syncFinished(self, type_, status, download): |
248 """ |
256 """ |
249 Private slot to handle a finished synchronization event. |
257 Private slot to handle a finished synchronization event. |
250 |
258 |
251 @param type_ type of the synchronization event (string one |
259 @param type_ type of the synchronization event (string one |
252 of "bookmarks", "history", "passwords", "useragents" or |
260 of "bookmarks", "history", "passwords", "useragents" or |
253 "speeddial") |
261 "speeddial") |
254 @param status flag indicating success (boolean) |
262 @param status flag indicating success (boolean) |
255 @param download flag indicating a download of a file (boolean) |
263 @param download flag indicating a download of a file (boolean) |