|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to configure the AdBlock exceptions. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot, Qt |
|
13 from PyQt5.QtWidgets import QDialog |
|
14 |
|
15 from .Ui_AdBlockExceptionsDialog import Ui_AdBlockExceptionsDialog |
|
16 |
|
17 import UI.PixmapCache |
|
18 |
|
19 |
|
20 class AdBlockExceptionsDialog(QDialog, Ui_AdBlockExceptionsDialog): |
|
21 """ |
|
22 Class implementing a dialog to configure the AdBlock exceptions. |
|
23 """ |
|
24 def __init__(self, parent=None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param parent reference to the parent widget |
|
29 @type QWidget |
|
30 """ |
|
31 super(AdBlockExceptionsDialog, self).__init__(parent) |
|
32 self.setupUi(self) |
|
33 self.setWindowFlags(Qt.Window) |
|
34 |
|
35 self.iconLabel.setPixmap( |
|
36 UI.PixmapCache.getPixmap("adBlockPlusGreen48.png")) |
|
37 |
|
38 self.hostEdit.setInactiveText(self.tr("Enter host to be added...")) |
|
39 |
|
40 self.buttonBox.setFocus() |
|
41 |
|
42 def load(self, hosts): |
|
43 """ |
|
44 Public slot to load the list of excepted hosts. |
|
45 |
|
46 @param hosts list of excepted hosts |
|
47 @type list of str |
|
48 """ |
|
49 self.hostList.clear() |
|
50 self.hostList.addItems(hosts) |
|
51 |
|
52 @pyqtSlot(str) |
|
53 def on_hostEdit_textChanged(self, txt): |
|
54 """ |
|
55 Private slot to handle changes of the host edit. |
|
56 |
|
57 @param txt text of the edit |
|
58 @type str |
|
59 """ |
|
60 self.addButton.setEnabled(bool(txt)) |
|
61 |
|
62 @pyqtSlot() |
|
63 def on_addButton_clicked(self): |
|
64 """ |
|
65 Private slot to handle a click of the add button. |
|
66 """ |
|
67 self.hostList.addItem(self.hostEdit.text()) |
|
68 self.hostEdit.clear() |
|
69 |
|
70 @pyqtSlot() |
|
71 def on_hostList_itemSelectionChanged(self): |
|
72 """ |
|
73 Private slot handling a change of the number of selected items. |
|
74 """ |
|
75 self.deleteButton.setEnabled(len(self.hostList.selectedItems()) > 0) |
|
76 |
|
77 @pyqtSlot() |
|
78 def on_deleteButton_clicked(self): |
|
79 """ |
|
80 Private slot handling a click of the delete button. |
|
81 """ |
|
82 for itm in self.hostList.selectedItems(): |
|
83 row = self.hostList.row(itm) |
|
84 removedItem = self.hostList.takeItem(row) |
|
85 del removedItem |
|
86 |
|
87 def accept(self): |
|
88 """ |
|
89 Public slot handling the acceptance of the dialog. |
|
90 """ |
|
91 hosts = [] |
|
92 for row in range(self.hostList.count()): |
|
93 hosts.append(self.hostList.item(row).text()) |
|
94 |
|
95 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
96 WebBrowserWindow.adBlockManager().setExceptions(hosts) |
|
97 |
|
98 super(AdBlockExceptionsDialog, self).accept() |