|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a class to manage closed tabs. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSignal, QUrl, QObject |
|
13 |
|
14 |
|
15 class ClosedTab(object): |
|
16 """ |
|
17 Class implementing a structure to store data about a closed tab. |
|
18 """ |
|
19 def __init__(self, url=None, title="", position=-1): |
|
20 """ |
|
21 Constructor |
|
22 |
|
23 @param url URL of the closed tab (QUrl) |
|
24 @param title title of the closed tab (string) |
|
25 @param position index of the closed tab (integer) |
|
26 """ |
|
27 self.url = QUrl() if url is None else QUrl(url) |
|
28 self.title = title |
|
29 self.position = position |
|
30 |
|
31 def __eq__(self, other): |
|
32 """ |
|
33 Special method implementing the equality operator. |
|
34 |
|
35 @param other reference to the object to compare against (ClosedTab) |
|
36 @return flag indicating equality of the tabs (boolean) |
|
37 """ |
|
38 return self.url == other.url and \ |
|
39 self.title == other.title and \ |
|
40 self.position == other.position |
|
41 |
|
42 |
|
43 class ClosedTabsManager(QObject): |
|
44 """ |
|
45 Class implementing a manager for closed tabs. |
|
46 |
|
47 @signal closedTabAvailable(boolean) emitted to signal a change of |
|
48 availability of closed tabs |
|
49 """ |
|
50 closedTabAvailable = pyqtSignal(bool) |
|
51 |
|
52 def __init__(self, parent=None): |
|
53 """ |
|
54 Constructor |
|
55 |
|
56 @param parent reference to the parent object (QObject) |
|
57 """ |
|
58 super(ClosedTabsManager, self).__init__() |
|
59 |
|
60 self.__closedTabs = [] |
|
61 |
|
62 def recordBrowser(self, browser, position): |
|
63 """ |
|
64 Public method to record the data of a browser about to be closed. |
|
65 |
|
66 @param browser reference to the browser to be closed (HelpBrowser) |
|
67 @param position index of the tab to be closed (integer) |
|
68 """ |
|
69 import WebBrowser.WebBrowserWindow |
|
70 if WebBrowser.WebBrowserWindow.WebBrowserWindow.isPrivate(): |
|
71 return |
|
72 |
|
73 if browser.url().isEmpty(): |
|
74 return |
|
75 |
|
76 tab = ClosedTab(browser.url(), browser.title(), position) |
|
77 self.__closedTabs.insert(0, tab) |
|
78 self.closedTabAvailable.emit(True) |
|
79 |
|
80 def getClosedTabAt(self, index): |
|
81 """ |
|
82 Public method to get the indexed closed tab. |
|
83 |
|
84 @param index index of the tab to return (integer) |
|
85 @return requested tab (ClosedTab) |
|
86 """ |
|
87 if len(self.__closedTabs) > 0 and len(self.__closedTabs) > index: |
|
88 tab = self.__closedTabs.pop(index) |
|
89 else: |
|
90 tab = ClosedTab() |
|
91 self.closedTabAvailable.emit(len(self.__closedTabs) > 0) |
|
92 return tab |
|
93 |
|
94 def isClosedTabAvailable(self): |
|
95 """ |
|
96 Public method to check for closed tabs. |
|
97 |
|
98 @return flag indicating the availability of closed tab data (boolean) |
|
99 """ |
|
100 return len(self.__closedTabs) > 0 |
|
101 |
|
102 def clearList(self): |
|
103 """ |
|
104 Public method to clear the list of closed tabs. |
|
105 """ |
|
106 self.__closedTabs = [] |
|
107 self.closedTabAvailable.emit(False) |
|
108 |
|
109 def allClosedTabs(self): |
|
110 """ |
|
111 Public method to get a list of all closed tabs. |
|
112 |
|
113 @return list of closed tabs (list of ClosedTab) |
|
114 """ |
|
115 return self.__closedTabs |