Integrated file selection dialogue with the main code. Improved the
[openvpnui.git] / qml / filebrowse / pages / PermissionsDialog.qml
1 import QtQuick 2.0
2 import Sailfish.Silica 1.0
3 import harbour.file.browser.FileInfo 1.0
4 import "../components"
5
6 Dialog {
7     property string path: ""
8
9     // return value
10     property string errorMessage: ""
11
12     id: dialog
13     allowedOrientations: Orientation.All
14
15     property int _executeWidth: executeLabel.width
16
17     onAccepted: errorMessage = engine.chmod(path,
18                         ownerRead.checked, ownerWrite.checked, ownerExecute.checked,
19                         groupRead.checked, groupWrite.checked, groupExecute.checked,
20                         othersRead.checked, othersWrite.checked, othersExecute.checked);
21
22     FileInfo {
23         id: fileInfo
24         file: path
25     }
26
27     // copy values to fields when page shows up
28     Component.onCompleted: {
29         ownerName.text = fileInfo.owner
30         groupName.text = fileInfo.group
31         var permissions = fileInfo.permissions
32         if (permissions.charAt(0) !== '-') ownerRead.checked = true;
33         if (permissions.charAt(1) !== '-') ownerWrite.checked = true;
34         if (permissions.charAt(2) !== '-') ownerExecute.checked = true;
35         if (permissions.charAt(3) !== '-') groupRead.checked = true;
36         if (permissions.charAt(4) !== '-') groupWrite.checked = true;
37         if (permissions.charAt(5) !== '-') groupExecute.checked = true;
38         if (permissions.charAt(6) !== '-') othersRead.checked = true;
39         if (permissions.charAt(7) !== '-') othersWrite.checked = true;
40         if (permissions.charAt(8) !== '-') othersExecute.checked = true;
41     }
42
43     SilicaFlickable {
44         id: flickable
45         anchors.fill: parent
46         contentHeight: column.height
47         VerticalScrollDecorator { flickable: flickable }
48
49         Column {
50             id: column
51             anchors.left: parent.left
52             anchors.right: parent.right
53
54             DialogHeader {
55                 id: dialogHeader
56                 title: qsTr("Change Permissions")
57                 acceptText: qsTr("Change")
58             }
59
60             Label {
61                 anchors.left: parent.left
62                 anchors.right: parent.right
63                 anchors.leftMargin: Theme.paddingLarge
64                 anchors.rightMargin: Theme.paddingLarge
65                 text: qsTr("Change permissions for\n%1").arg(path)
66                 color: Theme.secondaryColor
67                 wrapMode: Text.Wrap
68             }
69
70             Spacer {
71                 height: 40
72             }
73
74             // read, write, execute small labels
75             Row {
76                 width: parent.width
77                 Label {
78                     width: parent.width/2
79                     text: " "
80                 }
81
82                 Label {
83                     id: readLabel
84                     width: executeLabel.width
85                     text: qsTr("Read")
86                     font.pixelSize: Theme.fontSizeExtraSmall
87                     color: Theme.secondaryColor
88                     horizontalAlignment: Text.AlignHCenter
89                 }
90                 Label {
91                     id: writeLabel
92                     width: executeLabel.width
93                     text: qsTr("Write")
94                     font.pixelSize: Theme.fontSizeExtraSmall
95                     color: Theme.secondaryColor
96                     horizontalAlignment: Text.AlignHCenter
97                 }
98                 Label {
99                     id: executeLabel
100                     text: qsTr("Execute")
101                     font.pixelSize: Theme.fontSizeExtraSmall
102                     color: Theme.secondaryColor
103                     horizontalAlignment: Text.AlignHCenter
104                 }
105             }
106
107             // owner
108             Row {
109                 width: parent.width
110                 Column {
111                     width: parent.width/2
112                     Label {
113                         id: ownerName
114                         width: parent.width-20
115                         text: ""
116                         color: Theme.highlightColor
117                         horizontalAlignment: Text.AlignRight
118                     }
119                     Label {
120                         width: parent.width-20
121                         text: qsTr("Owner")
122                         font.pixelSize: Theme.fontSizeExtraSmall
123                         color: Theme.secondaryColor
124                         horizontalAlignment: Text.AlignRight
125                     }
126                 }
127                 LetterSwitch {
128                     id: ownerRead
129                     width: _executeWidth
130                     letter: 'r'
131                 }
132                 LetterSwitch {
133                     id: ownerWrite
134                     width: _executeWidth
135                     letter: 'w'
136                 }
137                 LetterSwitch {
138                     id: ownerExecute
139                     width: _executeWidth
140                     letter: 'x'
141                 }
142             }
143
144             // group
145             Row {
146                 id: groupRow
147                 width: parent.width
148                 Column {
149                     width: parent.width/2
150                     Label {
151                         id: groupName
152                         width: parent.width-20
153                         text: ""
154                         color: Theme.highlightColor
155                         horizontalAlignment: Text.AlignRight
156                     }
157                     Label {
158                         width: parent.width-20
159                         text: qsTr("Group")
160                         font.pixelSize: Theme.fontSizeExtraSmall
161                         color: Theme.secondaryColor
162                         horizontalAlignment: Text.AlignRight
163                     }
164                 }
165                 LetterSwitch {
166                     id: groupRead
167                     width: _executeWidth
168                     letter: 'r'
169                 }
170                 LetterSwitch {
171                     id: groupWrite
172                     width: _executeWidth
173                     letter: 'w'
174                 }
175                 LetterSwitch {
176                     id: groupExecute
177                     width: _executeWidth
178                     letter: 'x'
179                 }
180             }
181
182             // others
183             Row {
184                 width: parent.width
185                 height: groupRow.height
186                 Item {
187                     width: parent.width/2
188                     height: parent.height
189                     Label {
190                         width: parent.width-20
191                         height: parent.height
192                         text: qsTr("Others")
193                         color: Theme.highlightColor
194                         horizontalAlignment: Text.AlignRight
195                         verticalAlignment: Text.AlignVCenter
196                     }
197                 }
198                 LetterSwitch {
199                     id: othersRead
200                     width: _executeWidth
201                     letter: 'r'
202                 }
203                 LetterSwitch {
204                     id: othersWrite
205                     width: _executeWidth
206                     letter: 'w'
207                 }
208                 LetterSwitch {
209                     id: othersExecute
210                     width: _executeWidth
211                     letter: 'x'
212                 }
213             }
214         }
215     }
216 }
217
218