/*** ** Copyright (C) 2012 Christophe CHAPUIS ** ** This package 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 2 of the License, or ** (at your option) any later version. ** ** This package 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 package; if not, write to the Free Software ** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ** ***/ import QtQuick 1.0 import "../modelitf" import "../js/SettingsStorage.js" as Storage SourceModel { id: googleReaderModel name: "Google Reader" listViews: [ { viewComponent: 'content/view/Categories.qml' }, { viewComponent: 'content/view/News.qml' } ] listModels: [ categoriesModel, categoryContentModel ] property variant categoriesModel: GoogleReaderCategories { } property variant categoryContentModel: GoogleReaderNews { sourceDepth: 2 } property variant categorySubContentModel: GoogleReaderNews { sourceDepth: 3 } property variant newsDetailModel: QtObject { property int sourceDepth: 3 property string htmlcontent: "" property string title: "" property string image: "" } property variant sid; property variant sidToken; loading: false hasSettings: true settingsComponent: "GoogleReaderConfig.qml" function storeConfiguration(configUI) { // save the values in the database Storage.setSetting("GoogleReader.login", configUI.loginValue) Storage.setSetting("GoogleReader.password", configUI.passwordValue) tryLogin() } function loadConfiguration(configUI) { // retrieve the values from the database configUI.loginValue = Storage.getSetting("GoogleReader.login") configUI.passwordValue = Storage.getSetting("GoogleReader.password") } property variant googleReaderLoginWorker: WorkerScript { id: googleReaderLoginWorker source: "../js/GoogleReaderAPI.js" onMessage: { sid = messageObject.sid sidToken = messageObject.sidToken loading = false } } property variant googleReaderLoadCategoryWorker: WorkerScript { id: googleReaderLoadCategoryWorker source: "../js/GoogleReaderAPI.js" onMessage: { categoryContentModel.append({ 'title': messageObject.title, 'description': messageObject.published, 'image': '', 'id': messageObject.id }) loading = false } } property variant googleReaderLoadSubscriptionOrTagWorker: WorkerScript { id: googleReaderLoadSubscriptionOrTagWorker source: "../js/GoogleReaderAPI.js" onMessage: { categorySubContentModel.append({ 'title': messageObject.title, 'description': messageObject.published, 'image': '', 'content': messageObject.description }) loading = false } } property variant googleReaderLoadItemWorker: WorkerScript { id: googleReaderLoadItemWorker source: "../js/GoogleReaderAPI.js" onMessage: { newsDetailModel.htmlcontent = messageObject.newsContent loading = false } } function tryLogin() { var loginValue = Storage.getSetting("GoogleReader.login") var passwordValue = Storage.getSetting("GoogleReader.password") loading = true googleReaderLoginWorker.sendMessage({ 'action': 'login', 'email': loginValue, 'password': passwordValue }) } onCurrentPathChanged: { // build the right model. currentPath[1] => category var selectionDepth = 0; while(typeof currentPath[selectionDepth+1] !== "undefined") selectionDepth++; if( typeof currentPath[1] !== "undefined" ) { if( selectionDepth == 1 ) { // the category has been selected, so fill in the right content categoryContentModel.clear() // reshape the views and the models to fit the chosen path var newsDetailIndex = 2; var tmpListModels = listModels var tmpListViews = listViews if( currentPath[1] === 3 || currentPath[1] === 4 ) { tmpListModels[2] = categorySubContentModel; tmpListViews[2] = { viewComponent: 'content/view/News.qml' } newsDetailIndex = 3; } tmpListModels[newsDetailIndex] = newsDetailModel; tmpListViews[newsDetailIndex] = { viewComponent: 'content/view/NewsDetail.qml' }; tmpListModels[newsDetailIndex+1] = null tmpListViews[newsDetailIndex+1] = null listModels = tmpListModels listViews = tmpListViews googleReaderLoadCategoryWorker.sendMessage({ 'action': 'getCategoryContent', 'sid': sid, 'sidToken': sidToken, 'category': currentPath[1] }) } else if( selectionDepth == 2 && currentPath[1] === 3 ) { // subscriptions selected categorySubContentModel.clear() googleReaderLoadSubscriptionOrTagWorker.sendMessage({ 'action': 'getSubscriptionItems', 'sid': sid, 'sidToken': sidToken, 'subscription': categoryContentModel.get(currentPath[2]).id }) } else if( selectionDepth == 2 && currentPath[1] === 4 ) { // tags selected categorySubContentModel.clear() googleReaderLoadSubscriptionOrTagWorker.sendMessage({ 'action': 'getTaggedItems', 'sid': sid, 'sidToken': sidToken, 'tag': categoryContentModel.get(currentPath[2]).id }) } else if( selectionDepth == 3 ) { // subscription or tagged item selected newsDetailModel.htmlcontent = categorySubContentModel.get(currentPath[3]).content } else if( selectionDepth == 2 ) { // simply get the chosen news newsDetailModel.htmlcontent = categoryContentModel.get(currentPath[2]).content } } } Component.onCompleted: { Storage.initialize() tryLogin() } }