mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 18:23:19 +00:00
Convert classes and files to snake_case
This commit is contained in:
parent
686d86df6f
commit
6fa94b279c
26 changed files with 272 additions and 301 deletions
|
@ -4,13 +4,13 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "Mirai.h"
|
||||
#include "DataProvider.h"
|
||||
#include "MarkdownDataProvider.h"
|
||||
#include "Source.h"
|
||||
#include "core.h"
|
||||
#include "data_provider.h"
|
||||
#include "markdown_data_provider.h"
|
||||
#include "rei-json/Array.h"
|
||||
#include "rei-json/Object.h"
|
||||
#include "rei-json/json.h"
|
||||
#include "source.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
@ -22,7 +22,7 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
void Mirai::loadConfig(const std::string &path)
|
||||
void core::loadConfig(const std::string &path)
|
||||
{
|
||||
std::ifstream file(path);
|
||||
if (!file) {
|
||||
|
@ -54,7 +54,7 @@ void Mirai::loadConfig(const std::string &path)
|
|||
}
|
||||
}
|
||||
|
||||
void Mirai::saveConfig()
|
||||
void core::saveConfig()
|
||||
{
|
||||
std::ofstream file(configPath_);
|
||||
if (!file.is_open()) {
|
||||
|
@ -78,12 +78,12 @@ void Mirai::saveConfig()
|
|||
file.close();
|
||||
}
|
||||
|
||||
Mirai::Mirai(const std::string &configFilePath) : configPath_(configFilePath)
|
||||
core::core(const std::string &configFilePath) : configPath_(configFilePath)
|
||||
{
|
||||
loadConfig(configFilePath);
|
||||
}
|
||||
|
||||
void Mirai::addSource(
|
||||
void core::addSource(
|
||||
const std::string &name, const std::string &type, std::unique_ptr<data_provider> &&new_source
|
||||
)
|
||||
{
|
||||
|
@ -98,7 +98,7 @@ void Mirai::addSource(
|
|||
sourceAdded.emit(nullptr);
|
||||
};
|
||||
|
||||
void Mirai::editSource(
|
||||
void core::editSource(
|
||||
int id, const std::string &name, const std::string &color, const std::string &path
|
||||
)
|
||||
{
|
||||
|
@ -111,7 +111,7 @@ void Mirai::editSource(
|
|||
sourceEdited.emit(nullptr);
|
||||
}
|
||||
|
||||
void Mirai::deleteSource(int id)
|
||||
void core::deleteSource(int id)
|
||||
{
|
||||
sources_.erase(
|
||||
std::remove_if(
|
||||
|
@ -125,12 +125,12 @@ void Mirai::deleteSource(int id)
|
|||
sourceDeleted.emit(id);
|
||||
}
|
||||
|
||||
void Mirai::unloadAllSources()
|
||||
void core::unloadAllSources()
|
||||
{
|
||||
sources_.clear();
|
||||
}
|
||||
|
||||
void Mirai::save()
|
||||
void core::save()
|
||||
{
|
||||
for (auto &source : sources_) {
|
||||
if (source->is_dirty()) {
|
||||
|
@ -139,12 +139,12 @@ void Mirai::save()
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<source>> &Mirai::getSources()
|
||||
std::vector<std::unique_ptr<source>> &core::getSources()
|
||||
{
|
||||
return sources_;
|
||||
}
|
||||
|
||||
source *Mirai::getSourceById(int id)
|
||||
source *core::getSourceById(int id)
|
||||
{
|
||||
auto source_found = std::ranges::find_if(sources_, [&](const std::unique_ptr<source> &source) {
|
||||
return source->id == id;
|
||||
|
@ -156,7 +156,7 @@ source *Mirai::getSourceById(int id)
|
|||
return source_found->get();
|
||||
}
|
||||
|
||||
source *Mirai::getSourceByName(const std::string &name)
|
||||
source *core::getSourceByName(const std::string &name)
|
||||
{
|
||||
auto source_found = std::ranges::find_if(sources_, [&](const std::unique_ptr<source> &source) {
|
||||
return source->name() == name;
|
||||
|
@ -168,17 +168,17 @@ source *Mirai::getSourceByName(const std::string &name)
|
|||
return source_found->get();
|
||||
}
|
||||
|
||||
void Mirai::onSourceAdded(std::function<void(source *)> f)
|
||||
void core::onSourceAdded(std::function<void(source *)> f)
|
||||
{
|
||||
sourceAdded.registerCallback(f);
|
||||
}
|
||||
|
||||
void Mirai::onSourceEdited(std::function<void(source *)> f)
|
||||
void core::onSourceEdited(std::function<void(source *)> f)
|
||||
{
|
||||
sourceEdited.registerCallback(f);
|
||||
}
|
||||
|
||||
void Mirai::onSourceDeleted(std::function<void(int)> f)
|
||||
void core::onSourceDeleted(std::function<void(int)> f)
|
||||
{
|
||||
sourceDeleted.registerCallback(f);
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "DateTime.h"
|
||||
#include "date.h"
|
||||
#include <charconv>
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
|
@ -15,7 +15,7 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
std::optional<mirai::Date> stringToDate(const std::string &dateStr)
|
||||
std::optional<class date> string_to_date(const std::string &dateStr)
|
||||
{
|
||||
using std::operator""sv;
|
||||
|
||||
|
@ -33,14 +33,14 @@ std::optional<mirai::Date> stringToDate(const std::string &dateStr)
|
|||
auto year = dateSplit[0];
|
||||
auto month = dateSplit[1];
|
||||
auto day = dateSplit[2];
|
||||
return mirai::Date(year, static_cast<unsigned>(month), static_cast<unsigned>(day));
|
||||
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(int year, unsigned month, unsigned day) : year(year), month(month), day(day)
|
||||
{
|
||||
}
|
||||
|
||||
Date::Date(std::chrono::time_point<std::chrono::system_clock> tp)
|
||||
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());
|
||||
|
@ -48,19 +48,19 @@ Date::Date(std::chrono::time_point<std::chrono::system_clock> tp)
|
|||
day = static_cast<unsigned>(chronoDate.day());
|
||||
}
|
||||
|
||||
Date::Date(std::chrono::year_month_day chronoDate)
|
||||
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());
|
||||
}
|
||||
|
||||
bool Date::operator==(const Date &other) const
|
||||
bool date::operator==(const date &other) const
|
||||
{
|
||||
return other.year == year && other.month == month && other.day == day;
|
||||
}
|
||||
|
||||
bool Date::operator<(const Date &other) const
|
||||
bool date::operator<(const date &other) const
|
||||
{
|
||||
if (year < other.year) {
|
||||
return true;
|
||||
|
@ -74,42 +74,42 @@ bool Date::operator<(const Date &other) const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Date::operator>(const Date &other) const
|
||||
bool date::operator>(const date &other) const
|
||||
{
|
||||
return !(*this < other) && !(*this == other);
|
||||
}
|
||||
|
||||
bool Date::operator>=(const Date &other) const
|
||||
bool date::operator>=(const date &other) const
|
||||
{
|
||||
return (*this > other) || (*this == other);
|
||||
}
|
||||
|
||||
bool Date::operator<=(const Date &other) const
|
||||
bool date::operator<=(const date &other) const
|
||||
{
|
||||
return (*this < other) || (*this == other);
|
||||
}
|
||||
|
||||
Time::Time(int hour, int minute) : hour(hour), minute(minute)
|
||||
time::time(int hour, int minute) : hour(hour), minute(minute)
|
||||
{
|
||||
}
|
||||
|
||||
Time::Time(std::chrono::time_point<std::chrono::system_clock> tp)
|
||||
time::time(std::chrono::time_point<std::chrono::system_clock> tp)
|
||||
{
|
||||
auto localTp = std::chrono::zoned_time{std::chrono::current_zone(), tp}.get_local_time();
|
||||
auto chronoDate = std::chrono::floor<std::chrono::days>(localTp);
|
||||
auto chronoTime =
|
||||
std::chrono::hh_mm_ss{std::chrono::duration_cast<std::chrono::minutes>(localTp - chronoDate)
|
||||
};
|
||||
auto chronoTime = std::chrono::hh_mm_ss{
|
||||
std::chrono::duration_cast<std::chrono::minutes>(localTp - chronoDate)
|
||||
};
|
||||
hour = static_cast<int>(chronoTime.hours().count());
|
||||
minute = static_cast<int>(chronoTime.minutes().count());
|
||||
}
|
||||
|
||||
bool Time::operator==(const Time &other) const
|
||||
bool time::operator==(const time &other) const
|
||||
{
|
||||
return other.hour == hour && other.minute == minute;
|
||||
}
|
||||
|
||||
bool Time::operator<(const Time &other) const
|
||||
bool time::operator<(const time &other) const
|
||||
{
|
||||
if (hour < other.hour) {
|
||||
return true;
|
||||
|
@ -120,7 +120,7 @@ bool Time::operator<(const Time &other) const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Time::operator>(const Time &other) const
|
||||
bool time::operator>(const time &other) const
|
||||
{
|
||||
return !(*this < other) && !(*this == other);
|
||||
}
|
|
@ -4,59 +4,59 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "Event.h"
|
||||
#include "Task.h"
|
||||
#include "event.h"
|
||||
#include "task.h"
|
||||
#include <string>
|
||||
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
int Event::id() const
|
||||
int event::id() const
|
||||
{
|
||||
return _data.id;
|
||||
}
|
||||
|
||||
int Event::source_id() const
|
||||
int event::source_id() const
|
||||
{
|
||||
return _provider->id;
|
||||
}
|
||||
|
||||
std::string Event::title() const
|
||||
std::string event::title() const
|
||||
{
|
||||
return _data.title;
|
||||
}
|
||||
|
||||
Date Event::date() const
|
||||
date event::date() const
|
||||
{
|
||||
return _data.date;
|
||||
}
|
||||
|
||||
Time Event::starts_at() const
|
||||
time event::starts_at() const
|
||||
{
|
||||
return _data.starts_at;
|
||||
}
|
||||
|
||||
Time Event::ends_at() const
|
||||
time event::ends_at() const
|
||||
{
|
||||
return _data.ends_at;
|
||||
}
|
||||
|
||||
void Event::set_title(const std::string &newTitle)
|
||||
void event::set_title(const std::string &newTitle)
|
||||
{
|
||||
_provider->update_event(id(), {.title = newTitle});
|
||||
}
|
||||
|
||||
void Event::set_date(const Date &date)
|
||||
void event::set_date(const class date &date)
|
||||
{
|
||||
_provider->update_event(id(), {.date = date});
|
||||
}
|
||||
|
||||
void Event::set_start_time(const Time &time)
|
||||
void event::set_start_time(const time &time)
|
||||
{
|
||||
_provider->update_event(id(), {.starts_at = time});
|
||||
}
|
||||
|
||||
void Event::set_end_time(const Time &time)
|
||||
void event::set_end_time(const time &time)
|
||||
{
|
||||
_provider->update_event(id(), {.ends_at = time});
|
||||
}
|
|
@ -4,9 +4,9 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "MarkdownDataProvider.h"
|
||||
#include "DataProvider.h"
|
||||
#include "markdown_data_provider.h"
|
||||
#include "cpp-utils/debug.h"
|
||||
#include "data_provider.h"
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
@ -92,7 +92,7 @@ std::vector<task_data> markdown_data_provider::get_tasks_without_date()
|
|||
return findAll(_data.tasks, [](const task_data &t) { return t.due_date == std::nullopt; });
|
||||
}
|
||||
|
||||
std::vector<task_data> markdown_data_provider::get_tasks_by_date(Date date)
|
||||
std::vector<task_data> markdown_data_provider::get_tasks_by_date(class date date)
|
||||
{
|
||||
return findAll(_data.tasks, [&](const task_data &t) { return t.due_date == date; });
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ std::optional<event_data> markdown_data_provider::get_event_by_id(int eventId)
|
|||
return findFirst(_data.events, [&](const event_data &event) { return event.id == eventId; });
|
||||
}
|
||||
|
||||
std::vector<event_data> markdown_data_provider::get_events_by_date(Date date)
|
||||
std::vector<event_data> markdown_data_provider::get_events_by_date(class date date)
|
||||
{
|
||||
return findAll(_data.events, [&](const event_data &event) { return event.date == date; });
|
||||
}
|
|
@ -4,9 +4,9 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "MarkdownDataProvider.h"
|
||||
#include "DataProvider.h"
|
||||
#include "markdown_data_provider.h"
|
||||
#include "cpp-utils/debug.h"
|
||||
#include "data_provider.h"
|
||||
#include "utils.h"
|
||||
#include <optional>
|
||||
#include <print>
|
||||
|
@ -56,7 +56,7 @@ task_data stringToTask(const std::string &str, const std::string &date)
|
|||
return taskItem;
|
||||
}
|
||||
|
||||
Time stringToTime(const std::string &str)
|
||||
time stringToTime(const std::string &str)
|
||||
{
|
||||
if (str.length() != 5) {
|
||||
throw std::runtime_error("Str time length must be 5 (got '" + str + "')");
|
||||
|
@ -67,7 +67,7 @@ Time stringToTime(const std::string &str)
|
|||
int hour, minute;
|
||||
std::from_chars(str.data(), str.data() + 2, hour);
|
||||
std::from_chars(str.data() + 3, str.data() + 5, minute);
|
||||
Time time{hour, minute};
|
||||
time time{hour, minute};
|
||||
|
||||
return time;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ event_data stringToEvent(const std::string &str, const std::string &dateString)
|
|||
|
||||
std::string text = stringUtils::trim(matches[4]);
|
||||
|
||||
auto date = stringToDate(dateString);
|
||||
auto date = string_to_date(dateString);
|
||||
|
||||
if (!date.has_value()) {
|
||||
throw std::runtime_error("Malformated date");
|
||||
|
@ -124,7 +124,7 @@ std::string markdown_data_provider::to_markdown()
|
|||
});
|
||||
|
||||
while (next_event_index < _data.events.size() || next_task_index < _data.tasks.size()) {
|
||||
std::optional<Date> current_date = std::nullopt;
|
||||
std::optional<class date> current_date = std::nullopt;
|
||||
// First we find the lowest date between the events and the tasks
|
||||
if (_data.events.size() > 0 && next_event_index < _data.events.size()) {
|
||||
current_date = _data.events.at(next_event_index).date;
|
||||
|
@ -199,7 +199,7 @@ markdown_data markdown_data_provider::parse_markdown(const std::string &content)
|
|||
_data.name = line.substr(2);
|
||||
std::string currentDateString = "";
|
||||
|
||||
std::optional<Date> current_date = std::nullopt;
|
||||
std::optional<class date> current_date = std::nullopt;
|
||||
|
||||
cpputils::debug::Timer stringToTaskDuration;
|
||||
stringToTaskDuration.reset();
|
||||
|
@ -211,7 +211,7 @@ markdown_data markdown_data_provider::parse_markdown(const std::string &content)
|
|||
current_date = std::nullopt;
|
||||
continue;
|
||||
}
|
||||
current_date = mirai::stringToDate(currentDateString);
|
||||
current_date = mirai::string_to_date(currentDateString);
|
||||
if (!current_date.has_value()) {
|
||||
throw std::runtime_error("Malformated date (1)");
|
||||
}
|
|
@ -4,8 +4,8 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "Source.h"
|
||||
#include "DataProvider.h"
|
||||
#include "source.h"
|
||||
#include "data_provider.h"
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
@ -42,64 +42,64 @@ void source::create_event(const create_event_params &new_event)
|
|||
});
|
||||
};
|
||||
|
||||
std::vector<Event> source::get_events()
|
||||
std::vector<class event> source::get_events()
|
||||
{
|
||||
auto event_data = data->get_events();
|
||||
std::vector<Event> events;
|
||||
std::vector<class event> events;
|
||||
std::transform(
|
||||
event_data.begin(), event_data.end(), std::back_inserter(events),
|
||||
[&](const struct event_data &event_data) { return Event{data, event_data}; }
|
||||
[&](const struct event_data &event_data) { return event{data, event_data}; }
|
||||
);
|
||||
return events;
|
||||
}
|
||||
|
||||
std::optional<Event> source::get_event_by_id(int evendId)
|
||||
std::optional<class event> source::get_event_by_id(int evendId)
|
||||
{
|
||||
auto event = data->get_event_by_id(evendId);
|
||||
if (!event.has_value()) {
|
||||
auto event_data = data->get_event_by_id(evendId);
|
||||
if (!event_data.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return Event{data, event.value()};
|
||||
return event{data, event_data.value()};
|
||||
}
|
||||
|
||||
void source::remove_event(const Event &event)
|
||||
void source::remove_event(const event &event)
|
||||
{
|
||||
data->remove_event_by_id(event.id());
|
||||
}
|
||||
|
||||
void source::remove_task(const Task &task)
|
||||
void source::remove_task(const task &task)
|
||||
{
|
||||
data->remove_task_by_id(task.id());
|
||||
}
|
||||
|
||||
std::optional<Task> source::get_task_by_id(int taskId)
|
||||
std::optional<task> source::get_task_by_id(int taskId)
|
||||
{
|
||||
auto taskData = data->get_task_by_id(taskId);
|
||||
if (!taskData.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
Task task{data, taskData.value()};
|
||||
task task{data, taskData.value()};
|
||||
return task;
|
||||
}
|
||||
|
||||
std::vector<Task> source::get_tasks()
|
||||
std::vector<task> source::get_tasks()
|
||||
{
|
||||
auto tasksData = data->get_tasks();
|
||||
std::vector<Task> tasks;
|
||||
std::vector<task> tasks;
|
||||
std::transform(
|
||||
tasksData.begin(), tasksData.end(), std::back_inserter(tasks),
|
||||
[&](const task_data &taskData) { return Task{data, taskData}; }
|
||||
[&](const task_data &taskData) { return task{data, taskData}; }
|
||||
);
|
||||
return tasks;
|
||||
}
|
||||
|
||||
std::vector<Task> source::get_unscheduled_tasks()
|
||||
std::vector<task> source::get_unscheduled_tasks()
|
||||
{
|
||||
auto tasksData = data->get_tasks_without_date();
|
||||
std::vector<Task> tasks;
|
||||
std::vector<task> tasks;
|
||||
std::transform(
|
||||
tasksData.begin(), tasksData.end(), std::back_inserter(tasks),
|
||||
[&](const task_data &taskData) { return Task{data, taskData}; }
|
||||
[&](const task_data &taskData) { return task{data, taskData}; }
|
||||
);
|
||||
return tasks;
|
||||
}
|
|
@ -4,8 +4,8 @@
|
|||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
*/
|
||||
|
||||
#include "Task.h"
|
||||
#include "DataProvider.h"
|
||||
#include "task.h"
|
||||
#include "data_provider.h"
|
||||
#include "utils.h"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
@ -13,37 +13,37 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
int Task::id() const
|
||||
int task::id() const
|
||||
{
|
||||
return task_.id;
|
||||
}
|
||||
|
||||
int Task::source_id() const
|
||||
int task::source_id() const
|
||||
{
|
||||
return data_->id;
|
||||
}
|
||||
|
||||
std::string Task::title() const
|
||||
std::string task::title() const
|
||||
{
|
||||
return task_.title;
|
||||
}
|
||||
|
||||
mirai::task_state Task::state() const
|
||||
mirai::task_state task::state() const
|
||||
{
|
||||
return task_.state;
|
||||
}
|
||||
|
||||
bool Task::checked() const
|
||||
bool task::checked() const
|
||||
{
|
||||
return task_.state == mirai::DONE;
|
||||
}
|
||||
|
||||
bool Task::has_due_date() const
|
||||
bool task::has_due_date() const
|
||||
{
|
||||
return task_.due_date.has_value();
|
||||
}
|
||||
|
||||
std::optional<Date> Task::due_date() const
|
||||
std::optional<class date> task::due_date() const
|
||||
{
|
||||
if (!task_.due_date.has_value()) {
|
||||
return std::nullopt;
|
||||
|
@ -51,24 +51,24 @@ std::optional<Date> Task::due_date() const
|
|||
return task_.due_date.value();
|
||||
}
|
||||
|
||||
void Task::set_title(const std::string &newTitle)
|
||||
void task::set_title(const std::string &newTitle)
|
||||
{
|
||||
data_->update_task(id(), {.title = newTitle});
|
||||
}
|
||||
|
||||
void Task::set_date(const Date &date)
|
||||
void task::set_date(const date &date)
|
||||
{
|
||||
auto emptyEventId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
|
||||
data_->update_task(id(), {.due_date = date});
|
||||
}
|
||||
|
||||
void Task::unschedule()
|
||||
void task::unschedule()
|
||||
{
|
||||
auto emptyId = std::optional<std::optional<int>>(std::optional<int>(std::nullopt));
|
||||
data_->update_task(id(), {.due_date = std::nullopt});
|
||||
}
|
||||
|
||||
void Task::set_checked(bool checked)
|
||||
void task::set_checked(bool checked)
|
||||
{
|
||||
data_->update_task(id(), {.state = checked ? DONE : TODO});
|
||||
}
|
2
external/mirai-core/src/utils.cpp
vendored
2
external/mirai-core/src/utils.cpp
vendored
|
@ -12,7 +12,7 @@
|
|||
namespace mirai
|
||||
{
|
||||
|
||||
bool isDate(const std::string &dateStr)
|
||||
bool is_date(const std::string &dateStr)
|
||||
{
|
||||
// std regex are really slow
|
||||
/*std::regex regex("[0-9]{4}-[0-9]{2}-[0-9]{2}");*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue