def editPassword(self, item): row = self.passwordTable.row(item) group = self.pwMap.groups[self.selectedGroup] try: decrypted = self.cachedOrDecrypt(row) except CallException: return dialog = AddPasswordDialog() entry = group.entry(row) dialog.keyEdit.setText(s2q(entry[0])) dialog.pwEdit1.setText(s2q(decrypted)) dialog.pwEdit2.setText(s2q(decrypted)) if not dialog.exec_(): return item = QtGui.QTableWidgetItem(dialog.key()) pwItem = QtGui.QTableWidgetItem("*****") self.passwordTable.setItem(row, self.KEY_IDX, item) self.passwordTable.setItem(row, self.PASSWORD_IDX, pwItem) plainPw = q2s(dialog.pw1()) encPw = self.pwMap.encryptPassword(plainPw, self.selectedGroup) bkupPw = self.pwMap.backupKey.encryptPassword(plainPw) group.updateEntry(row, q2s(dialog.key()), encPw, bkupPw) self.cachePassword(row, plainPw) self.setModified(True)
def copyPasswordFromItem(self, item): row = self.passwordTable.row(item) try: decrypted = self.cachedOrDecrypt(row) except CallException: return clipboard = QtGui.QApplication.clipboard() clipboard.setText(s2q(decrypted)) self.cachePassword(row, decrypted)
def cachePassword(self, row, password): """ Cache decrypted password for group and row. Cached items are keps as data of QTableWidgetItem so that deletion invalidates cache. Cache applies to currently selectedGroup. Switching between groups clears the table and thus invalidates cached passwords. """ item = self.passwordTable.item(row, MainWindow.CACHE_IDX) item.setData(QtCore.Qt.UserRole, QtCore.QVariant(s2q(password)))
def showPassword(self, item): # check if this password has been decrypted, # use cached version row = self.passwordTable.row(item) try: decrypted = self.cachedOrDecrypt(row) except CallException: return item = QtGui.QTableWidgetItem(s2q(decrypted)) self.cachePassword(row, decrypted) self.passwordTable.setItem(row, self.PASSWORD_IDX, item)
def showPassword(self, item): #check if this password has been decrypted, use cached version row = self.passwordTable.row(item) try: decrypted = self.cachedOrDecrypt(row) except CallException: return item = QtGui.QTableWidgetItem(s2q(decrypted)) self.cachePassword(row, decrypted) self.passwordTable.setItem(row, self.PASSWORD_IDX, item)
def __init__(self, pwMap, dbFilename): """ @param pwMap: a PasswordMap instance with encrypted passwords @param dbFilename: file name for saving pwMap """ QtGui.QMainWindow.__init__(self) self.setupUi(self) self.pwMap = pwMap self.selectedGroup = None self.modified = False #modified flag "Save?" question on exit self.dbFilename = dbFilename self.groupsModel = QtGui.QStandardItemModel() self.groupsModel.setHorizontalHeaderLabels(["Password group"]) self.groupsFilter = QtGui.QSortFilterProxyModel() self.groupsFilter.setSourceModel(self.groupsModel) self.groupsTree.setModel(self.groupsFilter) self.groupsTree.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.groupsTree.customContextMenuRequested.connect(self.showGroupsContextMenu) self.groupsTree.clicked.connect(self.loadPasswordsBySelection) self.groupsTree.selectionModel().selectionChanged.connect(self.loadPasswordsBySelection) self.groupsTree.setSortingEnabled(True) self.passwordTable.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.passwordTable.customContextMenuRequested.connect(self.showPasswdContextMenu) self.passwordTable.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.passwordTable.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) shortcut = QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self.passwordTable, self.copyPasswordFromSelection) shortcut.setContext(QtCore.Qt.WidgetShortcut) self.actionQuit.triggered.connect(self.close) self.actionBackup.triggered.connect(self.saveBackup) self.actionSave.triggered.connect(self.saveDatabase) self.actionSave.setShortcut(QtGui.QKeySequence("Ctrl+S")) headerKey = QtGui.QTableWidgetItem("Key"); headerValue = QtGui.QTableWidgetItem("Value"); self.passwordTable.setColumnCount(2) self.passwordTable.setHorizontalHeaderItem(self.KEY_IDX, headerKey) self.passwordTable.setHorizontalHeaderItem(self.PASSWORD_IDX, headerValue) self.searchEdit.textChanged.connect(self.filterGroups) groupNames = self.pwMap.groups.keys() for groupName in groupNames: item = QtGui.QStandardItem(s2q(groupName)) self.groupsModel.appendRow(item) self.groupsTree.sortByColumn(0, QtCore.Qt.AscendingOrder)
def __init__(self, passwds, database): """ @param passwds: a PasswordMap instance w/ encrypted passwords @param database: file name for saving pwMap """ DeOS_Vault.__init__(self, passwds, database) self.groupsTree.setModel(self.groupsFilter) self.groupsTree.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.groupsTree.customContextMenuRequested.connect( self.showGroupsContextMenu) self.groupsTree.clicked.connect(self.loadPasswordsBySelection) self.groupsTree.selectionModel().selectionChanged.connect( self.loadPasswordsBySelection) self.groupsTree.setSortingEnabled(True) self.passwordTable.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.passwordTable.customContextMenuRequested.connect( self.showPasswdContextMenu) self.passwordTable.setSelectionBehavior( QtGui.QAbstractItemView.SelectRows) self.passwordTable.setSelectionMode( QtGui.QAbstractItemView.SingleSelection) # Shortcut shortcut = QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self.passwordTable, self.copyPasswordFromSelection) shortcut.setContext(QtCore.Qt.WidgetShortcut) # Action Triggers self.actionQuit.triggered.connect(self.close) self.actionBackup.triggered.connect(self.saveBackup) self.actionSave.triggered.connect(self.saveDatabase) self.actionSave.setShortcut(QtGui.QKeySequence("Ctrl+S")) # Header Key/Value Items headerKey = QtGui.QTableWidgetItem("Key") headerValue = QtGui.QTableWidgetItem("Value") # Password Table self.passwordTable.setColumnCount(2) self.passwordTable.setHorizontalHeaderItem(self.KEY_IDX, headerKey) self.passwordTable.setHorizontalHeaderItem(self.PASSWORD_IDX, headerValue) # Search Edit self.searchEdit.textChanged.connect(self.filterGroups) # Groups groupNames = self.pwMap.groups.keys() for groupName in groupNames: item = QtGui.QStandardItem(s2q(groupName)) self.groupsModel.appendRow(item) # Groups Tree self.groupsTree.sortByColumn(0, QtCore.Qt.AscendingOrder)
def loadPasswords(self, item): """ Slot that should load items for group that has been clicked on. """ #self.passwordTable.clear() name = q2s(item.text()) self.selectedGroup = name group = self.pwMap.groups[name] self.passwordTable.setRowCount(len(group.entries)) self.passwordTable.setColumnCount(2) i = 0 for key, encValue, bkupValue in group.entries: item = QtGui.QTableWidgetItem(s2q(key)) pwItem = QtGui.QTableWidgetItem("*****") self.passwordTable.setItem(i, self.KEY_IDX, item) self.passwordTable.setItem(i, self.PASSWORD_IDX, pwItem) i = i + 1 self.passwordTable.resizeRowsToContents()
def loadPasswords(self, item): """ Slot that should load items for group that has been clicked on. """ #self.passwordTable.clear() name = q2s(item.text()) self.selectedGroup = name group = self.pwMap.groups[name] self.passwordTable.setRowCount(len(group.entries)) self.passwordTable.setColumnCount(2) i = 0 for key, encValue, bkupValue in group.entries: item = QtGui.QTableWidgetItem(s2q(key)) pwItem = QtGui.QTableWidgetItem("*****") self.passwordTable.setItem(i, self.KEY_IDX, item) self.passwordTable.setItem(i, self.PASSWORD_IDX, pwItem) i = i+1 self.passwordTable.resizeRowsToContents()
def __init__(self, passwds, database): """ @param passwds: a PasswordMap instance w/ encrypted passwords @param database: file name for saving pwMap """ DeOS_Vault.__init__(self, passwds, database) self.groupsTree.setModel(self.groupsFilter) self.groupsTree.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.groupsTree.customContextMenuRequested.connect(self.showGroupsContextMenu) self.groupsTree.clicked.connect(self.loadPasswordsBySelection) self.groupsTree.selectionModel().selectionChanged.connect(self.loadPasswordsBySelection) self.groupsTree.setSortingEnabled(True) self.passwordTable.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.passwordTable.customContextMenuRequested.connect(self.showPasswdContextMenu) self.passwordTable.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.passwordTable.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) # Shortcut shortcut = QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self.passwordTable, self.copyPasswordFromSelection) shortcut.setContext(QtCore.Qt.WidgetShortcut) # Action Triggers self.actionQuit.triggered.connect(self.close) self.actionBackup.triggered.connect(self.saveBackup) self.actionSave.triggered.connect(self.saveDatabase) self.actionSave.setShortcut(QtGui.QKeySequence("Ctrl+S")) # Header Key/Value Items headerKey = QtGui.QTableWidgetItem("Key"); headerValue = QtGui.QTableWidgetItem("Value"); # Password Table self.passwordTable.setColumnCount(2) self.passwordTable.setHorizontalHeaderItem(self.KEY_IDX, headerKey) self.passwordTable.setHorizontalHeaderItem(self.PASSWORD_IDX, headerValue) # Search Edit self.searchEdit.textChanged.connect(self.filterGroups) # Groups groupNames = self.pwMap.groups.keys() for groupName in groupNames: item = QtGui.QStandardItem(s2q(groupName)) self.groupsModel.appendRow(item) # Groups Tree self.groupsTree.sortByColumn(0, QtCore.Qt.AscendingOrder)
def store(self): self.settings.setValue("database/filename", s2q(self.dbFilename))