Skip to content

Commit

Permalink
[transferengine] Offer 'open' action for downloaded files on the noti…
Browse files Browse the repository at this point in the history
…fication. Fixes JB#46934
  • Loading branch information
pvuorela committed Mar 10, 2021
1 parent aebd9b7 commit ede8a21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/transferengine.cpp
Expand Up @@ -330,7 +330,8 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
qreal progress,
const QString &fileName,
int transferId,
bool canCancel)
bool canCancel,
const QUrl &localFileUrl)
{
if (!m_notificationsEnabled || fileName.isEmpty()) {
return;
Expand Down Expand Up @@ -378,6 +379,17 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
//% "File downloaded"
body = qtTrId("transferengine-no-file-download-success");
summary = fileName;
if (!localFileUrl.isEmpty()) {
remoteActions.append(Notification::remoteAction(QString(),
//: Open a downloaded file
//% "Open"
qtTrId("transferengine-no-open"),
"org.sailfishos.fileservice",
"/",
"org.sailfishos.fileservice",
"openUrl",
QVariantList() << localFileUrl.toString()));
}
break;
case TransferEngineData::Sync:
// Ok exit
Expand Down Expand Up @@ -492,6 +504,7 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
if (useProgress) {
notification.setHintValue(TRANSFER_PROGRESS_HINT, static_cast<double>(progress));
}

notification.publish();
int newId = notification.replacesId();

Expand Down Expand Up @@ -1194,6 +1207,8 @@ void TransferEngine::finishTransfer(int transferId, int status, const QString &r
}

QString fileName;
QUrl localFileUrl;

// Read the file path from the database for download
if (type == TransferEngineData::Download) {
MediaItem *mediaItem = DbManager::instance()->mediaItem(transferId);
Expand All @@ -1202,14 +1217,22 @@ void TransferEngine::finishTransfer(int transferId, int status, const QString &r
return;
}
fileName = d->mediaFileOrResourceName(mediaItem);
QString mediaUrl = mediaItem->value(MediaItem::Url).toString();

if (mediaUrl.startsWith(QLatin1String("/"))) {
localFileUrl = QUrl::fromLocalFile(mediaUrl);
} else if (mediaUrl.startsWith(QLatin1String("file://"))) {
localFileUrl = QUrl(mediaUrl);
}
}

TransferEngineData::TransferStatus transferStatus = static_cast<TransferEngineData::TransferStatus>(status);
if (transferStatus == TransferEngineData::TransferFinished ||
transferStatus == TransferEngineData::TransferCanceled ||
transferStatus == TransferEngineData::TransferInterrupted) {
DbManager::instance()->updateTransferStatus(transferId, transferStatus);
d->sendNotification(type, transferStatus, DbManager::instance()->transferProgress(transferId), fileName, transferId, false);
d->sendNotification(type, transferStatus, DbManager::instance()->transferProgress(transferId), fileName, transferId, false, localFileUrl);

if (d->m_activityMonitor->isActiveTransfer(transferId)) {
d->m_activityMonitor->activityFinished(transferId);
}
Expand Down
3 changes: 2 additions & 1 deletion src/transferengine_p.h
Expand Up @@ -107,7 +107,8 @@ class TransferEnginePrivate: QObject
qreal progress,
const QString &fileName,
int transferId,
bool canCancel);
bool canCancel,
const QUrl &localFileUrl = QUrl());
int uploadMediaItem(MediaItem *mediaItem,
MediaTransferInterface *muif,
const QVariantMap &userData);
Expand Down

0 comments on commit ede8a21

Please sign in to comment.