From 19460119e9360b4f67eeac3e5f77b66e498c7417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9ven=20Car?= Date: Thu, 28 Oct 2021 10:22:59 +0200 Subject: [PATCH] PasteDialog: fix data pasting in Wayland In Wayland the clipboard changes anytime the focused window changes, which happens when opening the PasteDialog. In order to support this case, just check that chosen mimetype is still available after the dialog returns. CCBUG: 421974 --- src/widgets/paste.cpp | 6 +++--- src/widgets/pastedialog.cpp | 12 +----------- src/widgets/pastedialog_p.h | 10 +--------- 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/widgets/paste.cpp b/src/widgets/paste.cpp index 264a2778b..e7f44461d 100644 --- a/src/widgets/paste.cpp +++ b/src/widgets/paste.cpp @@ -149,13 +149,14 @@ static QByteArray chooseFormatAndUrl(const QUrl &u, dialogText = i18n("Filename for clipboard content:"); } - KIO::PasteDialog dlg(QString(), dialogText, suggestedFileName, formatLabels, widget, clipboard); + KIO::PasteDialog dlg(QString(), dialogText, suggestedFileName, formatLabels, widget); if (dlg.exec() != QDialog::Accepted) { return QByteArray(); } - if (clipboard && dlg.clipboardChanged()) { + const QString chosenFormat = formats[dlg.comboItem()]; + if (clipboard && !qApp->clipboard()->mimeData()->hasFormat(chosenFormat)) { KMessageBox::sorry(widget, i18n("The clipboard has changed since you used 'paste': " "the chosen data format is no longer applicable. " @@ -164,7 +165,6 @@ static QByteArray chooseFormatAndUrl(const QUrl &u, } const QString result = dlg.lineEditText(); - const QString chosenFormat = formats[dlg.comboItem()]; // qDebug() << " result=" << result << " chosenFormat=" << chosenFormat; *newUrl = u; diff --git a/src/widgets/pastedialog.cpp b/src/widgets/pastedialog.cpp index d74dbcfb3..b8571aaed 100644 --- a/src/widgets/pastedialog.cpp +++ b/src/widgets/pastedialog.cpp @@ -17,7 +17,7 @@ #include #include -KIO::PasteDialog::PasteDialog(const QString &caption, const QString &label, const QString &value, const QStringList &items, QWidget *parent, bool clipboard) +KIO::PasteDialog::PasteDialog(const QString &caption, const QString &label, const QString &value, const QStringList &items, QWidget *parent) : QDialog(parent) { setWindowTitle(caption); @@ -54,16 +54,6 @@ KIO::PasteDialog::PasteDialog(const QString &caption, const QString &label, cons topLayout->addWidget(buttonBox); setMinimumWidth(350); - - m_clipboardChanged = false; - if (clipboard) { - connect(QApplication::clipboard(), &QClipboard::dataChanged, this, &PasteDialog::slotClipboardDataChanged); - } -} - -void KIO::PasteDialog::slotClipboardDataChanged() -{ - m_clipboardChanged = true; } QString KIO::PasteDialog::lineEditText() const diff --git a/src/widgets/pastedialog_p.h b/src/widgets/pastedialog_p.h index 2386fc6e5..c4940febe 100644 --- a/src/widgets/pastedialog_p.h +++ b/src/widgets/pastedialog_p.h @@ -24,23 +24,15 @@ class PasteDialog : public QDialog { Q_OBJECT public: - PasteDialog(const QString &caption, const QString &label, const QString &value, const QStringList &items, QWidget *parent, bool clipboard); + PasteDialog(const QString &caption, const QString &label, const QString &value, const QStringList &items, QWidget *parent); QString lineEditText() const; int comboItem() const; - bool clipboardChanged() const - { - return m_clipboardChanged; - } - -private Q_SLOTS: - void slotClipboardDataChanged(); private: QLabel *m_label; QLineEdit *m_lineEdit; QComboBox *m_comboBox; - bool m_clipboardChanged; }; } // namespace -- GitLab