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"
2024-10-15 11:55:39 +02:00
#include "DataProvider.h"
#include "utils.h"
2024-10-11 16:26:13 +02:00
#include <optional>
#include <string>
namespace mirai
{
int Task::id() const
{
return task_.id;
}
2025-06-29 20:07:11 +02:00
int Task::source_id() const
2024-10-11 16:26:13 +02:00
{
return data_->id;
}
std::string Task::title() const
{
return task_.title;
}
2025-06-27 10:55:56 +02:00
mirai::task_state Task::state() const
2024-10-11 16:26:13 +02:00
{
return task_.state;
}
bool Task::checked() const
{
return task_.state == mirai::DONE;
}
2025-06-29 20:07:11 +02:00
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
}
2025-06-29 20:07:11 +02:00
std::optional<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();
}
2025-06-29 20:07:11 +02:00
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
}
2025-06-29 20:07:11 +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
}
2025-06-29 20:07:11 +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