add auto dirty (save toxfile) + minor stuff

This commit is contained in:
Green Sky 2023-07-29 20:39:31 +02:00
parent 93e5bb867b
commit d5e2dd2e1f
No known key found for this signature in database
6 changed files with 101 additions and 6 deletions

View File

@ -10,8 +10,10 @@ add_executable(tomato
main_screen.hpp main_screen.hpp
main_screen.cpp main_screen.cpp
tox_client.hpp ./tox_client.hpp
tox_client.cpp ./tox_client.cpp
./auto_dirty.hpp
./auto_dirty.cpp
theme.hpp theme.hpp
texture_uploader.hpp texture_uploader.hpp

62
src/auto_dirty.cpp Normal file
View File

@ -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;
}

27
src/auto_dirty.hpp Normal file
View File

@ -0,0 +1,27 @@
#pragma once
#include <solanaceae/toxcore/tox_event_interface.hpp>
// 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;
};

View File

@ -88,14 +88,16 @@ void ChatGui4::render(void) {
if (ri.name) { if (ri.name) {
ImGui::InputText("name to join with", &self_name); ImGui::InputText("name to join with", &self_name);
} else { } else {
ImGui::TextUnformatted(""); //ImGui::TextUnformatted("");
ImGui::Dummy({0, TEXT_BASE_HEIGHT});
} }
static std::string password; static std::string password;
if (ri.password) { if (ri.password) {
ImGui::InputText("password to join with", &password); ImGui::InputText("password to join with", &password);
} else { } else {
ImGui::TextUnformatted(""); ////ImGui::TextUnformatted("");
ImGui::Dummy({0, TEXT_BASE_HEIGHT});
} }
if (ImGui::Button("Accept")) { if (ImGui::Button("Accept")) {
@ -515,12 +517,11 @@ bool ChatGui4::renderContactListContactBig(const Contact3 c) {
ImGui::SameLine(); ImGui::SameLine();
ImGui::BeginGroup(); ImGui::BeginGroup();
{ {
ImGui::Text("%s", (_cr.all_of<Contact::Components::Name>(c) ? _cr.get<Contact::Components::Name>(c).name.c_str() : "<unk>"));
if (request_incoming) { if (request_incoming) {
ImGui::TextUnformatted("Incoming request/invite"); ImGui::TextUnformatted("Incoming request/invite");
} else if (request_outgoing) { } else if (request_outgoing) {
ImGui::TextUnformatted("Outgoing request/invite"); ImGui::TextUnformatted("Outgoing request/invite");
} else {
ImGui::Text("%s", (_cr.all_of<Contact::Components::Name>(c) ? _cr.get<Contact::Components::Name>(c).name.c_str() : "<unk>"));
} }
//ImGui::Text("status message..."); //ImGui::Text("status message...");
//ImGui::TextDisabled("hi"); //ImGui::TextDisabled("hi");

View File

@ -10,6 +10,7 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path) :
renderer(renderer_), renderer(renderer_),
rmm(cr), rmm(cr),
tc(save_path), tc(save_path),
ad(tc),
tcm(cr, tc, tc), tcm(cr, tc, tc),
tmm(rmm, cr, tcm, tc, tc), tmm(rmm, cr, tcm, tc, tc),
ttm(rmm, cr, tcm, tc, tc), ttm(rmm, cr, tcm, tc, tc),

View File

@ -13,6 +13,7 @@
#include <solanaceae/tox_messages/tox_transfer_manager.hpp> #include <solanaceae/tox_messages/tox_transfer_manager.hpp>
#include "./tox_client.hpp" #include "./tox_client.hpp"
#include "./auto_dirty.hpp"
#include "./sdlrenderer_texture_uploader.hpp" #include "./sdlrenderer_texture_uploader.hpp"
#include "./chat_gui4.hpp" #include "./chat_gui4.hpp"
@ -39,6 +40,7 @@ struct MainScreen final : public Screen {
ToxEventLogger tel{std::cout}; ToxEventLogger tel{std::cout};
ToxClient tc; ToxClient tc;
AutoDirty ad;
ToxContactModel2 tcm; ToxContactModel2 tcm;
ToxMessageManager tmm; ToxMessageManager tmm;
ToxTransferManager ttm; ToxTransferManager ttm;