summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorPavol Markovic <pavol.markovic@serato.com>2017-02-23 15:20:04 +1300
committerPavol Markovic <pavol.markovic@serato.com>2017-04-04 01:16:01 +0000
commit116ade88ea20d8b43a4cafac4ad23289f123b532 (patch)
treeda61484fff48cbb880fa878a29a8416c9ef50f8c /src/plugins/platforms
parent4e2f0fe4d6b252ea15167c514a127eb3f25fbbf8 (diff)
macOS: Replace deprecated NSOpenSavePanelDelegate method
shouldShowFilename method has been deprecated since macOS 10.6. In 10.11 the behavior of this method has been broken, causing files containing metadata (e.g. audio) to be incorrectly filtered out, displayed them as disabled in file dialog even though they shouldn’t be. This erratic behavior applies also to NSOpenPanel setAllowedFileTypes if set to anything but nil. This has been confirmed to be a known bug in Cocoa. Using shouldEnableURL solves this problem and also removes risk of breaking compatibility with future SDKs. Renamed and simplified private method isHiddenFile to isHiddenFileAtURL. Renamed to be consistent with other Cocoa file query methods. Simplified to return true only if the file is hidden as the name of the method implies. Previously it might have returned true also if the file has not existed which was in fact very metaphysical answer. Check for presence of the file is done by other method before calling this one and the scope of the method is limited to one source file. Task-number: QTBUG-57527 Change-Id: I2fded712d4e7098eb444331d92e38cee71655100 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm52
1 files changed, 28 insertions, 24 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
index e39d5e4546..4ba3dcb9a6 100644
--- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
@@ -101,7 +101,7 @@ typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions;
}
- (NSString *)strip:(const QString &)label;
-- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename;
+- (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url;
- (void)filterChanged:(id)sender;
- (void)showModelessPanel;
- (BOOL)runApplicationModalPanel;
@@ -222,12 +222,12 @@ static QString strippedText(QString s)
if (mOpenPanel){
QFileInfo info(*mCurrentSelection);
NSString *filepath = info.filePath().toNSString();
+ NSURL *url = [NSURL fileURLWithPath:filepath isDirectory:info.isDir()];
bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave)
- || [self panel:nil shouldShowFilename:filepath];
+ || [self panel:nil shouldEnableURL:url];
[self updateProperties];
QCocoaMenuBar::redirectKnownMenuItemsToFirstResponder();
- [mOpenPanel setAllowedFileTypes:nil];
[mSavePanel setNameFieldStringValue:selectable ? info.fileName().toNSString() : @""];
[mOpenPanel beginWithCompletionHandler:^(NSInteger result){
@@ -242,8 +242,9 @@ static QString strippedText(QString s)
{
QFileInfo info(*mCurrentSelection);
NSString *filepath = info.filePath().toNSString();
+ NSURL *url = [NSURL fileURLWithPath:filepath isDirectory:info.isDir()];
bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave)
- || [self panel:nil shouldShowFilename:filepath];
+ || [self panel:nil shouldEnableURL:url];
[mSavePanel setDirectoryURL: [NSURL fileURLWithPath:mCurrentDir]];
[mSavePanel setNameFieldStringValue:selectable ? info.fileName().toNSString() : @""];
@@ -273,8 +274,9 @@ static QString strippedText(QString s)
{
QFileInfo info(*mCurrentSelection);
NSString *filepath = info.filePath().toNSString();
+ NSURL *url = [NSURL fileURLWithPath:filepath isDirectory:info.isDir()];
bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave)
- || [self panel:nil shouldShowFilename:filepath];
+ || [self panel:nil shouldEnableURL:url];
[self updateProperties];
QCocoaMenuBar::redirectKnownMenuItemsToFirstResponder();
@@ -290,26 +292,24 @@ static QString strippedText(QString s)
}];
}
-- (BOOL)isHiddenFile:(NSString *)filename isDir:(BOOL)isDir
+- (BOOL)isHiddenFileAtURL:(NSURL *)url
{
- CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)filename, kCFURLPOSIXPathStyle, isDir);
- CFBooleanRef isHidden;
- Boolean errorOrHidden = false;
- if (!CFURLCopyResourcePropertyForKey(url, kCFURLIsHiddenKey, &isHidden, NULL)) {
- errorOrHidden = true;
- } else {
- if (CFBooleanGetValue(isHidden))
- errorOrHidden = true;
- CFRelease(isHidden);
+ BOOL hidden = NO;
+ if (url) {
+ CFBooleanRef isHiddenProperty;
+ if (CFURLCopyResourcePropertyForKey((__bridge CFURLRef)url, kCFURLIsHiddenKey, &isHiddenProperty, NULL)) {
+ hidden = CFBooleanGetValue(isHiddenProperty);
+ CFRelease(isHiddenProperty);
+ }
}
- CFRelease(url);
- return errorOrHidden;
+ return hidden;
}
-- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
+- (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url
{
Q_UNUSED(sender);
+ NSString *filename = [url path];
if ([filename length] == 0)
return NO;
@@ -353,7 +353,7 @@ static QString strippedText(QString s)
return NO;
}
if (!(filter & QDir::Hidden)
- && (qtFileName.startsWith(QLatin1Char('.')) || [self isHiddenFile:filename isDir:isDir]))
+ && (qtFileName.startsWith(QLatin1Char('.')) || [self isHiddenFileAtURL:url]))
return NO;
return YES;
@@ -446,11 +446,15 @@ static QString strippedText(QString s)
[mSavePanel setTitle:mOptions->windowTitle().toNSString()];
[mPopUpButton setHidden:chooseDirsOnly]; // TODO hide the whole sunken pane instead?
- QStringList ext = [self acceptableExtensionsForSave];
- const QString defaultSuffix = mOptions->defaultSuffix();
- if (!ext.isEmpty() && !defaultSuffix.isEmpty())
- ext.prepend(defaultSuffix);
- [mSavePanel setAllowedFileTypes:ext.isEmpty() ? nil : qt_mac_QStringListToNSMutableArray(ext)];
+ if (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) {
+ QStringList ext = [self acceptableExtensionsForSave];
+ const QString defaultSuffix = mOptions->defaultSuffix();
+ if (!ext.isEmpty() && !defaultSuffix.isEmpty())
+ ext.prepend(defaultSuffix);
+ [mSavePanel setAllowedFileTypes:ext.isEmpty() ? nil : qt_mac_QStringListToNSMutableArray(ext)];
+ } else {
+ [mOpenPanel setAllowedFileTypes:nil]; // delegate panel:shouldEnableURL: does the file filtering for NSOpenPanel
+ }
if ([mSavePanel respondsToSelector:@selector(isVisible)] && [mSavePanel isVisible]) {
if ([mSavePanel respondsToSelector:@selector(validateVisibleColumns)])