2023-06-20 04:33:09 +00:00
|
|
|
#include "StarJoinRequestDialog.hpp"
|
|
|
|
#include "StarGuiReader.hpp"
|
|
|
|
#include "StarRoot.hpp"
|
|
|
|
#include "StarLabelWidget.hpp"
|
|
|
|
#include "StarButtonWidget.hpp"
|
|
|
|
#include "StarImageWidget.hpp"
|
|
|
|
#include "StarRandom.hpp"
|
|
|
|
#include "StarAssets.hpp"
|
|
|
|
|
|
|
|
namespace Star {
|
|
|
|
|
2023-07-29 14:41:38 +00:00
|
|
|
JoinRequestDialog::JoinRequestDialog() : m_confirmed(false) {}
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
void JoinRequestDialog::displayRequest(String const& userName, function<void(P2PJoinRequestReply)> callback) {
|
|
|
|
auto assets = Root::singleton().assets();
|
|
|
|
|
|
|
|
removeAllChildren();
|
|
|
|
|
|
|
|
GuiReader reader;
|
|
|
|
|
2024-02-19 15:55:19 +00:00
|
|
|
m_callback = std::move(callback);
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
reader.registerCallback("yes", [this](Widget*){ reply(P2PJoinRequestReply::Yes); });
|
|
|
|
reader.registerCallback("no", [this](Widget*){ reply(P2PJoinRequestReply::No); });
|
|
|
|
reader.registerCallback("ignore", [this](Widget*){ reply(P2PJoinRequestReply::Ignore); });
|
|
|
|
|
|
|
|
m_confirmed = false;
|
|
|
|
|
|
|
|
Json config = assets->json("/interface/windowconfig/joinrequest.config");
|
|
|
|
|
|
|
|
reader.construct(config.get("paneLayout"), this);
|
|
|
|
|
|
|
|
String message = config.getString("joinMessage").replaceTags(StringMap<String>{{"username", userName}});
|
|
|
|
fetchChild<LabelWidget>("message")->setText(message);
|
|
|
|
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void JoinRequestDialog::reply(P2PJoinRequestReply reply) {
|
|
|
|
m_confirmed = true;
|
|
|
|
m_callback(reply);
|
|
|
|
dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
void JoinRequestDialog::dismissed() {
|
|
|
|
if (!m_confirmed)
|
|
|
|
m_callback(P2PJoinRequestReply::No);
|
|
|
|
|
|
|
|
Pane::dismissed();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|