You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.8 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. /**
  28. * Public interface of ownCloud for apps to use.
  29. * Preview interface
  30. *
  31. */
  32. // use OCP namespace for all classes that are considered public.
  33. // This means that they should be used by apps instead of the internal ownCloud classes
  34. namespace OCP;
  35. use OCP\Files\File;
  36. use OCP\Files\NotFoundException;
  37. use OCP\Files\SimpleFS\ISimpleFile;
  38. /**
  39. * This class provides functions to render and show thumbnails and previews of files
  40. * @since 6.0.0
  41. */
  42. interface IPreview {
  43. /**
  44. * @since 9.2.0
  45. */
  46. public const EVENT = self::class . ':' . 'PreviewRequested';
  47. public const MODE_FILL = 'fill';
  48. public const MODE_COVER = 'cover';
  49. /**
  50. * In order to improve lazy loading a closure can be registered which will be
  51. * called in case preview providers are actually requested
  52. *
  53. * $callable has to return an instance of \OCP\Preview\IProvider
  54. *
  55. * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider
  56. * @param \Closure $callable
  57. * @return void
  58. * @since 8.1.0
  59. */
  60. public function registerProvider($mimeTypeRegex, \Closure $callable);
  61. /**
  62. * Get all providers
  63. * @return array
  64. * @since 8.1.0
  65. */
  66. public function getProviders();
  67. /**
  68. * Does the manager have any providers
  69. * @return bool
  70. * @since 8.1.0
  71. */
  72. public function hasProviders();
  73. /**
  74. * Returns a preview of a file
  75. *
  76. * The cache is searched first and if nothing usable was found then a preview is
  77. * generated by one of the providers
  78. *
  79. * @param File $file
  80. * @param int $width
  81. * @param int $height
  82. * @param bool $crop
  83. * @param string $mode
  84. * @param string $mimeType To force a given mimetype for the file (files_versions needs this)
  85. * @return ISimpleFile
  86. * @throws NotFoundException
  87. * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
  88. * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0
  89. */
  90. public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null);
  91. /**
  92. * Returns true if the passed mime type is supported
  93. * @param string $mimeType
  94. * @return boolean
  95. * @since 6.0.0
  96. */
  97. public function isMimeSupported($mimeType = '*');
  98. /**
  99. * Check if a preview can be generated for a file
  100. *
  101. * @param \OCP\Files\FileInfo $file
  102. * @return bool
  103. * @since 8.0.0
  104. */
  105. public function isAvailable(\OCP\Files\FileInfo $file);
  106. /**
  107. * Generates previews of a file
  108. *
  109. * @param File $file
  110. * @param array $specifications
  111. * @param string $mimeType
  112. * @return ISimpleFile the last preview that was generated
  113. * @throws NotFoundException
  114. * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
  115. * @since 19.0.0
  116. */
  117. public function generatePreviews(File $file, array $specifications, $mimeType = null);
  118. }