147 |
148 |
148 def scriptsDirectory(self): |
149 def scriptsDirectory(self): |
149 """ |
150 """ |
150 Public method to get the path of the scripts directory. |
151 Public method to get the path of the scripts directory. |
151 |
152 |
152 @return path of the scripts directory (string) |
153 @return path of the scripts directory |
|
154 @rtype str |
153 """ |
155 """ |
154 return os.path.join(Globals.getConfigDir(), "web_browser", "greasemonkey") |
156 return os.path.join(Globals.getConfigDir(), "web_browser", "greasemonkey") |
155 |
157 |
156 def requireScriptsDirectory(self): |
158 def requireScriptsDirectory(self): |
157 """ |
159 """ |
158 Public method to get the path of the scripts directory. |
160 Public method to get the path of the scripts directory. |
159 |
161 |
160 @return path of the scripts directory (string) |
162 @return path of the scripts directory |
|
163 @rtype str |
161 """ |
164 """ |
162 return os.path.join(self.scriptsDirectory(), "requires") |
165 return os.path.join(self.scriptsDirectory(), "requires") |
163 |
166 |
164 def requireScripts(self, urlList): |
167 def requireScripts(self, urlList): |
165 """ |
168 """ |
166 Public method to get the sources of all required scripts. |
169 Public method to get the sources of all required scripts. |
167 |
170 |
168 @param urlList list of URLs (list of string) |
171 @param urlList list of URLs |
169 @return sources of all required scripts (string) |
172 @type list of str |
|
173 @return sources of all required scripts |
|
174 @rtype str |
170 """ |
175 """ |
171 requiresDir = QDir(self.requireScriptsDirectory()) |
176 requiresDir = QDir(self.requireScriptsDirectory()) |
172 if not requiresDir.exists() or len(urlList) == 0: |
177 if not requiresDir.exists() or len(urlList) == 0: |
173 return "" |
178 return "" |
174 |
179 |
202 |
207 |
203 def allScripts(self): |
208 def allScripts(self): |
204 """ |
209 """ |
205 Public method to get a list of all scripts. |
210 Public method to get a list of all scripts. |
206 |
211 |
207 @return list of all scripts (list of GreaseMonkeyScript) |
212 @return list of all scripts (list o |
|
213 @rtype GreaseMonkeyScript |
208 """ |
214 """ |
209 return self.__scripts[:] |
215 return self.__scripts[:] |
210 |
216 |
211 def containsScript(self, fullName): |
217 def containsScript(self, fullName): |
212 """ |
218 """ |
213 Public method to check, if the given script exists. |
219 Public method to check, if the given script exists. |
214 |
220 |
215 @param fullName full name of the script (string) |
221 @param fullName full name of the script |
216 @return flag indicating the existence (boolean) |
222 @type str |
|
223 @return flag indicating the existence |
|
224 @rtype bool |
217 """ |
225 """ |
218 return any(script.fullName() == fullName for script in self.__scripts) |
226 return any(script.fullName() == fullName for script in self.__scripts) |
219 |
227 |
220 def enableScript(self, script): |
228 def enableScript(self, script): |
221 """ |
229 """ |
222 Public method to enable the given script. |
230 Public method to enable the given script. |
223 |
231 |
224 @param script script to be enabled (GreaseMonkeyScript) |
232 @param script script to be enabled |
|
233 @type GreaseMonkeyScript |
225 """ |
234 """ |
226 script.setEnabled(True) |
235 script.setEnabled(True) |
227 fullName = script.fullName() |
236 fullName = script.fullName() |
228 if fullName in self.__disabledScripts: |
237 if fullName in self.__disabledScripts: |
229 self.__disabledScripts.remove(fullName) |
238 self.__disabledScripts.remove(fullName) |
233 |
242 |
234 def disableScript(self, script): |
243 def disableScript(self, script): |
235 """ |
244 """ |
236 Public method to disable the given script. |
245 Public method to disable the given script. |
237 |
246 |
238 @param script script to be disabled (GreaseMonkeyScript) |
247 @param script script to be disabled |
|
248 @type GreaseMonkeyScript |
239 """ |
249 """ |
240 script.setEnabled(False) |
250 script.setEnabled(False) |
241 fullName = script.fullName() |
251 fullName = script.fullName() |
242 if fullName not in self.__disabledScripts: |
252 if fullName not in self.__disabledScripts: |
243 self.__disabledScripts.append(fullName) |
253 self.__disabledScripts.append(fullName) |
249 |
259 |
250 def addScript(self, script): |
260 def addScript(self, script): |
251 """ |
261 """ |
252 Public method to add a script. |
262 Public method to add a script. |
253 |
263 |
254 @param script script to be added (GreaseMonkeyScript) |
264 @param script script to be added |
255 @return flag indicating success (boolean) |
265 @type GreaseMonkeyScript |
|
266 @return flag indicating success |
|
267 @rtype bool |
256 """ |
268 """ |
257 if not script or not script.isValid(): |
269 if not script or not script.isValid(): |
258 return False |
270 return False |
259 |
271 |
260 self.__scripts.append(script) |
272 self.__scripts.append(script) |
268 |
280 |
269 def removeScript(self, script, removeFile=True): |
281 def removeScript(self, script, removeFile=True): |
270 """ |
282 """ |
271 Public method to remove a script. |
283 Public method to remove a script. |
272 |
284 |
273 @param script script to be removed (GreaseMonkeyScript) |
285 @param script script to be removed |
|
286 @type GreaseMonkeyScript |
274 @param removeFile flag indicating to remove the script file as well |
287 @param removeFile flag indicating to remove the script file as well |
275 (bool) |
288 @type bool |
276 @return flag indicating success (boolean) |
289 @return flag indicating success |
|
290 @rtype bool |
277 """ |
291 """ |
278 if not script: |
292 if not script: |
279 return False |
293 return False |
280 |
294 |
281 with contextlib.suppress(ValueError): |
295 with contextlib.suppress(ValueError): |
299 |
313 |
300 def canRunOnScheme(self, scheme): |
314 def canRunOnScheme(self, scheme): |
301 """ |
315 """ |
302 Public method to check, if scripts can be run on a scheme. |
316 Public method to check, if scripts can be run on a scheme. |
303 |
317 |
304 @param scheme scheme to check (string) |
318 @param scheme scheme to check |
305 @return flag indicating, that scripts can be run (boolean) |
319 @type str |
|
320 @return flag indicating, that scripts can be run |
|
321 @rtype bool |
306 """ |
322 """ |
307 return scheme in ["http", "https", "data", "ftp"] |
323 return scheme in ["http", "https", "data", "ftp"] |
308 |
324 |
309 def __load(self): |
325 def __load(self): |
310 """ |
326 """ |