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