7 Module implementing a manager for open search engines. |
7 Module implementing a manager for open search engines. |
8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt4.QtCore import pyqtSignal, QObject, QUrl, QFile, QDir, QIODevice, QByteArray, \ |
12 from PyQt4.QtCore import pyqtSignal, QObject, QUrl, QFile, QDir, QIODevice, \ |
13 QBuffer |
13 QByteArray, QBuffer |
14 from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply |
14 from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply |
15 |
15 |
16 from E5Gui.E5Application import e5App |
16 from E5Gui.E5Application import e5App |
17 from E5Gui import E5MessageBox |
17 from E5Gui import E5MessageBox |
18 |
18 |
180 |
180 |
181 def __addEngineByFile(self, filename): |
181 def __addEngineByFile(self, filename): |
182 """ |
182 """ |
183 Private method to add a new search engine given a filename. |
183 Private method to add a new search engine given a filename. |
184 |
184 |
185 @param filename name of a file containing the engine definition (string) |
185 @param filename name of a file containing the engine definition |
|
186 (string) |
186 @return flag indicating success (boolean) |
187 @return flag indicating success (boolean) |
187 """ |
188 """ |
188 file_ = QFile(filename) |
189 file_ = QFile(filename) |
189 if not file_.open(QIODevice.ReadOnly): |
190 if not file_.open(QIODevice.ReadOnly): |
190 return False |
191 return False |
232 |
234 |
233 if name not in self.__engines: |
235 if name not in self.__engines: |
234 return |
236 return |
235 |
237 |
236 engine = self.__engines[name] |
238 engine = self.__engines[name] |
237 for keyword in [k for k in self.__keywords if self.__keywords[k] == engine]: |
239 for keyword in [k for k in self.__keywords |
|
240 if self.__keywords[k] == engine]: |
238 del self.__keywords[keyword] |
241 del self.__keywords[keyword] |
239 del self.__engines[name] |
242 del self.__engines[name] |
240 |
243 |
241 file_ = QDir(self.enginesDirectory()).filePath(self.generateEngineFileName(name)) |
244 file_ = QDir(self.enginesDirectory()).filePath( |
|
245 self.generateEngineFileName(name)) |
242 QFile.remove(file_) |
246 QFile.remove(file_) |
243 |
247 |
244 if name == self.__current: |
248 if name == self.__current: |
245 self.setCurrentEngineName(list(self.__engines.keys())[0]) |
249 self.setCurrentEngineName(list(self.__engines.keys())[0]) |
246 |
250 |
372 Public method to determine the directory containing the search engine |
376 Public method to determine the directory containing the search engine |
373 descriptions. |
377 descriptions. |
374 |
378 |
375 @return directory name (string) |
379 @return directory name (string) |
376 """ |
380 """ |
377 return os.path.join(Utilities.getConfigDir(), "browser", "searchengines") |
381 return os.path.join( |
|
382 Utilities.getConfigDir(), "browser", "searchengines") |
378 |
383 |
379 def __confirmAddition(self, engine): |
384 def __confirmAddition(self, engine): |
380 """ |
385 """ |
381 Private method to confirm the addition of a new search engine. |
386 Private method to confirm the addition of a new search engine. |
382 |
387 |
388 |
393 |
389 host = QUrl(engine.searchUrlTemplate()).host() |
394 host = QUrl(engine.searchUrlTemplate()).host() |
390 |
395 |
391 res = E5MessageBox.yesNo(None, |
396 res = E5MessageBox.yesNo(None, |
392 "", |
397 "", |
393 self.trUtf8("""<p>Do you want to add the following engine to your list of""" |
398 self.trUtf8( |
394 """ search engines?<br/><br/>Name: {0}<br/>""" |
399 """<p>Do you want to add the following engine to your""" |
395 """Searches on: {1}</p>""")\ |
400 """ list of search engines?<br/><br/>Name: {0}<br/>""" |
396 .format(engine.name(), host)) |
401 """Searches on: {1}</p>""").format(engine.name(), host)) |
397 return res |
402 return res |
398 |
403 |
399 def __engineFromUrlAvailable(self): |
404 def __engineFromUrlAvailable(self): |
400 """ |
405 """ |
401 Private slot to add a search engine from the net. |
406 Private slot to add a search engine from the net. |