Esempio n. 1
0
 def initUI(self):
     """
         Initialize UI components.
     """
     # set column count
     self.setColumnCount(len(PasswdController.getTableColumns()))
     
     # set column names
     self.setColumnCount(5)
     self.setHorizontalHeaderLabels(PasswdController.getTableColumns())
     
     # hide ID column
     self.hideColumn(self.__COL_ID)
     
     # auto resize columns
     self.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
     self.horizontalHeader().setMovable(True)
     
     # not editable
     self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
     
     self.setMinimumWidth(460)
     self.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum)
     
     self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
Esempio n. 2
0
    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)
Esempio n. 3
0
 def showAll(self):
     """
         Show all passwords.
     """        
     passwd_ctrl = PasswdController(self.__parent._db_ctrl, self.__parent._user._master)
     passwords = passwd_ctrl.selectByUserId(self.__parent._user._id)
     
     self.fillTable(passwords)
Esempio n. 4
0
    def deletePassword(self, p_id):
        """
            Delete password from DB. And reloads items.
            
            @param p_id: password ID
        """
        logging.info("deleting password with id: %i", p_id)
        
        passwd_ctrl = PasswdController(self.__parent._db_ctrl, self.__parent._user._master)
        passwd_ctrl.deletePassword(p_id)
        
        # now reload items
#         self.reloadItems()
Esempio n. 5
0
 def copyToClipBoard(self):
     """
         Copy data to clipboard from current cell. And clear clipboard after few seconds, AppSetting.CLIPBOARD_LIVE_MSEC
     """
     row = self.currentRow()
     col = self.currentColumn()
     
     logging.info("curent row: %i, column: %i", row, col)
     
     data = ""
     
     # first stop old timer to clear clipboard
     if (self._del_clipboard and self._del_clipboard.isActive()):
         logging.info("stopping old timer to delete clipboard")
         
         self._del_clipboard.stop()
     
     if (row >= 0 and col >= 0):
         if (col == self.__COL_USERNAME and not self._show_pass):
             # select username from DB
             pass_ctrl = PasswdController(self.__parent._db_ctrl, self.__parent._user._master)
             p_id = self.currentItemID()
             
             passwd = pass_ctrl.selectById(p_id)[0]
             
             data = passwd._username
         elif (col == self.__COL_PASSWORD and not self._show_pass):
             # select password from DB
             pass_ctrl = PasswdController(self.__parent._db_ctrl, self.__parent._user._master)
             p_id = self.currentItemID()
             
             passwd = pass_ctrl.selectById(p_id)[0]
             
             data = passwd._passwd
         else:
             item = self.item(row, col)
             data = str(item.text().toUtf8())
         # copy to clipboard
         QtGui.QApplication.clipboard().setText(QtCore.QString.fromUtf8(data))
         logging.debug("data to clipboard: '%s'", data)
         
         # delete clipboard after time
         self._del_clipboard.start()
         
         logging.info("clipboard will be cleared after %i seconds", AppSettings.CLIPBOARD_LIVE_MSEC / 1000)
Esempio n. 6
0
 def setPassword(self, p_id):
     """
         Show password detail with id p_id.
         
         @param p_id: password ID
     """
     logging.debug("password details ID: %i", p_id)
     
     passwd_ctrl = PasswdController(self.__parent._db_ctrl, self.__parent._user._master)
     
     # select password
     self.__password = passwd_ctrl.selectById(p_id)[0]
     
     # set window title
     self.setWindowTitle(QtCore.QString.fromUtf8(self.__password._title))
     
     date_time_str = str(datetime.datetime.fromtimestamp(self.__password._e_date).strftime("%Y-%m-%d %H:%M:%S"))
     logging.debug("date time string: %s", date_time_str)
     
     self._title.setText(QtCore.QString.fromUtf8(self.__password._title))
     self._username.setText(QtCore.QString.fromUtf8(self.__password._username))
     self._passwd.setText(QtCore.QString.fromUtf8(self.__password._passwd))
     self._url.setText(QtCore.QString.fromUtf8(self.__password._url))
     self._c_date.setText(str(datetime.datetime.fromtimestamp(self.__password._c_date).strftime("%Y-%m-%d %H:%M:%S")))
     self._m_date.setText(str(datetime.datetime.fromtimestamp(self.__password._m_date).strftime("%Y-%m-%d %H:%M:%S")))
     self._e_date_edit.setDateTime(QtCore.QDateTime.fromString(date_time_str, "yyyy-MM-dd HH:mm:ss"))
     self._comment.setText(QtCore.QString.fromUtf8(self.__password._comment))
     self._att_name.setText(QtCore.QString.fromUtf8(self.__password._att_name))
     
     # set attachment data
     self._attachment_data = self.__password._attachment
     
     # set expiration button
     if (self.__password._expire == "false"):
         self._e_date_never.setChecked(True)
     else:
         self._e_date_never.setChecked(False)
     
     self.loadGroups(self.__password._grp._id)
     
     # disable save button, because nothing changed, just loaded from DB
     self.disableSaveButton()
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 def setPassword(self, p_id):
     """
         Show password detail with id p_id.
         
         @param p_id: password ID
     """
     logging.debug("password details ID: %i", p_id)
     
     passwd_ctrl = PasswdController(self.__parent._db_ctrl, self.__parent._user._master)
     
     # select password
     passwd = passwd_ctrl.selectById(p_id)[0]
     
     if (not passwd):
         return
     
     self.__title.setText(QtCore.QString.fromUtf8(passwd._title))
     
     if (self._show_pass):
         self.__username.setText(QtCore.QString.fromUtf8(passwd._username))
         self.__passwd.setText(QtCore.QString.fromUtf8(passwd._passwd))
     else:
         self.__username.setText("******")
         self.__passwd.setText("******")
     self.__url.setText(QtCore.QString.fromUtf8(passwd._url))
     self.__c_date.setText(str(datetime.datetime.fromtimestamp(passwd._c_date).strftime("%Y-%m-%d %H:%M:%S")))
     self.__m_date.setText(str(datetime.datetime.fromtimestamp(passwd._m_date).strftime("%Y-%m-%d %H:%M:%S")))
     
     if (passwd._expire == "false"):
         self.__e_date.setText(tr("Never"))
     else:
         self.__e_date.setText(str(datetime.datetime.fromtimestamp(passwd._e_date).strftime("%Y-%m-%d %H:%M:%S")))
     self.__comment.setText(QtCore.QString.fromUtf8(passwd._comment))
     self.__attachment.setText(QtCore.QString.fromUtf8(passwd._att_name))
     
     # now show details
     self.setHidden(False)
Esempio n. 10
0
 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)