diff --git a/src/api/conversationmodel.h b/src/api/conversationmodel.h index 3203e787d8920e976b5df484335efa771b2071d0..795604f7eb4dd03e8a0840af671028f66ab0b318 100644 --- a/src/api/conversationmodel.h +++ b/src/api/conversationmodel.h @@ -148,13 +148,17 @@ public: */ void deleteObsoleteHistory(int date); + void sendFile(const std::string& uid, const std::string& path, const std::string& filename); + + void acceptFile(const std::string& uid, uint64_t interactionId); + Q_SIGNALS: /** * Emitted when a conversation receives a new interaction * @param uid of msg * @param msg */ - void newUnreadMessage(const std::string& uid, uint64_t msgId, const interaction::Info& msg) const; + void newUnreadMessage(const std::string& uid, uint64_t msgId, const interaction::Info& msg) const; // [jn] rendre cette fonction plus générique en remplaçant message par interaction /** * Emitted when an interaction got a new status * @param convUid conversation which owns the interaction diff --git a/src/api/datatransfermodel.h b/src/api/datatransfermodel.h index bc5d542b36f97869eb9fc571636e5751d07f4a59..de0edb858245e08f2629f87e7e373bc89f770d55 100644 --- a/src/api/datatransfermodel.h +++ b/src/api/datatransfermodel.h @@ -49,8 +49,7 @@ class LIB_EXPORT DataTransferModel : public QObject { public: DataTransferModel(Database& database, - const CallbacksHandler& callbacksHandler, - const api::BehaviorController& behaviorController); + const CallbacksHandler& callbacksHandler); ~DataTransferModel(); std::vector<std::string> transferIdList() const; diff --git a/src/callbackshandler.cpp b/src/callbackshandler.cpp index 18e90d15c570aaee8d575452dd5c59178a010af1..b8e187e4b688815c9bace5532b6bc0e796e10110 100644 --- a/src/callbackshandler.cpp +++ b/src/callbackshandler.cpp @@ -22,6 +22,7 @@ #include "api/account.h" #include "api/lrc.h" #include "api/newaccountmodel.h" +#include "api/datatransfer.h" // Lrc #include "account.h" @@ -30,6 +31,9 @@ #include "dbus/presencemanager.h" #include "namedirectory.h" +// DRing +#include <datatransfer_interface.h> + namespace lrc { @@ -109,6 +113,11 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent) &CallManagerInterface::incomingMessage, this, &CallbacksHandler::slotIncomingMessage); + + connect(&ConfigurationManager::instance(), + &ConfigurationManagerInterface::dataTransferEvent, + this, + &CallbacksHandler::slotDataTransferEvent); } CallbacksHandler::~CallbacksHandler() @@ -272,4 +281,10 @@ CallbacksHandler::slotAccountMessageStatusChanged(const QString& accountId, to.toStdString(), status); } +void +CallbacksHandler::slotDataTransferEvent(qulonglong dring_id, uint code) +{ + emit incomingTransfer(-1, -1); +} + } // namespace lrc diff --git a/src/callbackshandler.h b/src/callbackshandler.h index 2371c00f1b43d6383eab5bd397db9387e4466db6..c4e70b178a65c3b043ad95ff5d02b35fb6185c52 100644 --- a/src/callbackshandler.h +++ b/src/callbackshandler.h @@ -160,6 +160,8 @@ Q_SIGNALS: const uint64_t id, const std::string& to, int status); + void incomingTransfer(long long dring_id, uint code); + private Q_SLOTS: /** * Emit newAccountMessage @@ -278,6 +280,8 @@ private Q_SLOTS: const uint64_t id, const QString& to, int status); + void slotDataTransferEvent(qulonglong id, uint code); + private: const api::Lrc& parent; }; diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index 3eb82442c9af6cf80b57e27604d4f827a4f1a4f6..f1195270d67fe274ee3435e907cd1aa409c04d20 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -33,6 +33,8 @@ #include "api/newaccountmodel.h" #include "api/account.h" #include "api/call.h" +#include "api/datatransfer.h" +#include "api/datatransfermodel.h" #include "callbackshandler.h" #include "authority/databasehelper.h" @@ -135,6 +137,7 @@ public: const CallbacksHandler& callbacksHandler; const std::string accountProfileId; const BehaviorController& behaviorController; + DataTransferModel dataTransferModel; ConversationModel::ConversationQueue conversations; ///< non-filtered conversations ConversationModel::ConversationQueue filteredConversations; @@ -211,6 +214,14 @@ public Q_SLOTS: */ void slotConferenceRemoved(const std::string& confId); + void slotIncomingTransfer(const std::string& uid, + const std::string& display_name, + const std::size_t size, + const std::size_t offset); + + void slotTransferStatusChanged(const std::string& uid, + datatransfer::Status status); + }; ConversationModel::ConversationModel(const account::Info& owner, @@ -652,6 +663,7 @@ ConversationModelPimpl::ConversationModelPimpl(const ConversationModel& linked, , typeFilter(profile::Type::INVALID) , accountProfileId(database::getProfileId(db, linked.owner.profileInfo.uri)) , behaviorController(behaviorController) +, dataTransferModel(db, callbacksHandler) { initConversations(); @@ -699,6 +711,17 @@ ConversationModelPimpl::ConversationModelPimpl(const ConversationModel& linked, &CallbacksHandler::conferenceRemoved, this, &ConversationModelPimpl::slotConferenceRemoved); + + connect(&dataTransferModel, + &DataTransferModel::incomingTransfer, + this, + &ConversationModelPimpl::slotIncomingTransfer); + + connect(&dataTransferModel, + &DataTransferModel::transferStatusChanged, + this, + &ConversationModelPimpl::slotTransferStatusChanged); + } ConversationModelPimpl::~ConversationModelPimpl() @@ -1202,6 +1225,43 @@ ConversationModelPimpl::getNumberOfUnreadMessagesFor(const std::string& uid) database::countUnreadFromInteractions(db, uid); } +void +ConversationModelPimpl::slotIncomingTransfer(const std::string& uid, + const std::string& display_name, + const std::size_t size, + const std::size_t offset) +{ + emit linked.newUnreadMessage("", -1, {}); +} + +void +ConversationModelPimpl::slotTransferStatusChanged(const std::string& uid, datatransfer::Status status) +{ + emit linked.interactionStatusUpdated("", -1, {}); +} + +void +ConversationModel::sendFile(const std::string& uid, const std::string& path, const std::string& filename) +{ + auto conversationIdx = pimpl_->indexOf(uid); + if (conversationIdx != -1) { + auto& peerUri = pimpl_->conversations[conversationIdx].participants.front(); + if (not peerUri.empty()) + pimpl_->dataTransferModel.sendFile(owner.id.c_str(), peerUri.c_str(), path.c_str(), filename.c_str()); + } +} + +void +ConversationModel::acceptFile(const std::string& uid, uint64_t interactionId) +{ + auto conversationIdx = pimpl_->indexOf(uid); + if (conversationIdx != -1) { + auto& dataTransferUid = pimpl_->dataTransferModel.transferIdList()[interactionId]; + if (not dataTransferUid.empty()) + pimpl_->dataTransferModel.acceptFile(dataTransferUid, "~", 0); + } +} + } // namespace lrc #include "api/moc_conversationmodel.cpp" diff --git a/src/datatransfermodel.cpp b/src/datatransfermodel.cpp index 5c48cd61d263ecff8352a654f6a973b29bf99192..82d4f1d229ea8108c28a2c2852fe67264166eb77 100644 --- a/src/datatransfermodel.cpp +++ b/src/datatransfermodel.cpp @@ -18,7 +18,6 @@ // LRC #include "api/datatransfermodel.h" -#include "api/behaviorcontroller.h" #include "callbackshandler.h" #include "database.h" @@ -64,33 +63,29 @@ class DataTransferModel::Impl : public QObject public: Impl(DataTransferModel& up_link, Database& database, - const CallbacksHandler& callbacksHandler, - const api::BehaviorController& behaviorController); + const CallbacksHandler& callbacksHandler); DataTransferModel& upLink; std::map<DRing::DataTransferId, std::string> dring2lrcIdMap; std::map<std::string, DRing::DataTransferId> lrc2dringIdMap; // stricly the reverse map of dring2lrcIdMap Database& database; const CallbacksHandler& callbacksHandler; - const BehaviorController& behaviorController; std::string registerTransferId(DRing::DataTransferId id); public Q_SLOTS: - void slotDataTransferEvent(qulonglong id, uint code); + void slotDataTransferEvent(long long dring_id, uint code); }; DataTransferModel::Impl::Impl(DataTransferModel& up_link, Database& database, - const CallbacksHandler& callbacksHandler, - const api::BehaviorController& behaviorController) + const CallbacksHandler& callbacksHandler) : QObject {} - , behaviorController {behaviorController} , callbacksHandler {callbacksHandler} , database {database} , upLink {up_link} { - connect(&ConfigurationManager::instance(), &ConfigurationManagerInterface::dataTransferEvent, + connect(&callbacksHandler, &CallbacksHandler::incomingTransfer, this, &DataTransferModel::Impl::slotDataTransferEvent); } @@ -110,26 +105,24 @@ DataTransferModel::Impl::registerTransferId(DRing::DataTransferId dring_id) } void -DataTransferModel::Impl::slotDataTransferEvent(qulonglong dring_id, uint code) +DataTransferModel::Impl::slotDataTransferEvent(long long dring_id, uint code) { - auto lrc_id = registerTransferId(dring_id); auto event = DRing::DataTransferEventCode(code); if (event == DRing::DataTransferEventCode::created) { auto info = static_cast<DataTransferInfo>(ConfigurationManager::instance().dataTransferInfo(dring_id)); if (!info.isOutgoing) { - emit upLink.incomingTransfer(lrc_id, info.displayName.toStdString(), info.totalSize, info.bytesProgress); + emit upLink.incomingTransfer("", "", 0, 0); return; } } - emit upLink.transferStatusChanged(lrc_id, convertDataTransferEvent(event)); + emit upLink.transferStatusChanged("", convertDataTransferEvent(event)); } DataTransferModel::DataTransferModel(Database& database, - const CallbacksHandler& callbacksHandler, - const api::BehaviorController& behaviorController) + const CallbacksHandler& callbacksHandler) : QObject() - , pimpl_ { std::make_unique<Impl>(*this, database, callbacksHandler, behaviorController) } + , pimpl_ { std::make_unique<Impl>(*this, database, callbacksHandler) } {} DataTransferModel::~DataTransferModel() = default;