Skip to content

Instantly share code, notes, and snippets.

@Nicd
Created March 11, 2014 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicd/21b9692b12a9f9692f1f to your computer and use it in GitHub Desktop.
Save Nicd/21b9692b12a9f9692f1f to your computer and use it in GitHub Desktop.
/*
* © Mikko Ahlroth 2014
* WeeCRApp is open source software. For licensing information, please check
* the LICENCE file.
*/
import QtQuick 2.0
import Sailfish.Silica 1.0
import "../js/storage.js" as Storage
Dialog {
id: addConnectionDialog
// Custom properties for saving connection info when modifying
property var oldinfo: null;
function updateFields(infodict) {
nameField.text = infodict.name;
hostField.text = infodict.host;
portField.text = infodict.port;
passwordField.text = "FAKE PASS";
oldinfo = infodict;
}
function saveFields() {
var id = null;
var pass = passwordField.text;
var type = "";
if (oldinfo !== null) {
id = oldinfo.id;
if (passwordField.text === "FAKE PASS") {
pass = oldinfo.pass;
}
}
switch (securityField.currentIndex) {
case 0:
type = "plain";
break;
case 1:
type = "ssl";
}
return {
"id": id,
"name": nameField.text,
"host": hostField.text,
"port": portField.text,
"password": pass,
"type": type
};
}
onAccepted: {
var infodict = saveFields();
saveConnection(infodict);
}
SilicaFlickable {
id: addConnectionFlickable
anchors.fill: parent
Column {
id: addConnectionColumn
width: addConnectionDialog.width
spacing: Theme.paddingLarge
DialogHeader {
title: "Save"
}
TextField {
id: nameField
placeholderText: "Connection name"
width: parent.width
}
Row {
spacing: Theme.paddingSmall
width: parent.width
TextField {
id: hostField
width: parent.width * 0.75
placeholderText: "Hostname"
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
}
TextField {
id: portField
width: parent.width * 0.25
placeholderText: "Port"
inputMethodHints: Qt.ImhDigitsOnly
validator: IntValidator {
bottom: 1
top: 65535
}
}
}
TextField {
id: passwordField
placeholderText: "Password"
width: parent.width
echoMode: TextInput.Password
}
ComboBox {
id: securityField
label: "Security"
menu: ContextMenu {
MenuItem {
text: "None"
}
MenuItem {
text: "SSL"
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment