Helpviewer/CookieJar/CookiesDialog.py

changeset 0
de9c2efb9d02
child 7
c679fb30c8f3
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to show all cookies.
8 """
9
10 from PyQt4.QtCore import *
11 from PyQt4.QtGui import *
12
13 from CookieModel import CookieModel
14 from CookieDetailsDialog import CookieDetailsDialog
15 from CookiesExceptionsDialog import CookiesExceptionsDialog
16
17 from Ui_CookiesDialog import Ui_CookiesDialog
18
19 import UI.PixmapCache
20
21 class CookiesDialog(QDialog, Ui_CookiesDialog):
22 """
23 Class implementing a dialog to show all cookies.
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 self.addButton.setEnabled(False)
37
38 self.__cookieJar = cookieJar
39
40 self.connect(self.removeButton, SIGNAL("clicked()"),
41 self.cookiesTable.removeSelected)
42 self.connect(self.removeAllButton, SIGNAL("clicked()"),
43 self.cookiesTable.removeAll)
44
45 self.cookiesTable.verticalHeader().hide()
46 model = CookieModel(cookieJar, self)
47 self.__proxyModel = QSortFilterProxyModel(self)
48 self.__proxyModel.setSourceModel(model)
49 self.connect(self.searchEdit, SIGNAL("textChanged(QString)"),
50 self.__proxyModel.setFilterFixedString)
51 self.cookiesTable.setModel(self.__proxyModel)
52 self.connect(self.cookiesTable,
53 SIGNAL("doubleClicked(const QModelIndex&)"),
54 self.__showCookieDetails)
55 self.connect(self.cookiesTable.selectionModel(),
56 SIGNAL("selectionChanged(const QItemSelection&, const QItemSelection&)"),
57 self.__tableSelectionChanged)
58 self.connect(self.cookiesTable.model(),
59 SIGNAL("modelReset()"),
60 self.__tableModelReset)
61
62 fm = QFontMetrics(QFont())
63 height = fm.height() + fm.height() / 3
64 self.cookiesTable.verticalHeader().setDefaultSectionSize(height)
65 self.cookiesTable.verticalHeader().setMinimumSectionSize(-1)
66 for section in range(model.columnCount()):
67 header = self.cookiesTable.horizontalHeader().sectionSizeHint(section)
68 if section == 0:
69 header = fm.width("averagebiglonghost.averagedomain.info")
70 elif section == 1:
71 header = fm.width("_session_id")
72 elif section == 4:
73 header = fm.width(QDateTime.currentDateTime().toString(Qt.LocalDate))
74 buffer = fm.width("mm")
75 header += buffer
76 self.cookiesTable.horizontalHeader().resizeSection(section, header)
77 self.cookiesTable.horizontalHeader().setStretchLastSection(True)
78
79 self.__detailsDialog = None
80
81 def __showCookieDetails(self, index):
82 """
83 Private slot to show a dialog with the cookie details.
84
85 @param index index of the entry to show (QModelIndex)
86 """
87 if not index.isValid():
88 return
89
90 cookiesTable = self.sender()
91 if cookiesTable is None:
92 return
93
94 model = cookiesTable.model()
95 row = index.row()
96
97 domain = model.data(model.index(row, 0)).toString()
98 name = model.data(model.index(row, 1)).toString()
99 path = model.data(model.index(row, 2)).toString()
100 secure = model.data(model.index(row, 3)).toBool()
101 expires = model.data(model.index(row, 4)).toDateTime()\
102 .toString("yyyy-MM-dd hh:mm")
103 value = unicode(
104 QByteArray.fromPercentEncoding(model.data(model.index(row, 5)).toByteArray()))
105
106 if self.__detailsDialog is None:
107 self.__detailsDialog = CookieDetailsDialog(self)
108 self.__detailsDialog.setData(domain, name, path, secure, expires, value)
109 self.__detailsDialog.show()
110
111 @pyqtSlot()
112 def on_addButton_clicked(self):
113 """
114 Private slot to add a new exception.
115 """
116 selection = self.cookiesTable.selectionModel().selectedRows()
117 if len(selection) == 0:
118 return
119
120 firstSelected = selection[0]
121 domainSelection = firstSelected.sibling(firstSelected.row(), 0)
122 domain = self.__proxyModel.data(domainSelection, Qt.DisplayRole).toString()
123 dlg = CookiesExceptionsDialog(self.__cookieJar, self)
124 dlg.setDomainName(domain)
125 dlg.exec_()
126
127 def __tableSelectionChanged(self, selected, deselected):
128 """
129 Private slot to handle a change of selected items.
130
131 @param selected selected indexes (QItemSelection)
132 @param deselected deselected indexes (QItemSelection)
133 """
134 self.addButton.setEnabled(len(selected.indexes()) > 0)
135
136 def __tableModelReset(self):
137 """
138 Private slot to handle a reset of the cookies table.
139 """
140 self.addButton.setEnabled(False)

eric ide

mercurial