WebBrowser/History/HistoryMenu.py

changeset 5038
df7103c3f2a6
parent 4735
84e78ee0f361
child 5389
9b1c800daff3
equal deleted inserted replaced
5037:b2b37d7c0791 5038:df7103c3f2a6
253 class HistoryMenu(E5ModelMenu): 253 class HistoryMenu(E5ModelMenu):
254 """ 254 """
255 Class implementing the history menu. 255 Class implementing the history menu.
256 256
257 @signal openUrl(QUrl, str) emitted to open a URL in the current tab 257 @signal openUrl(QUrl, str) emitted to open a URL in the current tab
258 @signal newUrl(QUrl, str) emitted to open a URL in a new tab 258 @signal newTab(QUrl, str) emitted to open a URL in a new tab
259 @signal newBackgroundTab(QUrl, str) emitted to open a URL in a new
260 background tab
261 @signal newWindow(QUrl, str) emitted to open a URL in a new window
262 @signal newPrivateWindow(QUrl, str) emitted to open a URL in a new
263 private window
259 """ 264 """
260 openUrl = pyqtSignal(QUrl, str) 265 openUrl = pyqtSignal(QUrl, str)
261 newUrl = pyqtSignal(QUrl, str) 266 newTab = pyqtSignal(QUrl, str)
267 newBackgroundTab = pyqtSignal(QUrl, str)
268 newWindow = pyqtSignal(QUrl, str)
269 newPrivateWindow = pyqtSignal(QUrl, str)
262 270
263 def __init__(self, parent=None, tabWidget=None): 271 def __init__(self, parent=None, tabWidget=None):
264 """ 272 """
265 Constructor 273 Constructor
266 274
293 Private slot handling the activated signal. 301 Private slot handling the activated signal.
294 302
295 @param idx index of the activated item (QModelIndex) 303 @param idx index of the activated item (QModelIndex)
296 """ 304 """
297 if self._keyboardModifiers & Qt.ControlModifier: 305 if self._keyboardModifiers & Qt.ControlModifier:
298 self.newUrl.emit( 306 self.newTab.emit(
307 idx.data(HistoryModel.UrlRole),
308 idx.data(HistoryModel.TitleRole))
309 elif self._keyboardModifiers & Qt.ShiftModifier:
310 self.newWindow.emit(
299 idx.data(HistoryModel.UrlRole), 311 idx.data(HistoryModel.UrlRole),
300 idx.data(HistoryModel.TitleRole)) 312 idx.data(HistoryModel.TitleRole))
301 else: 313 else:
302 self.openUrl.emit( 314 self.openUrl.emit(
303 idx.data(HistoryModel.UrlRole), 315 idx.data(HistoryModel.UrlRole),
308 Public method to add any actions before the tree. 320 Public method to add any actions before the tree.
309 321
310 @return flag indicating if any actions were added (boolean) 322 @return flag indicating if any actions were added (boolean)
311 """ 323 """
312 if self.__historyManager is None: 324 if self.__historyManager is None:
313 import WebBrowser.WebBrowserWindow 325 from WebBrowser.WebBrowserWindow import WebBrowserWindow
314 self.__historyManager = \ 326 self.__historyManager = WebBrowserWindow.historyManager()
315 WebBrowser.WebBrowserWindow.WebBrowserWindow.historyManager()
316 self.__historyMenuModel = HistoryMenuModel( 327 self.__historyMenuModel = HistoryMenuModel(
317 self.__historyManager.historyTreeModel(), self) 328 self.__historyManager.historyTreeModel(), self)
318 self.setModel(self.__historyMenuModel) 329 self.setModel(self.__historyMenuModel)
319 330
320 # initial actions 331 # initial actions
335 346
336 if self.__mostVisitedMenu is None: 347 if self.__mostVisitedMenu is None:
337 self.__mostVisitedMenu = HistoryMostVisitedMenu(10, self) 348 self.__mostVisitedMenu = HistoryMostVisitedMenu(10, self)
338 self.__mostVisitedMenu.setTitle(self.tr("Most Visited")) 349 self.__mostVisitedMenu.setTitle(self.tr("Most Visited"))
339 self.__mostVisitedMenu.openUrl.connect(self.openUrl) 350 self.__mostVisitedMenu.openUrl.connect(self.openUrl)
340 self.__mostVisitedMenu.newUrl.connect(self.newUrl) 351 self.__mostVisitedMenu.newTab.connect(self.newTab)
352 self.__mostVisitedMenu.newBackgroundTab.connect(
353 self.newBackgroundTab)
354 self.__mostVisitedMenu.newWindow.connect(self.newWindow)
355 self.__mostVisitedMenu.newPrivateWindow.connect(
356 self.newPrivateWindow)
341 self.addMenu(self.__mostVisitedMenu) 357 self.addMenu(self.__mostVisitedMenu)
342 act = self.addMenu(self.__closedTabsMenu) 358 act = self.addMenu(self.__closedTabsMenu)
343 act.setIcon(UI.PixmapCache.getIcon("trash.png")) 359 act.setIcon(UI.PixmapCache.getIcon("trash.png"))
344 act.setEnabled(self.__tabWidget.canRestoreClosedTab()) 360 act.setEnabled(self.__tabWidget.canRestoreClosedTab())
345 self.addSeparator() 361 self.addSeparator()
366 """ 382 """
367 Private slot to show the history dialog. 383 Private slot to show the history dialog.
368 """ 384 """
369 from .HistoryDialog import HistoryDialog 385 from .HistoryDialog import HistoryDialog
370 dlg = HistoryDialog(self) 386 dlg = HistoryDialog(self)
371 dlg.newUrl.connect(self.newUrl)
372 dlg.openUrl.connect(self.openUrl) 387 dlg.openUrl.connect(self.openUrl)
388 dlg.newTab.connect(self.newTab)
389 dlg.newBackgroundTab.connect(self.newBackgroundTab)
390 dlg.newWindow.connect(self.newWindow)
391 dlg.newPrivateWindow.connect(self.newPrivateWindow)
373 dlg.show() 392 dlg.show()
374 393
375 def __clearHistoryDialog(self): 394 def __clearHistoryDialog(self):
376 """ 395 """
377 Private slot to clear the history. 396 Private slot to clear the history.
420 class HistoryMostVisitedMenu(E5ModelMenu): 439 class HistoryMostVisitedMenu(E5ModelMenu):
421 """ 440 """
422 Class implementing the most visited history menu. 441 Class implementing the most visited history menu.
423 442
424 @signal openUrl(QUrl, str) emitted to open a URL in the current tab 443 @signal openUrl(QUrl, str) emitted to open a URL in the current tab
425 @signal newUrl(QUrl, str) emitted to open a URL in a new tab 444 @signal newTab(QUrl, str) emitted to open a URL in a new tab
445 @signal newBackgroundTab(QUrl, str) emitted to open a URL in a new
446 background tab
447 @signal newWindow(QUrl, str) emitted to open a URL in a new window
448 @signal newPrivateWindow(QUrl, str) emitted to open a URL in a new
449 private window
426 """ 450 """
427 openUrl = pyqtSignal(QUrl, str) 451 openUrl = pyqtSignal(QUrl, str)
428 newUrl = pyqtSignal(QUrl, str) 452 newTab = pyqtSignal(QUrl, str)
453 newBackgroundTab = pyqtSignal(QUrl, str)
454 newWindow = pyqtSignal(QUrl, str)
455 newPrivateWindow = pyqtSignal(QUrl, str)
429 456
430 def __init__(self, count, parent=None): 457 def __init__(self, count, parent=None):
431 """ 458 """
432 Constructor 459 Constructor
433 460
438 465
439 self.__historyMenuModel = None 466 self.__historyMenuModel = None
440 467
441 self.setMaxRows(count + 1) 468 self.setMaxRows(count + 1)
442 469
443 self.activated.connect(self.__activated) 470 ## self.activated.connect(self.__activated)
444 self.setStatusBarTextRole(HistoryModel.UrlStringRole) 471 self.setStatusBarTextRole(HistoryModel.UrlStringRole)
445 472
446 def __activated(self, idx): 473 def __activated(self, idx):
447 """ 474 """
448 Private slot handling the activated signal. 475 Private slot handling the activated signal.
449 476
450 @param idx index of the activated item (QModelIndex) 477 @param idx index of the activated item (QModelIndex)
451 """ 478 """
452 if self._keyboardModifiers & Qt.ControlModifier: 479 if self._keyboardModifiers & Qt.ControlModifier:
453 self.newUrl.emit( 480 self.newTab.emit(
481 idx.data(HistoryModel.UrlRole),
482 idx.data(HistoryModel.TitleRole))
483 elif self._keyboardModifiers & Qt.ShiftModifier:
484 self.newWindow.emit(
454 idx.data(HistoryModel.UrlRole), 485 idx.data(HistoryModel.UrlRole),
455 idx.data(HistoryModel.TitleRole)) 486 idx.data(HistoryModel.TitleRole))
456 else: 487 else:
457 self.openUrl.emit( 488 self.openUrl.emit(
458 idx.data(HistoryModel.UrlRole), 489 idx.data(HistoryModel.UrlRole),
463 Public method to add any actions before the tree. 494 Public method to add any actions before the tree.
464 495
465 @return flag indicating if any actions were added (boolean) 496 @return flag indicating if any actions were added (boolean)
466 """ 497 """
467 if self.__historyMenuModel is None: 498 if self.__historyMenuModel is None:
468 import WebBrowser.WebBrowserWindow 499 from WebBrowser.WebBrowserWindow import WebBrowserWindow
469 historyManager = \ 500 historyManager = WebBrowserWindow.historyManager()
470 WebBrowser.WebBrowserWindow.WebBrowserWindow.historyManager()
471 self.__historyMenuModel = HistoryMostVisitedMenuModel( 501 self.__historyMenuModel = HistoryMostVisitedMenuModel(
472 historyManager.historyFilterModel(), self) 502 historyManager.historyFilterModel(), self)
473 self.setModel(self.__historyMenuModel) 503 self.setModel(self.__historyMenuModel)
474 self.__historyMenuModel.sort(0) 504 self.__historyMenuModel.sort(0)
475 505

eric ide

mercurial