Version 0.7-0
[vicar] / src / vicar-config-qml / qml / vicarconfigqml / MainPage.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import "Library/js/DBUtility.js" as DBUtility
4 import "Library/js/CoreLogic.js" as Core
5
6 Page {
7     tools: commonTools
8     id: mainPage
9
10     Component.onCompleted: {
11         DBUtility.initialize();
12         Core.loadRules();
13     }
14
15     function reload(){
16         Core.loadRules();
17     }
18
19     Rectangle{
20         id: headerRect
21         anchors.top:parent.top
22         width: parent.width ; height: parent.height/10
23         color: "grey"
24         opacity: 0.6
25
26         Text {
27             id: titleText
28             anchors.centerIn: parent //#cccccc
29             font.pointSize: 16; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "black"; style: Text.Raised; styleColor: "black"
30             font.bold: true
31             text: qsTr("VICaR - Rules")
32         }
33     }
34
35     Loader
36     {
37         id: uiLoader
38         anchors {top: headerRect.bottom; bottom: parent.bottom}
39         width: parent.width
40     }
41
42     ListModel{
43         id: rulesModel
44     }
45
46
47     Component {
48         id: rulesComponent
49         Item {
50             ListView {
51                 id: rulesView
52                 model: rulesModel
53                 anchors.fill: parent
54                 delegate:ruleDelegate
55             }
56         }
57     }
58
59     Component {
60         id: ruleDelegate
61         Item{
62             width: uiLoader.width
63             height: 40
64             Text {
65                 width: parent.width
66                 font.pointSize: 16; horizontalAlignment: Text.AlignLeft; elide: Text.ElideLeft; color: "black"; style: Text.Raised; styleColor: "black"
67                 text: "For #s starting with "+numberpattern+ ", use "+gatewaynumber;
68             }
69             MouseArea{
70                 anchors.fill: parent
71                 onPressAndHold: {
72                     ruleContextMenu.ruleID = id;
73                     console.log("Setting Rule ID as "+id);
74                     ruleContextMenu.open();
75                 }
76             }
77         }
78     }
79
80     ContextMenu{
81         id: ruleContextMenu
82         property int ruleID:0
83
84         MenuLayout{
85             MenuItem {
86                 text: qsTr("Edit");
87                 onClicked: {
88                     Core.editRule(ruleContextMenu.ruleID);
89                 }
90             }
91             MenuItem {
92                 text: qsTr("Delete");
93                 onClicked: {
94                     DBUtility.removeRule(ruleContextMenu.ruleID);
95                     Core.loadRules();
96                 }
97             }
98         }
99     }
100
101     Component{
102         id: blankComponent
103         Item {
104             Label {
105                 id: label
106                 anchors.centerIn: parent
107                 text: qsTr("Add rules for call routing.")
108                 visible: true
109             }
110         }
111     }
112 }