Warning, /multimedia/kid3/src/qml/app/RenameDirectoryPage.qml is written in an unsupported language. File is not indexed.
0001 /**
0002 * \file RenameDirectoryPage.qml
0003 * Rename directory page.
0004 *
0005 * \b Project: Kid3
0006 * \author Urs Fleisch
0007 * \date 16 Feb 2015
0008 *
0009 * Copyright (C) 2015-2019 Urs Fleisch
0010 *
0011 * This program is free software; you can redistribute it and/or modify
0012 * it under the terms of the GNU Lesser General Public License as published by
0013 * the Free Software Foundation; version 3.
0014 *
0015 * This program is distributed in the hope that it will be useful,
0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0018 * GNU Lesser General Public License for more details.
0019 *
0020 * You should have received a copy of the GNU Lesser General Public License
0021 * along with this program. If not, see <http://www.gnu.org/licenses/>.
0022 */
0023
0024 import QtQuick 2.11
0025 import QtQuick.Layouts 1.11
0026 import QtQuick.Controls 2.4
0027 import Kid3 1.1 as Kid3
0028
0029 Page {
0030 id: page
0031
0032 property int tagMask: Kid3.Frame.TagV2V1
0033 property string format
0034 property bool create: false
0035 property variant formats
0036
0037 title: qsTr("Rename Folder")
0038
0039 Connections {
0040 target: app.dirRenamer
0041 onActionScheduled: {
0042 var str = ""
0043 for (var i = 0; i < actionStrs.length; ++i) {
0044 if (i > 0)
0045 str += " "
0046 str += actionStrs[i]
0047 str += "\n"
0048 }
0049 textArea.text += str
0050 textArea.cursorPosition = textArea.text.length
0051 }
0052 }
0053
0054 header: ToolBar {
0055 IconButton {
0056 id: prevButton
0057 anchors.left: parent.left
0058 anchors.verticalCenter: parent.verticalCenter
0059 iconName: "go-previous"
0060 color: titleLabel.color
0061 width: visible ? height : 0
0062 visible: page.StackView.view && page.StackView.view.depth > 1
0063 onClicked: page.StackView.view.pop()
0064 }
0065 Label {
0066 id: titleLabel
0067 anchors.left: prevButton.right
0068 anchors.right: startButton.left
0069 anchors.verticalCenter: parent.verticalCenter
0070 clip: true
0071 text: page.title
0072 }
0073 ToolButton {
0074 id: startButton
0075 anchors.right: parent.right
0076 anchors.margins: constants.margins
0077 text: qsTr("Start")
0078 onClicked: {
0079 var errorMsg = app.performRenameActions()
0080 if (errorMsg) {
0081 textArea.text += qsTr("Error") + ": " + errorMsg
0082 textArea.cursorPosition = textArea.text.length
0083 } else {
0084 page.refreshPreview()
0085 }
0086 }
0087 }
0088 }
0089
0090 Grid {
0091 id: optionsGrid
0092 property int labelWidth: Math.max(actionLabel.implicitWidth,
0093 sourceLabel.implicitWidth,
0094 formatLabel.implicitWidth)
0095 property int valueWidth: width - labelWidth -spacing
0096 anchors {
0097 left: parent.left
0098 right: parent.right
0099 top: parent.top
0100 margins: constants.margins
0101 }
0102 columns: 2
0103 spacing: constants.spacing
0104 Label {
0105 id: actionLabel
0106 width: parent.labelWidth
0107 height: actionComboBox.height
0108 verticalAlignment: Text.AlignVCenter
0109 text: qsTr("Action:")
0110 }
0111 ComboBox {
0112 id: actionComboBox
0113 width: parent.valueWidth
0114 model: [ qsTr("Rename Folder"), qsTr("Create Folder") ]
0115 onCurrentIndexChanged: {
0116 page.create = currentIndex === 1
0117 page.refreshPreview()
0118 }
0119 }
0120 Label {
0121 id: sourceLabel
0122 width: parent.labelWidth
0123 height: sourceComboBox.height
0124 text: qsTr("Source:")
0125 }
0126 ComboBox {
0127 id: sourceComboBox
0128 width: parent.valueWidth
0129 model: [ qsTr("From Tag 2 and Tag 1"),
0130 qsTr("From Tag 1"),
0131 qsTr("From Tag 2"),
0132 qsTr("From Tag 3"),
0133 qsTr("All Tags")]
0134 onCurrentIndexChanged: {
0135 page.tagMask = [ Kid3.Frame.TagV2V1, Kid3.Frame.TagV1, Kid3.Frame.TagV2,
0136 Kid3.Frame.TagV3, Kid3.Frame.TagVAll ][currentIndex] || 3
0137 page.refreshPreview()
0138 }
0139 }
0140 Label {
0141 id: formatLabel
0142 width: parent.labelWidth
0143 height: formatComboBox.height
0144 text: qsTr("Format:")
0145 }
0146 RowLayout {
0147 width: parent.valueWidth
0148 IconButton {
0149 iconName: "edit"
0150 color: formatLabel.color
0151 onClicked: page.StackView.view.push(editDirFormatsPage)
0152
0153 StringListEditPage {
0154 id: editDirFormatsPage
0155 title: qsTr("Folder Name from Tag")
0156 visible: false
0157 StackView.onActivated: {
0158 setElements(page.formats)
0159 currentIndex = formatComboBox.currentIndex
0160 }
0161 StackView.onDeactivated: {
0162 page.formats = getElements()
0163 formatComboBox.currentIndex = currentIndex
0164 formatComboBox.currentIndexChanged()
0165 }
0166 }
0167 }
0168 ComboBox {
0169 id: formatComboBox
0170 Layout.fillWidth: true
0171 model: page.formats
0172 onCurrentIndexChanged: {
0173 page.format = model[currentIndex]
0174 page.refreshPreview()
0175 }
0176 }
0177 }
0178 }
0179
0180 Label {
0181 id: previewLabel
0182 anchors {
0183 left: parent.left
0184 right: parent.right
0185 top: optionsGrid.bottom
0186 margins: constants.margins
0187 }
0188 text: qsTr("Preview")
0189 }
0190 ScrollView {
0191 id: flick
0192 anchors {
0193 left: parent.left
0194 right: parent.right
0195 top: previewLabel.bottom
0196 bottom: parent.bottom
0197 margins: constants.margins
0198 }
0199
0200 TextArea {
0201 id: textArea
0202 readOnly: true
0203 selectByMouse: false
0204 }
0205 }
0206
0207 function refreshPreview() {
0208 textArea.text = ""
0209 app.renameDirectory(script.toTagVersion(page.tagMask),
0210 page.format, page.create)
0211 }
0212
0213 StackView.onActivated: {
0214 refreshPreview()
0215 }
0216 StackView.onDeactivated: {
0217 app.dirRenamer.abort()
0218 configs.renDirConfig().dirFormats = formats
0219 configs.renDirConfig().dirFormat = format
0220 }
0221
0222 Component.onCompleted: {
0223 var defaultFormats = configs.renDirConfig().dirFormats
0224 format = configs.renDirConfig().dirFormat
0225 var idx = defaultFormats.indexOf(format)
0226 if (idx === -1) {
0227 idx = defaultFormats.length
0228 defaultFormats.push(format)
0229 }
0230 formats = defaultFormats
0231 formatComboBox.currentIndex = idx
0232 }
0233 }