2 ** Copyright (C) 2012 Christophe CHAPUIS <chris.chapuis _at_ gmail _dot_ com>
4 ** This package is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
9 ** This package is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
14 ** You should have received a copy of the GNU General Public License
15 ** along with this package; if not, write to the Free Software
16 ** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 import "../js/SettingsStorage.js" as Storage
28 { viewComponent: 'content/view/Categories.qml' },
29 { viewComponent: 'content/view/News.qml' }
36 property variant categoriesModel: GoogleReaderCategories { }
37 property variant categoryContentModel: GoogleReaderNews { sourceDepth: 2 }
38 property variant categorySubContentModel: GoogleReaderNews { sourceDepth: 3 }
39 property variant newsDetailModel: QtObject {
40 property int sourceDepth: 3
42 property string htmlcontent: ""
43 property string title: ""
44 property string image: ""
47 property variant sidToken;
51 settingsComponent: "GoogleReaderConfig.qml"
52 function storeConfiguration(configUI) {
53 // save the values in the database
54 Storage.setSetting("GoogleReader.login", configUI.loginValue)
55 Storage.setSetting("GoogleReader.password", configUI.passwordValue)
59 function loadConfiguration(configUI) {
60 // retrieve the values from the database
61 configUI.loginValue = Storage.getSetting("GoogleReader.login")
62 configUI.passwordValue = Storage.getSetting("GoogleReader.password")
65 property variant googleReaderLoginWorker: WorkerScript {
66 id: googleReaderLoginWorker
67 source: "../js/GoogleReaderAPI.js"
70 sid = messageObject.sid
71 sidToken = messageObject.sidToken
77 property variant googleReaderLoadCategoryWorker: WorkerScript {
78 id: googleReaderLoadCategoryWorker
79 source: "../js/GoogleReaderAPI.js"
82 categoryContentModel.append({ 'title': messageObject.title, 'description': messageObject.published, 'image': '', 'id': messageObject.id })
87 property variant googleReaderLoadSubscriptionOrTagWorker: WorkerScript {
88 id: googleReaderLoadSubscriptionOrTagWorker
89 source: "../js/GoogleReaderAPI.js"
92 categorySubContentModel.append({ 'title': messageObject.title, 'description': messageObject.published, 'image': '', 'content': messageObject.description })
97 property variant googleReaderLoadItemWorker: WorkerScript {
98 id: googleReaderLoadItemWorker
99 source: "../js/GoogleReaderAPI.js"
102 newsDetailModel.htmlcontent = messageObject.newsContent
108 function tryLogin() {
109 var loginValue = Storage.getSetting("GoogleReader.login")
110 var passwordValue = Storage.getSetting("GoogleReader.password")
114 googleReaderLoginWorker.sendMessage({
117 'password': passwordValue
120 onCurrentPathChanged: {
121 // build the right model. currentPath[1] => category
122 var selectionDepth = 0;
123 while(typeof currentPath[selectionDepth+1] !== "undefined")
126 if( typeof currentPath[1] !== "undefined" ) {
127 if( selectionDepth == 1 ) {
128 // the category has been selected, so fill in the right content
129 categoryContentModel.clear()
131 // reshape the views and the models to fit the chosen path
132 var newsDetailIndex = 2;
133 var tmpListModels = listModels
134 var tmpListViews = listViews
135 if( currentPath[1] === 3 || currentPath[1] === 4 )
137 tmpListModels[2] = categorySubContentModel;
138 tmpListViews[2] = { viewComponent: 'content/view/News.qml' }
141 tmpListModels[newsDetailIndex] = newsDetailModel;
142 tmpListViews[newsDetailIndex] = { viewComponent: 'content/view/NewsDetail.qml' };
143 tmpListModels[newsDetailIndex+1] = null
144 tmpListViews[newsDetailIndex+1] = null
145 listModels = tmpListModels
146 listViews = tmpListViews
148 googleReaderLoadCategoryWorker.sendMessage({
149 'action': 'getCategoryContent',
150 'sid': sid, 'sidToken': sidToken,
151 'category': currentPath[1]
154 else if( selectionDepth == 2 && currentPath[1] === 3 ) {
155 // subscriptions selected
156 categorySubContentModel.clear()
157 googleReaderLoadSubscriptionOrTagWorker.sendMessage({
158 'action': 'getSubscriptionItems',
159 'sid': sid, 'sidToken': sidToken,
160 'subscription': categoryContentModel.get(currentPath[2]).id
163 else if( selectionDepth == 2 && currentPath[1] === 4 ) {
165 categorySubContentModel.clear()
166 googleReaderLoadSubscriptionOrTagWorker.sendMessage({
167 'action': 'getTaggedItems',
168 'sid': sid, 'sidToken': sidToken,
169 'tag': categoryContentModel.get(currentPath[2]).id
172 else if( selectionDepth == 3 ) {
173 // subscription or tagged item selected
174 newsDetailModel.htmlcontent = categorySubContentModel.get(currentPath[3]).content
176 else if( selectionDepth == 2 ) {
177 // simply get the chosen news
178 newsDetailModel.htmlcontent = categoryContentModel.get(currentPath[2]).content
183 Component.onCompleted: {