Warning, /multimedia/kid3/src/qml/app/ImportProfilesEditPage.qml is written in an unsupported language. File is not indexed.

0001 /**
0002  * \file ImportProfilesEditPage.qml
0003  * Page to edit import profiles.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 9 Mar 2019
0008  *
0009  * Copyright (C) 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 StringListEditPage {
0030   id: page
0031 
0032   signal finished()
0033 
0034   title: qsTr("Profiles")
0035 
0036   StringListEditPage {
0037     id: editProfilePage
0038 
0039     property string name
0040 
0041     editDialog: profileEditDialog
0042     title: qsTr("Profile") + " " + name
0043     visible: false
0044 
0045     function setElements(sources) {
0046       model.clear()
0047       for (var i = 0; i < sources.length; i++) {
0048         var src = sources[i]
0049         model.append({name: sourceToString(src), sources: src})
0050       }
0051     }
0052 
0053     function getElements() {
0054       var sources = []
0055       for (var i = 0; i < model.count; i++) {
0056         sources.push(model.get(i).sources)
0057       }
0058       return sources
0059     }
0060 
0061     function sourceToString(source) {
0062       var parts = source.split(":")
0063       var server = parts[0] || ""
0064       var accuracy = parts[1] || ""
0065       var enabledStr = parts[2] || ""
0066       var result = server
0067       if (result) {
0068         result += ", " + qsTr("Accuracy") + " " + accuracy
0069         var enabled = []
0070         if (enabledStr.indexOf("S") !== -1) {
0071           enabled.push(qsTr("Standard Tags"))
0072         }
0073         if (enabledStr.indexOf("A") !== -1) {
0074           enabled.push(qsTr("Additional Tags"))
0075         }
0076         if (enabledStr.indexOf("C") !== -1) {
0077           enabled.push(qsTr("Cover Art"))
0078         }
0079         if (enabled.length > 0) {
0080           result += ", "
0081           result += enabled.join(", ")
0082         }
0083       }
0084       return result
0085     }
0086 
0087     Dialog {
0088       id: profileEditDialog
0089 
0090       signal completed(bool ok)
0091 
0092       function setElement(element) {
0093         var parts = element.sources ? element.sources.split(":") : [""]
0094         serverComboBox.currentIndex = serverComboBox.find(parts[0])
0095         accuracyLineEdit.text = parts[1] || ""
0096         var enabledStr = parts[2] || ""
0097         standardTagsCheckBox.checked = enabledStr.indexOf("S") !== -1
0098         additionalTagsCheckBox.checked = enabledStr.indexOf("A") !== -1
0099         coverArtCheckBox.checked = enabledStr.indexOf("C") !== -1
0100       }
0101 
0102       function getElement() {
0103         var sources = serverComboBox.currentText + ":" +
0104                       accuracyLineEdit.text + ":"
0105         if (standardTagsCheckBox.checked) {
0106           sources += "S"
0107         }
0108         if (additionalTagsCheckBox.checked) {
0109           sources += "A"
0110         }
0111         if (coverArtCheckBox.checked) {
0112           sources += "C"
0113         }
0114         return {name: editProfilePage.sourceToString(sources),
0115                 sources: sources}
0116       }
0117 
0118       modal: true
0119       width: Math.min(parent.width, constants.gu(70))
0120       x: (parent.width - width) / 2
0121       y: 0
0122       standardButtons: Dialog.Ok | Dialog.Cancel
0123 
0124       GridLayout {
0125         columns: 2
0126         width: parent.width
0127         Label {
0128           text: qsTr("Server")
0129         }
0130         ComboBox {
0131           id: serverComboBox
0132           model: app.getServerImporterNames()
0133           Layout.fillWidth: true
0134         }
0135         Label {
0136           text: qsTr("Accuracy")
0137         }
0138         TextField {
0139           id: accuracyLineEdit
0140           validator: IntValidator{
0141             bottom: 0
0142             top: 100
0143           }
0144           selectByMouse: true
0145           Layout.fillWidth: true
0146         }
0147         CheckBox {
0148           id: standardTagsCheckBox
0149           text: qsTr("Standard Tags")
0150           Layout.columnSpan: 2
0151         }
0152         CheckBox {
0153           id: additionalTagsCheckBox
0154           text: qsTr("Additional Tags")
0155           Layout.columnSpan: 2
0156         }
0157         CheckBox {
0158           id: coverArtCheckBox
0159           text: qsTr("Cover Art")
0160           Layout.columnSpan: 2
0161         }
0162       }
0163 
0164       onAccepted: completed(true)
0165       onRejected: completed(false)
0166     }
0167 
0168     StackView.onActivated: {
0169       var idx = page.currentIndex
0170       var srcStr = ""
0171       if (idx >= 0 && idx < page.model.count) {
0172         var element = page.model.get(idx)
0173         name = element.name || ""
0174         srcStr = element.sources || ""
0175       } else {
0176         name = ""
0177         srcStr = ""
0178       }
0179       setElements(srcStr.split(";"))
0180     }
0181     StackView.onDeactivated: {
0182       var idx = page.currentIndex
0183       if (idx >= 0 && idx < page.model.count) {
0184         var element = page.model.get(idx)
0185         if (element.name === name) {
0186           element.sources = getElements().join(";")
0187           page.model.set(idx, element)
0188           page.saveModel()
0189         }
0190       }
0191     }
0192   }
0193 
0194   function setElements(namesSources) {
0195     var names = namesSources[0]
0196     var sources = namesSources[1]
0197     model.clear()
0198     for (var i = 0; i < names.length; i++) {
0199       model.append({name: names[i], sources: sources[i]})
0200     }
0201   }
0202 
0203   function getElements() {
0204     var names = []
0205     var sources = []
0206     for (var i = 0; i < model.count; i++) {
0207       names.push(model.get(i).name)
0208       sources.push(model.get(i).sources)
0209     }
0210     return [names, sources]
0211   }
0212 
0213   function saveModel() {
0214     var namesSources = getElements()
0215     configs.batchImportConfig().profileNames = namesSources[0]
0216     configs.batchImportConfig().profileSources = namesSources[1]
0217   }
0218 
0219   onEditClicked: function() {
0220     page.StackView.view.push(editProfilePage)
0221   }
0222   StackView.onActivated: {
0223     var idx = currentIndex
0224     setElements([configs.batchImportConfig().profileNames,
0225                  configs.batchImportConfig().profileSources])
0226     currentIndex = idx
0227   }
0228   StackView.onDeactivated: {
0229     saveModel()
0230     finished()
0231   }
0232 }