iOS File Dialog: Support setting name filters
Fixes: QTBUG-93624 Pick-to: 6.5 Change-Id: I2e1b522d572fd36f58a3de90f0a685f5d22dfeeb Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
3ff8629a0f
commit
ce20b81070
@ -14,19 +14,30 @@
|
||||
{
|
||||
NSMutableArray <UTType *> *docTypes = [[[NSMutableArray alloc] init] autorelease];
|
||||
|
||||
switch (fileDialog->options()->fileMode()) {
|
||||
case QFileDialogOptions::AnyFile:
|
||||
case QFileDialogOptions::ExistingFile:
|
||||
case QFileDialogOptions::ExistingFiles:
|
||||
[docTypes addObject:[UTType typeWithIdentifier:(__bridge NSString *)kUTTypeContent]];
|
||||
[docTypes addObject:[UTType typeWithIdentifier:(__bridge NSString *)kUTTypeItem]];
|
||||
[docTypes addObject:[UTType typeWithIdentifier:(__bridge NSString *)kUTTypeData]];
|
||||
break;
|
||||
// Showing files is not supported in Directory mode in iOS
|
||||
case QFileDialogOptions::Directory:
|
||||
case QFileDialogOptions::DirectoryOnly:
|
||||
[docTypes addObject:[UTType typeWithIdentifier:(__bridge NSString *)kUTTypeFolder]];
|
||||
break;
|
||||
QStringList nameFilters = fileDialog->options()->nameFilters();
|
||||
if (!nameFilters.isEmpty() && (fileDialog->options()->fileMode() != QFileDialogOptions::Directory
|
||||
|| fileDialog->options()->fileMode() != QFileDialogOptions::DirectoryOnly))
|
||||
{
|
||||
QStringList results;
|
||||
for (const QString &filter : nameFilters)
|
||||
results.append(QPlatformFileDialogHelper::cleanFilterList(filter));
|
||||
|
||||
docTypes = [self computeAllowedFileTypes:results];
|
||||
} else {
|
||||
switch (fileDialog->options()->fileMode()) {
|
||||
case QFileDialogOptions::AnyFile:
|
||||
case QFileDialogOptions::ExistingFile:
|
||||
case QFileDialogOptions::ExistingFiles:
|
||||
[docTypes addObject:[UTType typeWithIdentifier:(__bridge NSString *)kUTTypeContent]];
|
||||
[docTypes addObject:[UTType typeWithIdentifier:(__bridge NSString *)kUTTypeItem]];
|
||||
[docTypes addObject:[UTType typeWithIdentifier:(__bridge NSString *)kUTTypeData]];
|
||||
break;
|
||||
// Showing files is not supported in Directory mode in iOS
|
||||
case QFileDialogOptions::Directory:
|
||||
case QFileDialogOptions::DirectoryOnly:
|
||||
[docTypes addObject:[UTType typeWithIdentifier:(__bridge NSString *)kUTTypeFolder]];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (self = [super initForOpeningContentTypes:docTypes]) {
|
||||
@ -75,4 +86,25 @@
|
||||
emit m_fileDialog->reject();
|
||||
}
|
||||
|
||||
- (NSMutableArray<UTType*>*)computeAllowedFileTypes:(QStringList)filters
|
||||
{
|
||||
QStringList fileTypes;
|
||||
for (const QString &filter : filters) {
|
||||
if (filter.contains(u'?'))
|
||||
continue;
|
||||
|
||||
if (filter.count(u'*') != 1)
|
||||
continue;
|
||||
|
||||
auto extensions = filter.split('.', Qt::SkipEmptyParts);
|
||||
fileTypes += extensions.last();
|
||||
}
|
||||
|
||||
NSMutableArray<UTType *> *result = [NSMutableArray<UTType *> arrayWithCapacity:fileTypes.size()];
|
||||
for (const QString &string : fileTypes)
|
||||
[result addObject:[UTType typeWithFilenameExtension:string.toNSString()]];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user