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