eric6/WebBrowser/Network/SendRefererWhitelistDialog.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7781
607a6098cb44
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

4832
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4832
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to manage the Send Referer whitelist.
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt5.QtCore import pyqtSlot, Qt, QSortFilterProxyModel, QStringListModel
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt5.QtWidgets import QDialog, QInputDialog, QLineEdit
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from .Ui_SendRefererWhitelistDialog import Ui_SendRefererWhitelistDialog
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 import Preferences
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class SendRefererWhitelistDialog(QDialog, Ui_SendRefererWhitelistDialog):
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Class implementing a dialog to manage the Send Referer whitelist.
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 def __init__(self, parent=None):
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Constructor
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @param parent reference to the parent widget (QWidget)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 super(SendRefererWhitelistDialog, self).__init__(parent)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 self.setupUi(self)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 self.__model = QStringListModel(
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Preferences.getWebBrowser("SendRefererWhitelist"), self)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 self.__model.sort(0)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.__proxyModel = QSortFilterProxyModel(self)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.__proxyModel.setSourceModel(self.__model)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.whitelist.setModel(self.__proxyModel)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.searchEdit.textChanged.connect(
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.__proxyModel.setFilterFixedString)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.removeButton.clicked.connect(self.whitelist.removeSelected)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.removeAllButton.clicked.connect(self.whitelist.removeAll)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @pyqtSlot()
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 def on_addButton_clicked(self):
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 Private slot to add an entry to the whitelist.
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 host, ok = QInputDialog.getText(
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self,
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.tr("Send Referer Whitelist"),
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.tr("Enter host name to add to the whitelist:"),
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 QLineEdit.Normal)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 if ok and host != "" and host not in self.__model.stringList():
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__model.insertRow(self.__model.rowCount())
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.__model.setData(
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.__model.index(self.__model.rowCount() - 1), host)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__model.sort(0)
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 def accept(self):
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 Public method to accept the dialog data.
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 Preferences.setWebBrowser(
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 "SendRefererWhitelist", self.__model.stringList())
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
6032ba9fdcc7 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 super(SendRefererWhitelistDialog, self).accept()

eric ide

mercurial