]> git.tdb.fi Git - xinema.git/blob - remote/qml/pages/BrowsePage.qml
Go back to ConnectPage if connection to the server is lost
[xinema.git] / remote / qml / pages / BrowsePage.qml
1 import QtQuick 2.0
2 import Sailfish.Silica 1.0
3 import org.nemomobile.configuration 1.0
4 import fi.mikkosoft.xinema 0.1
5 import "../components"
6
7 Page
8 {
9         id: page
10
11         function navigate(dir)
12         {
13                 var newDir = browseDirectory.directory;
14                 if(newDir!="/")
15                         newDir += "/";
16                 newDir += dir;
17                 browseDirectory.directory = newDir;
18         }
19
20         function navigateUp()
21         {
22                 var newDir = browseDirectory.directory;
23                 var slash = newDir.lastIndexOf("/");
24                 if(slash>0)
25                         newDir = newDir.substring(0, slash);
26                 else
27                         newDir = "/";
28                 browseDirectory.directory = newDir;
29         }
30
31         SilicaListView
32         {
33                 anchors.fill: parent
34
35                 PullDownMenu
36                 {
37                         MenuItem
38                         {
39                                 text: "Set as default location"
40
41                                 onClicked: defaultLocation.value = browseDirectory.directory
42                         }
43
44                         MenuItem
45                         {
46                                 visible: streamControl.title
47                                 text: streamControl.title
48
49                                 onClicked: pageStack.push("PlaybackPage.qml");
50                         }
51                 }
52
53                 header: PageHeader
54                 {
55                         title: qsTr("Browse files")
56                 }
57
58                 model: browseDirectory.model
59
60                 delegate: DirectoryEntry
61                 {
62                         width: parent.width
63
64                         icon:
65                         {
66                                 if(type==DirectoryModel.ParentDir)
67                                         return "image://theme/icon-m-back";
68                                 else if(type==DirectoryModel.SubDir)
69                                         return "image://theme/icon-m-folder";
70                                 else
71                                         return "";
72                         }
73
74                         text: name
75
76                         onClicked:
77                         {
78                                 if(type==DirectoryModel.File)
79                                         xinemaControl.play_file(browseDirectory.directory+"/"+name);
80                                 else if(type==DirectoryModel.ParentDir)
81                                         page.navigateUp();
82                                 else if(type==DirectoryModel.SubDir)
83                                         page.navigate(name);
84                         }
85                 }
86
87                 VerticalScrollDecorator { }
88         }
89
90         BrowseDirectory
91         {
92                 id: browseDirectory
93                 control: xinemaControl
94         }
95
96         Component.onCompleted:
97         {
98                 if(xinemaControl.connected)
99                         browseDirectory.directory = defaultLocation.value;
100         }
101
102         Connections
103         {
104                 target: xinemaControl
105                 onConnectedChanged:
106                 {
107                         if(!xinemaControl.connected)
108                                 pageStack.replace("ConnectPage.qml");
109                 }
110         }
111
112         StreamControl
113         {
114                 id: streamControl
115                 control: xinemaControl
116                 onPlaybackStateChanged:
117                 {
118                         if(playbackState==StreamControl.Playing && pageContainer.currentPage==page)
119                         {
120                                 if(pageContainer.busy)
121                                         pageContainer.completeAnimation();
122                                 pageStack.push("PlaybackPage.qml");
123                         }
124                 }
125         }
126
127         ConfigurationValue
128         {
129                 id: defaultLocation
130                 key: "/fi/mikkosoft/xinema-remote/defaultLocation"
131                 defaultValue: "/"
132         }
133 }
134