2014-06-27 23:54:17 +02:00
|
|
|
/*******************************************************************************
|
2021-06-30 22:49:03 +02:00
|
|
|
* Copyright (c) 2013-2021 "Filippo Scognamiglio"
|
2014-09-03 22:19:34 +02:00
|
|
|
* https://github.com/Swordfish90/cool-retro-term
|
2014-06-27 23:54:17 +02:00
|
|
|
*
|
2014-09-03 22:19:34 +02:00
|
|
|
* This file is part of cool-retro-term.
|
2014-06-27 23:54:17 +02:00
|
|
|
*
|
2014-09-03 22:19:34 +02:00
|
|
|
* cool-retro-term is free software: you can redistribute it and/or modify
|
2014-06-27 23:54:17 +02:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*******************************************************************************/
|
2014-06-23 22:47:35 +02:00
|
|
|
import QtQuick 2.2
|
2021-06-30 08:33:31 +02:00
|
|
|
import QtQuick.Controls 2.4
|
2014-06-23 22:47:35 +02:00
|
|
|
import QtQuick.Layouts 1.1
|
2014-12-26 02:54:38 +01:00
|
|
|
import QtQuick.Dialogs 1.1
|
2014-06-23 22:47:35 +02:00
|
|
|
|
2021-06-30 22:49:03 +02:00
|
|
|
ColumnLayout {
|
|
|
|
GroupBox {
|
2021-06-30 08:33:31 +02:00
|
|
|
Layout.fillWidth: true
|
|
|
|
title: qsTr("Profile")
|
|
|
|
RowLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
ListView {
|
|
|
|
id: profilesView
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
model: appSettings.profilesList
|
|
|
|
delegate: Rectangle {
|
|
|
|
width: label.width
|
|
|
|
height: label.height
|
|
|
|
color: (index == profilesView.currentIndex) ? palette.highlight : palette.base
|
|
|
|
Label {
|
|
|
|
id: label
|
|
|
|
text: appSettings.profilesList.get(index).text
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: profilesView.currentIndex = index
|
|
|
|
onDoubleClicked: appSettings.loadProfile(index)
|
|
|
|
}
|
2014-12-26 02:28:51 +01:00
|
|
|
}
|
2014-06-23 22:47:35 +02:00
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
}
|
|
|
|
ColumnLayout {
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: false
|
2021-06-30 22:49:03 +02:00
|
|
|
Button {
|
2021-06-30 08:33:31 +02:00
|
|
|
Layout.fillWidth: true
|
|
|
|
text: qsTr("Save")
|
|
|
|
onClicked: {
|
2021-06-30 22:49:03 +02:00
|
|
|
insertname.profileName = ""
|
2021-06-30 08:33:31 +02:00
|
|
|
insertname.show()
|
2014-12-26 17:19:34 +01:00
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
}
|
2021-06-30 22:49:03 +02:00
|
|
|
Button {
|
2021-06-30 08:33:31 +02:00
|
|
|
Layout.fillWidth: true
|
|
|
|
property alias currentIndex: profilesView.currentIndex
|
|
|
|
enabled: currentIndex >= 0
|
|
|
|
text: qsTr("Load")
|
|
|
|
onClicked: {
|
2021-06-30 22:49:03 +02:00
|
|
|
var index = currentIndex
|
2021-06-30 08:33:31 +02:00
|
|
|
if (index >= 0)
|
2021-06-30 22:49:03 +02:00
|
|
|
appSettings.loadProfile(index)
|
2014-06-23 22:47:35 +02:00
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
}
|
2021-06-30 22:49:03 +02:00
|
|
|
Button {
|
2021-06-30 08:33:31 +02:00
|
|
|
Layout.fillWidth: true
|
|
|
|
text: qsTr("Remove")
|
|
|
|
property alias currentIndex: profilesView.currentIndex
|
|
|
|
|
2021-06-30 22:49:03 +02:00
|
|
|
enabled: currentIndex >= 0 && !appSettings.profilesList.get(
|
|
|
|
currentIndex).builtin
|
2021-06-30 08:33:31 +02:00
|
|
|
onClicked: {
|
2021-06-30 22:49:03 +02:00
|
|
|
appSettings.profilesList.remove(currentIndex)
|
|
|
|
profilesView.selection.clear()
|
2021-06-30 08:33:31 +02:00
|
|
|
|
|
|
|
// TODO This is a very ugly workaround. The view didn't update on Qt 5.3.2.
|
2021-06-30 22:49:03 +02:00
|
|
|
profilesView.model = 0
|
|
|
|
profilesView.model = appSettings.profilesList
|
2014-06-23 22:47:35 +02:00
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
}
|
|
|
|
Item {
|
|
|
|
// Spacing
|
|
|
|
Layout.fillHeight: true
|
|
|
|
}
|
2021-06-30 22:49:03 +02:00
|
|
|
Button {
|
2021-06-30 08:33:31 +02:00
|
|
|
Layout.fillWidth: true
|
|
|
|
text: qsTr("Import")
|
|
|
|
onClicked: {
|
2021-06-30 22:49:03 +02:00
|
|
|
fileDialog.selectExisting = true
|
|
|
|
fileDialog.callBack = function (url) {
|
|
|
|
loadFile(url)
|
|
|
|
}
|
|
|
|
fileDialog.open()
|
2014-12-26 17:51:10 +01:00
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
function loadFile(url) {
|
|
|
|
try {
|
|
|
|
if (appSettings.verbose)
|
2021-06-30 22:49:03 +02:00
|
|
|
console.log("Loading file: " + url)
|
2014-12-26 17:19:34 +01:00
|
|
|
|
2021-06-30 22:49:03 +02:00
|
|
|
var profileObject = JSON.parse(fileIO.read(url))
|
|
|
|
var name = profileObject.name
|
2014-12-26 17:19:34 +01:00
|
|
|
|
2021-06-30 08:33:31 +02:00
|
|
|
if (!name)
|
2021-06-30 22:49:03 +02:00
|
|
|
throw "Profile doesn't have a name"
|
2014-12-26 17:19:34 +01:00
|
|
|
|
2021-06-30 22:49:03 +02:00
|
|
|
var version = profileObject.version
|
|
|
|
!== undefined ? profileObject.version : 1
|
2021-06-30 08:33:31 +02:00
|
|
|
if (version !== appSettings.profileVersion)
|
2021-06-30 22:49:03 +02:00
|
|
|
throw "This profile is not supported on this version of CRT."
|
2018-11-21 18:11:01 +01:00
|
|
|
|
2021-06-30 22:49:03 +02:00
|
|
|
delete profileObject.name
|
2014-12-26 17:19:34 +01:00
|
|
|
|
2021-06-30 22:49:03 +02:00
|
|
|
appSettings.appendCustomProfile(name,
|
|
|
|
JSON.stringify(
|
|
|
|
profileObject))
|
2021-06-30 08:33:31 +02:00
|
|
|
} catch (err) {
|
|
|
|
messageDialog.text = qsTr(err)
|
2021-06-30 22:49:03 +02:00
|
|
|
messageDialog.open()
|
2014-12-26 02:54:38 +01:00
|
|
|
}
|
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
}
|
2021-06-30 22:49:03 +02:00
|
|
|
Button {
|
2021-06-30 08:33:31 +02:00
|
|
|
property alias currentIndex: profilesView.currentIndex
|
2014-12-26 17:19:34 +01:00
|
|
|
|
2021-06-30 08:33:31 +02:00
|
|
|
Layout.fillWidth: true
|
2014-12-26 17:19:34 +01:00
|
|
|
|
2021-06-30 08:33:31 +02:00
|
|
|
text: qsTr("Export")
|
2021-06-30 22:49:03 +02:00
|
|
|
enabled: currentIndex >= 0 && !appSettings.profilesList.get(
|
|
|
|
currentIndex).builtin
|
2021-06-30 08:33:31 +02:00
|
|
|
onClicked: {
|
2021-06-30 22:49:03 +02:00
|
|
|
fileDialog.selectExisting = false
|
|
|
|
fileDialog.callBack = function (url) {
|
|
|
|
storeFile(url)
|
|
|
|
}
|
|
|
|
fileDialog.open()
|
2021-06-30 08:33:31 +02:00
|
|
|
}
|
|
|
|
function storeFile(url) {
|
|
|
|
try {
|
2021-06-30 22:49:03 +02:00
|
|
|
var urlString = url.toString()
|
2021-06-30 08:33:31 +02:00
|
|
|
|
|
|
|
// Fix the extension if it's missing.
|
2021-06-30 22:49:03 +02:00
|
|
|
var extension = urlString.substring(
|
|
|
|
urlString.length - 5, urlString.length)
|
|
|
|
var urlTail = (extension === ".json" ? "" : ".json")
|
|
|
|
url += urlTail
|
2021-06-30 08:33:31 +02:00
|
|
|
|
|
|
|
if (true)
|
2021-06-30 22:49:03 +02:00
|
|
|
console.log("Storing file: " + url)
|
2021-06-30 08:33:31 +02:00
|
|
|
|
2021-06-30 22:49:03 +02:00
|
|
|
var profileObject = appSettings.profilesList.get(
|
|
|
|
currentIndex)
|
|
|
|
var profileSettings = JSON.parse(
|
|
|
|
profileObject.obj_string)
|
|
|
|
profileSettings["name"] = profileObject.text
|
|
|
|
profileSettings["version"] = appSettings.profileVersion
|
2021-06-30 08:33:31 +02:00
|
|
|
|
2021-06-30 22:49:03 +02:00
|
|
|
var result = fileIO.write(url, JSON.stringify(
|
|
|
|
profileSettings,
|
|
|
|
undefined, 2))
|
2021-06-30 08:33:31 +02:00
|
|
|
if (!result)
|
2021-06-30 22:49:03 +02:00
|
|
|
throw "The file could not be written."
|
2021-06-30 08:33:31 +02:00
|
|
|
} catch (err) {
|
2021-06-30 22:49:03 +02:00
|
|
|
console.log(err)
|
|
|
|
messageDialog.text = qsTr(
|
|
|
|
"There has been an error storing the file.")
|
|
|
|
messageDialog.open()
|
2014-12-26 02:54:38 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-23 22:47:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
}
|
2016-03-20 22:54:29 +01:00
|
|
|
|
2021-06-30 22:49:03 +02:00
|
|
|
GroupBox {
|
2021-06-30 08:33:31 +02:00
|
|
|
title: qsTr("Screen")
|
|
|
|
Layout.fillWidth: true
|
2021-06-30 22:49:03 +02:00
|
|
|
GridLayout {
|
2021-06-30 08:33:31 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
columns: 2
|
2021-06-30 22:49:03 +02:00
|
|
|
Label {
|
|
|
|
text: qsTr("Brightness")
|
|
|
|
}
|
|
|
|
SimpleSlider {
|
2021-06-30 08:33:31 +02:00
|
|
|
onValueChanged: appSettings.brightness = value
|
|
|
|
value: appSettings.brightness
|
|
|
|
}
|
2021-06-30 22:49:03 +02:00
|
|
|
Label {
|
|
|
|
text: qsTr("Contrast")
|
|
|
|
}
|
|
|
|
SimpleSlider {
|
2021-06-30 08:33:31 +02:00
|
|
|
onValueChanged: appSettings.contrast = value
|
|
|
|
value: appSettings.contrast
|
|
|
|
}
|
2021-06-30 22:49:03 +02:00
|
|
|
Label {
|
|
|
|
text: qsTr("Margin")
|
|
|
|
}
|
|
|
|
SimpleSlider {
|
2021-06-30 08:33:31 +02:00
|
|
|
onValueChanged: appSettings._margin = value
|
|
|
|
value: appSettings._margin
|
|
|
|
}
|
2021-07-15 23:20:42 +02:00
|
|
|
Label {
|
|
|
|
text: qsTr("Frame size")
|
|
|
|
}
|
|
|
|
SimpleSlider {
|
|
|
|
onValueChanged: appSettings._frameMargin = value
|
|
|
|
value: appSettings._frameMargin
|
|
|
|
}
|
2021-06-30 22:49:03 +02:00
|
|
|
Label {
|
|
|
|
text: qsTr("Opacity")
|
2022-01-03 18:43:07 +01:00
|
|
|
visible: !appSettings.isMacOS
|
2021-06-30 22:49:03 +02:00
|
|
|
}
|
|
|
|
SimpleSlider {
|
2021-06-30 08:33:31 +02:00
|
|
|
onValueChanged: appSettings.windowOpacity = value
|
|
|
|
value: appSettings.windowOpacity
|
2022-01-03 18:43:07 +01:00
|
|
|
visible: !appSettings.isMacOS
|
2016-03-20 22:54:29 +01:00
|
|
|
}
|
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
}
|
2016-03-20 22:54:29 +01:00
|
|
|
|
2021-06-30 08:33:31 +02:00
|
|
|
// DIALOGS ////////////////////////////////////////////////////////////////
|
2021-06-30 22:49:03 +02:00
|
|
|
InsertNameDialog {
|
2021-06-30 08:33:31 +02:00
|
|
|
id: insertname
|
|
|
|
onNameSelected: {
|
2021-06-30 22:49:03 +02:00
|
|
|
appSettings.appendCustomProfile(name,
|
|
|
|
appSettings.composeProfileString())
|
2014-06-23 22:47:35 +02:00
|
|
|
}
|
2021-06-30 08:33:31 +02:00
|
|
|
}
|
|
|
|
MessageDialog {
|
|
|
|
id: messageDialog
|
|
|
|
title: qsTr("File Error")
|
|
|
|
onAccepted: {
|
2021-06-30 22:49:03 +02:00
|
|
|
messageDialog.close()
|
2021-06-30 08:33:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Loader {
|
|
|
|
property var callBack
|
|
|
|
property bool selectExisting: false
|
|
|
|
id: fileDialog
|
|
|
|
|
2021-06-30 22:49:03 +02:00
|
|
|
sourceComponent: FileDialog {
|
2021-06-30 08:33:31 +02:00
|
|
|
nameFilters: ["Json files (*.json)"]
|
|
|
|
selectMultiple: false
|
|
|
|
selectFolder: false
|
|
|
|
selectExisting: fileDialog.selectExisting
|
2021-06-30 22:49:03 +02:00
|
|
|
onAccepted: callBack(fileUrl)
|
2014-12-26 17:19:34 +01:00
|
|
|
}
|
|
|
|
|
2021-06-30 08:33:31 +02:00
|
|
|
onSelectExistingChanged: reload()
|
2014-12-26 17:19:34 +01:00
|
|
|
|
2021-06-30 08:33:31 +02:00
|
|
|
function open() {
|
2021-06-30 22:49:03 +02:00
|
|
|
item.open()
|
2021-06-30 08:33:31 +02:00
|
|
|
}
|
2014-12-26 17:19:34 +01:00
|
|
|
|
2021-06-30 08:33:31 +02:00
|
|
|
function reload() {
|
2021-06-30 22:49:03 +02:00
|
|
|
active = false
|
|
|
|
active = true
|
2014-06-23 22:47:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|