~qqworini/ubuntu-rssreader-app/alpha-3

« back to all changes in this revision

Viewing changes to listview/ArticleListPage.qml

  • Committer: Tarmac
  • Author(s): Roman Shchekin
  • Date: 2013-08-01 16:18:40 UTC
  • mfrom: (25.1.1 ubuntu-rssreader-app)
  • Revision ID: tarmac-20130801161840-1vsr2c3uzswz98ha
New network engine and view mode.

Approved by Svenn-Arne Dragly, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
import QtQuick.XmlListModel 2.0
 
3
 
 
4
import Ubuntu.Components 0.1
 
5
import Ubuntu.Components.ListItems 0.1 as ListItems
 
6
import Ubuntu.Components.Popups 0.1
 
7
 
 
8
import "../databasemodule_v2.js" as DB
 
9
 
 
10
Page {
 
11
 
 
12
    signal articleSelected(var data) // mb id.
 
13
    property var updateData: null
 
14
 
 
15
    function reloadPageContent() {
 
16
        loadArticles(updateData)
 
17
        title = updateData.title
 
18
    }
 
19
 
 
20
    /* 1. Loading data from database by url.
 
21
     * 2. Appending data to ListModel for displaying.
 
22
     */
 
23
    function loadArticles(params) {
 
24
        articleList.model = null // TMP - doesn't work properly without that, mb bug.
 
25
        articleListModel.clear()
 
26
 
 
27
        var res = DB.loadArticles(params)
 
28
        var entries = res.rows
 
29
 
 
30
        for (var i = 0; i < entries.length; i++) {
 
31
            var e = entries.item(i)
 
32
            articleListModel.append({"title" : e.title,
 
33
                                        "content" : e.content,
 
34
                                        "link" : e.link,
 
35
                                        "description" : e.description,
 
36
                                        "pubdate" : e.pubdate,
 
37
                                        "status" : e.status,
 
38
                                        "favourite" : e.favourite,
 
39
                                        "feed_id" : e.feed_id,
 
40
                                        "image" : e.image,
 
41
                                        "feed_name" : e.feed_name,
 
42
                                        "guid" : e.guid}) // for what?
 
43
        }
 
44
 
 
45
        articleList.model = articleListModel // TMP - doesn't work properly without that, mb bug.
 
46
        articleListToolbar.opened = false
 
47
    }
 
48
 
 
49
    tools: ToolbarItems {
 
50
        id: articleListToolbar
 
51
    }
 
52
 
 
53
    ListView {
 
54
        id: articleList
 
55
 
 
56
        clip: true
 
57
        anchors.fill: parent
 
58
 
 
59
        model: articleListModel
 
60
 
 
61
        delegate: ListItems.Subtitled {
 
62
            text: model.title
 
63
            subText: model.pubdate
 
64
            progression: true
 
65
            icon: selectIcon()
 
66
            iconFrame: true
 
67
 
 
68
            function selectIcon() {
 
69
                var img = model.image
 
70
                // console.log("DELEGATE IMG", img)
 
71
                return (model.image == null || model.image == "" ) ? Qt.resolvedUrl("../rssreader64.png"): model.image
 
72
            }
 
73
 
 
74
            onPressAndHold: {
 
75
                articleList.currentIndex = model.index
 
76
            }
 
77
 
 
78
            onClicked: {
 
79
                console.log("ARTICLE SELECTED", model.title)
 
80
                // TODO DEMO
 
81
                mainView.toRssPage(articleListModel, model.index)
 
82
            }
 
83
        } // delegate
 
84
    } // ListView
 
85
 
 
86
    ListModel {
 
87
        id: articleListModel
 
88
    }
 
89
 
 
90
    Label {
 
91
        id: lblEmptyBase
 
92
 
 
93
        text: i18n.tr("There are no articles in selected feed")
 
94
        anchors.centerIn: parent
 
95
        visible: articleListModel.count == 0
 
96
        fontSize: "large"
 
97
    }
 
98
}