mirai/src/core/Mirai.cpp

75 lines
1.5 KiB
C++
Raw Normal View History

2024-04-13 11:52:42 +02:00
/*
2024-04-10 16:53:18 +02:00
* 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 "Mirai.h"
#include "TaskItem.h"
2024-04-12 20:58:13 +02:00
#include "cpp-utils/vector.h"
2024-04-10 16:53:18 +02:00
2024-04-13 11:52:42 +02:00
namespace mirai
{
2024-04-10 16:53:18 +02:00
2024-04-13 11:52:42 +02:00
void Mirai::loadFile(const std::string &path)
{
auto tasksFile = TodoMdFormat::readFile(path);
files->push_back(std::move(tasksFile));
tags.clear();
for (auto &task : (*files)[0].getTasks()) {
for (auto &tag : task->getTags()) {
if (!vectorUtils::contains(tags, tag)) {
tags.push_back(tag);
2024-04-10 16:53:18 +02:00
}
}
}
2024-04-13 11:52:42 +02:00
}
2024-04-10 16:53:18 +02:00
2024-04-13 11:52:42 +02:00
void Mirai::save()
{
for (auto &file : *files) {
TodoMdFormat::writeFile(file);
2024-04-10 16:53:18 +02:00
}
2024-04-13 11:52:42 +02:00
}
2024-04-10 16:53:18 +02:00
2024-04-13 11:52:42 +02:00
void Mirai::addTask(TaskItem taskItem)
{
(*files)[0].addTask(taskItem);
for (auto &view : views) {
view->update();
}
2024-04-13 11:52:42 +02:00
}
2024-04-13 11:52:42 +02:00
void Mirai::addTask(std::string text, std::string date)
{
/*std::time_t t = std::time(nullptr);*/
/*std::tm tm = *std::localtime(&t);*/
/*std::stringstream ssCreationDate;*/
/*ssCreationDate << std::put_time(&tm, "%Y-%m-%d");*/
(*files)[0].addTask(text, date);
for (auto &view : views) {
view->update();
2024-04-10 16:53:18 +02:00
}
2024-04-13 11:52:42 +02:00
}
2024-04-10 16:53:18 +02:00
2024-04-13 11:52:42 +02:00
void Mirai::removeTask(const TaskItem *taskItem)
{
(*files)[0].removeTask(taskItem);
for (auto &view : views) {
view->update();
2024-04-10 16:53:18 +02:00
}
2024-04-13 11:52:42 +02:00
}
2024-04-10 16:53:18 +02:00
2024-04-13 11:52:42 +02:00
std::weak_ptr<TasksView> Mirai::getTasks()
{
auto view = std::make_shared<TasksView>(files);
views.push_back(view);
return view;
}
2024-04-10 16:53:18 +02:00
2024-04-13 11:52:42 +02:00
const std::vector<std::string> &Mirai::getTags()
{
return tags;
2024-04-10 16:53:18 +02:00
}
2024-04-13 11:52:42 +02:00
} // namespace mirai