~josephjamesmills/ubuntutv/maps_fanart

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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
/*
 * This file is part of unity-2d
 *
 * Copyright 2010-2011 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 1.1
import Unity2d 1.0
import Effects 1.0
import "../common"
import "../indicators"
import "../sidebar"
import "../common/units.js" as Units

FocusScope {
    id: dash
    Accessible.name: "dash"

    LayoutMirroring.enabled: isRightToLeft()
    LayoutMirroring.childrenInherit: true

    property variant currentPage

    /* FIXME: 'active' property exactly mirrors 'declarativeView.dashActive'.
       The final goal is to transition to using exclusively the QML 'active' property
       and drop the C++ 'declarativeView.dashActive'.
    */

    property variant active
    property bool epgActive: false
   // property bool itvActive: false
    /* The following way of mirroring the values of 'declarativeView.dashActive'
       and 'active' works now and QML does not see it as a binding loop but we
       cannot count on it long term.
    */
    Binding {
        target: declarativeView
        property: "dashActive"
        value: dash.active
    }
    Binding {
        target: dash
        property: "active"
        value: declarativeView.dashActive
    }

    /* Unload the current page when closing the dash */
    onActiveChanged: {
        /* FIXME find a better way to hide the preview when disactivating the dash */
        if (!dash.active && previewer.active) delayHidePreview.restart()
        if (!dash.active && unity2dConfiguration.formFactor != "tv") {
            /* FIXME: currentPage needs to stop pointing to pageLoader.item
                      that is about to be invalidated otherwise a crash
                      occurs because SearchEntry has a binding that refers
                      to currentPage and tries to access it.
               Ref.: https://bugs.launchpad.net/ubuntu/+source/unity-2d/+bug/817896
                     https://bugreports.qt.nokia.com/browse/QTBUG-20692
            */
            deactivateActiveLens()
            currentPage = undefined
            // Delay the following instruction by 1 millisecond using a
            // timer. This is enough to work around a crash that happens
            // when the layout is mirrored (RTL locales). See QTBUG-22776
            // for details.
            //pageLoader.source = ""
            delayPageLoaderReset.restart()
        }
    }

    Timer {
        id: delayPageLoaderReset
        interval: 1
        onTriggered: pageLoader.setSource("")
    }

    Timer {
        id: delayHidePreview
        interval: 500
        onTriggered: hidePreview()
    }

    function isRightToLeft() {
        return Qt.application.layoutDirection == Qt.RightToLeft
    }

    property string startupLens: unity2dConfiguration.formFactor == "tv" ? "video.lens" : ""

    Connections {
        target: lenses
        onLoaded: if (startupLens) activateLens(startupLens)
    }

    Binding {
        target: declarativeView
        property: "expanded"
        value: (currentPage && currentPage.expanded != undefined) ? currentPage.expanded : true
    }

    DashSettings {
        id: dashSettings
    }

    Binding {
        target: declarativeView
        property: "dashMode"
        value: (dashSettings.formFactor == DashSettings.Desktop) ?
               ShellDeclarativeView.DesktopMode : ShellDeclarativeView.FullScreenMode
    }

    Connections {
        target: declarativeView

        onActivateHome: activateHome()
        onActivateLens: activateLens(lensId)
    }

    function edgeEvent(event) {
        if (unity2dConfiguration.formFactor == "tv"
            && (event.key == Qt.Key_F3 || event.key == Qt.Key_MediaPlay)
            && declarativeView.activeLens != ""
            && !previewer.active) {
                if (!sidebar.activeFocus) {
                    sidebar.forceActiveFocus()
                } else {
                    sidebar.focus = false
                    dash.forceActiveFocus()
                }
                event.accepted = true
        }
    }

    function activatePage(page) {
        /* Always give the focus to the search entry when switching pages */
        search_entry.focus = true

        if (page == currentPage) {
            return
        }

        if (currentPage != undefined) {
            currentPage.visible = false
        }
        currentPage = page
        currentPage.visible = true
    }

    function deactivateActiveLens() {
        epgActive = false
        if (previewer.active) hidePreview()
        if (declarativeView.activeLens != "") {
            var lens = lenses.get(declarativeView.activeLens)
            lens.active = false
        }
        declarativeView.activeLens = ""
    }

   /* function deactivateActiveLens() {
        itvActive = false
        if (previewer.active) hidePreview()
        if (declarativeView.activeLens != "") {
            var lens = lenses.get(declarativeView.activeLens)
            lens.active = false
        }
        declarativeView.activeLens = ""
    }
*/
    function activateLens(lensId) {
        if (lensId == declarativeView.activeLens) {
            dash.active = true
            return
        }

        deactivateActiveLens()
        var lens = lenses.get(lensId)
        if (lens == null) {
            console.log("No match for lens: %1".arg(lensId))
            return
        }

        lens.active = true
        declarativeView.activeLens = lens.id
        dash.active = true
        pageLoader.setSource("LensView.qml")
        /* Take advantage of the fact that the loaded qml is local and setting
           the source loads it immediately making pageLoader.item valid */
        pageLoader.item.model = lens
        activatePage(pageLoader.item)
    }

    function activateHome() {
        deactivateActiveLens()
        pageLoader.setSource("Home.qml")
        /* Take advantage of the fact that the loaded qml is local and setting
           the source loads it immediately making pageLoader.item valid */
        activatePage(pageLoader.item)
        declarativeView.activeLens = ""
        dash.active = true
    }

    function activateEPG() {
        deactivateActiveLens()
        epgActive = true
        pageLoader.setSource("EPG.qml")
        activatePage(pageLoader.item)
        declarativeView.activeLens = ""
        dash.active = true
    }

    /*function activateITV() {
        deactivateActiveLens()
        itvActive = true
        pageLoader.setSource("ITV.qml")
        activatePage(pageLoader.item)
        declarativeView.activeLens = ""
        dash.active = true
    }
*/
    function activateLensWithOptionFilter(lensId, filterId, optionId) {
        var lens = lenses.get(lensId)
        var filter = lens.filters.getFilter(filterId)
        var option = filter.getOption(optionId)
        filter.clear()
        option.active = true
        filterPane.folded = false
        activateLens(lensId)
    }

    function activateLensAndClearFilter(lensId, filterId) {
        var lens = lenses.get(lensId)
        var filter = lens.filters.getFilter(filterId)
        filter.clear()
        activateLens(lensId)
    }

    function activateUriWithLens(lens, category, uri, mimetype) {
        /* FIXME: need a reliable way to make the dash player intercept
                  content that is should playback */
        if (unity2dConfiguration.formFactor == "tv" && mimetype.indexOf("video/") == 0) {
            var cleanUri = decodeURIComponent(uri.substring(uri.indexOf(":")+1))
            if (lens.id == "video.lens") {
                showPreview(category, cleanUri, mimetype)
            } else {
                shell.play(cleanUri)
            }
        } else {
            if (unity2dConfiguration.formFactor == "desktop") {
                dash.active = false
            }
            lens.activate(decodeURIComponent(uri))
        }
    }

    function activateApplication(application) {
        if (unity2dConfiguration.formFactor == "desktop") {
            dash.active = false
        }
        application.activate()
    }

    property variant lenses: Lenses {}

    /* Previewer */
    function showPreview(category, uri, mimeType){
        previewer.category = category
        previewer.uri = uri
        previewer.mimeType = mimeType
        previewer.active = true
        previewer.focus = true
    }

    function hidePreview() {
        if (!previewer.active) return
        previewer.active = false
        pageLoader.focus = true
        previewer.uri = ""
        previewer.mimeType = ""
    }

    Item {
        id: background

        property bool transparent: unity2dConfiguration.formFactor == "desktop"
        visible: background.transparent
        anchors.fill: parent

        /* Avoid redraw at rendering */
        effect: CacheEffect {}

        Item {
            anchors.fill: parent
            anchors.bottomMargin: content.anchors.bottomMargin
            anchors.rightMargin: content.anchors.rightMargin
            clip: true

            Image {
                id: blurredBackground

                effect: Blur {blurRadius: 12}

                /* 'source' needs to be set when the dash becomes visible, that
                   is when dash.active becomes true, so that a
                   screenshot of the windows behind the dash is taken at that
                   point.
                   'source' also needs to change so that the screenshot is
                   re-taken as opposed to pulled from QML's image cache.
                   This workarounds the fact that the image cache cannot be
                   disabled. A new API to deal with this was introduced in Qt Quick 1.1.

                   See http://doc.qt.nokia.com/4.7-snapshot/qml-image.html#cache-prop
                */
                property variant timeAtActivation
                Connections {
                    target: dash
                    onActiveChanged: blurredBackground.timeAtActivation = screen.currentTime()
                }

                /* Use an image of the root window which essentially is a
                   capture of the entire screen */
                source: if (background.transparent) {
                            return dash.active ? "image://window/root@" + blurredBackground.timeAtActivation : ""
                        } else {
                            return ""
                        }

                fillMode: Image.PreserveAspectCrop
                x: -launcherLoader.width
                y: -declarativeView.globalPosition.y
            }

            Image {
                anchors.fill: parent
                fillMode: Image.PreserveAspectCrop
                source: background.transparent ? "artwork/background_sheen.png" : ""
            }
        }

        BorderImage {
            anchors.fill: parent
            visible: declarativeView.dashMode == ShellDeclarativeView.DesktopMode
            source: screen.isCompositingManagerRunning ? "artwork/desktop_dash_background.sci" : "artwork/desktop_dash_background_no_transparency.sci"
            mirror: isRightToLeft()
        }
    }

    FocusScope {
        id: content

        focus: true

        anchors.fill: parent
        /* Margins in DesktopMode set so that the content does not overlap with
           the border defined by the background image.
        */
        anchors.bottomMargin: declarativeView.dashMode == ShellDeclarativeView.DesktopMode ? 39 : 0
        anchors.rightMargin: declarativeView.dashMode == ShellDeclarativeView.DesktopMode ? 37 : 0

        /* Unhandled keys will always be forwarded to the search bar. That way
           the user can type and search from anywhere in the interface without
           necessarily focusing the search bar first. */
        /* FIXME: deactivated because it makes the user lose the focus very often */
        //Keys.forwardTo: [search_entry]

        Behavior on opacity { NumberAnimation { duration: 250 } }

        SearchEntry {
            id: search_entry

            focus: true
            /* FIXME: check on visible necessary; fixed in Qt Quick 1.1
                      ref: http://bugreports.qt.nokia.com/browse/QTBUG-15862
            */
            KeyNavigation.right: {
                if (unity2dConfiguration.formFactor == "desktop") return filterPane.visible ? filterPane : search_entry
                else if (unity2dConfiguration.formFactor == "tv") return indicators
                else return search_entry
            }
            KeyNavigation.down: pageLoader

            anchors.top: parent.top
            anchors.topMargin: Units.dtPx(11)
            anchors.left: parent.left
            anchors.leftMargin: Units.dtPx(10)
            anchors.right: unity2dConfiguration.formFactor == "desktop" ? filterPane.left : indicators.left
            anchors.rightMargin: unity2dConfiguration.formFactor == "desktop" ? Units.dtPx(15) : Units.tvPx(80)

            height: Units.dtPx(42)
        }

        FilterPane {
            id: filterPane

            KeyNavigation.left: search_entry

            /* FilterPane is only to be displayed for lenses, not in the home page or Alt+F2 Run page */
            visible: unity2dConfiguration.formFactor == "desktop" && declarativeView.activeLens != "" && declarativeView.activeLens != "commands.lens"
            lens: visible && currentPage != undefined ? currentPage.model : undefined

            anchors.top: search_entry.anchors.top
            anchors.topMargin: search_entry.anchors.topMargin
            anchors.bottom: unity2dConfiguration.formFactor != "tv" ? lensBar.top : parent.bottom
            headerHeight: search_entry.height
            width: Units.dtPx(300)
            anchors.right: parent.right
            anchors.rightMargin: Units.dtPx(8)
        }

        Loader {
            id: pageLoader

            Accessible.name: "loader"
            /* FIXME: check on visible necessary; fixed in Qt Quick 1.1
                      ref: http://bugreports.qt.nokia.com/browse/QTBUG-15862
            */
            KeyNavigation.right: filterPane.visible && !filterPane.folded ? filterPane : pageLoader
            KeyNavigation.up: search_entry
            KeyNavigation.down: lensBar

            anchors.top: search_entry.bottom
            anchors.topMargin: if (unity2dConfiguration.formFactor == "desktop") Units.dtPx(9)
                               else if (unity2dConfiguration.formFactor == "tv") Units.tvPx(16)
            anchors.bottom: unity2dConfiguration.formFactor != "tv" ? lensBar.top : parent.bottom
            anchors.left: parent.left
            anchors.right: !filterPane.visible || filterPane.folded ? parent.right : filterPane.left
            anchors.rightMargin: !filterPane.visible || filterPane.folded ? 0 : 15
            onLoaded: item.focus = true

            /* Workaround loss of focus issue happening when the loaded item has
               active focus and is then destroyed. The active focus was completely
               lost instead of being relinquished to the Loader.

               Ref.: https://bugreports.qt.nokia.com/browse/QTBUG-22939
            */
            function setSource(newSource) {
                sourceAnimation.restart()
                var hadActiveFocus = activeFocus
                source = newSource
                if (hadActiveFocus) forceActiveFocus()
            }

            SequentialAnimation {
                id: sourceAnimation
                property string source
                property bool hadActiveFocus
                PropertyAction { target: pageLoader; property: "opacity"; value: 0 }
                NumberAnimation { duration: 2500 }
                NumberAnimation { target: pageLoader; property: "opacity"; to: 1; duration: 300; easing.type: Easing.OutQuad }
            }
        }

        DashIndicators {
            id: indicators
            height: Units.tvPx(120)
            anchors.verticalCenter: search_entry.verticalCenter
            anchors.right: parent.right
            anchors.rightMargin: Units.tvPx(27)
            KeyNavigation.left: search_entry
            KeyNavigation.down: pageLoader
            visible: unity2dConfiguration.formFactor == "tv"

            onActiveFocusChanged: {
                if (!activeFocus) leftIndicator.focus = true
            }
        }

        Previews {
            id: previewer
            anchors.fill: parent
            onExitRequested: hidePreview()
        }

        LensBar {
            id: lensBar

            KeyNavigation.up: pageLoader

            anchors.bottom: parent.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            height: Units.dtPx(44)
            visible: declarativeView.expanded && unity2dConfiguration.formFactor != "tv"
        }

    }

    Rectangle {
        anchors.fill: sidebar
        color: "black"
        opacity: 0.5
    }
    MouseArea {
        anchors.fill: content
        enabled: !content.activeFocus
        onClicked: content.focus = true
    }

    Sidebar {
        id: sidebar
        source: "../dash/LensSidebar.qml"
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        width: Units.tvPx(550) + borderWidth
        x: sidebarVisibility.shown ? parent.width - width : parent.width

        Behavior on x { NumberAnimation { duration: 125 } }

        Keys.onPressed: {
            if (event.key == Qt.Key_Escape || event.key == Qt.Key_Backspace) {
                sidebar.focus = false
                content.forceActiveFocus()
            }
        }

        // Prevent key navigation from the sidebar
        Keys.onLeftPressed: {}
        Keys.onRightPressed: {}

        Binding {
            target: sidebar.item
            property: "lens"
            value: currentPage != undefined ? currentPage.model : undefined
            when: sidebar.status == Loader.Ready
        }
    }

    VisibilityController {
        id: sidebarVisibility
        behavior: ImmediateHideBehavior {
            target: sidebar
        }
        onShownChanged: if (!shown) {
            sidebar.focus = false
            content.forceActiveFocus()
        }
    }

    AbstractButton {
        id: fullScreenButton

        Accessible.name: "Full Screen"

        anchors.bottom: parent.bottom
        anchors.right: parent.right
        anchors.rightMargin: 15
        anchors.bottomMargin: 15
        width: fullScreenButtonImage.sourceSize.width
        height: fullScreenButtonImage.sourceSize.height
        visible: declarativeView.dashMode != ShellDeclarativeView.FullScreenMode

        Image {
            id: fullScreenButtonImage
            source: "artwork/fullscreen_button.png"
            mirror: isRightToLeft()
        }

        onClicked: {
            declarativeView.dashMode = ShellDeclarativeView.FullScreenMode
        }
    }

    property int desktopCollapsedHeight: 115
    property int desktopExpandedHeight: 606
    property int desktopWidth: 989
    property int fullscreenWidth: screen.availableGeometry.width
    property int fullscreenHeight: screen.availableGeometry.height

    states: [
        State {
            name: "desktop"
            when: declarativeView.dashMode == ShellDeclarativeView.DesktopMode
            PropertyChanges {
                target: dash
                width: desktopWidth
                height: declarativeView.expanded ? desktopExpandedHeight : desktopCollapsedHeight
            }
        },
        State {
            name: "fullscreen"
            when: declarativeView.dashMode == ShellDeclarativeView.FullScreenMode
            PropertyChanges {
                target: dash
                width: fullscreenWidth
                height: fullscreenHeight
            }
        }
    ]
}