From 2a5937652ead3c439f0bba92eae659f62f71bf01 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 18 Oct 2023 14:23:27 +0200 Subject: [PATCH] add file dropping support --- src/chat_gui4.cpp | 6 ++++++ src/chat_gui4.hpp | 2 ++ src/main_screen.cpp | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/src/chat_gui4.cpp b/src/chat_gui4.cpp index 877dca0..8fe466c 100644 --- a/src/chat_gui4.cpp +++ b/src/chat_gui4.cpp @@ -415,6 +415,12 @@ void ChatGui4::render(void) { _msg_tc.workLoadQueue(); } +void ChatGui4::sendFilePath(const char* file_path) { + if (_selected_contact && std::filesystem::is_regular_file(file_path)) { + _rmm.sendFilePath(*_selected_contact, std::filesystem::path(file_path).filename().u8string(), file_path); + } +} + // has MessageText void ChatGui4::renderMessageBodyText(Message3Registry& reg, const Message3 e) { const auto& msgtext = reg.get(e).text; diff --git a/src/chat_gui4.hpp b/src/chat_gui4.hpp index 5a54cd1..73b5739 100644 --- a/src/chat_gui4.hpp +++ b/src/chat_gui4.hpp @@ -50,6 +50,8 @@ class ChatGui4 { public: bool any_unread {false}; + void sendFilePath(const char* file_path); + private: void renderMessageBodyText(Message3Registry& reg, const Message3 e); void renderMessageBodyFile(Message3Registry& reg, const Message3 e); diff --git a/src/main_screen.cpp b/src/main_screen.cpp index d3795a7..34d152a 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -67,6 +67,12 @@ MainScreen::~MainScreen(void) { } bool MainScreen::handleEvent(SDL_Event& e) { + if (e.type == SDL_EVENT_DROP_FILE) { + std::cout << "DROP FILE: " << e.drop.file << "\n"; + cg.sendFilePath(e.drop.file); + return true; // TODO: forward return succ from sendFilePath() + } + return false; }