Refactor the whole structure, no more separation for C++ and Slint files

This commit is contained in:
Vyn 2024-11-04 14:45:27 +01:00
parent d6c781faa2
commit 893fcc11e3
35 changed files with 920 additions and 518 deletions

View file

@ -4,6 +4,8 @@
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
*/
#pragma once
#include <functional>
#include <vector>
@ -11,7 +13,7 @@ template <typename T> class EventEmitter
{
public:
void registerCallback(std::function<T> func)
void registerCallback(std::function<void(T)> func)
{
callbacks.push_back(func);
}
@ -24,5 +26,5 @@ template <typename T> class EventEmitter
}
private:
std::vector<std::function<T>> callbacks;
std::vector<std::function<void(T)>> callbacks;
};

View file

@ -6,6 +6,7 @@
#pragma once
#include "EventEmitter.h"
#include "Source.h"
#include <functional>
#include <memory>
@ -35,10 +36,18 @@ class Mirai
// Returns a non owning pointer to the requested resource or nullptr if not found.
Source *getSourceById(int id);
void onSourceAdded(std::function<void(Source *)> f);
void onSourceEdited(std::function<void(Source *)> f);
void onSourceDeleted(std::function<void(int)> f);
private:
void loadConfig(const std::string &path);
void saveConfig();
std::vector<std::unique_ptr<Source>> sources_;
std::string configPath_;
EventEmitter<Source *> sourceAdded;
EventEmitter<Source *> sourceEdited;
EventEmitter<int> sourceDeleted;
};
} // namespace mirai

View file

@ -88,6 +88,7 @@ void Mirai::addSource(
SourceConstructor{.name = name, .sourceDataProvider = sourceDataProvider}
));
saveConfig();
sourceAdded.emit(nullptr);
};
void Mirai::editSource(int id, const std::string &name, const std::string &path)
@ -97,6 +98,7 @@ void Mirai::editSource(int id, const std::string &name, const std::string &path)
DataProvider *sourceDataProvider = source->dataProvider();
saveConfig();
sourceEdited.emit(nullptr);
}
void Mirai::deleteSource(int id)
@ -113,6 +115,7 @@ void Mirai::deleteSource(int id)
);
saveConfig();
sourceDeleted.emit(id);
}
void Mirai::unloadAllSources()
@ -146,4 +149,19 @@ Source *Mirai::getSourceById(int id)
return source->get();
}
void Mirai::onSourceAdded(std::function<void(Source *)> f)
{
sourceAdded.registerCallback(f);
}
void Mirai::onSourceEdited(std::function<void(Source *)> f)
{
sourceEdited.registerCallback(f);
}
void Mirai::onSourceDeleted(std::function<void(int)> f)
{
sourceDeleted.registerCallback(f);
}
} // namespace mirai