Friendiqa/source-android/qml/configqml/ConfigTab.qml

351 lines
12 KiB
QML
Raw Normal View History

2017-05-11 22:15:34 +02:00
import QtQuick 2.7
2017-01-26 21:55:31 +01:00
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.2
import "qrc:/js/service.js" as Service
import "qrc:/js/layout.js" as Layoutjs
import "qrc:/js/helper.js" as Helperjs
import "qrc:/qml/configqml"
import "qrc:/qml/genericqml"
StackView{
id: configStack
anchors.fill:parent
initialItem: Flickable{
width:root.width-5*mm
height:root.height-12*mm
contentHeight: configBackground.height
boundsBehavior: Flickable.StopAtBounds
2017-05-11 22:15:34 +02:00
2017-01-26 21:55:31 +01:00
Rectangle{
id:configBackground
2017-03-25 23:36:14 +01:00
color: "white"
2017-01-26 21:55:31 +01:00
width:parent.width
height:Math.max(90*mm,root.height-12*mm)
property var users:[]
2017-05-11 22:15:34 +02:00
function setServericon(server){
try {Helperjs.friendicaWebRequest(server+"/api/statusnet/config",configBackground, function (obj){
var serverdata = JSON.parse(obj);
servericon.source=serverdata.site.logo})} catch(e){print(e)}
}
2017-01-26 21:55:31 +01:00
BlueButton{
id:userButton
text:qsTr("User")
y:mm
width: root.width/2
onClicked:{
var useritems="";
for (var i=0;i<configBackground.users.length;i++){
useritems=useritems+"MenuItem{text:'"+configBackground.users[i].username+
"'; onTriggered: {Service.readConfig(db,function(obj){
userButton.text=obj.username;
servername.text=obj.server;
2017-05-11 22:15:34 +02:00
configBackground.setServericon(obj.server);
2017-01-26 21:55:31 +01:00
username.text= obj.username;
password.text=Qt.atob(obj.password);
imagestore.text=obj.imagestore;
maxNews.value=obj.maxnews;
newsTypeField.text=obj.newsViewType;
2017-03-25 23:36:14 +01:00
if( obj.isActive==0){userButton.fontColor='black'} else {userButton.fontColor='grey'}
2017-01-26 21:55:31 +01:00
},'username','"+configBackground.users[i].username+"')}}"
}
var menuString="import QtQuick.Controls 1.4;import 'qrc:/js/service.js' as Service; Menu {"+useritems+"}";
var userlistObject=Qt.createQmlObject(menuString,configBackground,"usermenuOutput")
userlistObject.popup() }
}
Text {
2017-05-11 22:15:34 +02:00
text: qsTr("Server")
2017-01-26 21:55:31 +01:00
x: 4*mm; y: 10*mm
}
Text {
2017-05-11 22:15:34 +02:00
text: qsTr("User")
2017-01-26 21:55:31 +01:00
x: 4*mm; y: 20*mm
}
Text {
2017-05-11 22:15:34 +02:00
text: qsTr("Password")
2017-01-26 21:55:31 +01:00
x: 4*mm; y: 30*mm
}
Text {
2017-05-11 22:15:34 +02:00
text: qsTr("Image dir.")
2017-01-26 21:55:31 +01:00
x: 4*mm; y: 40*mm
}
Text {
2017-05-11 22:15:34 +02:00
text: qsTr("Max. News")
2017-01-26 21:55:31 +01:00
x: 4*mm; y: 50*mm
}
Text {
2017-05-11 22:15:34 +02:00
text: qsTr("News as")
2017-01-26 21:55:31 +01:00
x: 4*mm; y: 60*mm
}
Text {
2017-05-11 22:15:34 +02:00
text: qsTr("Interval (0=None)")
2017-03-25 23:36:14 +01:00
visible: false
x: 4*mm; y: 70*mm; width:20*mm;wrapMode: Text.Wrap
2017-01-26 21:55:31 +01:00
}
2017-05-11 22:15:34 +02:00
Image{
id:servericon
x:19*mm;y:10*mm
width:5*mm; height: 5*mm
source:""
MouseArea{
anchors.fill:parent
onClicked:{
Service.showServerConfig(servername.text, configBackground, function(configString){
var serverconfigObject=Qt.createQmlObject(configString,configBackground,"serverconfigOutput");})
}
}
}
2017-03-25 23:36:14 +01:00
Rectangle{color: "light grey"; x: 25*mm; y: 10*mm; width: root.width/2; height: 5*mm;}
2017-01-26 21:55:31 +01:00
Flickable {
id: servernameFlickable
x: 25*mm; y: 10*mm; width: root.width/2; height: 5*mm;
contentWidth: servername.paintedWidth
contentHeight: servername.paintedHeight
clip: true
TextEdit {
id: servername
width: servernameFlickable.width
height: servernameFlickable.height
focus: true
text:"https://..."
2017-05-11 22:15:34 +02:00
onEditingFinished:{
if((servername.text).substring(0,14) =="https://...http"){
serverstring.text= (serverstring.text).substring(11)
}
configBackground.setServericon(servername.text)
}
2017-01-26 21:55:31 +01:00
onCursorRectangleChanged: Layoutjs.ensureVisibility(cursorRectangle,servernameFlickable)
}
}
Rectangle{
2017-03-25 23:36:14 +01:00
color: "light grey"
2017-01-26 21:55:31 +01:00
x: 25*mm; y: 20*mm; width: root.width/2; height: 5*mm;
TextInput {
id: username
anchors.fill: parent
selectByMouse: true
}
}
Rectangle{
2017-03-25 23:36:14 +01:00
color: "light grey"
2017-01-26 21:55:31 +01:00
x: 25*mm; y: 30*mm; width: root.width/2; height: 5*mm;
TextInput {
id: password
anchors.fill: parent
selectByMouse: true
echoMode: TextInput.PasswordEchoOnEdit
}
}
2017-03-25 23:36:14 +01:00
Rectangle{color: "light grey"; x: 25*mm; y: 40*mm; width: root.width/2-9*mm; height: 5*mm;}
2017-01-26 21:55:31 +01:00
Flickable {
id: imagestoreFlickable
x: 25*mm; y: 40*mm; width: root.width/2-9*mm; height: 5*mm;
clip: true
TextInput {
id: imagestore
width: imagestoreFlickable.width
height: imagestoreFlickable.height
wrapMode: TextEdit.NoWrap
onCursorRectangleChanged: Layoutjs.ensureVisibility(cursorRectangle,imagestoreFlickable)
}
}
Slider{ id: maxNews
2017-05-11 22:15:34 +02:00
x:34*mm; y: 50*mm;width: root.width/3;height:5*mm
minimumValue: 0;maximumValue:2000; stepSize: 100
2017-01-26 21:55:31 +01:00
}
2017-05-11 22:15:34 +02:00
2017-03-25 23:36:14 +01:00
Rectangle{color: "light grey"; x: 25*mm; y: 50*mm; width: 9*mm; height: 5*mm;
2017-01-26 21:55:31 +01:00
TextEdit{id:maxNewsText;
anchors.fill: parent
verticalAlignment:TextEdit.AlignRight
text:maxNews.value
focus: true
selectByMouse: true
}
}
Rectangle{
x: 25*mm; y: 60*mm; width: root.width/2; height: 5*mm;
2017-03-25 23:36:14 +01:00
color:"light grey"
2017-01-26 21:55:31 +01:00
Text{
id: newsTypeField
anchors.fill: parent
text:"Timeline"
}
MouseArea{
anchors.fill:parent
onClicked:newstypemenu.popup()
}
}
2017-03-25 23:36:14 +01:00
Slider{ id: messageIntervalSlider
visible: false
x:37*mm; y: 70*mm;width: root.width/3;height:5*mm
minimumValue: 0;maximumValue:24; stepSize: 0.5
}
2017-01-26 21:55:31 +01:00
Rectangle{
2017-03-25 23:36:14 +01:00
visible:false
x: 25*mm; y: 70*mm; width: 9*mm; height: 5*mm;
TextEdit{
id: messageIntervalField
2017-01-26 21:55:31 +01:00
anchors.fill: parent
2017-03-25 23:36:14 +01:00
verticalAlignment:TextEdit.AlignRight
text:messageIntervalSlider.value
focus: true
selectByMouse: true
2017-01-26 21:55:31 +01:00
}
}
FileDialog {
id: imagestoreDialog
title: "Please choose a directory"
folder: shortcuts.pictures
selectFolder: true
onAccepted: {
var imagestoreString=imagestoreDialog.folder.toString();
imagestoreString=imagestoreString.replace(/^(file:\/{2})/,"")+"/"
2017-03-25 23:36:14 +01:00
imagestore.text=imagestoreString
2017-01-26 21:55:31 +01:00
}
}
BlueButton {
x: root.width/2+18*mm; y: 40*mm; width: 7*mm; height: 5*mm;
text: "..."
onClicked:
{imagestoreDialog.open()}
}
BlueButton {
2017-05-11 22:15:34 +02:00
x: 25*mm; y: 78*mm
text: qsTr("Confirm")
2017-01-26 21:55:31 +01:00
onClicked:{
2017-03-25 23:36:14 +01:00
var userconfig={server: servername.text, username: username.text, password:Qt.btoa(password.text), imagestore:imagestore.text,maxnews:maxNewsText.text,interval: messageIntervalField.text, newsViewType:newsTypeField.text};
2017-01-26 21:55:31 +01:00
var errormessage="";
if (servername.text==""){errormessage=qsTr("No server given! ")}
else if (username.text==""){errormessage+=qsTr("No username given! ")}
else if (password.text=="") {errormessage+=qsTr("No password given! ")}
else if (imagestore.text=="") {errormessage+=qsTr("No image directory given!")}
else if (maxNewsText.text=="") {errormessage+=qsTr("No maximum news number given!")}
else {errormessage=""}
if (errormessage=="") {
filesystem.Directory=userconfig.imagestore;
filesystem.makeDir("contacts");
filesystem.makeDir("albums");
Service.storeConfig(db,userconfig);
Service.readConfig(db,function(userconfig){
2017-03-25 23:36:14 +01:00
Service.getServerConfig(db,userconfig,root, function(obj){
2017-01-26 21:55:31 +01:00
var serverString=obj;
var serverconfigObject=Qt.createQmlObject(serverString,configBackground,"serverconfigOutput");
Helperjs.readData(db,"config","",function(storedUsers){
storedUsers.sort(function(obj1, obj2) {
return obj1.isActive - obj2.isActive;
});
configBackground.users=storedUsers});
2017-03-25 23:36:14 +01:00
userButton.color="black"
2017-01-26 21:55:31 +01:00
//reset values
root.login=userconfig;
newstab.newstabstatus=userconfig.newsViewType;
2017-01-26 21:55:31 +01:00
root.currentIndex=0;
newstab.active=true;
})},"isActive",0);
}
else {Helperjs.show("Error", errormessage,root)}
}}
BlueButton {
x: root.width/2+2*mm; y: mm; width: 5*mm; height: 5*mm;
text: "-"
onClicked:{
var userconfig={server: servername.text, username: username.text, password: Qt.btoa(password.text)};
Service.deleteConfig(db,userconfig,function(){
filesystem.Directory=imagestore.text+"contacts";
filesystem.rmDir();
filesystem.Directory=imagestore.text+"albums";
filesystem.rmDir();
servername.text="https://...";
2017-05-11 22:15:34 +02:00
servericon.source="";
2017-01-26 21:55:31 +01:00
username.text="";
password.text="";
imagestore.text="";
maxNews.value=0;
newsTypeField.text="Timeline";
2017-03-25 23:36:14 +01:00
messageIntervalSlider.value=0;
2017-01-26 21:55:31 +01:00
userButton.text=qsTr("User");
Helperjs.readData(db,"config","",function(storedUsers){
storedUsers.sort(function(obj1, obj2) {
return obj1.isActive - obj2.isActive;
})
configBackground.users=storedUsers;})
})
}}
BlueButton {
x: root.width/2+8*mm; y: mm; width: 5*mm; height: 5*mm;
text: "+"
onClicked:{
servername.text="https://..."
2017-05-11 22:15:34 +02:00
servericon.source="";
2017-01-26 21:55:31 +01:00
username.text=""
password.text=""
imagestore.text=""
maxNews.value=0
newsTypeField.text="Timeline"
2017-03-25 23:36:14 +01:00
messageIntervalSlider.value=0
2017-01-26 21:55:31 +01:00
userButton.text=qsTr("User")
}
}
BlueButton {
x: root.width/2+14*mm; y: mm; width: 5*mm; height: 5*mm;
text: "?"
onClicked:{
configStack.push({item:"qrc:/qml/configqml/InfoBox.qml"});
}
}
Menu {
id:newstypemenu
MenuItem {
text: qsTr("Timeline")
onTriggered: {newsTypeField.text="Timeline"}
}
MenuItem {
2017-05-11 22:15:34 +02:00
text: qsTr("Conversations")
onTriggered: {newsTypeField.text="Conversations"}
2017-01-26 21:55:31 +01:00
}
}
Component.onCompleted: {
try{Helperjs.readData(db,"config","",function(storedUsers){
storedUsers.sort(function(obj1, obj2) {
return obj1.isActive - obj2.isActive;
})
configBackground.users=storedUsers;
Service.readConfig(db,function(obj){
userButton.text=obj.username;
servername.text=obj.server;
2017-05-11 22:15:34 +02:00
configBackground.setServericon(obj.server);
2017-01-26 21:55:31 +01:00
username.text= obj.username;
password.text=Qt.atob(obj.password);
imagestore.text=obj.imagestore;
maxNews.value=obj.maxnews;
newsTypeField.text=obj.newsViewType;
2017-03-25 23:36:14 +01:00
messageIntervalSlider.value=obj.timerInterval;
if( obj.isActive==0){userButton.fontColor='black'} else {userButton.fontColor='grey'}},"isActive",0
2017-01-26 21:55:31 +01:00
)
})}
catch (e){print(e)}
}
}
}
}