def deleteGroup(self, g_id): """ Delete group with id. Delete cascade implemented on passwords. @param g_id: group id """ logging.info("deleting group and chlidren password with ID: '%i'", g_id) group_ctrl = GroupController(self.__parent._db_ctrl) group_ctrl.deleteGroup(g_id)
def loadGroup(self, g_id): """ Load group with ID. @param g_id: group ID """ logging.info("loading group with ID: '%i'", g_id) group_ctrl = GroupController(self.__parent._db_ctrl) self.__group = group_ctrl.selectById(g_id)
def currentItemGroupName(self): """ Return current item group name. """ g_id = self.currentItemGroupID() if (g_id): group_ctrl = GroupController(self.__parent._db_ctrl) return group_ctrl.selectById(g_id)._name return False
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 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 loadGroups(self, g_id = False): """ Load available groups to combobox """ # set groups combobox group_ctrl = GroupController(self.__db_ctrl) groups = group_ctrl.selectAll() # tmp index tmp = 0 # have to increment tmp inc_tmp = True # fill combobox for group in groups: logging.info("adding group ID: %d", group._id) # load icon pix = QtGui.QPixmap() pix.loadFromData(group._icon._icon) # add item with icon, name and group ID self._group.addItem(QtGui.QIcon(pix), tr(group._name), group._id) if (g_id): # if a dont have curent group if (group._id != g_id and inc_tmp): tmp += 1 logging.info("temp group index: %d, group._id: %d, g_id: %d", tmp, group._id, g_id) else: if inc_tmp: logging.info("group found") inc_tmp = False # set current group if (g_id): self._group.setCurrentIndex(tmp)
def initItems(self): """ Initialize groups tree items. Load items from DB. """ logging.debug("Adding items to tree.") group_ctrl = GroupController(self.__parent._db_ctrl) passwd_ctrl = PasswdController(self.__parent._db_ctrl, self.__parent._user._master) icon_ctrl = IconController(self.__parent._db_ctrl) groups = group_ctrl.selectAll() # group, that contains all passwords all_group = self.initItemData(icon_ctrl.selectByName("userpass")._icon, tr("All"), -1, tr("All passwords group."), self._TYPE_ALL, -1) self.addTopLevelItem(all_group) # add cildren, all passwords to group all passwords = passwd_ctrl.selectByUserId(self.__parent._user._id) for passwd in passwords: child = self.initItemData(passwd._grp._icon._icon, passwd._title, passwd._id, passwd._comment, self._TYPE_PASS, passwd._grp._id) all_group.addChild(child) # insert groups to tree for group in groups: item = self.initItemData(group._icon._icon, tr(group._name), group._id, group._description, self._TYPE_GROUP, group._id) self.addTopLevelItem(item) # add cildren, all passwords to group all passwords = passwd_ctrl.selectByUserGrpId(self.__parent._user._id, group._id) for passwd in passwords: child = self.initItemData(passwd._grp._icon._icon, passwd._title, passwd._id, passwd._comment, self._TYPE_PASS, passwd._grp._id) item.addChild(child)
def insertDefaultGroups(self): """ Creates default password groups. Page, SSH, E-Mail, PC, Code Revision """ grp_ctrl = GroupController(self) icon_ctrl = IconController(self) # now insert new groups grp_ctrl.insertGroup("Page", "Web page credentials.", icon_ctrl.selectByName("key-personal")._id) grp_ctrl.insertGroup("SSH", "SSH credentials.", icon_ctrl.selectByName("key-ssh")._id) grp_ctrl.insertGroup("E-Mail", "E-Mail credentials.", icon_ctrl.selectByName("key")._id) grp_ctrl.insertGroup("PC", "PC credentials.", icon_ctrl.selectByName("person")._id) grp_ctrl.insertGroup("Code revision", "Code revision credentials.", icon_ctrl.selectByName("git")._id) grp_ctrl.insertGroup("Bank account", "Bank account credentials.", icon_ctrl.selectByName("bank")._id)