summaryrefslogtreecommitdiff
path: root/kde-frameworks/kio/files/kio-5.113.0-fix-crash-while-copying.patch
diff options
context:
space:
mode:
Diffstat (limited to 'kde-frameworks/kio/files/kio-5.113.0-fix-crash-while-copying.patch')
-rw-r--r--kde-frameworks/kio/files/kio-5.113.0-fix-crash-while-copying.patch184
1 files changed, 184 insertions, 0 deletions
diff --git a/kde-frameworks/kio/files/kio-5.113.0-fix-crash-while-copying.patch b/kde-frameworks/kio/files/kio-5.113.0-fix-crash-while-copying.patch
new file mode 100644
index 000000000000..845e6bc64339
--- /dev/null
+++ b/kde-frameworks/kio/files/kio-5.113.0-fix-crash-while-copying.patch
@@ -0,0 +1,184 @@
+From 6bea074739d5a75920d5540bc266549df5642511 Mon Sep 17 00:00:00 2001
+From: Akseli Lahtinen <akselmo@akselmo.dev>
+Date: Fri, 1 Dec 2023 11:27:26 +0000
+Subject: [PATCH] WidgetsAskUserActionHandler: Use QPointer to check the
+ validity of parent widgets
+
+If Dolphin is closed during the copying process,
+and the overwrite/skip dialog appears,
+this crashes the copying process since the
+parent shows to faulty location.
+
+Use QPointer to check that the parent widgets are still
+valid. If not, we just use nullptr, and the dialogs
+will still open.
+
+This also cleans some repetition in code.
+
+BUG:448532
+(cherry picked from commit bdef648edd54e146c30e881d8eb95990a59c5bbc)
+---
+ src/widgets/widgetsaskuseractionhandler.cpp | 90 +++++++++------------
+ 1 file changed, 39 insertions(+), 51 deletions(-)
+
+diff --git a/src/widgets/widgetsaskuseractionhandler.cpp b/src/widgets/widgetsaskuseractionhandler.cpp
+index fe2975d0ce..9cbaaec99f 100644
+--- a/src/widgets/widgetsaskuseractionhandler.cpp
++++ b/src/widgets/widgetsaskuseractionhandler.cpp
+@@ -22,6 +22,7 @@
+
+ #include <QApplication>
+ #include <QDialogButtonBox>
++#include <QPointer>
+ #include <QRegularExpression>
+ #include <QUrl>
+
+@@ -40,7 +41,10 @@
+ void savePersistentUserReply(KIO::AskUserActionInterface::MessageDialogType type, KConfigGroup &cg, const QString &dontAskAgainName, int result);
+
+ WidgetsAskUserActionHandler *const q;
+- QWidget *m_parentWidget = nullptr;
++ QPointer<QWidget> m_parentWidget = nullptr;
++
++ QWidget *getParentWidget(KJob *job);
++ QWidget *getParentWidget(QWidget *widget);
+ };
+
+ bool KIO::WidgetsAskUserActionHandlerPrivate::gotPersistentUserReply(KIO::AskUserActionInterface::MessageDialogType type,
+@@ -106,6 +110,36 @@
+ }
+ }
+
++QWidget *KIO::WidgetsAskUserActionHandlerPrivate::getParentWidget(KJob *job)
++{
++ // This needs to be in qpointer, otherwise copying process
++ // will crash if done in background and dolphin is closed
++ QPointer<QWidget> parentWidget = nullptr;
++
++ if (job) {
++ parentWidget = KJobWidgets::window(job);
++ }
++
++ return getParentWidget(parentWidget);
++}
++
++QWidget *KIO::WidgetsAskUserActionHandlerPrivate::getParentWidget(QWidget *widget)
++{
++ // This needs to be in qpointer, otherwise copying process
++ // will crash if done in background and dolphin is closed
++ QPointer<QWidget> parentWidget = widget;
++
++ if (!parentWidget) {
++ parentWidget = this->m_parentWidget;
++ }
++
++ if (!parentWidget) {
++ parentWidget = qApp->activeWindow();
++ }
++
++ return parentWidget;
++}
++
+ KIO::WidgetsAskUserActionHandler::WidgetsAskUserActionHandler(QObject *parent)
+ : KIO::AskUserActionInterface(parent)
+ , d(new WidgetsAskUserActionHandlerPrivate(this))
+@@ -128,22 +162,8 @@
+ const QDateTime &mtimeSrc,
+ const QDateTime &mtimeDest)
+ {
+- QWidget *parentWidget = nullptr;
+-
+- if (job) {
+- parentWidget = KJobWidgets::window(job);
+- }
+-
+- if (!parentWidget) {
+- parentWidget = d->m_parentWidget;
+- }
+-
+- if (!parentWidget) {
+- parentWidget = qApp->activeWindow();
+- }
+-
+ QMetaObject::invokeMethod(qGuiApp, [=] {
+- auto *dlg = new KIO::RenameDialog(parentWidget, title, src, dest, options, sizeSrc, sizeDest, ctimeSrc, ctimeDest, mtimeSrc, mtimeDest);
++ auto *dlg = new KIO::RenameDialog(d->getParentWidget(job), title, src, dest, options, sizeSrc, sizeDest, ctimeSrc, ctimeDest, mtimeSrc, mtimeDest);
+
+ dlg->setAttribute(Qt::WA_DeleteOnClose);
+ dlg->setWindowModality(Qt::WindowModal);
+@@ -161,22 +181,8 @@
+
+ void KIO::WidgetsAskUserActionHandler::askUserSkip(KJob *job, KIO::SkipDialog_Options options, const QString &errorText)
+ {
+- QWidget *parentWidget = nullptr;
+-
+- if (job) {
+- parentWidget = KJobWidgets::window(job);
+- }
+-
+- if (!parentWidget) {
+- parentWidget = d->m_parentWidget;
+- }
+-
+- if (!parentWidget) {
+- parentWidget = qApp->activeWindow();
+- }
+-
+ QMetaObject::invokeMethod(qGuiApp, [=] {
+- auto *dlg = new KIO::SkipDialog(parentWidget, options, errorText);
++ auto *dlg = new KIO::SkipDialog(d->getParentWidget(job), options, errorText);
+ dlg->setAttribute(Qt::WA_DeleteOnClose);
+ dlg->setWindowModality(Qt::WindowModal);
+
+@@ -373,16 +379,6 @@
+ return;
+ }
+
+- QWidget *parentWidget = parent;
+-
+- if (!parentWidget) {
+- parentWidget = d->m_parentWidget;
+- }
+-
+- if (!parentWidget) {
+- parentWidget = qApp->activeWindow();
+- }
+-
+ const KGuiItem primaryActionButton(primaryActionText, primaryActionIconName);
+ const KGuiItem secondaryActionButton(secondaryActionText, secondaryActionIconName);
+
+@@ -412,7 +408,7 @@
+ hasCancelButton = true;
+ break;
+ case AskUserActionInterface::SSLMessageBox:
+- d->sslMessageBox(text, metaData, parentWidget);
++ d->sslMessageBox(text, metaData, d->getParentWidget(parent));
+ return;
+ case AskUserActionInterface::Information:
+ dlgType = KMessageDialog::Information;
+@@ -442,7 +438,7 @@
+
+ QMetaObject::invokeMethod(qGuiApp, [=]() {
+ auto cancelButton = hasCancelButton ? KStandardGuiItem::cancel() : KGuiItem();
+- auto *dialog = new KMessageDialog(dlgType, text, parentWidget);
++ auto *dialog = new KMessageDialog(dlgType, text, d->getParentWidget(parent));
+
+ dialog->setAttribute(Qt::WA_DeleteOnClose);
+ dialog->setCaption(title);
+@@ -492,15 +488,7 @@
+
+ void KIO::WidgetsAskUserActionHandlerPrivate::sslMessageBox(const QString &text, const KIO::MetaData &metaData, QWidget *parent)
+ {
+- QWidget *parentWidget = parent;
+-
+- if (!parentWidget) {
+- parentWidget = m_parentWidget;
+- }
+-
+- if (!parentWidget) {
+- parentWidget = qApp->activeWindow();
+- }
++ QWidget *parentWidget = getParentWidget(parent);
+
+ const QStringList sslList = metaData.value(QStringLiteral("ssl_peer_chain")).split(QLatin1Char('\x01'), Qt::SkipEmptyParts);
+