examples/QtQuick/telephonyexampleqml/qml/telephonyexampleqml/main.qml

00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation
00006 **
00007 **
00008 ** $QT_BEGIN_LICENSE:BSD$
00009 ** You may use this file under the terms of the BSD license as follows:
00010 **
00011 ** "Redistribution and use in source and binary forms, with or without
00012 ** modification, are permitted provided that the following conditions are
00013 ** met:
00014 **   * Redistributions of source code must retain the above copyright
00015 **     notice, this list of conditions and the following disclaimer.
00016 **   * Redistributions in binary form must reproduce the above copyright
00017 **     notice, this list of conditions and the following disclaimer in
00018 **     the documentation and/or other materials provided with the
00019 **     distribution.
00020 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
00021 **     the names of its contributors may be used to endorse or promote
00022 **     products derived from this software without specific prior written
00023 **     permission.
00024 **
00025 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00027 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00028 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00029 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00030 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00031 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00032 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00033 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00034 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00035 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
00036 ** $QT_END_LICENSE$
00037 **
00038 ****************************************************************************/
00039 
00040 import QtQuick 1.0
00041 import Qt 4.7
00042 import com.nokia.symbian 1.1
00043 import com.nokia.xqtelephonydeclarative 1.0
00044 
00045 /*
00046  * The application demonstrates the telephony Qt style APIs. It demonstrates
00047  * following use caess:
00048  * Change the volume level
00049  * Change the mute/ unmute status
00050  * Make a call
00051  * End the call
00052  * Note: the example does not demonstrates the incoming call use cases as the default phone
00053  * application has higher priority.
00054  */
00055 Window {
00056     id: view
00057         
00058         // status bar displayed at the top of the window
00059         // that shows signal strength, battery strength...      
00060     StatusBar {
00061         id: statusBar
00062         anchors.top: view.top
00063     }    
00064                 
00065     
00066     // provides access to the telephony manager which handles calls and services.       
00067     XQTelephonyManager {
00068         id: manager
00069     }
00070     
00071     
00072     // provides access to operations, properties related to microphone and speaker volume levels     
00073     XQTelephonyAudio {
00074         id: audio
00075         maxCallVolume: 20       // maximum volume of a call       
00076         callVolume:10           // volume of a call        
00077         
00078         // The event handler for the micMuteChanged signal that emites when the 
00079         //mute status changes. It displays an appropriate icon when the status changes.                 
00080         onMicMuteChanged: {
00081                 if (audio.micMuted == true) {                   
00082                         actionImage.source = "qgn_indi_button_mute_mic.svg";
00083                 }       
00084                 else {                  
00085                         actionImage.source = "qgn_indi_button_unmute_mic.svg";
00086                 }                       
00087         }           
00088         
00089         // The event handler for the callVolumeChanged signal that emits when the 
00090         // volume level changes. It displays an appropriate icon when the level changes.         
00091         onCallVolumeChanged: {      
00092                 actionImage.source = "button_sound_on.png";                     
00093         }
00094     }
00095     
00096     
00097     // CallHeader is displayed when a user dials a number.     
00098     Component {
00099         id: callItem
00100                 CallHeader {
00101                         id: callHeaderDisplay   
00102                         // Sets the labels of the buttons based on the state of the call 
00103                         // and takes the action appropriately.                  
00104                         property bool incomingCall: (call.callState == XQTelephonyCall.Incoming);
00105                 stateText: "";          
00106                 button1Text: incomingCall ? "Answer" : "End call";
00107                 onButton1Pressed: incomingCall ? answer() : endcall();       
00108                 
00109                 //Different call states are defined here
00110             states: [
00111                 State {
00112                     name: "idle"
00113                     when: call.callState == XQTelephonyCall.Idle || call.callState == XQTelephonyCall.Unknown
00114                     PropertyChanges { target: callHeaderDisplay; stateText: "Idle"; }
00115                 },
00116                 State {
00117                     name: "dialing"                             
00118                     when: call.callState == XQTelephonyCall.Dialing
00119                     PropertyChanges { target: callHeaderDisplay; stateText: "Dialing..."; }
00120                 },
00121                 State {
00122                     name: "remotebusy"
00123                     when: call.callError == XQTelephonyCall.RemoteBusy
00124                     PropertyChanges { target: callHeaderDisplay; stateText: "Remote busy"; }
00125                 },
00126                 State {
00127                     name: "alerting"
00128                     when: call.callState == XQTelephonyCall.Alerting
00129                     PropertyChanges { target: callHeaderDisplay; stateText: "Alerting..."; }
00130                 },
00131                 State {
00132                     name: "connected"
00133                     when: call.callState == XQTelephonyCall.Connected
00134                     PropertyChanges { target: callHeaderDisplay; stateText: "Connected"; }
00135                 },
00136                 State {
00137                     name: "onhold"
00138                     when: call.callState == XQTelephonyCall.Hold
00139                     PropertyChanges { target: callHeaderDisplay; stateText: "On hold"; }
00140                 },
00141                 State {
00142                     name: "disconnecting"
00143                     when: call.callState == XQTelephonyCall.Disconnecting
00144                     PropertyChanges { target: callHeaderDisplay; stateText: "Disconnecting..."; }
00145                 },
00146                 State {
00147                     name: "incoming"
00148                     when: call.callState == XQTelephonyCall.Incoming
00149                     PropertyChanges { target: callHeaderDisplay; stateText: "Incoming"; }
00150                 }
00151             ]
00152                     
00153                 // Function definitions for call actions - end call and answer call       
00154             function endcall() {             
00155                 call.handleEndCallPressed();
00156             }
00157 
00158             function answer() {              
00159                 call.handleAnswerPressed();
00160             }                   
00161             }
00162     }
00163     
00164     
00165     // View populates XQTelephonyManager active calls     
00166     ListView {
00167         id: callList
00168         model: manager.activeCalls
00169         delegate: callItem
00170         anchors.left: parent.left
00171                 anchors.top: statusBar.bottom
00172             anchors.topMargin: 10
00173     }   
00174    
00175     // Displays the dialled number at the specified position and sets 
00176     // the formating options for the text     
00177     Text {
00178                 id: phoneNumberEdit             
00179                 text:""                 
00180                 anchors.right: parent.right
00181                 anchors.rightMargin: 5                  
00182                 anchors.bottom: volumeSlider.top
00183                 anchors.bottomMargin: 25                        
00184                 font.weight: Font.Bold
00185         font.pixelSize:25
00186         color: "white"          
00187     }    
00188     
00189     
00190     // Displays appropriate image based on the event handler.     
00191     Image {
00192         id: actionImage
00193         anchors.bottom: volumeSlider.top
00194                 anchors.bottomMargin: 20
00195                 source: "button_sound_on.png"                   
00196     }
00197     
00198     
00199     // Slider for adjusting the volume level
00200     // Sets the minimum, maximum and default values 
00201     // When the slider value changes, it emits the callVolumeChanged
00202     // signal and sets the volume as per the slider value     
00203     Slider {
00204                 id: volumeSlider
00205                 maximumValue: audio.maxCallVolume
00206         minimumValue: 0
00207         value: audio.callVolume
00208         stepSize: 1
00209         valueIndicatorVisible: true             
00210         anchors.left: parent.left               
00211                 anchors.bottom: numberKeyboard.top      
00212                 anchors.bottomMargin: 5                 
00213                 onValueChanged: {
00214                         audio.callVolume = value;                                                                               
00215                 }       
00216     }   
00217 
00218         // The mute/unmute button. when clicked emits the micMuteChanged signal
00219         // also changes the mute satus.  
00220         Button {
00221                 id: muteButton
00222                 text: audio.micMuted ? "Unmute" : "Mute"
00223                 width: 120
00224                 height: 35              
00225                 anchors.left: volumeSlider.right
00226                 anchors.leftMargin: 20
00227                 anchors.bottom: numberKeyboard.top
00228                 anchors.bottomMargin: 25                
00229                 onClicked: {
00230                 audio.micMuted = !audio.micMuted             
00231         }
00232         } 
00233 
00234         
00235         // The keyboard for dialing a number and displays it.    
00236         VKeyboard {
00237                 id:numberKeyboard
00238                 anchors.bottom:dialButton.top   
00239                 onSend: {         
00240                 phoneNumberEdit.text =  phonenumber 
00241                 loader.sourceComponent = null
00242             onClicked: mainMenu.close()
00243         }                               
00244      }   
00245 
00246         
00247         // The dial button. It makes a call when clicked. 
00248         Button {
00249                 id:dialButton
00250                 text:"Dial"
00251                 anchors.right:parent.right
00252                 anchors.left:parent.left
00253                 anchors.bottom:toolBar.top              
00254                 height: 50
00255                 onClicked: {                    
00256             manager.makeCall(phoneNumberEdit.text, "CS");    
00257         } 
00258         }
00259         
00260         
00261         // The tool bar is displayed at the bottom of the screen with the option to exit 
00262         // the application and for the menu      
00263     ToolBar {
00264         id: toolBar
00265         anchors.bottom: view.bottom
00266         tools: ToolBarLayout {
00267             id: toolBarLayout
00268             ToolButton {
00269                 flat: true
00270                 iconSource: "toolbar-back"
00271                 onClicked: Qt.quit()
00272             }
00273             ToolButton {
00274                 flat: true
00275                 iconSource: "toolbar-menu"
00276                 onClicked: mainMenu.open()
00277             }
00278         }
00279     }
00280     
00281     // TextArea that displays the help of the application
00282     Component {
00283         id: helpComponent
00284         TextArea {
00285                         readOnly: true  
00286                         anchors.bottom: parent.bottom
00287                         anchors.right: parent.right                                             
00288                         text: "Click the Mute button to make it on/off \nUse the slider to change the volume \
00289                                                                         \nlevel. Type a number and click \nthe Dial button"                     
00290         }     
00291     }
00292     
00293     // TextArea that displays the information "about" the application
00294     Component {
00295         id: aboutComponent
00296         TextArea {
00297                         readOnly: true  
00298                         anchors.bottom: parent.bottom
00299                         anchors.right: parent.right                                             
00300                         text: "The example demonstrates the\nTelephony Qt style API by showcasing \
00301                                                                                                                                 \nout going call feature."                      
00302         }     
00303     }
00304     
00305     // To load a component
00306     Loader {
00307         id: loader       
00308     }
00309     
00310     // A Menu with 3 options - Help, About and Close
00311     Menu{
00312             id: mainMenu
00313             content:
00314             Column{
00315                 width: pageMenu.width
00316 
00317                 MenuItem{
00318                     id: menu1
00319                     text: "Help"
00320                     onClicked:{
00321                         loader.sourceComponent = helpComponent                  
00322                     }
00323                 }
00324                 MenuItem{
00325                     id: menu2
00326                     text: "About"
00327                     onClicked:{                        
00328                         loader.sourceComponent = aboutComponent
00329                     }
00330                 }
00331                 MenuItem{
00332                     id: menu3
00333                     text: "Close"
00334                     onClicked:{                        
00335                         loader.sourceComponent = null
00336                         onClicked: mainMenu.close()
00337                     }
00338                 }     
00339             }
00340     }           
00341 }
00342 

Generated by  doxygen 1.6.2