Skip to content
Permalink
Browse files
[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.
  • Loading branch information
Bea Lam committed Oct 2, 2013
1 parent 5f442cd commit b22fef56cb667354d872f864f874fa7d7d069ac2
Showing with 21 additions and 18 deletions.
  1. +19 −16 src/transferengine.cpp
  2. +2 −2 src/transferengine_p.h
@@ -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,25 +1104,24 @@ 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);
if (!mediaItem) {
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 @@ class TransferEnginePrivate: QObject
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 Q_SLOTS:
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;

0 comments on commit b22fef5

Please sign in to comment.