Linked key and ca file configuration to vpn execution. Added option to
[openvpnui.git] / qml / filebrowse / pages / DirectoryPage.qml
1 import QtQuick 2.0
2 import Sailfish.Silica 1.0
3 import harbour.file.browser.FileModel 1.0
4 import "functions.js" as Functions
5 import "../components"
6
7 Page {
8     id: page
9     //allowedOrientations: Orientation.All
10     property string dir: "/"
11     property string initialDir: ""
12     property bool initial: false // this is set to true if the page is initial page
13     property int _selectedMenu: 0
14
15     FileModel {
16         id: fileModel
17         dir: page.dir
18         // page.status does not exactly work - root folder seems to be active always??
19         active: page.status === PageStatus.Active
20     }
21
22     SilicaListView {
23         id: fileList
24         anchors.fill: parent
25
26         model: fileModel
27
28         VerticalScrollDecorator { flickable: fileList }
29
30         PullDownMenu {
31             id: pullMenu;
32
33             onActiveChanged: {
34                 switch (_selectedMenu) {
35                     case 1:
36                         Functions.cancel()
37                         break;
38                     case 2:
39                         Functions.fileSelect("")
40                         break;
41                     case 3:
42                         pageStack.push(Qt.resolvedUrl("SearchPage.qml"), { dir: page.dir });
43                         break;
44                     case 4:
45                         fileModel.showAll = true
46                         menuShowAll.visible = false
47                         menuShowFiltered.visible = true
48                         break;
49                     case 5:
50                         fileModel.showAll = false
51                         menuShowFiltered.visible = false
52                         menuShowAll.visible = true
53                         break;
54                 }
55                 _selectedMenu = 0
56             }
57
58             MenuItem {
59                 text: qsTr("Cancel")
60                 onClicked: _selectedMenu = 1
61             }
62             MenuItem {
63                 text: qsTr("Clear")
64                 onClicked: _selectedMenu = 2
65             }
66             MenuItem {
67                 text: qsTr("Search")
68                 onClicked: _selectedMenu = 3
69             }
70             MenuItem {
71                 id: menuShowAll
72                 visible: !fileModel.showAll
73                 text: qsTr("Show all files")
74                 onClicked: _selectedMenu = 4
75             }
76             MenuItem {
77                 id: menuShowFiltered
78                 visible: fileModel.showAll
79                 text: qsTr("Show only ") + engine.extensionFilter + qsTr(" files")
80                 onClicked: _selectedMenu = 5
81             }
82         }
83
84         header: PageHeader {
85             title: Functions.formatPathForTitle(page.dir) + " " +
86                    Functions.unicodeBlackDownPointingTriangle()
87             MouseArea {
88                 anchors.fill: parent
89                 onClicked: dirPopup.show();
90             }
91         }
92
93         delegate: ListItem {
94             id: fileItem
95             menu: contextMenu
96             width: ListView.view.width
97             contentHeight: listLabel.height+listSize.height + 13
98
99             Image {
100                 id: listIcon
101                 anchors.left: parent.left
102                 anchors.leftMargin: Theme.paddingLarge
103                 anchors.top: parent.top
104                 anchors.topMargin: 11
105                 source: "../images/small-"+fileIcon+".png"
106             }
107             Label {
108                 id: listLabel
109                 anchors.left: listIcon.right
110                 anchors.leftMargin: 10
111                 anchors.right: parent.right
112                 anchors.rightMargin: Theme.paddingLarge
113                 anchors.top: parent.top
114                 anchors.topMargin: 5
115                 text: filename
116                 elide: Text.ElideRight
117             }
118             Label {
119                 id: listSize
120                 anchors.left: listIcon.right
121                 anchors.leftMargin: 10
122                 anchors.top: listLabel.bottom
123                 text: !(isLink && isDir) ? size : Functions.unicodeArrow()+" "+symLinkTarget
124                 color: Theme.secondaryColor
125                 font.pixelSize: Theme.fontSizeExtraSmall
126             }
127             Label {
128                 visible: !(isLink && isDir)
129                 anchors.top: listLabel.bottom
130                 anchors.horizontalCenter: parent.horizontalCenter
131                 text: filekind+permissions
132                 color: Theme.secondaryColor
133                 font.pixelSize: Theme.fontSizeExtraSmall
134             }
135             Label {
136                 visible: !(isLink && isDir)
137                 anchors.top: listLabel.bottom
138                 anchors.right: listLabel.right
139                 text: modified
140                 color: Theme.secondaryColor
141                 font.pixelSize: Theme.fontSizeExtraSmall
142             }
143
144             onClicked: {
145                 if (model.isDir) {
146                     pageStack.push(Qt.resolvedUrl("DirectoryPage.qml"),
147                                    { dir: fileModel.appendPath(listLabel.text) });
148                 }
149                 else {
150                     Functions.fileSelect(fileModel.appendPath(listLabel.text))
151                     //Functions.cancel()
152                     //pageStack.push(Qt.resolvedUrl("FilePage.qml"),
153                     //               { file: fileModel.appendPath(listLabel.text) });
154                 }
155             }
156
157             // delete file after remorse time
158             ListView.onRemove: animateRemoval(fileItem)
159             function deleteFile(deleteFilename) {
160                 remorseAction(qsTr("Deleting"), function() {
161                     progressPanel.showText(qsTr("Deleting"));
162                     engine.deleteFiles([ deleteFilename ]);
163                 }, 5000)
164             }
165
166             // context menu is activated with long press
167             Component {
168                  id: contextMenu
169                  ContextMenu {
170                      MenuItem {
171                          visible: true
172                          text: qsTr("Properties")
173                          onClicked:  {
174                              pageStack.push(Qt.resolvedUrl("FilePage.qml"), { file: fileModel.fileNameAt(index) });
175                          }
176                      }
177                  }
178              }
179         }
180
181         // text if no files or error message
182         Text {
183             width: parent.width
184             anchors.leftMargin: Theme.paddingLarge
185             anchors.rightMargin: Theme.paddingLarge
186             horizontalAlignment: Qt.AlignHCenter
187             y: -fileList.contentY + 100
188             visible: fileModel.fileCount === 0 || fileModel.errorMessage !== ""
189             text: fileModel.errorMessage !== "" ? fileModel.errorMessage : (fileModel.showAll ? qsTr("No files") : qsTr("No key files"))
190             color: Theme.highlightColor
191         }
192     }
193
194     // update cover
195     onStatusChanged: {
196         if (status === PageStatus.Activating) {
197             // go to Home on startup
198             if (page.initial) {
199                 page.initial = false;
200                 Functions.goToInitial(dir);
201             }
202         }
203     }
204
205     DirPopup {
206         id: dirPopup
207         anchors.fill: parent
208         menuTop: 100
209     }
210
211     // connect signals from engine to panels
212     Connections {
213         target: engine
214         onProgressChanged: progressPanel.text = engine.progressFilename
215         onWorkerDone: progressPanel.hide()
216         onWorkerErrorOccurred: {
217             // the error signal goes to all pages in pagestack, show it only in the active one
218             if (progressPanel.open) {
219                 progressPanel.hide();
220                 if (message === "Unknown error")
221                     filename = qsTr("Trying to move between phone and SD Card? It doesn't work, try copying.");
222                 else if (message === "Failure to write block")
223                     filename = qsTr("Perhaps the storage is full?");
224
225                 notificationPanel.showText(message, filename);
226             }
227         }
228     }
229
230     NotificationPanel {
231         id: notificationPanel
232         page: page
233     }
234
235     ProgressPanel {
236         id: progressPanel
237         page: page
238         onCancelled: engine.cancel()
239     }
240
241 }
242
243