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