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