~mhr3/unity8/fix-1297246

« back to all changes in this revision

Viewing changes to Dash/Video/VideoInfo.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import QtQuick.XmlListModel 2.0
 
19
 
 
20
Item {
 
21
    id: info
 
22
    property string source
 
23
 
 
24
    property bool ready: nfo.status == XmlListModel.Ready || nfoTV.status == XmlListModel.Ready
 
25
    property bool isMovie: true
 
26
    property variant video: null
 
27
    property variant tvShow: null
 
28
 
 
29
    function getActors() {
 
30
        var c = []
 
31
        if (video.actor1) c.push(video.actor1)
 
32
        if (video.actor2) c.push(video.actor2)
 
33
        if (video.actor3) c.push(video.actor3)
 
34
        return c
 
35
    }
 
36
 
 
37
    onSourceChanged: isMovie = true
 
38
 
 
39
    XmlListModel {
 
40
        id: nfo
 
41
        source: info.source
 
42
        query: (isMovie) ? "/movie" : "/episodedetails"
 
43
 
 
44
        XmlRole { name: "title"; query: "title/string()" }
 
45
        XmlRole { name: "year"; query: "year/number()" }
 
46
        XmlRole { name: "runtime"; query: "runtime/number()" }
 
47
        XmlRole { name: "rating"; query: "rating/number()" }
 
48
        XmlRole { name: "plot"; query: "plot/string()" }
 
49
        XmlRole { name: "director"; query: "director[1]/string()" }
 
50
        XmlRole { name: "actor1"; query: "actor[1]/name/string()" }
 
51
        XmlRole { name: "actor2"; query: "actor[2]/name/string()" }
 
52
        XmlRole { name: "actor3"; query: "actor[3]/name/string()" }
 
53
        XmlRole { name: "author"; query: "author[1]/string()" }
 
54
        XmlRole { name: "season"; query: "season/number()" }
 
55
        XmlRole { name: "episode"; query: "episode/number()" }
 
56
 
 
57
        XmlRole { name: "rentPrice"; query: "rent_price/string()" }
 
58
        XmlRole { name: "buyPrice"; query: "buy_price/string()" }
 
59
        XmlRole { name: "expires"; query: "expires/string()" }
 
60
 
 
61
        onStatusChanged: if (status == XmlListModel.Ready) {
 
62
                             if (count > 0) info.video = nfo.get(0)
 
63
                             else info.isMovie = false
 
64
                         } else if (status == XmlListModel.Error) info.isMovie = false
 
65
    }
 
66
 
 
67
    XmlListModel {
 
68
        id: nfoTV
 
69
        source: (nfo.isMovie) ? "" : info.source.substring(0, info.source.lastIndexOf("/") + 1) + "tvshow.nfo"
 
70
        query: "/tvshow"
 
71
 
 
72
        XmlRole { name: "title"; query: "title/string()" }
 
73
 
 
74
        onStatusChanged: if (status == XmlListModel.Ready) {
 
75
                             if (count > 0) info.tvShow = nfoTV.get(0)
 
76
                         } else if (status == XmlListModel.Error) {
 
77
                             // Search for tvshow.nfo in the directory above this one to cater
 
78
                             // for directory layout Show/Season
 
79
                             var path = info.source.split("/")
 
80
                             path.splice(-2, 2, "tvshow.nfo")
 
81
                             source = path.join("/")
 
82
                         }
 
83
    }
 
84
}