Commit 35a50e59 authored by Nicolas Jager's avatar Nicolas Jager Committed by Anthony Léonard

stubs for data transfer

- this patch is a stub, it show signals and slots connected from
  the daemon to the client.

- each ConversationModel own a TransfertModel.

- add (stub) sendFile and acceptFile to ConversationModel.

Change-Id: Ie53db55e66f466f73644e4119ec1fd25336ab7ae
Reviewed-by: default avatarAnthony Léonard <anthony.leonard@savoirfairelinux.com>
parent eeb42c0f
......@@ -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
......
......@@ -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;
......
......@@ -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
......@@ -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;
};
......
......@@ -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"
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment