Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfilesystemengine_mac.mm
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include "qplatformdefs.h"
7#include "qfile.h"
8#include "qurl.h"
9
10#include <QtCore/private/qcore_mac_p.h>
11#include <CoreFoundation/CoreFoundation.h>
12
14
15/*
16 This implementation does not enable the "put back" option in Finder
17 for the trashed object. The only way to get this is to use Finder automation,
18 which would query the user for permission to access Finder using a modal,
19 blocking dialog - which we definitely can't have in a console application.
20
21 Using Finder would also play the trash sound, which we don't want either in
22 such a core API; applications that want that can play the sound themselves.
23*/
24//static
25bool QFileSystemEngine::supportsMoveFileToTrash()
26{
27#ifdef Q_OS_MACOS // desktop macOS has a trash can
28 return true;
29#else // watch, tv, iOS don't have a trash can
30 return false;
31#endif
32}
33
34//static
35bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source,
36 QFileSystemEntry &newLocation, QSystemError &error)
37{
38#ifdef Q_OS_MACOS // desktop macOS has a trash can
39 QMacAutoReleasePool pool;
40
41 QFileInfo info(source.filePath());
42 NSString *filepath = info.filePath().toNSString();
43 NSURL *fileurl = [NSURL fileURLWithPath:filepath isDirectory:info.isDir()];
44 NSURL *resultingUrl = nil;
45 NSError *nserror = nil;
46 NSFileManager *fm = [NSFileManager defaultManager];
47 if ([fm trashItemAtURL:fileurl resultingItemURL:&resultingUrl error:&nserror] != YES) {
48 error = QSystemError(nserror.code, QSystemError::NativeError);
49 return false;
50 }
51 newLocation = QFileSystemEntry(QUrl::fromNSURL(resultingUrl).path());
52 return true;
53#else // watch, tv, iOS don't have a trash can
54 Q_UNUSED(source);
55 Q_UNUSED(newLocation);
56 error = QSystemError(ENOSYS, QSystemError::StandardLibraryError);
57 return false;
58#endif
59}
60
61QT_END_NAMESPACE