Commit f82591e4 authored by pvuorela's avatar pvuorela

Merge branch 'open_file_action' into 'master'

[transferengine] Offer 'open' action for downloaded files on the notification. Fixes JB#46934

See merge request !23
parents aebd9b7c 743820cf
......@@ -193,8 +193,10 @@ TransferEnginePrivate::TransferEnginePrivate(TransferEngine *parent):
settings.endGroup();
if (!service.isEmpty() && !path.isEmpty() && !iface.isEmpty() && !method.isEmpty()) {
m_defaultActions << Notification::remoteAction("default", "", service, path, iface, method)
<< Notification::remoteAction("app", "", service, path, iface, method);
m_defaultActions << Notification::remoteAction("default", QString(), service, path, iface, method);
//% "Show transfers"
m_showTransfersAction = Notification::remoteAction(QString(), qtTrId("transferengine-no-show_transfers"),
service, path, iface, method);
}
}
}
......@@ -330,7 +332,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;
......@@ -378,6 +381,17 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
//% "File downloaded"
body = qtTrId("transferengine-no-file-download-success");
summary = fileName;
if (!localFileUrl.isEmpty()) {
remoteActions.clear();
remoteActions.append(Notification::remoteAction(QLatin1String("default"),
QString(),
"org.sailfishos.fileservice",
"/",
"org.sailfishos.fileservice",
"openUrl",
QVariantList() << localFileUrl.toString()));
remoteActions.append(m_showTransfersAction);
}
break;
case TransferEngineData::Sync:
// Ok exit
......@@ -492,6 +506,7 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
if (useProgress) {
notification.setHintValue(TRANSFER_PROGRESS_HINT, static_cast<double>(progress));
}
notification.publish();
int newId = notification.replacesId();
......@@ -1194,6 +1209,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);
......@@ -1202,6 +1219,13 @@ 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);
......@@ -1209,7 +1233,8 @@ 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, false);
d->sendNotification(type, transferStatus, DbManager::instance()->transferProgress(transferId), fileName, transferId, false, localFileUrl);
if (d->m_activityMonitor->isActiveTransfer(transferId)) {
d->m_activityMonitor->activityFinished(transferId);
}
......
......@@ -107,7 +107,8 @@ public:
qreal progress,
const QString &fileName,
int transferId,
bool canCancel);
bool canCancel,
const QUrl &localFileUrl = QUrl());
int uploadMediaItem(MediaItem *mediaItem,
MediaTransferInterface *muif,
const QVariantMap &userData);
......@@ -146,6 +147,7 @@ private:
ClientActivityMonitor *m_activityMonitor;
TransferEngine *q_ptr;
QVariantList m_defaultActions;
QVariant m_showTransfersAction;
Q_DECLARE_PUBLIC(TransferEngine)
};
......
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