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