summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-11-10 14:04:59 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2016-11-10 14:28:09 +0100
commit99ada40df48af18396b8a99363832b1bffc58d37 (patch)
treecb517371491f913f1a3dc4969d7aa0d7061e4bb5 /lib
parentcfda17d8f3c55cbbd8decb134c82c499e3c2c2f4 (diff)
downloadnextcloud-server-99ada40df48af18396b8a99363832b1bffc58d37.tar.gz
nextcloud-server-99ada40df48af18396b8a99363832b1bffc58d37.zip
Dispatch event on preview request
Fixes: #73 Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Preview/Generator.php19
-rw-r--r--lib/private/PreviewManager.php18
-rw-r--r--lib/private/Server.php3
-rw-r--r--lib/public/IPreview.php5
4 files changed, 39 insertions, 6 deletions
diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php
index 3d4e9bf3677..32a732d8580 100644
--- a/lib/private/Preview/Generator.php
+++ b/lib/private/Preview/Generator.php
@@ -32,6 +32,8 @@ use OCP\IConfig;
use OCP\IImage;
use OCP\IPreview;
use OCP\Preview\IProvider;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\EventDispatcher\GenericEvent;
class Generator {
@@ -43,23 +45,28 @@ class Generator {
private $appData;
/** @var GeneratorHelper */
private $helper;
+ /** @var EventDispatcherInterface */
+ private $eventDispatcher;
/**
* @param IConfig $config
* @param IPreview $previewManager
* @param IAppData $appData
* @param GeneratorHelper $helper
+ * @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(
IConfig $config,
IPreview $previewManager,
IAppData $appData,
- GeneratorHelper $helper
+ GeneratorHelper $helper,
+ EventDispatcherInterface $eventDispatcher
) {
$this->config = $config;
$this->previewManager = $previewManager;
$this->appData = $appData;
$this->helper = $helper;
+ $this->eventDispatcher = $eventDispatcher;
}
/**
@@ -78,6 +85,16 @@ class Generator {
* @throws NotFoundException
*/
public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) {
+ $this->eventDispatcher->dispatch(
+ IPreview::EVENT,
+ new GenericEvent($file,[
+ 'width' => $width,
+ 'height' => $height,
+ 'crop' => $crop,
+ 'mode' => $mode
+ ])
+ );
+
if ($mimeType === null) {
$mimeType = $file->getMimeType();
}
diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php
index a2ef9659b3b..799f94f2bef 100644
--- a/lib/private/PreviewManager.php
+++ b/lib/private/PreviewManager.php
@@ -35,6 +35,7 @@ use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig;
use OCP\IPreview;
use OCP\Preview\IProvider;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class PreviewManager implements IPreview {
/** @var IConfig */
@@ -46,6 +47,9 @@ class PreviewManager implements IPreview {
/** @var IAppData */
protected $appData;
+ /** @var EventDispatcherInterface */
+ protected $eventDispatcher;
+
/** @var Generator */
private $generator;
@@ -65,16 +69,21 @@ class PreviewManager implements IPreview {
protected $defaultProviders;
/**
- * Constructor
+ * PreviewManager constructor.
*
- * @param \OCP\IConfig $config
+ * @param IConfig $config
+ * @param IRootFolder $rootFolder
+ * @param IAppData $appData
+ * @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(IConfig $config,
IRootFolder $rootFolder,
- IAppData $appData) {
+ IAppData $appData,
+ EventDispatcherInterface $eventDispatcher) {
$this->config = $config;
$this->rootFolder = $rootFolder;
$this->appData = $appData;
+ $this->eventDispatcher = $eventDispatcher;
}
/**
@@ -165,7 +174,8 @@ class PreviewManager implements IPreview {
$this->appData,
new GeneratorHelper(
$this->rootFolder
- )
+ ),
+ $this->eventDispatcher
);
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 79efeb18d17..995dc8ed4a4 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -121,7 +121,8 @@ class Server extends ServerContainer implements IServerContainer {
return new PreviewManager(
$c->getConfig(),
$c->getRootFolder(),
- $c->getAppDataDir('preview')
+ $c->getAppDataDir('preview'),
+ $c->getEventDispatcher()
);
});
diff --git a/lib/public/IPreview.php b/lib/public/IPreview.php
index c6417b4d182..90f7a56b66c 100644
--- a/lib/public/IPreview.php
+++ b/lib/public/IPreview.php
@@ -43,6 +43,11 @@ use OCP\Files\NotFoundException;
*/
interface IPreview {
+ /**
+ * @since 9.2.0
+ */
+ const EVENT = self::class . ':' . 'PreviewRequested';
+
const MODE_FILL = 'fill';
const MODE_COVER = 'cover';