also scen media on message creation

This commit is contained in:
Green Sky 2023-08-02 20:58:16 +02:00
parent ea8cc85c61
commit 5547ff6d2b
No known key found for this signature in database
2 changed files with 34 additions and 28 deletions

View File

@ -9,35 +9,18 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
MediaMetaInfoLoader::MediaMetaInfoLoader(RegistryMessageModel& rmm) : _rmm(rmm) { void MediaMetaInfoLoader::handleMessage(const Message3Handle& m) {
// HACK: make them be added externally? if (m.any_of<Message::Components::TagNotImage, Message::Components::FrameDims>()) {
_image_loaders.push_back(std::make_unique<ImageLoaderWebP>()); return;
_image_loaders.push_back(std::make_unique<ImageLoaderSDLBMP>());
_image_loaders.push_back(std::make_unique<ImageLoaderSTB>());
_rmm.subscribe(this, RegistryMessageModel_Event::message_construct);
_rmm.subscribe(this, RegistryMessageModel_Event::message_updated);
} }
MediaMetaInfoLoader::~MediaMetaInfoLoader(void) { if (!m.all_of<Message::Components::Transfer::FileInfoLocal, Message::Components::Transfer::TagHaveAll>()) {
return;
} }
bool MediaMetaInfoLoader::onEvent(const Message::Events::MessageConstruct& e) { const auto& fil = m.get<Message::Components::Transfer::FileInfoLocal>();
return false;
}
bool MediaMetaInfoLoader::onEvent(const Message::Events::MessageUpdated& e) {
if (e.e.any_of<Message::Components::TagNotImage, Message::Components::FrameDims>()) {
return false;
}
if (!e.e.all_of<Message::Components::Transfer::FileInfoLocal, Message::Components::Transfer::TagHaveAll>()) {
return false;
}
const auto& fil = e.e.get<Message::Components::Transfer::FileInfoLocal>();
if (fil.file_list.size() != 1) { if (fil.file_list.size() != 1) {
return false; return;
} }
std::ifstream file(fil.file_list.front(), std::ios::binary); std::ifstream file(fil.file_list.front(), std::ios::binary);
@ -60,25 +43,46 @@ bool MediaMetaInfoLoader::onEvent(const Message::Events::MessageUpdated& e) {
continue; continue;
} }
e.e.emplace<Message::Components::FrameDims>(res.width, res.height); m.emplace<Message::Components::FrameDims>(res.width, res.height);
could_load = true; could_load = true;
std::cout << "MMIL loaded image info " << fil.file_list.front() << "\n"; std::cout << "MMIL loaded image info " << fil.file_list.front() << "\n";
_rmm.throwEventUpdate(e.e); _rmm.throwEventUpdate(m);
break; break;
} }
if (!could_load) { if (!could_load) {
e.e.emplace<Message::Components::TagNotImage>(); m.emplace<Message::Components::TagNotImage>();
std::cout << "MMIL loading failed image info " << fil.file_list.front() << "\n"; std::cout << "MMIL loading failed image info " << fil.file_list.front() << "\n";
_rmm.throwEventUpdate(e.e); _rmm.throwEventUpdate(m);
}
} }
} }
MediaMetaInfoLoader::MediaMetaInfoLoader(RegistryMessageModel& rmm) : _rmm(rmm) {
// HACK: make them be added externally?
_image_loaders.push_back(std::make_unique<ImageLoaderWebP>());
_image_loaders.push_back(std::make_unique<ImageLoaderSDLBMP>());
_image_loaders.push_back(std::make_unique<ImageLoaderSTB>());
_rmm.subscribe(this, RegistryMessageModel_Event::message_construct);
_rmm.subscribe(this, RegistryMessageModel_Event::message_updated);
}
MediaMetaInfoLoader::~MediaMetaInfoLoader(void) {
}
bool MediaMetaInfoLoader::onEvent(const Message::Events::MessageConstruct& e) {
handleMessage(e.e);
return false;
}
bool MediaMetaInfoLoader::onEvent(const Message::Events::MessageUpdated& e) {
handleMessage(e.e);
return false; return false;
} }

View File

@ -22,6 +22,8 @@ class MediaMetaInfoLoader : public RegistryMessageModelEventI {
std::vector<std::unique_ptr<ImageLoaderI>> _image_loaders; std::vector<std::unique_ptr<ImageLoaderI>> _image_loaders;
void handleMessage(const Message3Handle& m);
public: public:
MediaMetaInfoLoader(RegistryMessageModel& rmm); MediaMetaInfoLoader(RegistryMessageModel& rmm);
virtual ~MediaMetaInfoLoader(void); virtual ~MediaMetaInfoLoader(void);