mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 10:13:42 +00:00
Remove unused code, move logic from .h to their .cpp, clean some things
This commit is contained in:
parent
924e35ecc4
commit
cb6c663833
41 changed files with 492 additions and 978 deletions
|
@ -4,29 +4,27 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef MIRAI_BASE_FILE_RESOURCE_H
|
||||
#define MIRAI_BASE_FILE_RESOURCE_H
|
||||
#pragma once
|
||||
|
||||
#include "BaseResource.h"
|
||||
#include "BaseSource.h"
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct BaseFileResourceConstructor {
|
||||
struct BaseFileSourceConstructor {
|
||||
std::string name;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
class BaseFileResource : public BaseResource
|
||||
class BaseFileSource : public BaseSource
|
||||
{
|
||||
public:
|
||||
BaseFileResource(BaseFileResourceConstructor data)
|
||||
: BaseResource(data.name), path(data.path) {};
|
||||
BaseFileSource(BaseFileSourceConstructor data) : BaseSource(data.name), path(data.path) {};
|
||||
|
||||
BaseFileResource(BaseFileResource &) = delete;
|
||||
BaseFileResource(BaseFileResource &&) = delete;
|
||||
~BaseFileResource() override = default;
|
||||
BaseFileSource(BaseFileSource &) = delete;
|
||||
BaseFileSource(BaseFileSource &&) = delete;
|
||||
~BaseFileSource() override = default;
|
||||
|
||||
const std::string &getPath() const
|
||||
{
|
||||
|
@ -37,4 +35,3 @@ class BaseFileResource : public BaseResource
|
|||
std::string path;
|
||||
};
|
||||
} // namespace mirai
|
||||
#endif
|
|
@ -4,8 +4,7 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef MIRAI_BASE_RESOURCE_H
|
||||
#define MIRAI_BASE_RESOURCE_H
|
||||
#pragma once
|
||||
|
||||
#include "DateTime.h"
|
||||
#include "Day.h"
|
||||
|
@ -19,7 +18,7 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
class BaseResource
|
||||
class BaseSource
|
||||
{
|
||||
|
||||
public:
|
||||
|
@ -28,23 +27,16 @@ class BaseResource
|
|||
Tags tags;
|
||||
};
|
||||
|
||||
BaseResource(std::string name) : name_(name) {};
|
||||
BaseResource(BaseResource &) = delete;
|
||||
BaseResource(BaseResource &&) = delete;
|
||||
BaseSource(std::string name) : name_(name) {};
|
||||
BaseSource(BaseSource &) = delete;
|
||||
BaseSource(BaseSource &&) = delete;
|
||||
|
||||
virtual ~BaseResource() = default;
|
||||
virtual ~BaseSource() = default;
|
||||
virtual void save() = 0;
|
||||
virtual void load() = 0;
|
||||
|
||||
void setName(std::string name)
|
||||
{
|
||||
this->name_ = name;
|
||||
}
|
||||
|
||||
const std::string &getName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
void setName(std::string name);
|
||||
const std::string &getName() const;
|
||||
|
||||
void addDay(const DayData &dayData);
|
||||
Day *day(const Date &date);
|
||||
|
@ -56,10 +48,7 @@ class BaseResource
|
|||
void setDirty(bool shouldBeDirty);
|
||||
bool isDirty() const;
|
||||
|
||||
int id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
int id() const;
|
||||
|
||||
private:
|
||||
static int nextId_;
|
||||
|
@ -70,4 +59,3 @@ class BaseResource
|
|||
};
|
||||
|
||||
} // namespace mirai
|
||||
#endif
|
|
@ -16,78 +16,28 @@ namespace mirai
|
|||
{
|
||||
|
||||
struct Date {
|
||||
explicit Date(int year, unsigned month, unsigned day) : year(year), month(month), day(day)
|
||||
{
|
||||
}
|
||||
explicit Date(int year, unsigned month, unsigned day);
|
||||
|
||||
explicit Date(std::chrono::time_point<std::chrono::system_clock> tp)
|
||||
{
|
||||
auto chronoDate = std::chrono::year_month_day(std::chrono::floor<std::chrono::days>(tp));
|
||||
year = static_cast<int>(chronoDate.year());
|
||||
month = static_cast<unsigned>(chronoDate.month());
|
||||
day = static_cast<unsigned>(chronoDate.day());
|
||||
}
|
||||
explicit Date(std::chrono::time_point<std::chrono::system_clock> tp);
|
||||
explicit Date(std::chrono::year_month_day chronoDate);
|
||||
|
||||
explicit Date(std::chrono::year_month_day chronoDate)
|
||||
{
|
||||
year = static_cast<int>(chronoDate.year());
|
||||
month = static_cast<unsigned>(chronoDate.month());
|
||||
day = static_cast<unsigned>(chronoDate.day());
|
||||
}
|
||||
bool operator==(const Date &other) const;
|
||||
bool operator<(const Date &other) const;
|
||||
bool operator>(const Date &other) const;
|
||||
|
||||
int year;
|
||||
unsigned month;
|
||||
unsigned day;
|
||||
|
||||
bool operator==(const Date &other) const
|
||||
{
|
||||
return other.year == year && other.month == month && other.day == day;
|
||||
}
|
||||
|
||||
bool operator<(const Date &other) const
|
||||
{
|
||||
if (year < other.year) {
|
||||
return true;
|
||||
}
|
||||
if (year == other.year && month < other.month) {
|
||||
return true;
|
||||
}
|
||||
if (year == other.year && month == other.month && day < other.day) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator>(const Date &other) const
|
||||
{
|
||||
return !(*this < other) && !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
struct Time {
|
||||
|
||||
bool operator==(const Time &other) const;
|
||||
bool operator<(const Time &other) const;
|
||||
bool operator>(const Time &other) const;
|
||||
|
||||
int hour;
|
||||
int minute;
|
||||
|
||||
bool operator==(const Time &other) const
|
||||
{
|
||||
return other.hour == hour && other.minute == minute;
|
||||
}
|
||||
|
||||
bool operator<(const Time &other) const
|
||||
{
|
||||
if (hour < other.hour) {
|
||||
return true;
|
||||
}
|
||||
if (hour == other.hour && minute < other.minute) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator>(const Time &other) const
|
||||
{
|
||||
return !(*this < other) && !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
std::optional<mirai::Date> stringToDate(const std::string &dateStr);
|
||||
|
|
22
external/mirai-core/include/mirai-core/Day.h
vendored
22
external/mirai-core/include/mirai-core/Day.h
vendored
|
@ -17,7 +17,7 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
class BaseResource;
|
||||
class BaseSource;
|
||||
|
||||
struct DayData {
|
||||
Date date;
|
||||
|
@ -28,7 +28,7 @@ struct DayData {
|
|||
class Day
|
||||
{
|
||||
public:
|
||||
Day(BaseResource *source, const DayData &data);
|
||||
Day(BaseSource *source, const DayData &data);
|
||||
void setDate(const Date &date);
|
||||
|
||||
Event *createEvent(const EventData &eventData);
|
||||
|
@ -40,25 +40,13 @@ class Day
|
|||
|
||||
const Date &getDate() const;
|
||||
|
||||
Event *getEventById(int eventId)
|
||||
{
|
||||
for (auto &event : events_) {
|
||||
if (event->id() == eventId) {
|
||||
return event.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BaseResource *source()
|
||||
{
|
||||
return source_;
|
||||
}
|
||||
Event *getEventById(int eventId);
|
||||
BaseSource *source();
|
||||
|
||||
private:
|
||||
void onChange();
|
||||
|
||||
BaseResource *source_;
|
||||
BaseSource *source_;
|
||||
std::vector<std::unique_ptr<Event>> events_;
|
||||
std::vector<std::unique_ptr<TaskItem>> tasks_;
|
||||
DayData data_;
|
||||
|
|
24
external/mirai-core/include/mirai-core/Event.h
vendored
24
external/mirai-core/include/mirai-core/Event.h
vendored
|
@ -16,7 +16,7 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
class BaseResource;
|
||||
class BaseSource;
|
||||
|
||||
struct EventData {
|
||||
std::string description;
|
||||
|
@ -33,14 +33,9 @@ class Event
|
|||
{
|
||||
private:
|
||||
public:
|
||||
Event(BaseResource *source, Day *parent, const EventData &data);
|
||||
Event(BaseSource *source, Day *parent, const EventData &data);
|
||||
|
||||
Event &operator=(const EventData &newData)
|
||||
{
|
||||
data = newData;
|
||||
onChange();
|
||||
return *this;
|
||||
};
|
||||
Event &operator=(const EventData &newData);
|
||||
|
||||
void setText(const std::string &text);
|
||||
void setStartTime(const Time &time);
|
||||
|
@ -57,15 +52,8 @@ class Event
|
|||
const Tags &getTags() const;
|
||||
bool hasTag(const std::string &tag) const;
|
||||
|
||||
int id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
Day *day()
|
||||
{
|
||||
return day_;
|
||||
}
|
||||
int id() const;
|
||||
Day *day();
|
||||
|
||||
private:
|
||||
void onChange();
|
||||
|
@ -75,6 +63,6 @@ class Event
|
|||
Day *day_;
|
||||
EventData data;
|
||||
std::vector<std::unique_ptr<TaskItem>> tasks_;
|
||||
BaseResource *source_;
|
||||
BaseSource *source_;
|
||||
};
|
||||
} // namespace mirai
|
||||
|
|
30
external/mirai-core/include/mirai-core/Mirai.h
vendored
30
external/mirai-core/include/mirai-core/Mirai.h
vendored
|
@ -4,11 +4,10 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef MIRAI_MIRAI_H
|
||||
#define MIRAI_MIRAI_H
|
||||
#pragma once
|
||||
|
||||
#include "BaseFileResource.h"
|
||||
#include "BaseResource.h"
|
||||
#include "BaseFileSource.h"
|
||||
#include "BaseSource.h"
|
||||
#include "TaskItem.h"
|
||||
#include "TodoMd.h"
|
||||
#include <algorithm>
|
||||
|
@ -25,31 +24,22 @@ class Mirai
|
|||
{
|
||||
|
||||
public:
|
||||
void loadResource(std::unique_ptr<BaseResource> &&resource);
|
||||
void unloadAllResources();
|
||||
void loadSource(std::unique_ptr<BaseSource> &&resource);
|
||||
void unloadAllSources();
|
||||
void save();
|
||||
void removeTask(const TaskItem *taskItem);
|
||||
std::optional<std::reference_wrapper<BaseResource>> getResourceByName(const std::string &name);
|
||||
void deleteTask(const TaskItem &taskItem);
|
||||
std::optional<std::reference_wrapper<BaseSource>> getSourceByName(const std::string &name);
|
||||
|
||||
std::vector<std::unique_ptr<BaseResource>> &getResources();
|
||||
std::vector<std::unique_ptr<BaseSource>> &getSources();
|
||||
const std::vector<std::string> &getTags();
|
||||
|
||||
void reloadTags();
|
||||
|
||||
// new stuff
|
||||
|
||||
// Returns a non owning pointer to the requested resource or nullptr if not found.
|
||||
BaseResource *getResourceById(int id)
|
||||
{
|
||||
if (id >= resources_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
return resources_.at(id).get();
|
||||
}
|
||||
BaseSource *getSourceById(int id);
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<BaseResource>> resources_;
|
||||
std::vector<std::unique_ptr<BaseSource>> sources_;
|
||||
std::vector<std::string> tags_;
|
||||
};
|
||||
} // namespace mirai
|
||||
#endif
|
||||
|
|
|
@ -1,74 +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
|
||||
*/
|
||||
|
||||
#ifndef MIRAI_STD_FILE_RESOURCE_H
|
||||
#define MIRAI_STD_FILE_RESOURCE_H
|
||||
|
||||
#include "BaseFileResource.h"
|
||||
#include "TodoMd.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class StdFileResource : public BaseFileResource
|
||||
{
|
||||
public:
|
||||
StdFileResource(BaseFileResourceConstructor data) : BaseFileResource(data) {};
|
||||
StdFileResource(StdFileResource &) = delete;
|
||||
StdFileResource(StdFileResource &&) = delete;
|
||||
StdFileResource operator=(StdFileResource &) = delete;
|
||||
StdFileResource operator=(StdFileResource &&) = delete;
|
||||
|
||||
~StdFileResource() override = default;
|
||||
|
||||
void save() override
|
||||
{
|
||||
std::ofstream file(getPath());
|
||||
if (!file.is_open()) {
|
||||
throw std::runtime_error("can't create " + getPath());
|
||||
}
|
||||
|
||||
const std::string content = TodoMdFormat::stringify(getName(), *days());
|
||||
|
||||
file << content;
|
||||
file.close();
|
||||
};
|
||||
|
||||
void load() override
|
||||
{
|
||||
std::ifstream file(getPath());
|
||||
if (!file.is_open()) {
|
||||
return;
|
||||
}
|
||||
std::string content = "";
|
||||
std::string line;
|
||||
|
||||
while (std::getline(file, line)) {
|
||||
content += line + "\n";
|
||||
}
|
||||
file.close();
|
||||
auto result = TodoMdFormat::parse(content);
|
||||
for (const auto &dayData : result.days) {
|
||||
Day *newDay = day(dayData.date);
|
||||
for (const auto &eventData : dayData.events) {
|
||||
Event *newEvent = newDay->createEvent(eventData);
|
||||
for (const auto &taskData : eventData.tasks) {
|
||||
TaskItem *newTask = newEvent->createTask(taskData);
|
||||
}
|
||||
}
|
||||
for (const auto &taskData : dayData.tasks) {
|
||||
TaskItem *newTask = newDay->createTask(taskData);
|
||||
}
|
||||
}
|
||||
setName(result.name);
|
||||
};
|
||||
};
|
||||
} // namespace mirai
|
||||
#endif
|
29
external/mirai-core/include/mirai-core/StdFileSource.h
vendored
Normal file
29
external/mirai-core/include/mirai-core/StdFileSource.h
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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
|
|
@ -4,8 +4,7 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef MIRAI_TASKITEM_H
|
||||
#define MIRAI_TASKITEM_H
|
||||
#pragma once
|
||||
|
||||
#include "using.h"
|
||||
#include <functional>
|
||||
|
@ -14,7 +13,7 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
class BaseResource;
|
||||
class BaseSource;
|
||||
class Day;
|
||||
|
||||
enum TaskItemState { TODO, DONE };
|
||||
|
@ -28,20 +27,13 @@ struct TaskItemData {
|
|||
class TaskItem
|
||||
{
|
||||
public:
|
||||
TaskItem(BaseResource *source, Day *day, const TaskItemData data);
|
||||
TaskItem(BaseSource *source, Day *day, const TaskItemData data);
|
||||
|
||||
TaskItem &operator=(const TaskItemData &newData)
|
||||
{
|
||||
data = newData;
|
||||
onChange();
|
||||
return *this;
|
||||
};
|
||||
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;
|
||||
|
@ -50,20 +42,9 @@ class TaskItem
|
|||
const Tags &getTags() const;
|
||||
bool hasTag(const std::string &tag) const;
|
||||
|
||||
int id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
BaseResource *source()
|
||||
{
|
||||
return source_;
|
||||
}
|
||||
|
||||
Day *day()
|
||||
{
|
||||
return day_;
|
||||
}
|
||||
int id() const;
|
||||
BaseSource *source();
|
||||
Day *day();
|
||||
|
||||
private:
|
||||
void onChange();
|
||||
|
@ -72,10 +53,8 @@ class TaskItem
|
|||
int id_ = nextId++;
|
||||
TaskItemData data;
|
||||
|
||||
BaseResource *source_;
|
||||
BaseSource *source_;
|
||||
Day *day_;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef MIRAI_TASKSVIEW_H
|
||||
#define MIRAI_TASKSVIEW_H
|
||||
#pragma once
|
||||
#include "Mirai.h"
|
||||
#include "TaskItem.h"
|
||||
#include "using.h"
|
||||
|
@ -39,41 +38,14 @@ class TasksView
|
|||
void update();
|
||||
void addTagFilter(const std::string &tag);
|
||||
void removeTagFilter(const std::string &tag);
|
||||
void addResourceFilter(const std::string &fileName);
|
||||
void removeResourceFilter(const std::string &fileName);
|
||||
void addSourceFilter(const std::string &fileName);
|
||||
void removeSourceFilter(const std::string &fileName);
|
||||
void removeFilters();
|
||||
const Tags &getActiveTagsFilter();
|
||||
const std::vector<std::string> &getActiveFilesFilter();
|
||||
|
||||
void hideCompletedTasks(bool hide)
|
||||
{
|
||||
shouldHideCompletedTasks_ = hide;
|
||||
}
|
||||
|
||||
bool shouldHideCompletedTasks() const
|
||||
{
|
||||
return shouldHideCompletedTasks_;
|
||||
}
|
||||
|
||||
/*auto begin()*/ // TODO REWORK
|
||||
/*{*/
|
||||
/*return tasksToShow.begin();*/
|
||||
/*}*/
|
||||
|
||||
/*auto begin() const*/
|
||||
/*{*/
|
||||
/*return tasksToShow.cbegin();*/
|
||||
/*}*/
|
||||
|
||||
/*auto end() const*/
|
||||
/*{*/
|
||||
/*return tasksToShow.cend();*/
|
||||
/*}*/
|
||||
|
||||
/*auto end()*/
|
||||
/*{*/
|
||||
/*return tasksToShow.end();*/
|
||||
/*}*/
|
||||
void hideCompletedTasks(bool hide);
|
||||
bool shouldHideCompletedTasks() const;
|
||||
|
||||
private:
|
||||
std::vector<FilteredDay> filteredDays;
|
||||
|
@ -84,4 +56,3 @@ class TasksView
|
|||
bool shouldHideCompletedTasks_ = true;
|
||||
};
|
||||
} // namespace mirai
|
||||
#endif
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef MIRAI_TODOMD_H
|
||||
#define MIRAI_TODOMD_H
|
||||
#pragma once
|
||||
|
||||
#include "DateTime.h"
|
||||
#include "Day.h"
|
||||
|
@ -44,5 +43,3 @@ class TodoMdFormat
|
|||
static Tags extractTagsFromMetadata(std::string metadata);
|
||||
};
|
||||
} // namespace mirai
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef MIRAI_TODOTXT_H
|
||||
#define MIRAI_TODOTXT_H
|
||||
#pragma once
|
||||
|
||||
/*#include "TaskItem.h"*/
|
||||
/*#include "utils.h"*/
|
||||
|
@ -90,5 +89,3 @@
|
|||
/*}*/
|
||||
/*};*/
|
||||
/*}*/
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef MIRAI_USING_H
|
||||
#define MIRAI_USING_H
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
@ -15,5 +14,3 @@ namespace mirai
|
|||
{
|
||||
using Tags = std::vector<std::string>;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef MIRAI_UTILS_H
|
||||
#define MIRAI_UTILS_H
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
@ -21,5 +20,3 @@ namespace vectorUtils = cpputils::vector;
|
|||
|
||||
bool isDate(const std::string &dateStr);
|
||||
} // namespace mirai
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue