summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-07-30 16:29:18 +0200
committerRobin Appelman <icewind@owncloud.com>2014-07-30 16:31:37 +0200
commit4a9b0d5465927b0b4cc856cebbc724264ffdd404 (patch)
tree2203c4dd985bebc76fd92b3237f6f72c3d8f7077 /lib
parent2946a63f6bbcf298a30bb89ed72dbb650bc39def (diff)
downloadnextcloud-server-4a9b0d5465927b0b4cc856cebbc724264ffdd404.tar.gz
nextcloud-server-4a9b0d5465927b0b4cc856cebbc724264ffdd404.zip
Use svg mimeicons for empty text files
Diffstat (limited to 'lib')
-rwxr-xr-xlib/private/preview.php30
-rw-r--r--lib/private/preview/provider.php10
-rw-r--r--lib/private/preview/txt.php10
-rwxr-xr-xlib/private/previewmanager.php18
-rw-r--r--lib/public/ipreview.php7
5 files changed, 71 insertions, 4 deletions
diff --git a/lib/private/preview.php b/lib/private/preview.php
index 8089379bde5..c64cd19501e 100755
--- a/lib/private/preview.php
+++ b/lib/private/preview.php
@@ -13,6 +13,7 @@
*/
namespace OC;
+use OC\Files\Filesystem;
use OC\Preview\Provider;
require_once 'preview/image.php';
@@ -726,6 +727,35 @@ class Preview {
}
/**
+ * Check if a preview can be generated for a file
+ *
+ * @param \OC\Files\FileInfo $file
+ * @return bool
+ */
+ public static function isAvailable($file) {
+ if (!\OC_Config::getValue('enable_previews', true)) {
+ return false;
+ }
+
+ //check if there are preview backends
+ if (empty(self::$providers)) {
+ self::initProviders();
+ }
+
+ //remove last element because it has the mimetype *
+ $providers = array_slice(self::$providers, 0, -1);
+ foreach ($providers as $supportedMimeType => $provider) {
+ /**
+ * @var \OC\Preview\Provider $provider
+ */
+ if (preg_match($supportedMimeType, $file->getMimetype())) {
+ return $provider->isAvailable($file);
+ }
+ }
+ return false;
+ }
+
+ /**
* @param string $mimeType
* @return bool
*/
diff --git a/lib/private/preview/provider.php b/lib/private/preview/provider.php
index f769823f6e6..f544c2c4b13 100644
--- a/lib/private/preview/provider.php
+++ b/lib/private/preview/provider.php
@@ -11,6 +11,16 @@ abstract class Provider {
abstract public function getMimeType();
/**
+ * Check if a preview can be generated for $path
+ *
+ * @param string $path
+ * @return bool
+ */
+ public function isAvailable($path) {
+ return true;
+ }
+
+ /**
* get thumbnail for file at path $path
* @param string $path Path of file
* @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
diff --git a/lib/private/preview/txt.php b/lib/private/preview/txt.php
index 063543c6279..b81436baa06 100644
--- a/lib/private/preview/txt.php
+++ b/lib/private/preview/txt.php
@@ -14,6 +14,16 @@ class TXT extends Provider {
}
/**
+ * Check if a preview can be generated for $path
+ *
+ * @param \OC\Files\FileInfo $file
+ * @return bool
+ */
+ public function isAvailable($file) {
+ return $file->getSize() > 5;
+ }
+
+ /**
* @param string $path
* @param int $maxX
* @param int $maxY
diff --git a/lib/private/previewmanager.php b/lib/private/previewmanager.php
index 23dbee13c7d..85bf609743d 100755
--- a/lib/private/previewmanager.php
+++ b/lib/private/previewmanager.php
@@ -14,25 +14,35 @@ use OCP\IPreview;
class PreviewManager implements IPreview {
/**
* return a preview of a file
+ *
* @param string $file The path to the file where you want a thumbnail from
* @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
* @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
* @param boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly
* @return \OCP\Image
*/
- function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false)
- {
+ function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false) {
$preview = new \OC\Preview('', '/', $file, $maxX, $maxY, $scaleUp);
return $preview->getPreview();
}
/**
* returns true if the passed mime type is supported
+ *
* @param string $mimeType
* @return boolean
*/
- function isMimeSupported($mimeType = '*')
- {
+ function isMimeSupported($mimeType = '*') {
return \OC\Preview::isMimeSupported($mimeType);
}
+
+ /**
+ * Check if a preview can be generated for a file
+ *
+ * @param \OC\Files\FileInfo $file
+ * @return bool
+ */
+ function isAvailable($file) {
+ return \OC\Preview::isAvailable($file);
+ }
}
diff --git a/lib/public/ipreview.php b/lib/public/ipreview.php
index f74472ad368..cc756ef80d3 100644
--- a/lib/public/ipreview.php
+++ b/lib/public/ipreview.php
@@ -57,4 +57,11 @@ interface IPreview
*/
function isMimeSupported($mimeType = '*');
+ /**
+ * Check if a preview can be generated for a file
+ *
+ * @param \OCP\Files\FileInfo $file
+ * @return bool
+ */
+ function isAvailable($file);
}