Licensing GPLv3
[quicknewsreader] / qml / QuickNewsReader / main.qml
index 0c5cf69..14ec523 100644 (file)
@@ -1,3 +1,21 @@
+/***
+** Copyright (C) 2012 Christophe CHAPUIS <chris.chapuis _at_ gmail _dot_ com>
+**
+** 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 "content/view"
 import "content/modelimpl"
@@ -5,60 +23,30 @@ import "content/modelitf"
 
 Rectangle {
     id: window
+    //anchors.fill: parent // use this little trick to always adapt itself to the screen
     width: 800; height: 480
 
-    property int currentJournalIndex: 0
-    property int currentCategoryIndex: -1
-    property int currentNewsIndex: -1
+    property int currentSourceIndex: 0
 
-    property list<JournalModel> listJournalModel: [
-        LeMondeJournalModel{},
-        FavoriteFeedsJournalModel{},
-        YahooJournalModel{}
+    property list<SourceModel> listSourceModel: [
+        LeMondeSourceModel{},
+        GoogleReaderSourceModel{},
+        FavoriteFeedsSourceModel{},
+        YahooSourceModel{}
     ]
 
+    property variant currentSource: listSourceModel[currentSourceIndex]
+    property bool loading: currentSource.loading
+    property alias windowViewsModel: viewsModel
+    property alias windowViewsList: viewsList
+    property alias currentContentX: viewsList.contentX
+
     ListModel {
-        id: journalList
-
-        ListElement {
-            journalName: 'Le Monde'
-            journalHierarchy: [
-                // list of journals
-                ListElement { component: "content/view/Journals.qml"; componentId: "journalsRect" },
-                // list of categories for a given journal
-                ListElement { component: "content/view/Categories.qml"; componentId: "categoriesRect" },
-                // list of news for a given category
-                ListElement { component: "content/view/News.qml"; componentId: "newsRect" },
-                // Details for a given news
-                ListElement { component: "content/view/NewsDetail.qml"; componentId: "newsDetailRect" }
-            ]
-        }
-        ListElement {
-            journalName: 'Favorite RSS'
-            journalHierarchy: [
-                // list of journals
-                ListElement { component: "content/view/Journals.qml"; componentId: "journalsRect" },
-                // list of categories for a given journal
-                ListElement { component: "content/view/Categories.qml"; componentId: "categoriesRect" },
-                // list of news for a given category
-                ListElement { component: "content/view/News.qml"; componentId: "newsRect" }
-            ]
-        }
-        ListElement {
-            journalName: 'Yahoo! News'
-            journalHierarchy: [
-                // list of journals
-                ListElement { component: "content/view/Journals.qml"; componentId: "journalsRect" },
-                // list of categories for a given journal
-                ListElement { component: "content/view/Categories.qml"; componentId: "categoriesRect" },
-                // list of news for a given category
-                ListElement { component: "content/view/News.qml"; componentId: "newsRect" }
-            ]
-        }
+        id: viewsModel
+
+        ListElement { component: "content/view/Sources.qml"; componentDepth: 0 }
     }
 
-    property variant currentJournal: listJournalModel[currentJournalIndex]
-    property bool loading: currentJournal.loading
 
     ListView {
         id: viewsList
@@ -67,14 +55,40 @@ Rectangle {
         orientation: ListView.Horizontal
         snapMode: ListView.SnapOneItem
         flickDeceleration: 500
+        cacheBuffer: 1600 // so that the next delegate gets actually loaded...
+        preferredHighlightBegin: window.x
+        preferredHighlightEnd: window.width
+        highlightRangeMode: ListView.StrictlyEnforceRange
+        boundsBehavior: Flickable.StopAtBounds
+
+        Behavior on contentX {
+            NumberAnimation { duration: 500; easing.type: Easing.InOutCubic }
+        }
 
-        model: journalList.get(currentJournalIndex).journalHierarchy
+        model: viewsModel
         delegate: Loader {
-            id: componentId
+            id: modelLoader
             source: component
+
+            ListView.onAdd: {
+                viewsList.contentX = componentDepth*window.width
+                //viewsList.currentIndex = componentDepth  // doesn't work well with Qt 4.7.3 on Maemo...
+            }
         }
     }
 
+    function showConfigDialog(index) {
+        configDialog.configModel = listSourceModel[index]
+        configDialog.state = "showSourceConfig"
+    }
+
+    SourceConfigDialog {
+        id:configDialog
+    }
+
+/*
+*/
+
     Component {
         id: quitButtonDelegate
         Item {