~nskaggs/ubuntu-rssreader-app/carla-feed-commit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import QtQuick 2.0
import QtQuick.XmlListModel 2.0

import Ubuntu.Components 0.1
import Ubuntu.Components.ListItems 0.1 as ListItems
import Ubuntu.Components.Popups 0.1

import "databasemodule_v2.js" as DB2

Page {

    signal backRequst
    signal articleSelected(var data) // mb id.
    property string feedLink: ""

    /* 1. Loading data from database by url.
     * 2. Appending data to ListModel for displaying.
     */
    function loadArticles(params) {
        articleListModel.clear()
        var res = DB2.loadArticles(params)
        var entries = res.rows

        for (var i = 0; i < entries.length; i++) {
            articleListModel.append({"title":entries.item(i).title,
                                     "content":entries.item(i).content,
                                     "link":entries.item(i).link,
                                     "description":entries.item(i).description,
                                     "pubdate":entries.item(i).pubdate,
                                     "status":entries.item(i).status,
                                     "favourite":entries.item(i).favourite,
                                     "feed_id":entries.item(i).feed_id,
                                     "guid":entries.item(i).hash})
        }
        console.log("Loaded articles, isAll:", params.isAll, " feedId:", params.feedId)
    }

    onFeedLinkChanged: {
        loadEntriesByUrl(feedLink)
    }

    tools: ToolbarActions {
        back {
            visible: true
            onTriggered: {
                console.log("Back triggered!")
                backRequst()
            }
        }
    }

    ListView {
        id: articleList

        clip: true
        anchors.fill: parent

        model: ListModel {
            id: articleListModel
        }

        delegate: ListItems.Subtitled {
            text: model.title
            subText: model.pubdate
            progression: true

            onPressAndHold: {
                articleList.currentIndex = model.index
                PopupUtils.open(articleContextMenu, articleList)
            }

            onClicked: {
                //mainPageStack.push(singleEntryPage)
                //singleEntryPage.content.loadHtml((model.content !== "")? model.content : model.description) // FIRST WAY
                articleSelected((model.content !== "")? model.content : model.description) // FIRST WAY
            }
        } // delegate
    } // ListView


    Component {
        id: articleContextMenu

        /* This new popover works like context menu.
         * Actions can be reused in toolbar.
         */
        ActionSelectionPopover {
            id: articlePopover
            actions: ActionList {
                id: articleActionsList
                Action {
                    id: nameActionUpdate
                    text: i18n.tr("Add to favorites TODO")
                    onTriggered: {

                    }
                }

//                Action {
//                    text: i18n.tr("Edit")
//                    onTriggered: {
//                        PopupUtils.close(articlesPopover)
//                        var data = feedListModel.get(feedList.currentIndex)
//                        console.log("START EDIT ", data.source, data.status)
//                        if (data.status == '0') {
//                            console.log("EDIT ABORT")
//                            return
//                        }

//                        PopupUtils.open(popoverSheetComponent, tools, {"isForEdit":true, "itemData" : data})
//                    }
//                }

                Action {
                    text: i18n.tr("Open site")
                    onTriggered: {
                        PopupUtils.close(articlePopover)
                        Qt.openUrlExternally(articleListModel.get(articleList.currentIndex).link)
                    }
                }
            } // ActionList
        } // ActionSelectionPopover
    } // Popover component

    /* SECOND WAY OF DISPLAYING FEED. DOES NOT WORK ON MY QT5 LIBS, BUG */
    //    Flickable {
    //        id: tmpLabelFlick
    //        clip: true
    //        width: parent.width



    //        anchors {
    //            top: newsList.bottom
    //            bottom: parent.bottom
    //            margins: units.gu(1)
    //        }
    //        contentWidth: parent.width
    //        contentHeight: contentLabel.height

    //        Label {
    //            id: contentLabel

    //            // text: "Some text! <img src='avatar@8.png'/> Second part of the text!"
    //            text: "Some text! <img src='/home/qtros/splashScreen_256.png'/> Second part of the text!"
    //            wrapMode: Text.WordWrap
    //            width: parent.width
    //            textFormat: Text.RichText
    //        }
    //    }
}