21 class SyncHandler(QObject): |
21 class SyncHandler(QObject): |
22 """ |
22 """ |
23 Base class for synchronization handlers. |
23 Base class for synchronization handlers. |
24 |
24 |
25 @signal syncStatus(type_, message) emitted to indicate the synchronization |
25 @signal syncStatus(type_, message) emitted to indicate the synchronization |
26 status (string one of "bookmarks", "history", "passwords", "useragents" or |
26 status (string one of "bookmarks", "history", "passwords", |
27 "speeddial", string) |
27 "useragents" or "speeddial", string) |
28 @signal syncError(message) emitted for a general error with the error message (string) |
28 @signal syncError(message) emitted for a general error with the error |
29 @signal syncMessage(message) emitted to send a message about synchronization (string) |
29 message (string) |
30 @signal syncFinished(type_, done, download) emitted after a synchronization has |
30 @signal syncMessage(message) emitted to send a message about |
31 finished (string one of "bookmarks", "history", "passwords", "useragents" or |
31 synchronization (string) |
32 "speeddial", boolean, boolean) |
32 @signal syncFinished(type_, done, download) emitted after a |
|
33 synchronization has finished (string one of "bookmarks", "history", |
|
34 "passwords", "useragents" or "speeddial", boolean, boolean) |
33 """ |
35 """ |
34 syncStatus = pyqtSignal(str, str) |
36 syncStatus = pyqtSignal(str, str) |
35 syncError = pyqtSignal(str) |
37 syncError = pyqtSignal(str) |
36 syncMessage = pyqtSignal(str) |
38 syncMessage = pyqtSignal(str) |
37 syncFinished = pyqtSignal(str, bool, bool) |
39 syncFinished = pyqtSignal(str, bool, bool) |
57 self._messages = { |
59 self._messages = { |
58 "bookmarks": { |
60 "bookmarks": { |
59 "RemoteExists": self.trUtf8( |
61 "RemoteExists": self.trUtf8( |
60 "Remote bookmarks file exists! Syncing local copy..."), |
62 "Remote bookmarks file exists! Syncing local copy..."), |
61 "RemoteMissing": self.trUtf8( |
63 "RemoteMissing": self.trUtf8( |
62 "Remote bookmarks file does NOT exists. Exporting local copy..."), |
64 "Remote bookmarks file does NOT exists. Exporting" |
|
65 " local copy..."), |
63 "LocalNewer": self.trUtf8( |
66 "LocalNewer": self.trUtf8( |
64 "Local bookmarks file is NEWER. Exporting local copy..."), |
67 "Local bookmarks file is NEWER. Exporting local copy..."), |
65 "LocalMissing": self.trUtf8( |
68 "LocalMissing": self.trUtf8( |
66 "Local bookmarks file does NOT exist. Skipping synchronization!"), |
69 "Local bookmarks file does NOT exist. Skipping" |
|
70 " synchronization!"), |
67 "Uploading": self.trUtf8("Uploading local bookmarks file..."), |
71 "Uploading": self.trUtf8("Uploading local bookmarks file..."), |
68 }, |
72 }, |
69 "history": { |
73 "history": { |
70 "RemoteExists": self.trUtf8( |
74 "RemoteExists": self.trUtf8( |
71 "Remote history file exists! Syncing local copy..."), |
75 "Remote history file exists! Syncing local copy..."), |
72 "RemoteMissing": self.trUtf8( |
76 "RemoteMissing": self.trUtf8( |
73 "Remote history file does NOT exists. Exporting local copy..."), |
77 "Remote history file does NOT exists. Exporting" |
|
78 " local copy..."), |
74 "LocalNewer": self.trUtf8( |
79 "LocalNewer": self.trUtf8( |
75 "Local history file is NEWER. Exporting local copy..."), |
80 "Local history file is NEWER. Exporting local copy..."), |
76 "LocalMissing": self.trUtf8( |
81 "LocalMissing": self.trUtf8( |
77 "Local history file does NOT exist. Skipping synchronization!"), |
82 "Local history file does NOT exist. Skipping" |
|
83 " synchronization!"), |
78 "Uploading": self.trUtf8("Uploading local history file..."), |
84 "Uploading": self.trUtf8("Uploading local history file..."), |
79 }, |
85 }, |
80 "passwords": { |
86 "passwords": { |
81 "RemoteExists": self.trUtf8( |
87 "RemoteExists": self.trUtf8( |
82 "Remote logins file exists! Syncing local copy..."), |
88 "Remote logins file exists! Syncing local copy..."), |
83 "RemoteMissing": self.trUtf8( |
89 "RemoteMissing": self.trUtf8( |
84 "Remote logins file does NOT exists. Exporting local copy..."), |
90 "Remote logins file does NOT exists. Exporting" |
|
91 " local copy..."), |
85 "LocalNewer": self.trUtf8( |
92 "LocalNewer": self.trUtf8( |
86 "Local logins file is NEWER. Exporting local copy..."), |
93 "Local logins file is NEWER. Exporting local copy..."), |
87 "LocalMissing": self.trUtf8( |
94 "LocalMissing": self.trUtf8( |
88 "Local logins file does NOT exist. Skipping synchronization!"), |
95 "Local logins file does NOT exist. Skipping" |
|
96 " synchronization!"), |
89 "Uploading": self.trUtf8("Uploading local logins file..."), |
97 "Uploading": self.trUtf8("Uploading local logins file..."), |
90 }, |
98 }, |
91 "useragents": { |
99 "useragents": { |
92 "RemoteExists": self.trUtf8( |
100 "RemoteExists": self.trUtf8( |
93 "Remote user agent settings file exists! Syncing local copy..."), |
101 "Remote user agent settings file exists! Syncing local" |
|
102 " copy..."), |
94 "RemoteMissing": self.trUtf8( |
103 "RemoteMissing": self.trUtf8( |
95 "Remote user agent settings file does NOT exists." |
104 "Remote user agent settings file does NOT exists." |
96 " Exporting local copy..."), |
105 " Exporting local copy..."), |
97 "LocalNewer": self.trUtf8( |
106 "LocalNewer": self.trUtf8( |
98 "Local user agent settings file is NEWER. Exporting local copy..."), |
107 "Local user agent settings file is NEWER. Exporting" |
|
108 " local copy..."), |
99 "LocalMissing": self.trUtf8( |
109 "LocalMissing": self.trUtf8( |
100 "Local user agent settings file does NOT exist." |
110 "Local user agent settings file does NOT exist." |
101 " Skipping synchronization!"), |
111 " Skipping synchronization!"), |
102 "Uploading": self.trUtf8("Uploading local user agent settings file..."), |
112 "Uploading": self.trUtf8("Uploading local user agent" |
|
113 " settings file..."), |
103 }, |
114 }, |
104 "speeddial": { |
115 "speeddial": { |
105 "RemoteExists": self.trUtf8( |
116 "RemoteExists": self.trUtf8( |
106 "Remote speed dial settings file exists! Syncing local copy..."), |
117 "Remote speed dial settings file exists! Syncing local" |
|
118 " copy..."), |
107 "RemoteMissing": self.trUtf8( |
119 "RemoteMissing": self.trUtf8( |
108 "Remote speed dial settings file does NOT exists." |
120 "Remote speed dial settings file does NOT exists." |
109 " Exporting local copy..."), |
121 " Exporting local copy..."), |
110 "LocalNewer": self.trUtf8( |
122 "LocalNewer": self.trUtf8( |
111 "Local speed dial settings file is NEWER. Exporting local copy..."), |
123 "Local speed dial settings file is NEWER. Exporting" |
|
124 " local copy..."), |
112 "LocalMissing": self.trUtf8( |
125 "LocalMissing": self.trUtf8( |
113 "Local speed dial settings file does NOT exist." |
126 "Local speed dial settings file does NOT exist." |
114 " Skipping synchronization!"), |
127 " Skipping synchronization!"), |
115 "Uploading": self.trUtf8("Uploading local speed dial settings file..."), |
128 "Uploading": self.trUtf8("Uploading local speed dial" |
|
129 " settings file..."), |
116 }, |
130 }, |
117 } |
131 } |
118 |
132 |
119 def syncBookmarks(self): |
133 def syncBookmarks(self): |
120 """ |
134 """ |
121 Public method to synchronize the bookmarks. |
135 Public method to synchronize the bookmarks. |
|
136 |
|
137 @exception NotImplementedError raised to indicate that this method |
|
138 must be implemented by subclasses |
122 """ |
139 """ |
123 raise NotImplementedError |
140 raise NotImplementedError |
124 |
141 |
125 def syncHistory(self): |
142 def syncHistory(self): |
126 """ |
143 """ |
127 Public method to synchronize the history. |
144 Public method to synchronize the history. |
|
145 |
|
146 @exception NotImplementedError raised to indicate that this method |
|
147 must be implemented by subclasses |
128 """ |
148 """ |
129 raise NotImplementedError |
149 raise NotImplementedError |
130 |
150 |
131 def syncPasswords(self): |
151 def syncPasswords(self): |
132 """ |
152 """ |
133 Public method to synchronize the passwords. |
153 Public method to synchronize the passwords. |
|
154 |
|
155 @exception NotImplementedError raised to indicate that this method |
|
156 must be implemented by subclasses |
134 """ |
157 """ |
135 raise NotImplementedError |
158 raise NotImplementedError |
136 |
159 |
137 def syncUserAgents(self): |
160 def syncUserAgents(self): |
138 """ |
161 """ |
139 Public method to synchronize the user agents. |
162 Public method to synchronize the user agents. |
|
163 |
|
164 @exception NotImplementedError raised to indicate that this method |
|
165 must be implemented by subclasses |
140 """ |
166 """ |
141 raise NotImplementedError |
167 raise NotImplementedError |
142 |
168 |
143 def syncSpeedDial(self): |
169 def syncSpeedDial(self): |
144 """ |
170 """ |
145 Public method to synchronize the speed dial data. |
171 Public method to synchronize the speed dial data. |
|
172 |
|
173 @exception NotImplementedError raised to indicate that this method |
|
174 must be implemented by subclasses |
146 """ |
175 """ |
147 raise NotImplementedError |
176 raise NotImplementedError |
148 |
177 |
149 def initialLoadAndCheck(self, forceUpload): |
178 def initialLoadAndCheck(self, forceUpload): |
150 """ |
179 """ |
151 Public method to do the initial check. |
180 Public method to do the initial check. |
152 |
181 |
153 @keyparam forceUpload flag indicating a forced upload of the files (boolean) |
182 @keyparam forceUpload flag indicating a forced upload of the files |
|
183 (boolean) |
|
184 @exception NotImplementedError raised to indicate that this method |
|
185 must be implemented by subclasses |
154 """ |
186 """ |
155 raise NotImplementedError |
187 raise NotImplementedError |
156 |
188 |
157 def shutdown(self): |
189 def shutdown(self): |
158 """ |
190 """ |
159 Public method to shut down the handler. |
191 Public method to shut down the handler. |
|
192 |
|
193 @exception NotImplementedError raised to indicate that this method |
|
194 must be implemented by subclasses |
160 """ |
195 """ |
161 raise NotImplementedError |
196 raise NotImplementedError |
162 |
197 |
163 def readFile(self, fileName, type_): |
198 def readFile(self, fileName, type_): |
164 """ |
199 """ |
165 Public method to read a file. |
200 Public method to read a file. |
166 |
201 |
167 If encrypted synchronization is enabled, the data will be encrypted using |
202 If encrypted synchronization is enabled, the data will be encrypted |
168 the relevant encryption key. |
203 using the relevant encryption key. |
169 |
204 |
170 @param fileName name of the file to be read (string) |
205 @param fileName name of the file to be read (string) |
171 @param type_ type of the synchronization event (string one |
206 @param type_ type of the synchronization event (string one |
172 of "bookmarks", "history", "passwords", "useragents" or "speeddial") |
207 of "bookmarks", "history", "passwords", "useragents" or |
|
208 "speeddial") |
173 @return data of the file, optionally encrypted (QByteArray) |
209 @return data of the file, optionally encrypted (QByteArray) |
174 """ |
210 """ |
175 if os.path.exists(fileName): |
211 if os.path.exists(fileName): |
176 try: |
212 try: |
177 inputFile = open(fileName, "rb") |
213 inputFile = open(fileName, "rb") |
200 |
236 |
201 def writeFile(self, data, fileName, type_, timestamp=0): |
237 def writeFile(self, data, fileName, type_, timestamp=0): |
202 """ |
238 """ |
203 Public method to write the data to a file. |
239 Public method to write the data to a file. |
204 |
240 |
205 If encrypted synchronization is enabled, the data will be decrypted using |
241 If encrypted synchronization is enabled, the data will be decrypted |
206 the relevant encryption key. |
242 using the relevant encryption key. |
207 |
243 |
208 @param data data to be written and optionally decrypted (QByteArray) |
244 @param data data to be written and optionally decrypted (QByteArray) |
209 @param fileName name of the file the data is to be written to (string) |
245 @param fileName name of the file the data is to be written to (string) |
210 @param type_ type of the synchronization event (string one |
246 @param type_ type of the synchronization event (string one |
211 of "bookmarks", "history", "passwords", "useragents" or "speeddial") |
247 of "bookmarks", "history", "passwords", "useragents" or |
|
248 "speeddial") |
212 @param timestamp timestamp to be given to the file (int) |
249 @param timestamp timestamp to be given to the file (int) |
213 @return tuple giving a success flag and an error string (boolean, string) |
250 @return tuple giving a success flag and an error string (boolean, |
|
251 string) |
214 """ |
252 """ |
215 data = bytes(data) |
253 data = bytes(data) |
216 |
254 |
217 if Preferences.getHelp("SyncEncryptData") and \ |
255 if Preferences.getHelp("SyncEncryptData") and \ |
218 (not Preferences.getHelp("SyncEncryptPasswordsOnly") or \ |
256 (not Preferences.getHelp("SyncEncryptPasswordsOnly") or |
219 (Preferences.getHelp("SyncEncryptPasswordsOnly") and type_ == "passwords")): |
257 (Preferences.getHelp("SyncEncryptPasswordsOnly") and |
|
258 type_ == "passwords")): |
220 key = Preferences.getHelp("SyncEncryptionKey") |
259 key = Preferences.getHelp("SyncEncryptionKey") |
221 if not key: |
260 if not key: |
222 return False, self.trUtf8("Invalid encryption key given.") |
261 return False, self.trUtf8("Invalid encryption key given.") |
223 |
262 |
224 data, ok = dataDecrypt(data, key, |
263 data, ok = dataDecrypt(data, key, |