def loadIcons(self, i_id = False): """ Load icons from DB to combobox. If is set i_id seti as current. @param i_id: current icon ID """ # set groups combobox icon_ctrl = IconController(self.__db_ctrl) icons = icon_ctrl.selectAll() # tmp index tmp = 0 # have to increment tmp inc_tmp = True # fill combobox for icon in icons: logging.info("adding icon ID: %d", icon._id) # load icon pix = QtGui.QPixmap() pix.loadFromData(icon._icon) # add item with icon, name and icon ID self._icons.addItem(QtGui.QIcon(pix), tr(icon._name), icon._id) if (i_id): # if a dont have curent index if (icon._id != i_id and inc_tmp): tmp += 1 logging.info("temp icon index: %d, icon._id: %d, i_id: %d", tmp, icon._id, i_id) else: if inc_tmp: logging.info("icon found") inc_tmp = False # set current group if (i_id): self._icons.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)
def insertDefaultIcons(self): """ Creates default icons for groups. Page, SSH, E-Mail, PC, Code Revision, UserPass icon """ icon_ctrl = IconController(self) icon_ctrl.insertIcon("key-personal", AppSettings.ICONS_PATH + "key-personal.ico") icon_ctrl.insertIcon("key-ssh", AppSettings.ICONS_PATH+ "key-ssh.ico") icon_ctrl.insertIcon("key", AppSettings.ICONS_PATH + "key.ico") icon_ctrl.insertIcon("person", AppSettings.ICONS_PATH + "person.ico") icon_ctrl.insertIcon("git", AppSettings.ICONS_PATH + "git.ico") icon_ctrl.insertIcon("bank", AppSettings.ICONS_PATH + "bank.ico") icon_ctrl.insertIcon("userpass", AppSettings.ICONS_PATH + "userpass.ico")