From a03e71890c7fca4df380894b4b95eb884de88db7 Mon Sep 17 00:00:00 2001 From: Vyn Date: Sun, 2 Feb 2025 11:42:28 +0100 Subject: [PATCH] Add source's name next to each task --- src/components/TaskLine.slint | 10 ++++++++-- src/windows/AppWindow/AppWindow.cpp | 9 +++++++++ src/windows/AppWindow/Models.slint | 1 + src/windows/AppWindow/views/TasksView.slint | 2 ++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/TaskLine.slint b/src/components/TaskLine.slint index 9216e15..89d7173 100644 --- a/src/components/TaskLine.slint +++ b/src/components/TaskLine.slint @@ -1,5 +1,5 @@ import { ToggleButton } from "@selenite"; -import { VPopupIconMenu, VTag, VButton, VActionButton, VCheckBox, Svg, Palette } from "@selenite"; +import { VPopupIconMenu, VTag, VText, VButton, VActionButton, VCheckBox, Svg, Palette } from "@selenite"; import { TaskEdit } from "./TaskEdit.slint"; import { Date } from "std-widgets.slint"; @@ -12,6 +12,8 @@ export struct TaskLineEditData { export component TaskLine inherits VerticalLayout { in property title; + in property source-name; + in property hide-source-name; in property scheduled; in property date; in property checked; @@ -82,12 +84,16 @@ export component TaskLine inherits VerticalLayout { alignment: start; spacing: 8px; checkbox := VCheckBox { - text: root.title; + text: "\{root.title}"; checked: root.checked; toggled => { root.toggle-check() } } + if !hide-source-name : source-name := VTag { + text-color: Palette.accent; + text: "\{root.source-name}"; + } } } } diff --git a/src/windows/AppWindow/AppWindow.cpp b/src/windows/AppWindow/AppWindow.cpp index 85695e1..38b3d2f 100644 --- a/src/windows/AppWindow/AppWindow.cpp +++ b/src/windows/AppWindow/AppWindow.cpp @@ -98,6 +98,13 @@ void AppWindow::setupCallbacks() assert(source); return source->id; }); + + models().on_get_source_name_from_id([&](int sourceId) { + auto source = miraiInstance_->getSourceById(sourceId); + assert(source); + return slint::SharedString(source->name()); + }); + miraiInstance_->onSourceAdded([&](mirai::Source *source) { refreshModels(); }); @@ -338,6 +345,8 @@ void AppWindow::reloadTasks() unscheduledTasks_->clear(); for (int taskIndex = 0; taskIndex < unscheduledTasksView.size(); ++taskIndex) { auto &task = unscheduledTasksView.at(taskIndex); + const auto &source = miraiInstance_->getSourceById(task.sourceId()); + std::println("request name for source id {} : {}", task.sourceId(), source->name()); unscheduledTasks_->push_back({ .sourceId = task.sourceId(), .eventId = -1, diff --git a/src/windows/AppWindow/Models.slint b/src/windows/AppWindow/Models.slint index 9d6a79d..4c1008a 100644 --- a/src/windows/AppWindow/Models.slint +++ b/src/windows/AppWindow/Models.slint @@ -47,4 +47,5 @@ export global AppWindowModels { in-out property<[TaskData]> unscheduled-tasks; callback get-source-id-from-name(string) -> int; + pure callback get-source-name-from-id(int) -> string; } diff --git a/src/windows/AppWindow/views/TasksView.slint b/src/windows/AppWindow/views/TasksView.slint index da4a90c..63eb773 100644 --- a/src/windows/AppWindow/views/TasksView.slint +++ b/src/windows/AppWindow/views/TasksView.slint @@ -144,6 +144,7 @@ export component MainView inherits Rectangle { padding-bottom: 8px; TaskLine { title: task.title; + source-name: AppWindowModels.get-source-name-from-id(task.sourceId); scheduled: task.date.year != 0; date: day.date; checked: task.checked; @@ -187,6 +188,7 @@ export component MainView inherits Rectangle { padding-bottom: 8px; TaskLine { title: task.title; + source-name: AppWindowModels.get-source-name-from-id(task.sourceId); checked: task.checked; allow-edit-date: true; delete => {