76 lines
3.3 KiB
Python
76 lines
3.3 KiB
Python
|
|
import tkinter as tk
|
|
from tkinter import ttk
|
|
from shared_libs.message import MessageDialog
|
|
import keyring
|
|
|
|
|
|
class EncryptionFrame(ttk.Frame):
|
|
def __init__(self, parent, encryption_manager, **kwargs):
|
|
super().__init__(parent, **kwargs)
|
|
self.encryption_manager = encryption_manager
|
|
|
|
self.columnconfigure(0, weight=1)
|
|
|
|
ttk.Label(self, text="Encryption Settings", font=("Ubuntu", 16, "bold")).grid(
|
|
row=0, column=0, pady=10, sticky="w")
|
|
|
|
# Keyring status
|
|
self.keyring_status_label = ttk.Label(self, text="")
|
|
self.keyring_status_label.grid(
|
|
row=1, column=0, sticky="ew", padx=10, pady=5)
|
|
self.check_keyring_availability()
|
|
|
|
# Password section
|
|
password_frame = ttk.LabelFrame(self, text="Password Management")
|
|
password_frame.grid(row=2, column=0, sticky="ew", padx=10, pady=10)
|
|
password_frame.columnconfigure(1, weight=1)
|
|
|
|
ttk.Label(password_frame, text="Password:").grid(
|
|
row=0, column=0, padx=5, pady=5, sticky="w")
|
|
self.password_entry = ttk.Entry(password_frame, show="*")
|
|
self.password_entry.grid(row=0, column=1, padx=5, pady=5, sticky="ew")
|
|
|
|
self.save_to_keyring_var = tk.BooleanVar()
|
|
self.save_to_keyring_cb = ttk.Checkbutton(
|
|
password_frame, text="Save password to system keyring", variable=self.save_to_keyring_var)
|
|
self.save_to_keyring_cb.grid(
|
|
row=1, column=0, columnspan=2, padx=5, pady=5, sticky="w")
|
|
|
|
set_password_button = ttk.Button(
|
|
password_frame, text="Set Session Password", command=self.set_session_password)
|
|
set_password_button.grid(row=2, column=0, padx=5, pady=5)
|
|
|
|
clear_password_button = ttk.Button(
|
|
password_frame, text="Clear Session Password", command=self.clear_session_password)
|
|
clear_password_button.grid(row=2, column=1, padx=5, pady=5, sticky="w")
|
|
|
|
self.status_message_label = ttk.Label(self, text="", foreground="blue")
|
|
self.status_message_label.grid(row=3, column=0, sticky="ew", padx=10, pady=5)
|
|
|
|
def check_keyring_availability(self):
|
|
try:
|
|
kr = keyring.get_keyring()
|
|
if kr is None:
|
|
self.keyring_status_label.config(
|
|
text="No system keyring found. Passwords will not be saved.", foreground="orange")
|
|
self.save_to_keyring_cb.config(state="disabled")
|
|
except keyring.errors.NoKeyringError:
|
|
self.keyring_status_label.config(
|
|
text="No system keyring found. Passwords will not be saved.", foreground="orange")
|
|
self.save_to_keyring_cb.config(state="disabled")
|
|
|
|
def set_session_password(self):
|
|
password = self.password_entry.get()
|
|
if not password:
|
|
self.status_message_label.config(text="Password cannot be empty.", foreground="red")
|
|
return
|
|
|
|
self.encryption_manager.set_session_password(password, self.save_to_keyring_var.get())
|
|
self.status_message_label.config(text="Password set for this session.", foreground="green")
|
|
|
|
def clear_session_password(self):
|
|
self.encryption_manager.clear_session_password()
|
|
self.password_entry.delete(0, tk.END)
|
|
self.status_message_label.config(text="Session password cleared.", foreground="green")
|