Friendiqa/v0.002/Release/source-android/qml/photoqml/PhotoTab.qml

182 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
property string phototabstatus:"Images"
onPhototabstatusChanged:{phototabstatusButton.text=qsTr(phototabstatus)}
y:1
width:root.width-mm
height:root.height-5*mm
color: '#fff'
property var newimages:[]
property int currentimageno: 0
//onLoginChanged:{var msg = {'model': photogroupModel,'albums':[],'firstalbum':0,'foreignPicture':false};
// photoWorker.sendMessage(msg);
//}
onNewimagesChanged:{
if(newimages.length>0){
Helperjs.readField("album",root.db,"imageData",root.login.username,function(albums){
//print("albums"+JSON.stringify(albums)+JSON.stringify(newimages[currentimageno]));
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)}}
})
//print("Current image number"+currentImageNo)
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;showOwnFotos();
newimages=[];currentimageno=0}
// download next image if photoplaceholder is finished saving
}
function showOwnFotos(){
try {photogroupModel.clear()}catch (e){print(e)}
Helperjs.readField("album",root.db, "imageData",root.login.username,function(albums){
if (albums[0]) {
var msg = { 'model': photogroupModel,'albums':albums,'firstalbum':0,'foreignPicture': false};
photoWorker.sendMessage(msg);
};
})
}
Connections{
target:root
onLoginChanged:{var msg = {'model': photogroupModel,'albums':[],'firstalbum':0,'foreignPicture':false};
photoWorker.sendMessage(msg);}
}
Connections{
target:xhr
onDownloaded:{if(data=="picture"){currentimageno=currentimageno+1}}
}
Connections{
target:xhr
onError:{if(data=="picture"){print("Error"+data);
currentimageno=currentimageno+1}}
}
function onFriendsFotos(friend){
fotostab.phototabstatus=friend.screen_name;
//print("Friend "+friend.url);
try {photogroupModel.clear()}catch (e){print(e)}
Service.requestFriendsAlbumPictures(root.login,friend,fotostab,function(albums){
var msg = {'model': photogroupModel,'albums':albums,'firstalbum':0,'foreignPicture':true};
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: qsTr("Update")
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: qsTr(phototabstatus)
onClicked: {phototabmenu.popup()}
}
Menu {
id:phototabmenu
MenuItem {
text: qsTr("Own Images")
onTriggered: {
phototabstatus="Images";
showOwnFotos()}
}
}
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 { anchors.fill: parent; model: visualphotoModel.parts.browser; interactive: false }
BlueButton {
id: backButton
text: qsTr("Back")
x: parent.width - backButton.width - 3*mm
y: -backButton.height - 4*mm
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(onFriendsFotos);}
}