Friendiqa/v0.002/Develop/source-linux/qml/FriendsTab.qml

175 lines
5.7 KiB
QML
Raw Normal View History

import QtQuick 2.0
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.2
import "qrc:/js/service.js" as Service
import "qrc:/js/helper.js" as Helperjs
import "qrc:/js/news.js" as Newsjs
import "qrc:/qml"
Rectangle {
y:1
color: "white"
TabView{
id:friendsTabView
// property var contacts: []
// property var groups: []
tabPosition: Qt.TopEdge
x:mm
y:mm
width: root.width-5*mm
height: root.height-10*mm
currentIndex: 0
signal friendsSignal(var username)
signal contactsSignal(var username)
signal groupsSignal(var username)
onCurrentIndexChanged:{
if (currentIndex==0){friendsSignal(root.login.username)}
else if (currentIndex==1){contactsSignal(root.login.username)}
else if (currentIndex==2){groupsSignal(root.login.username)}
}
Tab{
title: qsTr("Friends")
Rectangle{
id: friendsGridTab
function showFriends(username){
try {friendsModel.clear()} catch(e){print(e)};
Helperjs.readData(db,"contacts",username,function(friends){
for (var i=0;i<friends.length;i++){
friendsModel.append({"friend":friends[i]});
}},"isFriend",1)
}
Button {
id: updateFriendsButton
text: qsTr("Update")
anchors.top: parent.top
anchors.right: parent.right
onClicked: {
try {friendsModel.clear()} catch(e){print(e)};
root.contactLoadType="friends";
Newsjs.requestFriends(root.login,db,root,function(nc){
root.newContacts=nc
})
}}
ProgressBar{
id: newContactsProgress
width: 15*mm
height: updateFriendsButton.height
anchors.top: parent.top
anchors.right:updateFriendsButton.left
anchors.rightMargin:mm
visible: (root.currentContact!=root.newContacts.length)?true:false
value: root.currentContact/root.newContacts.length
}
GridView {
id: friendsView
x:mm
y:updateFriendsButton.height+mm
width:friendsGridTab.width-2*mm
height:friendsGridTab.height-updateFriendsButton.height-2*mm
clip: true
cellHeight: 16*mm
cellWidth: 17*mm
add: Transition {
NumberAnimation { properties: "x,y"; from: 300; duration: 1000 }
}
model: friendsModel
delegate: FriendComponent { }
}
ListModel{id:friendsModel}
Component.onCompleted: {
friendsTabView.friendsSignal.connect(showFriends);
showFriends(root.login.username)
}
}
}
Tab{
title: qsTr("Other Contacts")
Rectangle{
id: contactsGridTab
function showContacts(username){
try {contactsModel.clear()} catch(e){print(e)};
Helperjs.readData(db, "contacts",root.login.username,function(friendsobject){
for (var j=0;j<friendsobject.length;j++){
contactsModel.append({"friend":friendsobject[j]});
}
},"isFriend",0)}
GridView {
id: contactsView
x:mm
y:mm
width:contactsGridTab.width-2*mm
height:contactsGridTab.height-2*mm
clip: true
cellHeight: 16*mm
cellWidth: 17*mm
add: Transition {
NumberAnimation { properties: "x,y"; from: 300; duration: 1000 }
}
model: contactsModel
delegate: FriendComponent { }
}
ListModel{id: contactsModel}
Component.onCompleted: {
friendsTabView.contactsSignal.connect(showContacts);
}
}
}
Tab{
title: qsTr("Groups")
Rectangle{
id: groupsGridTab
function showGroups(username){
try {groupsModel.clear()} catch(e){print(e)};
print("showGroups"+username);
Helperjs.readData(db, "groups",root.login.username,function(groupsobject){
for (var j=0;j<groupsobject.length;j++){
groupsModel.append({"group":groupsobject[j]});
}})}
Button {
id: updateGroupsButton
text: qsTr("Update")
anchors.top: parent.top
anchors.right: parent.right
onClicked: {
print("Update groups");
Newsjs.requestGroups(root.login,root.db,root,function(){
showGroups(root.login.username)})}
}
GridView {
id: groupsView
x:mm
y:updateGroupsButton.height+mm
width:groupsGridTab.width-2*mm
height:groupsGridTab.height-updateGroupsButton.height-2*mm
clip: true
cellHeight: 16*mm
cellWidth: 17*mm
add: Transition {
NumberAnimation { properties: "x,y"; from: 300; duration: 1000 }
}
model: groupsModel
delegate: GroupComponent { }
}
ListModel{
id: groupsModel
}
Component.onCompleted: {
friendsTabView.groupsSignal.connect(showGroups);
}
}
}
}
}