harbour-weechatrelay/qml/pages/AddConnection.qml
Mikko Ahlroth 840a50e54b Add licence details
Insert copyright statements

Implemented CRUD for connections

Refactor C++ connection side, create debugview and connect C++ to UI

Implement SSL verification, reconnection, import moment.js, refactor UI logic

Storing SSL certificate for later use now works

Add missing comments

Follow the end of a TextListComponent if view was already at bottom

Initial protocol stubs for WeeChat protocol

Add README
2014-06-27 09:08:53 +03:00

173 lines
4.2 KiB
QML

/*
* © 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
canAccept: false
property SilicaListView connList;
property int oldId: -1;
// 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";
switch (infodict.type) {
case "plain":
securityField.currentIndex = 0;
break;
case "ssl":
securityField.currentIndex = 1;
}
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.password;
}
}
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,
"options": {}
};
}
function setCanAccept() {
addConnectionDialog.canAccept = (nameField.text.length !== 0
&& hostField.text.length !== 0
&& portField.text.length !== 0);
}
Component.onCompleted: {
// Load old data if available
if (oldId === -1) return;
var db = Storage.connect();
var infodict = Storage.readConnection(db, oldId);
updateFields(infodict);
}
onAccepted: {
var infodict = saveFields();
var connection = new Storage.Connection(infodict);
var db = Storage.connect();
Storage.storeConnection(db, connection);
connList.updateList();
}
SilicaFlickable {
id: addConnectionFlickable
anchors.fill: parent
contentHeight: addConnectionColumn.height
VerticalScrollDecorator { flickable: addConnectionFlickable }
Column {
id: addConnectionColumn
width: addConnectionDialog.width
spacing: Theme.paddingLarge
DialogHeader {
title: "Save"
}
TextField {
id: nameField
placeholderText: "Connection name"
width: parent.width
onTextChanged: setCanAccept();
}
Row {
spacing: Theme.paddingSmall
width: parent.width
TextField {
id: hostField
width: parent.width * 0.75
placeholderText: "Hostname"
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
onTextChanged: setCanAccept();
}
TextField {
id: portField
width: parent.width * 0.25
placeholderText: "Port"
inputMethodHints: Qt.ImhDigitsOnly
validator: IntValidator {
bottom: 1
top: 65535
}
onTextChanged: setCanAccept();
}
}
TextField {
id: passwordField
placeholderText: "Password"
width: parent.width
echoMode: TextInput.Password
onTextChanged: setCanAccept();
}
ComboBox {
id: securityField
label: "Security"
menu: ContextMenu {
MenuItem {
text: "None"
}
MenuItem {
text: "SSL"
}
}
}
}
}
}