Green Sky
6d3ef742b5
Some checks failed
ContinuousDelivery / linux-ubuntu (push) Failing after 4m27s
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Failing after 5m39s
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Failing after 5m39s
ContinuousIntegration / linux (push) Successful in 3m34s
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Failing after 5m17s
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Failing after 5m16s
ContinuousDelivery / windows (push) Has been cancelled
ContinuousDelivery / windows-asan (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled
121 lines
3.2 KiB
C++
121 lines
3.2 KiB
C++
#include "./tox_ui_utils.hpp"
|
|
|
|
#include "./tox_client.hpp"
|
|
|
|
#include <tox/tox.h>
|
|
|
|
#include <solanaceae/util/utils.hpp>
|
|
|
|
#include <solanaceae/util/config_model.hpp>
|
|
|
|
#include <imgui/imgui.h>
|
|
#include <imgui/misc/cpp/imgui_stdlib.h>
|
|
|
|
ToxUIUtils::ToxUIUtils(
|
|
ToxClient& tc,
|
|
ConfigModelI& conf
|
|
) : _tc(tc), _conf(conf) {
|
|
}
|
|
|
|
void ToxUIUtils::render(void) {
|
|
{ // main window menubar injection
|
|
// assumes the window "tomato" was rendered already by cg
|
|
if (ImGui::Begin("tomato")) {
|
|
if (ImGui::BeginMenuBar()) {
|
|
ImGui::Separator();
|
|
if (ImGui::BeginMenu("Tox")) {
|
|
ImGui::SeparatorText("Friends/Groups");
|
|
|
|
if (ImGui::MenuItem("add Friend by ID")) {
|
|
_show_add_friend_window = true;
|
|
}
|
|
if (ImGui::MenuItem("copy own ToxID")) {
|
|
ImGui::SetClipboardText(_tc.toxSelfGetAddressStr().c_str());
|
|
}
|
|
if (ImGui::MenuItem("join Group by ID (ngc)")) {
|
|
_show_add_group_window = true;
|
|
}
|
|
|
|
ImGui::SeparatorText("DHT");
|
|
|
|
if (ImGui::MenuItem("rerun bootstrap")) {
|
|
_tc.runBootstrap();
|
|
}
|
|
|
|
ImGui::EndMenu();
|
|
}
|
|
ImGui::EndMenuBar();
|
|
}
|
|
|
|
}
|
|
ImGui::End();
|
|
}
|
|
|
|
if (_show_add_friend_window) {
|
|
if (ImGui::Begin("Tox add Friend", &_show_add_friend_window)) {
|
|
static char tox_id[TOX_ADDRESS_SIZE*2+1] = {};
|
|
ImGui::InputText("Tox ID", tox_id, TOX_ADDRESS_SIZE*2+1);
|
|
|
|
static std::string message = "Add me, I'm tomat";
|
|
ImGui::InputText("message", &message);
|
|
|
|
static Tox_Err_Friend_Add err = Tox_Err_Friend_Add::TOX_ERR_FRIEND_ADD_OK;
|
|
if (ImGui::Button("add")) {
|
|
// TODO: add string_view variant to utils
|
|
auto [_, err_r] = _tc.toxFriendAdd(hex2bin(std::string{tox_id}), message);
|
|
err = err_r;
|
|
}
|
|
if (err != Tox_Err_Friend_Add::TOX_ERR_FRIEND_ADD_OK) {
|
|
ImGui::SameLine();
|
|
ImGui::Text("error adding friend (code: %d)", err);
|
|
}
|
|
}
|
|
ImGui::End();
|
|
}
|
|
|
|
if (_show_add_group_window) {
|
|
if (ImGui::Begin("Tox join Group", &_show_add_group_window)) {
|
|
ImGui::TextDisabled("NGC refers to the New DHT enabled Group Chats.");
|
|
ImGui::TextDisabled("Connecting via ID might take a very long time.");
|
|
|
|
static char chat_id[TOX_GROUP_CHAT_ID_SIZE*2+1] = {};
|
|
ImGui::InputText("chat ID", chat_id, TOX_GROUP_CHAT_ID_SIZE*2+1);
|
|
|
|
static std::string self_name = _conf.get_string("tox", "name").value_or("default_tomato");
|
|
ImGui::InputText("name to join with", &self_name);
|
|
|
|
static std::string password;
|
|
ImGui::InputText("password to join with", &password);
|
|
|
|
static Tox_Err_Group_Join err = Tox_Err_Group_Join::TOX_ERR_GROUP_JOIN_OK;
|
|
if (ImGui::Button("join")) {
|
|
auto [_, err_r] = _tc.toxGroupJoin(
|
|
hex2bin(std::string{chat_id}), // TODO: add string_view variant to utils
|
|
self_name,
|
|
password
|
|
);
|
|
err = err_r;
|
|
|
|
{ // reset everything
|
|
for (size_t i = 0; i < sizeof(chat_id); i++) {
|
|
chat_id[i] = '\0';
|
|
}
|
|
|
|
self_name = _conf.get_string("tox", "name").value_or("default_tomato");
|
|
|
|
for (size_t i = 0; i < password.size(); i++) {
|
|
password.at(i) = '\0';
|
|
}
|
|
password.clear();
|
|
}
|
|
}
|
|
if (err != Tox_Err_Group_Join::TOX_ERR_GROUP_JOIN_OK) {
|
|
ImGui::SameLine();
|
|
ImGui::Text("error joining group (code: %d)", err);
|
|
}
|
|
}
|
|
ImGui::End();
|
|
}
|
|
}
|
|
|