Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added experimental support to use ODF as default new file format #886

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
var toolbarNoTabs = $("#onlyofficeToolbarNoTabs").is(":checked");
var reviewDisplay = $("input[type='radio'][name='reviewDisplay']:checked").attr("id").replace("onlyofficeReviewDisplay_", "");
var theme = $("input[type='radio'][name='theme']:checked").attr("id").replace("onlyofficeTheme_", "");
var defaultOdf = $("#defaultOdf").is(":checked");

$.ajax({
method: "PUT",
Expand All @@ -229,7 +230,9 @@
help: help,
toolbarNoTabs: toolbarNoTabs,
reviewDisplay: reviewDisplay,
theme: theme
theme: theme,
defaultOdf: defaultOdf

},
success: function onSuccess(response) {
$(".section-onlyoffice").removeClass("icon-loading");
Expand Down
27 changes: 27 additions & 0 deletions lib/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ class AppConfig {
*/
private $_editors_check_interval = "editors_check_interval";

/**
* The config key for the setting default odf
*
* @var string
*/
private $_defaultOdf = "default_odf";

/**
* @param string $AppName - application name
*/
Expand Down Expand Up @@ -886,6 +893,26 @@ public function GetCustomizationToolbarNoTabs() {
return $this->config->getAppValue($this->appName, $this->_customizationToolbarNoTabs, "true") === "true";
}

/**
* Save the default ODF setting
*
* @param bool $value - default ODF
*/
public function SetDefaultOdf($value) {
$this->logger->info("Set ODF as default: " . json_encode($value), ["app" => $this->appName]);

$this->config->setAppValue($this->appName, $this->_defaultOdf, json_encode($value));
}

/**
* Get the default ODF setting
*
* @return bool
*/
public function GetDefaultOdf() {
return $this->config->getAppValue($this->appName, $this->_defaultOdf, "false") === "true";
}

/**
* Save review viewing mode setting
*
Expand Down
36 changes: 30 additions & 6 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,26 +308,50 @@ function (FileCreatedFromTemplateEvent $event) {
&& $this->appConfig->isUserAllowedToUse()) {

$templateManager->registerTemplateFileCreator(function () use ($appName, $trans) {
$wordTemplate = new TemplateFileCreator($appName, $trans->t("New document"), ".docx");
$wordTemplate->addMimetype("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
$extension = ".docx";
$mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";

if ($this->appConfig->GetDefaultOdf()) {
$extension = ".odt";
$mimeType = "application/vnd.oasis.opendocument.text";
}
$wordTemplate = new TemplateFileCreator($appName, $trans->t("New document"), $extension);
$wordTemplate->addMimetype($mimeType);
$wordTemplate->setIconClass("icon-onlyoffice-new-docx");
$wordTemplate->setRatio(21/29.7);

return $wordTemplate;
});

$templateManager->registerTemplateFileCreator(function () use ($appName, $trans) {
$cellTemplate = new TemplateFileCreator($appName, $trans->t("New spreadsheet"), ".xlsx");
$cellTemplate->addMimetype("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
$extension = ".xlsx";
$mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

if ($this->appConfig->GetDefaultOdf()) {
$extension = ".ods";
$mimeType = "application/vnd.oasis.opendocument.spreadsheet";
}
$cellTemplate = new TemplateFileCreator($appName, $trans->t("New spreadsheet"), $extension);
$cellTemplate->addMimetype($mimeType);
$cellTemplate->setIconClass("icon-onlyoffice-new-xlsx");
$cellTemplate->setRatio(21/29.7);

return $cellTemplate;
});

$templateManager->registerTemplateFileCreator(function () use ($appName, $trans) {
$slideTemplate = new TemplateFileCreator($appName, $trans->t("New presentation"), ".pptx");
$slideTemplate->addMimetype("application/vnd.openxmlformats-officedocument.presentationml.presentation");
$extension = ".pptx";
$mimeType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";

if ($this->appConfig->GetDefaultOdf()) {
$extension = ".odp";
$mimeType = "application/vnd.oasis.opendocument.presentation";
}
$slideTemplate = new TemplateFileCreator($appName, $trans->t("New presentation"), $extension);
$slideTemplate->addMimetype($mimeType);
$slideTemplate->setIconClass("icon-onlyoffice-new-pptx");
$slideTemplate->setRatio(16/9);

return $slideTemplate;
});
}
Expand Down
8 changes: 6 additions & 2 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public function index() {
"tagsEnabled" => \OC::$server->getAppManager()->isEnabledForUser("systemtags"),
"reviewDisplay" => $this->config->GetCustomizationReviewDisplay(),
"theme" => $this->config->GetCustomizationTheme(),
"templates" => $this->GetGlobalTemplates()
"templates" => $this->GetGlobalTemplates(),
"defaultOdf" => $this->config->GetDefaultOdf()
];
return new TemplateResponse($this->appName, "settings", $data, "blank");
}
Expand Down Expand Up @@ -211,6 +212,7 @@ public function SaveAddress($documentserver,
* @param bool $help - display help
* @param bool $toolbarNoTabs - display toolbar tab
* @param string $reviewDisplay - review viewing mode
* @param bool $defaultOdf - use ODF formats as default
*
* @return array
*/
Expand All @@ -228,7 +230,8 @@ public function SaveCommon($defFormats,
$help,
$toolbarNoTabs,
$reviewDisplay,
$theme
$theme,
$defaultOdf
) {

$this->config->SetDefaultFormats($defFormats);
Expand All @@ -246,6 +249,7 @@ public function SaveCommon($defFormats,
$this->config->SetCustomizationToolbarNoTabs($toolbarNoTabs);
$this->config->SetCustomizationReviewDisplay($reviewDisplay);
$this->config->SetCustomizationTheme($theme);
$this->config->SetDefaultOdf($defaultOdf);

return [
];
Expand Down
14 changes: 7 additions & 7 deletions lib/FileCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ public function getId(): string {
* @return string
*/
public function getName(): string {
switch ($this->format) {
case "xlsx":
return $this->trans->t("New spreadsheet");
case "pptx":
return $this->trans->t("New presentation");
}
return $this->trans->t("New document");
$formats = [
"xlsx" => "Spreadsheet",
"ods" => "Spreadsheet",
"pptx" => "Presentation",
"odp" => "Presentation"
];
return $this->trans->t($formats[$this->format] ?? "Document"); // Document for docx/odt
}

/**
Expand Down
45 changes: 32 additions & 13 deletions lib/TemplateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ public static function GetTypeTemplate($mime) {
return "spreadsheet";
case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
return "presentation";
case "application/vnd.oasis.opendocument.text":
return "document";
case "application/vnd.oasis.opendocument.spreadsheet":
return "spreadsheet";
case "application/vnd.oasis.opendocument.presentation":
return "presentation";
}

return "";
Expand All @@ -142,16 +148,24 @@ public static function GetTypeTemplate($mime) {
* @return string
*/
public static function GetMimeTemplate($type) {
switch($type) {
case "document":
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
case "spreadsheet":
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
case "presentation":
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";

$defaultMimes = [
"document" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"spreadsheet" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"presentation" => "application/vnd.openxmlformats-officedocument.presentationml.presentation"
];

$appConfig = new AppConfig(self::$appName);
if ($appConfig->GetDefaultOdf()) {
$defaultMimes = [
"document" => "application/vnd.oasis.opendocument.text",
"spreadsheet" => "application/vnd.oasis.opendocument.spreadsheet",
"presentation" => "application/vnd.oasis.opendocument.presentation"
];
}

return "";
return $defaultMimes[$type] ?? "";

}

/**
Expand All @@ -163,11 +177,16 @@ public static function GetMimeTemplate($type) {
*/
public static function IsTemplateType($name) {
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
switch($ext) {
case "docx":
case "xlsx":
case "pptx":
return true;

$supportedExtensions = ["docx", "xlsx", "pptx"];

$appConfig = new AppConfig(self::$appName);
if ($appConfig->GetDefaultOdf()) {
$supportedExtensions = ["odt", "ods", "odp"];
}

if (in_array($ext, $supportedExtensions)) {
return true;
}

return false;
Expand Down
6 changes: 6 additions & 0 deletions templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
<button id="onlyofficeClearVersionHistory" class="button"><?php p($l->t("Clear")) ?></button>
</p>

<p>
<input type="checkbox" class="checkbox" id="defaultOdf"
<?php if ($_["defaultOdf"]) { ?>checked="checked"<?php } ?> />
<label for="defaultOdf"><?php p($l->t("Create ODF format files by default")) ?></label>
</p>

<p class="onlyoffice-header"><?php p($l->t("The default application for opening the format")) ?></p>
<div class="onlyoffice-exts">
<?php foreach ($_["formats"] as $format => $setting) { ?>
Expand Down