summaryrefslogtreecommitdiff
blob: 148825d496d00a775a166ee10a06ae574428209e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
commit 87b27476cc8a3865994da066ce06a3e836462719
Author: Albert Astals Cid <aacid@kde.org>
Date:   Sat Dec 31 11:55:43 2016 +0100

    Fix regression in which the Save dialog appears as an Open dialog
    
    7bbbd93cd3fc0abdffd3fa7f144cb50a33fafad9 makes the save dialog appear as Open dialog.
    
    Simplify the code in that commit so it does not regress anymore.
    
    Comes with a unit test
    
    New test fails without the patch, works with it. Kate Save As dialog no longer shows as Open dialog.
    
    REVIEW: 129732

diff --git a/autotests/kfiledialog_unittest.cpp b/autotests/kfiledialog_unittest.cpp
index 47a5543..d53c7e3 100644
--- a/autotests/kfiledialog_unittest.cpp
+++ b/autotests/kfiledialog_unittest.cpp
@@ -95,6 +95,29 @@ private Q_SLOTS:
         QCOMPARE(dialog.directoryUrl(), directoryUrl);
     }
 
+    void testGetSaveFileUrl()
+    {
+        QObject lambdaGuard;
+        QTemporaryFile tempFile(QDir::tempPath()+"/kfiledialogtest_XXXXXX");
+        tempFile.open();
+        const QString tempName = tempFile.fileName();
+        const QUrl url = QUrl::fromLocalFile(tempName);
+
+        // Need to use a lambda and not just QTest::qWaitForWindowExposed();
+        // because with the static getSaveFileUrl we do not have access
+        // to the QFileDialog object, so instead we hook to a signal
+        KFileWidget::OperationMode saveFileOperationMode = KFileWidget::Other;
+        connect(qApp, &QGuiApplication::focusWindowChanged, &lambdaGuard, [&saveFileOperationMode] {
+            KFileWidget *fileWidget = findFileWidget();
+            saveFileOperationMode = fileWidget->operationMode();
+            qApp->activeWindow()->close();
+        });
+
+        QFileDialog::getSaveFileUrl(0, QString(), url);
+
+        QCOMPARE(saveFileOperationMode, KFileWidget::Saving);
+    }
+
     void testViewMode()
     {
         // Open a file dialog, and change view mode to tree
diff --git a/src/platformtheme/kdeplatformfiledialoghelper.cpp b/src/platformtheme/kdeplatformfiledialoghelper.cpp
index 990b983..05cfe35 100644
--- a/src/platformtheme/kdeplatformfiledialoghelper.cpp
+++ b/src/platformtheme/kdeplatformfiledialoghelper.cpp
@@ -365,15 +365,7 @@ void KDEPlatformFileDialogHelper::selectFile(const QUrl &filename)
     // Qt 5 at least <= 5.8.0 does not derive the directory from the passed url
     // and set the initialDirectory option accordingly, also not for known schemes
     // like file://, so we have to do it ourselves
-
-    // Syntax-wise we have to use a copy ctor until Qt 5.7.x and clone() since Qt 5.8.
-#if QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
-    QSharedPointer<QFileDialogOptions> opt(new QFileDialogOptions(*options()));
-#else
-    auto opt = options()->clone();
-#endif
-    opt->setInitialDirectory(m_dialog->directory());
-    setOptions(opt);
+    options()->setInitialDirectory(m_dialog->directory());
 }
 
 void KDEPlatformFileDialogHelper::setDirectory(const QUrl &directory)