Initial commit
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
import QtQuick 2.0
|
||||
|
||||
Item {
|
||||
property string src: ""
|
||||
// property int donevalue: 3
|
||||
property bool done: true//donevalue !== 3 ? false : true
|
||||
JSONSimple {
|
||||
id: showupdated
|
||||
source: src
|
||||
|
||||
onReadyChanged: {
|
||||
if (ready) {
|
||||
var id
|
||||
var name
|
||||
var image
|
||||
var summary
|
||||
var status
|
||||
var premiered
|
||||
var rating
|
||||
var network
|
||||
var updated
|
||||
var next
|
||||
var prev
|
||||
var imdb
|
||||
|
||||
simple.id ? id = simple.id : id = "???"
|
||||
simple.name ? name = simple.name : name = "???"
|
||||
simple.image.medium ? image = simple.image.medium : image = "???"
|
||||
simple.summary ? summary = simple.summary : summary = "???"
|
||||
simple.status ? status = simple.status : status = "???"
|
||||
simple.premiered ? premiered = simple.premiered : premiered = "???"
|
||||
simple.rating.average ? rating = simple.rating.average : rating = "???"
|
||||
simple.webChannel ? network = simple.webChannel.name : network = simple.network.name
|
||||
simple.updated ? updated = simple.updated : updated = "???"
|
||||
|
||||
simple._links.previousepisode ? prev = simple._links.previousepisode.href : prev = ""
|
||||
simple._links.nextepisode ? next = simple._links.nextepisode.href : next = ""
|
||||
simple.externals.imdb ? imdb = simple.externals.imdb : imdb = ""
|
||||
|
||||
|
||||
updateFav(id, name, image, summary, status, premiered, rating, network, updated, prev, next, imdb)
|
||||
//donevalue = donevalue + 1
|
||||
|
||||
console.log("---SHOWUPDATED: "+simple.name)
|
||||
done = true
|
||||
// prevshow.shid = simple.id
|
||||
// simple._links.previousepisode ? prevshow.source = simple._links.previousepisode.href : donevalue = donevalue + 1
|
||||
// nextshow.shid = simple.id
|
||||
// simple._links.nextepisode ? nextshow.source = simple._links.nextepisode.href : donevalue = donevalue + 1
|
||||
|
||||
|
||||
|
||||
|
||||
/* if (typeof(simple._links.nextepisode.href) == 'undefined') {
|
||||
donevalue = donevalue + 1
|
||||
} else nextshow.source = simple._links.nextepisode.href */
|
||||
|
||||
|
||||
/* if (simple.status !== "Ended") {
|
||||
prevshow.next =
|
||||
prevshow.source = simple._links.previousepisode.href
|
||||
nextshow.source = simple._links.nextepisode.href
|
||||
} */
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSONSimple {
|
||||
id: nextshow
|
||||
property int shid
|
||||
onReadyChanged: {
|
||||
if (ready) {
|
||||
var senext = "S"+simple.season+"E"+simple.number
|
||||
updateNext(shid, simple.airdate, senext);
|
||||
donevalue = donevalue + 1
|
||||
console.log("---NEXT: "+shid+" : "+simple.airdate)
|
||||
|
||||
// snext = simple.airdate // update database here
|
||||
// senext = "S"+simple.season+"E"+simple.number
|
||||
|
||||
// list.append({"cost": 5.95, "name":"Pizza"})
|
||||
// updateFav(sshowid, showName, showimg, ssummary, showStatus, showPrem, showRating, showNetwork, shupdated, sprev, snext, senext);
|
||||
//showPrev.text = sprev
|
||||
//showNext.text = snext
|
||||
//reloadFav()
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSONSimple {
|
||||
id: prevshow
|
||||
property int shid
|
||||
onReadyChanged: {
|
||||
if (ready) {
|
||||
updatePrev(shid, simple.airdate);
|
||||
donevalue = donevalue + 1
|
||||
console.log("---PREVIOUS: "+shid+" : "+simple.airdate)
|
||||
// console.log("PREV: "+simple.airdate)
|
||||
// sprev = simple.airdate
|
||||
// senext = ""
|
||||
// if (showupdated.simple._links.nextepisode) {
|
||||
// console.log("GOING NEXT")
|
||||
// nextshow.source = lnext
|
||||
// } else {
|
||||
// console.log("NOT GOING NEXT")
|
||||
// snext = "" //update database here
|
||||
// updateFav(sshowid, showName, showimg, ssummary, showStatus, showPrem, showRating, showNetwork, shupdated, sprev, snext, senext);
|
||||
//showPrev.text = sprev
|
||||
//showNext.text = snext
|
||||
//reloadFav()
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/* JSONListModel - a QML ListModel with JSON and JSONPath support
|
||||
*
|
||||
* Copyright (c) 2012 Romain Pokrzywka (KDAB) (romain@kdab.com)
|
||||
* Licensed under the MIT licence (http://opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
import QtQuick 2.0
|
||||
import "../js/jsonpath.js" as JSONPath
|
||||
|
||||
Item {
|
||||
property string source: ""
|
||||
property string json: ""
|
||||
property string query: ""
|
||||
property bool jsonready: true
|
||||
property bool modelready: true
|
||||
property bool prev: false
|
||||
property bool next: false
|
||||
property string sortby: ""
|
||||
//property string filterby: ""
|
||||
//property string filterkey: ""
|
||||
|
||||
property ListModel model : ListModel { id: jsonModel }
|
||||
property alias count: jsonModel.count
|
||||
//property alias get: jsonModel.get
|
||||
|
||||
onSourceChanged: {
|
||||
if (source !== "") {
|
||||
jsonready = false
|
||||
modelready = false
|
||||
var xhr = new XMLHttpRequest;
|
||||
xhr.open("GET", source);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE)
|
||||
json = xhr.responseText;
|
||||
}
|
||||
xhr.send();
|
||||
} else jsonModel.clear();
|
||||
}
|
||||
|
||||
onJsonChanged: updateJSONModel()
|
||||
onQueryChanged: updateJSONModel()
|
||||
//onFilterbyChanged: updateJSONModel()
|
||||
//onFilterkeyChanged: updateJSONModel()
|
||||
|
||||
function updateJSONModel() {
|
||||
jsonModel.clear();
|
||||
|
||||
if ( json === "" )
|
||||
return;
|
||||
|
||||
var objectArray = parseJSONString(json, query);
|
||||
|
||||
if (sortby !== "") objectArray = sortByKey(objectArray, sortby);
|
||||
//if (filterby !== "" && filterkey !=="") objectArray = filterValuePart(objectArray, filterby, filterkey);
|
||||
|
||||
for ( var key in objectArray ) {
|
||||
var jo = objectArray[key];
|
||||
if( jo.toString() === "[object Object]"){
|
||||
jsonModel.append( jo );
|
||||
} else {
|
||||
//this is comma separated strings
|
||||
var str = jo.toString().split(",");
|
||||
for(var i = 0; i < str.length; i++){
|
||||
jsonModel.append({ "item": str[i] } );
|
||||
}
|
||||
break;
|
||||
}
|
||||
// var jo = objectArray[key];
|
||||
// jsonModel.append( jo );
|
||||
// console.log("JSON: "+objectArray[key])
|
||||
}
|
||||
jsonready = true
|
||||
}
|
||||
|
||||
function parseJSONString(jsonString, jsonPathQuery) {
|
||||
var objectArray = JSON.parse(jsonString);
|
||||
if ( jsonPathQuery !== "" )
|
||||
objectArray = JSONPath.jsonPath(objectArray, jsonPathQuery);
|
||||
|
||||
return objectArray;
|
||||
}
|
||||
|
||||
function filterValuePart(array, part, key) {
|
||||
part = part.toLowerCase();
|
||||
return array.filter(function(a) {
|
||||
var x = a[key];
|
||||
return x.toLowerCase().indexOf(part) !== -1;
|
||||
});
|
||||
}
|
||||
|
||||
function sortByKey(array, key) {
|
||||
var res = key.split(".")
|
||||
//console.log("RES: "+res.length)
|
||||
if (res.length === 1) {
|
||||
return array.sort(function(a, b) {
|
||||
var x = a[res[0]]; var y = b[res[0]];
|
||||
return ((x > y) ? -1 : ((x < y) ? 1 : 0));
|
||||
});
|
||||
} else {
|
||||
return array.sort(function(a, b) {
|
||||
var x = a[res[0]][res[1]]; var y = b[res[0]][res[1]];
|
||||
return ((x > y) ? -1 : ((x < y) ? 1 : 0));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import QtQuick 2.0
|
||||
|
||||
Item {
|
||||
property string source: ""
|
||||
property variant simple
|
||||
property bool ready: true
|
||||
|
||||
onSourceChanged: {
|
||||
ready = false
|
||||
request(source, function (o) {
|
||||
//console.log(o.responseText);
|
||||
simple = eval('new Object(' + o.responseText + ')');ready = true;
|
||||
});
|
||||
|
||||
}
|
||||
function request(url, callback) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = (function(myxhr) {
|
||||
return function() {
|
||||
if (myxhr.readyState === XMLHttpRequest.DONE && xhr.status == 200) {callback(myxhr);}
|
||||
}
|
||||
})(xhr);
|
||||
xhr.open('get', url, true);
|
||||
xhr.send('');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user