mirai/external/mirai-core/src/task.cpp

77 lines
1.4 KiB
C++
Raw Normal View History

2024-10-11 16:26:13 +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 "task.h"
#include "data_provider.h"
2024-10-15 11:55:39 +02:00
#include "utils.h"
2024-10-11 16:26:13 +02:00
#include <optional>
#include <string>
namespace mirai
{
int task::id() const
2024-10-11 16:26:13 +02:00
{
return task_.id;
}
int task::source_id() const
2024-10-11 16:26:13 +02:00
{
return data_->id;
}
std::string task::title() const
2024-10-11 16:26:13 +02:00
{
return task_.title;
}
mirai::task_state task::state() const
2024-10-11 16:26:13 +02:00
{
return task_.state;
}
bool task::checked() const
2024-10-11 16:26:13 +02:00
{
return task_.state == mirai::DONE;
}
bool task::has_due_date() const
2024-10-15 11:55:39 +02:00
{
2025-06-29 20:07:11 +02:00
return task_.due_date.has_value();
2024-10-15 11:55:39 +02:00
}
std::optional<class date> task::due_date() const
{
2025-06-29 20:07:11 +02:00
if (!task_.due_date.has_value()) {
return std::nullopt;
}
return task_.due_date.value();
}
void task::set_title(const std::string &newTitle)
2024-10-11 16:26:13 +02:00
{
2025-06-27 10:55:56 +02:00
data_->update_task(id(), {.title = newTitle});
2024-10-11 16:26:13 +02:00
}
void task::set_date(const date &date)
2024-10-11 16:26:13 +02:00
{
auto emptyEventId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
2025-06-29 20:07:11 +02:00
data_->update_task(id(), {.due_date = date});
2024-10-15 11:55:39 +02:00
}
void task::unschedule()
{
auto emptyId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
2025-06-29 20:07:11 +02:00
data_->update_task(id(), {.due_date = std::nullopt});
2024-10-11 16:26:13 +02:00
}
void task::set_checked(bool checked)
2024-10-11 16:26:13 +02:00
{
2025-06-27 10:55:56 +02:00
data_->update_task(id(), {.state = checked ? DONE : TODO});
2024-10-11 16:26:13 +02:00
}
} // namespace mirai