From 084cd1654144c45fe0a2715fb8617699ab982be8 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 5 Jan 2015 15:19:37 +0100 Subject: [PATCH] Fix OS X file drops from Finder This is a workaround for QTBUG-40449. Change-Id: I24a3bfb78d49e94dcafb99ee6d6b36ef4c4299c5 Task-number: QTBUG-40449 Reviewed-by: Christian Stenger Reviewed-by: Eike Ziller Reviewed-by: Erik Verbruggen --- src/libs/utils/fileutils.cpp | 16 ++++++++++- src/libs/utils/fileutils_mac.mm | 51 +++++++++++++++++++++++++++++++++ src/libs/utils/utils-lib.pri | 6 ++++ src/libs/utils/utils.qbs | 12 ++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/libs/utils/fileutils_mac.mm diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index 6d75342b994..b4a9c79f9cd 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -57,6 +57,15 @@ QDebug operator<<(QDebug dbg, const Utils::FileName &c) QT_END_NAMESPACE +#ifdef Q_OS_OSX +// for file drops from Finder, working around QTBUG-40449 +namespace Utils { +namespace Internal { +extern QUrl filePathUrl(const QUrl &url); +} // Internal +} // Utils +#endif + namespace Utils { /*! \class Utils::FileUtils @@ -743,7 +752,12 @@ static bool isFileDrop(const QMimeData *d, QList *fil bool hasFiles = false; const QList::const_iterator cend = urls.constEnd(); for (QList::const_iterator it = urls.constBegin(); it != cend; ++it) { - const QString fileName = it->toLocalFile(); + QUrl url = *it; +#ifdef Q_OS_OSX + // for file drops from Finder, working around QTBUG-40449 + url = Internal::filePathUrl(url); +#endif + const QString fileName = url.toLocalFile(); if (!fileName.isEmpty()) { hasFiles = true; if (files) diff --git a/src/libs/utils/fileutils_mac.mm b/src/libs/utils/fileutils_mac.mm new file mode 100644 index 00000000000..d219298b32e --- /dev/null +++ b/src/libs/utils/fileutils_mac.mm @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include + +#include +#include + +namespace Utils { +namespace Internal { + +QUrl filePathUrl(const QUrl &url) +{ + QUrl ret = url; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSURL *nsurl = url.toNSURL(); + if ([nsurl isFileReferenceURL]) + ret = QUrl::fromNSURL([nsurl filePathURL]); + [pool release]; + return ret; +} + +} // Internal +} // Utils diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 9b7e25b88bf..f339efdb8a2 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -200,3 +200,9 @@ FORMS += $$PWD/filewizardpage.ui \ $$PWD/proxycredentialsdialog.ui RESOURCES += $$PWD/utils.qrc + +osx { + OBJECTIVE_SOURCES += \ + $$PWD/fileutils_mac.mm + LIBS += -framework Foundation +} diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index 4a79fa9b4f7..456dbd7dbc4 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -18,6 +18,10 @@ QtcLibrary { condition: qbs.targetOS.contains("unix") && !qbs.targetOS.contains("osx") cpp.dynamicLibraries: ["X11"] } + Properties { + condition: qbs.targetOS.contains("osx") + cpp.frameworks: ["Foundation"] + } Depends { name: "Qt"; submodules: ["widgets", "network", "script", "concurrent"] } Depends { name: "app_version_header" } @@ -244,6 +248,14 @@ QtcLibrary { ] } + Group { + name: "FileUtils_osx" + condition: qbs.targetOS.contains("osx") + files: [ + "fileutils_mac.mm", + ] + } + Export { Depends { name: "Qt"; submodules: ["concurrent", "widgets" ] } }