Harmattan Config UI modifications
[vicar] / src / vicar-config-qml / qml / vicarconfigqml / MainPage.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import "file:///usr/lib/qt4/imports/com/meego/UIConstants.js" as UIConstants
4 //import "file:///usr/lib/qt4/imports/com/nokia/extras/constants.js" as ExtrasConstants
5 import "Library/js/DBUtility.js" as DBUtility
6 import "Library/js/CoreLogic.js" as Core
7
8 Page {
9     tools: commonTools
10     id: mainPage
11
12     Component.onCompleted: {
13         DBUtility.initialize();
14         Core.loadRules();
15     }
16
17     function reload(){
18         Core.loadRules();
19     }
20
21     Rectangle{
22         id: headerRect
23         anchors.top:parent.top
24         width: parent.width ; height: appWindow.inPortrait ? UIConstants.HEADER_DEFAULT_HEIGHT_PORTRAIT: UIConstants.HEADER_DEFAULT_HEIGHT_LANDSCAPE
25         color: "darkgray"
26
27         Text {
28             id: titleText
29             font.family: UIConstants.FONT_FAMILY
30             font.pixelSize: UIConstants.FONT_SLARGE
31             color: UIConstants.COLOR_FOREGROUND
32             anchors.centerIn: parent
33             horizontalAlignment: Text.AlignHCenter;
34             text: qsTr("VICaR - Rules")
35         }
36     }
37
38     Loader
39     {
40         id: uiLoader
41         anchors {top: headerRect.bottom; bottom: parent.bottom}
42         width: parent.width
43     }
44
45     ListModel{
46         id: rulesModel
47     }
48
49
50     Component {
51         id: rulesComponent
52         Item {
53             ListView {
54                 id: rulesView
55                 anchors.fill: parent
56                 clip: true
57                 model: rulesModel                      
58                 delegate:ruleDelegate
59             }
60         }
61     }
62
63     Component {
64         id: ruleDelegate
65         Item{
66             width: uiLoader.width            
67             height: UIConstants.LIST_ITEM_HEIGHT_DEFAULT
68
69             BorderImage {
70                 anchors.fill: parent
71                 visible: mouseArea.pressed
72                 source: theme.inverted ?
73                             'image://theme/meegotouch-list-fullwidth-inverted-background-pressed-vertical-center':
74                             'image://theme/meegotouch-list-fullwidth-background-pressed-vertical-center'
75             }
76
77             Text {
78                 height: parent.height;
79                 anchors {left: parent.left;leftMargin: UIConstants.DEFAULT_MARGIN; right: parent.right; rightMargin: UIConstants.DEFAULT_MARGIN}
80                 font.family: UIConstants.FONT_FAMILY
81                 font.pixelSize: UIConstants.FONT_SLARGE
82                 color: UIConstants.COLOR_FOREGROUND
83                 horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter
84                 wrapMode: Text.WordWrap
85                 //lineHeightMode: Text.ProportionalHeight; lineHeight: 1.5
86                 text: "For numbers starting with "+numberpattern+ ", use "+gatewaynumber;
87             }
88             MouseArea{
89                 id: mouseArea
90                 anchors.fill: parent
91                 onPressAndHold: {
92                     ruleContextMenu.ruleID = id;
93                     console.log("Setting Rule ID as "+id);
94                     ruleContextMenu.open();
95                 }
96             }
97         }
98     }
99
100     ContextMenu{
101         id: ruleContextMenu
102         property int ruleID:0
103
104         MenuLayout{
105             MenuItem {
106                 text: qsTr("Edit");
107                 onClicked: {
108                     Core.editRule(ruleContextMenu.ruleID);
109                 }
110             }
111             MenuItem {
112                 text: qsTr("Delete");
113                 onClicked: {
114                     DBUtility.removeRule(ruleContextMenu.ruleID);
115                     Core.loadRules();
116                 }
117             }
118         }
119     }
120
121     Component{
122         id: blankComponent
123         Item {
124             Label {
125                 id: label
126                 anchors.centerIn: parent
127                 text: qsTr("Add rules for call routing.")
128                 visible: true
129             }
130         }
131     }
132 }