Commit b22fef56 authored by blam's avatar blam

[transfer-engine] Ensure notifications are shown for non-file transfers

Allow MediaItem::ResourceName to be passed to sendNotification() when
MediaItem::Url is empty, as it will be if an uploader is sending a
non-file resource such as a vCard.
parent 5f442cdd
......@@ -263,20 +263,12 @@ void TransferEnginePrivate::recoveryCheck()
void TransferEnginePrivate::sendNotification(TransferEngineData::TransferType type,
TransferEngineData::TransferStatus status,
const QUrl &url)
const QString &fileName)
{
if (!m_notificationsEnabled || !url.isValid()) {
if (!m_notificationsEnabled || fileName.isEmpty()) {
return;
}
QStringList split;
QString fileName;
if (type != TransferEngineData::Sync) {
split = url.toString().split(QDir::separator());
fileName = split.at(split.length()-1);
}
QString msgGSummary;
QString msgNBody;
QString eventType;
......@@ -537,11 +529,23 @@ MediaTransferInterface *TransferEnginePrivate::loadPlugin(const QString &pluginI
return 0;
}
QString TransferEnginePrivate::mediaFileOrResourceName(MediaItem *mediaItem) const
{
if (!mediaItem) {
return QString();
}
QUrl url = mediaItem->value(MediaItem::Url).toUrl();
if (!url.isEmpty()) {
QStringList split = url.toString().split(QDir::separator());
return split.at(split.length()-1);
}
return mediaItem->value(MediaItem::ResourceName).toString();
}
void TransferEnginePrivate::uploadItemStatusChanged(MediaTransferInterface::TransferStatus status)
{
MediaTransferInterface *muif = qobject_cast<MediaTransferInterface*>(sender());
const int key = m_plugins.value(muif);
const QUrl filePath = muif->mediaItem()->value(MediaItem::Url).toString();
const TransferEngineData::TransferType type =
static_cast<TransferEngineData::TransferType>(muif->mediaItem()->value(MediaItem::TransferType).toInt());
......@@ -561,7 +565,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, filePath);
sendNotification(type, tStatus, mediaFileOrResourceName(muif->mediaItem()));
ok = DbManager::instance()->updateTransferStatus(key, tStatus);
if (m_plugins.remove(muif) == 0) {
qWarning() << "TransferEnginePrivate::uploadItemStatusChanged: Failed to remove media upload object from the map!";
......@@ -1100,7 +1104,7 @@ void TransferEngine::finishTransfer(int transferId, int status, const QString &r
return; // We don't handle plugins here
}
QUrl filePath;
QString fileName;
// Read the file path from the database for download
if (type == TransferEngineData::Download) {
MediaItem *mediaItem = DbManager::instance()->mediaItem(transferId);
......@@ -1108,17 +1112,16 @@ void TransferEngine::finishTransfer(int transferId, int status, const QString &r
qWarning() << "TransferEngine::finishTransfer: Failed to fetch MediaItem";
return;
}
filePath = mediaItem->value(MediaItem::Url).toUrl();
fileName = d->mediaFileOrResourceName(mediaItem);
}
TransferEngineData::TransferStatus transferStatus = static_cast<TransferEngineData::TransferStatus>(status);
if (transferStatus == TransferEngineData::TransferFinished ||
transferStatus == TransferEngineData::TransferCanceled ||
transferStatus == TransferEngineData::TransferInterrupted) {
DbManager::instance()->updateTransferStatus(transferId, transferStatus);
d->m_activityMonitor->activityFinished(transferId);
d->sendNotification(type, transferStatus, filePath);
d->sendNotification(type, transferStatus, fileName);
emit statusChanged(transferId, status);
// We don't want to leave successfully finished syncs to populate the database, just remove it.
......
......@@ -106,7 +106,7 @@ public:
void recoveryCheck();
void sendNotification(TransferEngineData::TransferType type,
TransferEngineData::TransferStatus status,
const QUrl &filePath);
const QString &fileName);
int uploadMediaItem(MediaItem *mediaItem,
MediaTransferInterface *muif,
const QVariantMap &userData);
......@@ -128,7 +128,7 @@ public:
QStringList pluginList() const;
QList <TransferMethodInfo> enabledPlugins() const;
MediaTransferInterface *loadPlugin(const QString &pluginId) const;
QString mediaFileOrResourceName(MediaItem *mediaItem) const;
QMap <MediaTransferInterface*, int> m_plugins;
QMap <int, TransferEngineData::TransferType> m_keyTypeCache;
......
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