Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'jb50340-action-display-names' into 'master'
Browse files Browse the repository at this point in the history
[transfer-engine] Add 'cancel' action to transfer notifications. JB#50340

See merge request mer-core/transfer-engine!18
  • Loading branch information
blam committed Sep 15, 2020
2 parents 4d5467b + d4c46d9 commit 11d3c58
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 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
45 changes: 34 additions & 11 deletions src/transferengine.cpp
Expand Up @@ -121,6 +121,11 @@ bool ClientActivityMonitor::activeTransfers() const
return !m_activityMap.isEmpty();
}

bool ClientActivityMonitor::isActiveTransfer(int transferId) const
{
return m_activityMap.contains(transferId);
}

void ClientActivityMonitor::checkActivity()
{
// Check if there are existing transfers which are not yet finished and
Expand Down Expand Up @@ -293,7 +298,9 @@ void TransferEnginePrivate::cleanupExpiredTransfers(const QList<int> &expiredIds
Q_Q(TransferEngine);
Q_FOREACH(int id, expiredIds) {
if (DbManager::instance()->updateTransferStatus(id, TransferEngineData::TransferInterrupted)) {
m_activityMonitor->activityFinished(id);
if (m_activityMonitor->isActiveTransfer(id)) {
m_activityMonitor->activityFinished(id);
}
emit q->statusChanged(id, TransferEngineData::TransferInterrupted);
}
}
Expand Down Expand Up @@ -322,7 +329,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 +343,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 +359,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 +432,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 +463,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 +646,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 @@ -818,6 +838,8 @@ TransferEngine::TransferEngine(QObject *parent) :
TransferDBRecord::registerType();
TransferPluginInfo::registerType();

new TransferEngineAdaptor(this);

QDBusConnection connection = QDBusConnection::sessionBus();
if (!connection.registerObject("/org/nemo/transferengine", this)) {
qFatal("Could not register object \'/org/nemo/transferengine\'");
Expand All @@ -827,8 +849,6 @@ TransferEngine::TransferEngine(QObject *parent) :
qFatal("DBUS service already taken. Kill the other instance first.");
}

new TransferEngineAdaptor(this);

// Let's make sure that db is open by creating
// DbManager singleton instance.
DbManager::instance();
Expand Down Expand Up @@ -1186,8 +1206,10 @@ 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->m_activityMonitor->activityFinished(transferId);
d->sendNotification(type, transferStatus, DbManager::instance()->transferProgress(transferId), fileName, transferId, false);
if (m_activityMonitor->isActiveTransfer(transferId)) {
d->m_activityMonitor->activityFinished(transferId);
}
emit statusChanged(transferId, status);

bool notify = false;
Expand Down Expand Up @@ -1241,7 +1263,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
4 changes: 3 additions & 1 deletion src/transferengine_p.h
Expand Up @@ -67,6 +67,7 @@ class ClientActivityMonitor: public QObject
void activityFinished(int transferId);

bool activeTransfers() const;
bool isActiveTransfer(int transferId) const;

public Q_SLOTS:
void checkActivity();
Expand Down Expand Up @@ -105,7 +106,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 11d3c58

Please sign in to comment.