diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a36b1f8..e23b3dfd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,6 +55,9 @@ add_executable(tomato ./settings_window.hpp ./settings_window.cpp + ./tox_ui_utils.hpp + ./tox_ui_utils.cpp + ./chat_gui4.hpp ./chat_gui4.cpp ) diff --git a/src/chat_gui4.cpp b/src/chat_gui4.cpp index ed47d173..f36a07b4 100644 --- a/src/chat_gui4.cpp +++ b/src/chat_gui4.cpp @@ -2,7 +2,6 @@ #include "./file_selector.hpp" -#include #include #include #include @@ -22,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/src/main_screen.cpp b/src/main_screen.cpp index b5f06aea..9b66b8a4 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -19,7 +19,8 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::stri tam(rmm, cr, conf), sdlrtu(renderer_), cg(conf, rmm, cr, sdlrtu), - sw(conf) + sw(conf), + tuiu(tc, conf) { tel.subscribeAll(tc); @@ -111,6 +112,7 @@ Screen* MainScreen::poll(bool& quit) { cg.render(); sw.render(); + tuiu.render(); if constexpr (false) { ImGui::ShowDemoWindow(); diff --git a/src/main_screen.hpp b/src/main_screen.hpp index 54ab7160..a4faef43 100644 --- a/src/main_screen.hpp +++ b/src/main_screen.hpp @@ -22,6 +22,7 @@ #include "./sdlrenderer_texture_uploader.hpp" #include "./chat_gui4.hpp" #include "./settings_window.hpp" +#include "./tox_ui_utils.hpp" #include #include @@ -59,6 +60,7 @@ struct MainScreen final : public Screen { ChatGui4 cg; SettingsWindow sw; + ToxUIUtils tuiu; MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector plugins); ~MainScreen(void); diff --git a/src/tox_client.cpp b/src/tox_client.cpp index 358db542..e015a1de 100644 --- a/src/tox_client.cpp +++ b/src/tox_client.cpp @@ -91,9 +91,16 @@ ToxClient::ToxClient(std::string_view save_path, std::string_view save_password) { // TODO: more/diff nodes // you can change or add your own bs and tcprelays here, ideally closer to you - {"tox.plastiras.org", 443, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14 - {"tox2.plastiras.org", 33445, "B6626D386BE7E3ACA107B46F48A5C4D522D29281750D44A0CBA6A2721E79C951", {}}, // DE tha14 + //{"tox.plastiras.org", 33445, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14 + {"104.244.74.69", 443, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14 + {"104.244.74.69", 33445, "8E8B63299B3D520FB377FE5100E65E3322F7AE5B20A0ACED2981769FC5B43725", {}}, // LU tha14 + + //{"tox2.plastiras.org", 33445, "B6626D386BE7E3ACA107B46F48A5C4D522D29281750D44A0CBA6A2721E79C951", {}}, // DE tha14 + + //{"tox4.plastiras.org", 33445, "836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409", {}}, // MD tha14 + {"37.221.66.161", 443, "836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409", {}}, // MD tha14 + {"37.221.66.161", 33445, "836D1DA2BE12FE0E669334E437BE3FB02806F1528C2B2782113E0910C7711409", {}}, // MD tha14 }; for (size_t i = 0; i < sizeof(nodes)/sizeof(DHT_node); i ++) { diff --git a/src/tox_ui_utils.cpp b/src/tox_ui_utils.cpp new file mode 100644 index 00000000..266c598d --- /dev/null +++ b/src/tox_ui_utils.cpp @@ -0,0 +1,105 @@ +#include "./tox_ui_utils.hpp" + +#include +#include + +#include + +#include +#include + +ToxUIUtils::ToxUIUtils( + ToxI& t, + ConfigModelI& conf +) : _t(t), _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")) { + if (ImGui::MenuItem("add Friend by ID")) { + _show_add_friend_window = true; + } + if (ImGui::MenuItem("join Group by ID (ngc)")) { + _show_add_group_window = true; + } + 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] = _t.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] = _t.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(); + } +} + diff --git a/src/tox_ui_utils.hpp b/src/tox_ui_utils.hpp new file mode 100644 index 00000000..3f0026bc --- /dev/null +++ b/src/tox_ui_utils.hpp @@ -0,0 +1,21 @@ +#pragma once + +struct ToxI; +struct ConfigModelI; + +class ToxUIUtils { + bool _show_add_friend_window {false}; + bool _show_add_group_window {false}; + + ToxI& _t; + ConfigModelI& _conf; + + public: + ToxUIUtils( + ToxI& t, + ConfigModelI& conf + ); + + void render(void); +}; +