diff options
author | Julius Härtl <jus@bitgrid.net> | 2021-04-08 08:53:31 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2021-11-08 15:32:35 +0300 |
commit | c3e331f658f71f880ee379ea97302d969bf645b6 (patch) | |
tree | bbe1b2afd3049f86f6315763647598de565db22e | |
parent | 69ade4da1c08e37ab60267220b3f8cf200a39d54 (diff) |
Add support for Collabora Online Draw and odg files
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r-- | assets/drawing.otg | bin | 0 -> 8158 bytes | |||
-rw-r--r-- | assets/odgtemplate.otg | bin | 0 -> 8158 bytes | |||
-rw-r--r-- | css/viewer.scss | 6 | ||||
-rw-r--r-- | img/x-office-drawing.svg | 1 | ||||
-rw-r--r-- | lib/AppInfo/Application.php | 25 | ||||
-rw-r--r-- | lib/Capabilities.php | 10 | ||||
-rw-r--r-- | lib/Service/CapabilitiesService.php | 15 | ||||
-rw-r--r-- | lib/Template/CollaboraTemplateProvider.php | 6 | ||||
-rw-r--r-- | lib/TemplateManager.php | 30 | ||||
-rw-r--r-- | src/files.js | 2 |
10 files changed, 59 insertions, 36 deletions
diff --git a/assets/drawing.otg b/assets/drawing.otg Binary files differnew file mode 100644 index 00000000..f29cd812 --- /dev/null +++ b/assets/drawing.otg diff --git a/assets/odgtemplate.otg b/assets/odgtemplate.otg Binary files differnew file mode 100644 index 00000000..f29cd812 --- /dev/null +++ b/assets/odgtemplate.otg diff --git a/css/viewer.scss b/css/viewer.scss index 3c2aeec0..d45236dc 100644 --- a/css/viewer.scss +++ b/css/viewer.scss @@ -17,10 +17,14 @@ background-image: url('../img/x-office-spreadsheet.svg'); } -.icon-filetype-presentation{ +.icon-filetype-presentation { background-image: url('../img/x-office-presentation.svg'); } +.icon-filetype-draw { + background-image: url('../img/x-office-drawing.svg'); +} + .icon-collabora { opacity: 0.6; &:hover { diff --git a/img/x-office-drawing.svg b/img/x-office-drawing.svg new file mode 100644 index 00000000..352347b6 --- /dev/null +++ b/img/x-office-drawing.svg @@ -0,0 +1 @@ +<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 1c-.28 0-.5.22-.5.5v13c0 .28.22.5.5.5h11c.28 0 .5-.22.5-.5V4l-3-3H2.5zM4 6h2.8v1.2h2.4V6H12v3.2H9.2V8h-.8v3.2h.8V10H12v3.2H9.2V12H7.6V8h-.8v1.2H4V6z" style="fill:#ebc94a;fill-opacity:1"/></svg> diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 5701d50e..721e8031 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -84,7 +84,10 @@ class Application extends App implements IBootstrap { \OCP\Util::addScript('richdocuments', 'richdocuments-viewer'); }); - $context->injectFn(function(ITemplateManager $templateManager, IL10N $l10n, IConfig $config) { + $context->injectFn(function(ITemplateManager $templateManager, IL10N $l10n, IConfig $config, CapabilitiesService $capabilitiesService) { + if (empty($capabilitiesService->getCapabilities())) { + return; + } $ooxml = $config->getAppValue(self::APPNAME, 'doc_format', '') === 'ooxml'; $templateManager->registerTemplateFileCreator(function () use ($l10n, $ooxml) { $odtType = new TemplateFileCreator('richdocuments', $l10n->t('New document'), ($ooxml ? '.docx' : '.odt')); @@ -125,6 +128,18 @@ class Application extends App implements IBootstrap { $odpType->setRatio(16/9); return $odpType; }); + + if (!$capabilitiesService->hasDrawSupport()) { + return; + } + $templateManager->registerTemplateFileCreator(function () use ($l10n, $ooxml) { + $odpType = new TemplateFileCreator('richdocuments', $l10n->t('New graphic'), '.odg'); + $odpType->addMimetype('application/vnd.oasis.opendocument.graphics'); + $odpType->addMimetype('application/vnd.oasis.opendocument.graphics-template'); + $odpType->setIconClass('icon-filetype-draw'); + $odpType->setRatio(16/9); + return $odpType; + }); }); $context->injectFn(function (SymfonyAdapter $eventDispatcher) { @@ -159,14 +174,6 @@ class Application extends App implements IBootstrap { public function registerProvider() { $container = $this->getContainer(); - // Register mimetypes - /** @var Detection $detector */ - $detector = $container->query(\OCP\Files\IMimeTypeDetector::class); - $detector->getAllMappings(); - $detector->registerType('ott','application/vnd.oasis.opendocument.text-template'); - $detector->registerType('ots', 'application/vnd.oasis.opendocument.spreadsheet-template'); - $detector->registerType('otp', 'application/vnd.oasis.opendocument.presentation-template'); - /** @var IPreview $previewManager */ $previewManager = $container->query(IPreview::class); diff --git a/lib/Capabilities.php b/lib/Capabilities.php index c4c345b3..0e58d48f 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -93,10 +93,18 @@ class Capabilities implements ICapability { public function getCapabilities() { if (!$this->capabilities) { $collaboraCapabilities = $this->capabilitiesService->getCapabilities(); + $filteredMimetypes = self::MIMETYPES; + // If version is too old, draw is not supported + if (!$this->capabilitiesService->hasDrawSupport()) { + $filteredMimetypes = array_diff($filteredMimetypes, [ + 'application/vnd.oasis.opendocument.graphics', + 'application/vnd.oasis.opendocument.graphics-flat-xml', + ]); + } $this->capabilities = [ 'richdocuments' => [ 'version' => \OC::$server->getAppManager()->getAppVersion('richdocuments'), - 'mimetypes' => self::MIMETYPES, + 'mimetypes' => $filteredMimetypes, 'mimetypesNoDefaultOpen' => self::MIMETYPES_OPTIONAL, 'collabora' => $collaboraCapabilities, 'direct_editing' => isset($collaboraCapabilities['hasMobileSupport']) ?: false, diff --git a/lib/Service/CapabilitiesService.php b/lib/Service/CapabilitiesService.php index 58115795..3d18c957 100644 --- a/lib/Service/CapabilitiesService.php +++ b/lib/Service/CapabilitiesService.php @@ -72,22 +72,27 @@ class CapabilitiesService { return $this->capabilities; } - public function hasTemplateSaveAs() { + public function hasDrawSupport(): bool { + $productVersion = $this->getCapabilities()['productVersion'] ?? '0.0.0.0'; + return version_compare($productVersion, '6.4.7', '>='); + } + + public function hasTemplateSaveAs(): bool { return $this->getCapabilities()['hasTemplateSaveAs'] ?? false; } - public function hasTemplateSource() { + public function hasTemplateSource(): bool { return $this->getCapabilities()['hasTemplateSource'] ?? false; } - public function clear() { + public function clear(): void { $this->cache->remove('capabilities'); } - public function refetch() { + public function refetch(): void { $remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url'); if ($remoteHost === '') { - return []; + return; } $capabilitiesEndpoint = rtrim($remoteHost, '/') . '/hosting/capabilities'; diff --git a/lib/Template/CollaboraTemplateProvider.php b/lib/Template/CollaboraTemplateProvider.php index 669f54d6..4246f98b 100644 --- a/lib/Template/CollaboraTemplateProvider.php +++ b/lib/Template/CollaboraTemplateProvider.php @@ -53,10 +53,12 @@ class CollaboraTemplateProvider implements ICustomTemplateProvider { public function getCustomTemplates(string $mimetype): array { if (in_array($mimetype, TemplateManager::MIMES_DOCUMENTS)) { $type = 'document'; - } else if (in_array($mimetype, TemplateManager::MIMES_SHEETS)) { + } elseif (in_array($mimetype, TemplateManager::MIMES_SHEETS)) { $type = 'spreadsheet'; - } else if (in_array($mimetype, TemplateManager::MIMES_PRESENTATIONS)) { + } elseif (in_array($mimetype, TemplateManager::MIMES_PRESENTATIONS)) { $type = 'presentation'; + } elseif (in_array($mimetype, TemplateManager::MIMES_DRAWINGS)) { + $type = 'drawing'; } else { return []; } diff --git a/lib/TemplateManager.php b/lib/TemplateManager.php index b54848ff..d8a01932 100644 --- a/lib/TemplateManager.php +++ b/lib/TemplateManager.php @@ -72,37 +72,30 @@ class TemplateManager { 'application/vnd.openxmlformats-officedocument.presentationml.template', 'application/vnd.ms-powerpoint' ]; + const MIMES_DRAWINGS = [ + 'application/vnd.oasis.opendocument.graphics-template', + ]; /** @var array Template mime types match */ static public $tplTypes = [ 'document' => self::MIMES_DOCUMENTS, 'spreadsheet' => self::MIMES_SHEETS, - 'presentation' => self::MIMES_PRESENTATIONS + 'presentation' => self::MIMES_PRESENTATIONS, + 'drawing' => self::MIMES_DRAWINGS, ]; const TYPE_EXTENTION = [ 'document' => 'odt', 'spreadsheet' => 'ods', - 'presentation' => 'odp' + 'presentation' => 'odp', + 'drawing' => 'odg', ]; const TYPE_EXTENSION_OOXML = [ 'document' => 'docx', 'spreadsheet' => 'xlsx', - 'presentation' => 'pptx' - ]; - - const EMPTY_TEMPLATE_ID_TYPE = [ - -1 => 'document', - -2 => 'spreadsheet', - -3 => 'presentation', + 'presentation' => 'pptx', ]; - const EMPTY_TEMPLATE_TYPE_ID = [ - 'document' => -1, - 'spreadsheet' => -2, - 'presentation' => -3, - ]; - /** * Template manager @@ -218,6 +211,7 @@ class TemplateManager { 'document.ott', 'spreadsheet.ots', 'presentation.otp', + 'drawing.otg', ]; foreach ($templates as $template) { @@ -451,7 +445,7 @@ class TemplateManager { 'preview' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.getPreview', ['fileId' => $template->getId()]), 'type' => $this->flipTypes()[$template->getMimeType()], 'delete' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.delete', ['fileId' => $template->getId()]), - 'extension' => $ooxml ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType], + 'extension' => ($ooxml && isset(self::TYPE_EXTENSION_OOXML[$documentType])) ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType], ]; } @@ -478,13 +472,13 @@ class TemplateManager { 'id' => $template->getId(), 'name' => $this->l->t('Empty'), 'type' => $this->flipTypes()[$template->getMimeType()], - 'extension' => $ooxml ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType], + 'extension' => ($ooxml && isset(self::TYPE_EXTENSION_OOXML[$documentType])) ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType], ]; } public function isValidTemplateMime($mime, $type = null) { if ($type === null) { - $allMimes = array_merge(self::$tplTypes['document'], self::$tplTypes['spreadsheet'], self::$tplTypes['presentation']); + $allMimes = array_merge(self::$tplTypes['document'], self::$tplTypes['spreadsheet'], self::$tplTypes['presentation'], self::$tplTypes['drawing']); if (!in_array($mime, $allMimes)) { return false; } diff --git a/src/files.js b/src/files.js index ad1744bb..7ce2e37c 100644 --- a/src/files.js +++ b/src/files.js @@ -363,6 +363,8 @@ $(document).ready(function() { } } + OC.MimeType._mimeTypeIcons['application/vnd.oasis.opendocument.graphics'] = OC.imagePath('richdocuments', 'x-office-draw') + // Open the template picker if there was a create parameter detected on load if (Preload.create && Preload.create.type && Preload.create.filename) { FilesAppIntegration.preloadCreate() |