Keep deferred drag results owned by their operation
This commit is contained in:
1 parent
11fc932905
commit
db91bccda3
2 files changed
+14
-18
No files matched your search
@@ -37,6 +37,7 @@
|
||||
#include <QEventLoop>
|
||||
#include <QCloseEvent>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <limits>
|
||||
#include <cstring>
|
||||
extern "C" {
|
||||
@@ -542,17 +543,13 @@ void MemberFileBrowser::download(bool open) {
|
||||
m_openAfter = open; startTransfer(selectedPath(), local, false, selectedVersion());
|
||||
}
|
||||
|
||||
void MemberFileBrowser::publishExport(const QStringList& paths, bool clipboard) {
|
||||
void MemberFileBrowser::publishExport(const QStringList& paths) {
|
||||
auto* mime = new QMimeData; QList<QUrl> urls; QByteArray gnome("copy");
|
||||
for (const auto& path : paths) { QUrl url = QUrl::fromLocalFile(path); urls.append(url); gnome += '\n' + url.toEncoded(); }
|
||||
mime->setUrls(urls); mime->setData("x-special/gnome-copied-files", gnome); mime->setData("application/x-kde-cutselection", "0");
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEDIA, "file browser: exporting entries=%d clipboard=%d", int(paths.size()), clipboard);
|
||||
if (clipboard) {
|
||||
QGuiApplication::clipboard()->setMimeData(mime);
|
||||
m_status->setText(text("Selection copied. Paste it in your file manager."));
|
||||
} else {
|
||||
auto* drag = new QDrag(m_entries); drag->setMimeData(mime); drag->exec(Qt::CopyAction, Qt::CopyAction);
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEDIA, "file browser: clipboard ready entries=%d", int(paths.size()));
|
||||
QGuiApplication::clipboard()->setMimeData(mime);
|
||||
m_status->setText(text("Selection copied. Paste it in your file manager."));
|
||||
}
|
||||
|
||||
void MemberFileBrowser::exportFile(bool clipboard, const QString& destination) {
|
||||
@@ -567,13 +564,14 @@ void MemberFileBrowser::exportFile(bool clipboard, const QString& destination) {
|
||||
m_status->setText(text("Cannot prepare a local copy")); return;
|
||||
}
|
||||
if (destination.isEmpty()) base += "/file-exports";
|
||||
m_exportId = requestId(); m_exportResult.clear(); m_openAfter = false;
|
||||
m_exportId = requestId(); m_openAfter = false;
|
||||
auto result = std::make_shared<QStringList>();
|
||||
quint64 id = m_exportId;
|
||||
auto* batch = createBatch(MemberFileBatch::Download);
|
||||
batch->finished = [this, batch, clipboard](bool ok, const QString& summary, const QStringList& roots) {
|
||||
batch->finished = [this, batch, clipboard, result](bool ok, const QString& summary, const QStringList& roots) {
|
||||
m_batch = nullptr; m_exportId = 0; m_progress->hide(); m_uploadStatus->setText(summary);
|
||||
m_exportResult = ok ? roots : QStringList(); batch->deleteLater(); updateActions();
|
||||
if (ok && clipboard) publishExport(roots, true);
|
||||
*result = ok ? roots : QStringList(); batch->deleteLater(); updateActions();
|
||||
if (ok && clipboard) publishExport(roots);
|
||||
else m_status->setText(ok ? text("Local copy ready") : summary);
|
||||
emit exportFinished();
|
||||
if (m_closeAfterBatch) QTimer::singleShot(0, this, &QWidget::close);
|
||||
@@ -583,16 +581,15 @@ void MemberFileBrowser::exportFile(bool clipboard, const QString& destination) {
|
||||
if (!clipboard && destination.isEmpty()) {
|
||||
QPointer<MemberFileBrowser> guard(this);
|
||||
auto* mime = new DeferredFileMimeData;
|
||||
mime->localFiles = [guard, id] {
|
||||
if (!guard) return QStringList();
|
||||
if (guard->m_exportId == id) {
|
||||
mime->localFiles = [guard, id, result] {
|
||||
if (guard && guard->m_exportId == id) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "file browser: drag waiting for batch id=%llu", (unsigned long long)id);
|
||||
QEventLoop wait;
|
||||
QObject::connect(guard, &MemberFileBrowser::exportFinished, &wait, &QEventLoop::quit);
|
||||
QObject::connect(guard, &QObject::destroyed, &wait, &QEventLoop::quit);
|
||||
wait.exec();
|
||||
}
|
||||
return guard ? guard->m_exportResult : QStringList();
|
||||
return *result;
|
||||
};
|
||||
auto* drag = new QDrag(m_entries); drag->setMimeData(mime); drag->setParent(QCoreApplication::instance());
|
||||
connect(this, &QObject::destroyed, drag, [] { QDrag::cancel(); });
|
||||
|
||||
Reference in new issue
Block a user