eric6/Helpviewer/Network/SendRefererWhitelistDialog.py

branch
maintenance
changeset 7286
7eb04391adf7
parent 7226
babe80d84a3e
parent 7285
1ff497f33f31
child 7287
1c17f2191bdd
equal deleted inserted replaced
7226:babe80d84a3e 7286:7eb04391adf7
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 manage the Send Referer whitelist.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot, Qt, QSortFilterProxyModel, QStringListModel
13 from PyQt5.QtWidgets import QDialog, QInputDialog, QLineEdit
14
15 from .Ui_SendRefererWhitelistDialog import Ui_SendRefererWhitelistDialog
16
17 import Preferences
18
19
20 class SendRefererWhitelistDialog(QDialog, Ui_SendRefererWhitelistDialog):
21 """
22 Class implementing a dialog to manage the Send Referer whitelist.
23 """
24 def __init__(self, parent=None):
25 """
26 Constructor
27
28 @param parent reference to the parent widget (QWidget)
29 """
30 super(SendRefererWhitelistDialog, self).__init__(parent)
31 self.setupUi(self)
32
33 self.__model = QStringListModel(
34 Preferences.getHelp("SendRefererWhitelist"), self)
35 self.__model.sort(0)
36 self.__proxyModel = QSortFilterProxyModel(self)
37 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
38 self.__proxyModel.setSourceModel(self.__model)
39 self.whitelist.setModel(self.__proxyModel)
40
41 self.searchEdit.textChanged.connect(
42 self.__proxyModel.setFilterFixedString)
43
44 self.removeButton.clicked.connect(self.whitelist.removeSelected)
45 self.removeAllButton.clicked.connect(self.whitelist.removeAll)
46
47 @pyqtSlot()
48 def on_addButton_clicked(self):
49 """
50 Private slot to add an entry to the whitelist.
51 """
52 host, ok = QInputDialog.getText(
53 self,
54 self.tr("Send Referer Whitelist"),
55 self.tr("Enter host name to add to the whitelist:"),
56 QLineEdit.Normal)
57 if ok and host != "" and host not in self.__model.stringList():
58 self.__model.insertRow(self.__model.rowCount())
59 self.__model.setData(
60 self.__model.index(self.__model.rowCount() - 1), host)
61 self.__model.sort(0)
62
63 def accept(self):
64 """
65 Public method to accept the dialog data.
66 """
67 Preferences.setHelp("SendRefererWhitelist", self.__model.stringList())
68
69 super(SendRefererWhitelistDialog, self).accept()

eric ide

mercurial