Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[transfer-engine] Add 'Open' action to file transfer notifications. J…
…B#50340
  • Loading branch information
Bea Lam committed Jun 26, 2020
1 parent 96616b9 commit 83b436e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
5 changes: 5 additions & 0 deletions dbus/org.nemo.transferengine.xml
Expand Up @@ -125,6 +125,11 @@
<arg name="enabled" type="b" direction="out"/>
</method>

# open a specific transfer file
<method name="openTransfer">
<arg name="transferId" type="i" direction="in"/>
</method>

# Signals for indicating changes in transfers
<signal name="progressChanged">
<arg name="transferId" type="i" direction="out"/>
Expand Down
1 change: 1 addition & 0 deletions rpm/nemo-transferengine-qt5.spec
Expand Up @@ -13,6 +13,7 @@ BuildRequires: pkgconfig(Qt5Test)
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5Quick)
BuildRequires: pkgconfig(accounts-qt5)
BuildRequires: pkgconfig(contentaction5)
BuildRequires: desktop-file-utils
BuildRequires: pkgconfig(quillmetadata-qt5)
BuildRequires: pkgconfig(nemonotifications-qt5) >= 1.0.4
Expand Down
2 changes: 1 addition & 1 deletion src/src.pro
Expand Up @@ -20,7 +20,7 @@ transferengine.header_flags = -i metatypedeclarations.h -i transferengine.h -l T
transferengine.source_flags = -l TransferEngine -c TransferEngineAdaptor

CONFIG += link_pkgconfig
PKGCONFIG += accounts-qt5 nemonotifications-qt5
PKGCONFIG += accounts-qt5 nemonotifications-qt5 contentaction5

# translations
TS_FILE = $$OUT_PWD/nemo-transfer-engine.ts
Expand Down
57 changes: 54 additions & 3 deletions src/transferengine.cpp
Expand Up @@ -41,12 +41,18 @@
#include <QTimer>
#include <QSettings>

// nemonotifications
#include <notification.h>

// stdlib
#include <signal.h>

// libaccounts-qt
#include <Accounts/Manager>

// libcontentaction
#include "contentaction.h"

#define CONFIG_PATH "/usr/share/nemo-transferengine/nemo-transfer-engine.conf"
#define FILE_WATCHER_TIMEOUT 5000
#define ACTIVITY_MONITOR_TIMEOUT 1*60*1000 // 1 minute in ms
Expand Down Expand Up @@ -339,6 +345,7 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
Notification::Urgency urgency = Notification::Normal;
QString appIcon = QStringLiteral("icon-lock-information");
QString icon = QStringLiteral("icon-lock-transfer");
QVariantList actions = 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 @@ -347,7 +354,7 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
// Notification & Banner rules:
//
// Show Banner:
// - For succesfull uploads and for downloads
// - For successful uploads and for downloads
// - For failed Uploads, Downloads, Syncs
//
// Show an event in the EventView:
Expand All @@ -367,14 +374,27 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
category = TRANSFER_EVENT_CATEGORY; // Use "generic" transfer event for uploads
break;
case TransferEngineData::Download:
{
category = TRANSFER_COMPLETE_EVENT_CATEGORY;
//: Notification for successful file download
//% "File downloaded"
body = qtTrId("transferengine-no-file-download-success");
summary = fileName;
previewBody = body;
previewSummary = summary;

//: Open the transferred file
//% "Open"
actions << Notification::remoteAction("action_open",
qtTrId("transferengine-la-open_file"),
"org.nemo.transferengine",
"/org/nemo/transferengine",
"org.nemo.transferengine",
"openTransfer",
(QVariantList() << transferId));

break;
}
case TransferEngineData::Sync:
// Ok exit
break;
Expand Down Expand Up @@ -451,8 +471,8 @@ void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType ty
notification.setReplacesId(notificationId);
}

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

//: Group name for notifications of successful transfers
Expand All @@ -477,6 +497,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 @@ -1408,3 +1429,33 @@ bool TransferEngine::notificationsEnabled()
d->exitSafely();
return d->m_notificationsEnabled;
}

/*!
DBus adaptor calls this method.
Opens the file with the given \a transferId.
*/
void TransferEngine::openTransfer(int transferId)
{
Q_D(TransferEngine);
d->exitSafely();

MediaItem *item = DbManager::instance()->mediaItem(transferId);
if (!item) {
qCWarning(lcTransferLog) << "TransferEngine::openTransfer: failed to fetch media item from db!";
return;
}

const QUrl url = item->value(MediaItem::Url).toUrl();
if (url.scheme() != QStringLiteral("http") && url.scheme() != QStringLiteral("https")) {
QString filePath = url.toString();
if (filePath.startsWith('/')) {
filePath = QStringLiteral("file://%1").arg(filePath);
}
ContentAction::Action action = ContentAction::Action::defaultActionForFile(filePath);
if (action.isValid()) {
action.trigger();
} else {
qCWarning(lcTransferLog) << "TransferEngine::openTransfer() cannot find desktop action to open" << filePath;
}
}
}
2 changes: 2 additions & 0 deletions src/transferengine.h
Expand Up @@ -98,6 +98,8 @@ public Q_SLOTS:

bool notificationsEnabled();

void openTransfer(int transferId);

Q_SIGNALS:
void progressChanged(int transferId, double progress);

Expand Down

0 comments on commit 83b436e

Please sign in to comment.