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