Warning, /graphics/peruse/src/creator/qml/BookBinaryEditor.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright (C) 2020 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) version 3, or any 0008 * later version accepted by the membership of KDE e.V. (or its 0009 * successor approved by the membership of KDE e.V.), which shall 0010 * act as a proxy defined in Section 6 of version 3 of the license. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 * 0020 */ 0021 0022 import QtQuick 2.12 0023 import QtQuick.Layouts 1.4 0024 import QtQuick.Controls 2.12 as QtControls 0025 import QtQuick.Dialogs 1.3 0026 0027 import org.kde.kirigami 2.13 as Kirigami 0028 0029 import org.kde.peruse 0.1 as Peruse 0030 0031 /** 0032 * @brief A sheet which lets you edit the details of a single embedded data binary 0033 */ 0034 Kirigami.OverlaySheet { 0035 id: editBinarySheet; 0036 property QtObject binary: null; 0037 function editBinary(binaryObject) { 0038 editBinarySheet.binary = binaryObject; 0039 binaryId.text = binaryObject.id; 0040 binaryContentType.text = binaryObject.contentType; 0041 open(); 0042 } 0043 showCloseButton: true 0044 header: RowLayout { 0045 Kirigami.Heading { 0046 text: i18nc("title text for a sheet which lets the user edit a binary entry", "Edit Binary"); 0047 Layout.fillWidth: true; 0048 elide: Text.ElideRight; 0049 } 0050 QtControls.ToolButton { 0051 icon.name: "document-save"; 0052 text: i18nc("label for a button which updates the binary with the new details", "OK"); 0053 onClicked: { 0054 editBinarySheet.binary.id = binaryId.text; 0055 editBinarySheet.binary.contentType = binaryContentType.text; 0056 editBinarySheet.close(); 0057 } 0058 } 0059 } 0060 Kirigami.FormLayout { 0061 QtControls.TextField { 0062 id: binaryId; 0063 Layout.fillWidth: true; 0064 Kirigami.FormData.label: i18nc("Label for the binary ID input field", "ID"); 0065 placeholderText: i18nc("Placeholder text for the binary ID input field", "Enter the name of your binary here (often a filename)"); 0066 } 0067 QtControls.TextField { 0068 id: binaryContentType; 0069 Kirigami.FormData.label: i18nc("Label for the binary content type input field", "Content Type"); 0070 Layout.fillWidth: true; 0071 placeholderText: i18nc("Placeholder text for the binary content type input field", "Enter the content type of your binary here (aka mimetype)"); 0072 } 0073 RowLayout { 0074 Layout.fillWidth: true; 0075 Kirigami.FormData.label: i18nc("Label for the field which describes the data currently held by the current instance", "Current Data"); 0076 QtControls.Label { 0077 id: binaryDataAmount; 0078 Layout.fillWidth: true; 0079 text: { 0080 if (editBinarySheet.binary !== null && editBinarySheet.binary.size > 0) { 0081 return i18nc("Label used in the binary editor sheet to describe the size of the binary data contained in the current instance", "%1 bytes", editBinarySheet.binary.size); 0082 } else { 0083 return i18nc("Label used in the binary editor sheet when there is no data in the current instance", "No data set"); 0084 } 0085 } 0086 } 0087 QtControls.Button { 0088 id: binaryDataImport; 0089 text: i18nc("Label for the button in the binary editor sheet which lets the user replace the data contained in the current instance", "Import Data..."); 0090 icon.name: "document-open-data"; 0091 property string fileName; 0092 function addFile() { 0093 editBinarySheet.binary.contentType = peruseConfig.getFilesystemProperty(fileName, "mimetype"); 0094 editBinarySheet.binary.setDataFromFile(fileName); 0095 binaryContentType.text = editBinarySheet.binary.contentType; 0096 // Reset the ID if and only if the text field is empty, or the ID is the default identifier in the user's language 0097 if (binaryId.text === "" || binaryId.text === i18nc("The initial identifier used for a newly created binary data element", "Unnamed Binary")) { 0098 editBinarySheet.binary.id = fileName.split("/").pop(); 0099 binaryId.text = editBinarySheet.binary.id; 0100 } 0101 fileName = ""; 0102 } 0103 onClicked: { openDlg.open(); } 0104 FileDialog { 0105 id: openDlg; 0106 title: i18nc("@title:window standard file open dialog used to add file data into the book", "Pick A File To Add"); 0107 folder: mainWindow.homeDir(); 0108 nameFilters: [ 0109 i18nc("The file type filter for showing all files", "All files %1", "(*)") 0110 ] 0111 property int splitPos: osIsWindows ? 8 : 7; 0112 onAccepted: { 0113 if (openDlg.fileUrl.toString().substring(0, 7) === "file://") { 0114 var aOk = false; 0115 binaryDataImport.fileName = openDlg.fileUrl.toString().substring(splitPos); 0116 // Make sure we're not just loading ginormous files, warn after 10MiB of size 0117 var byteSize = peruseConfig.getFilesystemProperty(binaryDataImport.fileName, "bytes"); 0118 if (byteSize > 0) { 0119 aOk = true; 0120 } 0121 if (aOk && byteSize > 10485760) { 0122 aOk = false; // let the user make the choice... 0123 fileSizeOkSheet.open(); 0124 } 0125 // Only keep going if we're all good 0126 if (aOk) { 0127 binaryDataImport.addFile(); 0128 } 0129 } 0130 } 0131 onRejected: { 0132 // Just do nothing, we don't really care... 0133 } 0134 } 0135 MessageBoxSheet { 0136 id: fileSizeOkSheet; 0137 title: i18nc("@title:window a message box used to ask the user if they really want to add a very large file to their book", "Very Large File"); 0138 text: i18nc("The main query text for a message box used to ask the user if they really want to add a very large file to their book", "The file you are attempting to add, %1, is more than 10MiB. Are you sure you want to add it to the book?", binaryDataImport.fileName); 0139 actions: [ 0140 QtControls.Action { 0141 text: i18nc("The option used to let the user agree to the proposed action", "Yes, Add Large File"); 0142 onTriggered: { binaryDataImport.addFile(); } 0143 }, 0144 QtControls.Action { 0145 text: i18nc("The option used to let the user abort the proposed action", "Don't Add"); 0146 onTriggered: { binaryDataImport.fileName = ""; } 0147 } 0148 ] 0149 } 0150 } 0151 } 0152 } 0153 }