Version 0.7-0
[vicar] / src / vicar-config-qml / qml / vicarconfigqml / addrulesheet.qml
diff --git a/src/vicar-config-qml/qml/vicarconfigqml/addrulesheet.qml b/src/vicar-config-qml/qml/vicarconfigqml/addrulesheet.qml
new file mode 100644 (file)
index 0000000..321950e
--- /dev/null
@@ -0,0 +1,146 @@
+import QtQuick 1.1
+import com.nokia.meego 1.0
+import "Library/js/DBUtility.js" as DBUtility
+
+Sheet{
+    id: screen
+    acceptButtonText: qsTr("Done")
+    rejectButtonText: qsTr("Cancel")
+
+    signal sheetDestroyed()
+
+    property int ruleID:0
+    property string numberpattern:""
+    property string gatewaynumber:""
+    property string dtmfformat:""
+    property int numberFormatIndex:0
+    property string dtmfprefix: ""
+    property string dtmfsuffix: ""
+
+    Component.onCompleted: {
+        if (ruleID != 0){
+            var ruleObj = DBUtility.getRuleByID(ruleID);
+            if (ruleObj !== null){
+                numberpattern = ruleObj.numberpattern;
+                gatewaynumber = ruleObj.gatewaynumber;
+                dtmfformat = ruleObj.dtmfformat;
+                var i;
+                for (i = 0; i < numberFormatModel.count; i++){
+                    if (numberFormatModel.get(i).name == dtmfformat) {
+                        numberFormatIndex = i;
+                        break;
+                    }
+                }
+                dtmfprefix = ruleObj.dtmfprefix;
+                dtmfsuffix = ruleObj.dtmfsuffix;
+            }
+        }
+    }
+
+    Component.onDestruction: {
+        console.log("OnDestruction");
+        sheetDestroyed();
+    }
+
+    ListModel {
+        id: numberFormatModel
+        ListElement { name: "<Country Code><Area Code><Phone Number>" }
+        ListElement { name: "+<Country Code><Area Code><Phone Number>" }
+        ListElement { name: "00<Country Code><Area Code><Phone Number>" }
+        ListElement { name: "011<Country Code><Area Code><Phone Number>" }
+    }
+
+    SelectionDialog {
+        id: numberFormatDialog
+        titleText: "Number Format"
+        width: container.width
+        selectedIndex: numberFormatIndex
+        model: numberFormatModel
+    }
+
+    content: Flickable {
+        id: container
+        anchors.fill: parent
+        anchors.leftMargin: 10
+        anchors.topMargin: 10
+        flickableDirection: Flickable.VerticalFlick
+
+        Column {
+            id: col
+            width: parent.width
+            spacing: 10
+            Label { text: (ruleID != 0)? qsTr("Edit Rule"):qsTr("Add Rule"); font.bold: true; }
+            Label { text: qsTr("For numbers starting with:") }
+            TextField {
+                id: numberStartingWith
+                anchors { left: parent.left; right: parent.right; }
+                //height: implicitHeight
+                inputMethodHints: Qt.ImhDialableCharactersOnly | Qt.ImhNoPredictiveText
+                text: screen.numberpattern
+            }
+            Label { text: qsTr("Route call via:") }
+            TextField {
+                id: gatewayNumber
+                anchors { left: parent.left; right: parent.right; }
+                //height: implicitHeight
+                inputMethodHints: Qt.ImhDialableCharactersOnly | Qt.ImhNoPredictiveText
+                text: screen.gatewaynumber
+            }
+
+            Label { text: qsTr("Dial number in this format:") }
+
+            Button {
+                anchors { horizontalCenter: parent.horizontalCenter }
+                //height: implicitHeight
+                text: "Change Format"
+                onClicked: {
+                    numberFormatDialog.open();
+                }
+            }
+
+            Rectangle {
+                width: parent.width
+                height: 30
+                color: "lightgray"
+                Text {
+                    anchors.horizontalCenter: parent.horizontalCenter
+                    text: numberFormatDialog.selectedIndex >= 0 ? numberFormatDialog.model.get(numberFormatDialog.selectedIndex).name : "None"
+                    font.pixelSize: 16
+                    //font.bold: true
+                }
+            }
+
+            Label { text: qsTr("Include this tone before dialing:") }
+            TextField {
+                id: dtmfPrefix
+                anchors { left: parent.left; right: parent.right; }
+                height: implicitHeight
+                inputMethodHints: Qt.ImhDialableCharactersOnly | Qt.ImhNoPredictiveText
+            }
+
+            Label { text: qsTr("Include this tone after dialing:") }
+            TextField {
+                id: dtmfSuffix
+                anchors { left: parent.left; right: parent.right; }
+                height: implicitHeight
+                inputMethodHints: Qt.ImhDialableCharactersOnly | Qt.ImhNoPredictiveText
+            }
+        }
+    }
+    onAccepted: {
+        //id, numberpattern, gatewaynumber, dtmfformat, dtmfprefix, dtmfsuffix
+        var ruleObj = new Object();
+        ruleObj.id = ruleID;
+        ruleObj.numberpattern = numberStartingWith.text;
+        ruleObj.gatewaynumber = gatewayNumber.text;
+        ruleObj.dtmfformat = numberFormatDialog.model.get(numberFormatDialog.selectedIndex).name;
+        ruleObj.dtmfprefix = dtmfPrefix.text;
+        ruleObj.dtmfsuffix = dtmfSuffix.text;
+        if (ruleID != 0)
+            DBUtility.updateRule(ruleID,ruleObj);
+        else
+            DBUtility.addRule(ruleObj);
+        destroy();
+    }
+    onRejected: destroy();
+}