71 @classmethod |
72 @classmethod |
72 def parseTemplate(cls, searchTerm, searchTemplate): |
73 def parseTemplate(cls, searchTerm, searchTemplate): |
73 """ |
74 """ |
74 Class method to parse a search template. |
75 Class method to parse a search template. |
75 |
76 |
76 @param searchTerm term to search for (string) |
77 @param searchTerm term to search for |
77 @param searchTemplate template to be parsed (string) |
78 @type str |
78 @return parsed template (string) |
79 @param searchTemplate template to be parsed |
|
80 @type str |
|
81 @return parsed template |
|
82 @rtype str |
79 """ |
83 """ |
80 locale = QLocale(Preferences.getWebBrowser("SearchLanguage")) |
84 locale = QLocale(Preferences.getWebBrowser("SearchLanguage")) |
81 language = locale.name().replace("_", "-") |
85 language = locale.name().replace("_", "-") |
82 country = locale.name().split("_")[0].lower() |
86 country = locale.name().split("_")[0].lower() |
83 |
87 |
99 @pyqtSlot(result=str) |
103 @pyqtSlot(result=str) |
100 def name(self): |
104 def name(self): |
101 """ |
105 """ |
102 Public method to get the name of the engine. |
106 Public method to get the name of the engine. |
103 |
107 |
104 @return name of the engine (string) |
108 @return name of the engine |
|
109 @rtype str |
105 """ |
110 """ |
106 return self._name |
111 return self._name |
107 |
112 |
108 def setName(self, name): |
113 def setName(self, name): |
109 """ |
114 """ |
110 Public method to set the engine name. |
115 Public method to set the engine name. |
111 |
116 |
112 @param name name of the engine (string) |
117 @param name name of the engine |
|
118 @type str |
113 """ |
119 """ |
114 self._name = name |
120 self._name = name |
115 |
121 |
116 def description(self): |
122 def description(self): |
117 """ |
123 """ |
118 Public method to get the description of the engine. |
124 Public method to get the description of the engine. |
119 |
125 |
120 @return description of the engine (string) |
126 @return description of the engine |
|
127 @rtype str |
121 """ |
128 """ |
122 return self._description |
129 return self._description |
123 |
130 |
124 def setDescription(self, description): |
131 def setDescription(self, description): |
125 """ |
132 """ |
126 Public method to set the engine description. |
133 Public method to set the engine description. |
127 |
134 |
128 @param description description of the engine (string) |
135 @param description description of the engine |
|
136 @type str |
129 """ |
137 """ |
130 self._description = description |
138 self._description = description |
131 |
139 |
132 def searchUrlTemplate(self): |
140 def searchUrlTemplate(self): |
133 """ |
141 """ |
134 Public method to get the search URL template of the engine. |
142 Public method to get the search URL template of the engine. |
135 |
143 |
136 @return search URL template of the engine (string) |
144 @return search URL template of the engine |
|
145 @rtype str |
137 """ |
146 """ |
138 return self._searchUrlTemplate |
147 return self._searchUrlTemplate |
139 |
148 |
140 def setSearchUrlTemplate(self, searchUrlTemplate): |
149 def setSearchUrlTemplate(self, searchUrlTemplate): |
141 """ |
150 """ |
162 <tr><td>{searchTerms}</td><td>the string supplied by the user</td></tr> |
171 <tr><td>{searchTerms}</td><td>the string supplied by the user</td></tr> |
163 <tr><td>{*:source}</td> |
172 <tr><td>{*:source}</td> |
164 <td>application name, QCoreApplication::applicationName()</td></tr> |
173 <td>application name, QCoreApplication::applicationName()</td></tr> |
165 </table> |
174 </table> |
166 |
175 |
167 @param searchUrlTemplate search URL template of the engine (string) |
176 @param searchUrlTemplate search URL template of the engine |
|
177 @type str |
168 """ |
178 """ |
169 self._searchUrlTemplate = searchUrlTemplate |
179 self._searchUrlTemplate = searchUrlTemplate |
170 |
180 |
171 def searchUrl(self, searchTerm): |
181 def searchUrl(self, searchTerm): |
172 """ |
182 """ |
173 Public method to get a URL ready for searching. |
183 Public method to get a URL ready for searching. |
174 |
184 |
175 @param searchTerm term to search for (string) |
185 @param searchTerm term to search for |
176 @return URL (QUrl) |
186 @type str |
|
187 @return URL |
|
188 @rtype QUrl |
177 """ |
189 """ |
178 if not self._searchUrlTemplate: |
190 if not self._searchUrlTemplate: |
179 return QUrl() |
191 return QUrl() |
180 |
192 |
181 ret = QUrl.fromEncoded( |
193 ret = QUrl.fromEncoded( |
194 |
206 |
195 def providesSuggestions(self): |
207 def providesSuggestions(self): |
196 """ |
208 """ |
197 Public method to check, if the engine provides suggestions. |
209 Public method to check, if the engine provides suggestions. |
198 |
210 |
199 @return flag indicating suggestions are provided (boolean) |
211 @return flag indicating suggestions are provided |
|
212 @rtype bool |
200 """ |
213 """ |
201 return self._suggestionsUrlTemplate != "" |
214 return self._suggestionsUrlTemplate != "" |
202 |
215 |
203 def suggestionsUrlTemplate(self): |
216 def suggestionsUrlTemplate(self): |
204 """ |
217 """ |
205 Public method to get the search URL template of the engine. |
218 Public method to get the search URL template of the engine. |
206 |
219 |
207 @return search URL template of the engine (string) |
220 @return search URL template of the engine |
|
221 @rtype str |
208 """ |
222 """ |
209 return self._suggestionsUrlTemplate |
223 return self._suggestionsUrlTemplate |
210 |
224 |
211 def setSuggestionsUrlTemplate(self, suggestionsUrlTemplate): |
225 def setSuggestionsUrlTemplate(self, suggestionsUrlTemplate): |
212 """ |
226 """ |
213 Public method to set the engine suggestions URL template. |
227 Public method to set the engine suggestions URL template. |
214 |
228 |
215 @param suggestionsUrlTemplate suggestions URL template of the |
229 @param suggestionsUrlTemplate suggestions URL template of the |
216 engine (string) |
230 engine |
|
231 @type str |
217 """ |
232 """ |
218 self._suggestionsUrlTemplate = suggestionsUrlTemplate |
233 self._suggestionsUrlTemplate = suggestionsUrlTemplate |
219 |
234 |
220 def suggestionsUrl(self, searchTerm): |
235 def suggestionsUrl(self, searchTerm): |
221 """ |
236 """ |
222 Public method to get a URL ready for suggestions. |
237 Public method to get a URL ready for suggestions. |
223 |
238 |
224 @param searchTerm term to search for (string) |
239 @param searchTerm term to search for |
225 @return URL (QUrl) |
240 @type str |
|
241 @return URL |
|
242 @rtype QUrl |
226 """ |
243 """ |
227 if not self._suggestionsUrlTemplate: |
244 if not self._suggestionsUrlTemplate: |
228 return QUrl() |
245 return QUrl() |
229 |
246 |
230 ret = QUrl.fromEncoded( |
247 ret = QUrl.fromEncoded( |
247 |
264 |
248 def searchParameters(self): |
265 def searchParameters(self): |
249 """ |
266 """ |
250 Public method to get the search parameters of the engine. |
267 Public method to get the search parameters of the engine. |
251 |
268 |
252 @return search parameters of the engine (list of two tuples) |
269 @return search parameters of the engine |
|
270 @rtype list of [tuple, tuple] |
253 """ |
271 """ |
254 return self._searchParameters[:] |
272 return self._searchParameters[:] |
255 |
273 |
256 def setSearchParameters(self, searchParameters): |
274 def setSearchParameters(self, searchParameters): |
257 """ |
275 """ |
258 Public method to set the engine search parameters. |
276 Public method to set the engine search parameters. |
259 |
277 |
260 @param searchParameters search parameters of the engine |
278 @param searchParameters search parameters of the engine |
261 (list of two tuples) |
279 @type list of [tuple, tuple] |
262 """ |
280 """ |
263 self._searchParameters = searchParameters[:] |
281 self._searchParameters = searchParameters[:] |
264 |
282 |
265 def suggestionsParameters(self): |
283 def suggestionsParameters(self): |
266 """ |
284 """ |
267 Public method to get the suggestions parameters of the engine. |
285 Public method to get the suggestions parameters of the engine. |
268 |
286 |
269 @return suggestions parameters of the engine (list of two tuples) |
287 @return suggestions parameters of the engine |
|
288 @rtype list of [tuple, tuple] |
270 """ |
289 """ |
271 return self._suggestionsParameters[:] |
290 return self._suggestionsParameters[:] |
272 |
291 |
273 def setSuggestionsParameters(self, suggestionsParameters): |
292 def setSuggestionsParameters(self, suggestionsParameters): |
274 """ |
293 """ |
275 Public method to set the engine suggestions parameters. |
294 Public method to set the engine suggestions parameters. |
276 |
295 |
277 @param suggestionsParameters suggestions parameters of the |
296 @param suggestionsParameters suggestions parameters of the engine |
278 engine (list of two tuples) |
297 @type list of [tuple, tuple] |
279 """ |
298 """ |
280 self._suggestionsParameters = suggestionsParameters[:] |
299 self._suggestionsParameters = suggestionsParameters[:] |
281 |
300 |
282 def searchMethod(self): |
301 def searchMethod(self): |
283 """ |
302 """ |
284 Public method to get the HTTP request method used to perform search |
303 Public method to get the HTTP request method used to perform search |
285 requests. |
304 requests. |
286 |
305 |
287 @return HTTP request method (string) |
306 @return HTTP request method |
|
307 @rtype str |
288 """ |
308 """ |
289 return self.__searchMethod |
309 return self.__searchMethod |
290 |
310 |
291 def setSearchMethod(self, method): |
311 def setSearchMethod(self, method): |
292 """ |
312 """ |
293 Public method to set the HTTP request method used to perform search |
313 Public method to set the HTTP request method used to perform search |
294 requests. |
314 requests. |
295 |
315 |
296 @param method HTTP request method (string) |
316 @param method HTTP request method |
|
317 @type str |
297 """ |
318 """ |
298 requestMethod = method.lower() |
319 requestMethod = method.lower() |
299 if requestMethod not in self.__requestMethods: |
320 if requestMethod not in self.__requestMethods: |
300 return |
321 return |
301 |
322 |
304 def suggestionsMethod(self): |
325 def suggestionsMethod(self): |
305 """ |
326 """ |
306 Public method to get the HTTP request method used to perform |
327 Public method to get the HTTP request method used to perform |
307 suggestions requests. |
328 suggestions requests. |
308 |
329 |
309 @return HTTP request method (string) |
330 @return HTTP request method |
|
331 @rtype str |
310 """ |
332 """ |
311 return self.__suggestionsMethod |
333 return self.__suggestionsMethod |
312 |
334 |
313 def setSuggestionsMethod(self, method): |
335 def setSuggestionsMethod(self, method): |
314 """ |
336 """ |
315 Public method to set the HTTP request method used to perform |
337 Public method to set the HTTP request method used to perform |
316 suggestions requests. |
338 suggestions requests. |
317 |
339 |
318 @param method HTTP request method (string) |
340 @param method HTTP request method |
|
341 @type str |
319 """ |
342 """ |
320 requestMethod = method.lower() |
343 requestMethod = method.lower() |
321 if requestMethod not in self.__requestMethods: |
344 if requestMethod not in self.__requestMethods: |
322 return |
345 return |
323 |
346 |
325 |
348 |
326 def imageUrl(self): |
349 def imageUrl(self): |
327 """ |
350 """ |
328 Public method to get the image URL of the engine. |
351 Public method to get the image URL of the engine. |
329 |
352 |
330 @return image URL of the engine (string) |
353 @return image URL of the engine |
|
354 @rtype str |
331 """ |
355 """ |
332 return self._imageUrl |
356 return self._imageUrl |
333 |
357 |
334 def setImageUrl(self, imageUrl): |
358 def setImageUrl(self, imageUrl): |
335 """ |
359 """ |
336 Public method to set the engine image URL. |
360 Public method to set the engine image URL. |
337 |
361 |
338 @param imageUrl image URL of the engine (string) |
362 @param imageUrl image URL of the engine |
|
363 @type str |
339 """ |
364 """ |
340 self._imageUrl = imageUrl |
365 self._imageUrl = imageUrl |
341 |
366 |
342 def setImageUrlAndLoad(self, imageUrl): |
367 def setImageUrlAndLoad(self, imageUrl): |
343 """ |
368 """ |
344 Public method to set the engine image URL. |
369 Public method to set the engine image URL. |
345 |
370 |
346 @param imageUrl image URL of the engine (string) |
371 @param imageUrl image URL of the engine |
|
372 @type str |
347 """ |
373 """ |
348 self.setImageUrl(imageUrl) |
374 self.setImageUrl(imageUrl) |
349 self.__iconMoved = False |
375 self.__iconMoved = False |
350 self.loadImage() |
376 self.loadImage() |
351 |
377 |
388 |
414 |
389 def image(self): |
415 def image(self): |
390 """ |
416 """ |
391 Public method to get the image of the engine. |
417 Public method to get the image of the engine. |
392 |
418 |
393 @return image of the engine (QImage) |
419 @return image of the engine |
|
420 @rtype QImage |
394 """ |
421 """ |
395 if not self.__iconMoved and self.__image.isNull(): |
422 if not self.__iconMoved and self.__image.isNull(): |
396 self.loadImage() |
423 self.loadImage() |
397 |
424 |
398 return self.__image |
425 return self.__image |
399 |
426 |
400 def setImage(self, image): |
427 def setImage(self, image): |
401 """ |
428 """ |
402 Public method to set the image of the engine. |
429 Public method to set the image of the engine. |
403 |
430 |
404 @param image image to be set (QImage) |
431 @param image image to be set |
|
432 @type QImage |
405 """ |
433 """ |
406 if not self._imageUrl: |
434 if not self._imageUrl: |
407 imageBuffer = QBuffer() |
435 imageBuffer = QBuffer() |
408 imageBuffer.open(QIODevice.OpenModeFlag.ReadWrite) |
436 imageBuffer.open(QIODevice.OpenModeFlag.ReadWrite) |
409 if image.save(imageBuffer, "PNG"): |
437 if image.save(imageBuffer, "PNG"): |
416 |
444 |
417 def isValid(self): |
445 def isValid(self): |
418 """ |
446 """ |
419 Public method to check, if the engine is valid. |
447 Public method to check, if the engine is valid. |
420 |
448 |
421 @return flag indicating validity (boolean) |
449 @return flag indicating validity |
|
450 @rtype bool |
422 """ |
451 """ |
423 return self._name and self._searchUrlTemplate |
452 return self._name and self._searchUrlTemplate |
424 |
453 |
425 def __eq__(self, other): |
454 def __eq__(self, other): |
426 """ |
455 """ |
427 Special method implementing the == operator. |
456 Special method implementing the == operator. |
428 |
457 |
429 @param other reference to an open search engine (OpenSearchEngine) |
458 @param other reference to an open search engine |
430 @return flag indicating equality (boolean) |
459 @type OpenSearchEngine |
|
460 @return flag indicating equality |
|
461 @rtype bool |
431 """ |
462 """ |
432 if not isinstance(other, OpenSearchEngine): |
463 if not isinstance(other, OpenSearchEngine): |
433 return NotImplemented |
464 return NotImplemented |
434 |
465 |
435 return ( |
466 return ( |
444 |
475 |
445 def __lt__(self, other): |
476 def __lt__(self, other): |
446 """ |
477 """ |
447 Special method implementing the < operator. |
478 Special method implementing the < operator. |
448 |
479 |
449 @param other reference to an open search engine (OpenSearchEngine) |
480 @param other reference to an open search engine |
450 @return flag indicating less than (boolean) |
481 @type OpenSearchEngine |
|
482 @return flag indicating less than |
|
483 @rtype bool |
451 """ |
484 """ |
452 if not isinstance(other, OpenSearchEngine): |
485 if not isinstance(other, OpenSearchEngine): |
453 return NotImplemented |
486 return NotImplemented |
454 |
487 |
455 return self._name < other._name |
488 return self._name < other._name |
456 |
489 |
457 def requestSuggestions(self, searchTerm): |
490 def requestSuggestions(self, searchTerm): |
458 """ |
491 """ |
459 Public method to request suggestions. |
492 Public method to request suggestions. |
460 |
493 |
461 @param searchTerm term to get suggestions for (string) |
494 @param searchTerm term to get suggestions for |
|
495 @type str |
462 """ |
496 """ |
463 if not searchTerm or not self.providesSuggestions(): |
497 if not searchTerm or not self.providesSuggestions(): |
464 return |
498 return |
465 |
499 |
466 if self.__networkAccessManager is None: |
500 if self.__networkAccessManager is None: |
521 def networkAccessManager(self): |
555 def networkAccessManager(self): |
522 """ |
556 """ |
523 Public method to get a reference to the network access manager object. |
557 Public method to get a reference to the network access manager object. |
524 |
558 |
525 @return reference to the network access manager object |
559 @return reference to the network access manager object |
526 (QNetworkAccessManager) |
560 @rtype QNetworkAccessManager |
527 """ |
561 """ |
528 return self.__networkAccessManager |
562 return self.__networkAccessManager |
529 |
563 |
530 def setNetworkAccessManager(self, networkAccessManager): |
564 def setNetworkAccessManager(self, networkAccessManager): |
531 """ |
565 """ |
532 Public method to set the reference to the network access manager. |
566 Public method to set the reference to the network access manager. |
533 |
567 |
534 @param networkAccessManager reference to the network access manager |
568 @param networkAccessManager reference to the network access manager |
535 object (QNetworkAccessManager) |
569 object |
|
570 @type QNetworkAccessManager |
536 """ |
571 """ |
537 self.__networkAccessManager = networkAccessManager |
572 self.__networkAccessManager = networkAccessManager |