mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 10:13:42 +00:00
Rework mirai core
This commit is contained in:
parent
f885d355cd
commit
36a2fe9220
62 changed files with 27689 additions and 765 deletions
67
external/mirai-core/src/Mirai.cpp
vendored
67
external/mirai-core/src/Mirai.cpp
vendored
|
@ -6,7 +6,8 @@
|
|||
|
||||
#include "Mirai.h"
|
||||
#include "Config.h"
|
||||
#include "TaskItem.h"
|
||||
#include "Source.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include "cpp-utils/debug.h"
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
|
@ -19,11 +20,13 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
void Mirai::loadSource(std::unique_ptr<BaseSource> &&resource)
|
||||
void Mirai::loadSource(std::unique_ptr<SourceDataProvider> &&resource)
|
||||
{
|
||||
resource->load();
|
||||
sources_.push_back(std::move(resource));
|
||||
reloadTags();
|
||||
SourceDataProvider *sourceDataProvider = resource.release();
|
||||
sourceDataProvider->load();
|
||||
sources_.push_back(
|
||||
std::make_unique<Source>(SourceConstructor{.sourceDataProvider = sourceDataProvider})
|
||||
);
|
||||
};
|
||||
|
||||
void Mirai::unloadAllSources()
|
||||
|
@ -33,63 +36,19 @@ void Mirai::unloadAllSources()
|
|||
|
||||
void Mirai::save()
|
||||
{
|
||||
for (auto &resource : sources_) {
|
||||
if (resource->isDirty()) {
|
||||
resource->save();
|
||||
resource->setDirty(false);
|
||||
for (auto &source : sources_) {
|
||||
if (source->isDirty()) {
|
||||
source->save();
|
||||
}
|
||||
}
|
||||
reloadTags();
|
||||
}
|
||||
|
||||
void Mirai::deleteTask(const TaskItem &taskItem)
|
||||
{
|
||||
for (auto &resource : sources_) {
|
||||
resource->deleteTask(taskItem);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<BaseSource>> &Mirai::getSources()
|
||||
std::vector<std::unique_ptr<Source>> &Mirai::getSources()
|
||||
{
|
||||
return sources_;
|
||||
}
|
||||
|
||||
std::optional<std::reference_wrapper<BaseSource>> Mirai::getSourceByName(const std::string &name)
|
||||
{
|
||||
auto resourceIterator =
|
||||
std::ranges::find_if(sources_, [&](const std::unique_ptr<BaseSource> &resource) {
|
||||
return resource->getName() == name;
|
||||
});
|
||||
|
||||
if (resourceIterator == sources_.end()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return *(resourceIterator->get());
|
||||
}
|
||||
|
||||
const std::vector<std::string> &Mirai::getTags()
|
||||
{
|
||||
return tags_;
|
||||
}
|
||||
|
||||
void Mirai::reloadTags()
|
||||
{
|
||||
// TODO TAGS
|
||||
/*cpputils::debug::Timer reloadingTagsDuration;*/
|
||||
/*tags.clear();*/
|
||||
/*for (auto &resource : resources) {*/
|
||||
/*for (auto &task : resource->getTasks()) {*/
|
||||
/*for (auto &tag : task->getTags()) {*/
|
||||
/*if (!vectorUtils::contains(tags, tag)) {*/
|
||||
/*tags.push_back(tag);*/
|
||||
/*}*/
|
||||
/*}*/
|
||||
/*}*/
|
||||
/*}*/
|
||||
/*reloadingTagsDuration.printTimeElapsed("ReloadingTags");*/
|
||||
}
|
||||
|
||||
BaseSource *Mirai::getSourceById(int id)
|
||||
Source *Mirai::getSourceById(int id)
|
||||
{
|
||||
if (id >= sources_.size()) {
|
||||
return nullptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue