mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 10:13:42 +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,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 <ostream>
|
||||
|
||||
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<QString> 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_;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue