Beispiel #1
0
    def __init__(self, parent=None, model=True) -> None:
        super().__init__()

        self.parent = parent
        self.setupUi(self)
        self.setWindowTitle('密钥管理')
        self.setModal(model)

        self.key_list = key_cache.get_key_list()
        self.list_model = None
        self.setup_key_list(self.key_list)

        self.tbCreate.clicked.connect(self.create_key_action)
        self.tbCreate.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.tbCreate.setIcon(
            qta.icon('ei.file-new',
                     color=icon_color['color'],
                     color_active=icon_color['active']))

        self.tbAdd.clicked.connect(self.add_key_action)
        self.tbAdd.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.tbAdd.setIcon(
            qta.icon('fa.plus',
                     color=icon_color['color'],
                     color_active=icon_color['active']))

        self.tbRemove.clicked.connect(self.remove_key_action)
        self.tbRemove.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.tbRemove.setIcon(
            qta.icon('fa.minus',
                     color=icon_color['color'],
                     color_active=icon_color['active']))

        add_key_invalidate_callback(self.key_invalidate)
Beispiel #2
0
def load_encrypt_image(path: str) -> QPixmap:

    try:
        raw_data = read_file(path)

        image_data = raw_data

        if is_encrypt_data(raw_data):
            image_data = decrypt_data(cache.get_cur_key().key, raw_data)

        pixmap = QPixmap()

        pixmap.loadFromData(image_data)
    except Exception as e:
        print(e)

    return pixmap, len(image_data)
Beispiel #3
0
    def context_menu(self, point):

        selected = self.keyListView.selectedIndexes()
        if not selected:
            return

        index = selected[0]
        item = self.list_model.item(index.row())
        key = item.data()

        pop_menu = QMenu()

        _set_default_key_action = pop_menu.addAction(
            qta.icon('fa.check',
                     color=icon_color['color'],
                     color_active=icon_color['active']), '设为默认')
        if key_cache.is_cur_key(key) or key.timeout:
            _set_default_key_action.setEnabled(False)

        pop_menu.addSeparator()
        _encrypt_files_action = pop_menu.addAction(
            qta.icon('ei.lock',
                     color=icon_color['color'],
                     color_active=icon_color['active']), "加密文件")
        _decrypt_files_action = pop_menu.addAction(
            qta.icon('ei.unlock',
                     color=icon_color['color'],
                     color_active=icon_color['active']), "解密文件")
        pop_menu.addSeparator()

        _reload_key_action = pop_menu.addAction(
            qta.icon('fa.refresh',
                     color=icon_color['color'],
                     color_active=icon_color['active']), "重新加载")
        _reload_key_action.setEnabled(key.timeout)

        selected_action = pop_menu.exec_(QCursor.pos())
        if selected_action == _encrypt_files_action:
            self.encrypt_files_action()
        elif selected_action == _set_default_key_action:
            self.set_default_key_action()
        elif selected_action == _reload_key_action:
            self.reload_key_action()
        elif selected_action == _decrypt_files_action:
            self.decrypt_files_action()
Beispiel #4
0
 def update_key_icon(self, item):
     key = item.data()
     if key.timeout:
         item.setIcon(
             qta.icon('fa.warning',
                      scale_factor=0.8,
                      color=icon_color['color'],
                      color_active=icon_color['active']))
     elif key_cache.is_cur_key(key):
         item.setIcon(
             qta.icon('fa.check',
                      scale_factor=0.8,
                      color=icon_color['color'],
                      color_active=icon_color['active']))
     else:
         item.setIcon(
             QIcon(
                 qta.icon('fa5s.key',
                          scale_factor=0.7,
                          color=icon_color['color'],
                          color_active=icon_color['active'])))
Beispiel #5
0
 def _set_default_key(self, item):
     key_cache.set_current_key(item.data())
     self.update_key_icon(item)
Beispiel #6
0
 def _remove_key(self, index):
     self.list_model.removeRow(index)
     key_cache.remove_key(index)
Beispiel #7
0
 def _add_key(self, item, key):
     self.list_model.appendRow(item)
     key_cache.add_key(key)