File indexing completed on 2024-05-19 04:27:04
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2023 Ivan Santa MarĂa <ghevan@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KisMacosSecurityScopeBookmarkManager_h 0008 #define KisMacosSecurityScopeBookmarkManager_h 0009 0010 #include <QObject> 0011 0012 class QString; 0013 class QUrl; 0014 0015 class KisMacosSecurityBookmarkManager : public QObject 0016 { 0017 Q_OBJECT 0018 0019 public: 0020 enum SecurityBookmarkType { 0021 File = 0, 0022 Directory 0023 }; 0024 Q_ENUM(SecurityBookmarkType) 0025 0026 static KisMacosSecurityBookmarkManager *instance(); 0027 0028 explicit KisMacosSecurityBookmarkManager(); 0029 0030 ~KisMacosSecurityBookmarkManager(); 0031 /** 0032 * @return Return true if file is contained within a directory with permissions 0033 * previouly granted by NSOpenPanel 0034 * 0035 */ 0036 bool parentDirHasPermissions(const QString &path); 0037 0038 /** 0039 * Creates a bookmark security scope for diven path 0040 * @param path File path returned from NSOpenPanel 0041 * @param refpath If non empty creates the security key relative to the 0042 * reference path. This is useful for documents refering to other documents 0043 */ 0044 void createBookmarkFromPath(const QString &path, const QString &refpath,SecurityBookmarkType type = SecurityBookmarkType::File); 0045 0046 /** 0047 * starts access to all registered security bookmarks 0048 */ 0049 void startAccessingSecurityScopedResources(); 0050 0051 /** 0052 * stops access to all started security bookmarks 0053 */ 0054 void stopAccessingSecurityScopedResources(); 0055 0056 /** 0057 * Shows NSOpenPanel and saves the selected directory for future access 0058 * 0059 * @return TRUE if selected path is same as input path. users can still select 0060 * any directory they want, but we specifically requested they give us 0061 * permission to a specific directory 0062 * 0063 */ 0064 bool requestAccessToDir(const QString &path); 0065 0066 /** 0067 * Loads security scoped files to internal dictionary 0068 * 0069 */ 0070 void loadSecurityScopedResources(); 0071 0072 bool isSandboxed(); 0073 0074 0075 public Q_SLOTS: 0076 void addBookmarkAndCheckParentDir(const QUrl &url); 0077 0078 void slotCreateBookmark(const QString &path); 0079 0080 private: 0081 Q_DISABLE_COPY(KisMacosSecurityBookmarkManager) 0082 0083 void loadKeysFromArray(SecurityBookmarkType); 0084 0085 QString securityBookmarkTypeToString(const SecurityBookmarkType); 0086 0087 QUrl decodeBookmarkToURL(QString encodedPath); 0088 0089 class Private; 0090 const QScopedPointer<Private> m_d; 0091 }; 0092 0093 #endif /* KisMacosSecurityScopeBookmarkManager_h */