def logIn(self): """ Read input lines and login user if possible. """ logging.debug("logging user ...") try: path = AppSettings.readDbFilePath() self.__db_ctrl.connectDB(path) login_ctrl = LoginController(self.__db_ctrl) username = AppSettings.USER_NAME master = str(self._passwd.text().toUtf8()) logged_user = login_ctrl.logInUser(username, master) if (logged_user): self.signalSuccessfullyLogged.emit(QtCore.QString.fromUtf8(username), QtCore.QString.fromUtf8(master)) self.close() else: # sleep for a while time.sleep(AppSettings.WRONG_PASWD_SLEEP) # show message QtGui.QMessageBox(QtGui.QMessageBox.Critical, tr("Wrong credentials!"), tr("Username or password are wrong.")).exec_() except Exception as e: InfoMsgBoxes.showErrorMsg(e)
def loadAttachment(self): """ Exec filedialog, open file and get absolute file path and name. """ try: home_loc = QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.HomeLocation) file_path = QtGui.QFileDialog.getOpenFileName(self, tr("Open attachment"), home_loc) if (not file_path.isEmpty()): file_path = str(file_path.toUtf8()) file_name = os.path.basename(file_path) logging.info("attachment file path: %s", file_path) logging.info("attachment file name: %s", file_name) # set attachment name self._att_name.setText(QtCore.QString.fromUtf8(file_name)) # read binary data data = self.readFile(file_path) if (data): self._attachment_data = data self.enableSaveButton() else: logging.debug("file not selected") except Exception as e: logging.exception(e) InfoMsgBoxes.showErrorMsg(e)
def closeEvent(self, event): """ Do matters on close event. In example delete clipboard. """ logging.debug("deleting clipboard") QtGui.QApplication.clipboard().clear() try: logging.info("removing tmp dir: '%s'", AppSettings.TMP_PATH) # remove tmp files shutil.rmtree(AppSettings.decodePath(AppSettings.TMP_PATH)) except Exception as e: logging.exception(e) InfoMsgBoxes.showErrorMsg(e)
def openAttachment(self): """ Open attachment using desktop services. """ try: tmp_file = AppSettings.TMP_PATH + str(self._att_name.text().toUtf8()) logging.info("saving attachment to tmp file: '%s'", tmp_file) self.writeFile(tmp_file) if (not QtGui.QDesktopServices.openUrl(QtCore.QUrl.fromLocalFile(QtCore.QString.fromUtf8(tmp_file)))): # not succesfully opened QtGui.QMessageBox(QtGui.QMessageBox.Information, tr("Something wrong!"), tr("Can't open file '") + QtCore.QString.fromUtf8(tmp_file) + "\n" + tr("Save it to disk and open with selected program.")).exec_() except Exception as e: logging.exception(e) InfoMsgBoxes.showErrorMsg(e)
def reloadItems(self, p_id = -1): """ Reload groups, passwords. @param p_id: password id to display, if is < 0, doesn't display """ try: self._groups_tw.reloadItems() self._passwords_table.reloadItems() if (p_id >= 0): self._detail_w.setPassword(p_id) else: self._detail_w.setHidden(True) except Exception as e: logging.exception(e) InfoMsgBoxes.showErrorMsg(e)
def saveChanges(self): """ Method for saving changes into db. """ try: group_ctrl = GroupController(self.__parent._db_ctrl) # prepare data name = str(self._name.text().toUtf8()) desc = str(self._desc.text().toUtf8()) icon_id = self.getIconId() group_ctrl.insertGroup(name, desc, icon_id) self.accept() except Exception as e: logging.exception(e) InfoMsgBoxes.showErrorMsg(e)
def saveChanges(self): """ Save changes to database, read all iinputs and insert DB entry. """ logging.debug("save button clicked.") try: title = str(self._title.text().toUtf8()) username = str(self._username.text().toUtf8()) passwd = str(self._passwd.text().toUtf8()) url = str(self._url.text().toUtf8()) comment = str(self._comment.toPlainText().toUtf8()) att_name = str(self._att_name.text().toUtf8()) attachment = self._attachment_data # get group grp_id = self.getGroupId() # creation date now c_date = time.time() # set expiration date e_date = self._e_date_edit.dateTime().toTime_t() # set expiration if (self._e_date_never.isChecked()): expire = "false" else: expire = "true" # update password passwd_ctrl = PasswdController(self.__parent._db_ctrl, self.__parent._user._master) passwd_ctrl.insertPassword(title, username, passwd, url, comment, c_date, e_date, grp_id, self.__parent._user._id, attachment, att_name, expire) self.accept() except Exception as e: logging.exception(e) InfoMsgBoxes.showErrorMsg(e)
def saveChanges(self): """ Save changes to database, read all iinputs and update DB entry. """ logging.debug("save button clicked.") try: self.__password._title = str(self._title.text().toUtf8()) self.__password._username = str(self._username.text().toUtf8()) self.__password._passwd = str(self._passwd.text().toUtf8()) self.__password._url = str(self._url.text().toUtf8()) self.__password._comment = str(self._comment.toPlainText().toUtf8()) self.__password._att_name = str(self._att_name.text().toUtf8()) # set expiration if (self._e_date_never.isChecked()): self.__password._expire = "false" else: self.__password._expire = "true" # get group group_ctrl = GroupController(self.__parent._db_ctrl) self.__password._grp = group_ctrl.selectById(self.getGroupId()) # set expiration date self.__password._e_date = self._e_date_edit.dateTime().toTime_t() # set attachment data self.__password._attachment = self._attachment_data # update password passwd_ctrl = PasswdController(self.__parent._db_ctrl, self.__parent._user._master) passwd_ctrl.updatePasswd(self.__password._id, self.__password._title, self.__password._username, self.__password._passwd, self.__password._url, self.__password._comment, self.__password._e_date, self.__password._grp._id, self.__password._user._id, self.__password._attachment, self.__password._att_name, self.__password._expire) self.signalPasswdSaved.emit(self.__password._id) self.accept() except Exception as e: InfoMsgBoxes.showErrorMsg(e)
def saveAttachment(self): """ Save attachment to disk. """ try: home_loc = QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.HomeLocation) home_loc = QtCore.QString.fromUtf8(home_loc + os.path.sep) home_loc.append(self._att_name.text()) file_path = QtGui.QFileDialog.getSaveFileName(self, tr("Open attachment"), home_loc) logging.info("save attachment to file: %s", file_path) if (not file_path.isEmpty()): file_path = str(file_path.toUtf8()) logging.info("attachment file path: %s", file_path) # write data to disk self.writeFile(file_path) else: logging.info("file not selected") except Exception as e: logging.exception(e) InfoMsgBoxes.showErrorMsg(e)