Skip to content

Commit bf01bfb

Browse files
committed
Add support for Collabora Online Draw and odg files
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent 69ade4d commit bf01bfb

File tree

10 files changed

+56
-33
lines changed

10 files changed

+56
-33
lines changed

assets/drawing.otg

7.97 KB
Binary file not shown.

assets/odgtemplate.otg

7.97 KB
Binary file not shown.

css/viewer.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
background-image: url('../img/x-office-spreadsheet.svg');
1818
}
1919

20-
.icon-filetype-presentation{
20+
.icon-filetype-presentation {
2121
background-image: url('../img/x-office-presentation.svg');
2222
}
2323

24+
.icon-filetype-draw {
25+
background-image: url('../img/x-office-drawing.svg');
26+
}
27+
2428
.icon-collabora {
2529
opacity: 0.6;
2630
&:hover {

img/x-office-drawing.svg

Lines changed: 1 addition & 0 deletions
Loading

lib/AppInfo/Application.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ public function boot(IBootContext $context): void {
8484
\OCP\Util::addScript('richdocuments', 'richdocuments-viewer');
8585
});
8686

87-
$context->injectFn(function(ITemplateManager $templateManager, IL10N $l10n, IConfig $config) {
87+
$context->injectFn(function(ITemplateManager $templateManager, IL10N $l10n, IConfig $config, CapabilitiesService $capabilitiesService) {
88+
if (empty($capabilitiesService->getCapabilities())) {
89+
return;
90+
}
8891
$ooxml = $config->getAppValue(self::APPNAME, 'doc_format', '') === 'ooxml';
8992
$templateManager->registerTemplateFileCreator(function () use ($l10n, $ooxml) {
9093
$odtType = new TemplateFileCreator('richdocuments', $l10n->t('New document'), ($ooxml ? '.docx' : '.odt'));
@@ -125,6 +128,18 @@ public function boot(IBootContext $context): void {
125128
$odpType->setRatio(16/9);
126129
return $odpType;
127130
});
131+
132+
if (!$capabilitiesService->hasDrawSupport()) {
133+
return;
134+
}
135+
$templateManager->registerTemplateFileCreator(function () use ($l10n, $ooxml) {
136+
$odpType = new TemplateFileCreator('richdocuments', $l10n->t('New graphic'), '.odg');
137+
$odpType->addMimetype('application/vnd.oasis.opendocument.graphics');
138+
$odpType->addMimetype('application/vnd.oasis.opendocument.graphics-template');
139+
$odpType->setIconClass('icon-filetype-draw');
140+
$odpType->setRatio(16/9);
141+
return $odpType;
142+
});
128143
});
129144

130145
$context->injectFn(function (SymfonyAdapter $eventDispatcher) {
@@ -159,14 +174,6 @@ function() {
159174
public function registerProvider() {
160175
$container = $this->getContainer();
161176

162-
// Register mimetypes
163-
/** @var Detection $detector */
164-
$detector = $container->query(\OCP\Files\IMimeTypeDetector::class);
165-
$detector->getAllMappings();
166-
$detector->registerType('ott','application/vnd.oasis.opendocument.text-template');
167-
$detector->registerType('ots', 'application/vnd.oasis.opendocument.spreadsheet-template');
168-
$detector->registerType('otp', 'application/vnd.oasis.opendocument.presentation-template');
169-
170177
/** @var IPreview $previewManager */
171178
$previewManager = $container->query(IPreview::class);
172179

lib/Capabilities.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,18 @@ public function __construct(IL10N $l10n, AppConfig $config, CapabilitiesService
9393
public function getCapabilities() {
9494
if (!$this->capabilities) {
9595
$collaboraCapabilities = $this->capabilitiesService->getCapabilities();
96+
$filteredMimetypes = self::MIMETYPES;
97+
// If version is too old, draw is not supported
98+
if (!$this->capabilitiesService->hasDrawSupport()) {
99+
$filteredMimetypes = array_diff($filteredMimetypes, [
100+
'application/vnd.oasis.opendocument.graphics',
101+
'application/vnd.oasis.opendocument.graphics-flat-xml',
102+
]);
103+
}
96104
$this->capabilities = [
97105
'richdocuments' => [
98106
'version' => \OC::$server->getAppManager()->getAppVersion('richdocuments'),
99-
'mimetypes' => self::MIMETYPES,
107+
'mimetypes' => $filteredMimetypes,
100108
'mimetypesNoDefaultOpen' => self::MIMETYPES_OPTIONAL,
101109
'collabora' => $collaboraCapabilities,
102110
'direct_editing' => isset($collaboraCapabilities['hasMobileSupport']) ?: false,

lib/Service/CapabilitiesService.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,27 @@ public function getCapabilities() {
7272
return $this->capabilities;
7373
}
7474

75-
public function hasTemplateSaveAs() {
75+
public function hasDrawSupport(): bool {
76+
$productVersion = $this->getCapabilities()['productVersion'] ?? '0.0.0.0';
77+
return version_compare($productVersion, '6.4.7', '>=');
78+
}
79+
80+
public function hasTemplateSaveAs(): bool {
7681
return $this->getCapabilities()['hasTemplateSaveAs'] ?? false;
7782
}
7883

79-
public function hasTemplateSource() {
84+
public function hasTemplateSource(): bool {
8085
return $this->getCapabilities()['hasTemplateSource'] ?? false;
8186
}
8287

83-
public function clear() {
88+
public function clear(): void {
8489
$this->cache->remove('capabilities');
8590
}
8691

87-
public function refetch() {
92+
public function refetch(): void {
8893
$remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url');
8994
if ($remoteHost === '') {
90-
return [];
95+
return;
9196
}
9297
$capabilitiesEndpoint = rtrim($remoteHost, '/') . '/hosting/capabilities';
9398

lib/Template/CollaboraTemplateProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public function getCustomTemplates(string $mimetype): array {
5757
$type = 'spreadsheet';
5858
} else if (in_array($mimetype, TemplateManager::MIMES_PRESENTATIONS)) {
5959
$type = 'presentation';
60+
} else if (in_array($mimetype, TemplateManager::MIMES_DRAWINGS)) {
61+
$type = 'drawing';
6062
} else {
6163
return [];
6264
}

lib/TemplateManager.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,23 @@ class TemplateManager {
7272
'application/vnd.openxmlformats-officedocument.presentationml.template',
7373
'application/vnd.ms-powerpoint'
7474
];
75+
const MIMES_DRAWINGS = [
76+
'application/vnd.oasis.opendocument.graphics-template'
77+
];
7578

7679
/** @var array Template mime types match */
7780
static public $tplTypes = [
7881
'document' => self::MIMES_DOCUMENTS,
7982
'spreadsheet' => self::MIMES_SHEETS,
80-
'presentation' => self::MIMES_PRESENTATIONS
83+
'presentation' => self::MIMES_PRESENTATIONS,
84+
'drawing' => self::MIMES_DRAWINGS
8185
];
8286

8387
const TYPE_EXTENTION = [
8488
'document' => 'odt',
8589
'spreadsheet' => 'ods',
86-
'presentation' => 'odp'
90+
'presentation' => 'odp',
91+
'drawing' => 'odg'
8792
];
8893

8994
const TYPE_EXTENSION_OOXML = [
@@ -92,18 +97,6 @@ class TemplateManager {
9297
'presentation' => 'pptx'
9398
];
9499

95-
const EMPTY_TEMPLATE_ID_TYPE = [
96-
-1 => 'document',
97-
-2 => 'spreadsheet',
98-
-3 => 'presentation',
99-
];
100-
const EMPTY_TEMPLATE_TYPE_ID = [
101-
'document' => -1,
102-
'spreadsheet' => -2,
103-
'presentation' => -3,
104-
];
105-
106-
107100
/**
108101
* Template manager
109102
*
@@ -218,6 +211,7 @@ private function getEmpty($type = null) {
218211
'document.ott',
219212
'spreadsheet.ots',
220213
'presentation.otp',
214+
'drawing.otg',
221215
];
222216

223217
foreach ($templates as $template) {
@@ -451,7 +445,7 @@ public function formatNodeReturn(File $template) {
451445
'preview' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.getPreview', ['fileId' => $template->getId()]),
452446
'type' => $this->flipTypes()[$template->getMimeType()],
453447
'delete' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.delete', ['fileId' => $template->getId()]),
454-
'extension' => $ooxml ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
448+
'extension' => ($ooxml && isset(self::TYPE_EXTENSION_OOXML[$documentType])) ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
455449
];
456450
}
457451

@@ -478,13 +472,13 @@ public function formatEmpty(File $template) {
478472
'id' => $template->getId(),
479473
'name' => $this->l->t('Empty'),
480474
'type' => $this->flipTypes()[$template->getMimeType()],
481-
'extension' => $ooxml ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
475+
'extension' => ($ooxml && isset(self::TYPE_EXTENSION_OOXML[$documentType])) ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
482476
];
483477
}
484478

485479
public function isValidTemplateMime($mime, $type = null) {
486480
if ($type === null) {
487-
$allMimes = array_merge(self::$tplTypes['document'], self::$tplTypes['spreadsheet'], self::$tplTypes['presentation']);
481+
$allMimes = array_merge(self::$tplTypes['document'], self::$tplTypes['spreadsheet'], self::$tplTypes['presentation'], self::$tplTypes['drawing']);
488482
if (!in_array($mime, $allMimes)) {
489483
return false;
490484
}

src/files.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ $(document).ready(function() {
363363
}
364364
}
365365

366+
OC.MimeType._mimeTypeIcons['application/vnd.oasis.opendocument.graphics'] = OC.imagePath('richdocuments', 'x-office-draw')
367+
366368
// Open the template picker if there was a create parameter detected on load
367369
if (Preload.create && Preload.create.type && Preload.create.filename) {
368370
FilesAppIntegration.preloadCreate()

0 commit comments

Comments
 (0)