2023-02-24 20:39:49 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
|
|
|
|
@onready var time_label: Label = %TimeLabel
|
|
|
|
@onready var start_button: Button = %StartButton
|
|
|
|
@onready var task_name_line_edit: LineEdit = %TaskNameLineEdit
|
2023-03-03 21:12:54 +00:00
|
|
|
@onready var time_entries_items_tree: TimeEntriesItemsTree = %TimeEntriesItemsTree
|
2023-02-24 20:39:49 +00:00
|
|
|
@onready var timer: Timer = %Timer
|
|
|
|
@onready var tasks_button: Button = %TasksButton
|
|
|
|
@onready var settings_button: Button = %SettingsButton
|
|
|
|
@onready var previous_tasks_window: Window = %PreviousTasksWindow
|
|
|
|
@onready var settings_window: Window = %SettingsWindow
|
|
|
|
@onready var file_path_file_dialog: FileDialog = %FilePathFileDialog
|
|
|
|
@onready var file_path_line_edit: LineEdit = %FilePathLineEdit
|
|
|
|
@onready var file_path_button: Button = %FilePathButton
|
|
|
|
@onready var theme_path_file_dialog: FileDialog = %ThemePathFileDialog
|
|
|
|
@onready var theme_path_button: Button = %ThemePathButton
|
|
|
|
@onready var sound_check_box: CheckBox = %SoundCheckBox
|
|
|
|
@onready var attributions_rich_text_label: RichTextLabel = %AttributionsRichTextLabel
|
|
|
|
@onready var audio_stream_player: AudioStreamPlayer = %AudioStreamPlayer
|
|
|
|
@onready var open_data_dir_button: Button = %OpenDataDirButton
|
|
|
|
|
|
|
|
|
2023-03-03 21:12:54 +00:00
|
|
|
var timesheet: TimeSheet
|
|
|
|
var config: ConfigManager = preload("res://config_manager.tres")
|
2023-02-24 20:39:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _init() -> void:
|
2023-03-03 21:12:54 +00:00
|
|
|
|
|
|
|
if config.theme_path:
|
|
|
|
var new_theme: Theme = ResourceLoader.load(config.theme_path, "Theme")
|
2023-02-24 20:39:49 +00:00
|
|
|
if new_theme != null:
|
|
|
|
theme = new_theme
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
|
|
|
get_tree().set_auto_accept_quit(false)
|
2023-03-03 21:12:54 +00:00
|
|
|
var _root := time_entries_items_tree.create_item()
|
2023-02-24 20:39:49 +00:00
|
|
|
|
|
|
|
file_path_button.pressed.connect(
|
|
|
|
file_path_file_dialog.popup_centered
|
|
|
|
)
|
|
|
|
|
|
|
|
file_path_file_dialog.file_selected.connect(set_current_file)
|
|
|
|
file_path_line_edit.text_submitted.connect(set_current_file)
|
|
|
|
|
|
|
|
theme_path_button.pressed.connect(
|
|
|
|
theme_path_file_dialog.popup_centered
|
|
|
|
)
|
|
|
|
theme_path_file_dialog.file_selected.connect(
|
|
|
|
func theme_selected(theme_path: String) -> void:
|
|
|
|
var new_theme: Theme = ResourceLoader.load(theme_path, "Theme")
|
|
|
|
if new_theme != null:
|
|
|
|
theme = new_theme
|
2023-03-03 21:12:54 +00:00
|
|
|
config.theme_path = theme_path
|
2023-02-24 20:39:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
theme_path_file_dialog.hide()
|
|
|
|
file_path_file_dialog.hide()
|
|
|
|
previous_tasks_window.hide()
|
|
|
|
settings_window.hide()
|
|
|
|
|
|
|
|
timer.timeout.connect(
|
|
|
|
func on_timer_timeout() -> void:
|
2023-03-03 21:12:54 +00:00
|
|
|
timesheet.update()
|
2023-02-24 20:39:49 +00:00
|
|
|
|
2023-03-03 21:12:54 +00:00
|
|
|
time_label.text = timesheet.get_period()
|
2023-02-24 20:39:49 +00:00
|
|
|
|
2023-03-03 21:12:54 +00:00
|
|
|
var total_elapsed: int = timesheet.get_total_elapsed_seconds()
|
|
|
|
time_entries_items_tree.set_time_elapsed(total_elapsed)
|
2023-02-24 20:39:49 +00:00
|
|
|
)
|
|
|
|
|
2023-03-03 21:12:54 +00:00
|
|
|
start_button.tooltip_text = tr(Consts.START)
|
2023-02-24 20:39:49 +00:00
|
|
|
start_button.toggle_mode = true
|
|
|
|
start_button.toggled.connect(
|
|
|
|
func start(is_on: bool) -> void:
|
|
|
|
if sound_check_box.button_pressed:
|
|
|
|
audio_stream_player.play()
|
|
|
|
if is_on:
|
2023-03-03 21:12:54 +00:00
|
|
|
timesheet.start_entry(task_name_line_edit.text)
|
|
|
|
set_button_as_started()
|
2023-02-24 20:39:49 +00:00
|
|
|
else:
|
2023-03-03 21:12:54 +00:00
|
|
|
timesheet.close_entry()
|
|
|
|
set_button_as_stopped()
|
2023-02-24 20:39:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-03-03 21:12:54 +00:00
|
|
|
task_name_line_edit.text = config.last_task_name
|
2023-02-24 20:39:49 +00:00
|
|
|
task_name_line_edit.text_changed.connect(
|
|
|
|
func(new_text: String) -> void:
|
2023-03-03 21:12:54 +00:00
|
|
|
config.last_task_name = new_text
|
2023-02-24 20:39:49 +00:00
|
|
|
)
|
2023-03-03 21:12:54 +00:00
|
|
|
time_entries_items_tree.item_selected.connect(
|
2023-02-24 20:39:49 +00:00
|
|
|
func item_selected() -> void:
|
2023-03-03 21:12:54 +00:00
|
|
|
task_name_line_edit.text = time_entries_items_tree.get_current_text()
|
2023-02-24 20:39:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
tasks_button.toggle_mode = true
|
|
|
|
tasks_button.toggled.connect(
|
|
|
|
func tasks_toggled(is_on: bool) -> void:
|
|
|
|
previous_tasks_window.visible = is_on
|
|
|
|
)
|
|
|
|
previous_tasks_window.close_requested.connect(
|
|
|
|
func close() -> void:
|
|
|
|
tasks_button.set_pressed_no_signal(false)
|
|
|
|
previous_tasks_window.hide()
|
|
|
|
)
|
|
|
|
|
|
|
|
settings_button.toggle_mode = true
|
|
|
|
settings_button.toggled.connect(
|
|
|
|
func settings_toggled(is_on: bool) -> void:
|
|
|
|
settings_window.visible = is_on
|
|
|
|
)
|
|
|
|
settings_window.close_requested.connect(
|
|
|
|
func close() -> void:
|
|
|
|
settings_button.set_pressed_no_signal(false)
|
|
|
|
settings_window.hide()
|
|
|
|
)
|
|
|
|
|
2023-03-03 21:12:54 +00:00
|
|
|
sound_check_box.button_pressed = config.sound_fx_on
|
2023-02-24 20:39:49 +00:00
|
|
|
sound_check_box.toggled.connect(
|
|
|
|
func sound_toggle(is_on: bool) -> void:
|
2023-03-03 21:12:54 +00:00
|
|
|
config.sound_fx_on = is_on
|
2023-02-24 20:39:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
open_data_dir_button.pressed.connect(
|
|
|
|
OS.shell_open.bind(OS.get_user_data_dir())
|
|
|
|
)
|
|
|
|
|
|
|
|
attributions_rich_text_label.meta_clicked.connect(OS.shell_open)
|
|
|
|
|
2023-03-03 21:12:54 +00:00
|
|
|
set_current_file(config.current_file)
|
2023-02-24 20:39:49 +00:00
|
|
|
|
|
|
|
|
2023-03-03 21:12:54 +00:00
|
|
|
func set_button_as_started() -> void:
|
|
|
|
time_entries_items_tree.set_current_item(timesheet.current_entry.name)
|
|
|
|
start_button.tooltip_text = tr(Consts.STOP)
|
|
|
|
start_button.theme_type_variation = Consts.THEME_OVERRIDE_STOP
|
|
|
|
timer.start()
|
2023-02-24 20:39:49 +00:00
|
|
|
|
|
|
|
|
2023-03-03 21:12:54 +00:00
|
|
|
func set_button_as_stopped() -> void:
|
|
|
|
start_button.tooltip_text = tr(Consts.START)
|
|
|
|
time_label.text = Consts.NO_TIME
|
|
|
|
start_button.theme_type_variation = Consts.THEME_OVERRIDE_START
|
|
|
|
timer.stop()
|
2023-02-24 20:39:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Changes the data file path, and loads the new path
|
|
|
|
func set_current_file(new_current_file: String) -> void:
|
2023-03-03 21:12:54 +00:00
|
|
|
timesheet = TimeSheet.restore(new_current_file)
|
|
|
|
if timesheet == null:
|
2023-02-24 20:39:49 +00:00
|
|
|
return
|
2023-03-03 21:12:54 +00:00
|
|
|
config.current_file = new_current_file
|
|
|
|
|
|
|
|
for entry_name in timesheet.entries_names:
|
|
|
|
time_entries_items_tree.append_name_to_tree(entry_name, timesheet.entries_names[entry_name])
|
|
|
|
|
|
|
|
if timesheet.current_entry != null and timesheet.current_entry.closed == false:
|
|
|
|
start_button.set_pressed_no_signal(true)
|
|
|
|
set_button_as_started()
|
|
|
|
file_path_file_dialog.current_path = config.current_file
|
|
|
|
file_path_file_dialog.current_dir = config.current_file.get_base_dir()
|
|
|
|
file_path_line_edit.text = config.current_file
|
2023-02-24 20:39:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _notification(what: int) -> void:
|
|
|
|
if what == NOTIFICATION_WM_CLOSE_REQUEST:
|
|
|
|
get_tree().quit()
|
|
|
|
|
|
|
|
|
|
|
|
## Unused; if a manual quit button is added, this would be used
|
|
|
|
func quit() -> void:
|
|
|
|
get_tree().notification(NOTIFICATION_WM_CLOSE_REQUEST)
|