19 |
19 |
20 |
20 |
21 class HistoryDialog(QDialog, Ui_HistoryDialog): |
21 class HistoryDialog(QDialog, Ui_HistoryDialog): |
22 """ |
22 """ |
23 Class implementing a dialog to manage history. |
23 Class implementing a dialog to manage history. |
24 |
24 |
25 @signal openUrl(QUrl, str) emitted to open a URL in the current tab |
25 @signal openUrl(QUrl, str) emitted to open a URL in the current tab |
26 @signal newTab(QUrl, str) emitted to open a URL in a new tab |
26 @signal newTab(QUrl, str) emitted to open a URL in a new tab |
27 @signal newBackgroundTab(QUrl, str) emitted to open a URL in a new |
27 @signal newBackgroundTab(QUrl, str) emitted to open a URL in a new |
28 background tab |
28 background tab |
29 @signal newWindow(QUrl, str) emitted to open a URL in a new window |
29 @signal newWindow(QUrl, str) emitted to open a URL in a new window |
30 @signal newPrivateWindow(QUrl, str) emitted to open a URL in a new |
30 @signal newPrivateWindow(QUrl, str) emitted to open a URL in a new |
31 private window |
31 private window |
32 """ |
32 """ |
|
33 |
33 openUrl = pyqtSignal(QUrl, str) |
34 openUrl = pyqtSignal(QUrl, str) |
34 newTab = pyqtSignal(QUrl, str) |
35 newTab = pyqtSignal(QUrl, str) |
35 newBackgroundTab = pyqtSignal(QUrl, str) |
36 newBackgroundTab = pyqtSignal(QUrl, str) |
36 newWindow = pyqtSignal(QUrl, str) |
37 newWindow = pyqtSignal(QUrl, str) |
37 newPrivateWindow = pyqtSignal(QUrl, str) |
38 newPrivateWindow = pyqtSignal(QUrl, str) |
38 |
39 |
39 def __init__(self, parent=None, manager=None): |
40 def __init__(self, parent=None, manager=None): |
40 """ |
41 """ |
41 Constructor |
42 Constructor |
42 |
43 |
43 @param parent reference to the parent widget (QWidget |
44 @param parent reference to the parent widget (QWidget |
44 @param manager reference to the history manager object (HistoryManager) |
45 @param manager reference to the history manager object (HistoryManager) |
45 """ |
46 """ |
46 super().__init__(parent) |
47 super().__init__(parent) |
47 self.setupUi(self) |
48 self.setupUi(self) |
48 self.setWindowFlags(Qt.WindowType.Window) |
49 self.setWindowFlags(Qt.WindowType.Window) |
49 |
50 |
50 self.__historyManager = manager |
51 self.__historyManager = manager |
51 if self.__historyManager is None: |
52 if self.__historyManager is None: |
52 import WebBrowser.WebBrowserWindow |
53 import WebBrowser.WebBrowserWindow |
|
54 |
53 self.__historyManager = ( |
55 self.__historyManager = ( |
54 WebBrowser.WebBrowserWindow.WebBrowserWindow.historyManager() |
56 WebBrowser.WebBrowserWindow.WebBrowserWindow.historyManager() |
55 ) |
57 ) |
56 |
58 |
57 self.__model = self.__historyManager.historyTreeModel() |
59 self.__model = self.__historyManager.historyTreeModel() |
58 self.__proxyModel = EricTreeSortFilterProxyModel(self) |
60 self.__proxyModel = EricTreeSortFilterProxyModel(self) |
59 self.__proxyModel.setSortRole(HistoryModel.DateTimeRole) |
61 self.__proxyModel.setSortRole(HistoryModel.DateTimeRole) |
60 self.__proxyModel.setFilterKeyColumn(-1) |
62 self.__proxyModel.setFilterKeyColumn(-1) |
61 self.__proxyModel.setSourceModel(self.__model) |
63 self.__proxyModel.setSourceModel(self.__model) |
67 except AttributeError: |
69 except AttributeError: |
68 header = fm.width("m") * 40 |
70 header = fm.width("m") * 40 |
69 self.historyTree.header().resizeSection(0, header) |
71 self.historyTree.header().resizeSection(0, header) |
70 self.historyTree.header().resizeSection(1, header) |
72 self.historyTree.header().resizeSection(1, header) |
71 self.historyTree.header().setStretchLastSection(True) |
73 self.historyTree.header().setStretchLastSection(True) |
72 self.historyTree.setContextMenuPolicy( |
74 self.historyTree.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
73 Qt.ContextMenuPolicy.CustomContextMenu) |
75 |
74 |
|
75 self.historyTree.activated.connect(self.__activated) |
76 self.historyTree.activated.connect(self.__activated) |
76 self.historyTree.customContextMenuRequested.connect( |
77 self.historyTree.customContextMenuRequested.connect( |
77 self.__customContextMenuRequested) |
78 self.__customContextMenuRequested |
78 |
79 ) |
79 self.searchEdit.textChanged.connect( |
80 |
80 self.__proxyModel.setFilterFixedString) |
81 self.searchEdit.textChanged.connect(self.__proxyModel.setFilterFixedString) |
81 self.removeButton.clicked.connect(self.historyTree.removeSelected) |
82 self.removeButton.clicked.connect(self.historyTree.removeSelected) |
82 self.removeAllButton.clicked.connect(self.__historyManager.clear) |
83 self.removeAllButton.clicked.connect(self.__historyManager.clear) |
83 |
84 |
84 self.__proxyModel.modelReset.connect(self.__modelReset) |
85 self.__proxyModel.modelReset.connect(self.__modelReset) |
85 |
86 |
86 def __modelReset(self): |
87 def __modelReset(self): |
87 """ |
88 """ |
88 Private slot handling a reset of the tree view's model. |
89 Private slot handling a reset of the tree view's model. |
89 """ |
90 """ |
90 self.historyTree.expandAll() |
91 self.historyTree.expandAll() |
91 |
92 |
92 def __customContextMenuRequested(self, pos): |
93 def __customContextMenuRequested(self, pos): |
93 """ |
94 """ |
94 Private slot to handle the context menu request for the bookmarks tree. |
95 Private slot to handle the context menu request for the bookmarks tree. |
95 |
96 |
96 @param pos position the context menu was requested (QPoint) |
97 @param pos position the context menu was requested (QPoint) |
97 """ |
98 """ |
98 menu = QMenu() |
99 menu = QMenu() |
99 idx = self.historyTree.indexAt(pos) |
100 idx = self.historyTree.indexAt(pos) |
100 idx = idx.sibling(idx.row(), 0) |
101 idx = idx.sibling(idx.row(), 0) |
101 if ( |
102 if ( |
102 idx.isValid() and |
103 idx.isValid() |
103 not self.historyTree.model().hasChildren(idx) and |
104 and not self.historyTree.model().hasChildren(idx) |
104 len(self.historyTree.selectionModel().selectedRows()) == 1 |
105 and len(self.historyTree.selectionModel().selectedRows()) == 1 |
105 ): |
106 ): |
106 menu.addAction( |
107 menu.addAction(self.tr("&Open"), self.__openHistoryInCurrentTab) |
107 self.tr("&Open"), |
108 menu.addAction(self.tr("Open in New &Tab"), self.__openHistoryInNewTab) |
108 self.__openHistoryInCurrentTab) |
|
109 menu.addAction( |
|
110 self.tr("Open in New &Tab"), |
|
111 self.__openHistoryInNewTab) |
|
112 menu.addAction( |
109 menu.addAction( |
113 self.tr("Open in New &Background Tab"), |
110 self.tr("Open in New &Background Tab"), |
114 self.__openHistoryInNewBackgroundTab) |
111 self.__openHistoryInNewBackgroundTab, |
|
112 ) |
115 menu.addAction( |
113 menu.addAction( |
116 self.tr("Open in New &Window"), |
114 self.tr("Open in New &Window"), self.__openHistoryInNewWindow |
117 self.__openHistoryInNewWindow) |
115 ) |
118 menu.addAction( |
116 menu.addAction( |
119 self.tr("Open in New Pri&vate Window"), |
117 self.tr("Open in New Pri&vate Window"), |
120 self.__openHistoryInPrivateWindow) |
118 self.__openHistoryInPrivateWindow, |
|
119 ) |
121 menu.addSeparator() |
120 menu.addSeparator() |
122 menu.addAction(self.tr("&Copy"), self.__copyHistory) |
121 menu.addAction(self.tr("&Copy"), self.__copyHistory) |
123 menu.addAction(self.tr("&Remove"), self.historyTree.removeSelected) |
122 menu.addAction(self.tr("&Remove"), self.historyTree.removeSelected) |
124 menu.exec(QCursor.pos()) |
123 menu.exec(QCursor.pos()) |
125 |
124 |
126 def __activated(self, idx): |
125 def __activated(self, idx): |
127 """ |
126 """ |
128 Private slot to handle the activation of an entry. |
127 Private slot to handle the activation of an entry. |
129 |
128 |
130 @param idx reference to the entry index (QModelIndex) |
129 @param idx reference to the entry index (QModelIndex) |
131 """ |
130 """ |
132 if ( |
131 if QApplication.keyboardModifiers() & Qt.KeyboardModifier.ControlModifier: |
133 QApplication.keyboardModifiers() & |
|
134 Qt.KeyboardModifier.ControlModifier |
|
135 ): |
|
136 self.__openHistoryInNewTab() |
132 self.__openHistoryInNewTab() |
137 elif ( |
133 elif QApplication.keyboardModifiers() & Qt.KeyboardModifier.ShiftModifier: |
138 QApplication.keyboardModifiers() & |
|
139 Qt.KeyboardModifier.ShiftModifier |
|
140 ): |
|
141 self.__openHistoryInNewWindow() |
134 self.__openHistoryInNewWindow() |
142 else: |
135 else: |
143 self.__openHistoryInCurrentTab() |
136 self.__openHistoryInCurrentTab() |
144 |
137 |
145 def __openHistoryInCurrentTab(self): |
138 def __openHistoryInCurrentTab(self): |
146 """ |
139 """ |
147 Private slot to open a history entry in the current browser tab. |
140 Private slot to open a history entry in the current browser tab. |
148 """ |
141 """ |
149 self.__openHistory() |
142 self.__openHistory() |
150 |
143 |
151 def __openHistoryInNewTab(self): |
144 def __openHistoryInNewTab(self): |
152 """ |
145 """ |
153 Private slot to open a history entry in a new browser tab. |
146 Private slot to open a history entry in a new browser tab. |
154 """ |
147 """ |
155 self.__openHistory(newTab=True) |
148 self.__openHistory(newTab=True) |
156 |
149 |
157 def __openHistoryInNewBackgroundTab(self): |
150 def __openHistoryInNewBackgroundTab(self): |
158 """ |
151 """ |
159 Private slot to open a history entry in a new background tab. |
152 Private slot to open a history entry in a new background tab. |
160 """ |
153 """ |
161 self.__openHistory(newTab=True, background=True) |
154 self.__openHistory(newTab=True, background=True) |
162 |
155 |
163 def __openHistoryInNewWindow(self): |
156 def __openHistoryInNewWindow(self): |
164 """ |
157 """ |
165 Private slot to open a history entry in a new browser window. |
158 Private slot to open a history entry in a new browser window. |
166 """ |
159 """ |
167 self.__openHistory(newWindow=True) |
160 self.__openHistory(newWindow=True) |
168 |
161 |
169 def __openHistoryInPrivateWindow(self): |
162 def __openHistoryInPrivateWindow(self): |
170 """ |
163 """ |
171 Private slot to open a history entry in a new private browser window. |
164 Private slot to open a history entry in a new private browser window. |
172 """ |
165 """ |
173 self.__openHistory(newWindow=True, privateWindow=True) |
166 self.__openHistory(newWindow=True, privateWindow=True) |
174 |
167 |
175 def __openHistory(self, newTab=False, background=False, |
168 def __openHistory( |
176 newWindow=False, privateWindow=False): |
169 self, newTab=False, background=False, newWindow=False, privateWindow=False |
|
170 ): |
177 """ |
171 """ |
178 Private method to open a history entry. |
172 Private method to open a history entry. |
179 |
173 |
180 @param newTab flag indicating to open the feed message in a new tab |
174 @param newTab flag indicating to open the feed message in a new tab |
181 @type bool |
175 @type bool |
182 @param background flag indicating to open the bookmark in a new |
176 @param background flag indicating to open the bookmark in a new |
183 background tab |
177 background tab |
184 @type bool |
178 @type bool |
191 """ |
185 """ |
192 idx = self.historyTree.currentIndex() |
186 idx = self.historyTree.currentIndex() |
193 if newTab: |
187 if newTab: |
194 if background: |
188 if background: |
195 self.newBackgroundTab.emit( |
189 self.newBackgroundTab.emit( |
196 idx.data(HistoryModel.UrlRole), |
190 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) |
197 idx.data(HistoryModel.TitleRole)) |
191 ) |
198 else: |
192 else: |
199 self.newTab.emit( |
193 self.newTab.emit( |
200 idx.data(HistoryModel.UrlRole), |
194 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) |
201 idx.data(HistoryModel.TitleRole)) |
195 ) |
202 elif newWindow: |
196 elif newWindow: |
203 if privateWindow: |
197 if privateWindow: |
204 self.newPrivateWindow.emit( |
198 self.newPrivateWindow.emit( |
205 idx.data(HistoryModel.UrlRole), |
199 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) |
206 idx.data(HistoryModel.TitleRole)) |
200 ) |
207 else: |
201 else: |
208 self.newWindow.emit( |
202 self.newWindow.emit( |
209 idx.data(HistoryModel.UrlRole), |
203 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) |
210 idx.data(HistoryModel.TitleRole)) |
204 ) |
211 else: |
205 else: |
212 self.openUrl.emit( |
206 self.openUrl.emit( |
213 idx.data(HistoryModel.UrlRole), |
207 idx.data(HistoryModel.UrlRole), idx.data(HistoryModel.TitleRole) |
214 idx.data(HistoryModel.TitleRole)) |
208 ) |
215 |
209 |
216 def __copyHistory(self): |
210 def __copyHistory(self): |
217 """ |
211 """ |
218 Private slot to copy a history entry's URL to the clipboard. |
212 Private slot to copy a history entry's URL to the clipboard. |
219 """ |
213 """ |
220 idx = self.historyTree.currentIndex() |
214 idx = self.historyTree.currentIndex() |
221 if not idx.parent().isValid(): |
215 if not idx.parent().isValid(): |
222 return |
216 return |
223 |
217 |
224 url = idx.data(HistoryModel.UrlStringRole) |
218 url = idx.data(HistoryModel.UrlStringRole) |
225 |
219 |
226 clipboard = QApplication.clipboard() |
220 clipboard = QApplication.clipboard() |
227 clipboard.setText(url) |
221 clipboard.setText(url) |