Friendiqa/source-android/qml/photoqml/PhotoTab.qml

184 lines
6.4 KiB
QML

import QtQuick 2.0
//import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.4
import QtQml.Models 2.1
import "qrc:/js/service.js" as Service
import "qrc:/js/helper.js" as Helperjs
import "qrc:/qml/photoqml"
import "qrc:/qml/genericqml"
Rectangle {
id:fotorectangle
y:1
width:root.width-mm
height:root.height-5*mm
color: '#fff'
property var newimages:[]
property int currentimageno: 0
onNewimagesChanged:{
if(newimages.length>0){
Helperjs.readField("album",root.db,"imageData",root.login.username,function(albums){
for (var i=0;i<newimages.length;i++){
if(albums.indexOf(newimages[i].album)==-1){
filesystem.Directory=root.login.imagestore+"/albums";
filesystem.makeDir(newimages[i].album)}}
})
Service.dataRequest(root.login,newimages[currentimageno].id,root.db,fotostab);
newImagesProgress.visible=true //download first image
}
}
onCurrentimagenoChanged:{
if(currentimageno<newimages.length){Service.dataRequest(root.login,newimages[currentimageno].id,root.db,fotostab)};
if(currentimageno==newimages.length){newImagesProgress.visible=false;showFotos("");
newimages=[];currentimageno=0}
// download next image
}
Connections{
target:xhr
onDownloaded:{if(data=="picture"){currentimageno=currentimageno+1}}
}
Connections{
target:xhr
onError:{if(data=="picture"){print("Error"+data);
currentimageno=currentimageno+1}}
}
function showFotos(friend){
if(friend=="backButton"){
if(!albumgridview.currentItem){root.currentIndex=0}
if(albumgridview.currentItem.state=='fullscreen'){
albumgridview.currentItem.state = 'inGrid'}
else if (albumgridview.currentItem.state == 'inGrid'){albumgridview.currentItem.state=''}
else{root.currentIndex=0}
}
else{
try {photogroupModel.clear()}catch (e){print(e)}
if (friend){
Service.requestFriendsAlbumPictures(login,friend,fotostab,function(albums){
var msg = {'model': photogroupModel,'albums':albums,'firstalbum':0,'foreignPicture':true}
photoWorker.sendMessage(msg);
})
phototabstatusButton.text=qsTr(friend.screen_name.toString())+qsTr("'s images")
}
else {
Helperjs.readField("album", root.db, "imageData",login.username,function(albums){
if (albums[0]) {
var msg = { 'model': photogroupModel,'albums':albums,'firstalbum':0,'foreignPicture': false};
photoWorker.sendMessage(msg);
}
})
}}
}
ProgressBar{
id: newImagesProgress
width: 15*mm
height: updatePhotolist.height
anchors.top: parent.top
anchors.right:updatePhotolist.left
anchors.rightMargin:mm
visible: false
value: currentimageno/newimages.length
}
BlueButton{
id: updatePhotolist
anchors.top: parent.top
anchors.topMargin: 0.5*mm
anchors.right:phototabstatusButton.left
anchors.rightMargin:mm
text:"\uf021"
onClicked: {
Service.requestList(root.login,root.db, fotostab,function(obj){
newimages=obj;print("newimages"+JSON.stringify(obj))
})}}
BlueButton{
id: phototabstatusButton
anchors.top: parent.top
anchors.topMargin: 0.5*mm
anchors.right: parent.right
anchors.rightMargin:2*mm
text: fotostab.phototabstatus=="Images"?qsTr("Own Images"):fotostab.phototabstatus
onClicked: {phototabmenu.popup()}
}
Menu {
id:phototabmenu
MenuItem {
text: qsTr("Own Images")
onTriggered: {
fotostab.phototabstatus="Images";
// phototabstatusButton.text=qsTr("Own images");
showFotos("")}
}
}
DelegateModel{
id: visualphotoModel
delegate: PhotogroupComponent{}
model: photogroupModel
}
ListModel{
id: photogroupModel
}
GridView {
id: albumgridview
cellWidth: 17*mm
cellHeight: 17*mm
x: mm;y:8*mm
width: parent.width-2*mm; height: parent.height-9*mm
clip: true
model: visualphotoModel.parts.album
footer:Rectangle{
border.color: "#EEEEEE"
border.width: 1
width:12*mm
height:6*mm
Text{
font.pixelSize: 1.5*mm
anchors.centerIn: parent
text:qsTr("More")
}
MouseArea{anchors.fill:parent
onClicked:{
var lastalbum_id=photogroupModel.get(photogroupModel.count-1);
if(photogroupModel.get(photogroupModel.count-1).foreignPictures==false){
Service.requestFriendsAlbumPictures(friend,fotostab,function(albums){
var msg = {'model': photogroupModel,'albums':albums,'firstalbum':lastalbum_id+1,'foreignPicture':true}
photoWorker.sendMessage(msg)
})}
else{Helperjs.readField("album",root.db, "imageData",root.login.username,function(albums){
var msg = { 'model': photogroupModel,'albums':albums,'foreignPicture': false,'firstalbum':lastalbum_id+1};
photoWorker.sendMessage(msg)})}
}}}
}
Rectangle { id: photoBackground; color: 'light grey'; width: parent.width; height: parent.height; opacity: 0; visible: opacity != 0.0 }
ListView { width: parent.width; height:parent.height; model: visualphotoModel.parts.browser; interactive: false }
BlueButton {
id: backButton
text: "\uf057"
x: parent.width - backButton.width - 3*mm
y: -backButton.height - 4*mm
z:2
onClicked: {photoBackground.opacity=0}
}
ListView {anchors.fill: parent; model: visualphotoModel.parts.fullscreen; interactive: false }
WorkerScript{id: photoWorker;source: "qrc:/js/photoworker.js"}
Component.onCompleted: { root.fotoSignal.connect(showFotos);
if (fotostab.phototabstatus=="Images"){showFotos("")}
}
}