psa: using 2 flickables
[feedingit] / psa_harmattan / feedingit / deb_dist / feedingit-0.1.0 / qml / main.qml
index dad5f3a..0b47445 100644 (file)
@@ -1,15 +1,59 @@
 import QtQuick 1.0
 import com.nokia.meego 1.0
 
-
 PageStackWindow {
     id: window
     initialPage: categoryPage
 
-    signal articleClosed()
+    signal longPressCategory(string catid)
+    signal longPressFeed(string key)
+    signal categoryReloadRequest()
+    signal feedReloadRequest()
+    signal articlesReloadRequest()
+    signal addFileSignal(string fullname, string filename)
+
+    property string articleid
     property string feedid
     property string catid
 
+    property bool isUpdateInProgress: false
+    property int updateProgressValue: 0
+
+    function addFileNotification(fullname, filename) {
+        window.addFileSignal(fullname,filename)
+    }
+
+    function updateStarted() {
+        banner.show(qsTr("Update Started"))
+        updateProgressValue = 0
+        isUpdateInProgress = true
+    }
+
+    function updateFinished() {
+        categoryReloadRequest()
+        feedReloadRequest()
+        banner.show(qsTr("Updated Completed"))
+        isUpdateInProgress = false
+    }
+
+    function updateProgress(total, completed) {
+        if (total>0) {
+            updateProgressValue = Math.round(100*completed/total);
+        } else {
+            updateProgressValue = 0
+        }
+    }
+
+    onLongPressFeed: {
+        unsubscribeFeedMenu.key = key
+        unsubscribeFeedMenu.open()
+    }
+
+    onLongPressCategory: {
+        unsubscribeCategoryMenu.catid = catid
+        unsubscribeCategoryMenu.open()
+    }
+
     ToolBarLayout {
         id: commonTools
         visible: false
@@ -26,9 +70,9 @@ PageStackWindow {
         id: myMenu
         visualParent: pageStack
         MenuLayout {
-            MenuItem { text: qsTr("Settings"); onClicked: {}  }
-            MenuItem { text: qsTr("Add Feeds"); onClicked: { pageStack.push(addFeedPage)  } }
-            MenuItem { text: qsTr("Update All Categories"); visible: pageStack.depth==3; onClicked: controller.updateAll(); }
+            MenuItem { text: qsTr("Settings"); onClicked: {pageStack.push(settingsPage)}  }
+            MenuItem { text: qsTr("Manage Subscriptions"); onClicked: { pageStack.push(addFeedPage)  } }
+            MenuItem { text: qsTr("Update All Categories"); onClicked: controller.updateAll(); }
             MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
         }
     }
@@ -37,8 +81,8 @@ PageStackWindow {
         id: myFeedsMenu
         visualParent: pageStack
         MenuLayout {
-            MenuItem { text: qsTr("Update All Feeds"); onClicked: controller.updateAll(); }
-            MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
+            MenuItem { text: qsTr("Update All Feeds"); onClicked: controller.updateCategory(catid); }
+            //MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
         }
     }
 
@@ -46,9 +90,67 @@ PageStackWindow {
         id: myArticlesMenu
         visualParent: pageStack
         MenuLayout {
-            MenuItem { text: qsTr("Mark All As Read"); onClicked: controller.markAllAsRead(feedid); }
+            MenuItem { text: qsTr("Mark All As Read"); onClicked: {
+                    controller.markAllAsRead(feedid);
+                    articlesReloadRequest()
+                }
+            }
             MenuItem { text: qsTr("Update Feed"); onClicked: controller.updateFeed(feedid); }
-            MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
+            //MenuItem { text: qsTr("About FeedingIt"); onClicked: query.open(); }
+        }
+    }
+
+    Menu {
+        id: unsubscribeFeedMenu
+        visualParent: pageStack
+        property string key
+        MenuLayout {
+            //MenuItem { text: qsTr("Update"); onClicked: controller.updateFeed(parent.feedid); }
+            MenuItem { text: qsTr("Delete");
+                onClicked: {
+                    feedConfirm.open()
+                    unsubscribeFeedMenu.close()
+                }
+            }
+        }
+        QueryDialog {
+            id: feedConfirm
+            //icon: "common/images/feedingit.png"
+            //titleText: "Delete Feed?"
+            message: "Delete this feed?"
+            acceptButtonText: "OK"
+            rejectButtonText: "Cancel"
+            onAccepted: {
+                controller.removeFeed(unsubscribeFeedMenu.key);
+                window.feedReloadRequest()
+            }
+        }
+    }
+
+    Menu {
+        id: unsubscribeCategoryMenu
+        visualParent: pageStack
+        property string catid
+        MenuLayout {
+            //MenuItem { text: qsTr("Update"); onClicked: controller.updateFeed(parent.feedid); }
+            MenuItem { text: qsTr("Delete");
+                onClicked: {
+                    categoryConfirm.open()
+                    unsubscribeFeedMenu.close()
+                }
+            }
+        }
+        QueryDialog {
+            id: categoryConfirm
+            //icon: "common/images/feedingit.png"
+            //titleText: "Delete Feed?"
+            message: "Delete this category?"
+            acceptButtonText: "OK"
+            rejectButtonText: "Cancel"
+            onAccepted: {
+                controller.removeCategory(unsubscribeCategoryMenu.catid);
+                window.categoryReloadRequest()
+            }
         }
     }
 
@@ -56,30 +158,31 @@ PageStackWindow {
         id: query
         icon: "common/images/feedingit.png"
         titleText: "Feedingit RSS Reader"
-        message: "Version: 0.0.9"
+        message: "Version: n9-0.1.0"
         +"<br><br>FeedingIt RSS Reader.<br>"
         +"<br>&copy; 2011 feedingit.marcoz.org"
         +"<br>http://feedingit.marcoz.org"
         acceptButtonText: "OK"
     }
 
-//    Page{
-//        id: mainPage
-//        Component.onCompleted: {
-//            var main = Qt.createComponent("FeedingIt.qml");
-//            main.createObject(mainPage);
-//        }
-//    }
-
     Component {
         id: categoryPage
         Page {
             tools: commonTools
             Categories {
+                id: categoriesItem
                 onCategoryClicked: {
                     window.catid = cat
                     pageStack.push(feedsPage)
                 }
+
+            }
+            Connections {
+                target: window
+                onCategoryReloadRequest: {
+                    console.log("category reloaded")
+                    categoriesItem.reload()
+                }
             }
         }
     }
@@ -95,8 +198,9 @@ PageStackWindow {
                 id: feedsItem
                 onFeedClicked: {
                     window.feedid = feedid
-                    pageStack.push(articlesPage)
+                    pageStack.push(articlesListPage)
                 }
+
             }
             ToolBarLayout {
                 id: feedsTools
@@ -104,6 +208,7 @@ PageStackWindow {
                 ToolIcon { iconId: "toolbar-back";
                     onClicked: {
                         myArticlesMenu.close();
+                        window.categoryReloadRequest()
                         pageStack.pop();
                     }
                 }
@@ -115,59 +220,187 @@ PageStackWindow {
             }
             Connections {
                  target: window
-                 onArticleClosed: feedsItem.reload()
+                 onFeedReloadRequest: feedsItem.reload()
              }
         }
     }
 
     Component {
-        id: articlesPage
+        id: articlesListPage
         Page {
-            tools: articleTools
+            tools: articleListTools
             property string feedid: window.feedid
+
             ArticleViewer {
                 id: flipper
+
+                onOpenArticle: {
+                    window.articleid = articleid
+                    pageStack.push(articleViewPage)
+                }
             }
 
             ToolBarLayout {
-                id: articleTools
+                id: articleListTools
                 visible: false
                 ToolIcon { iconId: "toolbar-back";
                     onClicked: {
                         myArticlesMenu.close();
-                        if (flipper.articleShown) {
-                            flipper.articleShown = false;
-                            flipper.reload()
-                        } else {
-                            window.articleClosed();
-                            pageStack.pop();
-                        }
+                        window.feedReloadRequest();
+                        pageStack.pop();
                     }
                 }
 
                 ToolIcon {
-                    platformIconId: "toolbar-prev"
-                    //anchors.right: (parent === undefined) ? undefined : parent.right
-                    onClicked: flipper.prev();
+                    platformIconId: "toolbar-view-menu"
+                    anchors.right: (parent === undefined) ? undefined : parent.right
+                    onClicked: (myArticlesMenu.status == DialogStatus.Closed) ? myArticlesMenu.open() : myArticlesMenu.close()
+                }
+            }
+            Connections {
+                 target: window
+                 onArticlesReloadRequest: flipper.reload()
+             }
+        }
+    }
+
+    Component {
+        id: articleViewPage
+        Page {
+            tools: articleTools
+            property string feedid: window.feedid
+
+
+            Articles {
+                id: articlePage
+                property string mainArticleId: window.articleid;
+            }
+
+            ToolBarLayout {
+                id: articleTools
+                visible: false
+                ToolIcon { iconId: "toolbar-back";
+                    onClicked: {
+                        window.articlesReloadRequest();
+                        pageStack.pop();
+                    }
                 }
 
                 ToolIcon {
-                    platformIconId: "toolbar-next"
-                    //anchors.right: (parent === undefined) ? undefined : parent.right
-                    onClicked: flipper.next()
+                    platformIconId: "toolbar-previous"
+                    onClicked: articlePage.prev();
                 }
 
                 ToolIcon {
-                    platformIconId: "toolbar-view-menu"
-                    anchors.right: (parent === undefined) ? undefined : parent.right
-                    onClicked: (myArticlesMenu.status == DialogStatus.Closed) ? myArticlesMenu.open() : myArticlesMenu.close()
+                    platformIconId: "toolbar-share"
+                    onClicked: {
+                        controller.share(window.feedid, articlePage.mainArticleId);
+                    }
                 }
+
+                ToolIcon {
+                    platformIconId: "toolbar-next"
+                    onClicked: articlePage.next()
+                }
+
+//                ToolIcon {
+//                    platformIconId: "toolbar-view-menu"
+//                    anchors.right: (parent === undefined) ? undefined : parent.right
+//                    onClicked: (myArticlesMenu.status == DialogStatus.Closed) ? myArticlesMenu.open() : myArticlesMenu.close()
+//                }
             }
+//            Connections {
+//                 target: window
+//                 onArticlesReloadRequest: flipper.reload()
+//             }
         }
     }
 
     Component {
         id: addFeedPage
-        AddFeed {}
+        AddFeed {
+            id: addFeedItem
+
+            Connections {
+                 target: window
+                 onAddFileSignal: addFeedItem.addFileToDialog(fullname, filename)
+             }
+        }
+    }
+
+    Component {
+        id: settingsPage
+        SettingsPage {
+            id: settingsItem
+            tools: commonTools
+        }
+    }
+
+    Settings {
+        id: settings
+    }
+
+    Rectangle {
+        id: banner
+        x: 10
+        width: parent.width - 20
+        height: bannerText.height + 20
+        y: 50
+        z:8
+
+        visible: false
+        radius: 4
+        border.color: "white"
+        color: "black"
+
+        Text {
+            id: bannerText
+            anchors.centerIn: parent
+            font.pixelSize: 24
+            //text: "Test"
+            color: "white"
+            wrapMode: Text.WordWrap;
+        }
+
+        Timer {
+            id: bannerTimer
+            interval: 3000
+            repeat: false
+            running: false
+            onTriggered: banner.visible = false
+        }
+
+        function show(str) {
+            bannerText.text = str;
+            banner.visible = true
+            bannerTimer.start()
+        }
+
+        MouseArea {
+            anchors.fill: parent
+            onClicked: {
+                bannerTimer.stop()
+                banner.visible= false
+            }
+        }
+
+        //text: "This is an info banner with no icon"
     }
+
+//    Item {
+//        AutomaticUpdate {
+//            id: autoUpdate
+//        }
+
+//        Connections {
+//            target: settings
+//            onAutoUpdateEnabledChanged: {
+//                if (!settings.autoUpdateEnabled) {
+//                    autoUpdate.stop();
+//                } else {
+//                    autoUpdate.start();
+//                }
+//            }
+//        }
+//    }
 }