62 |
63 |
63 def currentEngineName(self): |
64 def currentEngineName(self): |
64 """ |
65 """ |
65 Public method to get the name of the current search engine. |
66 Public method to get the name of the current search engine. |
66 |
67 |
67 @return name of the current search engine (string) |
68 @return name of the current search engine |
|
69 @rtype str |
68 """ |
70 """ |
69 return self.__current |
71 return self.__current |
70 |
72 |
71 def setCurrentEngineName(self, name): |
73 def setCurrentEngineName(self, name): |
72 """ |
74 """ |
73 Public method to set the current engine by name. |
75 Public method to set the current engine by name. |
74 |
76 |
75 @param name name of the new current engine (string) |
77 @param name name of the new current engine |
|
78 @type str |
76 """ |
79 """ |
77 if name not in self.__engines: |
80 if name not in self.__engines: |
78 return |
81 return |
79 |
82 |
80 self.__current = name |
83 self.__current = name |
83 |
86 |
84 def currentEngine(self): |
87 def currentEngine(self): |
85 """ |
88 """ |
86 Public method to get a reference to the current engine. |
89 Public method to get a reference to the current engine. |
87 |
90 |
88 @return reference to the current engine (OpenSearchEngine) |
91 @return reference to the current engine |
|
92 @rtype OpenSearchEngine |
89 """ |
93 """ |
90 if not self.__current or self.__current not in self.__engines: |
94 if not self.__current or self.__current not in self.__engines: |
91 return None |
95 return None |
92 |
96 |
93 return self.__engines[self.__current] |
97 return self.__engines[self.__current] |
94 |
98 |
95 def setCurrentEngine(self, engine): |
99 def setCurrentEngine(self, engine): |
96 """ |
100 """ |
97 Public method to set the current engine. |
101 Public method to set the current engine. |
98 |
102 |
99 @param engine reference to the new current engine (OpenSearchEngine) |
103 @param engine reference to the new current engine |
|
104 @type OpenSearchEngine |
100 """ |
105 """ |
101 if engine is None: |
106 if engine is None: |
102 return |
107 return |
103 |
108 |
104 for engineName in self.__engines: |
109 for engineName in self.__engines: |
108 |
113 |
109 def engine(self, name): |
114 def engine(self, name): |
110 """ |
115 """ |
111 Public method to get a reference to the named engine. |
116 Public method to get a reference to the named engine. |
112 |
117 |
113 @param name name of the engine (string) |
118 @param name name of the engine |
114 @return reference to the engine (OpenSearchEngine) |
119 @type str |
|
120 @return reference to the engine |
|
121 @rtype OpenSearchEngine |
115 """ |
122 """ |
116 if name not in self.__engines: |
123 if name not in self.__engines: |
117 return None |
124 return None |
118 |
125 |
119 return self.__engines[name] |
126 return self.__engines[name] |
120 |
127 |
121 def engineExists(self, name): |
128 def engineExists(self, name): |
122 """ |
129 """ |
123 Public method to check, if an engine exists. |
130 Public method to check, if an engine exists. |
124 |
131 |
125 @param name name of the engine (string) |
132 @param name name of the engine |
126 @return flag indicating an existing engine (boolean) |
133 @type str |
|
134 @return flag indicating an existing engine |
|
135 @rtype bool |
127 """ |
136 """ |
128 return name in self.__engines |
137 return name in self.__engines |
129 |
138 |
130 def allEnginesNames(self): |
139 def allEnginesNames(self): |
131 """ |
140 """ |
132 Public method to get a list of all engine names. |
141 Public method to get a list of all engine names. |
133 |
142 |
134 @return sorted list of all engine names (list of strings) |
143 @return sorted list of all engine names |
|
144 @rtype list of str |
135 """ |
145 """ |
136 return sorted(self.__engines) |
146 return sorted(self.__engines) |
137 |
147 |
138 def enginesCount(self): |
148 def enginesCount(self): |
139 """ |
149 """ |
140 Public method to get the number of available engines. |
150 Public method to get the number of available engines. |
141 |
151 |
142 @return number of engines (integer) |
152 @return number of engines |
|
153 @rtype int |
143 """ |
154 """ |
144 return len(self.__engines) |
155 return len(self.__engines) |
145 |
156 |
146 def addEngine(self, engine): |
157 def addEngine(self, engine): |
147 """ |
158 """ |
148 Public method to add a new search engine. |
159 Public method to add a new search engine. |
149 |
160 |
150 @param engine URL of the engine definition file (QUrl) or |
161 @param engine URL of the engine definition file (QUrl) or |
151 name of a file containing the engine definition (string) |
162 name of a file containing the engine definition |
|
163 @type str |
152 or reference to an engine object (OpenSearchEngine) |
164 or reference to an engine object (OpenSearchEngine) |
153 @return flag indicating success (boolean) |
165 @return flag indicating success |
|
166 @rtype bool |
154 """ |
167 """ |
155 from .OpenSearchEngine import OpenSearchEngine |
168 from .OpenSearchEngine import OpenSearchEngine |
156 |
169 |
157 if isinstance(engine, QUrl): |
170 if isinstance(engine, QUrl): |
158 return self.__addEngineByUrl(engine) |
171 return self.__addEngineByUrl(engine) |
163 |
176 |
164 def __addEngineByUrl(self, url): |
177 def __addEngineByUrl(self, url): |
165 """ |
178 """ |
166 Private method to add a new search engine given its URL. |
179 Private method to add a new search engine given its URL. |
167 |
180 |
168 @param url URL of the engine definition file (QUrl) |
181 @param url URL of the engine definition file |
169 @return flag indicating success (boolean) |
182 @type QUrl |
|
183 @return flag indicating success |
|
184 @rtype bool |
170 """ |
185 """ |
171 if not url.isValid(): |
186 if not url.isValid(): |
172 return False |
187 return False |
173 |
188 |
174 reply = WebBrowserWindow.networkManager().get(QNetworkRequest(url)) |
189 reply = WebBrowserWindow.networkManager().get(QNetworkRequest(url)) |
181 def __addEngineByFile(self, filename): |
196 def __addEngineByFile(self, filename): |
182 """ |
197 """ |
183 Private method to add a new search engine given a filename. |
198 Private method to add a new search engine given a filename. |
184 |
199 |
185 @param filename name of a file containing the engine definition |
200 @param filename name of a file containing the engine definition |
186 (string) |
201 @type str |
187 @return flag indicating success (boolean) |
202 @return flag indicating success |
|
203 @rtype bool |
188 """ |
204 """ |
189 from .OpenSearchReader import OpenSearchReader |
205 from .OpenSearchReader import OpenSearchReader |
190 |
206 |
191 file_ = QFile(filename) |
207 file_ = QFile(filename) |
192 if not file_.open(QIODevice.OpenModeFlag.ReadOnly): |
208 if not file_.open(QIODevice.OpenModeFlag.ReadOnly): |
438 def enginesDirectory(self): |
462 def enginesDirectory(self): |
439 """ |
463 """ |
440 Public method to determine the directory containing the search engine |
464 Public method to determine the directory containing the search engine |
441 descriptions. |
465 descriptions. |
442 |
466 |
443 @return directory name (string) |
467 @return directory name |
|
468 @rtype str |
444 """ |
469 """ |
445 return os.path.join(Globals.getConfigDir(), "web_browser", "searchengines") |
470 return os.path.join(Globals.getConfigDir(), "web_browser", "searchengines") |
446 |
471 |
447 def __confirmAddition(self, engine): |
472 def __confirmAddition(self, engine): |
448 """ |
473 """ |
449 Private method to confirm the addition of a new search engine. |
474 Private method to confirm the addition of a new search engine. |
450 |
475 |
451 @param engine reference to the engine to be added (OpenSearchEngine) |
476 @param engine reference to the engine to be added |
452 @return flag indicating the engine shall be added (boolean) |
477 @type OpenSearchEngine |
|
478 @return flag indicating the engine shall be added |
|
479 @rtype bool |
453 """ |
480 """ |
454 if engine is None or not engine.isValid(): |
481 if engine is None or not engine.isValid(): |
455 return False |
482 return False |
456 |
483 |
457 host = QUrl(engine.searchUrlTemplate()).host() |
484 host = QUrl(engine.searchUrlTemplate()).host() |
524 |
553 |
525 def engineForKeyword(self, keyword): |
554 def engineForKeyword(self, keyword): |
526 """ |
555 """ |
527 Public method to get the engine for a keyword. |
556 Public method to get the engine for a keyword. |
528 |
557 |
529 @param keyword keyword to get engine for (string) |
558 @param keyword keyword to get engine for |
530 @return reference to the search engine object (OpenSearchEngine) |
559 @type str |
|
560 @return reference to the search engine object |
|
561 @rtype OpenSearchEngine |
531 """ |
562 """ |
532 if keyword and keyword in self.__keywords: |
563 if keyword and keyword in self.__keywords: |
533 return self.__keywords[keyword] |
564 return self.__keywords[keyword] |
534 |
565 |
535 return None |
566 return None |
536 |
567 |
537 def setEngineForKeyword(self, keyword, engine): |
568 def setEngineForKeyword(self, keyword, engine): |
538 """ |
569 """ |
539 Public method to set the engine for a keyword. |
570 Public method to set the engine for a keyword. |
540 |
571 |
541 @param keyword keyword to get engine for (string) |
572 @param keyword keyword to get engine for |
542 @param engine reference to the search engine object (OpenSearchEngine) |
573 @type str |
543 or None to remove the keyword |
574 @param engine reference to the search engine object or None to |
|
575 remove the keyword |
|
576 @type OpenSearchEngine |
544 """ |
577 """ |
545 if not keyword: |
578 if not keyword: |
546 return |
579 return |
547 |
580 |
548 if engine is None: |
581 if engine is None: |
555 |
588 |
556 def keywordsForEngine(self, engine): |
589 def keywordsForEngine(self, engine): |
557 """ |
590 """ |
558 Public method to get the keywords for a given engine. |
591 Public method to get the keywords for a given engine. |
559 |
592 |
560 @param engine reference to the search engine object (OpenSearchEngine) |
593 @param engine reference to the search engine object |
561 @return list of keywords (list of strings) |
594 @type OpenSearchEngine |
|
595 @return list of keywords |
|
596 @rtype list of str |
562 """ |
597 """ |
563 return [k for k in self.__keywords if self.__keywords[k] == engine] |
598 return [k for k in self.__keywords if self.__keywords[k] == engine] |
564 |
599 |
565 def setKeywordsForEngine(self, engine, keywords): |
600 def setKeywordsForEngine(self, engine, keywords): |
566 """ |
601 """ |
567 Public method to set the keywords for an engine. |
602 Public method to set the keywords for an engine. |
568 |
603 |
569 @param engine reference to the search engine object (OpenSearchEngine) |
604 @param engine reference to the search engine object |
570 @param keywords list of keywords (list of strings) |
605 @type OpenSearchEngine |
|
606 @param keywords list of keywords |
|
607 @type list of str |
571 """ |
608 """ |
572 if engine is None: |
609 if engine is None: |
573 return |
610 return |
574 |
611 |
575 for keyword in self.keywordsForEngine(engine): |
612 for keyword in self.keywordsForEngine(engine): |