Compare commits
5 Commits
6df0417667
...
preview
Author | SHA1 | Date | |
---|---|---|---|
0b46b891c2 | |||
d131b5a02f | |||
9d9a486537 | |||
610ed10011 | |||
4edab11616 |
2
external/solanaceae_message3
vendored
2
external/solanaceae_message3
vendored
Submodule external/solanaceae_message3 updated: d2d6cfbf53...53d65a0685
2
external/solanaceae_tox
vendored
2
external/solanaceae_tox
vendored
Submodule external/solanaceae_tox updated: 70a234cdae...dd596bdad8
2
external/solanaceae_toxcore
vendored
2
external/solanaceae_toxcore
vendored
Submodule external/solanaceae_toxcore updated: b49db892f6...dfa5a501ec
4
external/toxcore/CMakeLists.txt
vendored
4
external/toxcore/CMakeLists.txt
vendored
@@ -134,6 +134,10 @@ add_library(toxcore STATIC
|
||||
${TOX_DIR}toxcore/tox_unpack.h
|
||||
${TOX_DIR}toxcore/util.c
|
||||
${TOX_DIR}toxcore/util.h
|
||||
|
||||
${TOX_DIR}toxencryptsave/defines.h
|
||||
${TOX_DIR}toxencryptsave/toxencryptsave.c
|
||||
${TOX_DIR}toxencryptsave/toxencryptsave.h
|
||||
)
|
||||
|
||||
# HACK: "install" api headers into self
|
||||
|
@@ -72,8 +72,6 @@ void ChatGui4::render(void) {
|
||||
if (_selected_contact) {
|
||||
const std::string chat_label = "chat " + std::to_string(entt::to_integral(*_selected_contact));
|
||||
if (ImGui::BeginChild(chat_label.c_str(), {0, 0}, true)) {
|
||||
static std::string text_buffer;
|
||||
|
||||
if (_cr.all_of<Contact::Components::ParentOf>(*_selected_contact)) {
|
||||
const auto sub_contacts = _cr.get<Contact::Components::ParentOf>(*_selected_contact).subs;
|
||||
if (!sub_contacts.empty()) {
|
||||
@@ -83,7 +81,7 @@ void ChatGui4::render(void) {
|
||||
for (const auto& c : sub_contacts) {
|
||||
// TODO: can a sub be selected? no
|
||||
if (renderSubContactListContact(c, _selected_contact.has_value() && *_selected_contact == c)) {
|
||||
text_buffer.insert(0, (_cr.all_of<Contact::Components::Name>(c) ? _cr.get<Contact::Components::Name>(c).name : "<unk>") + ": ");
|
||||
_text_input_buffer.insert(0, (_cr.all_of<Contact::Components::Name>(c) ? _cr.get<Contact::Components::Name>(c).name : "<unk>") + ": ");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -257,10 +255,10 @@ void ChatGui4::render(void) {
|
||||
ImGuiInputTextFlags_NoHorizontalScroll |
|
||||
ImGuiInputTextFlags_CtrlEnterForNewLine;
|
||||
|
||||
if (ImGui::InputTextMultiline("##text_input", &text_buffer, {-0.001f, -0.001f}, input_flags)) {
|
||||
if (ImGui::InputTextMultiline("##text_input", &_text_input_buffer, {-0.001f, -0.001f}, input_flags)) {
|
||||
//_mm.sendMessage(*_selected_contact, MessageType::TEXT, text_buffer);
|
||||
_rmm.sendText(*_selected_contact, text_buffer);
|
||||
text_buffer.clear();
|
||||
_rmm.sendText(*_selected_contact, _text_input_buffer);
|
||||
_text_input_buffer.clear();
|
||||
evil_enter_looses_focus_hack = true;
|
||||
}
|
||||
}
|
||||
@@ -315,12 +313,31 @@ void ChatGui4::renderMessageBodyText(Message3Registry& reg, const Message3 e) {
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBg, {0.f, 0.f, 0.f, 0.f}); // remove text input box
|
||||
|
||||
ImGui::InputTextMultiline(
|
||||
"",
|
||||
"##text",
|
||||
const_cast<char*>(msgtext.c_str()), // ugly const cast
|
||||
msgtext.size() + 1, // needs to include '\0'
|
||||
text_size,
|
||||
ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_NoHorizontalScroll
|
||||
);
|
||||
if (ImGui::BeginPopupContextItem("##text")) {
|
||||
if (ImGui::MenuItem("quote")) {
|
||||
//text_buffer.insert(0, (_cr.all_of<Contact::Components::Name>(c) ? _cr.get<Contact::Components::Name>(c).name : "<unk>") + ": ");
|
||||
if (!_text_input_buffer.empty()) {
|
||||
_text_input_buffer += "\n";
|
||||
}
|
||||
|
||||
_text_input_buffer += "> ";
|
||||
|
||||
for (const char c : msgtext) {
|
||||
_text_input_buffer += c;
|
||||
|
||||
if (c == '\n') {
|
||||
_text_input_buffer += "> ";
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopStyleVar();
|
||||
@@ -386,6 +403,7 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
|
||||
[](const auto& path) -> bool { return std::filesystem::is_directory(path); },
|
||||
[this, ®, e](const auto& path) {
|
||||
if (reg.valid(e)) { // still valid
|
||||
// TODO: trim file?
|
||||
reg.emplace<Message::Components::Transfer::ActionAccept>(e, path.string());
|
||||
_rmm.throwEventUpdate(reg, e);
|
||||
}
|
||||
|
@@ -26,6 +26,9 @@ class ChatGui4 {
|
||||
|
||||
std::optional<Contact3> _selected_contact;
|
||||
|
||||
// TODO: per contact
|
||||
std::string _text_input_buffer;
|
||||
|
||||
bool _show_chat_extra_info {true};
|
||||
|
||||
float TEXT_BASE_WIDTH {1};
|
||||
|
27
src/main.cpp
27
src/main.cpp
@@ -12,9 +12,19 @@
|
||||
#include <memory>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
|
||||
// setup hints
|
||||
if (SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1") != SDL_TRUE) {
|
||||
std::cerr << "Failed to set '" << SDL_HINT_VIDEO_ALLOW_SCREENSAVER << "' to 1\n";
|
||||
}
|
||||
|
||||
auto last_time = std::chrono::steady_clock::now();
|
||||
|
||||
// actual setup
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
std::cerr << "SDL_Init failed (" << SDL_GetError() << ")\n";
|
||||
return 1;
|
||||
}
|
||||
@@ -54,8 +64,13 @@ int main(int argc, char** argv) {
|
||||
|
||||
std::unique_ptr<Screen> screen = std::make_unique<StartScreen>(renderer.get());
|
||||
|
||||
|
||||
bool quit = false;
|
||||
while (!quit) {
|
||||
auto new_time = std::chrono::steady_clock::now();
|
||||
//const float time_delta {std::chrono::duration<float, std::chrono::seconds::period>(new_time - last_time).count()};
|
||||
last_time = new_time;
|
||||
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_EVENT_QUIT) {
|
||||
@@ -73,6 +88,11 @@ int main(int argc, char** argv) {
|
||||
break;
|
||||
}
|
||||
|
||||
//float fps_target = 60.f;
|
||||
//if (SDL_GetWindowFlags(window.get()) & (SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED)) {
|
||||
//fps_target = 30.f;
|
||||
//}
|
||||
|
||||
ImGui_ImplSDLRenderer3_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
@@ -91,6 +111,11 @@ int main(int argc, char** argv) {
|
||||
// clearing after present is (should) more performant, but first frame is a mess
|
||||
SDL_SetRenderDrawColor(renderer.get(), 0x10, 0x10, 0x10, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(renderer.get());
|
||||
|
||||
std::this_thread::sleep_for( // time left to get to 60fps
|
||||
std::chrono::duration<float, std::chrono::seconds::period>(0.0166f) // 60fps frame duration
|
||||
- std::chrono::duration<float, std::chrono::seconds::period>(std::chrono::steady_clock::now() - new_time) // time used for rendering
|
||||
);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@@ -6,11 +6,11 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::vector<std::string> plugins) :
|
||||
MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins) :
|
||||
renderer(renderer_),
|
||||
rmm(cr),
|
||||
mts(rmm),
|
||||
tc(save_path),
|
||||
tc(save_path, save_password),
|
||||
ad(tc),
|
||||
tcm(cr, tc, tc),
|
||||
tmm(rmm, cr, tcm, tc, tc),
|
||||
@@ -76,13 +76,15 @@ Screen* MainScreen::poll(bool& quit) {
|
||||
|
||||
quit = !tc.iterate();
|
||||
|
||||
tcm.iterate(time_delta);
|
||||
|
||||
pm.tick(time_delta);
|
||||
|
||||
mts.iterate();
|
||||
|
||||
cg.render();
|
||||
|
||||
{
|
||||
if constexpr (false) {
|
||||
bool open = !quit;
|
||||
ImGui::ShowDemoWindow(&open);
|
||||
quit = !open;
|
||||
|
@@ -56,7 +56,7 @@ struct MainScreen final : public Screen {
|
||||
|
||||
ChatGui4 cg;
|
||||
|
||||
MainScreen(SDL_Renderer* renderer_, std::string save_path, std::vector<std::string> plugins);
|
||||
MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector<std::string> plugins);
|
||||
~MainScreen(void);
|
||||
|
||||
bool handleEvent(SDL_Event& e) override;
|
||||
|
@@ -25,6 +25,15 @@ void MediaMetaInfoLoader::handleMessage(const Message3Handle& m) {
|
||||
|
||||
std::ifstream file(fil.file_list.front(), std::ios::binary);
|
||||
if (file.is_open()) {
|
||||
// figure out size
|
||||
file.seekg(0, file.end);
|
||||
if (file.tellg() > 50*1024*1024) {
|
||||
// TODO: conf
|
||||
// dont try load files larger 50mb
|
||||
return;
|
||||
}
|
||||
file.seekg(0, file.beg);
|
||||
|
||||
std::vector<uint8_t> tmp_buffer;
|
||||
while (file.good()) {
|
||||
auto ch = file.get();
|
||||
@@ -38,6 +47,7 @@ void MediaMetaInfoLoader::handleMessage(const Message3Handle& m) {
|
||||
bool could_load {false};
|
||||
// try all loaders after another
|
||||
for (auto& il : _image_loaders) {
|
||||
// TODO: impl callback based load
|
||||
auto res = il->loadInfoFromMemory(tmp_buffer.data(), tmp_buffer.size());
|
||||
if (res.height == 0 || res.width == 0) {
|
||||
continue;
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "./main_screen.hpp"
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/misc/cpp/imgui_stdlib.h>
|
||||
|
||||
#include <memory>
|
||||
#include <filesystem>
|
||||
@@ -24,6 +25,10 @@ Screen* StartScreen::poll(bool&) {
|
||||
|
||||
if (ImGui::BeginTabBar("view")) {
|
||||
if (ImGui::BeginTabItem("load profile")) {
|
||||
_new_save = false;
|
||||
|
||||
ImGui::TextUnformatted("profile :");
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("select")) {
|
||||
_fss.requestFile(
|
||||
[](const auto& path) -> bool { return std::filesystem::is_regular_file(path); },
|
||||
@@ -34,29 +39,52 @@ Screen* StartScreen::poll(bool&) {
|
||||
);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("profile: %s", tox_profile_path.c_str());
|
||||
ImGui::TextUnformatted(tox_profile_path.c_str());
|
||||
|
||||
ImGui::Text("TODO: profile password");
|
||||
ImGui::TextUnformatted("password:");
|
||||
ImGui::SameLine();
|
||||
if (_show_password) {
|
||||
ImGui::InputText("##password", &_password);
|
||||
} else {
|
||||
ImGui::InputText("##password", &_password, ImGuiInputTextFlags_Password);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("show password", &_show_password);
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("create profile")) {
|
||||
ImGui::Text("TODO: profile path");
|
||||
ImGui::Text("TODO: profile name");
|
||||
ImGui::Text("TODO: profile password");
|
||||
_new_save = true;
|
||||
|
||||
ImGui::TextUnformatted("TODO: profile path");
|
||||
ImGui::TextUnformatted("TODO: profile name");
|
||||
|
||||
ImGui::TextUnformatted("password:");
|
||||
ImGui::SameLine();
|
||||
if (_show_password) {
|
||||
ImGui::InputText("##password", &_password);
|
||||
} else {
|
||||
ImGui::InputText("##password", &_password, ImGuiInputTextFlags_Password);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("show password", &_show_password);
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("plugins")) {
|
||||
// list of selected plugins (in order)
|
||||
for (auto it = queued_plugin_paths.begin(); it != queued_plugin_paths.end();) {
|
||||
ImGui::PushID(it->c_str());
|
||||
if (ImGui::SmallButton("-")) {
|
||||
it = queued_plugin_paths.erase(it);
|
||||
ImGui::PopID();
|
||||
continue;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::TextUnformatted(it->c_str());
|
||||
|
||||
ImGui::PopID();
|
||||
it++;
|
||||
}
|
||||
|
||||
@@ -77,9 +105,31 @@ Screen* StartScreen::poll(bool&) {
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::Button("load", {60, 25})) {
|
||||
auto new_screen = std::make_unique<MainScreen>(_renderer, tox_profile_path, queued_plugin_paths);
|
||||
return new_screen.release();
|
||||
if (!_new_save && !std::filesystem::is_regular_file(tox_profile_path)) {
|
||||
// load but file missing
|
||||
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button("load", {60, 25});
|
||||
ImGui::EndDisabled();
|
||||
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip | ImGuiHoveredFlags_AllowWhenDisabled)) {
|
||||
ImGui::SetTooltip("file does not exist");
|
||||
}
|
||||
} else if (_new_save && std::filesystem::exists(tox_profile_path)) {
|
||||
// new but file exists
|
||||
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button("load", {60, 25});
|
||||
ImGui::EndDisabled();
|
||||
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip | ImGuiHoveredFlags_AllowWhenDisabled)) {
|
||||
ImGui::SetTooltip("file already exists");
|
||||
}
|
||||
} else {
|
||||
if (ImGui::Button("load", {60, 25})) {
|
||||
auto new_screen = std::make_unique<MainScreen>(_renderer, tox_profile_path, _password, queued_plugin_paths);
|
||||
return new_screen.release();
|
||||
}
|
||||
}
|
||||
|
||||
_fss.render();
|
||||
|
@@ -16,6 +16,11 @@ struct StartScreen final : public Screen {
|
||||
SDL_Renderer* _renderer;
|
||||
FileSelector _fss;
|
||||
|
||||
bool _new_save {false};
|
||||
|
||||
bool _show_password {false};
|
||||
std::string _password;
|
||||
|
||||
std::string tox_profile_path {"tomato.tox"};
|
||||
std::vector<std::string> queued_plugin_paths;
|
||||
|
||||
|
@@ -1,5 +1,10 @@
|
||||
#include "./tox_client.hpp"
|
||||
|
||||
// meh, change this
|
||||
#include <exception>
|
||||
#include <system_error>
|
||||
#include <toxencryptsave/toxencryptsave.h>
|
||||
|
||||
#include <sodium.h>
|
||||
|
||||
#include <vector>
|
||||
@@ -7,8 +12,8 @@
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
ToxClient::ToxClient(std::string_view save_path) :
|
||||
_tox_profile_path(save_path)
|
||||
ToxClient::ToxClient(std::string_view save_path, std::string_view save_password) :
|
||||
_tox_profile_path(save_path), _tox_profile_password(save_password)
|
||||
{
|
||||
TOX_ERR_OPTIONS_NEW err_opt_new;
|
||||
Tox_Options* options = tox_options_new(&err_opt_new);
|
||||
@@ -34,6 +39,19 @@ ToxClient::ToxClient(std::string_view save_path) :
|
||||
std::cerr << "empty tox save\n";
|
||||
} else {
|
||||
// set options
|
||||
if (!save_password.empty()) {
|
||||
std::vector<uint8_t> encrypted_copy(profile_data.begin(), profile_data.end());
|
||||
//profile_data.clear();
|
||||
profile_data.resize(encrypted_copy.size() - TOX_PASS_ENCRYPTION_EXTRA_LENGTH);
|
||||
if (!tox_pass_decrypt(
|
||||
encrypted_copy.data(), encrypted_copy.size(),
|
||||
reinterpret_cast<const uint8_t*>(save_password.data()), save_password.size(),
|
||||
profile_data.data(),
|
||||
nullptr // TODO: error checking
|
||||
)) {
|
||||
throw std::runtime_error("FAILED to decrypt save file!!!!");
|
||||
}
|
||||
}
|
||||
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
|
||||
tox_options_set_savedata_data(options, profile_data.data(), profile_data.size());
|
||||
}
|
||||
@@ -122,6 +140,19 @@ void ToxClient::saveToxProfile(void) {
|
||||
data.resize(tox_get_savedata_size(_tox));
|
||||
tox_get_savedata(_tox, data.data());
|
||||
|
||||
if (!_tox_profile_password.empty()) {
|
||||
std::vector<uint8_t> unencrypted_copy(data.begin(), data.end());
|
||||
//profile_data.clear();
|
||||
data.resize(unencrypted_copy.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH);
|
||||
if (!tox_pass_encrypt(
|
||||
unencrypted_copy.data(), unencrypted_copy.size(),
|
||||
reinterpret_cast<const uint8_t*>(_tox_profile_password.data()), _tox_profile_password.size(),
|
||||
data.data(),
|
||||
nullptr // TODO: error checking
|
||||
)) {
|
||||
throw std::runtime_error("FAILED to encrypt save file!!!!");
|
||||
}
|
||||
}
|
||||
std::ofstream ofile{_tox_profile_path, std::ios::binary};
|
||||
// TODO: improve
|
||||
for (const auto& ch : data) {
|
||||
|
@@ -20,11 +20,12 @@ class ToxClient : public ToxDefaultImpl, public ToxEventProviderBase {
|
||||
std::string _self_name;
|
||||
|
||||
std::string _tox_profile_path;
|
||||
std::string _tox_profile_password;
|
||||
bool _tox_profile_dirty {true}; // set in callbacks
|
||||
|
||||
public:
|
||||
//ToxClient(/*const CommandLine& cl*/);
|
||||
ToxClient(std::string_view save_path);
|
||||
ToxClient(std::string_view save_path, std::string_view save_password);
|
||||
~ToxClient(void);
|
||||
|
||||
public: // tox stuff
|
||||
|
Reference in New Issue
Block a user