Debian Codegraph @

src/qml/common/VideoInfo.qml

raw
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
18 import QtQuick 2.4
19 import QtQuick.XmlListModel 2.0
20 import "../common/utils.js" as Utils
21
22 Item {
23 id: info
24 property string uri
25
26 property bool isMovie: true
27 property variant video: null
28 property variant tvShow: null
29
30 function getActors() {
31 var c = []
32 if (video.actor1) c.push(video.actor1)
33 if (video.actor2) c.push(video.actor2)
34 if (video.actor3) c.push(video.actor3)
35 return c
36 }
37
38 onUriChanged: isMovie = true
39
40 XmlListModel {
41 id: nfo
42 source: Utils.removeExt(uri) + ".nfo"
43 query: (isMovie) ? "/movie" : "/episodedetails"
44
45 XmlRole { name: "title"; query: "title/string()" }
46 XmlRole { name: "year"; query: "year/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: "season"; query: "season/number()" }
54 XmlRole { name: "episode"; query: "episode/number()" }
55
56 XmlRole { name: "rent_price"; query: "rent_price/string()" }
57 XmlRole { name: "buy_price"; query: "buy_price/string()" }
58 XmlRole { name: "expires"; query: "expires/string()" }
59
60 onStatusChanged: if (status == XmlListModel.Ready) {
61 if (count > 0) info.video = nfo.get(0)
62 else info.isMovie = false
63 } else if (status == XmlListModel.Error) info.isMovie = false
64 }
65
66 XmlListModel {
67 id: nfoTV
68 source: (nfo.isMovie) ? "" : uri.substring(0, uri.lastIndexOf("/") + 1) + "tvshow.nfo"
69 query: "/tvshow"
70
71 XmlRole { name: "title"; query: "title/string()" }
72
73 onStatusChanged: if (status == XmlListModel.Ready) {
74 if (count > 0) info.tvShow = nfoTV.get(0)
75 } else if (status == XmlListModel.Error) {
76 // Search for tvshow.nfo in the directory above this one to cater
77 // for directory layout Show/Season
78 var path = uri.split("/")
79 path.splice(-2, 2, "tvshow.nfo")
80 source = path.join("/")
81 }
82 }
83 }