From d5e2dd2e1f6eff946b8cdf0197c398f0443cd668 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sat, 29 Jul 2023 20:39:31 +0200 Subject: [PATCH] add auto dirty (save toxfile) + minor stuff --- src/CMakeLists.txt | 6 +++-- src/auto_dirty.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++ src/auto_dirty.hpp | 27 ++++++++++++++++++++ src/chat_gui4.cpp | 9 ++++--- src/main_screen.cpp | 1 + src/main_screen.hpp | 2 ++ 6 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 src/auto_dirty.cpp create mode 100644 src/auto_dirty.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6680096..ca8f522 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,8 +10,10 @@ add_executable(tomato main_screen.hpp main_screen.cpp - tox_client.hpp - tox_client.cpp + ./tox_client.hpp + ./tox_client.cpp + ./auto_dirty.hpp + ./auto_dirty.cpp theme.hpp texture_uploader.hpp diff --git a/src/auto_dirty.cpp b/src/auto_dirty.cpp new file mode 100644 index 0000000..614fafe --- /dev/null +++ b/src/auto_dirty.cpp @@ -0,0 +1,62 @@ +#include "./auto_dirty.hpp" + +#include "./tox_client.hpp" + +// TODO: add more events + +void AutoDirty::subscribe(void) { + _tc.subscribe(this, Tox_Event::TOX_EVENT_SELF_CONNECTION_STATUS); + _tc.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_CONNECTION_STATUS); + _tc.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_REQUEST); + _tc.subscribe(this, Tox_Event::TOX_EVENT_GROUP_INVITE); + _tc.subscribe(this, Tox_Event::TOX_EVENT_GROUP_SELF_JOIN); + _tc.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_JOIN); + _tc.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_EXIT); + _tc.subscribe(this, Tox_Event::TOX_EVENT_CONFERENCE_INVITE); +} + +AutoDirty::AutoDirty(ToxClient& tc) : _tc(tc) { + subscribe(); +} + +bool AutoDirty::onToxEvent(const Tox_Event_Self_Connection_Status*) { + _tc.setDirty(); + return false; +} + +bool AutoDirty::onToxEvent(const Tox_Event_Friend_Connection_Status*) { + _tc.setDirty(); + return false; +} + +bool AutoDirty::onToxEvent(const Tox_Event_Friend_Request*) { + _tc.setDirty(); + return false; +} + +bool AutoDirty::onToxEvent(const Tox_Event_Group_Invite*) { + _tc.setDirty(); + return false; +} + +bool AutoDirty::onToxEvent(const Tox_Event_Group_Self_Join*) { + _tc.setDirty(); + return false; +} + +bool AutoDirty::onToxEvent(const Tox_Event_Group_Peer_Join*) { + _tc.setDirty(); + return false; +} + +bool AutoDirty::onToxEvent(const Tox_Event_Group_Peer_Exit*) { + _tc.setDirty(); + return false; +} + +bool AutoDirty::onToxEvent(const Tox_Event_Conference_Invite*) { + _tc.setDirty(); + return false; +} + + diff --git a/src/auto_dirty.hpp b/src/auto_dirty.hpp new file mode 100644 index 0000000..27409c0 --- /dev/null +++ b/src/auto_dirty.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include + +// fwd +class ToxClient; + +// sets ToxClient dirty on some events +class AutoDirty : public ToxEventI { + ToxClient& _tc; + + void subscribe(void); // private + + public: + AutoDirty(ToxClient& tc); + + protected: // tox events + bool onToxEvent(const Tox_Event_Self_Connection_Status* e) override; + bool onToxEvent(const Tox_Event_Friend_Connection_Status* e) override; + bool onToxEvent(const Tox_Event_Friend_Request* e) override; + bool onToxEvent(const Tox_Event_Group_Invite* e) override; + bool onToxEvent(const Tox_Event_Group_Self_Join* e) override; + bool onToxEvent(const Tox_Event_Group_Peer_Join* e) override; + bool onToxEvent(const Tox_Event_Group_Peer_Exit* e) override; + bool onToxEvent(const Tox_Event_Conference_Invite* e) override; +}; + diff --git a/src/chat_gui4.cpp b/src/chat_gui4.cpp index 206e65a..b527efe 100644 --- a/src/chat_gui4.cpp +++ b/src/chat_gui4.cpp @@ -88,14 +88,16 @@ void ChatGui4::render(void) { if (ri.name) { ImGui::InputText("name to join with", &self_name); } else { - ImGui::TextUnformatted(""); + //ImGui::TextUnformatted(""); + ImGui::Dummy({0, TEXT_BASE_HEIGHT}); } static std::string password; if (ri.password) { ImGui::InputText("password to join with", &password); } else { - ImGui::TextUnformatted(""); + ////ImGui::TextUnformatted(""); + ImGui::Dummy({0, TEXT_BASE_HEIGHT}); } if (ImGui::Button("Accept")) { @@ -515,12 +517,11 @@ bool ChatGui4::renderContactListContactBig(const Contact3 c) { ImGui::SameLine(); ImGui::BeginGroup(); { + ImGui::Text("%s", (_cr.all_of(c) ? _cr.get(c).name.c_str() : "")); if (request_incoming) { ImGui::TextUnformatted("Incoming request/invite"); } else if (request_outgoing) { ImGui::TextUnformatted("Outgoing request/invite"); - } else { - ImGui::Text("%s", (_cr.all_of(c) ? _cr.get(c).name.c_str() : "")); } //ImGui::Text("status message..."); //ImGui::TextDisabled("hi"); diff --git a/src/main_screen.cpp b/src/main_screen.cpp index 44c7767..495d40e 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -10,6 +10,7 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path) : renderer(renderer_), rmm(cr), tc(save_path), + ad(tc), tcm(cr, tc, tc), tmm(rmm, cr, tcm, tc, tc), ttm(rmm, cr, tcm, tc, tc), diff --git a/src/main_screen.hpp b/src/main_screen.hpp index 2dfff16..47edc87 100644 --- a/src/main_screen.hpp +++ b/src/main_screen.hpp @@ -13,6 +13,7 @@ #include #include "./tox_client.hpp" +#include "./auto_dirty.hpp" #include "./sdlrenderer_texture_uploader.hpp" #include "./chat_gui4.hpp" @@ -39,6 +40,7 @@ struct MainScreen final : public Screen { ToxEventLogger tel{std::cout}; ToxClient tc; + AutoDirty ad; ToxContactModel2 tcm; ToxMessageManager tmm; ToxTransferManager ttm;