OpenShot Audio Library | OpenShotAudio  0.6.0
juce_AndroidDocument.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2020 - Raw Material Software Limited
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  The code included in this file is provided under the terms of the ISC license
11  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12  To use, copy, modify, and/or distribute this software for any purpose with or
13  without fee is hereby granted provided that the above copyright notice and
14  this permission notice appear in all copies.
15 
16  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18  DISCLAIMED.
19 
20  ==============================================================================
21 */
22 
23 namespace juce
24 {
25 
26 //==============================================================================
39 {
40 public:
41  AndroidDocumentInfo() = default;
42 
44  bool exists() const { return isJuceFlagSet (flagExists); }
45 
47  bool isDirectory() const;
48 
50  bool isFile() const { return type.isNotEmpty() && ! isDirectory(); }
51 
57  bool canRead() const { return isJuceFlagSet (flagHasReadPermission) && type.isNotEmpty(); }
58 
64  bool canWrite() const
65  {
66  return isJuceFlagSet (flagHasWritePermission)
67  && type.isNotEmpty()
68  && (isNativeFlagSet (flagSupportsWrite)
69  || isNativeFlagSet (flagSupportsDelete)
70  || isNativeFlagSet (flagDirSupportsCreate));
71  }
72 
74  bool canDelete() const { return isNativeFlagSet (flagSupportsDelete); }
75 
77  bool canCreateChildren() const { return isNativeFlagSet (flagDirSupportsCreate); }
78 
80  bool canRename() const { return isNativeFlagSet (flagSupportsRename); }
81 
83  bool canCopy() const { return isNativeFlagSet (flagSupportsCopy); }
84 
86  bool canMove() const { return isNativeFlagSet (flagSupportsMove); }
87 
89  bool isVirtual() const { return isNativeFlagSet (flagVirtualDocument); }
90 
96  String getName() const { return name; }
97 
99  String getType() const { return isDirectory() ? String{} : type; }
100 
106  int64 getLastModified() const { return isJuceFlagSet (flagValidModified) ? lastModified : 0; }
107 
109  bool isLastModifiedValid() const { return isJuceFlagSet (flagValidModified); }
110 
116  int64 getSizeInBytes() const { return isJuceFlagSet (flagValidSize) ? sizeInBytes : 0; }
117 
119  bool isSizeInBytesValid() const { return isJuceFlagSet (flagValidSize); }
120 
122  class Args;
123 
124 private:
125  explicit AndroidDocumentInfo (Args);
126 
127  bool isNativeFlagSet (int flag) const { return (nativeFlags & flag) != 0; }
128  bool isJuceFlagSet (int flag) const { return (juceFlags & flag) != 0; }
129 
130  /* Native Android flags that might be set in the COLUMN_FLAGS for a particular document */
131  enum
132  {
133  flagSupportsWrite = 0x0002,
134  flagSupportsDelete = 0x0004,
135  flagDirSupportsCreate = 0x0008,
136  flagSupportsRename = 0x0040,
137  flagSupportsCopy = 0x0080,
138  flagSupportsMove = 0x0100,
139  flagVirtualDocument = 0x0200,
140  };
141 
142  /* Flags for other binary properties that aren't exposed in COLUMN_FLAGS */
143  enum
144  {
145  flagExists = 1 << 0,
146  flagValidModified = 1 << 1,
147  flagValidSize = 1 << 2,
148  flagHasReadPermission = 1 << 3,
149  flagHasWritePermission = 1 << 4,
150  };
151 
152  String name;
153  String type;
154  int64 lastModified = 0;
155  int64 sizeInBytes = 0;
156  int nativeFlags = 0, juceFlags = 0;
157 };
158 
159 //==============================================================================
170 {
171 public:
173  URL getUrl() const { return url; }
174 
176  int64 getPersistedTime() const { return time; }
177 
179  bool isReadPermission() const { return read; }
180 
182  bool isWritePermission() const { return write; }
183 
191  static void takePersistentReadWriteAccess (const URL&);
192 
194  static void releasePersistentReadWriteAccess (const URL&);
195 
199  static std::vector<AndroidDocumentPermission> getPersistedPermissions();
200 
201 private:
202  URL url;
203  int64 time = 0;
204  bool read = false, write = false;
205 };
206 
207 //==============================================================================
242 {
243 public:
246 
257  static AndroidDocument fromFile (const File& filePath);
258 
270  static AndroidDocument fromDocument (const URL& documentUrl);
271 
294  static AndroidDocument fromTree (const URL& treeUrl);
295 
297  AndroidDocument (AndroidDocument&&) noexcept;
298 
299  AndroidDocument& operator= (const AndroidDocument&);
300  AndroidDocument& operator= (AndroidDocument&&) noexcept;
301 
302  ~AndroidDocument();
303 
305  bool operator== (const AndroidDocument&) const;
306 
308  bool operator!= (const AndroidDocument&) const;
309 
311  bool deleteDocument() const;
312 
319  bool renameTo (const String& newDisplayName);
320 
332 
338 
344  bool hasValue() const { return pimpl != nullptr; }
345 
347  explicit operator bool() const { return hasValue(); }
348 
350  std::unique_ptr<InputStream> createInputStream() const;
351 
353  std::unique_ptr<OutputStream> createOutputStream() const;
354 
356  URL getUrl() const;
357 
360 
375 
387  const AndroidDocument& newParent);
388 
390  struct NativeInfo;
391 
393  NativeInfo getNativeInfo() const;
394 
395 private:
396  struct Utils;
397  class Pimpl;
398 
399  explicit AndroidDocument (std::unique_ptr<Pimpl>);
400 
401  void swap (AndroidDocument& other) noexcept { std::swap (other.pimpl, pimpl); }
402 
403  std::unique_ptr<Pimpl> pimpl;
404 };
405 
406 //==============================================================================
437 {
438 public:
439  using difference_type = std::ptrdiff_t;
440  using pointer = void;
441  using iterator_category = std::input_iterator_tag;
442 
445 
448 
451 
452  bool operator== (const AndroidDocumentIterator& other) const noexcept { return pimpl == nullptr && other.pimpl == nullptr; }
453  bool operator!= (const AndroidDocumentIterator& other) const noexcept { return ! operator== (other); }
454 
457 
460 
462  AndroidDocumentIterator begin() const { return *this; }
463 
466 
467 private:
468  struct Utils;
469  struct Pimpl;
470 
471  explicit AndroidDocumentIterator (std::unique_ptr<Pimpl>);
472 
473  std::shared_ptr<Pimpl> pimpl;
474 };
475 
476 } // namespace juce
AndroidDocument operator*() const
AndroidDocumentIterator begin() const
AndroidDocumentIterator & operator++()
AndroidDocumentIterator end() const
static AndroidDocumentIterator makeNonRecursive(const AndroidDocument &)
static AndroidDocumentIterator makeRecursive(const AndroidDocument &)
static std::vector< AndroidDocumentPermission > getPersistedPermissions()
static void releasePersistentReadWriteAccess(const URL &)
static void takePersistentReadWriteAccess(const URL &)
bool moveDocumentFromParentToParent(const AndroidDocument &currentParent, const AndroidDocument &newParent)
std::unique_ptr< OutputStream > createOutputStream() const
static AndroidDocument fromFile(const File &filePath)
AndroidDocumentInfo getInfo() const
static AndroidDocument fromDocument(const URL &documentUrl)
std::unique_ptr< InputStream > createInputStream() const
AndroidDocument createChildDirectory(const String &name) const
AndroidDocument copyDocumentToParentDocument(const AndroidDocument &target) const
bool renameTo(const String &newDisplayName)
bool deleteDocument() const
NativeInfo getNativeInfo() const
AndroidDocument createChildDocumentWithTypeAndName(const String &type, const String &name) const
static AndroidDocument fromTree(const URL &treeUrl)
bool isNotEmpty() const noexcept
Definition: juce_String.h:316