Skip to content

Commit

Permalink
[transfer-engine] Add 'cancel' action to transfer notifications. JB#5…
Browse files Browse the repository at this point in the history
…0340

When the transfer is ongoing and supports the cancel method, add
a 'cancel' action to the notification.

Note the progress notification is only shown in the Events, and not
the notification preview.

Update DbManager::mediaItem() to set some more of the MediaItem
properties in the returned object.
  • Loading branch information
Bea Lam committed Aug 19, 2020
1 parent 4d5467b commit 13eb0e0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/dbmanager.cpp
Expand Up @@ -911,6 +911,10 @@ MediaItem * DbManager::mediaItem(int key) const
item->setValue(MediaItem::AccountId, query.value(rec.indexOf("account_id")));
item->setValue(MediaItem::DisplayName, query.value(rec.indexOf("display_name")));
item->setValue(MediaItem::ServiceIcon, query.value(rec.indexOf("service_icon")));
item->setValue(MediaItem::ApplicationIcon, query.value(rec.indexOf("application_icon")));
item->setValue(MediaItem::ThumbnailIcon, query.value(rec.indexOf("thumbnail_icon")));
item->setValue(MediaItem::CancelSupported, query.value(rec.indexOf("cancel_supported")));
item->setValue(MediaItem::RestartSupported, query.value(rec.indexOf("restart_supported")));
} else {
qWarning() << "DbManager::mediaItem: Failed to get media item data from database!";
delete item;
Expand Down
28 changes: 21 additions & 7 deletions src/transferengine.cpp
Expand Up @@ -322,7 +322,8 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
TransferEngineData::TransferStatus status,
qreal progress,
const QString &fileName,
int transferId)
int transferId,
bool canCancel)
{
if (!m_notificationsEnabled || fileName.isEmpty()) {
return;
Expand All @@ -335,6 +336,7 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
bool useProgress = false;
Notification::Urgency urgency = Notification::Normal;
QString appIcon = QStringLiteral("icon-lock-transfer");
QVariantList remoteActions = m_defaultActions;

// TODO: explicit grouping of transfer notifications is now removed, as grouping
// will now be performed by lipstick. We may need to reinstate group summary
Expand All @@ -350,7 +352,6 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
// - For downloads
// - For failed uploads, downloads and syncs


int notificationId = DbManager::instance()->notificationId(transferId);

if (status == TransferEngineData::TransferFinished) {
Expand Down Expand Up @@ -424,6 +425,18 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty

if (progress > 0)
useProgress = true;

if (canCancel) {
remoteActions.append(Notification::remoteAction(QString(),
//: Cancel the file transfer
//% "Cancel"
qtTrId("transferengine-no-cancel"),
"org.nemo.transferengine",
"/org/nemo/transferengine",
"org.nemo.transferengine",
"cancelTransfer",
QVariantList() << transferId));
}
}

} else if (status == TransferEngineData::TransferCanceled && notificationId > 0) {
Expand All @@ -443,8 +456,8 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
notification.setReplacesId(notificationId);
}

if (!m_defaultActions.isEmpty()) {
notification.setRemoteActions(m_defaultActions);
if (!remoteActions.isEmpty()) {
notification.setRemoteActions(remoteActions);
}

//: Group name for notifications of successful transfers
Expand Down Expand Up @@ -626,7 +639,7 @@ void TransferEnginePrivate::uploadItemStatusChanged(MediaTransferInterface::Tran
// If the flow ends up here, we are not interested in any signals the same object
// might emit. Let's just disconnect them.
muif->disconnect();
sendNotification(type, tStatus, muif->progress(), mediaFileOrResourceName(muif->mediaItem()), key);
sendNotification(type, tStatus, muif->progress(), mediaFileOrResourceName(muif->mediaItem()), key, false);
ok = DbManager::instance()->updateTransferStatus(key, tStatus);
if (m_plugins.remove(muif) == 0) {
qCWarning(lcTransferLog) << "TransferEnginePrivate::uploadItemStatusChanged: Failed to remove media upload object from the map!";
Expand Down Expand Up @@ -1186,7 +1199,7 @@ void TransferEngine::finishTransfer(int transferId, int status, const QString &r
transferStatus == TransferEngineData::TransferCanceled ||
transferStatus == TransferEngineData::TransferInterrupted) {
DbManager::instance()->updateTransferStatus(transferId, transferStatus);
d->sendNotification(type, transferStatus, DbManager::instance()->transferProgress(transferId), fileName, transferId);
d->sendNotification(type, transferStatus, DbManager::instance()->transferProgress(transferId), fileName, transferId, false);
d->m_activityMonitor->activityFinished(transferId);
emit statusChanged(transferId, status);

Expand Down Expand Up @@ -1241,7 +1254,8 @@ void TransferEngine::updateTransferProgress(int transferId, double progress)
emit progressChanged(transferId, progress);

if (oldProgressPercentage != (progress * 100)) {
d->sendNotification(type, DbManager::instance()->transferStatus(transferId), progress, fileName, transferId);
bool canCancel = mediaItem->value(MediaItem::CancelSupported).toBool();
d->sendNotification(type, DbManager::instance()->transferStatus(transferId), progress, fileName, transferId, canCancel);
}
} else {
qCWarning(lcTransferLog) << "TransferEngine::updateTransferProgress: Failed to update progress for " << transferId;
Expand Down
3 changes: 2 additions & 1 deletion src/transferengine_p.h
Expand Up @@ -105,7 +105,8 @@ class TransferEnginePrivate: QObject
TransferEngineData::TransferStatus status,
qreal progress,
const QString &fileName,
int transferId);
int transferId,
bool canCancel);
int uploadMediaItem(MediaItem *mediaItem,
MediaTransferInterface *muif,
const QVariantMap &userData);
Expand Down

0 comments on commit 13eb0e0

Please sign in to comment.