diff --git a/.gitignore b/.gitignore index e6ca6a2..11ce06f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ todo.md .qmlls.ini .clangd .cache +.nvimrc diff --git a/libs/cpp-utils/vector.h b/libs/cpp-utils/vector.h index a7b7c04..52bb8d1 100644 --- a/libs/cpp-utils/vector.h +++ b/libs/cpp-utils/vector.h @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -8,37 +8,41 @@ #define CPP_UTILS_VECTOR_H #include -#include -#include #include -#include -namespace cpputils::vector { +namespace cpputils::vector +{ - template - concept AnyIterable = - std::same_as && - requires (C c) { - { c.begin() } -> std::forward_iterator; - { c.end() } -> std::forward_iterator; - { const_cast(c).begin() } -> std::forward_iterator; - { const_cast(c).end() } -> std::forward_iterator; - }; +template +concept AnyIterable = std::same_as && requires(C c) { + { + c.begin() + } -> std::forward_iterator; + { + c.end() + } -> std::forward_iterator; + { + const_cast(c).begin() + } -> std::forward_iterator; + { + const_cast(c).end() + } -> std::forward_iterator; +}; - template - bool contains(const std::vector& vec, const T& value) { - return std::ranges::find(vec, value) != vec.end(); - } - - template - bool containsAll(const std::vector& vec, const AnyIterable auto vec2) { - for (auto& elem : vec) { - if (!contains(vec2, elem)) { - return false; - } - } - return true; - } +template bool contains(const std::vector &vec, const T &value) +{ + return std::ranges::find(vec, value) != vec.end(); } +template bool containsAll(const std::vector &vec, const AnyIterable auto vec2) +{ + for (auto &elem : vec) { + if (!contains(vec2, elem)) { + return false; + } + } + return true; +} +} // namespace cpputils::vector + #endif diff --git a/src/Backend.cpp b/src/Backend.cpp index 4db2813..dbb7841 100644 --- a/src/Backend.cpp +++ b/src/Backend.cpp @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -6,8 +6,10 @@ #include "Backend.h" #include "core/TodoMd.h" +#include -Backend::Backend() { +Backend::Backend() +{ std::cout << "Backend created" << std::endl; QDir().mkdir(QDir::homePath() + "/.config/mirai"); QFile loadFile(QDir::homePath() + "/.config/mirai/config.json"); @@ -16,7 +18,7 @@ Backend::Backend() { qWarning() << "Couldn't find existing config file"; exit(1); } - + QByteArray loadData = loadFile.readAll(); QJsonDocument json = QJsonDocument::fromJson(loadData); loadFile.close(); @@ -25,7 +27,7 @@ Backend::Backend() { exit(1); } QJsonObject jsonRootObject = json.object(); - + auto jsonFilesPath = json["files"]; if (!jsonFilesPath.isArray()) { qWarning() << "config.json should contains a 'files' string array"; @@ -37,48 +39,56 @@ Backend::Backend() { rebuildQMLTasksList(); } -void Backend::addTodo(QString newTodo, QString date) { +void Backend::addTodo(QString newTodo, QString date) +{ mirai.addTask(newTodo.toStdString(), date.toStdString()); mirai.save(); rebuildQMLTasksList(); emit tasksChanged(); } -void Backend::addTodoFromRawFormat(QString text, QString date) { +void Backend::addTodoFromRawFormat(QString text, QString date) +{ mirai.addTask(mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString())); mirai.save(); rebuildQMLTasksList(); emit tasksChanged(); } -void Backend::addTagFilter(QString tag) { +void Backend::addTagFilter(QString tag) +{ view.lock()->addTagFilter(tag.toStdString()); rebuildQMLTasksList(); emit tasksChanged(); } -void Backend::removeTagFilter(QString tag) { +void Backend::removeTagFilter(QString tag) +{ view.lock()->removeTagFilter(tag.toStdString()); rebuildQMLTasksList(); emit tasksChanged(); } -void Backend::removeFilters() { +void Backend::removeFilters() +{ view.lock()->removeFilters(); rebuildQMLTasksList(); emit tasksChanged(); } -void Backend::updateTodoFromRawFormat(int todoIndex, QString text, QString date) { - QMLTaskItem& taskItem = QMLTasks[todoIndex]; - *(taskItem.taskItem) = mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString()); +void Backend::updateTodoFromRawFormat(int todoIndex, QString text, QString date) +{ + QMLTaskItem &taskItem = QMLTasks[todoIndex]; + *(taskItem.taskItem) = + mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString()); mirai.save(); rebuildQMLTasksList(); emit tasksChanged(); } -void Backend::updateTodo(int todoIndex, QString state, QString text, QString date) { - QMLTaskItem& taskItem = QMLTasks[todoIndex]; +void Backend::updateTodo(int todoIndex, QString state, QString text, QString date) +{ + QMLTaskItem &taskItem = QMLTasks[todoIndex]; taskItem.taskItem->state = state == "TODO" ? mirai::TODO : mirai::DONE; if (state == "DONE") { taskItem.taskItem->markAsDone(); @@ -92,21 +102,24 @@ void Backend::updateTodo(int todoIndex, QString state, QString text, QString dat emit tasksChanged(); } -void Backend::removeTodo(int todoIndex) { - QMLTaskItem& taskItem = QMLTasks[todoIndex]; +void Backend::removeTodo(int todoIndex) +{ + QMLTaskItem &taskItem = QMLTasks[todoIndex]; mirai.removeTask(taskItem.taskItem); mirai.save(); rebuildQMLTasksList(); emit tasksChanged(); } -void Backend::hideCompletedTasks(bool shouldHide) { +void Backend::hideCompletedTasks(bool shouldHide) +{ shouldHideCompletedTasks_ = shouldHide; rebuildQMLTasksList(); emit tasksChanged(); } -void Backend::rebuildQMLTasksList() { +void Backend::rebuildQMLTasksList() +{ QMLTasks.clear(); std::string lastDate = ""; std::time_t t = std::time(nullptr); @@ -114,8 +127,9 @@ void Backend::rebuildQMLTasksList() { std::stringstream currentDate; currentDate << std::put_time(&tm, "%Y-%m-%d"); for (int i = 0; i < view.lock()->count(); ++i) { - mirai::TaskItem& task = (*view.lock())[i]; - if (shouldHideCompletedTasks_ && task.getState() == mirai::DONE && task.hasDate() && task.getDate() < currentDate.str()) { + mirai::TaskItem &task = (*view.lock())[i]; + if (shouldHideCompletedTasks_ && task.getState() == mirai::DONE && task.hasDate() && + task.getDate() < currentDate.str()) { continue; } bool shouldShowDate = false; @@ -124,40 +138,40 @@ void Backend::rebuildQMLTasksList() { shouldShowDate = true; } QList qStringTags; - for (auto& tag : task.getTags()) { + for (auto &tag : task.getTags()) { qStringTags.push_back(QString::fromStdString(tag)); } - QMLTasks.push_back({ - .taskItem = &task, - .shouldShowDate = shouldShowDate, - .tags = qStringTags - }); + QMLTasks.push_back( + {.taskItem = &task, .shouldShowDate = shouldShowDate, .tags = qStringTags}); } - QMLTags.clear(); - for (auto& tag : mirai.getTags()) { + for (auto &tag : mirai.getTags()) { QMLTags.push_back(QString::fromStdString(tag)); } QMLActiveTagsFilter.clear(); - for (auto& activeTagFilter: view.lock()->getActiveTagsFilter()) { + for (auto &activeTagFilter : view.lock()->getActiveTagsFilter()) { QMLActiveTagsFilter.push_back(QString::fromStdString(activeTagFilter)); } } -QVariant Backend::getTasks() { +QVariant Backend::getTasks() +{ return QVariant::fromValue(QMLTasks); } -QVariant Backend::getTags() { +QVariant Backend::getTags() +{ return QVariant::fromValue(QMLTags); } -QVariant Backend::getActiveTagsFilter() { +QVariant Backend::getActiveTagsFilter() +{ return QVariant::fromValue(QMLActiveTagsFilter); } -bool Backend::shouldHideCompletedTasks() { +bool Backend::shouldHideCompletedTasks() +{ return shouldHideCompletedTasks_; } diff --git a/src/Backend.h b/src/Backend.h index 84b1148..4bc5f4e 100644 --- a/src/Backend.h +++ b/src/Backend.h @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -10,35 +10,32 @@ #include "QtCore/qcontainerfwd.h" #include "QtCore/qtmetamacros.h" #include "QtCore/qvariant.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "core/TaskItem.h" -#include "core/TasksView.h" -#include "core/TodoMd.h" #include "core/Mirai.h" +#include "core/TasksView.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "TaskItem.h" class Backend : public QObject { - Q_OBJECT - QML_ELEMENT - Q_PROPERTY(QVariant tasks READ getTasks NOTIFY tasksChanged) - Q_PROPERTY(QVariant tags READ getTags NOTIFY tasksChanged) - Q_PROPERTY(QVariant activeTagsFilter READ getActiveTagsFilter NOTIFY tasksChanged) - Q_PROPERTY(bool shouldHideCompletedTasks READ shouldHideCompletedTasks WRITE hideCompletedTasks NOTIFY tasksChanged) - -public: + Q_OBJECT + QML_ELEMENT + Q_PROPERTY(QVariant tasks READ getTasks NOTIFY tasksChanged) + Q_PROPERTY(QVariant tags READ getTags NOTIFY tasksChanged) + Q_PROPERTY(QVariant activeTagsFilter READ getActiveTagsFilter NOTIFY tasksChanged) + Q_PROPERTY(bool shouldHideCompletedTasks READ shouldHideCompletedTasks WRITE hideCompletedTasks + NOTIFY tasksChanged) + public: Backend(); Q_INVOKABLE void addTodo(QString newTodo, QString date); @@ -51,8 +48,7 @@ public: Q_INVOKABLE void removeTodo(int todoIndex); Q_INVOKABLE void hideCompletedTasks(bool shouldHide); -private: - + private: void rebuildQMLTasksList(); QVariant getTasks(); @@ -69,7 +65,7 @@ private: bool shouldHideCompletedTasks_ = true; -signals: + signals: void tasksChanged(); }; diff --git a/src/TaskItem.cpp b/src/TaskItem.cpp index 156e591..80bd79f 100644 --- a/src/TaskItem.cpp +++ b/src/TaskItem.cpp @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -7,33 +7,40 @@ #include "TaskItem.h" #include "core/TodoMd.h" -QString QMLTaskItem::getRawFormat() { +QString QMLTaskItem::getRawFormat() +{ return QString::fromStdString(mirai::TodoMdFormat::TaskToString(*taskItem)); } -QString QMLTaskItem::getText() { +QString QMLTaskItem::getText() +{ return QString::fromStdString(taskItem->getText()); } -QString QMLTaskItem::getState() { +QString QMLTaskItem::getState() +{ return QString::fromStdString(taskItem->getState() == mirai::TODO ? "TODO" : "DONE"); } -QString QMLTaskItem::getDate() { +QString QMLTaskItem::getDate() +{ return QString::fromStdString(taskItem->getDate()); } -QString QMLTaskItem::getTime() { +QString QMLTaskItem::getTime() +{ if (taskItem->getStartTime() != "" && taskItem->getEndTime() != "") { return QString::fromStdString(taskItem->getStartTime() + "-" + taskItem->getEndTime()); } return ""; } -QList QMLTaskItem::getTags() { +QList QMLTaskItem::getTags() +{ return tags; } -bool QMLTaskItem::getShouldShowDate() { +bool QMLTaskItem::getShouldShowDate() +{ return shouldShowDate; } diff --git a/src/TaskItem.h b/src/TaskItem.h index 34bc0b2..90a3773 100644 --- a/src/TaskItem.h +++ b/src/TaskItem.h @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -8,8 +8,8 @@ #define QML_TASKITEM_H #include "QtCore/qvariant.h" -#include #include +#include #include #include "core/TaskItem.h" @@ -17,26 +17,25 @@ struct QMLTaskItem { Q_GADGET - Q_PROPERTY(QString rawFormat READ getRawFormat) - Q_PROPERTY(QString text READ getText) - Q_PROPERTY(QString state READ getState) - Q_PROPERTY(QString date READ getDate) - Q_PROPERTY(QList tags READ getTags) - Q_PROPERTY(bool shouldShowDate READ getShouldShowDate) - Q_PROPERTY(QString time READ getTime) + Q_PROPERTY(QString rawFormat READ getRawFormat) + Q_PROPERTY(QString text READ getText) + Q_PROPERTY(QString state READ getState) + Q_PROPERTY(QString date READ getDate) + Q_PROPERTY(QList tags READ getTags) + Q_PROPERTY(bool shouldShowDate READ getShouldShowDate) + Q_PROPERTY(QString time READ getTime) QML_VALUE_TYPE(taskItem) -public: - + public: QString getText(); QString getRawFormat(); QString getState(); QString getDate(); QString getTime(); QList getTags(); - bool getShouldShowDate(); + bool getShouldShowDate(); - mirai::TaskItem* taskItem; + mirai::TaskItem *taskItem; bool shouldShowDate = false; QList tags; }; diff --git a/src/core/Mirai.cpp b/src/core/Mirai.cpp index bc2ab9a..66ff748 100644 --- a/src/core/Mirai.cpp +++ b/src/core/Mirai.cpp @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -8,59 +8,67 @@ #include "TaskItem.h" #include "cpp-utils/vector.h" -namespace mirai { +namespace mirai +{ - void Mirai::loadFile(const std::string& path) { - auto tasksFile = TodoMdFormat::readFile(path); - files->push_back(std::move(tasksFile)); - tags.clear(); - for (auto& task : (*files)[0].getTasks()) { - for (auto& tag : task->getTags()) { - if (vectorUtils::contains(tags, tag)) { - tags.push_back(tag); - } +void Mirai::loadFile(const std::string &path) +{ + auto tasksFile = TodoMdFormat::readFile(path); + files->push_back(std::move(tasksFile)); + tags.clear(); + for (auto &task : (*files)[0].getTasks()) { + for (auto &tag : task->getTags()) { + if (!vectorUtils::contains(tags, tag)) { + tags.push_back(tag); } } } +} - void Mirai::save() { - for (auto& file : *files) { - TodoMdFormat::writeFile(file); - } - } - - void Mirai::addTask(TaskItem taskItem) { - (*files)[0].addTask(taskItem); - for (auto& view : views) { - view->update(); - } - } - - void Mirai::addTask(std::string text, std::string date) { - /*std::time_t t = std::time(nullptr);*/ - /*std::tm tm = *std::localtime(&t);*/ - /*std::stringstream ssCreationDate;*/ - /*ssCreationDate << std::put_time(&tm, "%Y-%m-%d");*/ - (*files)[0].addTask(text, date); - for (auto& view : views) { - view->update(); - } - } - - void Mirai::removeTask(const TaskItem* taskItem) { - (*files)[0].removeTask(taskItem); - for (auto& view : views) { - view->update(); - } - } - - std::weak_ptr Mirai::getTasks() { - auto view = std::make_shared(files); - views.push_back(view); - return view; - } - - const std::vector& Mirai::getTags() { - return tags; +void Mirai::save() +{ + for (auto &file : *files) { + TodoMdFormat::writeFile(file); } } + +void Mirai::addTask(TaskItem taskItem) +{ + (*files)[0].addTask(taskItem); + for (auto &view : views) { + view->update(); + } +} + +void Mirai::addTask(std::string text, std::string date) +{ + /*std::time_t t = std::time(nullptr);*/ + /*std::tm tm = *std::localtime(&t);*/ + /*std::stringstream ssCreationDate;*/ + /*ssCreationDate << std::put_time(&tm, "%Y-%m-%d");*/ + (*files)[0].addTask(text, date); + for (auto &view : views) { + view->update(); + } +} + +void Mirai::removeTask(const TaskItem *taskItem) +{ + (*files)[0].removeTask(taskItem); + for (auto &view : views) { + view->update(); + } +} + +std::weak_ptr Mirai::getTasks() +{ + auto view = std::make_shared(files); + views.push_back(view); + return view; +} + +const std::vector &Mirai::getTags() +{ + return tags; +} +} // namespace mirai diff --git a/src/core/Mirai.h b/src/core/Mirai.h index 468db1f..ea00fd4 100644 --- a/src/core/Mirai.h +++ b/src/core/Mirai.h @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -14,33 +14,33 @@ #include #include -namespace mirai { +namespace mirai +{ - class Mirai { +class Mirai +{ - public: + public: + void loadFile(const std::string &path); + void save(); + void addTask(TaskItem taskItem); + void addTask(std::string text, std::string date); + void removeTask(const TaskItem *taskItem); - void loadFile(const std::string& path); - void save(); - void addTask(TaskItem taskItem); - void addTask(std::string text, std::string date); - void removeTask(const TaskItem* taskItem); + std::weak_ptr getTasks(); + const std::vector &getTags(); - std::weak_ptr getTasks(); - const std::vector& getTags(); + private: + // The `TasksFile`s are shared to the views, their lifetime can outlive + // this (Mirai) object + // because we can't control if the caller will keep the main object alive. + std::shared_ptr> files = std::make_shared>(); - private: - - // The `TasksFile`s are shared to the views, their lifetime can outlive - // this (Mirai) object - // because we can't control if the caller will keep the main object alive. - std::shared_ptr> files = std::make_shared>(); - - // We keep a vector of shared_ptr because we need the ref counting mechanism to know - // if we have to remove the view (not used) or tell the view to update() on - // some changes. - std::vector> views; - std::vector tags; - }; -} + // We keep a vector of shared_ptr because we need the ref counting mechanism to know + // if we have to remove the view (not used) or tell the view to update() on + // some changes. + std::vector> views; + std::vector tags; +}; +} // namespace mirai #endif diff --git a/src/core/TaskItem.cpp b/src/core/TaskItem.cpp index 118daf3..e4931df 100644 --- a/src/core/TaskItem.cpp +++ b/src/core/TaskItem.cpp @@ -1,41 +1,72 @@ -/* +/* * 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 "TaskItem.h" #include "cpp-utils/vector.h" -namespace mirai { +namespace mirai +{ - void TaskItem::markAsDone() { - state = DONE; - } - - void TaskItem::markAsUndone() { - state = TODO; - } - - void TaskItem::setDate(const std::string& date) { - this->date = date; - } - - void TaskItem::setText(const std::string& text) { - this->text = text; - } - - const std::string& TaskItem::getText() const { return text; } - const TaskItemState& TaskItem::getState() const { return state; } - const std::string& TaskItem::getDate() const { return date; } - const std::string& TaskItem::getStartTime() const { return startTime; } - const std::string& TaskItem::getEndTime() const { return endTime; } - const Tags& TaskItem::getTags() const { return tags; } - bool TaskItem::hasDate() const { return isDate(date); } - - - bool TaskItem::hasTag(const std::string& tag) const { - return vectorUtils::contains(tags, tag); - } +void TaskItem::markAsDone() +{ + state = DONE; } + +void TaskItem::markAsUndone() +{ + state = TODO; +} + +void TaskItem::setDate(const std::string &date) +{ + this->date = date; +} + +void TaskItem::setText(const std::string &text) +{ + this->text = text; +} + +const std::string &TaskItem::getText() const +{ + return text; +} + +const TaskItemState &TaskItem::getState() const +{ + return state; +} + +const std::string &TaskItem::getDate() const +{ + return date; +} + +const std::string &TaskItem::getStartTime() const +{ + return startTime; +} + +const std::string &TaskItem::getEndTime() const +{ + return endTime; +} + +const Tags &TaskItem::getTags() const +{ + return tags; +} + +bool TaskItem::hasDate() const +{ + return isDate(date); +} + +bool TaskItem::hasTag(const std::string &tag) const +{ + return vectorUtils::contains(tags, tag); +} +} // namespace mirai diff --git a/src/core/TaskItem.h b/src/core/TaskItem.h index 31c6d80..b963d5e 100644 --- a/src/core/TaskItem.h +++ b/src/core/TaskItem.h @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -20,39 +20,36 @@ #include #include -namespace mirai { - enum TaskItemState { - TODO, - DONE - }; +namespace mirai +{ +enum TaskItemState { TODO, DONE }; - struct TaskItem { - public: +struct TaskItem { + public: + void markAsDone(); - void markAsDone(); + void markAsUndone(); + void setDate(const std::string &date); - void markAsUndone(); - void setDate(const std::string& date); + void setText(const std::string &text); - void setText(const std::string& text); + const std::string &getLine() const; + const std::string &getText() const; + const TaskItemState &getState() const; + const std::string &getDate() const; + const std::string &getStartTime() const; + const std::string &getEndTime() const; + const Tags &getTags() const; + bool hasTag(const std::string &tag) const; + bool hasDate() const; - const std::string& getLine() const; - const std::string& getText() const; - const TaskItemState& getState() const; - const std::string& getDate() const; - const std::string& getStartTime() const; - const std::string& getEndTime() const; - const Tags& getTags() const; - bool hasTag(const std::string& tag) const; - bool hasDate() const; - - std::string text; - TaskItemState state; - std::string date; - std::string startTime; - std::string endTime; - Tags tags; - }; -} + std::string text; + TaskItemState state; + std::string date; + std::string startTime; + std::string endTime; + Tags tags; +}; +} // namespace mirai #endif diff --git a/src/core/TasksFile.cpp b/src/core/TasksFile.cpp index 645710a..20d33e9 100644 --- a/src/core/TasksFile.cpp +++ b/src/core/TasksFile.cpp @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -8,48 +8,64 @@ #include "TaskItem.h" #include -namespace mirai { +namespace mirai +{ - TasksFile::TasksFile(TasksFileConstructor params) : name(params.name), path(params.path) { - for (const auto& task : params.tasks) { - tasks.push_back(std::make_unique(task)); - } - sortByDate(); - } - - const std::string& TasksFile::getName() const { return name; } - const std::string& TasksFile::getPath() const { return path; } - TasksPtrs& TasksFile::getTasks() { return tasks; } - - void TasksFile::addTask(TaskItem taskItem) { - tasks.push_back(std::make_unique(taskItem)); - sortByDate(); - } - - void TasksFile::addTask(std::string text, std::string date) { - auto newTask = std::make_unique(TaskItem{ - .text = text, - .state = TODO, - .date = date == "" ? "No date" : date - }); - tasks.push_back(std::move(newTask)); - sortByDate(); - } - - void TasksFile::removeTask(const TaskItem* taskToRemove) { - tasks.erase(std::remove_if(tasks.begin(), tasks.end(), [&] (const std::unique_ptr& taskInFilter){ - return taskInFilter.get() == taskToRemove; - })); - } - - void TasksFile::sortByDate() { - std::sort(tasks.begin(), tasks.end(), [] (const std::unique_ptr& t1, const std::unique_ptr& t2) { - if (t1->hasDate() && !t2->hasDate()) { - return true; - } else if (!t1->hasDate() && t2->hasDate()) { - return false; - } - return t1->date < t2->date; - }); +TasksFile::TasksFile(TasksFileConstructor params) : name(params.name), path(params.path) +{ + for (const auto &task : params.tasks) { + tasks.push_back(std::make_unique(task)); } + sortByDate(); } + +const std::string &TasksFile::getName() const +{ + return name; +} + +const std::string &TasksFile::getPath() const +{ + return path; +} + +TasksPtrs &TasksFile::getTasks() +{ + return tasks; +} + +void TasksFile::addTask(TaskItem taskItem) +{ + tasks.push_back(std::make_unique(taskItem)); + sortByDate(); +} + +void TasksFile::addTask(std::string text, std::string date) +{ + auto newTask = std::make_unique( + TaskItem{.text = text, .state = TODO, .date = date == "" ? "No date" : date}); + tasks.push_back(std::move(newTask)); + sortByDate(); +} + +void TasksFile::removeTask(const TaskItem *taskToRemove) +{ + tasks.erase(std::remove_if(tasks.begin(), tasks.end(), + [&](const std::unique_ptr &taskInFilter) { + return taskInFilter.get() == taskToRemove; + })); +} + +void TasksFile::sortByDate() +{ + std::sort(tasks.begin(), tasks.end(), + [](const std::unique_ptr &t1, const std::unique_ptr &t2) { + if (t1->hasDate() && !t2->hasDate()) { + return true; + } else if (!t1->hasDate() && t2->hasDate()) { + return false; + } + return t1->date < t2->date; + }); +} +} // namespace mirai diff --git a/src/core/TasksFile.h b/src/core/TasksFile.h index 1dcdd6c..a8ebf96 100644 --- a/src/core/TasksFile.h +++ b/src/core/TasksFile.h @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -7,6 +7,9 @@ #ifndef MIRAI_TASKSFILE_H #define MIRAI_TASKSFILE_H +#include "TaskItem.h" +#include "using.h" +#include "utils.h" #include #include #include @@ -19,41 +22,38 @@ #include #include #include -#include "TaskItem.h" -#include "using.h" -#include "utils.h" -namespace mirai { +namespace mirai +{ +using TasksPtrs = std::vector>; - using TasksPtrs = std::vector>; +struct TasksFileConstructor { + const std::string &name; + const std::string &path; + std::vector tasks; +}; - struct TasksFileConstructor { - const std::string& name; - const std::string& path; - std::vector tasks; - }; +class TasksFile +{ - class TasksFile { + public: + TasksFile(TasksFileConstructor params); - public: + void addTask(std::string text, std::string date); + void addTask(TaskItem TaskItem); + void removeTask(const TaskItem *taskToRemove); + void sortByDate(); - TasksFile(TasksFileConstructor params); + const std::string &getName() const; + const std::string &getPath() const; + TasksPtrs &getTasks(); - void addTask(std::string text, std::string date); - void addTask(TaskItem TaskItem); - void removeTask(const TaskItem* taskToRemove); - void sortByDate(); - - const std::string& getName() const; - const std::string& getPath() const; - TasksPtrs& getTasks(); - - private: - std::string name; - std::string path; - TasksPtrs tasks; - }; -} + private: + std::string name; + std::string path; + TasksPtrs tasks; +}; +} // namespace mirai #endif diff --git a/src/core/TasksView.cpp b/src/core/TasksView.cpp index 092f248..198b899 100644 --- a/src/core/TasksView.cpp +++ b/src/core/TasksView.cpp @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -7,53 +7,63 @@ #include "TasksView.h" #include "cpp-utils/vector.h" #include +#include +#include +#include #include -namespace mirai { +namespace mirai +{ +TasksView::TasksView(std::shared_ptr> files) : files(files) +{ + update(); +} - TasksView::TasksView(std::shared_ptr> files) : files(files) { - update(); - } +TaskItem &TasksView::operator[](int index) +{ + return *(tasksToShow.at(index)); +} - TaskItem& TasksView::operator[](int index) { - return *(tasksToShow.at(index)); - } +size_t TasksView::count() const +{ + return tasksToShow.size(); +} - int TasksView::count() const { return tasksToShow.size(); } - - void TasksView::update() { - tasksToShow.clear(); - for (auto& file : *files) { - for (auto& task : file.getTasks()) { - std::function f = [&](const std::string& tag) { - return task->hasTag(tag); - }; - if (tagsFilter.size() > 0 && !vectorUtils::containsAll(tagsFilter, task->getTags())) - continue; - tasksToShow.push_back(task.get()); +void TasksView::update() +{ + tasksToShow.clear(); + for (auto &file : *files) { + for (auto &task : file.getTasks()) { + if (tagsFilter.size() > 0 && !vectorUtils::containsAll(tagsFilter, task->getTags())) { + continue; } + tasksToShow.push_back(task.get()); } } - - void TasksView::addTagFilter(const std::string& tag) { - tagsFilter.push_back(tag); - update(); - } - - void TasksView::removeTagFilter(const std::string& tag) { - tagsFilter.erase(std::remove_if(tagsFilter.begin(), tagsFilter.end(), [&] (const auto& tagInFilter){ - return tag == tagInFilter; - })); - update(); - } - - void TasksView::removeFilters() { - tagsFilter.clear(); - update(); - } - - const std::vector& TasksView::getActiveTagsFilter() { - return tagsFilter; - } } + +void TasksView::addTagFilter(const std::string &tag) +{ + tagsFilter.push_back(tag); + update(); +} + +void TasksView::removeTagFilter(const std::string &tag) +{ + tagsFilter.erase(std::remove_if(tagsFilter.begin(), tagsFilter.end(), + [&](const auto &tagInFilter) { return tag == tagInFilter; })); + update(); +} + +void TasksView::removeFilters() +{ + tagsFilter.clear(); + update(); +} + +const std::vector &TasksView::getActiveTagsFilter() +{ + return tagsFilter; +} +} // namespace mirai diff --git a/src/core/TasksView.h b/src/core/TasksView.h index ec00405..17bb646 100644 --- a/src/core/TasksView.h +++ b/src/core/TasksView.h @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -8,34 +8,32 @@ #define MIRAI_TASKSVIEW_H #include "TasksFile.h" #include "using.h" -#include -#include +#include #include -#include #include -namespace mirai { +namespace mirai +{ - class TasksView { +class TasksView +{ - public: + public: + TasksView(std::shared_ptr> files); - TasksView(std::shared_ptr> files); + TaskItem &operator[](int index); - TaskItem& operator[](int index); + size_t count() const; + void update(); + void addTagFilter(const std::string &tag); + void removeTagFilter(const std::string &tag); + void removeFilters(); + const Tags &getActiveTagsFilter(); - int count() const; - void update(); - void addTagFilter(const std::string& tag); - void removeTagFilter(const std::string& tag); - void removeFilters(); - const Tags& getActiveTagsFilter(); - - private: - - std::shared_ptr> files; - std::vector tasksToShow; - Tags tagsFilter; - }; -} + private: + std::shared_ptr> files; + std::vector tasksToShow; + Tags tagsFilter; +}; +} // namespace mirai #endif diff --git a/src/core/TodoMd.cpp b/src/core/TodoMd.cpp index 78072d1..38e426c 100644 --- a/src/core/TodoMd.cpp +++ b/src/core/TodoMd.cpp @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -8,122 +8,122 @@ #include "TaskItem.h" #include "cpp-utils/vector.h" -namespace mirai { +namespace mirai +{ - TasksFile TodoMdFormat::readFile(const std::string& path) { - std::ifstream file(path); - if (!file.is_open()) { - throw std::runtime_error("todo.txt file not found"); - } - std::vector taskItems; - std::string line; +TasksFile TodoMdFormat::readFile(const std::string &path) +{ + std::ifstream file(path); + if (!file.is_open()) { + throw std::runtime_error("todo.txt file not found"); + } + std::vector taskItems; + std::string line; - if (!std::getline(file, line) || line.substr(0, 2) != "# ") { - std::cerr << "Couldn't find the task list name" << std::endl; - } - - std::string name = line.substr(2); - std::string currentDate = ""; - - while (std::getline(file, line)) { - if (line.substr(0, 3) == "## ") { - currentDate = line.substr(3); - } else if (line.substr(0, 5) == "- [ ]" || line.substr(0, 5) == "- [X]") { - TaskItem taskItem = StringToTask(line, currentDate); - taskItem.setDate(currentDate); - taskItems.push_back(taskItem); - } - } - file.close(); - TasksFile tasks({ - .name = name, - .path = path, - .tasks = taskItems - }); - return tasks; + if (!std::getline(file, line) || line.substr(0, 2) != "# ") { + std::cerr << "Couldn't find the task list name" << std::endl; } - Tags TodoMdFormat::extractTagsFromMetadata(std::string metadata) { - Tags tags; + std::string name = line.substr(2); + std::string currentDate = ""; - std::regex regex("(#[a-zA-Z0-1]+)"); - std::smatch matches; - - while (std::regex_search(metadata, matches, regex)) - { - if (!vectorUtils::contains(tags, matches[0].str())) { - tags.push_back(matches[0]); - } - metadata = matches.suffix(); + while (std::getline(file, line)) { + if (line.substr(0, 3) == "## ") { + currentDate = line.substr(3); + } else if (line.substr(0, 5) == "- [ ]" || line.substr(0, 5) == "- [X]") { + TaskItem taskItem = StringToTask(line, currentDate); + taskItem.setDate(currentDate); + taskItems.push_back(taskItem); } - return tags; - } - - void TodoMdFormat::writeFile(TasksFile& tasks) { - std::ofstream file(tasks.getPath()); - if (!file.is_open()) { - throw std::runtime_error("can't create todo.txt"); - } - std::string currentDate = ""; - - file << "# " << tasks.getName() << "\n"; - for (const auto& task : tasks.getTasks()) { - if (currentDate != task->date) { - currentDate = task->date; - file << "\n## " << (task->date != "" ? task->date : "No date") << "\n\n"; - } - file << TaskToString(*task) << '\n'; - } - file.close(); - } - - std::string TodoMdFormat::fieldWithSpace(const std::string& field) { - if (field.length() == 0) - return ""; - return (field + " "); - } - - TaskItem TodoMdFormat::StringToTask(const std::string& str, const std::string& date) { - std::smatch matches; - std::regex regex("- \\[(\\s|X)\\] (([0-9]{2}:[0-9]{2})-([0-9]{2}:[0-9]{2}) > )?(.*?)( -- (.*))?"); - std::regex_match(str, matches, regex); - - /*std::cout << "line " << str << std::endl;*/ - /*std::cout << "M 0 " << matches[0] << std::endl;*/ - /*std::cout << "M 1 " << matches[1] << std::endl;*/ - /*std::cout << "M 2 " << matches[2] << std::endl;*/ - /*std::cout << "M 3 " << matches[3] << std::endl;*/ - /*std::cout << "M 4 " << matches[4] << std::endl;*/ - /*std::cout << "M 5 " << matches[5] << std::endl;*/ - /*std::cout << "M 6 " << matches[6] << std::endl;*/ - /*std::cout << "M 7 " << matches[7] << std::endl;*/ - - std::string text = stringUtils::trim(matches[5]); - - TaskItem taskItem = { - .text = text, - .state = str.substr(0, 5) == "- [X]" ? DONE : TODO, - .date = date, - .startTime = matches[3], - .endTime = matches[4], - .tags = extractTagsFromMetadata(matches[7]) - }; - return taskItem; - } - - std::string TodoMdFormat::TaskToString(const TaskItem& task) { - std::string str = task.getText(); - if (task.getTags().size() > 0) { - str += " --"; - for (const std::string& tag : task.getTags()) { - str += " " + tag; - } - } - if (task.getStartTime() != "" && task.getEndTime() != "") { - str = task.getStartTime() + "-" + task.getEndTime() + " > " + str; - } - str = (task.getState() == DONE ? "- [X] " : "- [ ] ") + str; - return str; } + file.close(); + TasksFile tasks({.name = name, .path = path, .tasks = taskItems}); + return tasks; } +Tags TodoMdFormat::extractTagsFromMetadata(std::string metadata) +{ + Tags tags; + + std::regex regex("(#[a-zA-Z0-1]+)"); + std::smatch matches; + + while (std::regex_search(metadata, matches, regex)) { + if (!vectorUtils::contains(tags, matches[0].str())) { + tags.push_back(matches[0]); + } + metadata = matches.suffix(); + } + return tags; +} + +void TodoMdFormat::writeFile(TasksFile &tasks) +{ + std::ofstream file(tasks.getPath()); + if (!file.is_open()) { + throw std::runtime_error("can't create todo.txt"); + } + std::string currentDate = ""; + + file << "# " << tasks.getName() << "\n"; + for (const auto &task : tasks.getTasks()) { + if (currentDate != task->date) { + currentDate = task->date; + file << "\n## " << (task->date != "" ? task->date : "No date") << "\n\n"; + } + file << TaskToString(*task) << '\n'; + } + file.close(); +} + +std::string TodoMdFormat::fieldWithSpace(const std::string &field) +{ + if (field.length() == 0) + return ""; + return (field + " "); +} + +TaskItem TodoMdFormat::StringToTask(const std::string &str, const std::string &date) +{ + std::smatch matches; + std::regex regex( + "- \\[(\\s|X)\\] (([0-9]{2}:[0-9]{2})-([0-9]{2}:[0-9]{2}) > )?(.*?)( -- (.*))?"); + std::regex_match(str, matches, regex); + + /*std::cout << "line " << str << std::endl;*/ + /*std::cout << "M 0 " << matches[0] << std::endl;*/ + /*std::cout << "M 1 " << matches[1] << std::endl;*/ + /*std::cout << "M 2 " << matches[2] << std::endl;*/ + /*std::cout << "M 3 " << matches[3] << std::endl;*/ + /*std::cout << "M 4 " << matches[4] << std::endl;*/ + /*std::cout << "M 5 " << matches[5] << std::endl;*/ + /*std::cout << "M 6 " << matches[6] << std::endl;*/ + /*std::cout << "M 7 " << matches[7] << std::endl;*/ + + std::string text = stringUtils::trim(matches[5]); + + TaskItem taskItem = {.text = text, + .state = str.substr(0, 5) == "- [X]" ? DONE : TODO, + .date = date, + .startTime = matches[3], + .endTime = matches[4], + .tags = extractTagsFromMetadata(matches[7])}; + return taskItem; +} + +std::string TodoMdFormat::TaskToString(const TaskItem &task) +{ + std::string str = task.getText(); + if (task.getTags().size() > 0) { + str += " --"; + for (const std::string &tag : task.getTags()) { + str += " " + tag; + } + } + if (task.getStartTime() != "" && task.getEndTime() != "") { + str = task.getStartTime() + "-" + task.getEndTime() + " > " + str; + } + str = (task.getState() == DONE ? "- [X] " : "- [ ] ") + str; + return str; +} +} // namespace mirai diff --git a/src/core/TodoMd.h b/src/core/TodoMd.h index 696939f..3e0d206 100644 --- a/src/core/TodoMd.h +++ b/src/core/TodoMd.h @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -20,23 +20,23 @@ #include #include -namespace mirai { +namespace mirai +{ - class TodoMdFormat { - public: +class TodoMdFormat +{ + public: + static TasksFile readFile(const std::string &path); + static void writeFile(TasksFile &tasks); - static TasksFile readFile(const std::string& path); - static void writeFile(TasksFile& tasks); + static std::string TaskToString(const TaskItem &task); + static TaskItem StringToTask(const std::string &str, const std::string &date); - static std::string TaskToString(const TaskItem& task); - static TaskItem StringToTask(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); - }; -} + private: + static std::string fieldWithSpace(const std::string &field); + static TaskItem parseLine(const std::string &line); + static Tags extractTagsFromMetadata(std::string metadata); +}; +} // namespace mirai #endif diff --git a/src/core/TodoTxt.h b/src/core/TodoTxt.h index 36d437b..6b523f3 100644 --- a/src/core/TodoTxt.h +++ b/src/core/TodoTxt.h @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -20,76 +20,75 @@ /*namespace mirai {*/ - /*class TodoTxtFormat {*/ - /*public:*/ +/*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 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 TaskList readFile() {*/ +/*std::ifstream file("../newqml/todo.txt");*/ +/*if (!file.is_open()) {*/ +/*throw std::runtime_error("todo.txt file not found");*/ +/*}*/ +/*std::vector 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();*/ - /*}*/ +/*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:*/ +/*private:*/ - /*static std::string fieldWithSpace(const std::string& field) {*/ - /*if (field.length() == 0)*/ - /*return "";*/ - /*return (field + " ");*/ - /*}*/ +/*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();*/ - /*}*/ +/*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);*/ - /*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());*/ +/*for (size_t i = 0; i < matches.size(); ++i) {*/ +/*std::ssub_match sub_match = matches[i];*/ +/*std::string piece = sub_match.str();*/ +/*}*/ - /*const std::string date = taskState == DONE ? firstDate : "";*/ +/*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());*/ - - - /*return {*/ - /*.text = text,*/ - /*.state = taskState,*/ - /*.date = date,*/ - /*};*/ - /*}*/ - /*};*/ +/*const std::string date = taskState == DONE ? firstDate : "";*/ + +/*return {*/ +/*.text = text,*/ +/*.state = taskState,*/ +/*.date = date,*/ +/*};*/ +/*}*/ +/*};*/ /*}*/ #endif diff --git a/src/core/using.h b/src/core/using.h index b778971..7f3a671 100644 --- a/src/core/using.h +++ b/src/core/using.h @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -11,8 +11,9 @@ #include #include -namespace mirai { - using Tags = std::vector; +namespace mirai +{ +using Tags = std::vector; } #endif diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 56614bd..e4faa71 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -6,9 +6,11 @@ #include "utils.h" -namespace mirai { - bool isDate(const std::string& dateStr) { - std::regex regex("[0-9]{4}-[0-9]{2}-[0-9]{2}"); - return std::regex_match(dateStr, regex); - } +namespace mirai +{ +bool isDate(const std::string &dateStr) +{ + std::regex regex("[0-9]{4}-[0-9]{2}-[0-9]{2}"); + return std::regex_match(dateStr, regex); } +} // namespace mirai diff --git a/src/core/utils.h b/src/core/utils.h index c43f2dc..6617567 100644 --- a/src/core/utils.h +++ b/src/core/utils.h @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -7,19 +7,19 @@ #ifndef MIRAI_UTILS_H #define MIRAI_UTILS_H -#include +#include #include -#include -#include #include #include +#include +#include -namespace mirai { - namespace stringUtils = cpputils::string; - namespace vectorUtils = cpputils::vector; - - bool isDate(const std::string& dateStr); -} +namespace mirai +{ +namespace stringUtils = cpputils::string; +namespace vectorUtils = cpputils::vector; +bool isDate(const std::string &dateStr); +} // namespace mirai #endif diff --git a/src/main.cpp b/src/main.cpp index 41a3991..ec81fb8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,12 @@ -/* +/* * 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 -#include #include +#include +#include #include #include #include @@ -17,7 +17,7 @@ int main(int argc, char *argv[]) { try { QGuiApplication app(argc, argv); - + qreal refDpi = 54.; qreal refHeight = 1440.; qreal refWidth = 2560.; @@ -25,21 +25,22 @@ int main(int argc, char *argv[]) qreal height = qMax(rect.width(), rect.height()); qreal width = qMin(rect.width(), rect.height()); qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch(); - //auto m_ratio = qMin(height/refHeight, width/refWidth); - auto m_ratioFont = qMin(height*refDpi/(dpi*refHeight), width*refDpi/(dpi*refWidth)); + // auto m_ratio = qMin(height/refHeight, width/refWidth); + auto m_ratioFont = + qMin(height * refDpi / (dpi * refHeight), width * refDpi / (dpi * refWidth)); QFont font("Helvetica", m_ratioFont); app.setFont(font); QQmlApplicationEngine engine; const QUrl url(u"qrc:/qt/qml/Mirai/src/qml/Main.qml"_qs); - QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, - &app, []() { QCoreApplication::exit(-1); }, - Qt::QueuedConnection); + QObject::connect( + &engine, &QQmlApplicationEngine::objectCreationFailed, &app, + []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); - } catch (const std::exception& e) { + } catch (const std::exception &e) { std::cout << e.what() << std::endl; } }