datatransfer: support awaiting_peer and awaiting_host states

Change-Id: I06f936bb798539860ca8b4d9f362faf0ef6ae77c
parent ec8238b2
......@@ -92,7 +92,8 @@ enum class Status {
TRANSFER_ERROR,
TRANSFER_UNJOINABLE_PEER,
TRANSFER_ONGOING,
TRANSFER_AWAITING,
TRANSFER_AWAITING_PEER,
TRANSFER_AWAITING_HOST,
TRANSFER_FINISHED
};
......@@ -124,8 +125,10 @@ to_string(const Status& status)
return "TRANSFER_UNJOINABLE_PEER";
case Status::TRANSFER_ONGOING:
return "TRANSFER_ONGOING";
case Status::TRANSFER_AWAITING:
return "TRANSFER_AWAITING";
case Status::TRANSFER_AWAITING_HOST:
return "TRANSFER_AWAITING_HOST";
case Status::TRANSFER_AWAITING_PEER:
return "TRANSFER_AWAITING_PEER";
case Status::TRANSFER_FINISHED:
return "TRANSFER_FINISHED";
case Status::INVALID:
......@@ -161,8 +164,10 @@ to_status(const std::string& status)
return interaction::Status::TRANSFER_UNJOINABLE_PEER;
else if (status == "TRANSFER_ONGOING")
return interaction::Status::TRANSFER_ONGOING;
else if (status == "TRANSFER_AWAITING")
return interaction::Status::TRANSFER_AWAITING;
else if (status == "TRANSFER_AWAITING_HOST")
return interaction::Status::TRANSFER_AWAITING_HOST;
else if (status == "TRANSFER_AWAITING_PEER")
return interaction::Status::TRANSFER_AWAITING_PEER;
else if (status == "TRANSFER_FINISHED")
return interaction::Status::TRANSFER_FINISHED;
else
......
......@@ -303,8 +303,10 @@ CallbacksHandler::slotDataTransferEvent(qulonglong dringId, uint codeStatus)
emit transferStatusCanceled(static_cast<long long>(dringId), info);
break;
case DRing::DataTransferEventCode::wait_peer_acceptance:
emit transferStatusAwaitingPeer(static_cast<long long>(dringId), info);
break;
case DRing::DataTransferEventCode::wait_host_acceptance:
emit transferStatusAwaiting(static_cast<long long>(dringId), info);
emit transferStatusAwaitingHost(static_cast<long long>(dringId), info);
break;
case DRing::DataTransferEventCode::ongoing:
emit transferStatusOngoing(static_cast<long long>(dringId), info);
......
......@@ -163,7 +163,8 @@ Q_SIGNALS:
void transferStatusCreated(long long dringId, api::datatransfer::Info info);
void transferStatusCanceled(long long dringId, api::datatransfer::Info info);
void transferStatusAwaiting(long long dringId, api::datatransfer::Info info);
void transferStatusAwaitingPeer(long long dringId, api::datatransfer::Info info);
void transferStatusAwaitingHost(long long dringId, api::datatransfer::Info info);
void transferStatusOngoing(long long dringId, api::datatransfer::Info info);
void transferStatusFinished(long long dringId, api::datatransfer::Info info);
void transferStatusError(long long dringId, api::datatransfer::Info info);
......
......@@ -231,7 +231,8 @@ public Q_SLOTS:
void slotTransferStatusCreated(long long dringId, api::datatransfer::Info info);
void slotTransferStatusCanceled(long long dringId, api::datatransfer::Info info);
void slotTransferStatusAwaiting(long long dringId, api::datatransfer::Info info);
void slotTransferStatusAwaitingPeer(long long dringId, api::datatransfer::Info info);
void slotTransferStatusAwaitingHost(long long dringId, api::datatransfer::Info info);
void slotTransferStatusOngoing(long long dringId, api::datatransfer::Info info);
void slotTransferStatusFinished(long long dringId, api::datatransfer::Info info);
void slotTransferStatusError(long long dringId, api::datatransfer::Info info);
......@@ -738,9 +739,13 @@ ConversationModelPimpl::ConversationModelPimpl(const ConversationModel& linked,
this,
&ConversationModelPimpl::slotTransferStatusCanceled);
connect(&callbacksHandler,
&CallbacksHandler::transferStatusAwaiting,
&CallbacksHandler::transferStatusAwaitingPeer,
this,
&ConversationModelPimpl::slotTransferStatusAwaiting);
&ConversationModelPimpl::slotTransferStatusAwaitingPeer);
connect(&callbacksHandler,
&CallbacksHandler::transferStatusAwaitingHost,
this,
&ConversationModelPimpl::slotTransferStatusAwaitingHost);
connect(&callbacksHandler,
&CallbacksHandler::transferStatusOngoing,
this,
......@@ -802,7 +807,8 @@ ConversationModelPimpl::initConversations()
// Check if file transfer interactions were left in an incorrect state
for(auto& interaction : conversations[convIdx].interactions) {
if (interaction.second.status == interaction::Status::TRANSFER_CREATED
|| interaction.second.status == interaction::Status::TRANSFER_AWAITING
|| interaction.second.status == interaction::Status::TRANSFER_AWAITING_HOST
|| interaction.second.status == interaction::Status::TRANSFER_AWAITING_PEER
|| interaction.second.status == interaction::Status::TRANSFER_ONGOING
|| interaction.second.status == interaction::Status::TRANSFER_ACCEPTED) {
// If a datatransfer was left in a non-terminal status in DB, we switch this status to ERROR
......@@ -1423,21 +1429,43 @@ ConversationModelPimpl::slotTransferStatusCreated(long long dringId, datatransfe
}
void
ConversationModelPimpl::slotTransferStatusAwaiting(long long dringId, datatransfer::Info info)
ConversationModelPimpl::slotTransferStatusAwaitingPeer(long long dringId, datatransfer::Info info)
{
int interactionId;
std::string convId;
if (not usefulDataFromDataTransfer(dringId, info, interactionId, convId))
return;
database::updateInteractionStatus(db, interactionId, interaction::Status::TRANSFER_AWAITING_PEER);
auto conversationIdx = indexOf(convId);
if (conversationIdx != -1) {
auto& interactions = conversations[conversationIdx].interactions;
auto it = interactions.find(interactionId);
if (it != interactions.end()) {
it->second.status = interaction::Status::TRANSFER_AWAITING_PEER;
dirtyConversations = true;
emit linked.interactionStatusUpdated(convId, interactionId, it->second);
}
}
}
void
ConversationModelPimpl::slotTransferStatusAwaitingHost(long long dringId, datatransfer::Info info)
{
int interactionId;
std::string convId;
if (not usefulDataFromDataTransfer(dringId, info, interactionId, convId))
return;
database::updateInteractionStatus(db, interactionId, interaction::Status::TRANSFER_AWAITING);
database::updateInteractionStatus(db, interactionId, interaction::Status::TRANSFER_AWAITING_HOST);
auto conversationIdx = indexOf(convId);
if (conversationIdx != -1) {
auto& interactions = conversations[conversationIdx].interactions;
auto it = interactions.find(interactionId);
if (it != interactions.end()) {
it->second.status = interaction::Status::TRANSFER_AWAITING;
it->second.status = interaction::Status::TRANSFER_AWAITING_HOST;
dirtyConversations = true;
emit linked.interactionStatusUpdated(convId, interactionId, it->second);
}
......
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