mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 01:33:19 +00:00
Format all c++ files
This commit is contained in:
parent
081e107b9b
commit
f8f49233dc
21 changed files with 683 additions and 599 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ todo.md
|
||||||
.qmlls.ini
|
.qmlls.ini
|
||||||
.clangd
|
.clangd
|
||||||
.cache
|
.cache
|
||||||
|
.nvimrc
|
||||||
|
|
|
@ -8,30 +8,34 @@
|
||||||
#define CPP_UTILS_VECTOR_H
|
#define CPP_UTILS_VECTOR_H
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
|
||||||
#include <optional>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <concepts>
|
|
||||||
|
|
||||||
namespace cpputils::vector {
|
namespace cpputils::vector
|
||||||
|
{
|
||||||
|
|
||||||
template <typename C, typename T>
|
template <typename C, typename T>
|
||||||
concept AnyIterable =
|
concept AnyIterable = std::same_as<typename C::value_type, T> && requires(C c) {
|
||||||
std::same_as<typename C::value_type, T> &&
|
{
|
||||||
requires (C c) {
|
c.begin()
|
||||||
{ c.begin() } -> std::forward_iterator;
|
} -> std::forward_iterator;
|
||||||
{ c.end() } -> std::forward_iterator;
|
{
|
||||||
{ const_cast<const C&>(c).begin() } -> std::forward_iterator;
|
c.end()
|
||||||
{ const_cast<const C&>(c).end() } -> std::forward_iterator;
|
} -> std::forward_iterator;
|
||||||
|
{
|
||||||
|
const_cast<const C &>(c).begin()
|
||||||
|
} -> std::forward_iterator;
|
||||||
|
{
|
||||||
|
const_cast<const C &>(c).end()
|
||||||
|
} -> std::forward_iterator;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template <typename T> bool contains(const std::vector<T> &vec, const T &value)
|
||||||
bool contains(const std::vector<T>& vec, const T& value) {
|
{
|
||||||
return std::ranges::find(vec, value) != vec.end();
|
return std::ranges::find(vec, value) != vec.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template <typename T> bool containsAll(const std::vector<T> &vec, const AnyIterable<T> auto vec2)
|
||||||
bool containsAll(const std::vector<T>& vec, const AnyIterable<T> auto vec2) {
|
{
|
||||||
for (auto &elem : vec) {
|
for (auto &elem : vec) {
|
||||||
if (!contains(vec2, elem)) {
|
if (!contains(vec2, elem)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -39,6 +43,6 @@ namespace cpputils::vector {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
} // namespace cpputils::vector
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,8 +6,10 @@
|
||||||
|
|
||||||
#include "Backend.h"
|
#include "Backend.h"
|
||||||
#include "core/TodoMd.h"
|
#include "core/TodoMd.h"
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
Backend::Backend() {
|
Backend::Backend()
|
||||||
|
{
|
||||||
std::cout << "Backend created" << std::endl;
|
std::cout << "Backend created" << std::endl;
|
||||||
QDir().mkdir(QDir::homePath() + "/.config/mirai");
|
QDir().mkdir(QDir::homePath() + "/.config/mirai");
|
||||||
QFile loadFile(QDir::homePath() + "/.config/mirai/config.json");
|
QFile loadFile(QDir::homePath() + "/.config/mirai/config.json");
|
||||||
|
@ -37,47 +39,55 @@ Backend::Backend() {
|
||||||
rebuildQMLTasksList();
|
rebuildQMLTasksList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend::addTodo(QString newTodo, QString date) {
|
void Backend::addTodo(QString newTodo, QString date)
|
||||||
|
{
|
||||||
mirai.addTask(newTodo.toStdString(), date.toStdString());
|
mirai.addTask(newTodo.toStdString(), date.toStdString());
|
||||||
mirai.save();
|
mirai.save();
|
||||||
rebuildQMLTasksList();
|
rebuildQMLTasksList();
|
||||||
emit tasksChanged();
|
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.addTask(mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString()));
|
||||||
mirai.save();
|
mirai.save();
|
||||||
rebuildQMLTasksList();
|
rebuildQMLTasksList();
|
||||||
emit tasksChanged();
|
emit tasksChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend::addTagFilter(QString tag) {
|
void Backend::addTagFilter(QString tag)
|
||||||
|
{
|
||||||
view.lock()->addTagFilter(tag.toStdString());
|
view.lock()->addTagFilter(tag.toStdString());
|
||||||
rebuildQMLTasksList();
|
rebuildQMLTasksList();
|
||||||
emit tasksChanged();
|
emit tasksChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend::removeTagFilter(QString tag) {
|
void Backend::removeTagFilter(QString tag)
|
||||||
|
{
|
||||||
view.lock()->removeTagFilter(tag.toStdString());
|
view.lock()->removeTagFilter(tag.toStdString());
|
||||||
rebuildQMLTasksList();
|
rebuildQMLTasksList();
|
||||||
emit tasksChanged();
|
emit tasksChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend::removeFilters() {
|
void Backend::removeFilters()
|
||||||
|
{
|
||||||
view.lock()->removeFilters();
|
view.lock()->removeFilters();
|
||||||
rebuildQMLTasksList();
|
rebuildQMLTasksList();
|
||||||
emit tasksChanged();
|
emit tasksChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend::updateTodoFromRawFormat(int todoIndex, QString text, QString date) {
|
void Backend::updateTodoFromRawFormat(int todoIndex, QString text, QString date)
|
||||||
|
{
|
||||||
QMLTaskItem &taskItem = QMLTasks[todoIndex];
|
QMLTaskItem &taskItem = QMLTasks[todoIndex];
|
||||||
*(taskItem.taskItem) = mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString());
|
*(taskItem.taskItem) =
|
||||||
|
mirai::TodoMdFormat::StringToTask(text.toStdString(), date.toStdString());
|
||||||
mirai.save();
|
mirai.save();
|
||||||
rebuildQMLTasksList();
|
rebuildQMLTasksList();
|
||||||
emit tasksChanged();
|
emit tasksChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend::updateTodo(int todoIndex, QString state, QString text, QString date) {
|
void Backend::updateTodo(int todoIndex, QString state, QString text, QString date)
|
||||||
|
{
|
||||||
QMLTaskItem &taskItem = QMLTasks[todoIndex];
|
QMLTaskItem &taskItem = QMLTasks[todoIndex];
|
||||||
taskItem.taskItem->state = state == "TODO" ? mirai::TODO : mirai::DONE;
|
taskItem.taskItem->state = state == "TODO" ? mirai::TODO : mirai::DONE;
|
||||||
if (state == "DONE") {
|
if (state == "DONE") {
|
||||||
|
@ -92,7 +102,8 @@ void Backend::updateTodo(int todoIndex, QString state, QString text, QString dat
|
||||||
emit tasksChanged();
|
emit tasksChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend::removeTodo(int todoIndex) {
|
void Backend::removeTodo(int todoIndex)
|
||||||
|
{
|
||||||
QMLTaskItem &taskItem = QMLTasks[todoIndex];
|
QMLTaskItem &taskItem = QMLTasks[todoIndex];
|
||||||
mirai.removeTask(taskItem.taskItem);
|
mirai.removeTask(taskItem.taskItem);
|
||||||
mirai.save();
|
mirai.save();
|
||||||
|
@ -100,13 +111,15 @@ void Backend::removeTodo(int todoIndex) {
|
||||||
emit tasksChanged();
|
emit tasksChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend::hideCompletedTasks(bool shouldHide) {
|
void Backend::hideCompletedTasks(bool shouldHide)
|
||||||
|
{
|
||||||
shouldHideCompletedTasks_ = shouldHide;
|
shouldHideCompletedTasks_ = shouldHide;
|
||||||
rebuildQMLTasksList();
|
rebuildQMLTasksList();
|
||||||
emit tasksChanged();
|
emit tasksChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend::rebuildQMLTasksList() {
|
void Backend::rebuildQMLTasksList()
|
||||||
|
{
|
||||||
QMLTasks.clear();
|
QMLTasks.clear();
|
||||||
std::string lastDate = "";
|
std::string lastDate = "";
|
||||||
std::time_t t = std::time(nullptr);
|
std::time_t t = std::time(nullptr);
|
||||||
|
@ -115,7 +128,8 @@ void Backend::rebuildQMLTasksList() {
|
||||||
currentDate << std::put_time(&tm, "%Y-%m-%d");
|
currentDate << std::put_time(&tm, "%Y-%m-%d");
|
||||||
for (int i = 0; i < view.lock()->count(); ++i) {
|
for (int i = 0; i < view.lock()->count(); ++i) {
|
||||||
mirai::TaskItem &task = (*view.lock())[i];
|
mirai::TaskItem &task = (*view.lock())[i];
|
||||||
if (shouldHideCompletedTasks_ && task.getState() == mirai::DONE && task.hasDate() && task.getDate() < currentDate.str()) {
|
if (shouldHideCompletedTasks_ && task.getState() == mirai::DONE && task.hasDate() &&
|
||||||
|
task.getDate() < currentDate.str()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
bool shouldShowDate = false;
|
bool shouldShowDate = false;
|
||||||
|
@ -127,14 +141,10 @@ void Backend::rebuildQMLTasksList() {
|
||||||
for (auto &tag : task.getTags()) {
|
for (auto &tag : task.getTags()) {
|
||||||
qStringTags.push_back(QString::fromStdString(tag));
|
qStringTags.push_back(QString::fromStdString(tag));
|
||||||
}
|
}
|
||||||
QMLTasks.push_back({
|
QMLTasks.push_back(
|
||||||
.taskItem = &task,
|
{.taskItem = &task, .shouldShowDate = shouldShowDate, .tags = qStringTags});
|
||||||
.shouldShowDate = shouldShowDate,
|
|
||||||
.tags = qStringTags
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QMLTags.clear();
|
QMLTags.clear();
|
||||||
for (auto &tag : mirai.getTags()) {
|
for (auto &tag : mirai.getTags()) {
|
||||||
QMLTags.push_back(QString::fromStdString(tag));
|
QMLTags.push_back(QString::fromStdString(tag));
|
||||||
|
@ -146,18 +156,22 @@ void Backend::rebuildQMLTasksList() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Backend::getTasks() {
|
QVariant Backend::getTasks()
|
||||||
|
{
|
||||||
return QVariant::fromValue(QMLTasks);
|
return QVariant::fromValue(QMLTasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Backend::getTags() {
|
QVariant Backend::getTags()
|
||||||
|
{
|
||||||
return QVariant::fromValue(QMLTags);
|
return QVariant::fromValue(QMLTags);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Backend::getActiveTagsFilter() {
|
QVariant Backend::getActiveTagsFilter()
|
||||||
|
{
|
||||||
return QVariant::fromValue(QMLActiveTagsFilter);
|
return QVariant::fromValue(QMLActiveTagsFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Backend::shouldHideCompletedTasks() {
|
bool Backend::shouldHideCompletedTasks()
|
||||||
|
{
|
||||||
return shouldHideCompletedTasks_;
|
return shouldHideCompletedTasks_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,21 +10,18 @@
|
||||||
#include "QtCore/qcontainerfwd.h"
|
#include "QtCore/qcontainerfwd.h"
|
||||||
#include "QtCore/qtmetamacros.h"
|
#include "QtCore/qtmetamacros.h"
|
||||||
#include "QtCore/qvariant.h"
|
#include "QtCore/qvariant.h"
|
||||||
#include <QtQml/qqmlregistration.h>
|
|
||||||
#include <QtCore/QObject>
|
|
||||||
#include <QtCore/QDateTime>
|
|
||||||
#include <QtCore/QString>
|
|
||||||
#include <QtCore/QList>
|
|
||||||
#include <QtCore/QDir>
|
|
||||||
#include <QtCore/QJsonObject>
|
|
||||||
#include <QtCore/QJsonDocument>
|
|
||||||
#include <QtCore/QJsonArray>
|
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
|
||||||
#include "core/TaskItem.h"
|
|
||||||
#include "core/TasksView.h"
|
|
||||||
#include "core/TodoMd.h"
|
|
||||||
#include "core/Mirai.h"
|
#include "core/Mirai.h"
|
||||||
|
#include "core/TasksView.h"
|
||||||
|
#include <QtCore/QDateTime>
|
||||||
|
#include <QtCore/QDir>
|
||||||
|
#include <QtCore/QJsonArray>
|
||||||
|
#include <QtCore/QJsonDocument>
|
||||||
|
#include <QtCore/QJsonObject>
|
||||||
|
#include <QtCore/QList>
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
#include <QtCore/QString>
|
||||||
|
#include <QtQml/qqmlregistration.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
|
|
||||||
|
@ -35,10 +32,10 @@ class Backend : public QObject
|
||||||
Q_PROPERTY(QVariant tasks READ getTasks NOTIFY tasksChanged)
|
Q_PROPERTY(QVariant tasks READ getTasks NOTIFY tasksChanged)
|
||||||
Q_PROPERTY(QVariant tags READ getTags NOTIFY tasksChanged)
|
Q_PROPERTY(QVariant tags READ getTags NOTIFY tasksChanged)
|
||||||
Q_PROPERTY(QVariant activeTagsFilter READ getActiveTagsFilter NOTIFY tasksChanged)
|
Q_PROPERTY(QVariant activeTagsFilter READ getActiveTagsFilter NOTIFY tasksChanged)
|
||||||
Q_PROPERTY(bool shouldHideCompletedTasks READ shouldHideCompletedTasks WRITE hideCompletedTasks NOTIFY tasksChanged)
|
Q_PROPERTY(bool shouldHideCompletedTasks READ shouldHideCompletedTasks WRITE hideCompletedTasks
|
||||||
|
NOTIFY tasksChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Backend();
|
Backend();
|
||||||
|
|
||||||
Q_INVOKABLE void addTodo(QString newTodo, QString date);
|
Q_INVOKABLE void addTodo(QString newTodo, QString date);
|
||||||
|
@ -52,7 +49,6 @@ public:
|
||||||
Q_INVOKABLE void hideCompletedTasks(bool shouldHide);
|
Q_INVOKABLE void hideCompletedTasks(bool shouldHide);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void rebuildQMLTasksList();
|
void rebuildQMLTasksList();
|
||||||
|
|
||||||
QVariant getTasks();
|
QVariant getTasks();
|
||||||
|
|
|
@ -7,33 +7,40 @@
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
#include "core/TodoMd.h"
|
#include "core/TodoMd.h"
|
||||||
|
|
||||||
QString QMLTaskItem::getRawFormat() {
|
QString QMLTaskItem::getRawFormat()
|
||||||
|
{
|
||||||
return QString::fromStdString(mirai::TodoMdFormat::TaskToString(*taskItem));
|
return QString::fromStdString(mirai::TodoMdFormat::TaskToString(*taskItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QMLTaskItem::getText() {
|
QString QMLTaskItem::getText()
|
||||||
|
{
|
||||||
return QString::fromStdString(taskItem->getText());
|
return QString::fromStdString(taskItem->getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QMLTaskItem::getState() {
|
QString QMLTaskItem::getState()
|
||||||
|
{
|
||||||
return QString::fromStdString(taskItem->getState() == mirai::TODO ? "TODO" : "DONE");
|
return QString::fromStdString(taskItem->getState() == mirai::TODO ? "TODO" : "DONE");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QMLTaskItem::getDate() {
|
QString QMLTaskItem::getDate()
|
||||||
|
{
|
||||||
return QString::fromStdString(taskItem->getDate());
|
return QString::fromStdString(taskItem->getDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QMLTaskItem::getTime() {
|
QString QMLTaskItem::getTime()
|
||||||
|
{
|
||||||
if (taskItem->getStartTime() != "" && taskItem->getEndTime() != "") {
|
if (taskItem->getStartTime() != "" && taskItem->getEndTime() != "") {
|
||||||
return QString::fromStdString(taskItem->getStartTime() + "-" + taskItem->getEndTime());
|
return QString::fromStdString(taskItem->getStartTime() + "-" + taskItem->getEndTime());
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> QMLTaskItem::getTags() {
|
QList<QString> QMLTaskItem::getTags()
|
||||||
|
{
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QMLTaskItem::getShouldShowDate() {
|
bool QMLTaskItem::getShouldShowDate()
|
||||||
|
{
|
||||||
return shouldShowDate;
|
return shouldShowDate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
#define QML_TASKITEM_H
|
#define QML_TASKITEM_H
|
||||||
|
|
||||||
#include "QtCore/qvariant.h"
|
#include "QtCore/qvariant.h"
|
||||||
#include <QtQml/qqmlregistration.h>
|
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
|
#include <QtQml/qqmlregistration.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "core/TaskItem.h"
|
#include "core/TaskItem.h"
|
||||||
|
@ -27,7 +27,6 @@ struct QMLTaskItem {
|
||||||
QML_VALUE_TYPE(taskItem)
|
QML_VALUE_TYPE(taskItem)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
QString getText();
|
QString getText();
|
||||||
QString getRawFormat();
|
QString getRawFormat();
|
||||||
QString getState();
|
QString getState();
|
||||||
|
|
|
@ -8,35 +8,40 @@
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
#include "cpp-utils/vector.h"
|
#include "cpp-utils/vector.h"
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
|
{
|
||||||
|
|
||||||
void Mirai::loadFile(const std::string& path) {
|
void Mirai::loadFile(const std::string &path)
|
||||||
|
{
|
||||||
auto tasksFile = TodoMdFormat::readFile(path);
|
auto tasksFile = TodoMdFormat::readFile(path);
|
||||||
files->push_back(std::move(tasksFile));
|
files->push_back(std::move(tasksFile));
|
||||||
tags.clear();
|
tags.clear();
|
||||||
for (auto &task : (*files)[0].getTasks()) {
|
for (auto &task : (*files)[0].getTasks()) {
|
||||||
for (auto &tag : task->getTags()) {
|
for (auto &tag : task->getTags()) {
|
||||||
if (vectorUtils::contains(tags, tag)) {
|
if (!vectorUtils::contains(tags, tag)) {
|
||||||
tags.push_back(tag);
|
tags.push_back(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mirai::save() {
|
void Mirai::save()
|
||||||
|
{
|
||||||
for (auto &file : *files) {
|
for (auto &file : *files) {
|
||||||
TodoMdFormat::writeFile(file);
|
TodoMdFormat::writeFile(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mirai::addTask(TaskItem taskItem) {
|
void Mirai::addTask(TaskItem taskItem)
|
||||||
|
{
|
||||||
(*files)[0].addTask(taskItem);
|
(*files)[0].addTask(taskItem);
|
||||||
for (auto &view : views) {
|
for (auto &view : views) {
|
||||||
view->update();
|
view->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mirai::addTask(std::string text, std::string date) {
|
void Mirai::addTask(std::string text, std::string date)
|
||||||
|
{
|
||||||
/*std::time_t t = std::time(nullptr);*/
|
/*std::time_t t = std::time(nullptr);*/
|
||||||
/*std::tm tm = *std::localtime(&t);*/
|
/*std::tm tm = *std::localtime(&t);*/
|
||||||
/*std::stringstream ssCreationDate;*/
|
/*std::stringstream ssCreationDate;*/
|
||||||
|
@ -47,20 +52,23 @@ namespace mirai {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mirai::removeTask(const TaskItem* taskItem) {
|
void Mirai::removeTask(const TaskItem *taskItem)
|
||||||
|
{
|
||||||
(*files)[0].removeTask(taskItem);
|
(*files)[0].removeTask(taskItem);
|
||||||
for (auto &view : views) {
|
for (auto &view : views) {
|
||||||
view->update();
|
view->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::weak_ptr<TasksView> Mirai::getTasks() {
|
std::weak_ptr<TasksView> Mirai::getTasks()
|
||||||
|
{
|
||||||
auto view = std::make_shared<TasksView>(files);
|
auto view = std::make_shared<TasksView>(files);
|
||||||
views.push_back(view);
|
views.push_back(view);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::string>& Mirai::getTags() {
|
const std::vector<std::string> &Mirai::getTags()
|
||||||
|
{
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
}
|
} // namespace mirai
|
||||||
|
|
|
@ -14,12 +14,13 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
|
{
|
||||||
|
|
||||||
class Mirai {
|
class Mirai
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void loadFile(const std::string &path);
|
void loadFile(const std::string &path);
|
||||||
void save();
|
void save();
|
||||||
void addTask(TaskItem taskItem);
|
void addTask(TaskItem taskItem);
|
||||||
|
@ -30,7 +31,6 @@ namespace mirai {
|
||||||
const std::vector<std::string> &getTags();
|
const std::vector<std::string> &getTags();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// The `TasksFile`s are shared to the views, their lifetime can outlive
|
// The `TasksFile`s are shared to the views, their lifetime can outlive
|
||||||
// this (Mirai) object
|
// this (Mirai) object
|
||||||
// because we can't control if the caller will keep the main object alive.
|
// because we can't control if the caller will keep the main object alive.
|
||||||
|
@ -42,5 +42,5 @@ namespace mirai {
|
||||||
std::vector<std::shared_ptr<TasksView>> views;
|
std::vector<std::shared_ptr<TasksView>> views;
|
||||||
std::vector<std::string> tags;
|
std::vector<std::string> tags;
|
||||||
};
|
};
|
||||||
}
|
} // namespace mirai
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,38 +4,69 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
#include "cpp-utils/vector.h"
|
#include "cpp-utils/vector.h"
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
|
{
|
||||||
|
|
||||||
void TaskItem::markAsDone() {
|
void TaskItem::markAsDone()
|
||||||
|
{
|
||||||
state = DONE;
|
state = DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskItem::markAsUndone() {
|
void TaskItem::markAsUndone()
|
||||||
|
{
|
||||||
state = TODO;
|
state = TODO;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskItem::setDate(const std::string& date) {
|
void TaskItem::setDate(const std::string &date)
|
||||||
|
{
|
||||||
this->date = date;
|
this->date = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskItem::setText(const std::string& text) {
|
void TaskItem::setText(const std::string &text)
|
||||||
|
{
|
||||||
this->text = text;
|
this->text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& TaskItem::getText() const { return text; }
|
const std::string &TaskItem::getText() const
|
||||||
const TaskItemState& TaskItem::getState() const { return state; }
|
{
|
||||||
const std::string& TaskItem::getDate() const { return date; }
|
return text;
|
||||||
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); }
|
|
||||||
|
|
||||||
|
const TaskItemState &TaskItem::getState() const
|
||||||
|
{
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
bool TaskItem::hasTag(const std::string& tag) const {
|
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);
|
return vectorUtils::contains(tags, tag);
|
||||||
}
|
}
|
||||||
}
|
} // namespace mirai
|
||||||
|
|
|
@ -20,15 +20,12 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
enum TaskItemState {
|
{
|
||||||
TODO,
|
enum TaskItemState { TODO, DONE };
|
||||||
DONE
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TaskItem {
|
struct TaskItem {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void markAsDone();
|
void markAsDone();
|
||||||
|
|
||||||
void markAsUndone();
|
void markAsUndone();
|
||||||
|
@ -53,6 +50,6 @@ namespace mirai {
|
||||||
std::string endTime;
|
std::string endTime;
|
||||||
Tags tags;
|
Tags tags;
|
||||||
};
|
};
|
||||||
}
|
} // namespace mirai
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,42 +8,58 @@
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
|
{
|
||||||
|
|
||||||
TasksFile::TasksFile(TasksFileConstructor params) : name(params.name), path(params.path) {
|
TasksFile::TasksFile(TasksFileConstructor params) : name(params.name), path(params.path)
|
||||||
|
{
|
||||||
for (const auto &task : params.tasks) {
|
for (const auto &task : params.tasks) {
|
||||||
tasks.push_back(std::make_unique<TaskItem>(task));
|
tasks.push_back(std::make_unique<TaskItem>(task));
|
||||||
}
|
}
|
||||||
sortByDate();
|
sortByDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& TasksFile::getName() const { return name; }
|
const std::string &TasksFile::getName() const
|
||||||
const std::string& TasksFile::getPath() const { return path; }
|
{
|
||||||
TasksPtrs& TasksFile::getTasks() { return tasks; }
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
void TasksFile::addTask(TaskItem taskItem) {
|
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>(taskItem));
|
tasks.push_back(std::make_unique<TaskItem>(taskItem));
|
||||||
sortByDate();
|
sortByDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TasksFile::addTask(std::string text, std::string date) {
|
void TasksFile::addTask(std::string text, std::string date)
|
||||||
auto newTask = std::make_unique<TaskItem>(TaskItem{
|
{
|
||||||
.text = text,
|
auto newTask = std::make_unique<TaskItem>(
|
||||||
.state = TODO,
|
TaskItem{.text = text, .state = TODO, .date = date == "" ? "No date" : date});
|
||||||
.date = date == "" ? "No date" : date
|
|
||||||
});
|
|
||||||
tasks.push_back(std::move(newTask));
|
tasks.push_back(std::move(newTask));
|
||||||
sortByDate();
|
sortByDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TasksFile::removeTask(const TaskItem* taskToRemove) {
|
void TasksFile::removeTask(const TaskItem *taskToRemove)
|
||||||
tasks.erase(std::remove_if(tasks.begin(), tasks.end(), [&] (const std::unique_ptr<TaskItem>& taskInFilter){
|
{
|
||||||
|
tasks.erase(std::remove_if(tasks.begin(), tasks.end(),
|
||||||
|
[&](const std::unique_ptr<TaskItem> &taskInFilter) {
|
||||||
return taskInFilter.get() == taskToRemove;
|
return taskInFilter.get() == taskToRemove;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TasksFile::sortByDate() {
|
void TasksFile::sortByDate()
|
||||||
std::sort(tasks.begin(), tasks.end(), [] (const std::unique_ptr<TaskItem>& t1, const std::unique_ptr<TaskItem>& t2) {
|
{
|
||||||
|
std::sort(tasks.begin(), tasks.end(),
|
||||||
|
[](const std::unique_ptr<TaskItem> &t1, const std::unique_ptr<TaskItem> &t2) {
|
||||||
if (t1->hasDate() && !t2->hasDate()) {
|
if (t1->hasDate() && !t2->hasDate()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (!t1->hasDate() && t2->hasDate()) {
|
} else if (!t1->hasDate() && t2->hasDate()) {
|
||||||
|
@ -52,4 +68,4 @@ namespace mirai {
|
||||||
return t1->date < t2->date;
|
return t1->date < t2->date;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
} // namespace mirai
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
#ifndef MIRAI_TASKSFILE_H
|
#ifndef MIRAI_TASKSFILE_H
|
||||||
#define MIRAI_TASKSFILE_H
|
#define MIRAI_TASKSFILE_H
|
||||||
|
|
||||||
|
#include "TaskItem.h"
|
||||||
|
#include "using.h"
|
||||||
|
#include "utils.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -19,12 +22,9 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "TaskItem.h"
|
|
||||||
#include "using.h"
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
namespace mirai {
|
|
||||||
|
|
||||||
|
namespace mirai
|
||||||
|
{
|
||||||
|
|
||||||
using TasksPtrs = std::vector<std::unique_ptr<TaskItem>>;
|
using TasksPtrs = std::vector<std::unique_ptr<TaskItem>>;
|
||||||
|
|
||||||
|
@ -34,10 +34,10 @@ namespace mirai {
|
||||||
std::vector<TaskItem> tasks;
|
std::vector<TaskItem> tasks;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TasksFile {
|
class TasksFile
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TasksFile(TasksFileConstructor params);
|
TasksFile(TasksFileConstructor params);
|
||||||
|
|
||||||
void addTask(std::string text, std::string date);
|
void addTask(std::string text, std::string date);
|
||||||
|
@ -54,6 +54,6 @@ namespace mirai {
|
||||||
std::string path;
|
std::string path;
|
||||||
TasksPtrs tasks;
|
TasksPtrs tasks;
|
||||||
};
|
};
|
||||||
}
|
} // namespace mirai
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,53 +7,63 @@
|
||||||
#include "TasksView.h"
|
#include "TasksView.h"
|
||||||
#include "cpp-utils/vector.h"
|
#include "cpp-utils/vector.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
|
{
|
||||||
|
|
||||||
|
TasksView::TasksView(std::shared_ptr<std::vector<TasksFile>> files) : files(files)
|
||||||
TasksView::TasksView(std::shared_ptr<std::vector<TasksFile>> files) : files(files) {
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskItem& TasksView::operator[](int index) {
|
TaskItem &TasksView::operator[](int index)
|
||||||
|
{
|
||||||
return *(tasksToShow.at(index));
|
return *(tasksToShow.at(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
int TasksView::count() const { return tasksToShow.size(); }
|
size_t TasksView::count() const
|
||||||
|
{
|
||||||
|
return tasksToShow.size();
|
||||||
|
}
|
||||||
|
|
||||||
void TasksView::update() {
|
void TasksView::update()
|
||||||
|
{
|
||||||
tasksToShow.clear();
|
tasksToShow.clear();
|
||||||
for (auto &file : *files) {
|
for (auto &file : *files) {
|
||||||
for (auto &task : file.getTasks()) {
|
for (auto &task : file.getTasks()) {
|
||||||
std::function<bool(const std::string&)> f = [&](const std::string& tag) {
|
if (tagsFilter.size() > 0 && !vectorUtils::containsAll(tagsFilter, task->getTags())) {
|
||||||
return task->hasTag(tag);
|
|
||||||
};
|
|
||||||
if (tagsFilter.size() > 0 && !vectorUtils::containsAll(tagsFilter, task->getTags()))
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
tasksToShow.push_back(task.get());
|
tasksToShow.push_back(task.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TasksView::addTagFilter(const std::string& tag) {
|
void TasksView::addTagFilter(const std::string &tag)
|
||||||
|
{
|
||||||
tagsFilter.push_back(tag);
|
tagsFilter.push_back(tag);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TasksView::removeTagFilter(const std::string& tag) {
|
void TasksView::removeTagFilter(const std::string &tag)
|
||||||
tagsFilter.erase(std::remove_if(tagsFilter.begin(), tagsFilter.end(), [&] (const auto& tagInFilter){
|
{
|
||||||
return tag == tagInFilter;
|
tagsFilter.erase(std::remove_if(tagsFilter.begin(), tagsFilter.end(),
|
||||||
}));
|
[&](const auto &tagInFilter) { return tag == tagInFilter; }));
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TasksView::removeFilters() {
|
void TasksView::removeFilters()
|
||||||
|
{
|
||||||
tagsFilter.clear();
|
tagsFilter.clear();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::string>& TasksView::getActiveTagsFilter() {
|
const std::vector<std::string> &TasksView::getActiveTagsFilter()
|
||||||
|
{
|
||||||
return tagsFilter;
|
return tagsFilter;
|
||||||
}
|
}
|
||||||
}
|
} // namespace mirai
|
||||||
|
|
|
@ -8,23 +8,22 @@
|
||||||
#define MIRAI_TASKSVIEW_H
|
#define MIRAI_TASKSVIEW_H
|
||||||
#include "TasksFile.h"
|
#include "TasksFile.h"
|
||||||
#include "using.h"
|
#include "using.h"
|
||||||
#include <algorithm>
|
#include <cstddef>
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <ostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
|
{
|
||||||
|
|
||||||
class TasksView {
|
class TasksView
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TasksView(std::shared_ptr<std::vector<TasksFile>> files);
|
TasksView(std::shared_ptr<std::vector<TasksFile>> files);
|
||||||
|
|
||||||
TaskItem &operator[](int index);
|
TaskItem &operator[](int index);
|
||||||
|
|
||||||
int count() const;
|
size_t count() const;
|
||||||
void update();
|
void update();
|
||||||
void addTagFilter(const std::string &tag);
|
void addTagFilter(const std::string &tag);
|
||||||
void removeTagFilter(const std::string &tag);
|
void removeTagFilter(const std::string &tag);
|
||||||
|
@ -32,10 +31,9 @@ namespace mirai {
|
||||||
const Tags &getActiveTagsFilter();
|
const Tags &getActiveTagsFilter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::shared_ptr<std::vector<TasksFile>> files;
|
std::shared_ptr<std::vector<TasksFile>> files;
|
||||||
std::vector<TaskItem *> tasksToShow;
|
std::vector<TaskItem *> tasksToShow;
|
||||||
Tags tagsFilter;
|
Tags tagsFilter;
|
||||||
};
|
};
|
||||||
}
|
} // namespace mirai
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,9 +8,11 @@
|
||||||
#include "TaskItem.h"
|
#include "TaskItem.h"
|
||||||
#include "cpp-utils/vector.h"
|
#include "cpp-utils/vector.h"
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
|
{
|
||||||
|
|
||||||
TasksFile TodoMdFormat::readFile(const std::string& path) {
|
TasksFile TodoMdFormat::readFile(const std::string &path)
|
||||||
|
{
|
||||||
std::ifstream file(path);
|
std::ifstream file(path);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
throw std::runtime_error("todo.txt file not found");
|
throw std::runtime_error("todo.txt file not found");
|
||||||
|
@ -35,22 +37,18 @@ namespace mirai {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
TasksFile tasks({
|
TasksFile tasks({.name = name, .path = path, .tasks = taskItems});
|
||||||
.name = name,
|
|
||||||
.path = path,
|
|
||||||
.tasks = taskItems
|
|
||||||
});
|
|
||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tags TodoMdFormat::extractTagsFromMetadata(std::string metadata) {
|
Tags TodoMdFormat::extractTagsFromMetadata(std::string metadata)
|
||||||
|
{
|
||||||
Tags tags;
|
Tags tags;
|
||||||
|
|
||||||
std::regex regex("(#[a-zA-Z0-1]+)");
|
std::regex regex("(#[a-zA-Z0-1]+)");
|
||||||
std::smatch matches;
|
std::smatch matches;
|
||||||
|
|
||||||
while (std::regex_search(metadata, matches, regex))
|
while (std::regex_search(metadata, matches, regex)) {
|
||||||
{
|
|
||||||
if (!vectorUtils::contains(tags, matches[0].str())) {
|
if (!vectorUtils::contains(tags, matches[0].str())) {
|
||||||
tags.push_back(matches[0]);
|
tags.push_back(matches[0]);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +57,8 @@ namespace mirai {
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TodoMdFormat::writeFile(TasksFile& tasks) {
|
void TodoMdFormat::writeFile(TasksFile &tasks)
|
||||||
|
{
|
||||||
std::ofstream file(tasks.getPath());
|
std::ofstream file(tasks.getPath());
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
throw std::runtime_error("can't create todo.txt");
|
throw std::runtime_error("can't create todo.txt");
|
||||||
|
@ -77,15 +76,18 @@ namespace mirai {
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TodoMdFormat::fieldWithSpace(const std::string& field) {
|
std::string TodoMdFormat::fieldWithSpace(const std::string &field)
|
||||||
|
{
|
||||||
if (field.length() == 0)
|
if (field.length() == 0)
|
||||||
return "";
|
return "";
|
||||||
return (field + " ");
|
return (field + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskItem TodoMdFormat::StringToTask(const std::string& str, const std::string& date) {
|
TaskItem TodoMdFormat::StringToTask(const std::string &str, const std::string &date)
|
||||||
|
{
|
||||||
std::smatch matches;
|
std::smatch matches;
|
||||||
std::regex regex("- \\[(\\s|X)\\] (([0-9]{2}:[0-9]{2})-([0-9]{2}:[0-9]{2}) > )?(.*?)( -- (.*))?");
|
std::regex regex(
|
||||||
|
"- \\[(\\s|X)\\] (([0-9]{2}:[0-9]{2})-([0-9]{2}:[0-9]{2}) > )?(.*?)( -- (.*))?");
|
||||||
std::regex_match(str, matches, regex);
|
std::regex_match(str, matches, regex);
|
||||||
|
|
||||||
/*std::cout << "line " << str << std::endl;*/
|
/*std::cout << "line " << str << std::endl;*/
|
||||||
|
@ -100,18 +102,17 @@ namespace mirai {
|
||||||
|
|
||||||
std::string text = stringUtils::trim(matches[5]);
|
std::string text = stringUtils::trim(matches[5]);
|
||||||
|
|
||||||
TaskItem taskItem = {
|
TaskItem taskItem = {.text = text,
|
||||||
.text = text,
|
|
||||||
.state = str.substr(0, 5) == "- [X]" ? DONE : TODO,
|
.state = str.substr(0, 5) == "- [X]" ? DONE : TODO,
|
||||||
.date = date,
|
.date = date,
|
||||||
.startTime = matches[3],
|
.startTime = matches[3],
|
||||||
.endTime = matches[4],
|
.endTime = matches[4],
|
||||||
.tags = extractTagsFromMetadata(matches[7])
|
.tags = extractTagsFromMetadata(matches[7])};
|
||||||
};
|
|
||||||
return taskItem;
|
return taskItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TodoMdFormat::TaskToString(const TaskItem& task) {
|
std::string TodoMdFormat::TaskToString(const TaskItem &task)
|
||||||
|
{
|
||||||
std::string str = task.getText();
|
std::string str = task.getText();
|
||||||
if (task.getTags().size() > 0) {
|
if (task.getTags().size() > 0) {
|
||||||
str += " --";
|
str += " --";
|
||||||
|
@ -125,5 +126,4 @@ namespace mirai {
|
||||||
str = (task.getState() == DONE ? "- [X] " : "- [ ] ") + str;
|
str = (task.getState() == DONE ? "- [X] " : "- [ ] ") + str;
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
}
|
} // namespace mirai
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,12 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
|
{
|
||||||
|
|
||||||
class TodoMdFormat {
|
class TodoMdFormat
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static TasksFile readFile(const std::string &path);
|
static TasksFile readFile(const std::string &path);
|
||||||
static void writeFile(TasksFile &tasks);
|
static void writeFile(TasksFile &tasks);
|
||||||
|
|
||||||
|
@ -32,11 +33,10 @@ namespace mirai {
|
||||||
static TaskItem StringToTask(const std::string &str, const std::string &date);
|
static TaskItem StringToTask(const std::string &str, const std::string &date);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static std::string fieldWithSpace(const std::string &field);
|
static std::string fieldWithSpace(const std::string &field);
|
||||||
static TaskItem parseLine(const std::string &line);
|
static TaskItem parseLine(const std::string &line);
|
||||||
static Tags extractTagsFromMetadata(std::string metadata);
|
static Tags extractTagsFromMetadata(std::string metadata);
|
||||||
};
|
};
|
||||||
}
|
} // namespace mirai
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -65,7 +65,8 @@
|
||||||
|
|
||||||
/*static TaskItem parseLine(const std::string& line) {*/
|
/*static TaskItem parseLine(const std::string& line) {*/
|
||||||
/*std::smatch matches;*/
|
/*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 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);*/
|
/*std::regex_match(line, matches, regex);*/
|
||||||
|
|
||||||
/*for (size_t i = 0; i < matches.size(); ++i) {*/
|
/*for (size_t i = 0; i < matches.size(); ++i) {*/
|
||||||
|
@ -81,8 +82,6 @@
|
||||||
|
|
||||||
/*const std::string date = taskState == DONE ? firstDate : "";*/
|
/*const std::string date = taskState == DONE ? firstDate : "";*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*return {*/
|
/*return {*/
|
||||||
/*.text = text,*/
|
/*.text = text,*/
|
||||||
/*.state = taskState,*/
|
/*.state = taskState,*/
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
|
{
|
||||||
using Tags = std::vector<std::string>;
|
using Tags = std::vector<std::string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,11 @@
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
bool isDate(const std::string& dateStr) {
|
{
|
||||||
|
bool isDate(const std::string &dateStr)
|
||||||
|
{
|
||||||
std::regex regex("[0-9]{4}-[0-9]{2}-[0-9]{2}");
|
std::regex regex("[0-9]{4}-[0-9]{2}-[0-9]{2}");
|
||||||
return std::regex_match(dateStr, regex);
|
return std::regex_match(dateStr, regex);
|
||||||
}
|
}
|
||||||
}
|
} // namespace mirai
|
||||||
|
|
|
@ -9,17 +9,17 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <locale>
|
|
||||||
#include <regex>
|
|
||||||
#include <cpp-utils/string.h>
|
#include <cpp-utils/string.h>
|
||||||
#include <cpp-utils/vector.h>
|
#include <cpp-utils/vector.h>
|
||||||
|
#include <locale>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
namespace mirai {
|
namespace mirai
|
||||||
|
{
|
||||||
namespace stringUtils = cpputils::string;
|
namespace stringUtils = cpputils::string;
|
||||||
namespace vectorUtils = cpputils::vector;
|
namespace vectorUtils = cpputils::vector;
|
||||||
|
|
||||||
bool isDate(const std::string &dateStr);
|
bool isDate(const std::string &dateStr);
|
||||||
}
|
} // namespace mirai
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
13
src/main.cpp
13
src/main.cpp
|
@ -4,9 +4,9 @@
|
||||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QtGui/QGuiApplication>
|
|
||||||
#include <QtGui/QFont>
|
|
||||||
#include <QtCore/QRect>
|
#include <QtCore/QRect>
|
||||||
|
#include <QtGui/QFont>
|
||||||
|
#include <QtGui/QGuiApplication>
|
||||||
#include <QtGui/QScreen>
|
#include <QtGui/QScreen>
|
||||||
#include <QtQml/QQmlApplicationEngine>
|
#include <QtQml/QQmlApplicationEngine>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
@ -26,16 +26,17 @@ int main(int argc, char *argv[])
|
||||||
qreal width = qMin(rect.width(), rect.height());
|
qreal width = qMin(rect.width(), rect.height());
|
||||||
qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch();
|
qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch();
|
||||||
// auto m_ratio = qMin(height/refHeight, width/refWidth);
|
// auto m_ratio = qMin(height/refHeight, width/refWidth);
|
||||||
auto m_ratioFont = qMin(height*refDpi/(dpi*refHeight), width*refDpi/(dpi*refWidth));
|
auto m_ratioFont =
|
||||||
|
qMin(height * refDpi / (dpi * refHeight), width * refDpi / (dpi * refWidth));
|
||||||
|
|
||||||
QFont font("Helvetica", m_ratioFont);
|
QFont font("Helvetica", m_ratioFont);
|
||||||
app.setFont(font);
|
app.setFont(font);
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
const QUrl url(u"qrc:/qt/qml/Mirai/src/qml/Main.qml"_qs);
|
const QUrl url(u"qrc:/qt/qml/Mirai/src/qml/Main.qml"_qs);
|
||||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
QObject::connect(
|
||||||
&app, []() { QCoreApplication::exit(-1); },
|
&engine, &QQmlApplicationEngine::objectCreationFailed, &app,
|
||||||
Qt::QueuedConnection);
|
[]() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);
|
||||||
engine.load(url);
|
engine.load(url);
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue