9cc0f22c735582efe990fb96ea8b3d1f8c0a683a
[qzeecontrol] / qml / QZeeControl / KeyBindingSettings.qml
1 /*
2  *  Copyright 2012 Ruediger Gad
3  *
4  *  This file is part of QZeeControl.
5  *
6  *  QZeeControl is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  QZeeControl is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with QZeeControl.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 import QtQuick 1.1
21 import com.nokia.meego 1.0
22 import "settingsstorage.js" as SettingsStorage
23
24 Sheet {
25     id: keyBindingSettings
26     anchors.fill: parent
27     visualParent: mainPage
28     z: 2
29
30     acceptButtonText: "Save"
31     rejectButtonText: "Cancel"
32
33     property string currentRemote: "none"
34
35     function loadBindings(){
36         if(currentRemote === "none"){
37             console.log("Current remote is none. Not going to load key bindings.")
38             return
39         }
40
41         console.log("Loading stored key bindings for " + currentRemote + ".")
42         fieldA.text = SettingsStorage.getSetting(currentRemote + "A")
43         fieldB.text = SettingsStorage.getSetting(currentRemote + "B")
44         fieldC.text = SettingsStorage.getSetting(currentRemote + "C")
45         fieldD.text = SettingsStorage.getSetting(currentRemote + "D")
46
47         fieldUp.text = SettingsStorage.getSetting(currentRemote + "Up")
48         fieldDown.text = SettingsStorage.getSetting(currentRemote + "Down")
49         fieldLeft.text = SettingsStorage.getSetting(currentRemote + "Left")
50         fieldRight.text = SettingsStorage.getSetting(currentRemote + "Right")
51     }
52
53     function saveBindings(){
54         if(currentRemote === "none"){
55             console.log("Current remote is none. Not going to save key bindings.")
56             return
57         }
58
59         console.log("Saving new key bindings for " + currentRemote + ".")
60         SettingsStorage.setSetting(currentRemote + "A", fieldA.text)
61         SettingsStorage.setSetting(currentRemote + "B", fieldB.text)
62         SettingsStorage.setSetting(currentRemote + "C", fieldC.text)
63         SettingsStorage.setSetting(currentRemote + "D", fieldD.text)
64
65         SettingsStorage.setSetting(currentRemote + "Up", fieldUp.text)
66         SettingsStorage.setSetting(currentRemote + "Down", fieldDown.text)
67         SettingsStorage.setSetting(currentRemote + "Left", fieldLeft.text)
68         SettingsStorage.setSetting(currentRemote + "Right", fieldRight.text)
69     }
70
71     onAccepted: saveBindings()
72
73     onStatusChanged:{
74         if(status === DialogStatus.Opening){
75             loadBindings()
76         }
77     }
78
79     content: Flickable{
80         anchors.fill: parent
81         anchors.margins: 10
82         contentHeight: contentGrid.height + explanationLabel.height
83
84         Grid{
85             id: contentGrid
86
87             anchors{top: parent.top}
88             width: 300
89             spacing: 10
90
91             Label{
92                 text: "A"
93             }
94             TextField{
95                 id: fieldA
96                 text: "-"
97                 width: 150
98             }
99
100             Label{
101                 text: "B"
102             }
103             TextField{
104                 id: fieldB
105                 text: "-"
106                 width: 150
107             }
108
109             Label{
110                 text: "C"
111             }
112             TextField{
113                 id: fieldC
114                 text: "-"
115                 width: 150
116             }
117
118             Label{
119                 text: "D"
120             }
121             TextField{
122                 id: fieldD
123                 text: "-"
124                 width: 150
125             }
126
127             Label{
128                 text: "Up"
129             }
130             TextField{
131                 id: fieldUp
132                 text: "-"
133                 width: 150
134             }
135
136             Label{
137                 text: "Down"
138             }
139             TextField{
140                 id: fieldDown
141                 text: "-"
142                 width: 150
143             }
144
145             Label{
146                 text: "Left"
147             }
148             TextField{
149                 id: fieldLeft
150                 text: "-"
151                 width: 150
152             }
153
154             Label{
155                 text: "Right"
156             }
157             TextField{
158                 id: fieldRight
159                 text: "-"
160                 width: 150
161             }
162         }
163
164         Label{
165             id: explanationLabel
166             anchors{top: contentGrid.bottom; left: parent.left; right: parent.right; margins: 20}
167             horizontalAlignment: Text.AlignHCenter
168             wrapMode: Text.WordWrap
169
170             text: "Some possibly useful key names are:\nUp, Down, Left, Right, Return, space\n" +
171                   "If you don't need any of these special keys just enter a single character for each key binding. " +
172                   "Upper- and lowercase characters are allowed."
173         }
174     }
175 }
176