examples/QtQuick/nfcshareappqml/nfcshareexample.cpp

00001 /*
00002  * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *  
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  * 
00007  * Redistributions of source code must retain the above copyright notice, this
00008  *  list of conditions and the following disclaimer.
00009  * Redistributions in binary form must reproduce the above copyright notice,
00010  *   this list of conditions and the following disclaimer in the documentation
00011  *   and/or other materials provided with the distribution.
00012  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *  may be used to endorse or promote products derived from this software
00014  * without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *
00027  * Description:  source file of nfc share class.
00028  * 
00029  */
00030 
00031 // User Include Files.
00032 #include <QStringList>
00033 #include "nfcshareexample.h"
00034 
00035 /*
00036  * Constructor, create an instance of the NfcShareExample class.
00037  * Create an instance of Qt Style NFC Share class.
00038  * Connect NFC Share signals with the handles implemented in the class.
00039  */
00040 NfcShareExample::NfcShareExample()
00041 {
00042     mNfcShare = new XQNfcShare(this);
00043 
00044     // Connect the NFC share signals.
00045     connect( mNfcShare, SIGNAL( busy(bool) ), this, SLOT( handleNfcShareBusy(bool) ) );
00046     connect( mNfcShare, SIGNAL( easySetupStarted() ), this, SLOT( handleEasySetupStarted()) );
00047     connect( mNfcShare, SIGNAL( shareStarted() ), this, SLOT( handleShareStarted() ) );
00048     connect( mNfcShare, SIGNAL( shareCompleted() ), this, SLOT( handleShareCompleted() ) );
00049     connect( mNfcShare, SIGNAL( easySetupCompleted() ), this, SLOT( handleEasySetupCompleted() ) );
00050     connect( mNfcShare, SIGNAL( error(XQNfcShare::Error) ), this, SLOT( handleNfcShareError(XQNfcShare::Error) ) );
00051 }
00052 
00053 /*
00054  * Destructor.
00055  */
00056 NfcShareExample::~NfcShareExample()
00057 {  
00058     if(mNfcShare)
00059         {
00060         delete mNfcShare;
00061         }
00062 }
00063 
00067 void NfcShareExample::handleNfcShareBusy( bool value )
00068 {
00069     if(value == true){
00070         mDisplayText.append( "Nfc share is busy\n" );
00071         mDisplayText.append( "Wait till it completes your request.\n" );
00072     }
00073     else{
00074         mDisplayText.append( "Nfc share is not busy\n" );
00075     }
00076     emit displayText( mDisplayText );
00077 }
00078 
00082 void NfcShareExample::handleEasySetupStarted()
00083 {
00084     mDisplayText.append( "Nfc share easy setup started\n" );
00085     emit displayText( mDisplayText );
00086 }
00087 
00091 void NfcShareExample::handleEasySetupCompleted()
00092 {
00093     mDisplayText.append( "Nfc share easy setup completed\n" );  
00094 
00095     // Display the details of the device detected
00096     if( mNfcShare->bearerType()== XQNfcShare::NoBearer ){
00097         mDisplayText.append( "Bearer type : No Bearer\n" );
00098     }
00099     else if( mNfcShare->bearerType()== XQNfcShare::Bluetooth ){
00100         mDisplayText.append( "Bearer type : Bluetooth\n" );
00101         mDisplayText.append( "Device Address : " );
00102         mDisplayText.append( mNfcShare->bluetoothDeviceAddress() );
00103         mDisplayText.append( "\nDevice Name : " );
00104         mDisplayText.append( mNfcShare->bluetoothDeviceName() );
00105         mDisplayText.append( "\n" );
00106     }
00107     emit displayText( mDisplayText );        
00108 }
00109 
00113 void NfcShareExample::handleShareStarted()
00114 {
00115     mDisplayText.append( "share started\n" ); 
00116     
00117     // Display the details of the device detected
00118     if( mNfcShare->bearerType()== XQNfcShare::NoBearer ){
00119         mDisplayText.append( "Bearer type : No Bearer\n" );
00120     }
00121     else if( mNfcShare->bearerType()== XQNfcShare::Bluetooth ){
00122         mDisplayText.append( "Bearer type : Bluetooth\n" );
00123     }
00124     mDisplayText.append( "Device Address : " );
00125     mDisplayText.append(mNfcShare->bluetoothDeviceAddress());
00126     mDisplayText.append( "\nDevice Name : " );
00127     mDisplayText.append(mNfcShare->bluetoothDeviceName());
00128     
00129     // Depending upon the share option, share files.
00130     if( mShareOption == NfcShareExample::Single ){
00131         mDisplayText.append( "\nSharing single file." );
00132         mNfcShare->shareFile( "c:\\data\\dailymeeting.ics" );
00133     }
00134     else if( mShareOption == NfcShareExample::Multiple ){
00135         mDisplayText.append( "\nSharing multiple files.\n" );
00136         mNfcShare->shareFiles( QStringList()<<"c:\\data\\mycontact.vcf"<<"c:\\data\\dailymeeting.ics" );
00137     }
00138     
00139     emit displayText(mDisplayText);        
00140 }
00141 
00145 void NfcShareExample::handleShareCompleted()
00146 {
00147     mDisplayText.append( "share completed\n" );
00148     emit displayText( mDisplayText );
00149 }
00150 
00154 void NfcShareExample::handleNfcShareError( XQNfcShare::Error aError )
00155 {
00156     if( aError == XQNfcShare::NoError )
00157         mDisplayText.append( "Nfc share error cannot be determined\n" );
00158     
00159     // This error is displayed, when NFC is not switched on.
00160     else if( aError == XQNfcShare::NfcNotAvailable )
00161         mDisplayText.append( "Nfc is not available\n" );
00162     
00163     // This error is displayed, when there are no detected devices.
00164     else if( aError == XQNfcShare::DeviceNotAvailable )
00165         mDisplayText.append( "Device is not available\n" );
00166     
00167     // System Error.
00168     else if( aError == XQNfcShare::SystemError )
00169         mDisplayText.append( "System error\n" );
00170     
00171     // When connection is rejected by the detected device.
00172     else if( aError == XQNfcShare::ConnectionDenied )
00173         mDisplayText.append( "Connection denied error\n" );
00174     
00175     // When a pending 'Nfc Share' request is cancelled.
00176     else if( aError == XQNfcShare::Cancelled )
00177         mDisplayText.append( "Cancelled error\n" );
00178     
00179     emit displayText( mDisplayText );
00180 }
00181 
00182 /*
00183  * Starts the easy setup service, it will fetch the details of the 
00184  * detected device after completing the setup.
00185  * use mNfcShare->easySetupAndPair() API to pair with the 
00186  * detected device.
00187  */ 
00188 void NfcShareExample::startEasySetup()
00189 {
00190     mNfcShare->easySetup();
00191 }
00192 
00196 void NfcShareExample::startEasySetupAndPair()
00197 {
00198     mNfcShare->easySetupAndPair();
00199 }
00200 
00201 /*
00202  * Cancels the onging request of 'NFC Share', and NFC is not busy once again.
00203  */
00204 void NfcShareExample::cancel()
00205 {
00206     mNfcShare->cancel();
00207 }
00208 
00209 /*
00210  * Starts sharing single file.
00211  */
00212 void NfcShareExample::shareFile()
00213 {
00214     mShareOption = NfcShareExample::Single;
00215     mNfcShare->share();
00216 }
00217 
00221 void NfcShareExample::shareFiles()
00222 {
00223     mShareOption = NfcShareExample::Multiple;
00224     mNfcShare->share();
00225 }
00226 
00230 void NfcShareExample::clear()
00231 {
00232     mDisplayText.clear();
00233 }

Generated by  doxygen 1.6.2