diff --git a/tools/chatgui/src/messagedelegate.cpp b/tools/chatgui/src/messagedelegate.cpp index ceeb9790..e116b6ab 100644 --- a/tools/chatgui/src/messagedelegate.cpp +++ b/tools/chatgui/src/messagedelegate.cpp @@ -24,14 +24,6 @@ #include #include -extern "C" { -#include "../transport/gui_bridge.h" -#include "chat/chat_core.h" -#include "../../lib/u_async.h" -#include "../../lib/mem.h" -void chat_core_attachment_download_trampoline(void* arg); -} - MessageDelegate::MessageDelegate(QObject *parent) : QStyledItemDelegate(parent) {} @@ -96,16 +88,7 @@ bool MessageDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, } if (dlState == 1) return false; /* скачивается */ - if (chId.isEmpty() || msgId <= 0) return false; - struct attachment_dl_req* req = (struct attachment_dl_req*) - u_malloc(sizeof(struct attachment_dl_req)); - if (!req) return false; - memset(req, 0, sizeof(*req)); - req->inst = gui_bridge_get_inst(); - strncpy(req->channel_id, chId.toUtf8().constData(), sizeof(req->channel_id) - 1); - req->msg_id = msgId; - gui_bridge_post_uasync_fn(chat_core_attachment_download_trampoline, req); - return true; + return m_downloadCb && m_downloadCb(index); } if (L.isImage) { @@ -123,16 +106,7 @@ bool MessageDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, } if (dlState == 1) return false; /* скачивается */ - if (chId.isEmpty() || msgId <= 0) return false; - struct attachment_dl_req* req = (struct attachment_dl_req*) - u_malloc(sizeof(struct attachment_dl_req)); - if (!req) return false; - memset(req, 0, sizeof(*req)); - req->inst = gui_bridge_get_inst(); - strncpy(req->channel_id, chId.toUtf8().constData(), sizeof(req->channel_id) - 1); - req->msg_id = msgId; - gui_bridge_post_uasync_fn(chat_core_attachment_download_trampoline, req); - return true; + return m_downloadCb && m_downloadCb(index); } if (L.isFile) { @@ -151,16 +125,7 @@ bool MessageDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, } if (dlState == 1) return false; /* downloading — no action */ - if (chId.isEmpty() || msgId <= 0) return false; - struct attachment_dl_req* req = (struct attachment_dl_req*) - u_malloc(sizeof(struct attachment_dl_req)); - if (!req) return false; - memset(req, 0, sizeof(*req)); - req->inst = gui_bridge_get_inst(); - strncpy(req->channel_id, chId.toUtf8().constData(), sizeof(req->channel_id) - 1); - req->msg_id = msgId; - gui_bridge_post_uasync_fn(chat_core_attachment_download_trampoline, req); - return true; + return m_downloadCb && m_downloadCb(index); } if (!L.isVoice) return false; @@ -184,15 +149,7 @@ bool MessageDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, /* not downloaded (or file evicted): start download (play will start on completion) */ bool fileMissing = filePath.isEmpty() || !QFile::exists(filePath); if (fileMissing && dlState != 1) { - if (chId.isEmpty() || msgId <= 0) return false; - struct attachment_dl_req* req = (struct attachment_dl_req*) - u_malloc(sizeof(struct attachment_dl_req)); - if (!req) return false; - memset(req, 0, sizeof(*req)); - req->inst = gui_bridge_get_inst(); - strncpy(req->channel_id, chId.toUtf8().constData(), sizeof(req->channel_id) - 1); - req->msg_id = msgId; - gui_bridge_post_uasync_fn(chat_core_attachment_download_trampoline, req); + if (!m_downloadCb || !m_downloadCb(index)) return false; model->setData(index, true, MsgVoiceDownloadPendingRole); return true; } diff --git a/tools/chatgui/src/messagedelegate.h b/tools/chatgui/src/messagedelegate.h index 11af1818..a8181e16 100644 --- a/tools/chatgui/src/messagedelegate.h +++ b/tools/chatgui/src/messagedelegate.h @@ -60,6 +60,7 @@ public: void setVideoOpenCallback(std::function cb) { m_videoOpenCb = std::move(cb); } void setImageOpenCallback(std::function cb) { m_imageOpenCb = std::move(cb); } + void setDownloadCallback(std::function cb) { m_downloadCb = std::move(cb); } private: struct Layout { @@ -102,6 +103,7 @@ private: std::function m_videoOpenCb; std::function m_imageOpenCb; + std::function m_downloadCb; Layout calcLayout(const QStyleOptionViewItem &option, const QModelIndex &index) const;