Harmattan Config UI modifications
[vicar] / src / vicar-config-qml / qml / vicarconfigqml / addrulesheet.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import "Library/js/DBUtility.js" as DBUtility
4 import "file:///usr/lib/qt4/imports/com/meego/UIConstants.js" as UIConstants
5 import "file:///usr/lib/qt4/imports/com/nokia/extras/constants.js" as ExtrasConstants
6
7 Sheet{
8     id: screen
9     acceptButtonText: qsTr("Done")
10     rejectButtonText: qsTr("Cancel")
11
12     signal sheetDestroyed()
13
14     property int ruleID:0
15     property string numberpattern:""
16     property string gatewaynumber:""
17     property string dtmfformat:""
18     property int numberFormatIndex:0
19     property string dtmfprefix: ""
20     property string dtmfsuffix: ""
21
22     Component.onCompleted: {
23         if (ruleID != 0){
24             var ruleObj = DBUtility.getRuleByID(ruleID);
25             if (ruleObj !== null){
26                 numberpattern = ruleObj.numberpattern;
27                 gatewaynumber = ruleObj.gatewaynumber;
28                 dtmfformat = ruleObj.dtmfformat;
29                 var i;
30                 for (i = 0; i < numberFormatModel.count; i++){
31                     if (numberFormatModel.get(i).name === dtmfformat) {
32                         numberFormatIndex = i;
33                         break;
34                     }
35                 }
36                 dtmfprefix = ruleObj.dtmfprefix;
37                 dtmfsuffix = ruleObj.dtmfsuffix;
38             }
39         }
40     }
41
42     Component.onDestruction: {
43         console.log("OnDestruction");
44         sheetDestroyed();
45     }
46
47     ListModel {
48         id: numberFormatModel
49         ListElement { name: "<Country Code><Area Code><Phone Number>" }
50         ListElement { name: "+<Country Code><Area Code><Phone Number>" }
51         ListElement { name: "00<Country Code><Area Code><Phone Number>" }
52         ListElement { name: "011<Country Code><Area Code><Phone Number>" }
53     }
54
55     SelectionDialog {
56         id: numberFormatDialog
57         titleText: "Number Format"
58         width: container.width
59         selectedIndex: numberFormatIndex
60         model: numberFormatModel
61     }
62
63     content: Flickable {
64         id: container
65         anchors.fill: parent
66         anchors.leftMargin: UIConstants.DEFAULT_MARGIN
67         anchors.rightMargin: UIConstants.DEFAULT_MARGIN
68         anchors.topMargin: UIConstants.DEFAULT_MARGIN
69         flickableDirection: Flickable.VerticalFlick
70         contentHeight: col.height + UIConstants.DEFAULT_MARGIN
71
72         Column {
73             id: col
74             width: parent.width
75             spacing: 10
76             Label {
77                 text: (ruleID != 0)? qsTr("Edit Rule"):qsTr("Add Rule");
78                 font.family: UIConstants.FONT_FAMILY_LIGHT
79                 font.pixelSize: UIConstants.FONT_XLARGE
80             }
81             Label { text: qsTr("For numbers starting with:") }
82             TextField {
83                 id: numberStartingWith
84                 anchors { left: parent.left; right: parent.right; }
85                 inputMethodHints: Qt.ImhDialableCharactersOnly | Qt.ImhNoPredictiveText
86                 text: screen.numberpattern
87             }
88             Label { text: qsTr("Route call via:") }
89             TextField {
90                 id: gatewayNumber
91                 anchors { left: parent.left; right: parent.right; }
92                 inputMethodHints: Qt.ImhDialableCharactersOnly | Qt.ImhNoPredictiveText
93                 text: screen.gatewaynumber
94             }
95
96             Label { text: qsTr("Dial number in this format (tap to change): ") }
97
98             Rectangle {
99                 width: parent.width
100                 height: UIConstants.LIST_ITEM_HEIGHT_SMALL
101                 color: "transparent"
102
103                 BorderImage {
104                     anchors.fill: parent
105                     visible: mouseArea.pressed
106                     source: theme.inverted ?
107                                 'image://theme/meegotouch-list-fullwidth-inverted-background-pressed-vertical-center':
108                                 'image://theme/meegotouch-list-fullwidth-background-pressed-vertical-center'
109                 }
110
111                 Text {
112                     anchors.verticalCenter: parent.verticalCenter
113                     verticalAlignment: Text.AlignVCenter
114                     text: numberFormatDialog.selectedIndex >= 0 ? numberFormatDialog.model.get(numberFormatDialog.selectedIndex).name : "None"
115                     font.family: UIConstants.FONT_FAMILY_LIGHT
116                     font.pixelSize: UIConstants.FONT_SMALL
117                 }
118
119                 MouseArea{
120                     id: mouseArea
121                     anchors.fill: parent
122                     onClicked: {
123                         numberFormatDialog.open();
124                     }
125                 }
126             }
127
128             Label { text: qsTr("Send this tone before dialing:") }
129             TextField {
130                 id: dtmfPrefix
131                 anchors { left: parent.left; right: parent.right; }
132                 inputMethodHints: Qt.ImhDialableCharactersOnly | Qt.ImhNoPredictiveText
133             }
134
135             Label { text: qsTr("Send this tone after dialing:") }
136             TextField {
137                 id: dtmfSuffix
138                 anchors { left: parent.left; right: parent.right; }
139                 inputMethodHints: Qt.ImhDialableCharactersOnly | Qt.ImhNoPredictiveText
140             }
141         }
142     }
143     onAccepted: {
144         //id, numberpattern, gatewaynumber, dtmfformat, dtmfprefix, dtmfsuffix
145         var ruleObj = new Object();
146         ruleObj.id = ruleID;
147         ruleObj.numberpattern = numberStartingWith.text;
148         ruleObj.gatewaynumber = gatewayNumber.text;
149         ruleObj.dtmfformat = numberFormatDialog.model.get(numberFormatDialog.selectedIndex).name;
150         ruleObj.dtmfprefix = dtmfPrefix.text;
151         ruleObj.dtmfsuffix = dtmfSuffix.text;
152         if (ruleID != 0)
153             DBUtility.updateRule(ruleID,ruleObj);
154         else
155             DBUtility.addRule(ruleObj);
156         destroy();
157     }
158     onRejected: destroy();
159 }