|
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 saved logins. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import * |
|
11 from PyQt4.QtGui import * |
|
12 |
|
13 import Helpviewer.HelpWindow |
|
14 |
|
15 from PasswordModel import PasswordModel |
|
16 |
|
17 from Ui_PasswordsDialog import Ui_PasswordsDialog |
|
18 |
|
19 import UI.PixmapCache |
|
20 |
|
21 class PasswordsDialog(QDialog, Ui_PasswordsDialog): |
|
22 """ |
|
23 Class implementing a dialog to show all saved logins. |
|
24 """ |
|
25 def __init__(self, parent = None): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param parent reference to the parent widget (QWidget) |
|
30 """ |
|
31 QDialog.__init__(self, parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft.png")) |
|
35 |
|
36 self.__showPasswordsText = self.trUtf8("Show Passwords") |
|
37 self.__hidePasswordsText = self.trUtf8("Hide Passwords") |
|
38 self.passwordsButton.setText(self.__showPasswordsText) |
|
39 |
|
40 self.connect(self.removeButton, SIGNAL("clicked()"), |
|
41 self.passwordsTable.removeSelected) |
|
42 self.connect(self.removeAllButton, SIGNAL("clicked()"), |
|
43 self.passwordsTable.removeAll) |
|
44 |
|
45 self.passwordsTable.verticalHeader().hide() |
|
46 self.__passwordModel = \ |
|
47 PasswordModel(Helpviewer.HelpWindow.HelpWindow.passwordManager(), self) |
|
48 self.__proxyModel = QSortFilterProxyModel(self) |
|
49 self.__proxyModel.setSourceModel(self.__passwordModel) |
|
50 self.connect(self.searchEdit, SIGNAL("textChanged(QString)"), |
|
51 self.__proxyModel.setFilterFixedString) |
|
52 self.passwordsTable.setModel(self.__proxyModel) |
|
53 |
|
54 fm = QFontMetrics(QFont()) |
|
55 height = fm.height() + fm.height() / 3 |
|
56 self.passwordsTable.verticalHeader().setDefaultSectionSize(height) |
|
57 self.passwordsTable.verticalHeader().setMinimumSectionSize(-1) |
|
58 |
|
59 self.__calculateHeaderSizes() |
|
60 |
|
61 def __calculateHeaderSizes(self): |
|
62 """ |
|
63 Private method to calculate the section sizes of the horizontal header. |
|
64 """ |
|
65 fm = QFontMetrics(QFont()) |
|
66 for section in range(self.__passwordModel.columnCount()): |
|
67 header = self.passwordsTable.horizontalHeader().sectionSizeHint(section) |
|
68 if section == 0: |
|
69 header = fm.width("averagebiglongsitename") |
|
70 elif section == 1: |
|
71 header = fm.width("averagelongusername") |
|
72 elif section == 2: |
|
73 header = fm.width("averagelongpassword") |
|
74 buffer = fm.width("mm") |
|
75 header += buffer |
|
76 self.passwordsTable.horizontalHeader().resizeSection(section, header) |
|
77 self.passwordsTable.horizontalHeader().setStretchLastSection(True) |
|
78 |
|
79 @pyqtSlot() |
|
80 def on_passwordsButton_clicked(self): |
|
81 """ |
|
82 Private slot to switch the password display mode. |
|
83 """ |
|
84 if self.__passwordModel.showPasswords(): |
|
85 self.__passwordModel.setShowPasswords(False) |
|
86 self.passwordsButton.setText(self.__showPasswordsText) |
|
87 else: |
|
88 res = QMessageBox.question(self, |
|
89 self.trUtf8("Saved Passwords"), |
|
90 self.trUtf8("""Do you really want to show passwords?"""), |
|
91 QMessageBox.StandardButtons(\ |
|
92 QMessageBox.No | \ |
|
93 QMessageBox.Yes), |
|
94 QMessageBox.No) |
|
95 if res == QMessageBox.Yes: |
|
96 self.__passwordModel.setShowPasswords(True) |
|
97 self.passwordsButton.setText(self.__hidePasswordsText) |
|
98 self.__calculateHeaderSizes() |