diff --git a/src/platformtheme/kdeplatformtheme.cpp b/src/platformtheme/kdeplatformtheme.cpp index 8e99b69..c6e5c4f 100644 --- a/src/platformtheme/kdeplatformtheme.cpp +++ b/src/platformtheme/kdeplatformtheme.cpp @@ -1,315 +1,331 @@ /* This file is part of the KDE libraries * Copyright 2013 Kevin Ottens * Copyright 2013 Aleix Pol Gonzalez * Copyright 2014 Lukáš Tinkl * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include "kdeplatformtheme.h" #include "kfontsettingsdata.h" #include "khintssettings.h" #include "kdeplatformfiledialoghelper.h" #include "kdeplatformsystemtrayicon.h" #include "platformtheme_logging.h" #include #include #include #include #include #include #include #include #include #include #include #include #include KdePlatformTheme::KdePlatformTheme() { m_fontsData = Q_NULLPTR; m_hints = Q_NULLPTR; loadSettings(); QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, false); + setQtQuickControlsTheme(); } KdePlatformTheme::~KdePlatformTheme() { delete m_fontsData; delete m_hints; } QVariant KdePlatformTheme::themeHint(QPlatformTheme::ThemeHint hintType) const { QVariant hint = m_hints->hint(hintType); if (hint.isValid()) { return hint; } else { return QPlatformTheme::themeHint(hintType); } } QIcon KdePlatformTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions) const { if (iconOptions.testFlag(DontUseCustomDirectoryIcons) && fileInfo.isDir()) { qCWarning(PLATFORMTHEME) << Q_FUNC_INFO << "icon \"inode-directory\""; return QIcon::fromTheme(QLatin1String("inode-directory")); } qCWarning(PLATFORMTHEME) << Q_FUNC_INFO << "file:" << fileInfo.absoluteFilePath() << "icon:" << KIO::iconNameForUrl(QUrl::fromLocalFile(fileInfo.absoluteFilePath())); return QIcon::fromTheme(KIO::iconNameForUrl(QUrl::fromLocalFile(fileInfo.absoluteFilePath()))); } #if QT_VERSION < QT_VERSION_CHECK(5, 8, 0) QPixmap KdePlatformTheme::fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &size, QPlatformTheme::IconOptions iconOptions) const { return fileIcon(fileInfo, iconOptions).pixmap(size.toSize(), QIcon::Normal); } #endif const QPalette *KdePlatformTheme::palette(Palette type) const { QPalette *palette = m_hints->palette(type); if (palette) { return palette; } else { return QPlatformTheme::palette(type); } } KFontSettingsData::FontTypes KdePlatformTheme::fontType(Font type) const { KFontSettingsData::FontTypes fdtype; switch (type) { case SystemFont: fdtype = KFontSettingsData::GeneralFont; break; case MenuFont: case MenuBarFont: case MenuItemFont: fdtype = KFontSettingsData::MenuFont; break; case MessageBoxFont: case LabelFont: case TipLabelFont: case StatusBarFont: case PushButtonFont: case ItemViewFont: case ListViewFont: case HeaderViewFont: case ListBoxFont: case ComboMenuItemFont: case ComboLineEditFont: fdtype = KFontSettingsData::GeneralFont; break; case TitleBarFont: case MdiSubWindowTitleFont: case DockWidgetTitleFont: fdtype = KFontSettingsData::WindowTitleFont; break; case SmallFont: case MiniFont: fdtype = KFontSettingsData::SmallestReadableFont; break; case FixedFont: fdtype = KFontSettingsData::FixedFont; break; case ToolButtonFont: fdtype = KFontSettingsData::ToolbarFont; break; default: fdtype = KFontSettingsData::GeneralFont; break; } return fdtype; } const QFont *KdePlatformTheme::font(Font type) const { return m_fontsData->font(fontType(type)); } QIconEngine *KdePlatformTheme::createIconEngine(const QString &iconName) const { return new KIconEngine(iconName, KIconLoader::global()); } void KdePlatformTheme::loadSettings() { if (!m_fontsData) { m_fontsData = new KFontSettingsData; m_hints = new KHintsSettings; } } QList KdePlatformTheme::keyBindings(QKeySequence::StandardKey key) const { switch (key) { case QKeySequence::HelpContents: return KStandardShortcut::shortcut(KStandardShortcut::Help); case QKeySequence::WhatsThis: return KStandardShortcut::shortcut(KStandardShortcut::WhatsThis); case QKeySequence::Open: return KStandardShortcut::shortcut(KStandardShortcut::Open); case QKeySequence::Close: return KStandardShortcut::shortcut(KStandardShortcut::Close); case QKeySequence::Save: return KStandardShortcut::shortcut(KStandardShortcut::Save); case QKeySequence::New: return KStandardShortcut::shortcut(KStandardShortcut::New); case QKeySequence::Cut: return KStandardShortcut::shortcut(KStandardShortcut::Cut); case QKeySequence::Copy: return KStandardShortcut::shortcut(KStandardShortcut::Copy); case QKeySequence::Paste: return KStandardShortcut::shortcut(KStandardShortcut::Paste); case QKeySequence::Undo: return KStandardShortcut::shortcut(KStandardShortcut::Undo); case QKeySequence::Redo: return KStandardShortcut::shortcut(KStandardShortcut::Redo); case QKeySequence::Back: return KStandardShortcut::shortcut(KStandardShortcut::Back); case QKeySequence::Forward: return KStandardShortcut::shortcut(KStandardShortcut::Forward); case QKeySequence::Refresh: return KStandardShortcut::shortcut(KStandardShortcut::Reload); case QKeySequence::ZoomIn: return KStandardShortcut::shortcut(KStandardShortcut::ZoomIn); case QKeySequence::ZoomOut: return KStandardShortcut::shortcut(KStandardShortcut::ZoomOut); case QKeySequence::Print: return KStandardShortcut::shortcut(KStandardShortcut::Print); case QKeySequence::Find: return KStandardShortcut::shortcut(KStandardShortcut::Find); case QKeySequence::FindNext: return KStandardShortcut::shortcut(KStandardShortcut::FindNext); case QKeySequence::FindPrevious: return KStandardShortcut::shortcut(KStandardShortcut::FindPrev); case QKeySequence::Replace: return KStandardShortcut::shortcut(KStandardShortcut::Replace); case QKeySequence::SelectAll: return KStandardShortcut::shortcut(KStandardShortcut::SelectAll); case QKeySequence::MoveToNextWord: return KStandardShortcut::shortcut(KStandardShortcut::ForwardWord); case QKeySequence::MoveToPreviousWord: return KStandardShortcut::shortcut(KStandardShortcut::BackwardWord); case QKeySequence::MoveToNextPage: return KStandardShortcut::shortcut(KStandardShortcut::Next); case QKeySequence::MoveToPreviousPage: return KStandardShortcut::shortcut(KStandardShortcut::Prior); case QKeySequence::MoveToStartOfLine: return KStandardShortcut::shortcut(KStandardShortcut::BeginningOfLine); case QKeySequence::MoveToEndOfLine: return KStandardShortcut::shortcut(KStandardShortcut::EndOfLine); case QKeySequence::MoveToStartOfDocument: return KStandardShortcut::shortcut(KStandardShortcut::Begin); case QKeySequence::MoveToEndOfDocument: return KStandardShortcut::shortcut(KStandardShortcut::End); case QKeySequence::SaveAs: return KStandardShortcut::shortcut(KStandardShortcut::SaveAs); case QKeySequence::Preferences: return KStandardShortcut::shortcut(KStandardShortcut::Preferences); case QKeySequence::Quit: return KStandardShortcut::shortcut(KStandardShortcut::Quit); case QKeySequence::FullScreen: return KStandardShortcut::shortcut(KStandardShortcut::FullScreen); case QKeySequence::Deselect: return KStandardShortcut::shortcut(KStandardShortcut::Deselect); case QKeySequence::DeleteStartOfWord: return KStandardShortcut::shortcut(KStandardShortcut::DeleteWordBack); case QKeySequence::DeleteEndOfWord: return KStandardShortcut::shortcut(KStandardShortcut::DeleteWordForward); case QKeySequence::NextChild: return KStandardShortcut::shortcut(KStandardShortcut::TabNext); case QKeySequence::PreviousChild: return KStandardShortcut::shortcut(KStandardShortcut::TabPrev); default: return QPlatformTheme::keyBindings(key); } } bool KdePlatformTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const { return type == QPlatformTheme::FileDialog; } QString KdePlatformTheme::standardButtonText(int button) const { switch (static_cast(button)) { case QPlatformDialogHelper::NoButton: qCWarning(PLATFORMTHEME) << Q_FUNC_INFO << "Unsupported standard button:" << button; return QString(); case QPlatformDialogHelper::Ok: return KStandardGuiItem::ok().text(); case QPlatformDialogHelper::Save: return KStandardGuiItem::save().text(); case QPlatformDialogHelper::SaveAll: return i18nc("@action:button", "Save All"); case QPlatformDialogHelper::Open: return KStandardGuiItem::open().text(); case QPlatformDialogHelper::Yes: return KStandardGuiItem::yes().text(); case QPlatformDialogHelper::YesToAll: return i18nc("@action:button", "Yes to All"); case QPlatformDialogHelper::No: return KStandardGuiItem::no().text(); case QPlatformDialogHelper::NoToAll: return i18nc("@action:button", "No to All"); case QPlatformDialogHelper::Abort: // FIXME KStandardGuiItem::stop() doesn't seem right here return i18nc("@action:button", "Abort"); case QPlatformDialogHelper::Retry: return i18nc("@action:button", "Retry"); case QPlatformDialogHelper::Ignore: return i18nc("@action:button", "Ignore"); case QPlatformDialogHelper::Close: return KStandardGuiItem::close().text(); case QPlatformDialogHelper::Cancel: return KStandardGuiItem::cancel().text(); case QPlatformDialogHelper::Discard: return KStandardGuiItem::discard().text(); case QPlatformDialogHelper::Help: return KStandardGuiItem::help().text(); case QPlatformDialogHelper::Apply: return KStandardGuiItem::apply().text(); case QPlatformDialogHelper::Reset: return KStandardGuiItem::reset().text(); case QPlatformDialogHelper::RestoreDefaults: return KStandardGuiItem::defaults().text(); default: return QPlatformTheme::defaultStandardButtonText(button); } } QPlatformDialogHelper *KdePlatformTheme::createPlatformDialogHelper(QPlatformTheme::DialogType type) const { switch (type) { case QPlatformTheme::FileDialog: return new KDEPlatformFileDialogHelper; case QPlatformTheme::FontDialog: case QPlatformTheme::ColorDialog: case QPlatformTheme::MessageDialog: default: return 0; } } QPlatformSystemTrayIcon *KdePlatformTheme::createPlatformSystemTrayIcon() const { return new KDEPlatformSystemTrayIcon; } + +//force QtQuickControls2 to use the desktop theme as default +void KdePlatformTheme::setQtQuickControlsTheme() +{ + //if the user has explicitly set something else, don't meddle + if (qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_STYLE")) { + return; + } + //if the user is running only a QGuiApplication. Abort as this style is all about QWidgets and we know setting this will make it crash + if (!qobject_cast(qApp)) { + return; + } + qputenv("QT_QUICK_CONTROLS_STYLE", "org.kde.desktop"); +} + diff --git a/src/platformtheme/kdeplatformtheme.h b/src/platformtheme/kdeplatformtheme.h index 53f9958..923037b 100644 --- a/src/platformtheme/kdeplatformtheme.h +++ b/src/platformtheme/kdeplatformtheme.h @@ -1,72 +1,73 @@ /* This file is part of the KDE libraries * Copyright 2013 Kevin Ottens * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KDEPLATFORMTHEME_H #define KDEPLATFORMTHEME_H #include #include "kfontsettingsdata.h" #include #include #include class KHintsSettings; class QIconEngine; class KdePlatformTheme : public QPlatformTheme { public: KdePlatformTheme(); ~KdePlatformTheme(); QVariant themeHint(ThemeHint hint) const override; #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions) const override; #else QPixmap fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &size, QPlatformTheme::IconOptions iconOptions) const override; // this will be the implementation QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions) const; #endif const QPalette *palette(Palette type = SystemPalette) const override; const QFont *font(Font type) const override; QIconEngine *createIconEngine(const QString &iconName) const override; QList keyBindings(QKeySequence::StandardKey key) const override; QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const override; bool usePlatformNativeDialog(DialogType type) const override; QString standardButtonText(int button) const override; QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const override; protected: void loadSettings(); + void setQtQuickControlsTheme(); KFontSettingsData::FontTypes fontType(Font type) const; private: KHintsSettings *m_hints; KFontSettingsData *m_fontsData; }; #endif // KDEPLATFORMTHEME_H diff --git a/src/platformtheme/plintegration-cumpatch1.diff b/src/platformtheme/plintegration-cumpatch1.diff index b727430..ba4c9ab 100644 --- a/src/platformtheme/plintegration-cumpatch1.diff +++ b/src/platformtheme/plintegration-cumpatch1.diff @@ -1,335 +1,336 @@ We were forked off frameworkintegration around the time that plasma-integration was also split off that framework. This file lists potentially relevant changes from plasma-integration's creation (c0ffbc2d87f7711b660d80a70b2c422a9152392e) until f33d00ef1321b96395ed4007df1d10b451d5ce5f (20170320) 20171129: merging plasma-integration commits (in reverse order): 0a6be721e4e35b54c2fba6a59243eea3c5d912d4 Implement support for selected mime type filters 7a7dfffba98d383821c39ac68de6e8aabe45b7ed Implement QPlatformTheme::fileIconPixmap() to make QFileIconProvider work. 4aef17e64f564331c79d5307dd6aeded828bf382 Replace Q_DECL_OVERRIDE with override f25c5e10d0235c2d383e998bddc39fb35517ce9e Fix deprecation warnings. setSelection -> setSelectedUrl ui -> uiDelegate 0dafb9403266d6064074250d44b74dc0db946cfb Make sure we always set a default mime filter in save mode 4be9b478e5296914258b77eb02c2583ee0e84c7c Allow to disable blinking cursor completely 267e7c635733031d2990e78637cf6c10a56f9f05 Don't ignore initially selected mime type filter b0059b1c8342b5ef95b054a0a5081b5db7e1c7bb Middle-click on QSystemTrayIcon сauses context menu 1b21b5977c2068c5bd30c9f9f641f60bdba9ea8e Also specify a default StyleName for fonts 2434bafcb168467f6763a20226918d27afa26744 [KHintsSettings] Update AA_DontShowIconsInMenus at runtime 86be8d49d8988fb6c35e847ed9e0aad3e8514208 Allow to change toolbar font separately again f9e5b852faa78f6d67615ea3c435b10b393cdaa5 Add ~/.local/share/icons to icons search paths +1781d60b230c32977c078e2943d94c506d7ee645 Set QtQuickControls theme in QPT 20170425: synced with the following plasma-integration commits (everything related to QDbusMenuBar is irrelevant on Mac): Fix warning when no initial directory is set. (7bca66673f9575083181ca1b0a9602ba077c9016) [KHintsSettings] Emit QGuiApplication::paletteChanged when run as QApplication (ab3298b3f5f728765d5afa8830aa7793140617c8) Do not treat filename in selection as URL (e70f8134a2bc4b3647e245c05f469aeed462a246) Use the native dialog if there's no QApplication (c6305f5edbbd15244d79cfc7569352cf6f6ea4d6) (in KdeMacTheme::usePlatformNativeDialog()) 20170119: synced, among others with the current version of these plasma-integration commits: 8fefab22498c15643e87ae104ef1d5fbfef8f539 Mon Sep 17 00:00:00 2001 7bbbd93cd3fc0abdffd3fa7f144cb50a33fafad9 Mon Sep 17 00:00:00 2001 ### Done: diff --git a/src/platformtheme/kdeplatformfiledialoghelper.cpp b/src/platformtheme/kdeplatformfiledialoghelper.cpp index 139c35d..15b5e90 100644 --- a/src/platformtheme/kdeplatformfiledialoghelper.cpp +++ b/src/platformtheme/kdeplatformfiledialoghelper.cpp @@ -288,6 +288,8 @@ void KDEPlatformFileDialogHelper::initializeDialog() // overwrite option if (options()->testOption(QFileDialogOptions::FileDialogOption::DontConfirmOverwrite)) { dialog->m_fileWidget->setConfirmOverwrite(false); + } else if (options()->acceptMode() == QFileDialogOptions::AcceptSave) { + dialog->m_fileWidget->setConfirmOverwrite(true); } } } @@ -328,11 +330,11 @@ void KDEPlatformFileDialogHelper::restoreSize() bool KDEPlatformFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) { - Q_UNUSED(parent) initializeDialog(); m_dialog->setWindowFlags(windowFlags); m_dialog->setWindowModality(windowModality); restoreSize(); + m_dialog->windowHandle()->setTransientParent(parent); // Use a delayed show here to delay show() after the internal Qt invisible QDialog. // The delayed call shouldn't matter, because for other "real" native QPlatformDialog // implementation like Mac and Windows, the native dialog is not necessarily diff --git a/src/platformtheme/khintssettings.cpp b/src/platformtheme/khintssettings.cpp index edbed5f..7768a1c 100644 --- a/src/platformtheme/khintssettings.cpp +++ b/src/platformtheme/khintssettings.cpp @@ -375,12 +375,6 @@ void KHintsSettings::loadPalettes() return; } - path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("plasma/look-and-feel/org.kde.loonandfeel/contents/colors")); - if (!path.isEmpty()) { - m_palettes[QPlatformTheme::SystemPalette] = new QPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig(path))); - return; - } - const QString scheme = readConfigValue(QStringLiteral("General"), QStringLiteral("ColorScheme"), QStringLiteral("Breeze")).toString(); path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("color-schemes/") + scheme + QStringLiteral(".colors")); diff --git not done ### ### not done: There is little point changing the default fixed font in kfontsettingsdata.cpp (from Oxygen Mono to Hack); it's overridden in kfontsettingsdatamac.m (Monaco is close enough to Hack but still more elegant; has true Italic instead of an improved slanted (Oblique) mode. diff --git a/autotests/kfiledialog_unittest.cpp b/autotests/kfiledialog_unittest.cpp index 59915da..b32cd8e 100644 --- a/autotests/kfiledialog_unittest.cpp +++ b/autotests/kfiledialog_unittest.cpp @@ -19,6 +19,9 @@ */ #include +#include +#include +#include #include #include #include @@ -200,7 +203,61 @@ private Q_SLOTS: QCOMPARE(dialog.fileMode(), qtFileMode); } + + void testSaveOverwrite_data() + { + QTest::addColumn("qtOverwriteOption"); + QTest::addColumn("messageBoxExpected"); + QTest::newRow("checkoverwrite") << false << true; + QTest::newRow("allowoverwrite") << true << false; + } + + void testSaveOverwrite() + { + QFETCH(bool, qtOverwriteOption); + QFETCH(bool, messageBoxExpected); + + QTemporaryFile tempFile(QDir::tempPath()+"/kfiledialogtest_XXXXXX"); + tempFile.setAutoRemove(true); + tempFile.open(); + QString tempName = tempFile.fileName(); + tempFile.close(); + int idx = tempName.lastIndexOf('/'); + + QFileDialog dialog; + dialog.setAcceptMode(QFileDialog::AcceptSave); + if (qtOverwriteOption) dialog.setOption(QFileDialog::DontConfirmOverwrite); + dialog.setDirectory(tempName.left(idx+1)); + dialog.selectFile(tempName.mid(idx+1)); + dialog.open(); + + KFileWidget *fw = findFileWidget(); + QVERIFY(fw); + QTest::qWaitForWindowExposed(fw->window()); + QCOMPARE(fw->isVisible(), true); + + messageBoxSeen = false; + QTimer::singleShot(500, this, SLOT(checkMessageBox())); + fw->slotOk(); + + fw->slotCancel(); + QVERIFY(messageBoxSeen == messageBoxExpected); + } + +protected Q_SLOTS: + void checkMessageBox() + { + QDialog *msgbox = findMessageBox(); + if (!msgbox) return; + QTest::qWaitForWindowExposed(msgbox); + QCOMPARE(msgbox->isVisible(), true); + messageBoxSeen = true; + msgbox->close(); + } + private: + bool messageBoxSeen; + static QString fileViewToString(KFile::FileView fv) { switch (fv) { @@ -230,6 +287,18 @@ private: Q_ASSERT(widgets.count() == 1); return (widgets.count() == 1) ? widgets.first() : Q_NULLPTR; } + + static QDialog *findMessageBox() + { + QList widgets; + foreach (QWidget *widget, QApplication::topLevelWidgets()) { + QDialog *dlg = widget->findChild(); + if (dlg) { + widgets.append(dlg); + } + } + return (widgets.count() == 1) ? widgets.first() : Q_NULLPTR; + } }; QTEST_MAIN(KFileDialog_UnitTest) diff --git a/src/platformtheme/kfontsettingsdata.cpp b/src/platformtheme/kfontsettingsdata.cpp index a43e8be..d3f8fe3 100644 --- a/src/platformtheme/kfontsettingsdata.cpp +++ b/src/platformtheme/kfontsettingsdata.cpp @@ -54,7 +54,7 @@ static const char DefaultFont[] = "Noto Sans"; static const KFontData DefaultFontData[KFontSettingsData::FontTypesCount] = { { GeneralId, "font", DefaultFont, 10, -1, QFont::SansSerif }, - { GeneralId, "fixed", "Oxygen Mono", 9, -1, QFont::Monospace }, + { GeneralId, "fixed", "Hack", 9, -1, QFont::Monospace }, { GeneralId, "toolBarFont", DefaultFont, 9, -1, QFont::SansSerif }, { GeneralId, "menuFont", DefaultFont, 10, -1, QFont::SansSerif }, { "WM", "activeFont", DefaultFont, 10, -1, QFont::SansSerif }, diff --git a/tests/qfiledialogtest.cpp b/tests/qfiledialogtest.cpp index 1d69ea1..329eabf 100644 --- a/tests/qfiledialogtest.cpp +++ b/tests/qfiledialogtest.cpp @@ -31,6 +31,8 @@ int main(int argc, char **argv) parser.addHelpOption(); parser.addOption(QCommandLineOption(QStringList(QStringLiteral("staticFunction")), QStringLiteral("Test one of the static convenience function: 'getOpenFileUrl', 'getExistingDirectory'"), QStringLiteral("function name"))); parser.addOption(QCommandLineOption(QStringList(QStringLiteral("acceptMode")), QStringLiteral("File dialog acceptMode: 'open' or 'save'"), QStringLiteral("type"), QStringLiteral("open"))); + parser.addOption(QCommandLineOption(QStringList(QStringLiteral("confirmOverwrite")), QStringLiteral("Test overwrite option: 'on' or 'off'"), QStringLiteral("option"), QStringLiteral("on"))); + parser.addOption(QCommandLineOption(QStringList(QStringLiteral("nativeDialog")), QStringLiteral("Use the platform native dialog: 'on' or 'off'"), QStringLiteral("option"), QStringLiteral("on"))); parser.addOption(QCommandLineOption(QStringList(QStringLiteral("fileMode")), QStringLiteral("File dialog fileMode: 'AnyFile' or 'ExistingFile' or 'Directory' or 'ExistingFiles'"), QStringLiteral("type"))); parser.addOption(QCommandLineOption(QStringList(QStringLiteral("nameFilter")), QStringLiteral("Dialog nameFilter, e. g. 'cppfiles (*.cpp *.h *.hpp)', can be specified multiple times"), QStringLiteral("nameFilter"), QStringLiteral("Everything (*)"))); // add option mimeTypeFilter later @@ -83,6 +85,14 @@ int main(int argc, char **argv) dialog.selectNameFilter(selectNameFilter); } + if (parser.value(QStringLiteral("confirmOverwrite")) == QStringLiteral("off")) { + dialog.setOption(QFileDialog::DontConfirmOverwrite, true); + } + + if (parser.value(QStringLiteral("nativeDialog")) == QStringLiteral("off")) { + dialog.setOption(QFileDialog::DontUseNativeDialog, true); + } + dialog.setDirectory(parser.value(QStringLiteral("selectDirectory"))); dialog.selectFile(parser.value(QStringLiteral("selectFile"))); From 8fefab22498c15643e87ae104ef1d5fbfef8f539 Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 23 Dec 2016 15:46:41 +0100 Subject: [PATCH] Fix compilation with Qt 5.8. --- src/platformtheme/kdeplatformfiledialoghelper.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/platformtheme/kdeplatformfiledialoghelper.cpp b/src/platformtheme/kdeplatformfiledialoghelper.cpp index 7e7e2e9..990b983 100644 --- a/src/platformtheme/kdeplatformfiledialoghelper.cpp +++ b/src/platformtheme/kdeplatformfiledialoghelper.cpp @@ -365,7 +365,13 @@ 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 opt(new QFileDialogOptions(*options())); +#else + auto opt = options()->clone(); +#endif opt->setInitialDirectory(m_dialog->directory()); setOptions(opt); } -- 2.11.0 From 7bbbd93cd3fc0abdffd3fa7f144cb50a33fafad9 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Thu, 22 Dec 2016 19:51:32 +0100 Subject: [PATCH] Fix Plasma-QPA filedialog to show wrong directory with QFileDialog::selectUrl() Summary: QFileDialog does not set the initialDirectory option in codepaths from QFileDialog::selectUrl(...) or QFileDialog::selectFile(...) when passing the task on to the native widget. So KDEPlatformFileDialogHelper has to make sure itself that info is kept. Because KDEPlatformFileDialogHelper::initializeDialog() calls setDirectory(options()->initialDirectory()); as intended, usually during the show event. And by that it resets any otherwise wanted state of the filewidget it had from previous setup calls via QFileDialog, and instead to whatever value the initialDirectory option had before, usually the working directory as set during initialization. Test Plan: New unit test kfiledialog_unittest testSelectUrl no longer fails with added code, also behaves now as expected with code e.g. from KUrlRequester. Reviewers: #plasma, #frameworks, dfaure Reviewed By: #plasma, graesslin, dfaure Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D3796 --- autotests/kfiledialog_unittest.cpp | 18 ++++++++++++++++++ src/platformtheme/kdeplatformfiledialoghelper.cpp | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/autotests/kfiledialog_unittest.cpp b/autotests/kfiledialog_unittest.cpp index b32cd8e..47a5543 100644 --- a/autotests/kfiledialog_unittest.cpp +++ b/autotests/kfiledialog_unittest.cpp @@ -77,6 +77,24 @@ private Q_SLOTS: QCOMPARE(dialog.directory().absolutePath(), QDir::rootPath()); } + void testSelectUrl() + { + QTemporaryFile tempFile(QDir::tempPath()+"/kfiledialogtest_XXXXXX"); + tempFile.setAutoRemove(true); + tempFile.open(); + QString tempName = tempFile.fileName(); + QUrl url = QUrl::fromLocalFile(tempName); + int idx = tempName.lastIndexOf('/'); + QUrl directoryUrl = QUrl::fromLocalFile(tempName.left(idx+1)); + + QFileDialog dialog; + dialog.selectUrl(url); + dialog.show(); + + // check if dialog was set to base directory url of the passed file url + QCOMPARE(dialog.directoryUrl(), directoryUrl); + } + 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 15b5e90..7e7e2e9 100644 --- a/src/platformtheme/kdeplatformfiledialoghelper.cpp +++ b/src/platformtheme/kdeplatformfiledialoghelper.cpp @@ -361,6 +361,13 @@ QUrl KDEPlatformFileDialogHelper::directory() const void KDEPlatformFileDialogHelper::selectFile(const QUrl &filename) { m_dialog->selectFile(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 + QSharedPointer opt(new QFileDialogOptions(*options())); + opt->setInitialDirectory(m_dialog->directory()); + setOptions(opt); } void KDEPlatformFileDialogHelper::setDirectory(const QUrl &directory) -- 2.11.0