|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to manage the ClickToFlash whitelist. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot, Qt |
|
11 from PyQt4.QtGui import QDialog, QStringListModel, QSortFilterProxyModel, \ |
|
12 QInputDialog, QLineEdit |
|
13 |
|
14 from .Ui_ClickToFlashWhitelistDialog import Ui_ClickToFlashWhitelistDialog |
|
15 |
|
16 import UI.PixmapCache |
|
17 |
|
18 |
|
19 class ClickToFlashWhitelistDialog(QDialog, Ui_ClickToFlashWhitelistDialog): |
|
20 """ |
|
21 Class implementing a dialog to manage the ClickToFlash whitelist |
|
22 """ |
|
23 def __init__(self, whitelist, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param whitelist list of whitelisted hosts (list of string) |
|
28 @param parent reference to the parent widget (QWidget) |
|
29 """ |
|
30 super().__init__(parent) |
|
31 self.setupUi(self) |
|
32 |
|
33 self.clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft.png")) |
|
34 self.iconLabel.setPixmap(UI.PixmapCache.getPixmap("flashBlock48.png")) |
|
35 |
|
36 self.__model = QStringListModel(whitelist[:], self) |
|
37 self.__model.sort(0) |
|
38 self.__proxyModel = QSortFilterProxyModel(self) |
|
39 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive) |
|
40 self.__proxyModel.setSourceModel(self.__model) |
|
41 self.whitelist.setModel(self.__proxyModel) |
|
42 |
|
43 self.searchEdit.textChanged.connect(self.__proxyModel.setFilterFixedString) |
|
44 |
|
45 self.removeButton.clicked[()].connect(self.whitelist.removeSelected) |
|
46 self.removeAllButton.clicked[()].connect(self.whitelist.removeAll) |
|
47 |
|
48 @pyqtSlot() |
|
49 def on_addButton_clicked(self): |
|
50 """ |
|
51 Private slot to add an entry to the whitelist. |
|
52 """ |
|
53 host, ok = QInputDialog.getText( |
|
54 self, |
|
55 self.trUtf8("ClickToFlash Whitelist"), |
|
56 self.trUtf8("Enter host name to add to whitelist:"), |
|
57 QLineEdit.Normal) |
|
58 if ok and host != "" and host not in self.__model.stringList(): |
|
59 self.__model.insertRow(self.__model.rowCount()) |
|
60 self.__model.setData( |
|
61 self.__model.index(self.__model.rowCount() - 1), host) |
|
62 self.__model.sort(0) |
|
63 |
|
64 def getWhitelist(self): |
|
65 """ |
|
66 Public method to get the whitelisted hosts. |
|
67 |
|
68 @return list of whitelisted hosts (list of string) |
|
69 """ |
|
70 return self.__model.stringList() |