mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-01 17:03:19 +00:00
Ui changes, remove unused buttons
This commit is contained in:
parent
36a2fe9220
commit
e28ba796cd
53 changed files with 133 additions and 27125 deletions
25
external/mirai-core-old/CMakeLists.txt
vendored
25
external/mirai-core-old/CMakeLists.txt
vendored
|
@ -1,25 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.21)
|
||||
project(mirai LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
|
||||
|
||||
add_library(mirai-core
|
||||
src/Mirai.cpp
|
||||
src/Config.cpp
|
||||
src/ConfigImpl.cpp
|
||||
src/TaskItem.cpp
|
||||
src/Day.cpp
|
||||
src/Event.cpp
|
||||
src/DateTime.cpp
|
||||
src/EventEmitter.cpp
|
||||
src/BaseSource.cpp
|
||||
src/StdFileSource.cpp
|
||||
src/TasksView.cpp
|
||||
src/TodoMd.cpp
|
||||
src/utils.cpp
|
||||
)
|
||||
|
||||
target_include_directories(mirai-core PRIVATE "external")
|
||||
target_include_directories(mirai-core PRIVATE "include/mirai-core")
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef CPP_UTILS_DEBUG_H
|
||||
#define CPP_UTILS_DEBUG_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
namespace cpputils::debug
|
||||
{
|
||||
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
Timer() : startTime(std::chrono::steady_clock::now())
|
||||
{
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
startTime = std::chrono::steady_clock::now();
|
||||
isRunning = true;
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
duration += std::chrono::duration_cast<std::chrono::milliseconds>(now - startTime).count();
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
duration = 0;
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
void printTimeElapsed(const std::string &message) const
|
||||
{
|
||||
long durationToShow = duration;
|
||||
if (isRunning) {
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
durationToShow +=
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(now - startTime).count();
|
||||
}
|
||||
std::cout << "[Debug - Timer] " << message << ": " << durationToShow << " ms" << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
std::chrono::time_point<std::chrono::steady_clock, std::chrono::nanoseconds> startTime;
|
||||
|
||||
// Timer are always running when created. You can use .reset() after creation.
|
||||
bool isRunning = true;
|
||||
long duration = 0;
|
||||
};
|
||||
} // namespace cpputils::debug
|
||||
|
||||
#endif
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef CPP_UTILS_STRING_H
|
||||
#define CPP_UTILS_STRING_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
namespace cpputils::string {
|
||||
|
||||
inline std::string trim(std::string str) {
|
||||
str.erase(str.begin(), std::ranges::find_if(str, [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}));
|
||||
str.erase(std::ranges::find_if(str.rbegin(), str.rend(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}).base(), str.end());
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#ifndef CPP_UTILS_VECTOR_H
|
||||
#define CPP_UTILS_VECTOR_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace cpputils::vector
|
||||
{
|
||||
|
||||
template <typename C, typename T>
|
||||
concept AnyIterable = std::same_as<typename C::value_type, T> && requires(C c) {
|
||||
{
|
||||
c.begin()
|
||||
} -> std::forward_iterator;
|
||||
{
|
||||
c.end()
|
||||
} -> std::forward_iterator;
|
||||
{
|
||||
const_cast<const C &>(c).begin()
|
||||
} -> std::forward_iterator;
|
||||
{
|
||||
const_cast<const C &>(c).end()
|
||||
} -> std::forward_iterator;
|
||||
};
|
||||
|
||||
template <typename T> bool contains(const std::vector<T> &vec, const T &value)
|
||||
{
|
||||
return std::ranges::find(vec, value) != vec.end();
|
||||
}
|
||||
|
||||
template <typename T> bool containsAll(const std::vector<T> &vec, const AnyIterable<T> auto vec2)
|
||||
{
|
||||
for (auto &elem : vec) {
|
||||
if (!contains(vec2, elem)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace cpputils::vector
|
||||
|
||||
#endif
|
24767
external/mirai-core-old/external/nlohmann/json.hpp
vendored
24767
external/mirai-core-old/external/nlohmann/json.hpp
vendored
File diff suppressed because it is too large
Load diff
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BaseSource.h"
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct BaseFileSourceConstructor {
|
||||
std::string name;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
class BaseFileSource : public BaseSource
|
||||
{
|
||||
public:
|
||||
BaseFileSource(BaseFileSourceConstructor data) : BaseSource(data.name), path(data.path) {};
|
||||
|
||||
BaseFileSource(BaseFileSource &) = delete;
|
||||
BaseFileSource(BaseFileSource &&) = delete;
|
||||
~BaseFileSource() override = default;
|
||||
|
||||
const std::string &getPath() const
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string path;
|
||||
};
|
||||
} // namespace mirai
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DateTime.h"
|
||||
#include "Day.h"
|
||||
#include "Event.h"
|
||||
#include "TaskItem.h"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct SourceData {
|
||||
std::vector<std::unique_ptr<Day>> days;
|
||||
std::vector<std::unique_ptr<Event>> events;
|
||||
std::vector<std::unique_ptr<TaskItem>> tasks;
|
||||
};
|
||||
|
||||
struct createTaskParams {
|
||||
std::string title;
|
||||
std::optional<Event> event;
|
||||
std::optional<Date> date;
|
||||
};
|
||||
|
||||
struct createEventParams {
|
||||
std::string title;
|
||||
Date date;
|
||||
Time startsAt;
|
||||
Time endsAt;
|
||||
};
|
||||
|
||||
class BaseSource
|
||||
{
|
||||
|
||||
public:
|
||||
struct AddTaskData {
|
||||
std::string text;
|
||||
Tags tags;
|
||||
};
|
||||
|
||||
BaseSource(std::string name) : name_(name) {};
|
||||
BaseSource(BaseSource &) = delete;
|
||||
BaseSource(BaseSource &&) = delete;
|
||||
|
||||
virtual ~BaseSource() = default;
|
||||
virtual void save() = 0;
|
||||
virtual void load() = 0;
|
||||
|
||||
void setName(std::string name);
|
||||
const std::string &getName() const;
|
||||
|
||||
void createTask(const createTaskParams &task);
|
||||
void removeTask(const TaskItem &task);
|
||||
|
||||
TaskItem *getTaskById(int taskId);
|
||||
Event *getEventById(int eventId);
|
||||
Day *day(const Date &date);
|
||||
|
||||
// --
|
||||
|
||||
// void addDay(const DayData &dayData);
|
||||
// void addUnscheduledTask(const TaskItemData &taskData);
|
||||
// std::vector<std::unique_ptr<TaskItem>> *unscheduledTasks();
|
||||
// std::vector<std::unique_ptr<Day>> *days();
|
||||
|
||||
// void deleteTask(const TaskItem &task);
|
||||
|
||||
void setDirty(bool shouldBeDirty);
|
||||
bool isDirty() const;
|
||||
|
||||
int id() const;
|
||||
|
||||
private:
|
||||
static int nextId_;
|
||||
int id_ = nextId_++;
|
||||
std::string name_;
|
||||
SourceData data;
|
||||
// std::vector<std::unique_ptr<Day>> days_;
|
||||
// std::vector<std::unique_ptr<TaskItem>> unscheduledTasks_;
|
||||
bool isDirty_ = false;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class ConfigImpl;
|
||||
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
Config(const std::string &path);
|
||||
~Config();
|
||||
|
||||
std::vector<std::string> sources() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<ConfigImpl> impl_;
|
||||
};
|
||||
} // namespace mirai
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <bits/chrono.h>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct Date {
|
||||
explicit Date(int year, unsigned month, unsigned day);
|
||||
|
||||
explicit Date(std::chrono::time_point<std::chrono::system_clock> tp);
|
||||
explicit Date(std::chrono::year_month_day chronoDate);
|
||||
|
||||
bool operator==(const Date &other) const;
|
||||
bool operator<(const Date &other) const;
|
||||
bool operator>(const Date &other) const;
|
||||
|
||||
std::chrono::year_month_day toStdChrono() const
|
||||
{
|
||||
return std::chrono::year_month_day{
|
||||
std::chrono::year(year),
|
||||
std::chrono::month(month),
|
||||
std::chrono::day(day),
|
||||
};
|
||||
}
|
||||
|
||||
int year;
|
||||
unsigned month;
|
||||
unsigned day;
|
||||
};
|
||||
|
||||
struct Time {
|
||||
|
||||
bool operator==(const Time &other) const;
|
||||
bool operator<(const Time &other) const;
|
||||
bool operator>(const Time &other) const;
|
||||
|
||||
int hour;
|
||||
int minute;
|
||||
};
|
||||
|
||||
std::optional<mirai::Date> stringToDate(const std::string &dateStr);
|
||||
|
||||
} // namespace mirai
|
56
external/mirai-core-old/include/mirai-core/Day.h
vendored
56
external/mirai-core-old/include/mirai-core/Day.h
vendored
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DateTime.h"
|
||||
#include "Event.h"
|
||||
#include "TaskItem.h"
|
||||
#include "using.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class BaseSource;
|
||||
|
||||
struct DayData {
|
||||
Date date;
|
||||
std::vector<EventData> events;
|
||||
std::vector<TaskItemData> tasks;
|
||||
};
|
||||
|
||||
class Day
|
||||
{
|
||||
public:
|
||||
Day(BaseSource *source, const DayData &data);
|
||||
void setDate(const Date &date);
|
||||
|
||||
Event *createEvent(const EventData &eventData);
|
||||
TaskItem *createTask(const TaskItemData &taskData);
|
||||
void insertTask(std::unique_ptr<TaskItem> &&task);
|
||||
void deleteTask(const TaskItem &taskToDelete);
|
||||
std::optional<std::unique_ptr<TaskItem>> takeTask(const TaskItem &taskToDelete);
|
||||
void deleteEvent(const Event &eventToDelete);
|
||||
std::vector<std::unique_ptr<Event>> *events();
|
||||
std::vector<std::unique_ptr<TaskItem>> *tasks();
|
||||
|
||||
const Date &getDate() const;
|
||||
|
||||
Event *getEventById(int eventId);
|
||||
BaseSource *source();
|
||||
|
||||
private:
|
||||
void onChange();
|
||||
|
||||
BaseSource *source_;
|
||||
std::vector<std::unique_ptr<Event>> events_;
|
||||
std::vector<std::unique_ptr<TaskItem>> tasks_;
|
||||
DayData data_;
|
||||
};
|
||||
} // namespace mirai
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DateTime.h"
|
||||
#include "TaskItem.h"
|
||||
#include "using.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class BaseSource;
|
||||
|
||||
struct EventData {
|
||||
std::string description;
|
||||
Date date;
|
||||
Time startTime;
|
||||
Time endTime;
|
||||
Tags tags;
|
||||
std::vector<TaskItemData> tasks;
|
||||
};
|
||||
|
||||
class Day;
|
||||
|
||||
class Event
|
||||
{
|
||||
private:
|
||||
public:
|
||||
Event(BaseSource *source, Day *parent, const EventData &data);
|
||||
|
||||
Event &operator=(const EventData &newData);
|
||||
|
||||
void setText(const std::string &text);
|
||||
void setStartTime(const Time &time);
|
||||
void setEndTime(const Time &time);
|
||||
|
||||
TaskItem *createTask(const TaskItemData &taskData);
|
||||
void deleteTask(const TaskItem &taskToDelete);
|
||||
std::vector<std::unique_ptr<TaskItem>> *tasks();
|
||||
|
||||
const std::string &getText() const;
|
||||
const Date &getDate() const;
|
||||
const Time &getStartTime() const;
|
||||
const Time &getEndTime() const;
|
||||
const Tags &getTags() const;
|
||||
bool hasTag(const std::string &tag) const;
|
||||
|
||||
int id() const;
|
||||
Day *day();
|
||||
|
||||
private:
|
||||
void onChange();
|
||||
|
||||
static int nextId;
|
||||
int id_ = nextId++;
|
||||
Day *day_;
|
||||
EventData data;
|
||||
std::vector<std::unique_ptr<TaskItem>> tasks_;
|
||||
BaseSource *source_;
|
||||
};
|
||||
} // namespace mirai
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
template <typename T> class EventEmitter
|
||||
{
|
||||
|
||||
public:
|
||||
void registerCallback(std::function<T> func)
|
||||
{
|
||||
callbacks.push_back(func);
|
||||
}
|
||||
|
||||
void emit(T data)
|
||||
{
|
||||
for (auto &callback : callbacks) {
|
||||
callback(data);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::function<T>> callbacks;
|
||||
};
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BaseFileSource.h"
|
||||
#include "BaseSource.h"
|
||||
#include "TaskItem.h"
|
||||
#include "TodoMd.h"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class Mirai
|
||||
{
|
||||
|
||||
public:
|
||||
void loadSource(std::unique_ptr<BaseSource> &&resource);
|
||||
void unloadAllSources();
|
||||
void save();
|
||||
void deleteTask(const TaskItem &taskItem);
|
||||
std::optional<std::reference_wrapper<Source>> getSourceByName(const std::string &name);
|
||||
|
||||
std::vector<std::unique_ptr<BaseSource>> &getSources();
|
||||
const std::vector<std::string> &getTags();
|
||||
|
||||
void reloadTags();
|
||||
|
||||
// Returns a non owning pointer to the requested resource or nullptr if not found.
|
||||
BaseSource *getSourceById(int id);
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<BaseSource>> sources_;
|
||||
std::vector<std::string> tags_;
|
||||
};
|
||||
} // namespace mirai
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BaseFileSource.h"
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class StdFileSource : public BaseFileSource
|
||||
{
|
||||
public:
|
||||
StdFileSource(BaseFileSourceConstructor data) : BaseFileSource(data) {};
|
||||
StdFileSource(StdFileSource &) = delete;
|
||||
StdFileSource(StdFileSource &&) = delete;
|
||||
StdFileSource operator=(StdFileSource &) = delete;
|
||||
StdFileSource operator=(StdFileSource &&) = delete;
|
||||
|
||||
~StdFileSource() override = default;
|
||||
|
||||
void save() override;
|
||||
void load() override;
|
||||
;
|
||||
};
|
||||
} // namespace mirai
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "using.h"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class SourceDataProvider;
|
||||
class Day;
|
||||
|
||||
enum TaskItemState { TODO, DONE };
|
||||
|
||||
struct TaskItemData {
|
||||
std::string text;
|
||||
TaskItemState state;
|
||||
Tags tags;
|
||||
};
|
||||
|
||||
class TaskItem
|
||||
{
|
||||
public:
|
||||
TaskItem(SourceDataProvider *source, Day *day, const TaskItemData data);
|
||||
|
||||
TaskItem &operator=(const TaskItemData &newData);
|
||||
|
||||
void markAsDone();
|
||||
void markAsUndone();
|
||||
void setDate(const std::string &date);
|
||||
void setText(const std::string &text);
|
||||
|
||||
const std::string &getLine() const;
|
||||
const std::string &getText() const;
|
||||
const TaskItemState &getState() const;
|
||||
const Tags &getTags() const;
|
||||
bool hasTag(const std::string &tag) const;
|
||||
|
||||
int id() const;
|
||||
SourceDataProvider *source();
|
||||
Day *day();
|
||||
|
||||
private:
|
||||
void onChange();
|
||||
|
||||
static int nextId;
|
||||
int id_ = nextId++;
|
||||
TaskItemData data;
|
||||
|
||||
SourceDataProvider *source_;
|
||||
Day *day_;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "Mirai.h"
|
||||
#include "TaskItem.h"
|
||||
#include "using.h"
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct FilteredEvent {
|
||||
Event *event;
|
||||
std::vector<TaskItem *> filteredTasks;
|
||||
};
|
||||
|
||||
struct FilteredDay {
|
||||
Day *day;
|
||||
std::vector<FilteredEvent> filteredEvents;
|
||||
std::vector<TaskItem *> filteredTasks;
|
||||
};
|
||||
|
||||
class TasksView
|
||||
{
|
||||
|
||||
public:
|
||||
TasksView(Mirai *mirai);
|
||||
|
||||
FilteredDay &operator[](int index);
|
||||
std::vector<TaskItem *> &filteredUnscheduledTasks();
|
||||
|
||||
size_t count() const;
|
||||
void update();
|
||||
void addTagFilter(const std::string &tag);
|
||||
void removeTagFilter(const std::string &tag);
|
||||
void addSourceFilter(const std::string &fileName);
|
||||
void removeSourceFilter(const std::string &fileName);
|
||||
void removeFilters();
|
||||
const Tags &getActiveTagsFilter();
|
||||
const std::vector<std::string> &getActiveFilesFilter();
|
||||
bool isSourceFilterActive(const std::string &sourceName);
|
||||
|
||||
void hideCompletedTasks(bool hide);
|
||||
bool shouldHideCompletedTasks() const;
|
||||
|
||||
private:
|
||||
std::vector<FilteredDay> filteredDays;
|
||||
std::vector<TaskItem *> filteredUnscheduledTasks_;
|
||||
|
||||
Mirai *mirai;
|
||||
Tags tagsFilter;
|
||||
std::vector<std::string> resourcesFilter;
|
||||
bool shouldHideCompletedTasks_ = true;
|
||||
};
|
||||
} // namespace mirai
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BaseSource.h"
|
||||
#include "DateTime.h"
|
||||
#include "Day.h"
|
||||
#include "Event.h"
|
||||
#include "TaskItem.h"
|
||||
#include <format>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
struct MiraiMarkdownFormatParseResult {
|
||||
std::string name;
|
||||
std::vector<DayData> days;
|
||||
std::vector<TaskItemData> unscheduledTasks;
|
||||
};
|
||||
|
||||
class TodoMdFormat
|
||||
{
|
||||
public:
|
||||
static std::string stringify(BaseSource &source);
|
||||
|
||||
static MiraiMarkdownFormatParseResult parse(const std::string &content);
|
||||
|
||||
static std::string taskToString(const TaskItem &task);
|
||||
static TaskItemData stringToTask(const std::string &str, const std::string &date);
|
||||
static EventData stringToEvent(const std::string &str, const std::string &date);
|
||||
|
||||
private:
|
||||
static std::string fieldWithSpace(const std::string &field);
|
||||
static TaskItem parseLine(const std::string &line);
|
||||
static Tags extractTagsFromMetadata(std::string metadata);
|
||||
};
|
||||
} // namespace mirai
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/*#include "TaskItem.h"*/
|
||||
/*#include "utils.h"*/
|
||||
/*#include <fstream>*/
|
||||
/*#include <iostream>*/
|
||||
/*#include <iterator>*/
|
||||
/*#include <memory>*/
|
||||
/*#include <regex>*/
|
||||
/*#include <stdexcept>*/
|
||||
/*#include <string>*/
|
||||
/*#include <vector>*/
|
||||
|
||||
/*namespace mirai {*/
|
||||
|
||||
/*class TodoTxtFormat {*/
|
||||
/*public:*/
|
||||
|
||||
/*static TaskList readFile() {*/
|
||||
/*std::ifstream file("../newqml/todo.txt");*/
|
||||
/*if (!file.is_open()) {*/
|
||||
/*throw std::runtime_error("todo.txt file not found");*/
|
||||
/*}*/
|
||||
/*std::vector<TaskItem> taskItems;*/
|
||||
/*std::string line;*/
|
||||
/*while (std::getline(file, line)) {*/
|
||||
/*auto taskItem = parseLine(line);*/
|
||||
/*taskItems.push_back(taskItem);*/
|
||||
/*}*/
|
||||
/*file.close();*/
|
||||
/*TaskList tasks({*/
|
||||
/*.tasks = taskItems*/
|
||||
/*});*/
|
||||
/*return tasks;*/
|
||||
/*}*/
|
||||
|
||||
/*static void writeFile(TaskList& tasks) {*/
|
||||
/*std::ofstream file("../newqml/todo.txt");*/
|
||||
/*if (!file.is_open()) {*/
|
||||
/*throw std::runtime_error("can't create todo.txt");*/
|
||||
/*}*/
|
||||
/*for (const auto& task : tasks.getTasks()) {*/
|
||||
/*file << fieldWithSpace(task->state == DONE ? "x" : task->priority);*/
|
||||
/*file << fieldWithSpace(task->state == DONE ? task->getDate() : "");*/
|
||||
/*file << fieldWithSpace(task->getCreationDate());*/
|
||||
/*file << task->getText() << '\n';*/
|
||||
/*}*/
|
||||
/*file.close();*/
|
||||
/*}*/
|
||||
|
||||
/*private:*/
|
||||
|
||||
/*static std::string fieldWithSpace(const std::string& field) {*/
|
||||
/*if (field.length() == 0)*/
|
||||
/*return "";*/
|
||||
/*return (field + " ");*/
|
||||
/*}*/
|
||||
|
||||
/*static TaskItem parseLine(const std::string& line) {*/
|
||||
/*std::smatch matches;*/
|
||||
/*std::regex regex("(^x )?(\\([A-Z]\\) )?([0-9]{4}-[0-9]{2}-[0-9]{2} )?([0-9]{4}-[0-9]{2}-[0-9]{2}
|
||||
* )?(.*)");*/
|
||||
/*std::regex_match(line, matches, regex);*/
|
||||
|
||||
/*for (size_t i = 0; i < matches.size(); ++i) {*/
|
||||
/*std::ssub_match sub_match = matches[i];*/
|
||||
/*std::string piece = sub_match.str();*/
|
||||
/*}*/
|
||||
|
||||
/*const TaskItemState taskState = trim_copy(matches[1].str()) == "x" ? DONE : TODO;*/
|
||||
/*const std::string priority = trim_copy(matches[2].str());*/
|
||||
/*const std::string firstDate = trim_copy(matches[3].str());*/
|
||||
/*const std::string secondDate = trim_copy(matches[4].str());*/
|
||||
/*const std::string text = trim_copy(matches[5].str());*/
|
||||
|
||||
/*const std::string date = taskState == DONE ? firstDate : "";*/
|
||||
|
||||
/*return {*/
|
||||
/*.text = text,*/
|
||||
/*.state = taskState,*/
|
||||
/*.date = date,*/
|
||||
/*};*/
|
||||
/*}*/
|
||||
/*};*/
|
||||
/*}*/
|
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
using Tags = std::vector<std::string>;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cpp-utils/string.h>
|
||||
#include <cpp-utils/vector.h>
|
||||
#include <locale>
|
||||
#include <regex>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
namespace stringUtils = cpputils::string;
|
||||
namespace vectorUtils = cpputils::vector;
|
||||
|
||||
bool isDate(const std::string &dateStr);
|
||||
} // namespace mirai
|
167
external/mirai-core-old/src/BaseSource.cpp
vendored
167
external/mirai-core-old/src/BaseSource.cpp
vendored
|
@ -1,167 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "BaseSource.h"
|
||||
#include "Day.h"
|
||||
#include "TaskItem.h"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
void BaseSource::setDirty(bool shouldBeDirty)
|
||||
{
|
||||
isDirty_ = shouldBeDirty;
|
||||
}
|
||||
|
||||
bool BaseSource::isDirty() const
|
||||
{
|
||||
return isDirty_;
|
||||
}
|
||||
|
||||
Day *BaseSource::day(const Date &date)
|
||||
{
|
||||
auto dayFound = std::find_if(days_.begin(), days_.end(), [&](std::unique_ptr<Day> &day) {
|
||||
return day->getDate().day == date.day && day->getDate().month == date.month &&
|
||||
day->getDate().year == date.year;
|
||||
});
|
||||
if (dayFound == days_.end()) {
|
||||
auto newDay = std::make_unique<Day>(this, DayData{.date = date});
|
||||
Day *dayPtr = newDay.get();
|
||||
days_.push_back(std::move(newDay));
|
||||
return dayPtr;
|
||||
}
|
||||
return dayFound->get();
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Day>> *BaseSource::days()
|
||||
{
|
||||
return &days_;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<TaskItem>> *BaseSource::unscheduledTasks()
|
||||
{
|
||||
return &unscheduledTasks_;
|
||||
}
|
||||
|
||||
void BaseSource::addDay(const DayData &dayData)
|
||||
{
|
||||
days_.push_back(std::make_unique<Day>(this, dayData));
|
||||
setDirty(true);
|
||||
}
|
||||
|
||||
void BaseSource::addUnscheduledTask(const TaskItemData &taskData)
|
||||
{
|
||||
unscheduledTasks_.push_back(std::make_unique<TaskItem>(this, nullptr, taskData));
|
||||
setDirty(true);
|
||||
}
|
||||
|
||||
TaskItem *BaseSource::getTaskById(int taskId)
|
||||
{
|
||||
for (auto &day : days_) {
|
||||
for (auto &task : *day->tasks()) {
|
||||
if (task->id() == taskId) {
|
||||
return task.get();
|
||||
}
|
||||
}
|
||||
for (auto &event : *day->events()) {
|
||||
for (auto &task : *event->tasks()) {
|
||||
if (task->id() == taskId) {
|
||||
return task.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto &task : *unscheduledTasks()) {
|
||||
if (task->id() == taskId) {
|
||||
return task.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void BaseSource::deleteTask(const TaskItem &taskToDelete)
|
||||
{
|
||||
for (auto &day : days_) {
|
||||
for (auto &task : *day->tasks()) {
|
||||
if (task->id() == taskToDelete.id()) {
|
||||
day->deleteTask(taskToDelete);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (auto &event : *day->events()) {
|
||||
for (auto &task : *event->tasks()) {
|
||||
if (task->id() == taskToDelete.id()) {
|
||||
event->deleteTask(taskToDelete);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unscheduledTasks_.erase(
|
||||
std::remove_if(
|
||||
unscheduledTasks_.begin(), unscheduledTasks_.end(),
|
||||
[&](const std::unique_ptr<TaskItem> &task) {
|
||||
return task->id() == taskToDelete.id();
|
||||
}
|
||||
),
|
||||
unscheduledTasks_.end()
|
||||
);
|
||||
}
|
||||
|
||||
Event *BaseSource::getEventById(int eventId)
|
||||
{
|
||||
for (auto &day : days_) {
|
||||
for (auto &event : *day->events()) {
|
||||
if (event->id() == eventId) {
|
||||
return event.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void BaseSource::setName(std::string name)
|
||||
{
|
||||
this->name_ = name;
|
||||
}
|
||||
|
||||
const std::string &BaseSource::getName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
int BaseSource::id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
/*void BaseResource::addTask(TaskItemData taskItem)*/
|
||||
/*{*/
|
||||
/*tasks.push_back(std::make_unique<TaskItem>(this, taskItem));*/
|
||||
/*setDirty(true);*/
|
||||
/*}*/
|
||||
|
||||
/*void BaseResource::removeTask(const TaskItem *taskToRemove)*/
|
||||
/*{*/
|
||||
/*auto findFunction = [&](const std::unique_ptr<TaskItem> &taskInFilter) {*/
|
||||
/*return taskInFilter.get() == taskToRemove;*/
|
||||
/*};*/
|
||||
/*auto taskToDelete = std::remove_if(tasks_.begin(), tasks_.end(), findFunction);*/
|
||||
/*if (taskToDelete == tasks_.end()) {*/
|
||||
/*return;*/
|
||||
/*}*/
|
||||
/*tasks_.erase(taskToDelete);*/
|
||||
/*setDirty(true);*/
|
||||
/*}*/
|
||||
|
||||
int BaseSource::nextId_ = 0;
|
||||
|
||||
} // namespace mirai
|
30
external/mirai-core-old/src/Config.cpp
vendored
30
external/mirai-core-old/src/Config.cpp
vendored
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "Config.h"
|
||||
#include "ConfigImpl.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
Config::~Config() = default;
|
||||
|
||||
Config::Config(const std::string &path) : impl_(new ConfigImpl(path))
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::string> Config::sources() const
|
||||
{
|
||||
return impl_->sources();
|
||||
}
|
||||
|
||||
}; // namespace mirai
|
48
external/mirai-core-old/src/ConfigImpl.cpp
vendored
48
external/mirai-core-old/src/ConfigImpl.cpp
vendored
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "ConfigImpl.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
ConfigImpl::ConfigImpl(const std::string &path) : path_(path)
|
||||
{
|
||||
std::ifstream file(path_);
|
||||
if (!file) {
|
||||
configJson_ = nlohmann::json::parse(R"(
|
||||
{
|
||||
"files": []
|
||||
}
|
||||
)");
|
||||
return;
|
||||
}
|
||||
configJson_ = nlohmann::json::parse(file);
|
||||
}
|
||||
|
||||
std::vector<std::string> ConfigImpl::sources() const
|
||||
{
|
||||
std::vector<std::string> sources;
|
||||
assert(configJson_.is_object());
|
||||
assert(configJson_["files"].is_array());
|
||||
auto jsonSources = configJson_["files"];
|
||||
for (const auto &filePath : jsonSources) {
|
||||
assert(filePath.is_string());
|
||||
sources.push_back(filePath.get<std::string>());
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
std::string ConfigImpl::path() const
|
||||
{
|
||||
return path_;
|
||||
}
|
||||
|
||||
}; // namespace mirai
|
27
external/mirai-core-old/src/ConfigImpl.h
vendored
27
external/mirai-core-old/src/ConfigImpl.h
vendored
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
class ConfigImpl
|
||||
{
|
||||
public:
|
||||
ConfigImpl(const std::string &path);
|
||||
|
||||
std::vector<std::string> sources() const;
|
||||
std::string path() const;
|
||||
|
||||
private:
|
||||
std::string path_;
|
||||
nlohmann::json configJson_;
|
||||
};
|
||||
} // namespace mirai
|
105
external/mirai-core-old/src/DateTime.cpp
vendored
105
external/mirai-core-old/src/DateTime.cpp
vendored
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "DateTime.h"
|
||||
#include <charconv>
|
||||
#include <optional>
|
||||
#include <ranges>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
std::optional<mirai::Date> stringToDate(const std::string &dateStr)
|
||||
{
|
||||
using std::operator""sv;
|
||||
|
||||
auto dateSplitView =
|
||||
dateStr | std::views::split("-"sv) | std::views::transform([](auto v) -> int {
|
||||
int i = 0;
|
||||
std::from_chars(v.data(), v.data() + v.size(), i);
|
||||
return i;
|
||||
});
|
||||
std::vector<int> dateSplit{dateSplitView.begin(), dateSplitView.end()};
|
||||
if (dateSplit.size() != 3) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto year = dateSplit[0];
|
||||
auto month = dateSplit[1];
|
||||
auto day = dateSplit[2];
|
||||
return mirai::Date(year, static_cast<unsigned>(month), static_cast<unsigned>(day));
|
||||
}
|
||||
|
||||
Date::Date(int year, unsigned month, unsigned day) : year(year), month(month), day(day)
|
||||
{
|
||||
}
|
||||
|
||||
Date::Date(std::chrono::time_point<std::chrono::system_clock> tp)
|
||||
{
|
||||
auto chronoDate = std::chrono::year_month_day(std::chrono::floor<std::chrono::days>(tp));
|
||||
year = static_cast<int>(chronoDate.year());
|
||||
month = static_cast<unsigned>(chronoDate.month());
|
||||
day = static_cast<unsigned>(chronoDate.day());
|
||||
}
|
||||
|
||||
Date::Date(std::chrono::year_month_day chronoDate)
|
||||
{
|
||||
year = static_cast<int>(chronoDate.year());
|
||||
month = static_cast<unsigned>(chronoDate.month());
|
||||
day = static_cast<unsigned>(chronoDate.day());
|
||||
}
|
||||
|
||||
int year;
|
||||
unsigned month;
|
||||
unsigned day;
|
||||
|
||||
bool Date::operator==(const Date &other) const
|
||||
{
|
||||
return other.year == year && other.month == month && other.day == day;
|
||||
}
|
||||
|
||||
bool Date::operator<(const Date &other) const
|
||||
{
|
||||
if (year < other.year) {
|
||||
return true;
|
||||
}
|
||||
if (year == other.year && month < other.month) {
|
||||
return true;
|
||||
}
|
||||
if (year == other.year && month == other.month && day < other.day) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Date::operator>(const Date &other) const
|
||||
{
|
||||
return !(*this < other) && !(*this == other);
|
||||
}
|
||||
|
||||
bool Time::operator==(const Time &other) const
|
||||
{
|
||||
return other.hour == hour && other.minute == minute;
|
||||
}
|
||||
|
||||
bool Time::operator<(const Time &other) const
|
||||
{
|
||||
if (hour < other.hour) {
|
||||
return true;
|
||||
}
|
||||
if (hour == other.hour && minute < other.minute) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Time::operator>(const Time &other) const
|
||||
{
|
||||
return !(*this < other) && !(*this == other);
|
||||
}
|
||||
} // namespace mirai
|
126
external/mirai-core-old/src/Day.cpp
vendored
126
external/mirai-core-old/src/Day.cpp
vendored
|
@ -1,126 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "Day.h"
|
||||
#include "BaseSource.h"
|
||||
#include "TaskItem.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
Day::Day(BaseSource *source, const DayData &data) : source_(source), data_(data)
|
||||
{
|
||||
}
|
||||
|
||||
Event *Day::createEvent(const EventData &eventData)
|
||||
{
|
||||
auto event = std::make_unique<Event>(source_, this, eventData);
|
||||
mirai::Event *eventPtr = event.get();
|
||||
events_.push_back(std::move(event));
|
||||
onChange();
|
||||
return eventPtr;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Event>> *Day::events()
|
||||
{
|
||||
return &events_;
|
||||
}
|
||||
|
||||
const Date &Day::getDate() const
|
||||
{
|
||||
return data_.date;
|
||||
}
|
||||
|
||||
TaskItem *Day::createTask(const TaskItemData &taskData)
|
||||
{
|
||||
auto task = std::make_unique<TaskItem>(source_, this, taskData);
|
||||
mirai::TaskItem *taskPtr = task.get();
|
||||
tasks_.push_back(std::move(task));
|
||||
onChange();
|
||||
return taskPtr;
|
||||
}
|
||||
|
||||
void Day::insertTask(std::unique_ptr<TaskItem> &&task)
|
||||
{
|
||||
tasks_.push_back(std::move(task));
|
||||
onChange();
|
||||
}
|
||||
|
||||
void Day::deleteTask(const TaskItem &taskToDelete)
|
||||
{
|
||||
int id = taskToDelete.id();
|
||||
tasks_.erase(
|
||||
std::remove_if(
|
||||
tasks_.begin(), tasks_.end(),
|
||||
[&](const std::unique_ptr<TaskItem> &task) {
|
||||
return task->id() == id;
|
||||
}
|
||||
),
|
||||
tasks_.end()
|
||||
);
|
||||
onChange();
|
||||
}
|
||||
|
||||
std::optional<std::unique_ptr<TaskItem>> Day::takeTask(const TaskItem &taskToDelete)
|
||||
{
|
||||
auto taskIterator = std::ranges::find_if(tasks_, [&](const auto &task) {
|
||||
return task->id() == taskToDelete.id();
|
||||
});
|
||||
if (taskIterator == tasks_.end()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto task = std::move(*taskIterator);
|
||||
tasks_.erase(taskIterator);
|
||||
onChange();
|
||||
return task;
|
||||
}
|
||||
|
||||
void Day::deleteEvent(const Event &eventToDelete)
|
||||
{
|
||||
int id = eventToDelete.id();
|
||||
events_.erase(
|
||||
std::remove_if(
|
||||
events_.begin(), events_.end(),
|
||||
[&](const std::unique_ptr<Event> &event) {
|
||||
return event->id() == id;
|
||||
}
|
||||
),
|
||||
events_.end()
|
||||
);
|
||||
onChange();
|
||||
}
|
||||
|
||||
void Day::onChange()
|
||||
{
|
||||
source()->setDirty(true);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<TaskItem>> *Day::tasks()
|
||||
{
|
||||
return &tasks_;
|
||||
}
|
||||
|
||||
Event *Day::getEventById(int eventId)
|
||||
{
|
||||
for (auto &event : events_) {
|
||||
if (event->id() == eventId) {
|
||||
return event.get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BaseSource *Day::source()
|
||||
{
|
||||
return source_;
|
||||
}
|
||||
} // namespace mirai
|
116
external/mirai-core-old/src/Event.cpp
vendored
116
external/mirai-core-old/src/Event.cpp
vendored
|
@ -1,116 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "Event.h"
|
||||
#include "BaseSource.h"
|
||||
#include "TaskItem.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
Event::Event(BaseSource *source, Day *parent, const EventData &data)
|
||||
: source_(source), day_(parent), data(data)
|
||||
{
|
||||
}
|
||||
|
||||
void Event::setText(const std::string &text)
|
||||
{
|
||||
this->data.description = text;
|
||||
onChange();
|
||||
}
|
||||
|
||||
const std::string &Event::getText() const
|
||||
{
|
||||
return data.description;
|
||||
}
|
||||
|
||||
const Date &Event::getDate() const
|
||||
{
|
||||
return data.date;
|
||||
}
|
||||
|
||||
const Time &Event::getStartTime() const
|
||||
{
|
||||
return data.startTime;
|
||||
}
|
||||
|
||||
const Time &Event::getEndTime() const
|
||||
{
|
||||
return data.endTime;
|
||||
}
|
||||
|
||||
const Tags &Event::getTags() const
|
||||
{
|
||||
return data.tags;
|
||||
}
|
||||
|
||||
bool Event::hasTag(const std::string &tag) const
|
||||
{
|
||||
return vectorUtils::contains(data.tags, tag);
|
||||
}
|
||||
|
||||
TaskItem *Event::createTask(const TaskItemData &taskData)
|
||||
{
|
||||
auto task = std::make_unique<TaskItem>(source_, day_, taskData);
|
||||
mirai::TaskItem *taskPtr = task.get();
|
||||
tasks_.push_back(std::move(task));
|
||||
onChange();
|
||||
return taskPtr;
|
||||
}
|
||||
|
||||
void Event::deleteTask(const TaskItem &taskToDelete)
|
||||
{
|
||||
tasks_.erase(std::remove_if(
|
||||
tasks_.begin(), tasks_.end(),
|
||||
[&](const std::unique_ptr<TaskItem> &task) {
|
||||
return task->id() == taskToDelete.id();
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<TaskItem>> *Event::tasks()
|
||||
{
|
||||
return &tasks_;
|
||||
}
|
||||
|
||||
void Event::setStartTime(const Time &time)
|
||||
{
|
||||
data.startTime = time;
|
||||
onChange();
|
||||
}
|
||||
|
||||
void Event::setEndTime(const Time &time)
|
||||
{
|
||||
data.endTime = time;
|
||||
onChange();
|
||||
}
|
||||
|
||||
void Event::onChange()
|
||||
{
|
||||
source_->setDirty(true);
|
||||
}
|
||||
|
||||
Event &Event::operator=(const EventData &newData)
|
||||
{
|
||||
data = newData;
|
||||
onChange();
|
||||
return *this;
|
||||
};
|
||||
|
||||
int Event::id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
Day *Event::day()
|
||||
{
|
||||
return day_;
|
||||
}
|
||||
|
||||
int Event::nextId = 0;
|
||||
|
||||
} // namespace mirai
|
7
external/mirai-core-old/src/EventEmitter.cpp
vendored
7
external/mirai-core-old/src/EventEmitter.cpp
vendored
|
@ -1,7 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "EventEmitter.h"
|
100
external/mirai-core-old/src/Mirai.cpp
vendored
100
external/mirai-core-old/src/Mirai.cpp
vendored
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "Mirai.h"
|
||||
#include "Config.h"
|
||||
#include "TaskItem.h"
|
||||
#include "cpp-utils/debug.h"
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
void Mirai::loadSource(std::unique_ptr<BaseSource> &&resource)
|
||||
{
|
||||
resource->load();
|
||||
sources_.push_back(std::move(resource));
|
||||
reloadTags();
|
||||
};
|
||||
|
||||
void Mirai::unloadAllSources()
|
||||
{
|
||||
sources_.clear();
|
||||
}
|
||||
|
||||
void Mirai::save()
|
||||
{
|
||||
for (auto &resource : sources_) {
|
||||
if (resource->isDirty()) {
|
||||
resource->save();
|
||||
resource->setDirty(false);
|
||||
}
|
||||
}
|
||||
reloadTags();
|
||||
}
|
||||
|
||||
void Mirai::deleteTask(const TaskItem &taskItem)
|
||||
{
|
||||
for (auto &resource : sources_) {
|
||||
resource->deleteTask(taskItem);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<BaseSource>> &Mirai::getSources()
|
||||
{
|
||||
return sources_;
|
||||
}
|
||||
|
||||
std::optional<std::reference_wrapper<BaseSource>> Mirai::getSourceByName(const std::string &name)
|
||||
{
|
||||
auto resourceIterator =
|
||||
std::ranges::find_if(sources_, [&](const std::unique_ptr<BaseSource> &resource) {
|
||||
return resource->getName() == name;
|
||||
});
|
||||
|
||||
if (resourceIterator == sources_.end()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return *(resourceIterator->get());
|
||||
}
|
||||
|
||||
const std::vector<std::string> &Mirai::getTags()
|
||||
{
|
||||
return tags_;
|
||||
}
|
||||
|
||||
void Mirai::reloadTags()
|
||||
{
|
||||
// TODO TAGS
|
||||
/*cpputils::debug::Timer reloadingTagsDuration;*/
|
||||
/*tags.clear();*/
|
||||
/*for (auto &resource : resources) {*/
|
||||
/*for (auto &task : resource->getTasks()) {*/
|
||||
/*for (auto &tag : task->getTags()) {*/
|
||||
/*if (!vectorUtils::contains(tags, tag)) {*/
|
||||
/*tags.push_back(tag);*/
|
||||
/*}*/
|
||||
/*}*/
|
||||
/*}*/
|
||||
/*}*/
|
||||
/*reloadingTagsDuration.printTimeElapsed("ReloadingTags");*/
|
||||
}
|
||||
|
||||
BaseSource *Mirai::getSourceById(int id)
|
||||
{
|
||||
if (id >= sources_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
return sources_.at(id).get();
|
||||
}
|
||||
|
||||
} // namespace mirai
|
61
external/mirai-core-old/src/StdFileSource.cpp
vendored
61
external/mirai-core-old/src/StdFileSource.cpp
vendored
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "StdFileSource.h"
|
||||
#include "TodoMd.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
void StdFileSource::save()
|
||||
{
|
||||
std::ofstream file(getPath());
|
||||
if (!file.is_open()) {
|
||||
throw std::runtime_error("can't create " + getPath());
|
||||
}
|
||||
|
||||
const std::string content = TodoMdFormat::stringify(*this);
|
||||
|
||||
file << content;
|
||||
file.close();
|
||||
};
|
||||
|
||||
void StdFileSource::load()
|
||||
{
|
||||
std::ifstream file(getPath());
|
||||
if (!file.is_open()) {
|
||||
return;
|
||||
}
|
||||
std::string content = "";
|
||||
std::string line;
|
||||
|
||||
while (std::getline(file, line)) {
|
||||
content += line + "\n";
|
||||
}
|
||||
file.close();
|
||||
auto result = TodoMdFormat::parse(content);
|
||||
for (const auto &dayData : result.days) {
|
||||
Day *newDay = day(dayData.date);
|
||||
for (const auto &eventData : dayData.events) {
|
||||
Event *newEvent = newDay->createEvent(eventData);
|
||||
for (const auto &taskData : eventData.tasks) {
|
||||
TaskItem *newTask = newEvent->createTask(taskData);
|
||||
}
|
||||
}
|
||||
for (const auto &taskData : dayData.tasks) {
|
||||
TaskItem *newTask = newDay->createTask(taskData);
|
||||
}
|
||||
}
|
||||
for (const auto &taskData : result.unscheduledTasks) {
|
||||
addUnscheduledTask(taskData);
|
||||
}
|
||||
setName(result.name);
|
||||
};
|
||||
} // namespace mirai
|
87
external/mirai-core-old/src/TaskItem.cpp
vendored
87
external/mirai-core-old/src/TaskItem.cpp
vendored
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "TaskItem.h"
|
||||
#include "BaseSource.h"
|
||||
#include "utils.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
int TaskItem::nextId = 0;
|
||||
|
||||
TaskItem &TaskItem::operator=(const TaskItemData &newData)
|
||||
{
|
||||
data = newData;
|
||||
onChange();
|
||||
return *this;
|
||||
};
|
||||
|
||||
TaskItem::TaskItem(BaseSource *source, Day *day, TaskItemData data)
|
||||
: source_(source), day_(day), data(data)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskItem::markAsDone()
|
||||
{
|
||||
data.state = DONE;
|
||||
onChange();
|
||||
}
|
||||
|
||||
void TaskItem::markAsUndone()
|
||||
{
|
||||
data.state = TODO;
|
||||
onChange();
|
||||
}
|
||||
|
||||
void TaskItem::setText(const std::string &text)
|
||||
{
|
||||
this->data.text = text;
|
||||
onChange();
|
||||
}
|
||||
|
||||
const std::string &TaskItem::getText() const
|
||||
{
|
||||
return data.text;
|
||||
}
|
||||
|
||||
const TaskItemState &TaskItem::getState() const
|
||||
{
|
||||
return data.state;
|
||||
}
|
||||
|
||||
const Tags &TaskItem::getTags() const
|
||||
{
|
||||
return data.tags;
|
||||
}
|
||||
|
||||
bool TaskItem::hasTag(const std::string &tag) const
|
||||
{
|
||||
return vectorUtils::contains(data.tags, tag);
|
||||
}
|
||||
|
||||
void TaskItem::onChange()
|
||||
{
|
||||
source()->setDirty(true);
|
||||
}
|
||||
|
||||
int TaskItem::id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
BaseSource *TaskItem::source()
|
||||
{
|
||||
return source_;
|
||||
}
|
||||
|
||||
Day *TaskItem::day()
|
||||
{
|
||||
return day_;
|
||||
}
|
||||
|
||||
} // namespace mirai
|
212
external/mirai-core-old/src/TasksView.cpp
vendored
212
external/mirai-core-old/src/TasksView.cpp
vendored
|
@ -1,212 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "TasksView.h"
|
||||
#include "Mirai.h"
|
||||
#include "TaskItem.h"
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <ctime>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
TasksView::TasksView(Mirai *miraiInstance) : mirai(miraiInstance)
|
||||
{
|
||||
if (!miraiInstance) {
|
||||
throw std::runtime_error("NULL pointer passed in TasksView");
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
FilteredDay &TasksView::operator[](int index)
|
||||
{
|
||||
return filteredDays.at(index);
|
||||
}
|
||||
|
||||
std::vector<TaskItem *> &TasksView::filteredUnscheduledTasks()
|
||||
{
|
||||
return filteredUnscheduledTasks_;
|
||||
}
|
||||
|
||||
size_t TasksView::count() const
|
||||
{
|
||||
return filteredDays.size();
|
||||
}
|
||||
|
||||
void TasksView::update()
|
||||
{
|
||||
auto todayDate = std::format("{:%Y-%m-%d}", std::chrono::system_clock::now());
|
||||
filteredDays.clear();
|
||||
filteredUnscheduledTasks_.clear();
|
||||
|
||||
for (auto &file : mirai->getSources()) {
|
||||
if (resourcesFilter.size() > 0 &&
|
||||
!vectorUtils::contains(resourcesFilter, file->getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (auto &task : *file->unscheduledTasks()) {
|
||||
if (shouldHideCompletedTasks() && task->getState() == DONE) {
|
||||
continue;
|
||||
}
|
||||
if (tagsFilter.size() > 0 && !vectorUtils::containsAll(tagsFilter, task->getTags())) {
|
||||
continue;
|
||||
}
|
||||
filteredUnscheduledTasks_.push_back(task.get());
|
||||
}
|
||||
for (auto &day : *file->days()) {
|
||||
FilteredDay filteredDay{.day = day.get()};
|
||||
for (auto &task : *day->tasks()) {
|
||||
auto taskDate = std::format(
|
||||
"{:04d}-{:02d}-{:02d}", day->getDate().year, day->getDate().month,
|
||||
day->getDate().day
|
||||
);
|
||||
if (shouldHideCompletedTasks() && task->getState() == DONE &&
|
||||
taskDate < todayDate) {
|
||||
continue;
|
||||
}
|
||||
if (tagsFilter.size() > 0 &&
|
||||
!vectorUtils::containsAll(tagsFilter, task->getTags())) {
|
||||
continue;
|
||||
}
|
||||
filteredDay.filteredTasks.push_back(task.get());
|
||||
}
|
||||
for (auto &event : *day->events()) {
|
||||
FilteredEvent filteredEvent{.event = event.get()};
|
||||
auto eventDate = std::format(
|
||||
"{:04d}-{:02d}-{:02d}", day->getDate().year, day->getDate().month,
|
||||
day->getDate().day
|
||||
);
|
||||
for (auto &task : *event->tasks()) {
|
||||
|
||||
if (shouldHideCompletedTasks() && task->getState() == DONE &&
|
||||
eventDate < todayDate) {
|
||||
continue;
|
||||
}
|
||||
if (tagsFilter.size() > 0 &&
|
||||
!vectorUtils::containsAll(tagsFilter, task->getTags())) {
|
||||
continue;
|
||||
}
|
||||
filteredEvent.filteredTasks.push_back(task.get());
|
||||
}
|
||||
if (!filteredEvent.filteredTasks.empty() || !shouldHideCompletedTasks() ||
|
||||
eventDate >= todayDate) {
|
||||
filteredDay.filteredEvents.push_back(filteredEvent);
|
||||
}
|
||||
}
|
||||
if (!filteredDay.filteredEvents.empty() || !filteredDay.filteredTasks.empty()) {
|
||||
auto existingDay = std::ranges::find_if(filteredDays, [&](const FilteredDay &date) {
|
||||
return date.day->getDate() == filteredDay.day->getDate();
|
||||
});
|
||||
if (existingDay == filteredDays.end()) {
|
||||
filteredDays.push_back(filteredDay);
|
||||
} else {
|
||||
existingDay->filteredTasks.insert(
|
||||
existingDay->filteredTasks.end(), filteredDay.filteredTasks.begin(),
|
||||
filteredDay.filteredTasks.end()
|
||||
);
|
||||
existingDay->filteredEvents.insert(
|
||||
existingDay->filteredEvents.end(), filteredDay.filteredEvents.begin(),
|
||||
filteredDay.filteredEvents.end()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &filteredDay : filteredDays) {
|
||||
std::ranges::sort(
|
||||
filteredDay.filteredEvents,
|
||||
[](const FilteredEvent &t1, const FilteredEvent &t2) {
|
||||
return t1.event->getStartTime().hour < t2.event->getStartTime().hour;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
std::ranges::sort(filteredDays, [](const FilteredDay &t1, const FilteredDay &t2) {
|
||||
return t1.day->getDate() < t2.day->getDate();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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::addSourceFilter(const std::string &fileName)
|
||||
{
|
||||
resourcesFilter.push_back(fileName);
|
||||
update();
|
||||
}
|
||||
|
||||
void TasksView::removeSourceFilter(const std::string &fileName)
|
||||
{
|
||||
resourcesFilter.erase(std::remove_if(
|
||||
resourcesFilter.begin(), resourcesFilter.end(),
|
||||
[&](const auto &fileInFilter) {
|
||||
return fileName == fileInFilter;
|
||||
}
|
||||
));
|
||||
update();
|
||||
}
|
||||
|
||||
void TasksView::removeFilters()
|
||||
{
|
||||
tagsFilter.clear();
|
||||
resourcesFilter.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
const std::vector<std::string> &TasksView::getActiveTagsFilter()
|
||||
{
|
||||
return tagsFilter;
|
||||
}
|
||||
|
||||
const std::vector<std::string> &TasksView::getActiveFilesFilter()
|
||||
{
|
||||
return resourcesFilter;
|
||||
}
|
||||
|
||||
bool TasksView::isSourceFilterActive(const std::string &sourceName)
|
||||
{
|
||||
if (std::ranges::find(getActiveFilesFilter(), sourceName) == getActiveFilesFilter().end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TasksView::hideCompletedTasks(bool hide)
|
||||
{
|
||||
shouldHideCompletedTasks_ = hide;
|
||||
}
|
||||
|
||||
bool TasksView::shouldHideCompletedTasks() const
|
||||
{
|
||||
return shouldHideCompletedTasks_;
|
||||
}
|
||||
} // namespace mirai
|
239
external/mirai-core-old/src/TodoMd.cpp
vendored
239
external/mirai-core-old/src/TodoMd.cpp
vendored
|
@ -1,239 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "TodoMd.h"
|
||||
#include "TaskItem.h"
|
||||
#include "cpp-utils/debug.h"
|
||||
#include "utils.h"
|
||||
#include <charconv>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <ranges>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
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[2].str())) {
|
||||
tags.push_back(matches[2]);
|
||||
}
|
||||
metadata = matches.suffix();
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
std::string TodoMdFormat::fieldWithSpace(const std::string &field)
|
||||
{
|
||||
if (field.length() == 0) {
|
||||
return "";
|
||||
}
|
||||
return (field + " ");
|
||||
}
|
||||
|
||||
TaskItemData 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]);
|
||||
|
||||
TaskItemData taskItem{
|
||||
.text = text,
|
||||
.state = str.substr(0, 5) == "- [X]" ? DONE : TODO,
|
||||
.tags = extractTagsFromMetadata(matches[7])
|
||||
};
|
||||
return taskItem;
|
||||
}
|
||||
|
||||
Time stringToTime(const std::string &str)
|
||||
{
|
||||
if (str.length() != 5) {
|
||||
throw std::runtime_error("Str time length must be 5 (got '" + str + "')");
|
||||
}
|
||||
if (str[2] != 'h') {
|
||||
throw std::runtime_error("Malformated time range");
|
||||
}
|
||||
Time time{};
|
||||
std::from_chars(str.data(), str.data() + 2, time.hour);
|
||||
std::from_chars(str.data() + 3, str.data() + 5, time.minute);
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
EventData TodoMdFormat::stringToEvent(const std::string &str, const std::string &dateString)
|
||||
{
|
||||
std::smatch matches;
|
||||
std::regex regex("> (([0-9]{2}h[0-9]{2})-([0-9]{2}h[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::string text = stringUtils::trim(matches[4]);
|
||||
|
||||
auto date = stringToDate(dateString);
|
||||
|
||||
if (!date.has_value()) {
|
||||
throw std::runtime_error("Malformated date");
|
||||
}
|
||||
|
||||
EventData eventData{
|
||||
.description = text,
|
||||
.date = date.value(),
|
||||
.startTime = stringToTime(matches[2]),
|
||||
.endTime = stringToTime(matches[3]),
|
||||
.tags = extractTagsFromMetadata(matches[6])
|
||||
};
|
||||
return eventData;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
str = (task.getState() == DONE ? "- [X] " : "- [ ] ") + str;
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string TodoMdFormat::stringify(BaseSource &source)
|
||||
{
|
||||
const std::string &name = source.getName();
|
||||
const std::vector<std::unique_ptr<Day>> *days = source.days();
|
||||
std::string result = "# " + name + "\n\n";
|
||||
std::string currentDate = "";
|
||||
|
||||
for (const auto &day : *days) {
|
||||
auto &date = day->getDate();
|
||||
result +=
|
||||
"## " + std::format("{:02d}-{:02d}-{:02d}", date.year, date.month, date.day) + "\n\n";
|
||||
for (const auto &event : *(day->events())) {
|
||||
auto &start = event->getStartTime();
|
||||
auto &end = event->getEndTime();
|
||||
result += "> " +
|
||||
std::format(
|
||||
"{:02d}h{:02d}-{:02d}h{:02d} {}", start.hour, start.minute, end.hour,
|
||||
end.minute, event->getText()
|
||||
) +
|
||||
"\n";
|
||||
for (const auto &task : *(event->tasks())) {
|
||||
result += taskToString(*task) + '\n';
|
||||
}
|
||||
result += '\n';
|
||||
}
|
||||
for (const auto &task : *(day->tasks())) {
|
||||
result += taskToString(*task) + '\n';
|
||||
}
|
||||
result += '\n';
|
||||
}
|
||||
|
||||
if (source.unscheduledTasks()->size() > 0) {
|
||||
result += "## Unscheduled\n\n";
|
||||
for (const auto &task : *(source.unscheduledTasks())) {
|
||||
result += taskToString(*task) + '\n';
|
||||
}
|
||||
result += '\n';
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
MiraiMarkdownFormatParseResult TodoMdFormat::parse(const std::string &content)
|
||||
{
|
||||
cpputils::debug::Timer readMdFormatDuration;
|
||||
std::vector<TaskItem> taskItems;
|
||||
std::string line;
|
||||
|
||||
std::stringstream contentStream(content);
|
||||
|
||||
if (!std::getline(contentStream, line) || line.substr(0, 2) != "# ") {
|
||||
std::cerr << "Couldn't find the task list name" << std::endl;
|
||||
}
|
||||
|
||||
std::string name = line.substr(2);
|
||||
std::string currentDateString = "";
|
||||
|
||||
std::vector<mirai::DayData> daysData;
|
||||
std::vector<mirai::TaskItemData> unscheduledTasks;
|
||||
mirai::DayData *currentDay = nullptr;
|
||||
mirai::EventData *currentEvent = nullptr;
|
||||
|
||||
cpputils::debug::Timer stringToTaskDuration;
|
||||
stringToTaskDuration.reset();
|
||||
cpputils::debug::Timer gelinesDuration;
|
||||
while (std::getline(contentStream, line)) {
|
||||
if (std::string_view{line.data(), 3} == "## ") {
|
||||
currentDateString = line.substr(3);
|
||||
if (currentDateString == "Unscheduled") {
|
||||
currentDay = nullptr;
|
||||
continue;
|
||||
}
|
||||
auto dateOpt = mirai::stringToDate(currentDateString);
|
||||
if (!dateOpt.has_value()) {
|
||||
throw std::runtime_error("Malformated date");
|
||||
}
|
||||
daysData.push_back({.date = dateOpt.value()});
|
||||
currentDay = &daysData.back();
|
||||
} else if (line.starts_with("> ")) {
|
||||
auto event = stringToEvent(line, currentDateString);
|
||||
if (currentDay) {
|
||||
currentDay->events.push_back(event);
|
||||
currentEvent = ¤tDay->events.back();
|
||||
}
|
||||
} else if (line.starts_with("- [ ]") || line.starts_with("- [X]")) {
|
||||
stringToTaskDuration.start();
|
||||
TaskItemData taskItemData = stringToTask(line, currentDateString);
|
||||
stringToTaskDuration.stop();
|
||||
if (currentEvent) {
|
||||
currentEvent->tasks.push_back(taskItemData);
|
||||
} else if (currentDay) {
|
||||
currentDay->tasks.push_back(taskItemData);
|
||||
} else {
|
||||
unscheduledTasks.push_back(taskItemData);
|
||||
}
|
||||
} else if (cpputils::string::trim(line) == "") {
|
||||
currentEvent = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
gelinesDuration.printTimeElapsed("getlinesDuration");
|
||||
stringToTaskDuration.printTimeElapsed("stringToTaskDuration");
|
||||
readMdFormatDuration.printTimeElapsed("Reading MD File duration");
|
||||
return {.name = name, .days = daysData, .unscheduledTasks = unscheduledTasks};
|
||||
}
|
||||
} // namespace mirai
|
38
external/mirai-core-old/src/utils.cpp
vendored
38
external/mirai-core-old/src/utils.cpp
vendored
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "utils.h"
|
||||
#include <cctype>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
bool isDate(const std::string &dateStr)
|
||||
{
|
||||
// std regex are really slow
|
||||
/*std::regex regex("[0-9]{4}-[0-9]{2}-[0-9]{2}");*/
|
||||
/*return std::regex_match(dateStr, regex);*/
|
||||
|
||||
// Quick hand made check instead of regex until I rework date to use timestamp or std::chrono
|
||||
if (dateStr.length() != 10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dateStr[4] != '-' || dateStr[7] != '-') {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < dateStr.length(); ++i) {
|
||||
if (i == 4 || i == 7) {
|
||||
// These are the '-' characters
|
||||
continue;
|
||||
}
|
||||
if (!isdigit(dateStr[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace mirai
|
|
@ -55,15 +55,15 @@ struct UpdatableEventData {
|
|||
std::optional<Time> endsAt;
|
||||
};
|
||||
|
||||
class SourceDataProvider
|
||||
class DataProvider
|
||||
{
|
||||
|
||||
public:
|
||||
SourceDataProvider() {};
|
||||
SourceDataProvider(SourceDataProvider &) = delete;
|
||||
SourceDataProvider(SourceDataProvider &&) = delete;
|
||||
DataProvider() {};
|
||||
DataProvider(DataProvider &) = delete;
|
||||
DataProvider(DataProvider &&) = delete;
|
||||
|
||||
virtual ~SourceDataProvider() = default;
|
||||
virtual ~DataProvider() = default;
|
||||
virtual void save() = 0;
|
||||
virtual void load() = 0;
|
||||
|
||||
|
@ -95,7 +95,7 @@ class SourceDataProvider
|
|||
virtual std::optional<DayData> getDayByDate(const Date &date) = 0;
|
||||
virtual void updateDay(int dayId, UpdatableDayData updateData) = 0;
|
||||
|
||||
const int id = SourceDataProvider::generateNextId();
|
||||
const int id = DataProvider::generateNextId();
|
||||
|
||||
void setDirty(bool dirty)
|
||||
{
|
6
external/mirai-core/include/mirai-core/Day.h
vendored
6
external/mirai-core/include/mirai-core/Day.h
vendored
|
@ -6,7 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "SourceDataProvider.h"
|
||||
#include "DataProvider.h"
|
||||
#include <vector>
|
||||
|
||||
namespace mirai
|
||||
|
@ -19,7 +19,7 @@ class Day
|
|||
{
|
||||
|
||||
public:
|
||||
Day(SourceDataProvider *data, DayData day) : data_(data), dayData_(day) {};
|
||||
Day(DataProvider *data, DayData day) : data_(data), dayData_(day) {};
|
||||
|
||||
Date date() const;
|
||||
std::vector<Task> tasks();
|
||||
|
@ -32,7 +32,7 @@ class Day
|
|||
|
||||
private:
|
||||
DayData dayData_;
|
||||
SourceDataProvider *data_;
|
||||
DataProvider *data_;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "DataProvider.h"
|
||||
#include "Day.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -20,7 +20,7 @@ class Event
|
|||
{
|
||||
|
||||
public:
|
||||
Event(SourceDataProvider *data, EventData eventData) : data_(data), eventData_(eventData) {};
|
||||
Event(DataProvider *data, EventData eventData) : data_(data), eventData_(eventData) {};
|
||||
|
||||
std::string title() const;
|
||||
Time startsAt() const;
|
||||
|
@ -38,7 +38,7 @@ class Event
|
|||
|
||||
private:
|
||||
EventData eventData_;
|
||||
SourceDataProvider *data_;
|
||||
DataProvider *data_;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "DataProvider.h"
|
||||
#include "DateTime.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
|
@ -26,10 +26,10 @@ struct MarkdownData {
|
|||
std::vector<EventData> events;
|
||||
};
|
||||
|
||||
class MarkdownDataProvider : public SourceDataProvider
|
||||
class MarkdownDataProvider : public DataProvider
|
||||
{
|
||||
public:
|
||||
MarkdownDataProvider(const std::string &filePath) : filePath_(filePath), SourceDataProvider()
|
||||
MarkdownDataProvider(const std::string &filePath) : filePath_(filePath), DataProvider()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -19,11 +19,10 @@ class Mirai
|
|||
{
|
||||
|
||||
public:
|
||||
void loadSource(std::unique_ptr<SourceDataProvider> &&resource);
|
||||
void loadSource(std::unique_ptr<DataProvider> &&resource);
|
||||
void unloadAllSources();
|
||||
void save();
|
||||
std::optional<std::reference_wrapper<SourceDataProvider>>
|
||||
getSourceByName(const std::string &name);
|
||||
std::optional<std::reference_wrapper<DataProvider>> getSourceByName(const std::string &name);
|
||||
|
||||
std::vector<std::unique_ptr<Source>> &getSources();
|
||||
const std::vector<std::string> &getTags();
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "DataProvider.h"
|
||||
#include "DateTime.h"
|
||||
#include "Day.h"
|
||||
#include "Event.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include "Task.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -31,7 +31,7 @@ struct createEventParams {
|
|||
};
|
||||
|
||||
struct SourceConstructor {
|
||||
SourceDataProvider *sourceDataProvider;
|
||||
DataProvider *sourceDataProvider;
|
||||
};
|
||||
|
||||
class Source
|
||||
|
@ -84,6 +84,6 @@ class Source
|
|||
return nextId++;
|
||||
}
|
||||
|
||||
SourceDataProvider *data;
|
||||
DataProvider *data;
|
||||
};
|
||||
} // namespace mirai
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "DataProvider.h"
|
||||
#include "Event.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
|
@ -19,14 +19,16 @@ class Task
|
|||
{
|
||||
|
||||
public:
|
||||
Task(SourceDataProvider *data, TaskData task) : data_(data), task_(task) {};
|
||||
Task(DataProvider *data, TaskData task) : data_(data), task_(task) {};
|
||||
|
||||
std::string title() const;
|
||||
mirai::TaskState state() const;
|
||||
bool checked() const;
|
||||
bool hasEvent() const;
|
||||
|
||||
void setTitle(const std::string &newTitle);
|
||||
void setDay(const Day &day);
|
||||
void setDate(const Date &date);
|
||||
void setEvent(const Event &event);
|
||||
void setChecked(bool checked);
|
||||
|
||||
|
@ -35,7 +37,7 @@ class Task
|
|||
|
||||
private:
|
||||
TaskData task_;
|
||||
SourceDataProvider *data_;
|
||||
DataProvider *data_;
|
||||
};
|
||||
|
||||
} // namespace mirai
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include "MarkdownDataProvider.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include "DataProvider.h"
|
||||
#include "cpp-utils/debug.h"
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
|
|
6
external/mirai-core/src/Mirai.cpp
vendored
6
external/mirai-core/src/Mirai.cpp
vendored
|
@ -6,8 +6,8 @@
|
|||
|
||||
#include "Mirai.h"
|
||||
#include "Config.h"
|
||||
#include "DataProvider.h"
|
||||
#include "Source.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include "cpp-utils/debug.h"
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
|
@ -20,9 +20,9 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
void Mirai::loadSource(std::unique_ptr<SourceDataProvider> &&resource)
|
||||
void Mirai::loadSource(std::unique_ptr<DataProvider> &&resource)
|
||||
{
|
||||
SourceDataProvider *sourceDataProvider = resource.release();
|
||||
DataProvider *sourceDataProvider = resource.release();
|
||||
sourceDataProvider->load();
|
||||
sources_.push_back(
|
||||
std::make_unique<Source>(SourceConstructor{.sourceDataProvider = sourceDataProvider})
|
||||
|
|
2
external/mirai-core/src/Source.cpp
vendored
2
external/mirai-core/src/Source.cpp
vendored
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include "Source.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include "DataProvider.h"
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
|
18
external/mirai-core/src/Task.cpp
vendored
18
external/mirai-core/src/Task.cpp
vendored
|
@ -5,8 +5,9 @@
|
|||
*/
|
||||
|
||||
#include "Task.h"
|
||||
#include "DataProvider.h"
|
||||
#include "Day.h"
|
||||
#include "SourceDataProvider.h"
|
||||
#include "utils.h"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
|
@ -38,6 +39,11 @@ bool Task::checked() const
|
|||
return task_.state == mirai::DONE;
|
||||
}
|
||||
|
||||
bool Task::hasEvent() const
|
||||
{
|
||||
return task_.eventId.has_value();
|
||||
}
|
||||
|
||||
void Task::setTitle(const std::string &newTitle)
|
||||
{
|
||||
data_->updateTask(id(), {.title = newTitle});
|
||||
|
@ -49,6 +55,16 @@ void Task::setDay(const Day &day)
|
|||
data_->updateTask(id(), {.dayId = day.id(), .eventId = emptyEventId});
|
||||
}
|
||||
|
||||
void Task::setDate(const Date &date)
|
||||
{
|
||||
auto day = data_->getDayByDate(date);
|
||||
if (!day.has_value()) {
|
||||
day = data_->insertDay({.id = generateUniqueId(), .date = date});
|
||||
}
|
||||
auto emptyEventId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
|
||||
data_->updateTask(id(), {.dayId = day.value().id, .eventId = emptyEventId});
|
||||
}
|
||||
|
||||
void Task::setEvent(const Event &event)
|
||||
{
|
||||
auto emptyDayId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
|
||||
|
|
3
external/slint-vynui/ActionButton.slint
vendored
3
external/slint-vynui/ActionButton.slint
vendored
|
@ -7,6 +7,7 @@ export component VActionButton inherits Rectangle {
|
|||
in property<brush> icon-colorize: Palette.foreground;
|
||||
in property<length> icon-size: 1rem;
|
||||
in property<string> icon-svg;
|
||||
in property<length> icon-svg-stroke-width: 2px;
|
||||
in property enabled <=> ta.enabled;
|
||||
callback clicked;
|
||||
|
||||
|
@ -33,7 +34,7 @@ export component VActionButton inherits Rectangle {
|
|||
padding: 8px;
|
||||
commands: root.icon-svg;
|
||||
stroke: icon-colorize;
|
||||
stroke-width: 2px;
|
||||
stroke-width: icon-svg-stroke-width;
|
||||
width: icon-size;
|
||||
height: icon-size;
|
||||
fill: icon-colorize;
|
||||
|
|
34
external/slint-vynui/DatePicker.slint
vendored
34
external/slint-vynui/DatePicker.slint
vendored
|
@ -1,12 +1,11 @@
|
|||
import { Button, DatePickerPopup, Date, Palette } from "std-widgets.slint";
|
||||
import { VLabeledComponent } from "LabeledComponent.slint";
|
||||
import { VActionButton } from "ActionButton.slint";
|
||||
import { VButton } from "Button.slint";
|
||||
|
||||
|
||||
|
||||
export component VDatePicker inherits VLabeledComponent {
|
||||
in-out property<Date> date;
|
||||
in-out property<string> dateDisplay: formatZeroPadding(date.day) + "/" + formatZeroPadding(date.month) + "/" + date.year;
|
||||
in-out property<string> dateDisplay;
|
||||
|
||||
pure function formatZeroPadding(number: int) -> string {
|
||||
if (number < 10) {
|
||||
|
@ -15,10 +14,31 @@ export component VDatePicker inherits VLabeledComponent {
|
|||
return number;
|
||||
}
|
||||
|
||||
button := VButton {
|
||||
text: dateDisplay;
|
||||
enabled: root.enabled;
|
||||
clicked => { taskDateInput.show() }
|
||||
pure function getDateDisplay() -> string {
|
||||
if (date.year == 0) {
|
||||
return "Unscheduled";
|
||||
}
|
||||
return formatZeroPadding(date.day) + "/" + formatZeroPadding(date.month) + "/" + date.year;
|
||||
}
|
||||
|
||||
function resetDate() {
|
||||
date.year = 0;
|
||||
date.month = 0;
|
||||
date.day = 0;
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
VButton {
|
||||
text: getDateDisplay();
|
||||
enabled: root.enabled;
|
||||
clicked => { taskDateInput.show() }
|
||||
}
|
||||
VActionButton {
|
||||
icon-svg: "M18 28A12 12 0 1 0 6 16v6.2l-3.6-3.6L1 20l6 6l6-6l-1.4-1.4L8 22.2V16a10 10 0 1 1 10 10Z";
|
||||
icon-svg-stroke-width: 1px;
|
||||
enabled: root.enabled;
|
||||
clicked => { resetDate() }
|
||||
}
|
||||
}
|
||||
|
||||
taskDateInput := DatePickerPopup {
|
||||
|
|
16
external/slint-vynui/TextInput.slint
vendored
16
external/slint-vynui/TextInput.slint
vendored
|
@ -8,6 +8,15 @@ export component VTextInput inherits VLabeledComponent {
|
|||
in-out property placeholder <=> textInputComponent.accessible-placeholder-text;
|
||||
in-out property wrap <=> textInputComponent.wrap;
|
||||
callback accepted();
|
||||
callback edited();
|
||||
callback started-writting();
|
||||
|
||||
public function edit-text(text: string) {
|
||||
root.text = text;
|
||||
root.old-text = text;
|
||||
}
|
||||
|
||||
private property <string> old-text: "";
|
||||
|
||||
VerticalLayout {
|
||||
padding: 4px;
|
||||
|
@ -16,6 +25,13 @@ export component VTextInput inherits VLabeledComponent {
|
|||
textInputComponent := TextInput {
|
||||
color: Palette.foreground;
|
||||
accepted => { root.accepted() }
|
||||
edited => {
|
||||
root.edited();
|
||||
if (textInputComponent.text != "" && old-text == "") {
|
||||
root.started-writting();
|
||||
}
|
||||
old-text = textInputComponent.text;
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
VText {
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
#include "UiState.h"
|
||||
#include "Utils.h"
|
||||
#include "appwindow.h"
|
||||
#include "mirai-core/DataProvider.h"
|
||||
#include "mirai-core/Day.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "mirai-core/SourceDataProvider.h"
|
||||
#include "slint.h"
|
||||
#include "slint_sharedvector.h"
|
||||
#include "slint_string.h"
|
||||
|
@ -110,6 +110,7 @@ void UiState::setupCallbacks()
|
|||
const mirai::Source *source = miraiInstance_->getSourceById(index);
|
||||
view_.addSource(*source);
|
||||
}
|
||||
mainWindow_->global<Backend>().set_default_source_index(index == -1 ? 0 : index);
|
||||
view_.update();
|
||||
reloadSources();
|
||||
reloadTasks();
|
||||
|
@ -152,18 +153,14 @@ void UiState::setupCallbacks()
|
|||
auto source = miraiInstance_->getSourceById(newTaskData.sourceId);
|
||||
assert(source);
|
||||
auto task = source->getTaskById(newTaskData.id);
|
||||
assert(task);
|
||||
assert(task.has_value());
|
||||
const mirai::Date &date = SlintDateToMiraiDate(newTaskData.date);
|
||||
const auto dayOpt = source->getDayByDate(date);
|
||||
|
||||
if (!dayOpt.has_value()) {
|
||||
throw std::runtime_error("Missing auto day creation implementation");
|
||||
}
|
||||
|
||||
const auto day = dayOpt.value();
|
||||
|
||||
task->setTitle(std::string(newTaskData.title));
|
||||
task->setDay(day);
|
||||
|
||||
if (!task.value().hasEvent() && date.year != 0) {
|
||||
task->setDate(date);
|
||||
}
|
||||
|
||||
miraiInstance_->save();
|
||||
view_.update();
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
#include "UiState.h"
|
||||
#include "mirai-core/Config.h"
|
||||
#include "mirai-core/DataProvider.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include "mirai-core/SourceDataProvider.h"
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
|
@ -21,7 +21,7 @@ int main(int argc, char **argv)
|
|||
mirai::Mirai mirai;
|
||||
|
||||
for (const auto &sourceFilePath : config.sources()) {
|
||||
std::unique_ptr<mirai::SourceDataProvider> file =
|
||||
std::unique_ptr<mirai::DataProvider> file =
|
||||
std::make_unique<mirai::MarkdownDataProvider>(sourceFilePath);
|
||||
mirai.loadSource(std::move(file));
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ struct OpenNewTaskFormParams {
|
|||
|
||||
export global Backend {
|
||||
in-out property<[Source]> sources-selected;
|
||||
in-out property<int> default-source-index;
|
||||
in-out property<[string]> sources;
|
||||
in-out property<bool> no-source-selected;
|
||||
in-out property<[string]> tags;
|
||||
|
|
|
@ -30,22 +30,6 @@ export component MainView inherits Rectangle {
|
|||
horizontal-stretch: 1;
|
||||
alignment: start;
|
||||
spacing: 8px;
|
||||
VButton {
|
||||
text: "New task";
|
||||
clicked => { Backend.open_new_task_form({
|
||||
eventSourceId: -1,
|
||||
eventId: -1,
|
||||
})}
|
||||
icon-source: @image-url("./images/add.png");
|
||||
icon-colorize: Colors.greenyellow;
|
||||
}
|
||||
|
||||
VButton {
|
||||
text: "New event";
|
||||
clicked => { Backend.open_new_event_form() }
|
||||
icon-source: @image-url("./images/add.png");
|
||||
icon-colorize: Colors.greenyellow;
|
||||
}
|
||||
VButton {
|
||||
text: "Show/Hide completed tasks";
|
||||
clicked => {
|
||||
|
@ -71,9 +55,10 @@ export component MainView inherits Rectangle {
|
|||
VerticalLayout {
|
||||
alignment: start;
|
||||
spacing: 16px;
|
||||
if Backend.visible_tasks.length == 0 : VText {
|
||||
if Backend.visible_tasks.length == 0 && Backend.unscheduled-tasks.length == 0 : VText {
|
||||
text: "There is no task to show";
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
for day[dayIndex] in Backend.visible_tasks: VerticalLayout {
|
||||
Rectangle {
|
||||
|
|
|
@ -19,6 +19,32 @@ export component CreateTaskOrEvent inherits Rectangle {
|
|||
animate padding {
|
||||
duration: 250ms;
|
||||
}
|
||||
newTaskTitleInput := VTextInput {
|
||||
placeholder: "Add new Task / Event";
|
||||
started-writting() => {
|
||||
sourceInput.current-index = Backend.default-source-index;
|
||||
}
|
||||
accepted => {
|
||||
if (task-or-event == 1) {
|
||||
Backend.createTask({
|
||||
sourceId: sourceInput.current-index,
|
||||
eventId: -1,
|
||||
title: newTaskTitleInput.text,
|
||||
scheduled: taskDateInput.date.year != 0,
|
||||
date: taskDateInput.date
|
||||
})
|
||||
} else {
|
||||
Backend.createEvent({
|
||||
sourceId: sourceInput.current-index,
|
||||
title: newTaskTitleInput.text,
|
||||
date: taskDateInput.date,
|
||||
startsAt: eventStartTimeInput.time,
|
||||
endsAt: eventEndTimeInput.time,
|
||||
});
|
||||
}
|
||||
newTaskTitleInput.edit-text("");
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
min-height: 0px;
|
||||
max-height: newTaskTitleInput.text != "" ? 512px : 0px;
|
||||
|
@ -43,11 +69,11 @@ export component CreateTaskOrEvent inherits Rectangle {
|
|||
alignment: end;
|
||||
sourceInput := ComboBox {
|
||||
model: Backend.sources;
|
||||
|
||||
}
|
||||
}
|
||||
VText { text: "on"; vertical-alignment: bottom;}
|
||||
taskDateInput := VDatePicker {
|
||||
label: "Date";
|
||||
enabled: true;
|
||||
}
|
||||
HorizontalLayout {
|
||||
|
@ -55,41 +81,14 @@ export component CreateTaskOrEvent inherits Rectangle {
|
|||
HorizontalLayout {
|
||||
spacing: 4px;
|
||||
VText { text: "between"; vertical-alignment: bottom; }
|
||||
eventStartTimeInput := VTimePicker {
|
||||
label: "Starts at";
|
||||
}
|
||||
eventStartTimeInput := VTimePicker { }
|
||||
VText { text: "and"; vertical-alignment: bottom; }
|
||||
eventEndTimeInput := VTimePicker {
|
||||
label: "Ends at";
|
||||
}
|
||||
eventEndTimeInput := VTimePicker { }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
newTaskTitleInput := VTextInput {
|
||||
placeholder: "Add new Task / Event";
|
||||
accepted => {
|
||||
if (task-or-event == 1) {
|
||||
Backend.createTask({
|
||||
sourceId: sourceInput.current-index,
|
||||
eventId: -1,
|
||||
title: newTaskTitleInput.text,
|
||||
scheduled: taskDateInput.date.year != 0,
|
||||
date: taskDateInput.date
|
||||
})
|
||||
} else {
|
||||
Backend.createEvent({
|
||||
sourceId: sourceInput.current-index,
|
||||
title: newTaskTitleInput.text,
|
||||
date: taskDateInput.date,
|
||||
startsAt: eventStartTimeInput.time,
|
||||
endsAt: eventEndTimeInput.time,
|
||||
});
|
||||
}
|
||||
newTaskTitleInput.text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue