364 lines
15 KiB
QML
364 lines
15 KiB
QML
// This file is part of Friendiqa
|
|
// https://git.friendi.ca/lubuwest/Friendiqa
|
|
// Copyright (C) 2020 Marco R. <thomasschmidt45@gmx.net>
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// 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.
|
|
//
|
|
// In addition, as a special exception, the copyright holders give
|
|
// permission to link the code of portions of this program with the
|
|
// OpenSSL library under certain conditions as described in each
|
|
// individual source file, and distribute linked combinations including
|
|
// the two.
|
|
//
|
|
// You must obey the GNU General Public License in all respects for all
|
|
// of the code used other than OpenSSL. If you modify file(s) with this
|
|
// exception, you may extend this exception to your version of the
|
|
// file(s), but you are not obligated to do so. If you do not wish to do
|
|
// so, delete this exception statement from your version. If you delete
|
|
// this exception statement from all source files in the program, then
|
|
// also delete it here.
|
|
//
|
|
// 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/>.
|
|
|
|
import QtQuick 2.7
|
|
import QtQuick.Dialogs 1.2
|
|
import QtQuick.Controls 2.12
|
|
import QtQuick.Layouts 1.12
|
|
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"
|
|
|
|
Page{
|
|
id:accountPage
|
|
width: root.width
|
|
height: root.height
|
|
property var users:[]
|
|
property var userdata: ({})
|
|
property string imagestoredir: ""
|
|
|
|
|
|
function setServericon(server){
|
|
try {Helperjs.friendicaWebRequest(server+"/api/statusnet/config",accountPage, function (obj){
|
|
var serverdata = JSON.parse(obj);
|
|
servericon.visible=true;
|
|
servericon.source=serverdata.site.logo})} catch(e){print(e)}
|
|
}
|
|
|
|
MButton{
|
|
id:userButton
|
|
text:qsTr("User")
|
|
font.pointSize: osSettings.bigFontSize
|
|
x: root.fontFactor*osSettings.bigFontSize
|
|
y: root.fontFactor*osSettings.bigFontSize
|
|
width: root.width/2 - 2*mm
|
|
height: 2*root.fontFactor*osSettings.bigFontSize
|
|
visible: users.length>0
|
|
|
|
onClicked:{
|
|
var useritems="";
|
|
for (var i=0;i<accountPage.users.length;i++){
|
|
|
|
useritems=useritems+"MenuItem{font.pointSize: osSettings.bigFontSize;width:accountPage.width*2/3; text:'"+accountPage.users[i].username+
|
|
"'; onTriggered: {Service.readConfig(db,function(obj){
|
|
userButton.text=obj.username;
|
|
servername.text=obj.server;
|
|
accountPage.setServericon(obj.server);
|
|
username.text= obj.username;
|
|
password.text=Qt.atob(obj.password);
|
|
imagestore.text=obj.imagestore;
|
|
imagestoredir=obj.imagestore;
|
|
if( obj.isActive==0){userButton.font.bold='true'} else {userButton.font.bold='false'}
|
|
},'username','"+ accountPage.users[i].username+"')}}"
|
|
}
|
|
var menuString="import QtQuick.Controls 2.12;import 'qrc:/js/service.js' as Service;"+
|
|
" Menu {width:8*root.fontFactor*osSettings.bigFontSize;"+useritems+"}";
|
|
var userlistObject=Qt.createQmlObject(menuString,accountPage,"usermenuOutput")
|
|
userlistObject.popup() }
|
|
}
|
|
|
|
|
|
Image{
|
|
id:servericon
|
|
x:root.fontFactor*osSettings.bigFontSize;y:3*root.fontFactor*osSettings.bigFontSize
|
|
width:2.5*root.fontFactor*osSettings.bigFontSize; height: 2.5*root.fontFactor*osSettings.bigFontSize
|
|
visible: false
|
|
source:""
|
|
MouseArea{
|
|
anchors.fill:parent
|
|
onClicked:{
|
|
Service.showServerConfig(servername.text, accountPage, function(configString){
|
|
var serverconfigObject=Qt.createQmlObject(configString,accountPage,"serverconfigOutput");})
|
|
}
|
|
}
|
|
}
|
|
FontLoader{id: fontAwesome; source: "qrc:/images/fontawesome-webfont.ttf"}
|
|
MButton{
|
|
id:serverSearchButton
|
|
text:"\uf002"
|
|
icon.name: "search"
|
|
font.pointSize: osSettings.bigFontSize
|
|
x:root.fontFactor*osSettings.bigFontSize
|
|
y:3*root.fontFactor*osSettings.bigFontSize
|
|
width: 2*root.fontFactor*osSettings.bigFontSize; height:2*root.fontFactor*osSettings.bigFontSize
|
|
visible: servericon.visible?false:true
|
|
onClicked:{Qt.openUrlExternally(Qt.resolvedUrl("https://dir.friendica.social/servers"))}
|
|
}
|
|
|
|
|
|
TextField {
|
|
id: servername
|
|
x: 4*root.fontFactor*osSettings.bigFontSize; y: 4*root.fontFactor*osSettings.bigFontSize; width: root.width-18*mm; //height: 5*mm;
|
|
placeholderText: qsTr("Server")
|
|
font.pointSize: osSettings.systemFontSize
|
|
onEditingFinished: {
|
|
if ((servername.text)==""){}
|
|
else if((servername.text).substring(0,7) !=="https://"){
|
|
servername.text= "https://"+text//(serverstring.text).substring(8)
|
|
}
|
|
accountPage.setServericon(servername.text)}
|
|
}
|
|
|
|
TextField {
|
|
id: username
|
|
x: root.fontFactor*osSettings.bigFontSize; y: 6*root.fontFactor*osSettings.bigFontSize; width: root.width-9*mm; //height: 5*mm;
|
|
font.pointSize: osSettings.systemFontSize
|
|
placeholderText: qsTr("Nickname")
|
|
selectByMouse: true
|
|
onEditingFinished: {
|
|
if (username.text.indexOf('@')>-1){
|
|
Helperjs.showMessage(qsTr("Error"),qsTr("Nicknames containing @ symbol currently not supported"),accountPage)
|
|
}
|
|
imagestoredir=filesystem.homePath+"/"+username.text+"/"
|
|
//if (imagestore.text==filesystem.homePath+"/.friendiqa/"){imagestore.text=filesystem.homePath+"/.friendiqa/"+username.text+"/"}
|
|
}
|
|
}
|
|
|
|
|
|
TextField {
|
|
id: password
|
|
x: root.fontFactor*osSettings.bigFontSize; y: 9*root.fontFactor*osSettings.bigFontSize; width: root.width-9*mm; //height: 5*mm;
|
|
//font.pixelSize:3*mm
|
|
font.pointSize: osSettings.systemFontSize
|
|
selectByMouse: true
|
|
echoMode: TextInput.Password
|
|
placeholderText: qsTr("Password")
|
|
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText | Qt.ImhSensitiveData
|
|
}
|
|
|
|
Text {
|
|
id: imagedirlabel
|
|
visible: imagestore.text!=""
|
|
text: qsTr("Image dir.")
|
|
font.pointSize: osSettings.systemFontSize
|
|
x: root.fontFactor*osSettings.bigFontSize; y: 12*root.fontFactor*osSettings.bigFontSize
|
|
}
|
|
|
|
TextField {
|
|
id: imagestore
|
|
x: root.fontFactor*osSettings.bigFontSize; y: 13*root.fontFactor*osSettings.bigFontSize; width: root.width-17*mm; //height: 5*mm;
|
|
visible:imagestore.text!=""
|
|
font.pointSize: osSettings.systemFontSize
|
|
selectByMouse: true
|
|
text: "" //filesystem.homePath+"/.friendiqa/"+username.text+"/" //(osSettings.osType=="Android") && (filesystem.fileexist("/storage/emulated/0/Pictures/"))?"/storage/emulated/0/Pictures/":""
|
|
wrapMode: TextEdit.NoWrap
|
|
onTextChanged: imagestoredir=imagestore.text
|
|
}
|
|
MButton {
|
|
x: root.width-3*root.fontFactor*osSettings.bigFontSize; y: 13*root.fontFactor*osSettings.bigFontSize;
|
|
height: 2*root.fontFactor*osSettings.bigFontSize;
|
|
visible:imagestore.text!=""
|
|
text: "..."
|
|
font.pointSize: osSettings.bigFontSize
|
|
onClicked:{imagestoreDialog.open()}
|
|
}
|
|
|
|
|
|
FileDialog {
|
|
id: imagestoreDialog
|
|
title: "Please choose a directory"
|
|
folder: shortcuts.pictures
|
|
selectFolder: true
|
|
onAccepted: {
|
|
var imagestoreString=imagestoreDialog.folder.toString();
|
|
imagestoreString=imagestoreString.replace(/^(file:\/{2})/,"")+"/"
|
|
imagestore.text=imagestoreString
|
|
}
|
|
}
|
|
|
|
|
|
BusyIndicator{
|
|
id: accountBusy
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
y: 16*root.fontFactor*osSettings.bigFontSize
|
|
width:10*mm
|
|
height: 10*mm
|
|
running: false
|
|
}
|
|
|
|
MButton {
|
|
x: root.fontFactor*osSettings.bigFontSize; y: 16*root.fontFactor*osSettings.bigFontSize
|
|
text: qsTr("Confirm")
|
|
font.pointSize: osSettings.bigFontSize
|
|
onClicked:{
|
|
accountBusy.running=true;
|
|
var userconfig={server: servername.text, username: username.text, password:Qt.btoa(password.text), imagestore:imagestoredir, maxnews:"",interval: ""};
|
|
var errormessage="";
|
|
if (servername.text==""){errormessage=qsTr("No server given! ")}
|
|
else if (username.text==""){errormessage+=qsTr("No nickname given! ")}
|
|
else if (password.text=="") {errormessage+=qsTr("No password given! ")}
|
|
else if (imagestoredir=="") {errormessage+=qsTr("No image directory 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=="") {
|
|
Helperjs.friendicaRequest(userconfig,"/api/account/verify_credentials?skip_status=true",root,function(obj){
|
|
accountBusy.running=false;
|
|
var credentials=JSON.parse(obj);
|
|
if (credentials.hasOwnProperty('status')){
|
|
Helperjs.showMessage(qsTr("Error"),qsTr("Wrong password!"),root)
|
|
}
|
|
else{
|
|
if (users.length==0){Service.setDefaultOptions(db);}
|
|
//print("imagestore" + userconfig.imagestore + " path "+ filesystem.homePath+"/"+username.text)
|
|
if(userconfig.imagestore == filesystem.homePath+"/"+username.text+"/")
|
|
{//filesystem.Directory=filesystem.homePath;
|
|
filesystem.makePath(filesystem.homePath+"/"+username.text);
|
|
}
|
|
filesystem.Directory=imagestoredir //userconfig.imagestore;
|
|
filesystem.makeDir("contacts");
|
|
filesystem.makeDir("albums");
|
|
Service.storeConfig(db,userconfig);
|
|
Service.readConfig(db,function(userconfig){
|
|
Helperjs.readData(db,"config","",function(storedUsers){
|
|
storedUsers.sort(function(obj1, obj2) {
|
|
return obj1.isActive - obj2.isActive;
|
|
});
|
|
accountPage.users=storedUsers});
|
|
//reset values
|
|
login=userconfig;
|
|
news=[];
|
|
rootstack.currentIndex=0;
|
|
newstypeSignal("refresh");
|
|
},"isActive",0);
|
|
|
|
//Service.requestProfile(userconfig,db,root,function(nc){root.newContacts=nc});
|
|
Helperjs.showMessage(qsTr("Success"),qsTr("Name")+": "+credentials.name+"\nScreen Name: "+credentials.screen_name,root)
|
|
rootstackView.pop()
|
|
}
|
|
});
|
|
|
|
}
|
|
else {Helperjs.showMessage(qsTr("Error"), errormessage,root)}
|
|
}}
|
|
|
|
|
|
Row{
|
|
spacing:0.5*mm
|
|
anchors.top: parent.top
|
|
anchors.topMargin: root.fontFactor*osSettings.bigFontSize
|
|
anchors.right: parent.right
|
|
anchors.rightMargin: 1*mm
|
|
MButton {
|
|
//x: parent.width/2+4*mm; y: mm;
|
|
width: 5*mm;
|
|
//height: 3*root.fontFactor*osSettings.bigFontSize
|
|
visible: users.length>0
|
|
text: "-"
|
|
font.pointSize: osSettings.bigFontSize
|
|
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://";
|
|
servericon.visible=false;
|
|
servericon.source="";
|
|
username.text="";
|
|
password.text="";
|
|
imagestore.text="";
|
|
//maxNews.value=0;
|
|
//newsTypeField.text="Conversations";
|
|
//messageIntervalSlider.value=30;
|
|
userButton.text=qsTr("User");
|
|
Helperjs.readData(db,"config","",function(storedUsers){
|
|
storedUsers.sort(function(obj1, obj2) {
|
|
return obj1.isActive - obj2.isActive;
|
|
})
|
|
accountPage.users=storedUsers;})
|
|
})
|
|
}}
|
|
|
|
MButton {
|
|
//x: parent.width/2+10*mm; y: mm; //width: 5*mm; height: 8*mm;
|
|
//height: 3*root.fontFactor*osSettings.bigFontSize
|
|
width: 5*mm;
|
|
visible: users.length>0
|
|
text: "+"
|
|
font.pointSize: osSettings.bigFontSize
|
|
onClicked:{
|
|
servername.text="https://"
|
|
servericon.visible=false;
|
|
servericon.source="";
|
|
username.text=""
|
|
password.text=""
|
|
imagestore.text="" //filesystem.homePath+"/.friendiqa/"+username.text//""
|
|
userButton.text=qsTr("User")
|
|
}
|
|
}
|
|
|
|
MButton {
|
|
//x: parent.width-12*mm; y: mm; //width: 5*mm; height: 8*mm;
|
|
//height: 3*root.fontFactor*osSettings.bigFontSize
|
|
width: 5*mm;
|
|
text: "?"
|
|
font.pointSize: osSettings.bigFontSize
|
|
onClicked:{
|
|
rootstackView.push("qrc:/qml/configqml/InfoBox.qml");
|
|
}
|
|
}
|
|
MButton{
|
|
id:closeButton
|
|
//height: 3*root.fontFactor*osSettings.bigFontSize
|
|
width: 5*mm;
|
|
visible: users.length>0
|
|
text: "\uf057"
|
|
font.pointSize: osSettings.bigFontSize
|
|
onClicked:{rootstackView.pop()}
|
|
}
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
try{Helperjs.readData(db,"config","",function(storedUsers){
|
|
storedUsers.sort(function(obj1, obj2) {
|
|
return obj1.isActive - obj2.isActive;
|
|
})
|
|
accountPage.users=storedUsers;
|
|
Service.readConfig(db,function(obj){
|
|
userButton.text=obj.username;
|
|
servername.text=obj.server;
|
|
accountPage.setServericon(obj.server);
|
|
username.text= obj.username;
|
|
password.text=Qt.atob(obj.password);
|
|
imagestore.text=obj.imagestore;
|
|
imagestoredir=obj.imagestore;
|
|
if( obj.isActive==0){userButton.font.bold='true'} else {userButton.font.bold='false'}
|
|
},"isActive",0)
|
|
})}
|
|
catch (e){//print("onCompleted" +users.count +e)
|
|
}
|
|
}
|
|
}
|