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
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* 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 "BaseSource.h"
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct BaseFileSourceConstructor {
|
||||
std::string name;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
class BaseFileSource : public BaseSource
|
||||
{
|
||||
public:
|
||||
BaseFileSource(BaseFileSourceConstructor data) : BaseSource(data.name), path(data.path) {};
|
||||
|
||||
BaseFileSource(BaseFileSource &) = delete;
|
||||
BaseFileSource(BaseFileSource &&) = delete;
|
||||
~BaseFileSource() override = default;
|
||||
|
||||
const std::string &getPath() const
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string path;
|
||||
};
|
||||
} // namespace mirai
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* 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 "DateTime.h"
|
||||
#include "Day.h"
|
||||
#include "Event.h"
|
||||
#include "TaskItem.h"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class BaseSource
|
||||
{
|
||||
|
||||
public:
|
||||
struct AddTaskData {
|
||||
std::string text;
|
||||
Tags tags;
|
||||
};
|
||||
|
||||
BaseSource(std::string name) : name_(name) {};
|
||||
BaseSource(BaseSource &) = delete;
|
||||
BaseSource(BaseSource &&) = delete;
|
||||
|
||||
virtual ~BaseSource() = default;
|
||||
virtual void save() = 0;
|
||||
virtual void load() = 0;
|
||||
|
||||
void setName(std::string name);
|
||||
const std::string &getName() const;
|
||||
|
||||
void addDay(const DayData &dayData);
|
||||
void addUnscheduledTask(const TaskItemData &taskData);
|
||||
Day *day(const Date &date);
|
||||
std::vector<std::unique_ptr<TaskItem>> *unscheduledTasks();
|
||||
std::vector<std::unique_ptr<Day>> *days();
|
||||
TaskItem *getTaskById(int taskId);
|
||||
Event *getEventById(int eventId);
|
||||
void deleteTask(const TaskItem &task);
|
||||
|
||||
void setDirty(bool shouldBeDirty);
|
||||
bool isDirty() const;
|
||||
|
||||
int id() const;
|
||||
|
||||
private:
|
||||
static int nextId_;
|
||||
int id_ = nextId_++;
|
||||
std::string name_;
|
||||
std::vector<std::unique_ptr<Day>> days_;
|
||||
std::vector<std::unique_ptr<TaskItem>> unscheduledTasks_;
|
||||
bool isDirty_ = false;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
|
@ -24,6 +24,8 @@ struct Date {
|
|||
bool operator==(const Date &other) const;
|
||||
bool operator<(const Date &other) const;
|
||||
bool operator>(const Date &other) const;
|
||||
bool operator>=(const Date &other) const;
|
||||
bool operator<=(const Date &other) const;
|
||||
|
||||
std::chrono::year_month_day toStdChrono() const
|
||||
{
|
||||
|
@ -34,6 +36,11 @@ struct Date {
|
|||
};
|
||||
}
|
||||
|
||||
int toIntRepresentation()
|
||||
{
|
||||
return day + month * 100 + year * 10000;
|
||||
}
|
||||
|
||||
int year;
|
||||
unsigned month;
|
||||
unsigned day;
|
||||
|
|
44
external/mirai-core/include/mirai-core/Day.h
vendored
44
external/mirai-core/include/mirai-core/Day.h
vendored
|
@ -6,49 +6,33 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "DateTime.h"
|
||||
#include "Event.h"
|
||||
#include "TaskItem.h"
|
||||
#include "using.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "SourceDataProvider.h"
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class BaseSource;
|
||||
|
||||
struct DayData {
|
||||
Date date;
|
||||
std::vector<EventData> events;
|
||||
std::vector<TaskItemData> tasks;
|
||||
};
|
||||
class Task;
|
||||
class Event;
|
||||
|
||||
class Day
|
||||
{
|
||||
|
||||
public:
|
||||
Day(BaseSource *source, const DayData &data);
|
||||
void setDate(const Date &date);
|
||||
Day(SourceDataProvider *data, DayData day) : data_(data), dayData_(day) {};
|
||||
|
||||
Event *createEvent(const EventData &eventData);
|
||||
TaskItem *createTask(const TaskItemData &taskData);
|
||||
void deleteTask(const TaskItem &taskToDelete);
|
||||
void deleteEvent(const Event &eventToDelete);
|
||||
std::vector<std::unique_ptr<Event>> *events();
|
||||
std::vector<std::unique_ptr<TaskItem>> *tasks();
|
||||
Date date() const;
|
||||
std::vector<Task> tasks();
|
||||
std::vector<Event> events();
|
||||
|
||||
const Date &getDate() const;
|
||||
void mergeDay(const Day &otherDay);
|
||||
|
||||
Event *getEventById(int eventId);
|
||||
BaseSource *source();
|
||||
int id() const;
|
||||
int sourceId() const;
|
||||
|
||||
private:
|
||||
void onChange();
|
||||
|
||||
BaseSource *source_;
|
||||
std::vector<std::unique_ptr<Event>> events_;
|
||||
std::vector<std::unique_ptr<TaskItem>> tasks_;
|
||||
DayData data_;
|
||||
DayData dayData_;
|
||||
SourceDataProvider *data_;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
||||
|
|
56
external/mirai-core/include/mirai-core/Event.h
vendored
56
external/mirai-core/include/mirai-core/Event.h
vendored
|
@ -6,63 +6,39 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "DateTime.h"
|
||||
#include "TaskItem.h"
|
||||
#include "using.h"
|
||||
#include <memory>
|
||||
#include "Day.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class BaseSource;
|
||||
|
||||
struct EventData {
|
||||
std::string description;
|
||||
Date date;
|
||||
Time startTime;
|
||||
Time endTime;
|
||||
Tags tags;
|
||||
std::vector<TaskItemData> tasks;
|
||||
};
|
||||
|
||||
class Day;
|
||||
class Task;
|
||||
|
||||
class Event
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
Event(BaseSource *source, Day *parent, const EventData &data);
|
||||
Event(SourceDataProvider *data, EventData eventData) : data_(data), eventData_(eventData) {};
|
||||
|
||||
Event &operator=(const EventData &newData);
|
||||
std::string title() const;
|
||||
Time startsAt() const;
|
||||
Time endsAt() const;
|
||||
|
||||
void setText(const std::string &text);
|
||||
std::vector<Task> queryTasks() const;
|
||||
|
||||
void setTitle(const std::string &newTitle);
|
||||
void setDay(const Day &day);
|
||||
void setStartTime(const Time &time);
|
||||
void setEndTime(const Time &time);
|
||||
|
||||
TaskItem *createTask(const TaskItemData &taskData);
|
||||
void deleteTask(const TaskItem &taskToDelete);
|
||||
std::vector<std::unique_ptr<TaskItem>> *tasks();
|
||||
|
||||
const std::string &getText() const;
|
||||
const Date &getDate() const;
|
||||
const Time &getStartTime() const;
|
||||
const Time &getEndTime() const;
|
||||
const Tags &getTags() const;
|
||||
bool hasTag(const std::string &tag) const;
|
||||
|
||||
int id() const;
|
||||
Day *day();
|
||||
int sourceId() const;
|
||||
|
||||
private:
|
||||
void onChange();
|
||||
|
||||
static int nextId;
|
||||
int id_ = nextId++;
|
||||
Day *day_;
|
||||
EventData data;
|
||||
std::vector<std::unique_ptr<TaskItem>> tasks_;
|
||||
BaseSource *source_;
|
||||
EventData eventData_;
|
||||
SourceDataProvider *data_;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
||||
|
|
76
external/mirai-core/include/mirai-core/MarkdownDataProvider.h
vendored
Normal file
76
external/mirai-core/include/mirai-core/MarkdownDataProvider.h
vendored
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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 "DateTime.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <optional>
|
||||
#include <ranges>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct MarkdownData {
|
||||
std::string name;
|
||||
std::vector<TaskData> tasks;
|
||||
std::vector<DayData> days;
|
||||
std::vector<EventData> events;
|
||||
};
|
||||
|
||||
class MarkdownDataProvider : public SourceDataProvider
|
||||
{
|
||||
public:
|
||||
MarkdownDataProvider(const std::string &filePath) : filePath_(filePath), SourceDataProvider()
|
||||
{
|
||||
}
|
||||
|
||||
std::string toMarkdown();
|
||||
MarkdownData parseMarkdown(const std::string &content);
|
||||
|
||||
void save() override;
|
||||
void load() override;
|
||||
|
||||
std::string name() const override;
|
||||
|
||||
// Tasks
|
||||
TaskData insertTask(const TaskData &task) override;
|
||||
void removeTaskById(int taskId) override;
|
||||
std::optional<TaskData> getTaskById(int taskId) override;
|
||||
std::vector<TaskData> getTasksByEventId(int eventId) override;
|
||||
std::vector<TaskData> getTasksByDayId(int dayId) override;
|
||||
std::vector<TaskData> getTasksByDate(Date date) override;
|
||||
std::vector<TaskData> getTasksWithoutDate() override;
|
||||
std::vector<TaskData> getTasks() override;
|
||||
void updateTask(int taskId, UpdatableTaskData updateData) override;
|
||||
|
||||
// Events
|
||||
EventData insertEvent(const EventData &task) override;
|
||||
void removeEventById(int eventId) override;
|
||||
std::optional<EventData> getEventById(int eventId) override;
|
||||
std::vector<EventData> getEvents() override;
|
||||
std::vector<EventData> getEventsByDate(Date date) override;
|
||||
void updateEvent(int eventId, UpdatableEventData updateData) override;
|
||||
|
||||
// Days
|
||||
DayData insertDay(const DayData &day) override;
|
||||
void removeDayById(int dayId) override;
|
||||
std::vector<DayData> getDays() override;
|
||||
std::optional<DayData> getDayByDate(const Date &date) override;
|
||||
void updateDay(int dayId, UpdatableDayData updateData) override;
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::string filePath_;
|
||||
MarkdownData data;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
23
external/mirai-core/include/mirai-core/Mirai.h
vendored
23
external/mirai-core/include/mirai-core/Mirai.h
vendored
|
@ -6,13 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "BaseFileSource.h"
|
||||
#include "BaseSource.h"
|
||||
#include "TaskItem.h"
|
||||
#include "TodoMd.h"
|
||||
#include <algorithm>
|
||||
#include "Source.h"
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
@ -24,22 +19,20 @@ class Mirai
|
|||
{
|
||||
|
||||
public:
|
||||
void loadSource(std::unique_ptr<BaseSource> &&resource);
|
||||
void loadSource(std::unique_ptr<SourceDataProvider> &&resource);
|
||||
void unloadAllSources();
|
||||
void save();
|
||||
void deleteTask(const TaskItem &taskItem);
|
||||
std::optional<std::reference_wrapper<BaseSource>> getSourceByName(const std::string &name);
|
||||
std::optional<std::reference_wrapper<SourceDataProvider>>
|
||||
getSourceByName(const std::string &name);
|
||||
|
||||
std::vector<std::unique_ptr<BaseSource>> &getSources();
|
||||
std::vector<std::unique_ptr<Source>> &getSources();
|
||||
const std::vector<std::string> &getTags();
|
||||
|
||||
void reloadTags();
|
||||
|
||||
// Returns a non owning pointer to the requested resource or nullptr if not found.
|
||||
BaseSource *getSourceById(int id);
|
||||
Source *getSourceById(int id);
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<BaseSource>> sources_;
|
||||
std::vector<std::string> tags_;
|
||||
std::vector<std::unique_ptr<Source>> sources_;
|
||||
// std::vector<std::string> tags_;
|
||||
};
|
||||
} // namespace mirai
|
||||
|
|
89
external/mirai-core/include/mirai-core/Source.h
vendored
Normal file
89
external/mirai-core/include/mirai-core/Source.h
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* 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 "DateTime.h"
|
||||
#include "Day.h"
|
||||
#include "Event.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include "Task.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct createTaskParams {
|
||||
std::string title;
|
||||
std::optional<Event> event;
|
||||
std::optional<Date> date;
|
||||
};
|
||||
|
||||
struct createEventParams {
|
||||
std::string title;
|
||||
Date date;
|
||||
Time startsAt;
|
||||
Time endsAt;
|
||||
};
|
||||
|
||||
struct SourceConstructor {
|
||||
SourceDataProvider *sourceDataProvider;
|
||||
};
|
||||
|
||||
class Source
|
||||
{
|
||||
public:
|
||||
Source(SourceConstructor params) : data(params.sourceDataProvider)
|
||||
{
|
||||
}
|
||||
|
||||
Source(Source &) = delete;
|
||||
Source(Source &&) = delete;
|
||||
Source operator=(Source &) = delete;
|
||||
Source operator=(Source &&) = delete;
|
||||
|
||||
~Source() = default;
|
||||
|
||||
void init();
|
||||
void save();
|
||||
void load();
|
||||
|
||||
std::string name() const;
|
||||
|
||||
void createTask(const createTaskParams &task);
|
||||
void removeTask(const Task &task);
|
||||
std::optional<Task> getTaskById(int taskId);
|
||||
std::vector<Task> getTasksByDate(Date date);
|
||||
std::vector<Task> getUnscheduledTasks();
|
||||
std::vector<Task> getTasks();
|
||||
|
||||
void createEvent(const createEventParams &eventToCreate);
|
||||
void removeEvent(const Event &event);
|
||||
std::vector<Event> getEvents();
|
||||
std::optional<Event> getEventById(int eventId);
|
||||
std::vector<Event> getEventsByDate(Date date);
|
||||
|
||||
std::vector<Day> getDays();
|
||||
std::optional<Day> getDayByDate(Date date);
|
||||
|
||||
const int id = Source::generateNextId();
|
||||
|
||||
bool isDirty() const
|
||||
{
|
||||
return data->isDirty();
|
||||
};
|
||||
|
||||
private:
|
||||
static int generateNextId()
|
||||
{
|
||||
static int nextId = 0;
|
||||
return nextId++;
|
||||
}
|
||||
|
||||
SourceDataProvider *data;
|
||||
};
|
||||
} // namespace mirai
|
120
external/mirai-core/include/mirai-core/SourceDataProvider.h
vendored
Normal file
120
external/mirai-core/include/mirai-core/SourceDataProvider.h
vendored
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* 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 "DateTime.h"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct DayData {
|
||||
int id;
|
||||
Date date;
|
||||
};
|
||||
|
||||
struct UpdatableDayData {
|
||||
std::optional<Date> date;
|
||||
};
|
||||
|
||||
enum TaskState { TODO, DONE };
|
||||
|
||||
struct TaskData {
|
||||
int id;
|
||||
std::string title;
|
||||
TaskState state;
|
||||
std::optional<int> dayId;
|
||||
std::optional<int> eventId;
|
||||
};
|
||||
|
||||
struct UpdatableTaskData {
|
||||
std::optional<std::string> title = std::nullopt;
|
||||
std::optional<TaskState> state = std::nullopt;
|
||||
std::optional<std::optional<int>> dayId = std::nullopt;
|
||||
std::optional<std::optional<int>> eventId = std::nullopt;
|
||||
};
|
||||
|
||||
struct EventData {
|
||||
int id;
|
||||
int dayId;
|
||||
std::string title;
|
||||
Time startsAt;
|
||||
Time endsAt;
|
||||
};
|
||||
|
||||
struct UpdatableEventData {
|
||||
std::optional<int> dayId;
|
||||
std::optional<std::string> title;
|
||||
std::optional<Time> startsAt;
|
||||
std::optional<Time> endsAt;
|
||||
};
|
||||
|
||||
class SourceDataProvider
|
||||
{
|
||||
|
||||
public:
|
||||
SourceDataProvider() {};
|
||||
SourceDataProvider(SourceDataProvider &) = delete;
|
||||
SourceDataProvider(SourceDataProvider &&) = delete;
|
||||
|
||||
virtual ~SourceDataProvider() = default;
|
||||
virtual void save() = 0;
|
||||
virtual void load() = 0;
|
||||
|
||||
virtual std::string name() const = 0;
|
||||
|
||||
// Tasks
|
||||
virtual TaskData insertTask(const TaskData &task) = 0;
|
||||
virtual void removeTaskById(int taskId) = 0;
|
||||
virtual std::optional<TaskData> getTaskById(int taskId) = 0;
|
||||
virtual std::vector<TaskData> getTasksByEventId(int eventId) = 0;
|
||||
virtual std::vector<TaskData> getTasksByDayId(int dayId) = 0;
|
||||
virtual std::vector<TaskData> getTasksByDate(Date date) = 0;
|
||||
virtual std::vector<TaskData> getTasksWithoutDate() = 0;
|
||||
virtual std::vector<TaskData> getTasks() = 0;
|
||||
virtual void updateTask(int taskId, UpdatableTaskData updateData) = 0;
|
||||
|
||||
// Events
|
||||
virtual EventData insertEvent(const EventData &task) = 0;
|
||||
virtual void removeEventById(int eventId) = 0;
|
||||
virtual std::optional<EventData> getEventById(int eventId) = 0;
|
||||
virtual std::vector<EventData> getEvents() = 0;
|
||||
virtual std::vector<EventData> getEventsByDate(Date date) = 0;
|
||||
virtual void updateEvent(int eventId, UpdatableEventData updateData) = 0;
|
||||
|
||||
// Days
|
||||
virtual DayData insertDay(const DayData &day) = 0;
|
||||
virtual void removeDayById(int dayId) = 0;
|
||||
virtual std::vector<DayData> getDays() = 0;
|
||||
virtual std::optional<DayData> getDayByDate(const Date &date) = 0;
|
||||
virtual void updateDay(int dayId, UpdatableDayData updateData) = 0;
|
||||
|
||||
const int id = SourceDataProvider::generateNextId();
|
||||
|
||||
void setDirty(bool dirty)
|
||||
{
|
||||
isDirty_ = dirty;
|
||||
};
|
||||
|
||||
bool isDirty() const
|
||||
{
|
||||
return isDirty_;
|
||||
};
|
||||
|
||||
private:
|
||||
bool isDirty_ = false;
|
||||
|
||||
static int generateNextId()
|
||||
{
|
||||
static int nextId = 0;
|
||||
return nextId++;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mirai
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* 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 "BaseFileSource.h"
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class StdFileSource : public BaseFileSource
|
||||
{
|
||||
public:
|
||||
StdFileSource(BaseFileSourceConstructor data) : BaseFileSource(data) {};
|
||||
StdFileSource(StdFileSource &) = delete;
|
||||
StdFileSource(StdFileSource &&) = delete;
|
||||
StdFileSource operator=(StdFileSource &) = delete;
|
||||
StdFileSource operator=(StdFileSource &&) = delete;
|
||||
|
||||
~StdFileSource() override = default;
|
||||
|
||||
void save() override;
|
||||
void load() override;
|
||||
;
|
||||
};
|
||||
} // namespace mirai
|
41
external/mirai-core/include/mirai-core/Task.h
vendored
Normal file
41
external/mirai-core/include/mirai-core/Task.h
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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 "Event.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class Day;
|
||||
|
||||
class Task
|
||||
{
|
||||
|
||||
public:
|
||||
Task(SourceDataProvider *data, TaskData task) : data_(data), task_(task) {};
|
||||
|
||||
std::string title() const;
|
||||
mirai::TaskState state() const;
|
||||
bool checked() const;
|
||||
|
||||
void setTitle(const std::string &newTitle);
|
||||
void setDay(const Day &day);
|
||||
void setEvent(const Event &event);
|
||||
void setChecked(bool checked);
|
||||
|
||||
int id() const;
|
||||
int sourceId() const;
|
||||
|
||||
private:
|
||||
TaskData task_;
|
||||
SourceDataProvider *data_;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* 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 "using.h"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class BaseSource;
|
||||
class Day;
|
||||
|
||||
enum TaskItemState { TODO, DONE };
|
||||
|
||||
struct TaskItemData {
|
||||
std::string text;
|
||||
TaskItemState state;
|
||||
Tags tags;
|
||||
};
|
||||
|
||||
class TaskItem
|
||||
{
|
||||
public:
|
||||
TaskItem(BaseSource *source, Day *day, const TaskItemData data);
|
||||
|
||||
TaskItem &operator=(const TaskItemData &newData);
|
||||
|
||||
void markAsDone();
|
||||
void markAsUndone();
|
||||
void setDate(const std::string &date);
|
||||
void setText(const std::string &text);
|
||||
|
||||
const std::string &getLine() const;
|
||||
const std::string &getText() const;
|
||||
const TaskItemState &getState() const;
|
||||
const Tags &getTags() const;
|
||||
bool hasTag(const std::string &tag) const;
|
||||
|
||||
int id() const;
|
||||
BaseSource *source();
|
||||
Day *day();
|
||||
|
||||
private:
|
||||
void onChange();
|
||||
|
||||
static int nextId;
|
||||
int id_ = nextId++;
|
||||
TaskItemData data;
|
||||
|
||||
BaseSource *source_;
|
||||
Day *day_;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* 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.h"
|
||||
#include "TaskItem.h"
|
||||
#include "using.h"
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct FilteredEvent {
|
||||
Event *event;
|
||||
std::vector<TaskItem *> filteredTasks;
|
||||
};
|
||||
|
||||
struct FilteredDay {
|
||||
Day *day;
|
||||
std::vector<FilteredEvent> filteredEvents;
|
||||
std::vector<TaskItem *> filteredTasks;
|
||||
};
|
||||
|
||||
class TasksView
|
||||
{
|
||||
|
||||
public:
|
||||
TasksView(Mirai *mirai);
|
||||
|
||||
FilteredDay &operator[](int index);
|
||||
std::vector<TaskItem *> &filteredUnscheduledTasks();
|
||||
|
||||
size_t count() const;
|
||||
void update();
|
||||
void addTagFilter(const std::string &tag);
|
||||
void removeTagFilter(const std::string &tag);
|
||||
void addSourceFilter(const std::string &fileName);
|
||||
void removeSourceFilter(const std::string &fileName);
|
||||
void removeFilters();
|
||||
const Tags &getActiveTagsFilter();
|
||||
const std::vector<std::string> &getActiveFilesFilter();
|
||||
bool isSourceFilterActive(const std::string &sourceName);
|
||||
|
||||
void hideCompletedTasks(bool hide);
|
||||
bool shouldHideCompletedTasks() const;
|
||||
|
||||
private:
|
||||
std::vector<FilteredDay> filteredDays;
|
||||
std::vector<TaskItem *> filteredUnscheduledTasks_;
|
||||
|
||||
Mirai *mirai;
|
||||
Tags tagsFilter;
|
||||
std::vector<std::string> resourcesFilter;
|
||||
bool shouldHideCompletedTasks_ = true;
|
||||
};
|
||||
} // namespace mirai
|
46
external/mirai-core/include/mirai-core/TodoMd.h
vendored
46
external/mirai-core/include/mirai-core/TodoMd.h
vendored
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* 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 "BaseSource.h"
|
||||
#include "DateTime.h"
|
||||
#include "Day.h"
|
||||
#include "Event.h"
|
||||
#include "TaskItem.h"
|
||||
#include <format>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct MiraiMarkdownFormatParseResult {
|
||||
std::string name;
|
||||
std::vector<DayData> days;
|
||||
std::vector<TaskItemData> unscheduledTasks;
|
||||
};
|
||||
|
||||
class TodoMdFormat
|
||||
{
|
||||
public:
|
||||
static std::string stringify(BaseSource &source);
|
||||
|
||||
static MiraiMarkdownFormatParseResult parse(const std::string &content);
|
||||
|
||||
static std::string taskToString(const TaskItem &task);
|
||||
static TaskItemData stringToTask(const std::string &str, const std::string &date);
|
||||
static EventData stringToEvent(const std::string &str, const std::string &date);
|
||||
|
||||
private:
|
||||
static std::string fieldWithSpace(const std::string &field);
|
||||
static TaskItem parseLine(const std::string &line);
|
||||
static Tags extractTagsFromMetadata(std::string metadata);
|
||||
};
|
||||
} // namespace mirai
|
91
external/mirai-core/include/mirai-core/TodoTxt.h
vendored
91
external/mirai-core/include/mirai-core/TodoTxt.h
vendored
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* 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 "TaskItem.h"*/
|
||||
/*#include "utils.h"*/
|
||||
/*#include <fstream>*/
|
||||
/*#include <iostream>*/
|
||||
/*#include <iterator>*/
|
||||
/*#include <memory>*/
|
||||
/*#include <regex>*/
|
||||
/*#include <stdexcept>*/
|
||||
/*#include <string>*/
|
||||
/*#include <vector>*/
|
||||
|
||||
/*namespace mirai {*/
|
||||
|
||||
/*class TodoTxtFormat {*/
|
||||
/*public:*/
|
||||
|
||||
/*static TaskList readFile() {*/
|
||||
/*std::ifstream file("../newqml/todo.txt");*/
|
||||
/*if (!file.is_open()) {*/
|
||||
/*throw std::runtime_error("todo.txt file not found");*/
|
||||
/*}*/
|
||||
/*std::vector<TaskItem> taskItems;*/
|
||||
/*std::string line;*/
|
||||
/*while (std::getline(file, line)) {*/
|
||||
/*auto taskItem = parseLine(line);*/
|
||||
/*taskItems.push_back(taskItem);*/
|
||||
/*}*/
|
||||
/*file.close();*/
|
||||
/*TaskList tasks({*/
|
||||
/*.tasks = taskItems*/
|
||||
/*});*/
|
||||
/*return tasks;*/
|
||||
/*}*/
|
||||
|
||||
/*static void writeFile(TaskList& tasks) {*/
|
||||
/*std::ofstream file("../newqml/todo.txt");*/
|
||||
/*if (!file.is_open()) {*/
|
||||
/*throw std::runtime_error("can't create todo.txt");*/
|
||||
/*}*/
|
||||
/*for (const auto& task : tasks.getTasks()) {*/
|
||||
/*file << fieldWithSpace(task->state == DONE ? "x" : task->priority);*/
|
||||
/*file << fieldWithSpace(task->state == DONE ? task->getDate() : "");*/
|
||||
/*file << fieldWithSpace(task->getCreationDate());*/
|
||||
/*file << task->getText() << '\n';*/
|
||||
/*}*/
|
||||
/*file.close();*/
|
||||
/*}*/
|
||||
|
||||
/*private:*/
|
||||
|
||||
/*static std::string fieldWithSpace(const std::string& field) {*/
|
||||
/*if (field.length() == 0)*/
|
||||
/*return "";*/
|
||||
/*return (field + " ");*/
|
||||
/*}*/
|
||||
|
||||
/*static TaskItem parseLine(const std::string& line) {*/
|
||||
/*std::smatch matches;*/
|
||||
/*std::regex regex("(^x )?(\\([A-Z]\\) )?([0-9]{4}-[0-9]{2}-[0-9]{2} )?([0-9]{4}-[0-9]{2}-[0-9]{2}
|
||||
* )?(.*)");*/
|
||||
/*std::regex_match(line, matches, regex);*/
|
||||
|
||||
/*for (size_t i = 0; i < matches.size(); ++i) {*/
|
||||
/*std::ssub_match sub_match = matches[i];*/
|
||||
/*std::string piece = sub_match.str();*/
|
||||
/*}*/
|
||||
|
||||
/*const TaskItemState taskState = trim_copy(matches[1].str()) == "x" ? DONE : TODO;*/
|
||||
/*const std::string priority = trim_copy(matches[2].str());*/
|
||||
/*const std::string firstDate = trim_copy(matches[3].str());*/
|
||||
/*const std::string secondDate = trim_copy(matches[4].str());*/
|
||||
/*const std::string text = trim_copy(matches[5].str());*/
|
||||
|
||||
/*const std::string date = taskState == DONE ? firstDate : "";*/
|
||||
|
||||
/*return {*/
|
||||
/*.text = text,*/
|
||||
/*.state = taskState,*/
|
||||
/*.date = date,*/
|
||||
/*};*/
|
||||
/*}*/
|
||||
/*};*/
|
||||
/*}*/
|
58
external/mirai-core/include/mirai-core/View.h
vendored
Normal file
58
external/mirai-core/include/mirai-core/View.h
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.h"
|
||||
#include "Task.h"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct DateView {
|
||||
std::vector<Task> tasks;
|
||||
std::vector<Event> events;
|
||||
};
|
||||
|
||||
class View
|
||||
{
|
||||
|
||||
public:
|
||||
View(Mirai *mirai);
|
||||
|
||||
void hideCompletedTasks(bool hide);
|
||||
bool shouldHideCompletedTasks() const;
|
||||
|
||||
std::vector<Date> getDates();
|
||||
|
||||
std::vector<Task> getTasksForDate(const Date &date);
|
||||
std::vector<Event> getEventsForDate(const Date &date);
|
||||
std::vector<Task> getUnscheduledTasks();
|
||||
|
||||
void update();
|
||||
|
||||
void removeSources();
|
||||
void addSource(const Source &source);
|
||||
void setSources(const std::vector<Source> &sources);
|
||||
void setAllSources();
|
||||
bool isSourceSelected(const Source &source) const;
|
||||
|
||||
size_t activeSourceCount() const;
|
||||
|
||||
private:
|
||||
Mirai *mirai_;
|
||||
std::vector<int> sourcesIds_;
|
||||
std::vector<Task> unscheduledTasks_;
|
||||
std::map<Date, DateView> dates;
|
||||
|
||||
bool shouldHideCompletedTasks_ = true;
|
||||
};
|
||||
} // namespace mirai
|
34
external/mirai-core/include/mirai-core/utils.h
vendored
34
external/mirai-core/include/mirai-core/utils.h
vendored
|
@ -6,12 +6,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cpp-utils/string.h>
|
||||
#include <cpp-utils/vector.h>
|
||||
#include <locale>
|
||||
#include <regex>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
@ -19,4 +18,33 @@ namespace stringUtils = cpputils::string;
|
|||
namespace vectorUtils = cpputils::vector;
|
||||
|
||||
bool isDate(const std::string &dateStr);
|
||||
|
||||
template <typename T, typename F> T *ptrFindFirst(std::vector<T> &container, F f)
|
||||
{
|
||||
auto element = std::ranges::find_if(container, f);
|
||||
if (element == container.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &(*element);
|
||||
}
|
||||
|
||||
// TODO use ref for container first arg
|
||||
template <typename T, typename F> std::optional<T> findFirst(std::vector<T> container, F f)
|
||||
{
|
||||
auto element = std::ranges::find_if(container, f);
|
||||
if (element == container.end()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return *element;
|
||||
}
|
||||
|
||||
template <typename T, typename F> std::vector<T> findAll(std::vector<T> container, F f)
|
||||
{
|
||||
std::vector<T> result;
|
||||
std::ranges::copy_if(container, std::back_inserter(result), f);
|
||||
return result;
|
||||
}
|
||||
|
||||
int generateUniqueId();
|
||||
|
||||
} // namespace mirai
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue