diff --git a/src/platformtheme/kfontsettingsdata.cpp b/src/platformtheme/kfontsettingsdata.cpp index fc0c980..e504fb7 100644 --- a/src/platformtheme/kfontsettingsdata.cpp +++ b/src/platformtheme/kfontsettingsdata.cpp @@ -1,131 +1,132 @@ /* This file is part of the KDE libraries Copyright (C) 2000, 2006 David Faure Copyright 2008 Friedrich W. H. Kossebau Copyright 2013 Aleix Pol Gonzalez This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. 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 Library 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. */ #undef QT_NO_CAST_FROM_ASCII #include "kfontsettingsdata.h" #include #include #include #include #ifdef DBUS_SUPPORT_ENABLED #include #include #endif #include #include #include KFontSettingsData::KFontSettingsData() : QObject(0) { #ifdef DBUS_SUPPORT_ENABLED QMetaObject::invokeMethod(this, "delayedDBusConnects", Qt::QueuedConnection); #endif for (int i = 0; i < FontTypesCount; ++i) { mFonts[i] = 0; } } KFontSettingsData::~KFontSettingsData() { for (int i = 0; i < FontTypesCount; ++i) { delete mFonts[i]; } } // NOTE: keep in sync with plasma-desktop/kcms/fonts/fonts.cpp static const char GeneralId[] = "General"; static const char DefaultFont[] = "Lucida Grande"; static const KFontData DefaultFontData[KFontSettingsData::FontTypesCount] = { - { GeneralId, "font", DefaultFont, 10, -1, QFont::SansSerif }, - { GeneralId, "fixed", "Monaco", 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 }, - { GeneralId, "taskbarFont", DefaultFont, 10, -1, QFont::SansSerif }, - { GeneralId, "smallestReadableFont", DefaultFont, 8, -1, QFont::SansSerif } + { GeneralId, "font", DefaultFont, 10, -1, QFont::SansSerif, "Regular" }, + { GeneralId, "fixed", "Monaco", 9, -1, QFont::Monospace, "Regular" }, + { GeneralId, "toolBarFont", DefaultFont, 9, -1, QFont::SansSerif, "Regular" }, + { GeneralId, "menuFont", DefaultFont, 10, -1, QFont::SansSerif, "Regular" }, + { "WM", "activeFont", DefaultFont, 10, -1, QFont::SansSerif, "Regular" }, + { GeneralId, "taskbarFont", DefaultFont, 10, -1, QFont::SansSerif, "Regular" }, + { GeneralId, "smallestReadableFont", DefaultFont, 8, -1, QFont::SansSerif, "Regular" } }; KSharedConfigPtr &KFontSettingsData::kdeGlobals() { if (!mKdeGlobals) { if (qEnvironmentVariableIsSet("QT_QPA_PLATFORMTHEME_CONFIG_FILE")) { mKdeGlobals = KSharedConfig::openConfig(qgetenv("QT_QPA_PLATFORMTHEME_CONFIG_FILE"), KConfig::NoGlobals); } else { mKdeGlobals = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals); } } return mKdeGlobals; } QFont *KFontSettingsData::font(FontTypes fontType) { QFont *cachedFont = mFonts[fontType]; if (!cachedFont) { const KFontData &fontData = DefaultFontData[fontType]; cachedFont = new QFont(QLatin1String(fontData.FontName), fontData.Size, fontData.Weight); cachedFont->setStyleHint(fontData.StyleHint); + cachedFont->setStyleName(QLatin1String(fontData.StyleName)); const KConfigGroup configGroup(kdeGlobals(), fontData.ConfigGroupKey); QString fontInfo = configGroup.readEntry(fontData.ConfigKey, QString()); //If we have serialized information for this font, restore it //NOTE: We are not using KConfig directly because we can't call QFont::QFont from here if (!fontInfo.isEmpty()) { cachedFont->fromString(fontInfo); } mFonts[fontType] = cachedFont; } return cachedFont; } void KFontSettingsData::dropFontSettingsCache() { if (mKdeGlobals) { mKdeGlobals->reparseConfiguration(); } for (int i = 0; i < FontTypesCount; ++i) { delete mFonts[i]; mFonts[i] = 0; } QWindowSystemInterface::handleThemeChange(0); if (qobject_cast(QCoreApplication::instance())) { QApplication::setFont(*font(KFontSettingsData::GeneralFont)); } else { QGuiApplication::setFont(*font(KFontSettingsData::GeneralFont)); } } void KFontSettingsData::delayedDBusConnects() { #ifdef DBUS_SUPPORT_ENABLED QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KDEPlatformTheme"), QStringLiteral("org.kde.KDEPlatformTheme"), QStringLiteral("refreshFonts"), this, SLOT(dropFontSettingsCache())); #endif } diff --git a/src/platformtheme/kfontsettingsdata.h b/src/platformtheme/kfontsettingsdata.h index 4c14f54..cd04e9f 100644 --- a/src/platformtheme/kfontsettingsdata.h +++ b/src/platformtheme/kfontsettingsdata.h @@ -1,74 +1,75 @@ /* This file is part of the KDE libraries Copyright (C) 2000, 2006 David Faure Copyright 2008 Friedrich W. H. Kossebau Copyright 2013 Aleix Pol Gonzalez This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. 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 Library 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 KFONTSETTINGSDATA_H #define KFONTSETTINGSDATA_H #include #include #include struct KFontData { const char *ConfigGroupKey; const char *ConfigKey; const char *FontName; int Size; int Weight; QFont::StyleHint StyleHint; + const char *StyleName; }; class KFontSettingsData : public QObject { Q_OBJECT public: // if adding a new type here also add an entry to DefaultFontData enum FontTypes { GeneralFont = 0, FixedFont, ToolbarFont, MenuFont, WindowTitleFont, TaskbarFont, SmallestReadableFont, FontTypesCount }; public: KFontSettingsData(); ~KFontSettingsData(); public Q_SLOTS: void dropFontSettingsCache(); protected Q_SLOTS: void delayedDBusConnects(); public: // access, is not const due to caching QFont *font(FontTypes fontType); protected: KSharedConfigPtr &kdeGlobals(); private: QFont *mFonts[FontTypesCount]; KSharedConfigPtr mKdeGlobals; }; #endif // KFONTSETTINGSDATA_H diff --git a/src/platformtheme/kfontsettingsdatamac.mm b/src/platformtheme/kfontsettingsdatamac.mm index 2b6ebcc..6b45621 100644 --- a/src/platformtheme/kfontsettingsdatamac.mm +++ b/src/platformtheme/kfontsettingsdatamac.mm @@ -1,245 +1,246 @@ /* This file is part of the KDE libraries Copyright (C) 2000, 2006 David Faure Copyright 2008 Friedrich W. H. Kossebau Copyright 2013 Aleix Pol Gonzalez Copyright 2015 René J.V. Bertin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. 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 Library 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 "kfontsettingsdatamac.h" #include "platformtheme_logging.h" #include #include #include #include #include #include #include #ifdef DBUS_SUPPORT_ENABLED #include #include #endif #include #include #include // NOTE: keep in sync with plasma-desktop/kcms/fonts/fonts.cpp static const char GeneralId[] = "General"; // NOTE: the default system font changed with OS X 10.11, from Lucida Grande to // San Francisco. With luck this will be caught by QFontDatabase::GeneralFont const char DefaultFont[] = "Lucida Grande"; static const char DefaultFixedFont[] = "Monaco"; static const char *LocalDefaultFont = NULL; // See README.fonts.txt for information and thoughts about native/default fonts KFontData DefaultFontData[KFontSettingsDataMac::FontTypesCount] = { - { GeneralId, "font", DefaultFont, 12, -1, QFont::SansSerif }, - { GeneralId, "fixed", DefaultFixedFont, 10, -1, QFont::Monospace }, - { GeneralId, "toolBarFont", DefaultFont, 10, -1, QFont::SansSerif }, - { GeneralId, "menuFont", DefaultFont, 14, -1, QFont::SansSerif }, + { GeneralId, "font", DefaultFont, 12, -1, QFont::SansSerif, "Medium" }, + { GeneralId, "fixed", DefaultFixedFont, 10, -1, QFont::Monospace, "Regular" }, + { GeneralId, "toolBarFont", DefaultFont, 10, -1, QFont::SansSerif, "Medium" }, + { GeneralId, "menuFont", DefaultFont, 14, -1, QFont::SansSerif, "Medium" }, // applications don't control the window titlebar fonts - { "WM", "activeFont", DefaultFont, 13, -1, QFont::SansSerif }, - { GeneralId, "taskbarFont", DefaultFont, 9, -1, QFont::SansSerif }, - { GeneralId, "smallestReadableFont", DefaultFont, 9, -1, QFont::SansSerif }, + { "WM", "activeFont", DefaultFont, 13, -1, QFont::SansSerif, "Medium" }, + { GeneralId, "taskbarFont", DefaultFont, 9, -1, QFont::SansSerif, "Medium" }, + { GeneralId, "smallestReadableFont", DefaultFont, 9, -1, QFont::SansSerif, "Medium" }, // this one is to accomodate for the MessageBoxFont which should be bold on OS X // when using the native theme fonts. - { GeneralId, "messageBoxFont", DefaultFont, 13, QFont::Bold, QFont::SansSerif } + { GeneralId, "messageBoxFont", DefaultFont, 13, QFont::Bold, QFont::SansSerif, "Bold" } }; static const char *fontNameFor(QFontDatabase::SystemFont role) { QFont qf = QFontDatabase::systemFont(role); if (!qf.defaultFamily().isEmpty()) { char *fn; if (role == QFontDatabase::FixedFont && !qf.fixedPitch()) { fn = strdup("Monaco"); } else if (qf.defaultFamily() == QStringLiteral(".Lucida Grande UI")) { fn = strdup("Lucida Grande"); } else { fn = strdup(qf.defaultFamily().toLocal8Bit().data()); } if (qEnvironmentVariableIsSet("QT_QPA_PLATFORMTHEME_VERBOSE")) { qCWarning(PLATFORMTHEME) << "fontNameFor" << role << "font:" << qf << "name:" << fn; } return fn; } else { return NULL; } } void initDefaultFonts() { const char *fn; static bool active = false; // we must protect ourselves from being called recursively if (active) { return; } active = true; if (!LocalDefaultFont) { fn = fontNameFor(QFontDatabase::GeneralFont); LocalDefaultFont = fn; } for (int i = 0 ; i < KFontSettingsDataMac::FontTypesCount ; ++i) { switch(i) { case KFontSettingsDataMac::FixedFont: fn = fontNameFor(QFontDatabase::FixedFont); break; case KFontSettingsDataMac::WindowTitleFont: fn = fontNameFor(QFontDatabase::TitleFont); break; case KFontSettingsDataMac::SmallestReadableFont: fn = fontNameFor(QFontDatabase::SmallestReadableFont); break; default: fn = LocalDefaultFont; break; } if (qEnvironmentVariableIsSet("QT_QPA_PLATFORMTHEME_VERBOSE")) { qCWarning(PLATFORMTHEME) << "Default font for type" << i << ":" << fn << "; currently:" << DefaultFontData[i].FontName; } if (fn) { if (DefaultFontData[i].FontName != DefaultFont && DefaultFontData[i].FontName != DefaultFixedFont && DefaultFontData[i].FontName != LocalDefaultFont) { free((void*)DefaultFontData[i].FontName); } DefaultFontData[i].FontName = fn; } } active = false; } KFontSettingsDataMac::KFontSettingsDataMac() { #ifdef DBUS_SUPPORT_ENABLED QMetaObject::invokeMethod(this, "delayedDBusConnects", Qt::QueuedConnection); #endif for (int i = 0; i < FontTypesCount; ++i) { // remove any information that already have been cached by our parent // IFF we don't have our own mFonts copy // delete mFonts[i]; mFonts[i] = 0; } } KFontSettingsDataMac::~KFontSettingsDataMac() { for (int i = 0 ; i < KFontSettingsDataMac::FontTypesCount ; ++i) { if (DefaultFontData[i].FontName != DefaultFont && DefaultFontData[i].FontName != DefaultFixedFont) { if (DefaultFontData[i].FontName && DefaultFontData[i].FontName != LocalDefaultFont) { free((void*)(DefaultFontData[i].FontName)); } DefaultFontData[i].FontName = (i == FixedFont)? DefaultFixedFont : DefaultFont; } } if (LocalDefaultFont) { free((void*)(LocalDefaultFont)); } LocalDefaultFont = NULL; } QFont *KFontSettingsDataMac::font(FontTypes fontType) { QFont *cachedFont = mFonts[fontType]; if (!cachedFont) { // check if we have already initialised our local database mapping font types to fonts // if not, we do it here, at the latest possible moment. Doing it in the KFontSettingsDataMac // ctor is bound for failure as our instance is likely to be created before Qt's own // font database has been populated. That's expectable: the font database also represents // platform (theme) specific fonts for various roles, and our ctor is called as part of the // platform theme creation procedure. if (!LocalDefaultFont) { static bool active = false; // NB: initDefaultFonts() queries Qt's font database which in turn can call us // again. Protection against this is built into initDefaultFonts(), but in practice // we prefer to return NULL if called through recursively. if (!active) { active = true; initDefaultFonts(); active = false; } else { // our caller must handle NULL, preferably by relaying the font request // to the native platform theme (see KdeMacTheme::font()). return NULL; } } const KConfigGroup configGroup(kdeGlobals(), DefaultFontData[fontType].ConfigGroupKey); QString fontInfo; bool forceBold = false; if (fontType == MessageBoxFont) { // OS X special: the MessageBoxFont is by default a bold version of the GeneralFont // and that's what is cached in DefaultFontData[MessageBoxFont]. // NB: we can use a single configGroup for this hack as long as MessageBoxFont and // GeneralFont share the same ConfigGroupKey (or MessageBoxFont cannot be configured). fontInfo = configGroup.readEntry(DefaultFontData[GeneralFont].ConfigKey, QString()); if (!fontInfo.isEmpty()) { // However, if the user has configured a GeneralFont (MessageBoxFont cannot be configured), // we respect his/her choice but maintain the bold aspect dictated by the platform. fontType = GeneralFont; forceBold = true; } } const KFontData &fontData = DefaultFontData[fontType]; cachedFont = new QFont(QLatin1String(fontData.FontName), fontData.Size, forceBold? QFont::Bold : fontData.Weight); cachedFont->setStyleHint(fontData.StyleHint); + cachedFont->setStyleName(QLatin1String(fontData.StyleName)); // if (qEnvironmentVariableIsSet("QT_QPA_PLATFORMTHEME_VERBOSE")) { // qCWarning(PLATFORMTHEME) << "Requested font type" << fontType << "name=" << fontData.FontName << "forceBold=" << forceBold << "styleHint=" << fontData.StyleHint; // qCWarning(PLATFORMTHEME) << "\t->" << *cachedFont; // } fontInfo = configGroup.readEntry(fontData.ConfigKey, QString()); if (!fontInfo.isEmpty()) { cachedFont->fromString(fontInfo); // if (qEnvironmentVariableIsSet("QT_QPA_PLATFORMTHEME_VERBOSE")) { // qCWarning(PLATFORMTHEME) << "\tfontInfo=" << fontInfo << "->" << *cachedFont; // } } mFonts[fontType] = cachedFont; } return cachedFont; } void KFontSettingsDataMac::dropFontSettingsCache() { if (qobject_cast(QCoreApplication::instance())) { QApplication::setFont(*font(KFontSettingsDataMac::GeneralFont)); } else { QGuiApplication::setFont(*font(KFontSettingsDataMac::GeneralFont)); } } void KFontSettingsDataMac::delayedDBusConnects() { #ifdef DBUS_SUPPORT_ENABLED QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KDEPlatformTheme"), QStringLiteral("org.kde.KDEPlatformTheme"), QStringLiteral("refreshFonts"), this, SLOT(dropFontSettingsCache())); #endif } diff --git a/src/platformtheme/plintegration-cumpatch1.diff b/src/platformtheme/plintegration-cumpatch1.diff index 5d4c993..0ea86f9 100644 --- a/src/platformtheme/plintegration-cumpatch1.diff +++ b/src/platformtheme/plintegration-cumpatch1.diff @@ -1,331 +1,332 @@ 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 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