Skip to content

Commit

Permalink
Fix portal urls cache on X11
Browse files Browse the repository at this point in the history
When I was reading QPA code at first, I was thinking that windows and
cocoa QPAs have a QMimeData for all the run time, while xcb and wayland
create them on every owner change. It seems I've misread the xcb code
as the portal cache bugs on it now.

This changes the cache to use the last transfer ID that should make it
unaware of the implementation detail while still allowing the consumer
to get portal urls until another file is copied.

BUG: 460314
  • Loading branch information
ilya-fedin authored and nicolasfella committed Dec 15, 2022
1 parent babf0a0 commit 4f35c8d
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/lib/io/kurlmimedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ static QString portalFormat()
static QList<QUrl> extractPortalUriList(const QMimeData *mimeData)
{
Q_ASSERT(QCoreApplication::instance()->thread() == QThread::currentThread());
static QHash<const QMimeData*, QList<QUrl>> cache;
if (const auto uris = cache.constFind(mimeData); uris != cache.constEnd()) {
qCDebug(KCOREADDONS_DEBUG) << "Urls from portal cache" << *uris;
return *uris;
}
static std::pair<QByteArray, QList<QUrl>> cache;
const auto transferId = mimeData->data(portalFormat());
qCDebug(KCOREADDONS_DEBUG) << "Picking up portal urls from transfer" << transferId;
if (std::get<QByteArray>(cache) == transferId) {
const auto uris = std::get<QList<QUrl>>(cache);
qCDebug(KCOREADDONS_DEBUG) << "Urls from portal cache" << uris;
return uris;
}
auto iface =
new OrgFreedesktopPortalFileTransferInterface(portalServiceName(), QStringLiteral("/org/freedesktop/portal/documents"), QDBusConnection::sessionBus());
const QStringList list = iface->RetrieveFiles(QString::fromUtf8(transferId), {});
Expand All @@ -135,10 +136,7 @@ static QList<QUrl> extractPortalUriList(const QMimeData *mimeData)
uris.append(QUrl::fromLocalFile(path));
}
qCDebug(KCOREADDONS_DEBUG) << "Urls from portal" << uris;
cache.insert(mimeData, uris);
QObject::connect(mimeData, &QObject::destroyed, [mimeData] {
cache.remove(mimeData);
});
cache = std::make_pair(transferId, uris);
return uris;
}
#endif
Expand Down

0 comments on commit 4f35c8d

Please sign in to comment.