WebBrowser/CookieJar/CookiesExceptionsDialog.py

branch
QtWebEngine
changeset 4845
2d22ff71c005
parent 4631
5c1a96925da4
child 4895
3baaf8303a7f
equal deleted inserted replaced
4840:69ee7965ba27 4845:2d22ff71c005
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 2016 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog for the configuration of cookie exceptions.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot, QSortFilterProxyModel
13 from PyQt5.QtGui import QFont, QFontMetrics
14 from PyQt5.QtWidgets import QDialog, QCompleter
15
16 from .CookieExceptionsModel import CookieExceptionsModel
17 from .CookieModel import CookieModel
18
19 from .Ui_CookiesExceptionsDialog import Ui_CookiesExceptionsDialog
20
21
22 class CookiesExceptionsDialog(QDialog, Ui_CookiesExceptionsDialog):
23 """
24 Class implementing a dialog for the configuration of cookie exceptions.
25 """
26 def __init__(self, cookieJar, parent=None):
27 """
28 Constructor
29
30 @param cookieJar reference to the cookie jar (CookieJar)
31 @param parent reference to the parent widget (QWidget)
32 """
33 super(CookiesExceptionsDialog, self).__init__(parent)
34 self.setupUi(self)
35
36 self.__cookieJar = cookieJar
37
38 self.removeButton.clicked.connect(
39 self.exceptionsTable.removeSelected)
40 self.removeAllButton.clicked.connect(
41 self.exceptionsTable.removeAll)
42
43 self.exceptionsTable.verticalHeader().hide()
44 self.__exceptionsModel = CookieExceptionsModel(cookieJar)
45 self.__proxyModel = QSortFilterProxyModel(self)
46 self.__proxyModel.setSourceModel(self.__exceptionsModel)
47 self.searchEdit.textChanged.connect(
48 self.__proxyModel.setFilterFixedString)
49 self.exceptionsTable.setModel(self.__proxyModel)
50
51 cookieModel = CookieModel(cookieJar, self)
52 self.domainEdit.setCompleter(QCompleter(cookieModel, self.domainEdit))
53
54 f = QFont()
55 f.setPointSize(10)
56 fm = QFontMetrics(f)
57 height = fm.height() + fm.height() // 3
58 self.exceptionsTable.verticalHeader().setDefaultSectionSize(height)
59 self.exceptionsTable.verticalHeader().setMinimumSectionSize(-1)
60 for section in range(self.__exceptionsModel.columnCount()):
61 header = self.exceptionsTable.horizontalHeader()\
62 .sectionSizeHint(section)
63 if section == 0:
64 header = fm.width("averagebiglonghost.averagedomain.info")
65 elif section == 1:
66 header = fm.width(self.tr("Allow For Session"))
67 buffer = fm.width("mm")
68 header += buffer
69 self.exceptionsTable.horizontalHeader()\
70 .resizeSection(section, header)
71
72 def setDomainName(self, domain):
73 """
74 Public method to set the domain to be displayed.
75
76 @param domain domain name to be displayed (string)
77 """
78 self.domainEdit.setText(domain)
79
80 @pyqtSlot(str)
81 def on_domainEdit_textChanged(self, txt):
82 """
83 Private slot to handle a change of the domain edit text.
84
85 @param txt current text of the edit (string)
86 """
87 enabled = txt != ""
88 self.blockButton.setEnabled(enabled)
89 self.allowButton.setEnabled(enabled)
90 self.allowForSessionButton.setEnabled(enabled)
91
92 @pyqtSlot()
93 def on_blockButton_clicked(self):
94 """
95 Private slot to block cookies of a domain.
96 """
97 from .CookieJar import CookieJar
98 self.__exceptionsModel.addRule(self.domainEdit.text(), CookieJar.Block)
99 self.domainEdit.clear()
100
101 @pyqtSlot()
102 def on_allowForSessionButton_clicked(self):
103 """
104 Private slot to allow cookies of a domain for the current session only.
105 """
106 from .CookieJar import CookieJar
107 self.__exceptionsModel.addRule(self.domainEdit.text(),
108 CookieJar.AllowForSession)
109 self.domainEdit.clear()
110
111 @pyqtSlot()
112 def on_allowButton_clicked(self):
113 """
114 Private slot to allow cookies of a domain.
115 """
116 from .CookieJar import CookieJar
117 self.__exceptionsModel.addRule(self.domainEdit.text(), CookieJar.Allow)
118 self.domainEdit.clear()

eric ide

mercurial