mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-02 01:13:19 +00:00
Refactor the whole structure, no more separation for C++ and Slint files
This commit is contained in:
parent
d6c781faa2
commit
893fcc11e3
35 changed files with 920 additions and 518 deletions
|
@ -30,8 +30,12 @@ add_subdirectory(external/evalyte-cpp-common)
|
|||
|
||||
add_executable(mirai
|
||||
src/main.cpp
|
||||
src/AppWindowBackend.cpp
|
||||
src/Utils.cpp
|
||||
src/windows/AppWindow/AppWindow.cpp
|
||||
src/windows/AddSourceWindow/AddSourceWindow.cpp
|
||||
src/windows/SettingsWindow/SettingsWindow.cpp
|
||||
src/windows/EditSourceWindow/EditSourceWindow.cpp
|
||||
src/SeleniteSetup.cpp
|
||||
src/shared/Utils.cpp
|
||||
)
|
||||
|
||||
target_include_directories(mirai PRIVATE "external/mirai-core/include")
|
||||
|
@ -48,7 +52,7 @@ target_include_directories(mirai PRIVATE "external")
|
|||
target_link_libraries(mirai PRIVATE mirai-core)
|
||||
|
||||
slint_target_sources(
|
||||
mirai ui/AppWindow.slint
|
||||
mirai src/ui.slint
|
||||
NAMESPACE ui
|
||||
LIBRARY_PATHS selenite=${CMAKE_CURRENT_SOURCE_DIR}/external/selenite/components/index.slint
|
||||
)
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
|
@ -11,7 +13,7 @@ template <typename T> class EventEmitter
|
|||
{
|
||||
|
||||
public:
|
||||
void registerCallback(std::function<T> func)
|
||||
void registerCallback(std::function<void(T)> func)
|
||||
{
|
||||
callbacks.push_back(func);
|
||||
}
|
||||
|
@ -24,5 +26,5 @@ template <typename T> class EventEmitter
|
|||
}
|
||||
|
||||
private:
|
||||
std::vector<std::function<T>> callbacks;
|
||||
std::vector<std::function<void(T)>> callbacks;
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "EventEmitter.h"
|
||||
#include "Source.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
@ -35,10 +36,18 @@ class Mirai
|
|||
// Returns a non owning pointer to the requested resource or nullptr if not found.
|
||||
Source *getSourceById(int id);
|
||||
|
||||
void onSourceAdded(std::function<void(Source *)> f);
|
||||
void onSourceEdited(std::function<void(Source *)> f);
|
||||
void onSourceDeleted(std::function<void(int)> f);
|
||||
|
||||
private:
|
||||
void loadConfig(const std::string &path);
|
||||
void saveConfig();
|
||||
std::vector<std::unique_ptr<Source>> sources_;
|
||||
std::string configPath_;
|
||||
|
||||
EventEmitter<Source *> sourceAdded;
|
||||
EventEmitter<Source *> sourceEdited;
|
||||
EventEmitter<int> sourceDeleted;
|
||||
};
|
||||
} // namespace mirai
|
||||
|
|
18
external/mirai-core/src/Mirai.cpp
vendored
18
external/mirai-core/src/Mirai.cpp
vendored
|
@ -88,6 +88,7 @@ void Mirai::addSource(
|
|||
SourceConstructor{.name = name, .sourceDataProvider = sourceDataProvider}
|
||||
));
|
||||
saveConfig();
|
||||
sourceAdded.emit(nullptr);
|
||||
};
|
||||
|
||||
void Mirai::editSource(int id, const std::string &name, const std::string &path)
|
||||
|
@ -97,6 +98,7 @@ void Mirai::editSource(int id, const std::string &name, const std::string &path)
|
|||
|
||||
DataProvider *sourceDataProvider = source->dataProvider();
|
||||
saveConfig();
|
||||
sourceEdited.emit(nullptr);
|
||||
}
|
||||
|
||||
void Mirai::deleteSource(int id)
|
||||
|
@ -113,6 +115,7 @@ void Mirai::deleteSource(int id)
|
|||
);
|
||||
|
||||
saveConfig();
|
||||
sourceDeleted.emit(id);
|
||||
}
|
||||
|
||||
void Mirai::unloadAllSources()
|
||||
|
@ -146,4 +149,19 @@ Source *Mirai::getSourceById(int id)
|
|||
return source->get();
|
||||
}
|
||||
|
||||
void Mirai::onSourceAdded(std::function<void(Source *)> f)
|
||||
{
|
||||
sourceAdded.registerCallback(f);
|
||||
}
|
||||
|
||||
void Mirai::onSourceEdited(std::function<void(Source *)> f)
|
||||
{
|
||||
sourceEdited.registerCallback(f);
|
||||
}
|
||||
|
||||
void Mirai::onSourceDeleted(std::function<void(int)> f)
|
||||
{
|
||||
sourceDeleted.registerCallback(f);
|
||||
}
|
||||
|
||||
} // namespace mirai
|
||||
|
|
28
src/SeleniteSetup.cpp
Normal file
28
src/SeleniteSetup.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "SeleniteSetup.h"
|
||||
#include "selenite/palette.h"
|
||||
|
||||
slint::Color seleniteColorToSlint(const selenite::Color &color)
|
||||
{
|
||||
return slint::Color::from_rgb_uint8(color.r, color.g, color.b);
|
||||
}
|
||||
|
||||
void setSelenitePalette(const ui::Palette &uiPalette, const selenite::Palette &palette)
|
||||
{
|
||||
uiPalette.set_accent(seleniteColorToSlint(palette.primary));
|
||||
uiPalette.set_background(seleniteColorToSlint(palette.background));
|
||||
uiPalette.set_pane(seleniteColorToSlint(palette.pane));
|
||||
uiPalette.set_foreground(seleniteColorToSlint(palette.foreground));
|
||||
uiPalette.set_foreground_hint(seleniteColorToSlint(palette.foregroundHint));
|
||||
uiPalette.set_control_background(seleniteColorToSlint(palette.background3));
|
||||
uiPalette.set_control_foreground(seleniteColorToSlint(palette.foreground));
|
||||
uiPalette.set_card_background(seleniteColorToSlint(palette.background2));
|
||||
uiPalette.set_green(seleniteColorToSlint(palette.green));
|
||||
uiPalette.set_orange(seleniteColorToSlint(palette.orange));
|
||||
uiPalette.set_red(seleniteColorToSlint(palette.red));
|
||||
}
|
|
@ -6,26 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "AppWindow.h"
|
||||
#include "selenite/palette.h"
|
||||
#include "slint_color.h"
|
||||
#include "ui.h"
|
||||
|
||||
slint::Color seleniteColorToSlint(const selenite::Color &color)
|
||||
{
|
||||
return slint::Color::from_rgb_uint8(color.r, color.g, color.b);
|
||||
}
|
||||
|
||||
void setSelenitePalette(const ui::Palette &uiPalette, const selenite::Palette &palette)
|
||||
{
|
||||
uiPalette.set_accent(seleniteColorToSlint(palette.primary));
|
||||
uiPalette.set_background(seleniteColorToSlint(palette.background));
|
||||
uiPalette.set_pane(seleniteColorToSlint(palette.pane));
|
||||
uiPalette.set_foreground(seleniteColorToSlint(palette.foreground));
|
||||
uiPalette.set_foreground_hint(seleniteColorToSlint(palette.foregroundHint));
|
||||
uiPalette.set_control_background(seleniteColorToSlint(palette.background3));
|
||||
uiPalette.set_control_foreground(seleniteColorToSlint(palette.foreground));
|
||||
uiPalette.set_card_background(seleniteColorToSlint(palette.background2));
|
||||
uiPalette.set_green(seleniteColorToSlint(palette.green));
|
||||
uiPalette.set_orange(seleniteColorToSlint(palette.orange));
|
||||
uiPalette.set_red(seleniteColorToSlint(palette.red));
|
||||
}
|
||||
slint::Color seleniteColorToSlint(const selenite::Color &color);
|
||||
void setSelenitePalette(const ui::Palette &uiPalette, const selenite::Palette &palette);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { ScrollView, Date, Time } from "std-widgets.slint";
|
||||
import { VCheckBox, VButton, VActionButton, Svg, VTag, VPopupIconMenu, VText, Palette } from "@selenite";
|
||||
import { Utils } from "../Utils.slint";
|
||||
import { Utils } from "../shared/Utils.slint";
|
||||
|
||||
export struct CalendarDayEvent {
|
||||
title: string,
|
|
@ -1,28 +1,44 @@
|
|||
import { Backend, TaskData } from "../Backend.slint";
|
||||
import { Button, VerticalBox, CheckBox, ScrollView, ComboBox } from "std-widgets.slint";
|
||||
import { AppWindowModels } from "../windows/AppWindow/Models.slint";
|
||||
import { Date, Time, Button, VerticalBox, CheckBox, ScrollView, ComboBox } from "std-widgets.slint";
|
||||
import { VPopupIconMenu, VDatePicker, VTimePicker, VCheckBox, VButton, VActionButton, VTag, VText, Svg, VTextInput, Palette } from "@selenite";
|
||||
import { NewTaskData, SaveTaskData } from "../Backend.slint";
|
||||
|
||||
export struct CreateTaskData {
|
||||
sourceId: int,
|
||||
title: string,
|
||||
date: Date
|
||||
}
|
||||
|
||||
export struct CreateEventData {
|
||||
sourceId: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
startsAt: Time,
|
||||
endsAt: Time
|
||||
}
|
||||
|
||||
export component CreateTaskOrEvent inherits Rectangle {
|
||||
|
||||
in property <[string]> sources;
|
||||
private property <int> task-or-event: 1;
|
||||
function create-task() {
|
||||
|
||||
callback create-task(CreateTaskData);
|
||||
callback create-event(CreateEventData);
|
||||
|
||||
function accepted() {
|
||||
if (task-or-event == 1) {
|
||||
Backend.create-task({
|
||||
sourceId: sourceInput.current-index,
|
||||
eventId: -1,
|
||||
root.create-task({
|
||||
sourceId: AppWindowModels.get-source-id-from-name(sourceInput.current-value),
|
||||
title: newTaskTitleInput.text,
|
||||
scheduled: taskDateInput.date.year != 0,
|
||||
date: taskDateInput.date
|
||||
})
|
||||
} else {
|
||||
Backend.create-event({
|
||||
sourceId: sourceInput.current-index,
|
||||
root.create-event({
|
||||
sourceId: AppWindowModels.get-source-id-from-name(sourceInput.current-value),
|
||||
title: newTaskTitleInput.text,
|
||||
date: taskDateInput.date,
|
||||
startsAt: eventStartTimeInput.time,
|
||||
endsAt: eventEndTimeInput.time,
|
||||
});
|
||||
endsAt: eventEndTimeInput.time
|
||||
})
|
||||
}
|
||||
newTaskTitleInput.edit-text("");
|
||||
}
|
||||
|
@ -43,9 +59,9 @@ export component CreateTaskOrEvent inherits Rectangle {
|
|||
newTaskTitleInput := VTextInput {
|
||||
placeholder: "Add new Task / Event";
|
||||
started-writting() => {
|
||||
sourceInput.current-index = Backend.default-source-index;
|
||||
sourceInput.current-index = AppWindowModels.default-source-index;
|
||||
}
|
||||
accepted => { create-task() }
|
||||
accepted => { accepted() }
|
||||
}
|
||||
Rectangle {
|
||||
min-height: 0px;
|
||||
|
@ -70,7 +86,7 @@ export component CreateTaskOrEvent inherits Rectangle {
|
|||
VerticalLayout {
|
||||
alignment: end;
|
||||
sourceInput := ComboBox {
|
||||
model: Backend.sources;
|
||||
model: root.sources;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +114,7 @@ export component CreateTaskOrEvent inherits Rectangle {
|
|||
text: "Create";
|
||||
icon-svg: Svg.correct;
|
||||
icon-colorize: greenyellow;
|
||||
clicked => { create-task() }
|
||||
clicked => { accepted() }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,25 @@
|
|||
import { Backend, TaskData, Event } from "../Backend.slint";
|
||||
import { Event } from "../windows/AppWindow/Models.slint";
|
||||
import { ScrollView } from "std-widgets.slint";
|
||||
import { VCheckBox, VTextInput, VButton, VActionButton, Svg, VTag, VPopupIconMenu, VText, Palette } from "@selenite";
|
||||
import { TaskLine } from "./TaskLine.slint";
|
||||
import { Utils } from "../Utils.slint";
|
||||
import { Utils } from "../shared/Utils.slint";
|
||||
|
||||
export struct EventGroupAddTask {
|
||||
title: string
|
||||
}
|
||||
|
||||
export component EventGroup {
|
||||
in property<Event> event;
|
||||
private property <bool> show-add-task: false;
|
||||
private property <bool> edit-name: false;
|
||||
|
||||
callback add-task(EventGroupAddTask);
|
||||
callback edit-task(int, EventGroupAddTask);
|
||||
callback delete-task(int);
|
||||
callback delete();
|
||||
callback edit(EventGroupAddTask);
|
||||
callback toggle-check-task(int);
|
||||
|
||||
eventPopup := VPopupIconMenu {
|
||||
VActionButton {
|
||||
icon-svg: Svg.plus;
|
||||
|
@ -32,7 +43,7 @@ export component EventGroup {
|
|||
icon-colorize: Colors.pink;
|
||||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => { Backend.delete-event-clicked(event.sourceId, event.id) }
|
||||
clicked => { root.delete() }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,13 +90,8 @@ export component EventGroup {
|
|||
if edit-name : title := VTextInput {
|
||||
text: event.title;
|
||||
accepted => {
|
||||
Backend.save-event({
|
||||
sourceId: event.sourceId,
|
||||
id: event.id,
|
||||
title: title.text,
|
||||
//date: event.date,
|
||||
startsAt: event.startsAt,
|
||||
endsAt: event.endsAt,
|
||||
root.edit({
|
||||
title: title.text
|
||||
});
|
||||
root.edit-name = false;
|
||||
}
|
||||
|
@ -94,22 +100,28 @@ export component EventGroup {
|
|||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
task: task;
|
||||
source-index: task.sourceId;
|
||||
task-index: task.id;
|
||||
title: task.title;
|
||||
delete => {
|
||||
root.delete-task(task.id)
|
||||
}
|
||||
toggle-check => {
|
||||
root.toggle-check-task(task.id)
|
||||
}
|
||||
edited(data) => {
|
||||
root.edit-task(task.id, {
|
||||
title: data.title
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if show-add-task : taskInput := VTextInput {
|
||||
accepted => {
|
||||
Backend.create-task({
|
||||
sourceId: event.sourceId,
|
||||
eventId: event.id,
|
||||
title: taskInput.text,
|
||||
root.add-task({
|
||||
title: taskInput.text
|
||||
});
|
||||
root.show-add-task = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +1,36 @@
|
|||
import { Backend, TaskData } from "../Backend.slint";
|
||||
import { Button, VerticalBox, CheckBox, Date, ScrollView, ComboBox } from "std-widgets.slint";
|
||||
import { VPopupIconMenu, VDatePicker, VTimePicker, VCheckBox, VButton, VTag, VText, VTextInput, Svg, Palette } from "@selenite";
|
||||
import { NewTaskData, SaveTaskData } from "../Backend.slint";
|
||||
|
||||
export struct TaskEditData {
|
||||
title: string,
|
||||
date: Date,
|
||||
}
|
||||
|
||||
export component TaskEdit inherits VerticalLayout {
|
||||
in-out property <TaskData> task;
|
||||
out property <bool> should-show;
|
||||
in property <bool> allow-edit-date;
|
||||
in-out property <TaskEditData> task;
|
||||
|
||||
callback accepted(TaskEditData);
|
||||
|
||||
private property <Date> newDate: task.date;
|
||||
|
||||
public function show(task: TaskData) {
|
||||
public function show(task: TaskEditData) {
|
||||
root.task = task;
|
||||
should-show = true;
|
||||
}
|
||||
public function close() {
|
||||
should-show = false;
|
||||
}
|
||||
callback accepted(SaveTaskData);
|
||||
|
||||
// Render
|
||||
|
||||
if !should-show : Rectangle {}
|
||||
|
||||
if should-show : Rectangle {
|
||||
function modify() {
|
||||
root.accepted({
|
||||
id: task.id,
|
||||
sourceId: task.sourceId,
|
||||
title: newTaskTitleInput.text,
|
||||
scheduled: newDate.year != 0,
|
||||
date: newDate
|
||||
});
|
||||
}
|
||||
|
@ -43,7 +47,7 @@ export component TaskEdit inherits VerticalLayout {
|
|||
HorizontalLayout {
|
||||
alignment: start;
|
||||
spacing: 8px;
|
||||
if root.task.eventId == -1 : taskDateInput := VDatePicker {
|
||||
if root.allow-edit-date : taskDateInput := VDatePicker {
|
||||
date: task.date;
|
||||
enabled: true;
|
||||
edited(date) => { newDate = date; }
|
|
@ -1,30 +1,34 @@
|
|||
import { Backend, TaskData } from "../Backend.slint";
|
||||
import { ToggleButton } from "@selenite";
|
||||
import { VPopupIconMenu, VTag, VButton, VActionButton, VCheckBox, Svg, Palette } from "@selenite";
|
||||
import { TaskEdit } from "./TaskEdit.slint";
|
||||
import { Date } from "std-widgets.slint";
|
||||
|
||||
export struct TaskLineEditData {
|
||||
title: string,
|
||||
scheduled: bool,
|
||||
date: Date,
|
||||
checked: bool
|
||||
}
|
||||
|
||||
export component TaskLine inherits VerticalLayout {
|
||||
in property<TaskData> task;
|
||||
in property<string> title;
|
||||
in property<bool> scheduled;
|
||||
in property<Date> date;
|
||||
in property<int> event-index: -1;
|
||||
in property<int> source-index: -1;
|
||||
in property<int> task-index: -1;
|
||||
in property<bool> checked;
|
||||
in property<bool> allow-edit-date;
|
||||
|
||||
callback delete();
|
||||
callback edit();
|
||||
callback toggle-check();
|
||||
callback edited(TaskLineEditData);
|
||||
|
||||
private property<length> popup-x: 200px;
|
||||
private property<length> popup-y: 200px;
|
||||
|
||||
init => {
|
||||
if (task-index == -1) {
|
||||
debug("Error: missing task-index")
|
||||
}
|
||||
}
|
||||
|
||||
taskEdit := TaskEdit {
|
||||
allow-edit-date: root.allow-edit-date;
|
||||
accepted(task) => {
|
||||
Backend.save-task({
|
||||
id: task.id,
|
||||
sourceId: task.sourceId,
|
||||
root.edited({
|
||||
title: task.title,
|
||||
scheduled: task.date.year != 0,
|
||||
date: task.date
|
||||
|
@ -42,13 +46,8 @@ export component TaskLine inherits VerticalLayout {
|
|||
border-radius: 0;
|
||||
clicked => {
|
||||
taskEdit.show({
|
||||
sourceId: task.sourceId,
|
||||
id: task.id,
|
||||
eventId: task.eventId,
|
||||
title: task.title,
|
||||
scheduled: root.date.year != 0,
|
||||
checked: task.checked,
|
||||
date: date,
|
||||
title: title,
|
||||
date: date
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +58,7 @@ export component TaskLine inherits VerticalLayout {
|
|||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => {
|
||||
Backend.delete-task-clicked(source-index, task-index)
|
||||
root.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +66,7 @@ export component TaskLine inherits VerticalLayout {
|
|||
ta := TouchArea {
|
||||
clicked => {
|
||||
checkbox.checked = !checkbox.checked;
|
||||
Backend.task-clicked(source-index, task-index);
|
||||
root.toggle-check();
|
||||
}
|
||||
pointer-event(e) => {
|
||||
if (e.button == PointerEventButton.right && e.kind == PointerEventKind.up) {
|
||||
|
@ -83,20 +82,13 @@ export component TaskLine inherits VerticalLayout {
|
|||
alignment: start;
|
||||
spacing: 8px;
|
||||
checkbox := VCheckBox {
|
||||
text: task.title;
|
||||
checked: task.checked;
|
||||
text: root.title;
|
||||
checked: root.checked;
|
||||
toggled => {
|
||||
Backend.task-clicked(source-index, task-index)
|
||||
root.toggle-check()
|
||||
}
|
||||
}
|
||||
/*for tag[tag-index] in task.tags: VTag {
|
||||
text: tag;
|
||||
size: 0.8rem;
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -4,9 +4,10 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "AppWindowBackend.h"
|
||||
#include "evalyte-cpp-common/evalyte.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "ui.h"
|
||||
#include "windows/AppWindow/AppWindow.h"
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
|
@ -15,7 +16,7 @@ int main(int argc, char **argv)
|
|||
evalyte::createRequiredDirectories("mirai");
|
||||
const auto configFilePath = evalyte::configDirectoryPath("mirai") + "/config.json";
|
||||
mirai::Mirai mirai{configFilePath};
|
||||
AppWindowBackend appWindow{&mirai};
|
||||
AppWindow appWindow{&mirai};
|
||||
appWindow.run();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,18 @@
|
|||
#include <format>
|
||||
#include <string>
|
||||
|
||||
void bindSlintUtils(const ui::Utils &utils)
|
||||
{
|
||||
utils.on_format_date([&](const ui::Date &date) {
|
||||
std::chrono::year_month_day chronoDate{
|
||||
std::chrono::year(date.year),
|
||||
std::chrono::month(date.month),
|
||||
std::chrono::day(date.day),
|
||||
};
|
||||
return std::format("{:%B %d}", chronoDate);
|
||||
});
|
||||
}
|
||||
|
||||
std::string formatZeroPadding(const int number)
|
||||
{
|
||||
if (number < 10) {
|
|
@ -6,10 +6,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "AppWindow.h"
|
||||
#include "mirai-core/DateTime.h"
|
||||
#include "ui.h"
|
||||
#include <string>
|
||||
|
||||
void bindSlintUtils(const ui::Utils &utils);
|
||||
|
||||
std::string formatZeroPadding(const int number);
|
||||
std::string formatDateRelative(const ui::Date &date);
|
||||
std::string capitalize(std::string str);
|
|
@ -1,4 +1,4 @@
|
|||
import { Time } from "std-widgets.slint";
|
||||
import { Date, Time } from "std-widgets.slint";
|
||||
|
||||
export global Utils {
|
||||
pure function format-zero-padding(number: int) -> string {
|
||||
|
@ -14,4 +14,6 @@ export global Utils {
|
|||
}
|
||||
return "\{time.hour}:\{format-zero-padding(time.minute)}";
|
||||
}
|
||||
|
||||
pure callback format-date(Date) -> string;
|
||||
}
|
10
src/ui.slint
Normal file
10
src/ui.slint
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { AppWindowModels } from "windows/AppWindow/Models.slint";
|
||||
import { AppWindowActions } from "windows/AppWindow/Actions.slint";
|
||||
import { AppWindow } from "windows/AppWindow/AppWindow.slint";
|
||||
import { SettingsWindow } from "windows/SettingsWindow/SettingsWindow.slint";
|
||||
import { AddSourceWindow } from "windows/AddSourceWindow//AddSourceWindow.slint";
|
||||
import { EditSourceWindow } from "windows/EditSourceWindow/EditSourceWindow.slint";
|
||||
import { Utils } from "shared/Utils.slint";
|
||||
import { Palette } from "@selenite";
|
||||
|
||||
export { Utils, Palette, AppWindow, AppWindowModels, AppWindowActions, SettingsWindow, AddSourceWindow, EditSourceWindow }
|
59
src/windows/AddSourceWindow/AddSourceWindow.cpp
Normal file
59
src/windows/AddSourceWindow/AddSourceWindow.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "AddSourceWindow.h"
|
||||
#include "../../SeleniteSetup.h"
|
||||
#include "evalyte-cpp-common/evalyte.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "slint.h"
|
||||
#include "slint_string.h"
|
||||
#include "ui.h"
|
||||
#include <bits/chrono.h>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <optional>
|
||||
#include <print>
|
||||
#include <string>
|
||||
|
||||
AddSourceWindow::AddSourceWindow(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance)
|
||||
{
|
||||
window_->set_default_source_path(slint::SharedString(evalyte::dataDirectoryPath("mirai") + "/")
|
||||
);
|
||||
|
||||
const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json";
|
||||
const auto palette = selenite::parseJson(palettePath);
|
||||
|
||||
if (palette.has_value()) {
|
||||
setSelenitePalette(window_->global<ui::Palette>(), palette.value());
|
||||
}
|
||||
|
||||
setupCallbacks();
|
||||
}
|
||||
|
||||
void AddSourceWindow::setupCallbacks()
|
||||
{
|
||||
window_->on_add_source([&](ui::AddSourceParam params) {
|
||||
std::unique_ptr<mirai::DataProvider> file =
|
||||
std::make_unique<mirai::MarkdownDataProvider>(std::string(params.path));
|
||||
miraiInstance_->addSource(
|
||||
std::string(params.name), std::string(params.type), std::move(file)
|
||||
);
|
||||
window_->hide();
|
||||
});
|
||||
}
|
||||
|
||||
void AddSourceWindow::open()
|
||||
{
|
||||
window_->show();
|
||||
}
|
||||
|
||||
void AddSourceWindow::close()
|
||||
{
|
||||
window_->hide();
|
||||
}
|
28
src/windows/AddSourceWindow/AddSourceWindow.h
Normal file
28
src/windows/AddSourceWindow/AddSourceWindow.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "slint.h"
|
||||
#include "ui.h"
|
||||
|
||||
class AddSourceWindow
|
||||
{
|
||||
|
||||
public:
|
||||
AddSourceWindow(mirai::Mirai *mirai);
|
||||
|
||||
void open();
|
||||
void close();
|
||||
|
||||
private:
|
||||
void setupCallbacks();
|
||||
|
||||
std::shared_ptr<slint::VectorModel<ui::Source>> sources_;
|
||||
slint::ComponentHandle<ui::AddSourceWindow> window_ = ui::AddSourceWindow::create();
|
||||
mirai::Mirai *miraiInstance_;
|
||||
};
|
|
@ -1,8 +1,12 @@
|
|||
import { Backend } from "../Backend.slint";
|
||||
import { VerticalBox, CheckBox } from "std-widgets.slint";
|
||||
import { SideBar } from "../components/SideBar.slint";
|
||||
import { VButton, VText, VTextInput, Palette } from "@selenite";
|
||||
|
||||
export struct AddSourceParam {
|
||||
name: string,
|
||||
type: string,
|
||||
path: string
|
||||
}
|
||||
|
||||
export component AddSourceWindow inherits Window {
|
||||
|
||||
title: "Mirai - Add source";
|
||||
|
@ -13,6 +17,7 @@ export component AddSourceWindow inherits Window {
|
|||
background: Palette.background;
|
||||
|
||||
in-out property <string> default-source-path;
|
||||
callback add-source(AddSourceParam);
|
||||
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
|
@ -28,7 +33,7 @@ export component AddSourceWindow inherits Window {
|
|||
VButton {
|
||||
text: "Create";
|
||||
clicked => {
|
||||
Backend.add-source({
|
||||
root.add-source({
|
||||
name: nameInput.text,
|
||||
type: "FileSystemMarkdown",
|
||||
path: pathInput.text
|
||||
|
@ -38,4 +43,4 @@ export component AddSourceWindow inherits Window {
|
|||
}
|
||||
}
|
||||
|
||||
export { Backend, Palette } // Export to make it visible to the C++ backend
|
||||
export { Palette } // Export to make it visible to the C++ backend
|
61
src/windows/AppWindow/Actions.slint
Normal file
61
src/windows/AppWindow/Actions.slint
Normal file
|
@ -0,0 +1,61 @@
|
|||
import { Date, Time } from "std-widgets.slint";
|
||||
import { CalendarDay } from "../../components/Calendar.slint";
|
||||
|
||||
export struct NewTaskData {
|
||||
sourceId: int,
|
||||
eventId: int,
|
||||
title: string,
|
||||
scheduled: bool,
|
||||
date: Date
|
||||
}
|
||||
|
||||
export struct SaveTaskData {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
scheduled: bool,
|
||||
date: Date,
|
||||
}
|
||||
|
||||
export struct NewEventParams {
|
||||
sourceId: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
startsAt: Time,
|
||||
endsAt: Time
|
||||
}
|
||||
|
||||
export struct SaveEventParams {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
startsAt: Time,
|
||||
endsAt: Time
|
||||
}
|
||||
|
||||
struct OpenNewTaskFormParams {
|
||||
eventSourceId: int,
|
||||
eventId: int,
|
||||
}
|
||||
|
||||
export global AppWindowActions {
|
||||
callback task-clicked(int, int);
|
||||
callback source-clicked(int);
|
||||
callback open-settings-window();
|
||||
callback open-add-source-window();
|
||||
callback open-edit-source-window(int);
|
||||
|
||||
callback open-new-task-form(OpenNewTaskFormParams);
|
||||
callback open-edit-task-form(int, int);
|
||||
callback open-new-event-form();
|
||||
callback open-edit-event-form(int, int);
|
||||
callback toggle-show-completed-tasks();
|
||||
callback delete-task-clicked(int, int);
|
||||
callback delete-event-clicked(int, int);
|
||||
|
||||
callback create-task(NewTaskData);
|
||||
callback save-task(SaveTaskData);
|
||||
callback create-event(NewEventParams);
|
||||
callback save-event(SaveEventParams);
|
||||
}
|
|
@ -4,18 +4,17 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "AppWindowBackend.h"
|
||||
#include "AppWindow.h"
|
||||
#include "SeleniteSetup.h"
|
||||
#include "Utils.h"
|
||||
#include "evalyte-cpp-common/evalyte.h"
|
||||
#include "mirai-core/DataProvider.h"
|
||||
#include "../../SeleniteSetup.h"
|
||||
#include "../../shared/Utils.h"
|
||||
#include "mirai-core/DateTime.h"
|
||||
#include "mirai-core/Day.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "selenite/palette.h"
|
||||
#include "slint.h"
|
||||
#include "slint_string.h"
|
||||
#include "ui.h"
|
||||
#include <bits/chrono.h>
|
||||
#include <cassert>
|
||||
#include <charconv>
|
||||
|
@ -23,7 +22,6 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
@ -34,14 +32,14 @@
|
|||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
AppWindowBackend::AppWindowBackend(mirai::Mirai *miraiInstance)
|
||||
: miraiInstance_(miraiInstance), view_(miraiInstance)
|
||||
AppWindow::AppWindow(mirai::Mirai *miraiInstance)
|
||||
: miraiInstance_(miraiInstance), addSourceWindow_(miraiInstance),
|
||||
editSourceWindow_(miraiInstance), settingsWindow_(miraiInstance), view_(miraiInstance)
|
||||
{
|
||||
sources_ = std::make_shared<slint::VectorModel<ui::Source>>();
|
||||
days_ = std::make_shared<slint::VectorModel<ui::Day>>();
|
||||
calendar_ = std::make_shared<slint::VectorModel<ui::CalendarDay>>();
|
||||
unscheduledTasks_ = std::make_shared<slint::VectorModel<ui::TaskData>>();
|
||||
tags_ = std::make_shared<slint::VectorModel<slint::SharedString>>();
|
||||
auto sourcesNames = std::make_shared<slint::MapModel<ui::Source, slint::SharedString>>(
|
||||
sources_,
|
||||
[&](const ui::Source &a) {
|
||||
|
@ -49,29 +47,19 @@ AppWindowBackend::AppWindowBackend(mirai::Mirai *miraiInstance)
|
|||
}
|
||||
);
|
||||
|
||||
addSourceWindow_->set_default_source_path(
|
||||
slint::SharedString(evalyte::dataDirectoryPath("mirai") + "/")
|
||||
);
|
||||
|
||||
const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json";
|
||||
const auto palette = selenite::parseJson(palettePath);
|
||||
if (palette.has_value()) {
|
||||
std::println(std::cerr, "Warning, no {} found", palettePath);
|
||||
setSelenitePalette(mainWindow_->global<ui::Palette>(), palette.value());
|
||||
setSelenitePalette(settingsWindow_->global<ui::Palette>(), palette.value());
|
||||
setSelenitePalette(addSourceWindow_->global<ui::Palette>(), palette.value());
|
||||
setSelenitePalette(editSourceWindow_->global<ui::Palette>(), palette.value());
|
||||
}
|
||||
|
||||
mainWindow_->global<ui::Backend>().set_sources(sourcesNames);
|
||||
settingsWindow_->global<ui::Backend>().set_sources(sourcesNames);
|
||||
bindSlintUtils(mainWindow_->global<ui::Utils>());
|
||||
|
||||
mainWindow_->global<ui::Backend>().set_sources_selected(sources_);
|
||||
settingsWindow_->global<ui::Backend>().set_sources_selected(sources_);
|
||||
|
||||
mainWindow_->global<ui::Backend>().set_tags(tags_);
|
||||
mainWindow_->global<ui::Backend>().set_days(days_);
|
||||
mainWindow_->global<ui::Backend>().set_calendar(calendar_);
|
||||
models().set_sources(sourcesNames);
|
||||
models().set_sources_selected(sources_);
|
||||
models().set_days(days_);
|
||||
models().set_calendar(calendar_);
|
||||
|
||||
view_.setAllSources();
|
||||
view_.update();
|
||||
|
@ -103,64 +91,30 @@ std::optional<ui::Date> stringToDate(const std::string &dateStr)
|
|||
return ui::Date{.year = year, .month = month, .day = day};
|
||||
}
|
||||
|
||||
void AppWindowBackend::setupUtilsCallbacks()
|
||||
void AppWindow::setupCallbacks()
|
||||
{
|
||||
mainWindow_->global<ui::Backend>().on_format_date([&](const ui::Date &date) {
|
||||
std::chrono::year_month_day chronoDate{
|
||||
std::chrono::year(date.year),
|
||||
std::chrono::month(date.month),
|
||||
std::chrono::day(date.day),
|
||||
};
|
||||
return std::format("{:%B %d}", chronoDate);
|
||||
miraiInstance_->onSourceAdded([&](mirai::Source *source) {
|
||||
refreshModels();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_format_date_relative([&](const ui::Date &date) {
|
||||
return formatDateRelative(date);
|
||||
miraiInstance_->onSourceEdited([&](mirai::Source *source) {
|
||||
refreshModels();
|
||||
});
|
||||
}
|
||||
|
||||
void AppWindowBackend::setupCallbacks()
|
||||
{
|
||||
mainWindow_->global<ui::Backend>().on_settings_clicked([&]() {
|
||||
settingsWindow_->show();
|
||||
miraiInstance_->onSourceDeleted([&](int id) {
|
||||
refreshModels();
|
||||
});
|
||||
mainWindow_->global<ui::Backend>().on_add_source_clicked([&]() {
|
||||
addSourceWindow_->show();
|
||||
actions().on_open_settings_window([&]() {
|
||||
settingsWindow_.open();
|
||||
});
|
||||
mainWindow_->global<ui::Backend>().on_edit_source_clicked([&](int sourceId) {
|
||||
actions().on_open_add_source_window([&]() {
|
||||
addSourceWindow_.open();
|
||||
});
|
||||
actions().on_open_edit_source_window([&](int sourceId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
auto markdownSource = dynamic_cast<mirai::MarkdownDataProvider *>(source->dataProvider());
|
||||
editSourceWindow_->set_id(source->id);
|
||||
editSourceWindow_->set_name(slint::SharedString(source->name()));
|
||||
editSourceWindow_->set_path(slint::SharedString(markdownSource->path()));
|
||||
editSourceWindow_->show();
|
||||
editSourceWindow_.open(source);
|
||||
});
|
||||
addSourceWindow_->global<ui::Backend>().on_add_source([&](ui::AddSourceParam params) {
|
||||
std::unique_ptr<mirai::DataProvider> file =
|
||||
std::make_unique<mirai::MarkdownDataProvider>(std::string(params.path));
|
||||
miraiInstance_->addSource(
|
||||
std::string(params.name), std::string(params.type), std::move(file)
|
||||
);
|
||||
addSourceWindow_->hide();
|
||||
view_.setAllSources();
|
||||
view_.update();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
});
|
||||
editSourceWindow_->global<ui::Backend>().on_modify_source([&](ui::ModifySourceParam params) {
|
||||
miraiInstance_->editSource(params.id, std::string(params.name), std::string(params.path));
|
||||
editSourceWindow_->hide();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
});
|
||||
editSourceWindow_->global<ui::Backend>().on_delete_source([&](int sourceId) {
|
||||
miraiInstance_->deleteSource(sourceId);
|
||||
editSourceWindow_->hide();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
});
|
||||
mainWindow_->global<ui::Backend>().on_task_clicked([&](int sourceId, int taskId) {
|
||||
|
||||
actions().on_task_clicked([&](int sourceId, int taskId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
auto task = source->getTaskById(taskId);
|
||||
|
@ -174,7 +128,7 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_source_clicked([&](int index) {
|
||||
actions().on_source_clicked([&](int index) {
|
||||
// index with value -1 is equal to no selection, aka "All"
|
||||
if (index == -1) {
|
||||
view_.setAllSources();
|
||||
|
@ -183,13 +137,13 @@ void AppWindowBackend::setupCallbacks()
|
|||
const mirai::Source *source = miraiInstance_->getSourceById(index);
|
||||
view_.addSource(*source);
|
||||
}
|
||||
mainWindow_->global<ui::Backend>().set_default_source_index(index == -1 ? 0 : index);
|
||||
models().set_default_source_index(index == -1 ? 0 : index);
|
||||
view_.update();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_delete_task_clicked([&](int sourceId, int taskId) {
|
||||
actions().on_delete_task_clicked([&](int sourceId, int taskId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
auto task = source->getTaskById(taskId);
|
||||
|
@ -200,13 +154,13 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_toggle_show_completed_tasks([&] {
|
||||
actions().on_toggle_show_completed_tasks([&] {
|
||||
view_.hideCompletedTasks(!view_.shouldHideCompletedTasks());
|
||||
view_.update();
|
||||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_save_task([&](ui::SaveTaskData newTaskData) {
|
||||
actions().on_save_task([&](ui::SaveTaskData newTaskData) {
|
||||
auto source = miraiInstance_->getSourceById(newTaskData.sourceId);
|
||||
assert(source);
|
||||
auto task = source->getTaskById(newTaskData.id);
|
||||
|
@ -228,7 +182,7 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_create_task([&](ui::NewTaskData newTaskData) {
|
||||
actions().on_create_task([&](ui::NewTaskData newTaskData) {
|
||||
std::optional<mirai::Date> date = std::nullopt;
|
||||
if (newTaskData.date.year != 0) {
|
||||
date = SlintDateToMiraiDate(newTaskData.date);
|
||||
|
@ -251,7 +205,7 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_delete_event_clicked([&](int sourceId, int eventId) {
|
||||
actions().on_delete_event_clicked([&](int sourceId, int eventId) {
|
||||
auto source = miraiInstance_->getSourceById(sourceId);
|
||||
assert(source);
|
||||
auto event = source->getEventById(eventId);
|
||||
|
@ -262,7 +216,7 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_create_event([&](ui::NewEventParams newEventParams) {
|
||||
actions().on_create_event([&](ui::NewEventParams newEventParams) {
|
||||
const ui::Date &date = newEventParams.date;
|
||||
const std::string dateStr = SlintDateToStdString(date);
|
||||
auto source = miraiInstance_->getSourceById(newEventParams.sourceId);
|
||||
|
@ -278,7 +232,7 @@ void AppWindowBackend::setupCallbacks()
|
|||
reloadTasks();
|
||||
});
|
||||
|
||||
mainWindow_->global<ui::Backend>().on_save_event([&](ui::SaveEventParams newEventParams) {
|
||||
actions().on_save_event([&](ui::SaveEventParams newEventParams) {
|
||||
const ui::Date &date = newEventParams.date;
|
||||
const std::string dateStr = SlintDateToStdString(date);
|
||||
auto source = miraiInstance_->getSourceById(newEventParams.sourceId);
|
||||
|
@ -295,7 +249,6 @@ void AppWindowBackend::setupCallbacks()
|
|||
view_.update();
|
||||
reloadTasks();
|
||||
});
|
||||
setupUtilsCallbacks();
|
||||
}
|
||||
|
||||
std::shared_ptr<slint::VectorModel<slint::SharedString>>
|
||||
|
@ -308,7 +261,7 @@ stdToSlintStringVector(const std::vector<std::string> &stdVector)
|
|||
return slintVector;
|
||||
}
|
||||
|
||||
void AppWindowBackend::reloadTasks()
|
||||
void AppWindow::reloadTasks()
|
||||
{
|
||||
days_->clear();
|
||||
if (miraiInstance_->getSources().size() == 0) {
|
||||
|
@ -374,7 +327,7 @@ void AppWindowBackend::reloadTasks()
|
|||
}
|
||||
}
|
||||
days_ = slintDays;
|
||||
mainWindow_->global<ui::Backend>().set_days(days_);
|
||||
models().set_days(days_);
|
||||
|
||||
auto unscheduledTasksView = view_.getUnscheduledTasks();
|
||||
unscheduledTasks_->clear();
|
||||
|
@ -388,7 +341,7 @@ void AppWindowBackend::reloadTasks()
|
|||
.checked = task.checked(),
|
||||
});
|
||||
}
|
||||
mainWindow_->global<ui::Backend>().set_unscheduled_tasks(unscheduledTasks_);
|
||||
models().set_unscheduled_tasks(unscheduledTasks_);
|
||||
|
||||
calendar_->clear();
|
||||
for (int dayIndex = 0; dayIndex < 7; ++dayIndex) {
|
||||
|
@ -427,7 +380,7 @@ void AppWindowBackend::reloadTasks()
|
|||
}
|
||||
}
|
||||
|
||||
void AppWindowBackend::reloadSources()
|
||||
void AppWindow::reloadSources()
|
||||
{
|
||||
sources_->clear();
|
||||
bool noSourceSelected = miraiInstance_->getSources().size() == view_.activeSourceCount();
|
||||
|
@ -442,10 +395,28 @@ void AppWindowBackend::reloadSources()
|
|||
.path = slint::SharedString(sourceProvider->path())}
|
||||
);
|
||||
}
|
||||
mainWindow_->global<ui::Backend>().set_no_source_selected(noSourceSelected);
|
||||
models().set_no_source_selected(noSourceSelected);
|
||||
}
|
||||
|
||||
void AppWindowBackend::run()
|
||||
void AppWindow::refreshModels()
|
||||
{
|
||||
view_.setAllSources();
|
||||
view_.update();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
}
|
||||
|
||||
void AppWindow::run()
|
||||
{
|
||||
mainWindow_->run();
|
||||
}
|
||||
|
||||
const ui::AppWindowModels &AppWindow::models()
|
||||
{
|
||||
return mainWindow_->global<ui::AppWindowModels>();
|
||||
}
|
||||
|
||||
const ui::AppWindowActions &AppWindow::actions()
|
||||
{
|
||||
return mainWindow_->global<ui::AppWindowActions>();
|
||||
}
|
|
@ -6,36 +6,40 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "AppWindow.h"
|
||||
#include "../AddSourceWindow/AddSourceWindow.h"
|
||||
#include "../EditSourceWindow/EditSourceWindow.h"
|
||||
#include "../SettingsWindow/SettingsWindow.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "mirai-core/View.h"
|
||||
#include "slint.h"
|
||||
#include "ui.h"
|
||||
|
||||
class AppWindowBackend
|
||||
class AppWindow
|
||||
{
|
||||
|
||||
public:
|
||||
AppWindowBackend(mirai::Mirai *mirai);
|
||||
AppWindow(mirai::Mirai *mirai);
|
||||
|
||||
void run();
|
||||
|
||||
void reloadSources();
|
||||
void reloadTasks();
|
||||
void refreshModels();
|
||||
|
||||
private:
|
||||
void setupCallbacks();
|
||||
void setupUtilsCallbacks();
|
||||
const ui::AppWindowModels &models();
|
||||
const ui::AppWindowActions &actions();
|
||||
|
||||
std::shared_ptr<slint::VectorModel<ui::Source>> sources_;
|
||||
std::shared_ptr<slint::VectorModel<slint::SharedString>> tags_;
|
||||
std::shared_ptr<slint::VectorModel<ui::Day>> days_;
|
||||
std::shared_ptr<slint::VectorModel<ui::CalendarDay>> calendar_;
|
||||
std::shared_ptr<slint::VectorModel<ui::TaskData>> unscheduledTasks_;
|
||||
|
||||
slint::ComponentHandle<ui::AppWindow> mainWindow_ = ui::AppWindow::create();
|
||||
slint::ComponentHandle<ui::SettingsWindow> settingsWindow_ = ui::SettingsWindow::create();
|
||||
slint::ComponentHandle<ui::AddSourceWindow> addSourceWindow_ = ui::AddSourceWindow::create();
|
||||
slint::ComponentHandle<ui::EditSourceWindow> editSourceWindow_ = ui::EditSourceWindow::create();
|
||||
SettingsWindow settingsWindow_;
|
||||
AddSourceWindow addSourceWindow_;
|
||||
EditSourceWindow editSourceWindow_;
|
||||
|
||||
mirai::Mirai *miraiInstance_;
|
||||
mirai::View view_;
|
26
src/windows/AppWindow/AppWindow.slint
Normal file
26
src/windows/AppWindow/AppWindow.slint
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { AppWindowModels } from "Models.slint";
|
||||
import { Button, VerticalBox, CheckBox } from "std-widgets.slint";
|
||||
import { SideBar } from "views/SideBar.slint";
|
||||
import { MainView } from "views/TasksView.slint";
|
||||
import { SettingsWindow } from "../SettingsWindow/SettingsWindow.slint";
|
||||
import { AddSourceWindow } from "../AddSourceWindow//AddSourceWindow.slint";
|
||||
import { EditSourceWindow } from "../EditSourceWindow/EditSourceWindow.slint";
|
||||
import { Palette } from "@selenite";
|
||||
|
||||
export component AppWindow inherits Window {
|
||||
|
||||
title: "Mirai";
|
||||
min-height: 100px;
|
||||
max-height: 4000px; // needed, otherwise the window wants to fit the content (on Swaywm)
|
||||
default-font-size: 16px;
|
||||
|
||||
HorizontalLayout {
|
||||
SideBar {}
|
||||
MainView {
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { AppWindowModels, Palette, SettingsWindow, AddSourceWindow, EditSourceWindow } // Export to make it visible to the C++ backend
|
50
src/windows/AppWindow/Models.slint
Normal file
50
src/windows/AppWindow/Models.slint
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { Date, Time } from "std-widgets.slint";
|
||||
import { CalendarDay } from "../../components/Calendar.slint";
|
||||
|
||||
export struct Source {
|
||||
id: int,
|
||||
name: string,
|
||||
selected: bool,
|
||||
path: string
|
||||
}
|
||||
|
||||
export struct TaskData {
|
||||
sourceId: int,
|
||||
eventId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
checked: bool,
|
||||
}
|
||||
|
||||
export struct Event {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
startsAt: Time,
|
||||
endsAt: Time,
|
||||
tasks: [TaskData],
|
||||
}
|
||||
|
||||
export struct Day {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
date: Date,
|
||||
events: [Event],
|
||||
tasks: [TaskData],
|
||||
isLate: bool,
|
||||
isToday: bool,
|
||||
relativeDaysDiff: int
|
||||
}
|
||||
|
||||
export global AppWindowModels {
|
||||
in-out property<[Source]> sources-selected;
|
||||
in-out property<int> default-source-index;
|
||||
in-out property<[string]> sources;
|
||||
in-out property<bool> no-source-selected;
|
||||
in-out property<[Day]> days;
|
||||
in-out property<[CalendarDay]> calendar;
|
||||
in-out property<[TaskData]> unscheduled-tasks;
|
||||
|
||||
callback get-source-id-from-name(string) -> int;
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import { Backend } from "../Backend.slint";
|
||||
import { AppWindowModels, TaskData } from "../Models.slint";
|
||||
import { AppWindowActions } from "../Actions.slint";
|
||||
import { VButton, ToggleButton, VActionButton, VText, Svg, Palette } from "@selenite";
|
||||
|
||||
export component SideBar inherits Rectangle {
|
||||
|
@ -20,7 +21,7 @@ export component SideBar inherits Rectangle {
|
|||
icon-svg: Svg.plus;
|
||||
icon-colorize: Palette.green;
|
||||
background: transparent;
|
||||
clicked => { Backend.add-source-clicked() }
|
||||
clicked => { AppWindowActions.open-add-source-window() }
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
|
@ -32,21 +33,21 @@ export component SideBar inherits Rectangle {
|
|||
ToggleButton {
|
||||
text: "All";
|
||||
text-alignment: left;
|
||||
active: Backend.no-source-selected;
|
||||
clicked => { Backend.source-clicked(-1) }
|
||||
active: AppWindowModels.no-source-selected;
|
||||
clicked => { AppWindowActions.source-clicked(-1) }
|
||||
|
||||
|
||||
}
|
||||
for item[index] in Backend.sources-selected: ToggleButton {
|
||||
for item[index] in AppWindowModels.sources-selected: ToggleButton {
|
||||
text: item.name;
|
||||
text-alignment: left;
|
||||
active: item.selected;
|
||||
clicked => { Backend.source-clicked(item.id) }
|
||||
clicked => { AppWindowActions.source-clicked(item.id) }
|
||||
VActionButton {
|
||||
visible: parent.active;
|
||||
icon-svg: Svg.cog;
|
||||
background: transparent;
|
||||
clicked => { Backend.edit-source-clicked(item.id) }
|
||||
clicked => { AppWindowActions.open-edit-source-window(item.id) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +57,7 @@ export component SideBar inherits Rectangle {
|
|||
icon-svg: Svg.cog;
|
||||
text: "Settings";
|
||||
background: transparent;
|
||||
clicked => { Backend.settings-clicked() }
|
||||
clicked => { AppWindowModels.open-settings-window() }
|
||||
}*/
|
||||
}
|
||||
}
|
221
src/windows/AppWindow/views/TasksView.slint
Normal file
221
src/windows/AppWindow/views/TasksView.slint
Normal file
|
@ -0,0 +1,221 @@
|
|||
import { AppWindowModels, TaskData } from "../Models.slint";
|
||||
import { AppWindowActions, NewTaskData, SaveTaskData } from "../Actions.slint";
|
||||
import { Button, VerticalBox, CheckBox, ScrollView, ComboBox } from "std-widgets.slint";
|
||||
import { TaskLine } from "../../../components/TaskLine.slint";
|
||||
import { EventGroup } from "../../../components/EventGroup.slint";
|
||||
import { Calendar } from "../../../components/Calendar.slint";
|
||||
import { VPopupIconMenu, VDatePicker, VTimePicker, VCheckBox, VButton, VTag, VText, VTextInput, Svg, Palette } from "@selenite";
|
||||
import { CreateTaskOrEvent } from "../../../components/CreateTaskOrEvent.slint";
|
||||
import { Utils } from "../../../shared/Utils.slint";
|
||||
|
||||
export component MainView inherits Rectangle {
|
||||
|
||||
background: Palette.background;
|
||||
private property<string> icon-visible: Svg.visible;
|
||||
private property<string> icon-not-visible: Svg.not-visible;
|
||||
private property<bool> completed-tasks-visible: false;
|
||||
|
||||
HorizontalLayout {
|
||||
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
padding: 16px;
|
||||
spacing: 16px;
|
||||
HorizontalLayout {
|
||||
horizontal-stretch: 1;
|
||||
alignment: start;
|
||||
spacing: 8px;
|
||||
VButton {
|
||||
text: "Show/Hide completed tasks";
|
||||
clicked => {
|
||||
AppWindowActions.toggle-show-completed-tasks();
|
||||
completed-tasks-visible = !completed-tasks-visible;
|
||||
}
|
||||
icon-svg: completed-tasks-visible ? icon-visible : icon-not-visible;
|
||||
icon-colorize: Palette.control-foreground;
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
background: Palette.background.brighter(0.2);
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
CreateTaskOrEvent {
|
||||
sources: AppWindowModels.sources;
|
||||
create-task(data) => {
|
||||
AppWindowActions.create-task({
|
||||
sourceId: data.sourceId,
|
||||
eventId: -1,
|
||||
title: data.title,
|
||||
scheduled: data.date.year != 0,
|
||||
date: data.date
|
||||
})
|
||||
}
|
||||
|
||||
create-event(data) => {
|
||||
AppWindowActions.create-event({
|
||||
sourceId: data.sourceId,
|
||||
title: data.title,
|
||||
date: data.date,
|
||||
startsAt: data.startsAt,
|
||||
endsAt: data.endsAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Flickable {
|
||||
horizontal-stretch: 1;
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
spacing: 16px;
|
||||
if AppWindowModels.days.length == 0 && AppWindowModels.unscheduled-tasks.length == 0 : VText {
|
||||
text: "There is no task to show";
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
for day[dayIndex] in AppWindowModels.days: VerticalLayout {
|
||||
Rectangle {
|
||||
background: Palette.card-background;
|
||||
border-radius: 8px;
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
VText {
|
||||
text: Utils.format-date(day.date);
|
||||
color: day.isLate ? Palette.orange : Palette.foreground;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
VText {
|
||||
text: day.relativeDaysDiff == 0 ? " - today" :
|
||||
day.relativeDaysDiff == 1 ? " - tomorrow" :
|
||||
day.relativeDaysDiff == -1 ? " - yesterday" :
|
||||
day.relativeDaysDiff > 0 ? " - in \{day.relativeDaysDiff} days" :
|
||||
" - \{-day.relativeDaysDiff} days ago";
|
||||
color: Palette.foreground-hint;
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
for event[eventIndex] in day.events: VerticalLayout {
|
||||
padding-top: 16px;
|
||||
EventGroup {
|
||||
event: event;
|
||||
add-task(data) => {
|
||||
AppWindowActions.create-task({
|
||||
sourceId: event.sourceId,
|
||||
eventId: event.id,
|
||||
title: data.title,
|
||||
});
|
||||
}
|
||||
edit-task(taskId, data) => {
|
||||
AppWindowActions.save-task({
|
||||
id: taskId,
|
||||
sourceId: event.sourceId,
|
||||
title: data.title,
|
||||
});
|
||||
}
|
||||
delete-task(taskId) => {
|
||||
AppWindowActions.delete-task-clicked(event.sourceId, taskId)
|
||||
}
|
||||
toggle-check-task(taskId) => {
|
||||
AppWindowActions.task-clicked(event.sourceId, taskId);
|
||||
}
|
||||
delete => {
|
||||
AppWindowActions.delete-event-clicked(event.sourceId, event.id)
|
||||
}
|
||||
edit(data) => {
|
||||
AppWindowActions.save-event({
|
||||
sourceId: event.sourceId,
|
||||
id: event.id,
|
||||
title: data.title,
|
||||
//date: event.date,
|
||||
startsAt: event.startsAt,
|
||||
endsAt: event.endsAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
for task[taskIndex] in day.tasks: VerticalLayout {
|
||||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
title: task.title;
|
||||
scheduled: task.date.year != 0;
|
||||
date: day.date;
|
||||
checked: task.checked;
|
||||
allow-edit-date: true;
|
||||
delete => {
|
||||
AppWindowActions.delete-task-clicked(task.sourceId, task.id)
|
||||
}
|
||||
toggle-check => {
|
||||
AppWindowActions.task-clicked(task.sourceId, task.id);
|
||||
}
|
||||
edited(data) => {
|
||||
AppWindowActions.save-task({
|
||||
id: task.id,
|
||||
sourceId: task.sourceId,
|
||||
title: data.title,
|
||||
scheduled: data.scheduled,
|
||||
date: data.date
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if AppWindowModels.unscheduled-tasks.length > 0 : VerticalLayout {
|
||||
Rectangle {
|
||||
background: Palette.card-background;
|
||||
border-radius: 8px;
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
VText {
|
||||
text: "Unscheduled";
|
||||
color: Palette.foreground;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
}
|
||||
for task[taskIndex] in AppWindowModels.unscheduled-tasks: VerticalLayout {
|
||||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
title: task.title;
|
||||
checked: task.checked;
|
||||
allow-edit-date: true;
|
||||
delete => {
|
||||
AppWindowActions.delete-task-clicked(task.sourceId, task.id)
|
||||
}
|
||||
toggle-check => {
|
||||
AppWindowActions.task-clicked(task.sourceId, task.id);
|
||||
}
|
||||
edited(data) => {
|
||||
AppWindowActions.save-task({
|
||||
id: task.id,
|
||||
sourceId: task.sourceId,
|
||||
title: data.title,
|
||||
scheduled: data.scheduled,
|
||||
date: data.date
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Calendar {
|
||||
init => { debug("cal len", AppWindowModels.calendar.length) }
|
||||
days: AppWindowModels.calendar;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
61
src/windows/EditSourceWindow/EditSourceWindow.cpp
Normal file
61
src/windows/EditSourceWindow/EditSourceWindow.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "EditSourceWindow.h"
|
||||
#include "../../SeleniteSetup.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "slint.h"
|
||||
#include "slint_string.h"
|
||||
#include "ui.h"
|
||||
#include <bits/chrono.h>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <optional>
|
||||
#include <print>
|
||||
#include <string>
|
||||
|
||||
EditSourceWindow::EditSourceWindow(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance)
|
||||
{
|
||||
|
||||
const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json";
|
||||
const auto palette = selenite::parseJson(palettePath);
|
||||
|
||||
if (palette.has_value()) {
|
||||
setSelenitePalette(window_->global<ui::Palette>(), palette.value());
|
||||
}
|
||||
|
||||
setupCallbacks();
|
||||
}
|
||||
|
||||
void EditSourceWindow::setupCallbacks()
|
||||
{
|
||||
window_->on_modify_source([&](ui::ModifySourceParam params) {
|
||||
miraiInstance_->editSource(params.id, std::string(params.name), std::string(params.path));
|
||||
close();
|
||||
});
|
||||
window_->on_delete_source([&](int sourceId) {
|
||||
miraiInstance_->deleteSource(sourceId);
|
||||
close();
|
||||
});
|
||||
}
|
||||
|
||||
void EditSourceWindow::open(mirai::Source *source)
|
||||
{
|
||||
assert(source != nullptr);
|
||||
auto markdownSource = dynamic_cast<mirai::MarkdownDataProvider *>(source->dataProvider());
|
||||
window_->set_id(source->id);
|
||||
window_->set_name(slint::SharedString(source->name()));
|
||||
window_->set_path(slint::SharedString(markdownSource->path()));
|
||||
window_->show();
|
||||
}
|
||||
|
||||
void EditSourceWindow::close()
|
||||
{
|
||||
window_->hide();
|
||||
}
|
29
src/windows/EditSourceWindow/EditSourceWindow.h
Normal file
29
src/windows/EditSourceWindow/EditSourceWindow.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "mirai-core/Source.h"
|
||||
#include "slint.h"
|
||||
#include "ui.h"
|
||||
|
||||
class EditSourceWindow
|
||||
{
|
||||
|
||||
public:
|
||||
EditSourceWindow(mirai::Mirai *mirai);
|
||||
|
||||
void open(mirai::Source *source);
|
||||
void close();
|
||||
|
||||
private:
|
||||
void setupCallbacks();
|
||||
|
||||
std::shared_ptr<slint::VectorModel<ui::Source>> sources_;
|
||||
slint::ComponentHandle<ui::EditSourceWindow> window_ = ui::EditSourceWindow::create();
|
||||
mirai::Mirai *miraiInstance_;
|
||||
};
|
|
@ -1,8 +1,12 @@
|
|||
import { Backend } from "../Backend.slint";
|
||||
import { VerticalBox, CheckBox } from "std-widgets.slint";
|
||||
import { SideBar } from "../components/SideBar.slint";
|
||||
import { VButton, VText, VTextInput, Palette } from "@selenite";
|
||||
|
||||
export struct ModifySourceParam {
|
||||
id: int,
|
||||
name: string,
|
||||
path: string
|
||||
}
|
||||
|
||||
export component EditSourceWindow inherits Window {
|
||||
in-out property <int> id;
|
||||
in-out property name <=> nameInput.text;
|
||||
|
@ -15,6 +19,9 @@ export component EditSourceWindow inherits Window {
|
|||
default-font-size: 16px;
|
||||
background: Palette.background;
|
||||
|
||||
callback modify-source(ModifySourceParam);
|
||||
callback delete-source(int);
|
||||
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 8px;
|
||||
|
@ -27,7 +34,7 @@ export component EditSourceWindow inherits Window {
|
|||
VButton {
|
||||
text: "Save";
|
||||
clicked => {
|
||||
Backend.modify-source({
|
||||
root.modify-source({
|
||||
id: root.id,
|
||||
name: nameInput.text,
|
||||
path: pathInput.text
|
||||
|
@ -38,10 +45,10 @@ export component EditSourceWindow inherits Window {
|
|||
text: "Delete";
|
||||
background-color: Palette.red;
|
||||
double-clicked => {
|
||||
Backend.delete-source(root.id)
|
||||
root.delete-source(root.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { Backend, Palette } // Export to make it visible to the C++ backend
|
||||
export { Palette } // Export to make it visible to the C++ backend
|
50
src/windows/SettingsWindow/SettingsWindow.cpp
Normal file
50
src/windows/SettingsWindow/SettingsWindow.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "SettingsWindow.h"
|
||||
#include "../../SeleniteSetup.h"
|
||||
#include "evalyte-cpp-common/evalyte.h"
|
||||
#include "mirai-core/DataProvider.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "slint.h"
|
||||
#include "slint_string.h"
|
||||
#include <bits/chrono.h>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <print>
|
||||
#include <string>
|
||||
|
||||
SettingsWindow::SettingsWindow(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance)
|
||||
{
|
||||
|
||||
const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json";
|
||||
const auto palette = selenite::parseJson(palettePath);
|
||||
|
||||
if (palette.has_value()) {
|
||||
setSelenitePalette(window_->global<ui::Palette>(), palette.value());
|
||||
}
|
||||
|
||||
setupCallbacks();
|
||||
}
|
||||
|
||||
void SettingsWindow::setupCallbacks()
|
||||
{
|
||||
}
|
||||
|
||||
void SettingsWindow::open()
|
||||
{
|
||||
window_->show();
|
||||
}
|
||||
|
||||
void SettingsWindow::close()
|
||||
{
|
||||
window_->hide();
|
||||
}
|
28
src/windows/SettingsWindow/SettingsWindow.h
Normal file
28
src/windows/SettingsWindow/SettingsWindow.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "slint.h"
|
||||
#include "ui.h"
|
||||
|
||||
class SettingsWindow
|
||||
{
|
||||
|
||||
public:
|
||||
SettingsWindow(mirai::Mirai *mirai);
|
||||
|
||||
void open();
|
||||
void close();
|
||||
|
||||
private:
|
||||
void setupCallbacks();
|
||||
|
||||
std::shared_ptr<slint::VectorModel<ui::Source>> sources_;
|
||||
slint::ComponentHandle<ui::SettingsWindow> window_ = ui::SettingsWindow::create();
|
||||
mirai::Mirai *miraiInstance_;
|
||||
};
|
|
@ -1,7 +1,5 @@
|
|||
import { Backend } from "Backend.slint";
|
||||
import { AppWindowModels } from "../AppWindow/Models.slint";
|
||||
import { Button, VerticalBox, CheckBox } from "std-widgets.slint";
|
||||
import { SideBar } from "./components/SideBar.slint";
|
||||
import { MainView } from "MainView.slint";
|
||||
import { VText, VTextInput, Palette } from "@selenite";
|
||||
|
||||
export component SettingsWindow inherits Window {
|
||||
|
@ -15,7 +13,7 @@ export component SettingsWindow inherits Window {
|
|||
VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 8px;
|
||||
for source[source-index] in Backend.sources-selected: VerticalLayout {
|
||||
for source[source-index] in AppWindowModels.sources-selected: VerticalLayout {
|
||||
VText {
|
||||
text: source.name;
|
||||
}
|
||||
|
@ -26,4 +24,4 @@ export component SettingsWindow inherits Window {
|
|||
}
|
||||
}
|
||||
|
||||
export { Backend, Palette } // Export to make it visible to the C++ backend
|
||||
export { AppWindowModels, Palette } // Export to make it visible to the C++ backend
|
|
@ -1,26 +0,0 @@
|
|||
import { Backend } from "Backend.slint";
|
||||
import { Button, VerticalBox, CheckBox } from "std-widgets.slint";
|
||||
import { SideBar } from "./components/SideBar.slint";
|
||||
import { MainView } from "MainView.slint";
|
||||
import { SettingsWindow } from "SettingsWindow.slint";
|
||||
import { AddSourceWindow } from "windows/AddSourceWindow.slint";
|
||||
import { EditSourceWindow } from "windows/EditSourceWindow.slint";
|
||||
import { Palette } from "@selenite";
|
||||
|
||||
export component AppWindow inherits Window {
|
||||
|
||||
title: "Mirai";
|
||||
min-height: 100px;
|
||||
max-height: 4000px; // needed, otherwise the window wants to fit the content (on Swaywm)
|
||||
default-font-size: 16px;
|
||||
|
||||
HorizontalLayout {
|
||||
SideBar {}
|
||||
MainView {
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { Backend, Palette, SettingsWindow, AddSourceWindow, EditSourceWindow } // Export to make it visible to the C++ backend
|
128
ui/Backend.slint
128
ui/Backend.slint
|
@ -1,128 +0,0 @@
|
|||
import { Date, Time } from "std-widgets.slint";
|
||||
import { CalendarDay } from "components/Calendar.slint";
|
||||
|
||||
export struct NewTaskData {
|
||||
sourceId: int,
|
||||
eventId: int,
|
||||
title: string,
|
||||
scheduled: bool,
|
||||
date: Date
|
||||
}
|
||||
|
||||
export struct SaveTaskData {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
scheduled: bool,
|
||||
date: Date,
|
||||
}
|
||||
|
||||
export struct NewEventParams {
|
||||
sourceId: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
startsAt: Time,
|
||||
endsAt: Time
|
||||
}
|
||||
|
||||
export struct SaveEventParams {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
startsAt: Time,
|
||||
endsAt: Time
|
||||
}
|
||||
|
||||
export struct AddSourceParam {
|
||||
name: string,
|
||||
type: string,
|
||||
path: string
|
||||
}
|
||||
|
||||
export struct ModifySourceParam {
|
||||
id: int,
|
||||
name: string,
|
||||
path: string
|
||||
}
|
||||
|
||||
export struct Source {
|
||||
id: int,
|
||||
name: string,
|
||||
selected: bool,
|
||||
path: string
|
||||
}
|
||||
|
||||
export struct TaskData {
|
||||
sourceId: int,
|
||||
eventId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
date: Date,
|
||||
checked: bool,
|
||||
}
|
||||
|
||||
export struct Event {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
title: string,
|
||||
startsAt: Time,
|
||||
endsAt: Time,
|
||||
tasks: [TaskData],
|
||||
}
|
||||
|
||||
export struct Day {
|
||||
sourceId: int,
|
||||
id: int,
|
||||
date: Date,
|
||||
events: [Event],
|
||||
tasks: [TaskData],
|
||||
isLate: bool,
|
||||
isToday: bool,
|
||||
relativeDaysDiff: int
|
||||
}
|
||||
|
||||
struct OpenNewTaskFormParams {
|
||||
eventSourceId: int,
|
||||
eventId: int,
|
||||
}
|
||||
|
||||
export global Backend {
|
||||
in-out property<[Source]> sources-selected;
|
||||
in-out property<int> default-source-index;
|
||||
in-out property<[string]> sources;
|
||||
in-out property<bool> no-source-selected;
|
||||
in-out property<[string]> tags;
|
||||
in-out property<[Day]> days;
|
||||
in-out property<[CalendarDay]> calendar;
|
||||
in-out property<[TaskData]> unscheduled-tasks;
|
||||
|
||||
callback task-clicked(int, int);
|
||||
callback source-clicked(int);
|
||||
callback tag-clicked(int);
|
||||
callback settings-clicked();
|
||||
callback add-source-clicked();
|
||||
callback edit-source-clicked(int);
|
||||
|
||||
callback open-new-task-form(OpenNewTaskFormParams);
|
||||
callback open-edit-task-form(int, int);
|
||||
callback open-new-event-form();
|
||||
callback open-edit-event-form(int, int);
|
||||
callback toggle-show-completed-tasks();
|
||||
callback delete-task-clicked(int, int);
|
||||
callback delete-event-clicked(int, int);
|
||||
|
||||
callback create-task(NewTaskData);
|
||||
callback save-task(SaveTaskData);
|
||||
callback create-event(NewEventParams);
|
||||
callback save-event(SaveEventParams);
|
||||
|
||||
callback add-source(AddSourceParam);
|
||||
callback modify-source(ModifySourceParam);
|
||||
callback delete-source(int);
|
||||
|
||||
// Utils
|
||||
pure callback format-date(Date) -> string;
|
||||
pure callback format-date-relative(Date) -> string;
|
||||
pure callback capitalize-string(string) -> string;
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
import { Backend, TaskData } from "Backend.slint";
|
||||
import { Button, VerticalBox, CheckBox, ScrollView, ComboBox } from "std-widgets.slint";
|
||||
import { TaskLine } from "./components/TaskLine.slint";
|
||||
import { EventGroup } from "./components/EventGroup.slint";
|
||||
import { Calendar } from "./components/Calendar.slint";
|
||||
import { VPopupIconMenu, VDatePicker, VTimePicker, VCheckBox, VButton, VTag, VText, VTextInput, Svg, Palette } from "@selenite";
|
||||
import { NewTaskData, SaveTaskData } from "Backend.slint";
|
||||
import { CreateTaskOrEvent } from "components/CreateTaskOrEvent.slint";
|
||||
|
||||
export component MainView inherits Rectangle {
|
||||
|
||||
background: Palette.background;
|
||||
private property<string> icon-visible: Svg.visible;
|
||||
private property<string> icon-not-visible: Svg.not-visible;
|
||||
private property<bool> completed-tasks-visible: false;
|
||||
|
||||
HorizontalLayout {
|
||||
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
padding: 16px;
|
||||
spacing: 16px;
|
||||
HorizontalLayout {
|
||||
horizontal-stretch: 1;
|
||||
alignment: start;
|
||||
spacing: 8px;
|
||||
VButton {
|
||||
text: "Show/Hide completed tasks";
|
||||
clicked => {
|
||||
Backend.toggle-show-completed-tasks();
|
||||
completed-tasks-visible = !completed-tasks-visible;
|
||||
}
|
||||
icon-svg: completed-tasks-visible ? icon-visible : icon-not-visible;
|
||||
icon-colorize: Palette.control-foreground;
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
background: Palette.background.brighter(0.2);
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
CreateTaskOrEvent {
|
||||
|
||||
}
|
||||
|
||||
Flickable {
|
||||
horizontal-stretch: 1;
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
spacing: 16px;
|
||||
if Backend.days.length == 0 && Backend.unscheduled-tasks.length == 0 : VText {
|
||||
text: "There is no task to show";
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
for day[dayIndex] in Backend.days: VerticalLayout {
|
||||
Rectangle {
|
||||
background: Palette.card-background;
|
||||
border-radius: 8px;
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
VText {
|
||||
text: Backend.format-date(day.date);
|
||||
color: day.isLate ? Palette.orange : Palette.foreground;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
VText {
|
||||
text: day.relativeDaysDiff == 0 ? " - today" :
|
||||
day.relativeDaysDiff == 1 ? " - tomorrow" :
|
||||
day.relativeDaysDiff == -1 ? " - yesterday" :
|
||||
day.relativeDaysDiff > 0 ? " - in \{day.relativeDaysDiff} days" :
|
||||
" - \{-day.relativeDaysDiff} days ago";
|
||||
color: Palette.foreground-hint;
|
||||
font-size: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
for event[eventIndex] in day.events: VerticalLayout {
|
||||
padding-top: 16px;
|
||||
EventGroup {
|
||||
event: event;
|
||||
}
|
||||
}
|
||||
for task[taskIndex] in day.tasks: VerticalLayout {
|
||||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
task: task;
|
||||
date: day.date;
|
||||
source-index: task.sourceId;
|
||||
task-index: task.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if Backend.unscheduled-tasks.length > 0 : VerticalLayout {
|
||||
Rectangle {
|
||||
background: Palette.card-background;
|
||||
border-radius: 8px;
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
VText {
|
||||
text: "Unscheduled";
|
||||
color: Palette.foreground;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
}
|
||||
for task[taskIndex] in Backend.unscheduled-tasks: VerticalLayout {
|
||||
padding-top: taskIndex == 0 ? 16px : 0px;
|
||||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
task: task;
|
||||
source-index: task.sourceId;
|
||||
task-index: task.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Calendar {
|
||||
init => { debug("cal len", Backend.calendar.length) }
|
||||
days: Backend.calendar;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue