~nick-dedekind/unity/phablet-greeter-indicators

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
/*
 * Copyright (C) 2013 Canonical, Ltd.
 *
 * This program 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; version 3.
 *
 * This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.0
import Ubuntu.Components 0.1
import Unity 0.1

Item {
    id: dashContent
    width: units.gu(40)
    height: units.gu(71)

    property var model: null
    property var lenses: null
    property real contentProgress: Math.max(0, Math.min(dashContentList.contentX / (dashContentList.contentWidth - dashContentList.width), units.dp(1)))
    property alias currentIndex: dashContentList.currentIndex

    signal movementStarted()
    signal movementEnded()
    signal contentFlickStarted()
    signal contentEndReached()
    signal previewShown()
    signal lensLoaded(string lensId)
    signal positionedAtBeginning()

    function setCurrentLensAtIndex(index, animate, reset) {
        var storedMoveDuration = dashContentList.highlightMoveDuration
        var storedMoveSpeed = dashContentList.highlightMoveVelocity
        if (!animate) {
            dashContentList.highlightMoveVelocity = units.gu(4167)
            dashContentList.highlightMoveDuration = 0
        }

        dashContentList.currentIndex = index

        if (reset) {
            dashContent.positionedAtBeginning()
        }

        // FIXME: workaround, see below
        if (dashContentList.currentIndex != index) {
            listTimer.index = index
            listTimer.start()
        }

        if (!animate) {
            dashContentList.highlightMoveDuration = storedMoveDuration
            dashContentList.highlightMoveVelocity = storedMoveSpeed
        }
    }

    property var lensDelegateMapping: {"mockmusic.lens": "DashMusic.qml",
                                       "applications.lens": "DashApps.qml",
                                       "home.lens": "DashHome.qml",
                                       "mockvideos.lens": "DashVideos.qml",
                                       "people.lens": "DashPeople.qml",
                                      }
    property string genericLens: "GenericLensView.qml"

    // FIXME: workaround the fact that you can't switch to a ListView item
    // until it's ready, and even onLoaded on the item's Loader is too early
    Timer {
        id: listTimer
        property int index
        interval: 10
        repeat: true
        onTriggered: {
            dashContentList.currentIndex = index
            if (dashContentList.currentIndex == index) stop()
        }
    }

    ListView {
        id: dashContentList

        interactive: dashContent.lenses.loaded

        anchors.fill: parent
        model: dashContent.model
        orientation: ListView.Horizontal
        boundsBehavior: Flickable.DragAndOvershootBounds
        flickDeceleration: units.gu(625)
        maximumFlickVelocity: width * 5
        snapMode: ListView.SnapOneItem
        highlightMoveDuration: 250
        highlightRangeMode: ListView.StrictlyEnforceRange
        /* FIXME: workaround rendering issue due to use of ShaderEffectSource in
           UbuntuShape. While switching from the home lens to the People lens the
           rendering would block midway.
        */
        cacheBuffer: 2147483647
        onMovementStarted: dashContent.movementStarted()
        onMovementEnded: dashContent.movementEnded()

        delegate:
            Loader {
                width: ListView.view.width
                height: ListView.view.height
                asynchronous: true
                source: {
                    var customLens = lensDelegateMapping[lens.id]
                    if (customLens) {
                        customLens.searchHistory = shell.searchHistory
                        return customLens
                    } else {
                        genericLens.searchHistory = shell.searchHistory
                        return genericLens
                    }
                }
                onLoaded: {
                    item.lens = Qt.binding(function() { return lens })
                    item.isCurrent = Qt.binding(function() { return ListView.isCurrentItem })
                    dashContentList.movementStarted.connect(item.movementStarted)
                    dashContent.positionedAtBeginning.connect(item.positionedAtBeginning)
                    dashContent.lensLoaded(item.lens.id)
                }
                Connections {
                    target: item
                    ignoreUnknownSignals: true
                    onEndReached: contentEndReached()
                    onPreviewShownChanged: {
                        if (item.previewShown) {
                            previewShown()
                            dashContentList.interactive = false
                        } else {
                            dashContentList.interactive = true
                        }
                    }
                }
            }
    }
}