Compare commits
7 Commits
4cd295065b
...
v0.1
Author | SHA1 | Date | |
---|---|---|---|
3aaa1b0350 | |||
823a4ae189 | |||
40cd04f9dd | |||
6a979d31a0 | |||
56f7db9ae6 | |||
d5e2dd2e1f | |||
93e5bb867b |
2
external/solanaceae_contact
vendored
2
external/solanaceae_contact
vendored
Submodule external/solanaceae_contact updated: 5397fcc5c2...65d253afea
2
external/solanaceae_tox
vendored
2
external/solanaceae_tox
vendored
Submodule external/solanaceae_tox updated: b68ef51d64...a262ab9d3a
@ -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
|
||||
|
62
src/auto_dirty.cpp
Normal file
62
src/auto_dirty.cpp
Normal 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
27
src/auto_dirty.hpp
Normal 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;
|
||||
};
|
||||
|
@ -19,10 +19,11 @@
|
||||
#include <ctime>
|
||||
|
||||
ChatGui4::ChatGui4(
|
||||
ConfigModelI& conf,
|
||||
RegistryMessageModel& rmm,
|
||||
Contact3Registry& cr,
|
||||
TextureUploaderI& tu
|
||||
) : _rmm(rmm), _cr(cr) {
|
||||
) : _conf(conf), _rmm(rmm), _cr(cr) {
|
||||
}
|
||||
|
||||
void ChatGui4::render(void) {
|
||||
@ -73,6 +74,47 @@ void ChatGui4::render(void) {
|
||||
}
|
||||
}
|
||||
|
||||
const bool request_incoming = _cr.all_of<Contact::Components::RequestIncoming>(*_selected_contact);
|
||||
const bool request_outgoing = _cr.all_of<Contact::Components::TagRequestOutgoing>(*_selected_contact);
|
||||
if (request_incoming || request_outgoing) {
|
||||
// TODO: theming
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, {0.90f, 0.70f, 0.00f, 0.32f});
|
||||
if (ImGui::BeginChild("request", {0, TEXT_BASE_HEIGHT*6.1f}, true, ImGuiWindowFlags_NoScrollbar)) {
|
||||
if (request_incoming) {
|
||||
const auto& ri = _cr.get<Contact::Components::RequestIncoming>(*_selected_contact);
|
||||
ImGui::TextUnformatted("You got a request to add this contact.");
|
||||
|
||||
static std::string self_name = _conf.get_string("tox", "name").value_or("default_tomato");
|
||||
if (ri.name) {
|
||||
ImGui::InputText("name to join with", &self_name);
|
||||
} else {
|
||||
//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::Dummy({0, TEXT_BASE_HEIGHT});
|
||||
}
|
||||
|
||||
if (ImGui::Button("Accept")) {
|
||||
_cr.get<Contact::Components::ContactModel>(*_selected_contact)->acceptRequest(*_selected_contact, self_name, password);
|
||||
password.clear();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Decline")) {
|
||||
}
|
||||
} else {
|
||||
ImGui::TextUnformatted("You sent a reqeust to add this contact.");
|
||||
}
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
if (ImGui::BeginChild("message_log", {0, -100}, false, ImGuiWindowFlags_MenuBar)) {
|
||||
if (ImGui::BeginMenuBar()) {
|
||||
ImGui::Checkbox("show extra info", &_show_chat_extra_info);
|
||||
@ -207,7 +249,7 @@ void ChatGui4::render(void) {
|
||||
_fss.requestFile(
|
||||
[](const auto& path) -> bool { return std::filesystem::is_regular_file(path); },
|
||||
[this](const auto& path){
|
||||
_rmm.sendFilePath(*_selected_contact, path.filename().c_str(), path.c_str());
|
||||
_rmm.sendFilePath(*_selected_contact, path.filename().u8string(), path.u8string());
|
||||
},
|
||||
[](){}
|
||||
);
|
||||
@ -230,6 +272,7 @@ void ChatGui4::render(void) {
|
||||
void ChatGui4::renderMessageBodyText(Message3Registry& reg, const Message3 e) {
|
||||
const auto& msgtext = reg.get<Message::Components::MessageText>(e).text;
|
||||
|
||||
// TODO: set word wrap
|
||||
ImVec2 text_size = ImGui::CalcTextSize(msgtext.c_str(), msgtext.c_str()+msgtext.size());
|
||||
text_size.x = -FLT_MIN; // fill width (suppresses label)
|
||||
text_size.y += ImGui::GetStyle().FramePadding.y; // single pad
|
||||
@ -411,8 +454,25 @@ bool ChatGui4::renderContactListContactBig(const Contact3 c) {
|
||||
|
||||
auto label = "###" + std::to_string(entt::to_integral(c));
|
||||
|
||||
const bool request_incoming = _cr.all_of<Contact::Components::RequestIncoming>(c);
|
||||
const bool request_outgoing = _cr.all_of<Contact::Components::TagRequestOutgoing>(c);
|
||||
|
||||
ImVec2 orig_curser_pos = ImGui::GetCursorPos();
|
||||
bool selected = ImGui::Selectable(label.c_str(), _selected_contact.has_value() && *_selected_contact == c, 0, {0,3*TEXT_BASE_HEIGHT});
|
||||
// HACK: fake selected to make it draw a box for us
|
||||
const bool show_selected = request_incoming || request_outgoing || (_selected_contact.has_value() && *_selected_contact == c);
|
||||
if (request_incoming) {
|
||||
// TODO: theming
|
||||
ImGui::PushStyleColor(ImGuiCol_Header, {0.98f, 0.41f, 0.26f, 0.52f});
|
||||
} else if (request_outgoing) {
|
||||
// TODO: theming
|
||||
ImGui::PushStyleColor(ImGuiCol_Header, {0.98f, 0.26f, 0.41f, 0.52f});
|
||||
}
|
||||
|
||||
const bool selected = ImGui::Selectable(label.c_str(), show_selected, 0, {0,3*TEXT_BASE_HEIGHT});
|
||||
|
||||
if (request_incoming || request_outgoing) {
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
ImVec2 post_curser_pos = ImGui::GetCursorPos();
|
||||
|
||||
ImVec2 img_curser {
|
||||
@ -459,6 +519,11 @@ bool ChatGui4::renderContactListContactBig(const Contact3 c) {
|
||||
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) {
|
||||
ImGui::TextUnformatted("Incoming request/invite");
|
||||
} else if (request_outgoing) {
|
||||
ImGui::TextUnformatted("Outgoing request/invite");
|
||||
}
|
||||
//ImGui::Text("status message...");
|
||||
//ImGui::TextDisabled("hi");
|
||||
//ImGui::RenderTextEllipsis
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
#include <solanaceae/util/config_model.hpp>
|
||||
|
||||
#include "./texture_uploader.hpp"
|
||||
#include "./file_selector.hpp"
|
||||
@ -9,6 +10,7 @@
|
||||
#include <set>
|
||||
|
||||
class ChatGui4 {
|
||||
ConfigModelI& _conf;
|
||||
RegistryMessageModel& _rmm;
|
||||
Contact3Registry& _cr;
|
||||
|
||||
@ -23,6 +25,7 @@ class ChatGui4 {
|
||||
|
||||
public:
|
||||
ChatGui4(
|
||||
ConfigModelI& conf,
|
||||
RegistryMessageModel& rmm,
|
||||
Contact3Registry& cr,
|
||||
TextureUploaderI& tu
|
||||
|
@ -1,10 +1,11 @@
|
||||
#include "./file_selector.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
void FileSelector::reset(void) {
|
||||
_is_valid = [](auto){ return true; };
|
||||
@ -46,7 +47,7 @@ void FileSelector::render(void) {
|
||||
std::filesystem::path current_path = _current_file_path;
|
||||
current_path.remove_filename();
|
||||
|
||||
ImGui::Text("path: %s", _current_file_path.c_str());
|
||||
ImGui::Text("path: %s", _current_file_path.u8string().c_str());
|
||||
|
||||
// begin table with selectables
|
||||
constexpr ImGuiTableFlags table_flags =
|
||||
@ -174,7 +175,7 @@ void FileSelector::render(void) {
|
||||
}
|
||||
|
||||
if (ImGui::TableNextColumn()) {
|
||||
ImGui::TextUnformatted((dir_entry.path().filename().string() + "/").c_str());
|
||||
ImGui::TextUnformatted((dir_entry.path().filename().u8string() + "/").c_str());
|
||||
}
|
||||
|
||||
if (ImGui::TableNextColumn()) {
|
||||
@ -182,7 +183,13 @@ void FileSelector::render(void) {
|
||||
}
|
||||
|
||||
if (ImGui::TableNextColumn()) {
|
||||
const auto ctime = std::chrono::system_clock::to_time_t(dir_entry.last_write_time() - decltype(dir_entry.last_write_time())::clock::now() + std::chrono::system_clock::now());
|
||||
const auto file_time_converted = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
|
||||
dir_entry.last_write_time()
|
||||
- decltype(dir_entry.last_write_time())::clock::now()
|
||||
+ std::chrono::system_clock::now()
|
||||
);
|
||||
const auto ctime = std::chrono::system_clock::to_time_t(file_time_converted);
|
||||
|
||||
const auto ltime = std::localtime(&ctime);
|
||||
ImGui::TextDisabled("%2d.%2d.%2d - %2d:%2d", ltime->tm_mday, ltime->tm_mon, ltime->tm_year + 1900, ltime->tm_hour, ltime->tm_min);
|
||||
}
|
||||
@ -199,7 +206,7 @@ void FileSelector::render(void) {
|
||||
}
|
||||
|
||||
if (ImGui::TableNextColumn()) {
|
||||
ImGui::TextUnformatted(dir_entry.path().filename().c_str());
|
||||
ImGui::TextUnformatted(dir_entry.path().filename().u8string().c_str());
|
||||
}
|
||||
|
||||
if (ImGui::TableNextColumn()) {
|
||||
@ -207,7 +214,13 @@ void FileSelector::render(void) {
|
||||
}
|
||||
|
||||
if (ImGui::TableNextColumn()) {
|
||||
const auto ctime = std::chrono::system_clock::to_time_t(dir_entry.last_write_time() - decltype(dir_entry.last_write_time())::clock::now() + std::chrono::system_clock::now());
|
||||
const auto file_time_converted = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
|
||||
dir_entry.last_write_time()
|
||||
- decltype(dir_entry.last_write_time())::clock::now()
|
||||
+ std::chrono::system_clock::now()
|
||||
);
|
||||
const auto ctime = std::chrono::system_clock::to_time_t(file_time_converted);
|
||||
|
||||
const auto ltime = std::localtime(&ctime);
|
||||
ImGui::TextDisabled("%2d.%2d.%2d - %2d:%2d", ltime->tm_mday, ltime->tm_mon, ltime->tm_year + 1900, ltime->tm_hour, ltime->tm_min);
|
||||
}
|
||||
|
@ -9,12 +9,14 @@
|
||||
MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path) :
|
||||
renderer(renderer_),
|
||||
rmm(cr),
|
||||
mts(rmm),
|
||||
tc(save_path),
|
||||
ad(tc),
|
||||
tcm(cr, tc, tc),
|
||||
tmm(rmm, cr, tcm, tc, tc),
|
||||
ttm(rmm, cr, tcm, tc, tc),
|
||||
sdlrtu(renderer_),
|
||||
cg(rmm, cr, sdlrtu)
|
||||
cg(conf, rmm, cr, sdlrtu)
|
||||
{
|
||||
tel.subscribeAll(tc);
|
||||
|
||||
@ -62,6 +64,8 @@ Screen* MainScreen::poll(bool& quit) {
|
||||
|
||||
pm.tick(time_delta);
|
||||
|
||||
mts.iterate();
|
||||
|
||||
cg.render();
|
||||
|
||||
{
|
||||
@ -70,6 +74,7 @@ Screen* MainScreen::poll(bool& quit) {
|
||||
quit = !open;
|
||||
}
|
||||
|
||||
#if 0
|
||||
{ // texture tests
|
||||
const size_t width = 8;
|
||||
const size_t height = 8;
|
||||
@ -96,6 +101,7 @@ Screen* MainScreen::poll(bool& quit) {
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
#endif
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <solanaceae/util/simple_config_model.hpp>
|
||||
#include <solanaceae/contact/contact_model3.hpp>
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
#include <solanaceae/message3/message_time_sort.hpp>
|
||||
#include <solanaceae/plugin/plugin_manager.hpp>
|
||||
#include <solanaceae/toxcore/tox_event_logger.hpp>
|
||||
|
||||
@ -13,6 +14,7 @@
|
||||
#include <solanaceae/tox_messages/tox_transfer_manager.hpp>
|
||||
|
||||
#include "./tox_client.hpp"
|
||||
#include "./auto_dirty.hpp"
|
||||
|
||||
#include "./sdlrenderer_texture_uploader.hpp"
|
||||
#include "./chat_gui4.hpp"
|
||||
@ -34,11 +36,13 @@ struct MainScreen final : public Screen {
|
||||
SimpleConfigModel conf;
|
||||
Contact3Registry cr;
|
||||
RegistryMessageModel rmm;
|
||||
MessageTimeSort mts;
|
||||
|
||||
PluginManager pm;
|
||||
|
||||
ToxEventLogger tel{std::cout};
|
||||
ToxClient tc;
|
||||
AutoDirty ad;
|
||||
ToxContactModel2 tcm;
|
||||
ToxMessageManager tmm;
|
||||
ToxTransferManager ttm;
|
||||
|
Reference in New Issue
Block a user