Improvement: initial implementation of profiles json IO.

This commit is contained in:
Filippo Scognamiglio
2014-12-26 02:54:38 +01:00
parent c7fbe591ba
commit 88079a3ee4
6 changed files with 126 additions and 3 deletions

View File

@@ -208,7 +208,7 @@ QtObject{
return stringify(settings);
}
function composeProfileString(){
function composeProfileObject(){
var settings = {
backgroundColor: _backgroundColor,
fontColor: _fontColor,
@@ -232,7 +232,11 @@ QtObject{
fontName: fontNames[rasterization],
fontWidth: fontWidth
}
return stringify(settings);
return settings;
}
function composeProfileString() {
return stringify(composeProfileObject());
}
function loadSettings(){

View File

@@ -21,6 +21,7 @@
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.1
Tab{
ColumnLayout{
@@ -77,10 +78,62 @@ Tab{
profilesView.activated(currentIndex);
}
}
Button{
text: qsTr("Import")
onClicked: {
fileDialog.selectExisting = true;
fileDialog.callBack = function (url) {loadFile(url);};
fileDialog.open();
}
function loadFile(url) {
if (true)
console.log("Loading file: " + url);
var profileStirng = fileIO.read(url);
appSettings.loadProfileString(profileStirng);
}
}
Button{
text: qsTr("Export")
onClicked: {
fileDialog.selectExisting = false;
fileDialog.callBack = function (url) {storeFile(url);};
fileDialog.open();
}
function storeFile(url) {
if (true)
console.log("Storing file: " + url);
var profileObject = appSettings.composeProfileObject();
fileIO.write(url, JSON.stringify(profileObject, undefined, 2));
}
}
InsertNameDialog{
id: insertname
onNameSelected: appSettings.addNewCustomProfile(name)
}
Loader {
property var callBack
property bool selectExisting: false
id: fileDialog
sourceComponent: FileDialog{
nameFilters: ["Json files (*.json)"]
selectMultiple: false
selectFolder: false
selectExisting: fileDialog.selectExisting
onAccepted: callBack(fileUrl);
}
onSelectExistingChanged: reload()
function open() {
item.open();
}
function reload() {
active = false;
active = true;
}
}
}
}
}