def showPasswords(self, item_type, item_id): """ Public slot to show passwords in table, whe signal emitPasswords(int, int) is emited. @param item_type: type of selected item (group, password, all) @param item_id: unique id from DB """ # first remove all items self.removeAllRows() logging.info("signal: type: %i, ID: %i", item_type, item_id) passwd_ctrl = PasswdController(self.__parent._db_ctrl, self.__parent._user._master) # detect type if (item_type == GroupsWidget._TYPE_ALL): # select all passwords = passwd_ctrl.selectByUserId(self.__parent._user._id) elif (item_type == GroupsWidget._TYPE_GROUP): #select by group passwords = passwd_ctrl.selectByUserGrpId(self.__parent._user._id, item_id) elif (item_type == GroupsWidget._TYPE_PASS): #select just one password passwords = passwd_ctrl.selectById(item_id) self.fillTable(passwords)
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)