Make Tags and TimeLog optional features that can be switched on/off in Settings (enabled by default)
All checks were successful
CI / test (push) Successful in 4m31s
Lint / test (push) Successful in 1m2s
Trivy / test (push) Successful in 23s

This commit is contained in:
Miguel Jacq 2025-11-21 08:50:06 +11:00
parent f9ee150a23
commit 3e91f158c3
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
8 changed files with 49 additions and 18 deletions

View file

@ -61,6 +61,8 @@ class DBConfig:
idle_minutes: int = 15 # 0 = never lock
theme: str = "system"
move_todos: bool = False
tags: bool = True
time_log: bool = True
locale: str = "en"

View file

@ -238,5 +238,7 @@
"export_csv_error_message": "Could not write CSV file:\n{error}",
"export_pdf": "Export PDF",
"export_pdf_error_title": "PDF export failed",
"export_pdf_error_message": "Could not write PDF file:\n{error}"
"export_pdf_error_message": "Could not write PDF file:\n{error}",
"enable_tags_feature": "Enable Tags",
"enable_time_log_feature": "Enable Time Logging"
}

View file

@ -66,7 +66,7 @@ from .statistics_dialog import StatisticsDialog
from . import strings
from .tags_widget import PageTagsWidget
from .theme import ThemeManager
from .time_log import TimeLogWidget, TimeReportDialog
from .time_log import TimeLogWidget
from .toolbar import ToolBar
@ -219,18 +219,10 @@ class MainWindow(QMainWindow):
act_backup.setShortcut("Ctrl+Shift+B")
act_backup.triggered.connect(self._backup)
file_menu.addAction(act_backup)
act_tags = QAction(strings._("main_window_manage_tags_accessible_flag"), self)
act_tags.setShortcut("Ctrl+T")
act_tags.triggered.connect(self.tags._open_manager)
file_menu.addAction(act_tags)
act_stats = QAction(strings._("main_window_statistics_accessible_flag"), self)
act_stats.setShortcut("Shift+Ctrl+S")
act_stats.triggered.connect(self._open_statistics)
file_menu.addAction(act_stats)
act_time_report = QAction(strings._("time_log_report"), self)
act_time_report.setShortcut("Ctrl+Shift+L")
act_time_report.triggered.connect(self._open_time_report)
file_menu.addAction(act_time_report)
file_menu.addSeparator()
act_quit = QAction("&" + strings._("quit"), self)
act_quit.setShortcut("Ctrl+Q")
@ -320,6 +312,12 @@ class MainWindow(QMainWindow):
self._load_selected_date()
self._refresh_calendar_marks()
# Hide tags and time log widgets if not enabled
if not self.cfg.tags:
self.tags.hide()
if not self.cfg.time_log:
self.time_log.hide()
# Restore window position from settings
self.settings = QSettings(APP_ORG, APP_NAME)
self._restore_window_position()
@ -1320,11 +1318,12 @@ class MainWindow(QMainWindow):
self.cfg.idle_minutes = getattr(new_cfg, "idle_minutes", self.cfg.idle_minutes)
self.cfg.theme = getattr(new_cfg, "theme", self.cfg.theme)
self.cfg.move_todos = getattr(new_cfg, "move_todos", self.cfg.move_todos)
self.cfg.tags = getattr(new_cfg, "tags", self.cfg.tags)
self.cfg.time_log = getattr(new_cfg, "time_log", self.cfg.time_log)
self.cfg.locale = getattr(new_cfg, "locale", self.cfg.locale)
# Persist once
save_db_config(self.cfg)
# Apply idle setting immediately (restart the timer with new interval if it changed)
self._apply_idle_minutes(self.cfg.idle_minutes)
@ -1341,6 +1340,13 @@ class MainWindow(QMainWindow):
self._load_selected_date()
self._refresh_calendar_marks()
# Show or hide the tags and time_log features depending on what the settings are now.
self.tags.hide() if not self.cfg.tags else self.tags.show()
if not self.cfg.time_log:
self.time_log.hide()
else:
self.time_log.show()
# ------------ Statistics handler --------------- #
def _open_statistics(self):
@ -1358,11 +1364,6 @@ class MainWindow(QMainWindow):
dlg._heatmap.date_clicked.connect(on_date_clicked)
dlg.exec()
# ------------ Timesheet report handler --------------- #
def _open_time_report(self):
dlg = TimeReportDialog(self.db, self)
dlg.exec()
# ------------ Window positioning --------------- #
def _restore_window_position(self):
geom = self.settings.value("main/geometry", None)

View file

@ -3,7 +3,6 @@ from __future__ import annotations
import datetime
from PySide6.QtGui import QFontMetrics
from PySide6.QtCore import QSize
from PySide6.QtWidgets import (
QDialog,
QVBoxLayout,

View file

@ -41,6 +41,8 @@ def load_db_config() -> DBConfig:
idle = s.value("ui/idle_minutes", 15, type=int)
theme = s.value("ui/theme", "system", type=str)
move_todos = s.value("ui/move_todos", False, type=bool)
tags = s.value("ui/tags", True, type=bool)
time_log = s.value("ui/time_log", True, type=bool)
locale = s.value("ui/locale", "en", type=str)
return DBConfig(
path=path,
@ -48,6 +50,8 @@ def load_db_config() -> DBConfig:
idle_minutes=idle,
theme=theme,
move_todos=move_todos,
tags=tags,
time_log=time_log,
locale=locale,
)
@ -59,4 +63,6 @@ def save_db_config(cfg: DBConfig) -> None:
s.setValue("ui/idle_minutes", str(cfg.idle_minutes))
s.setValue("ui/theme", str(cfg.theme))
s.setValue("ui/move_todos", str(cfg.move_todos))
s.setValue("ui/tags", str(cfg.tags))
s.setValue("ui/time_log", str(cfg.time_log))
s.setValue("ui/locale", str(cfg.locale))

View file

@ -98,13 +98,26 @@ class SettingsDialog(QDialog):
behaviour_group = QGroupBox(strings._("behaviour"))
behaviour_layout = QVBoxLayout(behaviour_group)
# Checkbox moving
self.move_todos = QCheckBox(
strings._("move_yesterdays_unchecked_todos_to_today_on_startup")
)
self.move_todos.setChecked(self.current_settings.move_todos)
self.move_todos.setCursor(Qt.PointingHandCursor)
behaviour_layout.addWidget(self.move_todos)
# Tags
self.tags = QCheckBox(strings._("enable_tags_feature"))
self.tags.setChecked(self.current_settings.tags)
self.tags.setCursor(Qt.PointingHandCursor)
behaviour_layout.addWidget(self.tags)
# Time logging
self.time_log = QCheckBox(strings._("enable_time_log_feature"))
self.time_log.setChecked(self.current_settings.time_log)
self.time_log.setCursor(Qt.PointingHandCursor)
behaviour_layout.addWidget(self.time_log)
form.addRow(behaviour_group)
# Encryption settings
@ -236,6 +249,8 @@ class SettingsDialog(QDialog):
idle_minutes=self.idle_spin.value(),
theme=selected_theme.value,
move_todos=self.move_todos.isChecked(),
tags=self.tags.isChecked(),
time_log=self.time_log.isChecked(),
locale=self.locale_combobox.currentText(),
)