Helpviewer/OpenSearch/OpenSearchManager.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2791
a9577f248f04
parent 3002
6ffc581f00f1
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
9 9
10 from __future__ import unicode_literals # __IGNORE_WARNING__ 10 from __future__ import unicode_literals # __IGNORE_WARNING__
11 11
12 import os 12 import os
13 13
14 from PyQt4.QtCore import pyqtSignal, QObject, QUrl, QFile, QDir, QIODevice, QByteArray, \ 14 from PyQt4.QtCore import pyqtSignal, QObject, QUrl, QFile, QDir, QIODevice, \
15 QBuffer 15 QByteArray, QBuffer
16 from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply 16 from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply
17 17
18 from E5Gui.E5Application import e5App 18 from E5Gui.E5Application import e5App
19 from E5Gui import E5MessageBox 19 from E5Gui import E5MessageBox
20 20
122 def engineExists(self, name): 122 def engineExists(self, name):
123 """ 123 """
124 Public method to check, if an engine exists. 124 Public method to check, if an engine exists.
125 125
126 @param name name of the engine (string) 126 @param name name of the engine (string)
127 @return flag indicating an existing engine (boolean)
127 """ 128 """
128 return name in self.__engines 129 return name in self.__engines
129 130
130 def allEnginesNames(self): 131 def allEnginesNames(self):
131 """ 132 """
181 182
182 def __addEngineByFile(self, filename): 183 def __addEngineByFile(self, filename):
183 """ 184 """
184 Private method to add a new search engine given a filename. 185 Private method to add a new search engine given a filename.
185 186
186 @param filename name of a file containing the engine definition (string) 187 @param filename name of a file containing the engine definition
188 (string)
187 @return flag indicating success (boolean) 189 @return flag indicating success (boolean)
188 """ 190 """
189 file_ = QFile(filename) 191 file_ = QFile(filename)
190 if not file_.open(QIODevice.ReadOnly): 192 if not file_.open(QIODevice.ReadOnly):
191 return False 193 return False
199 201
200 return True 202 return True
201 203
202 def __addEngineByEngine(self, engine): 204 def __addEngineByEngine(self, engine):
203 """ 205 """
204 Private method to add a new search engine given a reference to an engine. 206 Private method to add a new search engine given a reference to an
207 engine.
205 208
206 @param engine reference to an engine object (OpenSearchEngine) 209 @param engine reference to an engine object (OpenSearchEngine)
207 @return flag indicating success (boolean) 210 @return flag indicating success (boolean)
208 """ 211 """
209 if engine is None: 212 if engine is None:
233 236
234 if name not in self.__engines: 237 if name not in self.__engines:
235 return 238 return
236 239
237 engine = self.__engines[name] 240 engine = self.__engines[name]
238 for keyword in [k for k in self.__keywords if self.__keywords[k] == engine]: 241 for keyword in [k for k in self.__keywords
242 if self.__keywords[k] == engine]:
239 del self.__keywords[keyword] 243 del self.__keywords[keyword]
240 del self.__engines[name] 244 del self.__engines[name]
241 245
242 file_ = QDir(self.enginesDirectory()).filePath(self.generateEngineFileName(name)) 246 file_ = QDir(self.enginesDirectory()).filePath(
247 self.generateEngineFileName(name))
243 QFile.remove(file_) 248 QFile.remove(file_)
244 249
245 if name == self.__current: 250 if name == self.__current:
246 self.setCurrentEngineName(list(self.__engines.keys())[0]) 251 self.setCurrentEngineName(list(self.__engines.keys())[0])
247 252
373 Public method to determine the directory containing the search engine 378 Public method to determine the directory containing the search engine
374 descriptions. 379 descriptions.
375 380
376 @return directory name (string) 381 @return directory name (string)
377 """ 382 """
378 return os.path.join(Utilities.getConfigDir(), "browser", "searchengines") 383 return os.path.join(
384 Utilities.getConfigDir(), "browser", "searchengines")
379 385
380 def __confirmAddition(self, engine): 386 def __confirmAddition(self, engine):
381 """ 387 """
382 Private method to confirm the addition of a new search engine. 388 Private method to confirm the addition of a new search engine.
383 389
389 395
390 host = QUrl(engine.searchUrlTemplate()).host() 396 host = QUrl(engine.searchUrlTemplate()).host()
391 397
392 res = E5MessageBox.yesNo(None, 398 res = E5MessageBox.yesNo(None,
393 "", 399 "",
394 self.trUtf8("""<p>Do you want to add the following engine to your list of""" 400 self.trUtf8(
395 """ search engines?<br/><br/>Name: {0}<br/>""" 401 """<p>Do you want to add the following engine to your"""
396 """Searches on: {1}</p>""")\ 402 """ list of search engines?<br/><br/>Name: {0}<br/>"""
397 .format(engine.name(), host)) 403 """Searches on: {1}</p>""").format(engine.name(), host))
398 return res 404 return res
399 405
400 def __engineFromUrlAvailable(self): 406 def __engineFromUrlAvailable(self):
401 """ 407 """
402 Private slot to add a search engine from the net. 408 Private slot to add a search engine from the net.
515 521
516 self.changed.emit() 522 self.changed.emit()
517 523
518 def enginesChanged(self): 524 def enginesChanged(self):
519 """ 525 """
520 Public slot to tell the search engine manager, that something has changed. 526 Public slot to tell the search engine manager, that something has
527 changed.
521 """ 528 """
522 self.changed.emit() 529 self.changed.emit()

eric ide

mercurial