|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : applicationusinguisettings.cpp 00004 * Part of : datamobility 00005 * Description : CApplicationUsingUiSettings implementation. 00006 * 00007 * Copyright (c) 2007 Nokia Corporation. 00008 * This material, including documentation and any related 00009 * computer programs, is protected by copyright controlled by 00010 * Nokia Corporation. 00011 * ============================================================================== 00012 */ 00013 00014 // INCLUDE FILES 00015 #include <e32cons.h> 00016 #include <stringloader.h> 00017 #include <datamobility.rsg> 00018 #include <CommDbConnPref.h> 00019 #include "applicationusinguisettings.h" 00020 #include "datamobilityprinter.h" 00021 00022 // ============================ MEMBER FUNCTIONS =============================== 00023 00024 // ----------------------------------------------------------------------------- 00025 // CApplicationUsingUiSettings::NewL 00026 // ----------------------------------------------------------------------------- 00027 // 00028 CApplicationUsingUiSettings* CApplicationUsingUiSettings::NewL( MDataMobilityPrinter& aObserver ) 00029 { 00030 CApplicationUsingUiSettings* self = 00031 new ( ELeave ) CApplicationUsingUiSettings( aObserver ); 00032 CleanupStack::PushL( self ); 00033 self->ConstructL(); 00034 CleanupStack::Pop( self ); 00035 return self; 00036 } 00037 00038 // ----------------------------------------------------------------------------- 00039 // CApplicationUsingUiSettings::ConstructL 00040 // ----------------------------------------------------------------------------- 00041 // 00042 void CApplicationUsingUiSettings::ConstructL() 00043 { 00044 User::LeaveIfError( iSocketServer.Connect() ); 00045 } 00046 00047 // ----------------------------------------------------------------------------- 00048 // CApplicationUsingUiSettings::CApplicationUsingUiSettings 00049 // ----------------------------------------------------------------------------- 00050 // 00051 CApplicationUsingUiSettings::CApplicationUsingUiSettings( MDataMobilityPrinter& aObserver ) 00052 : CActive( CActive::EPriorityStandard ), 00053 iObserver( aObserver ) 00054 { 00055 CActiveScheduler::Add( this ); 00056 } 00057 00058 // ----------------------------------------------------------------------------- 00059 // CApplicationUsingUiSettings::~CApplicationUsingUiSettings 00060 // ----------------------------------------------------------------------------- 00061 // 00062 CApplicationUsingUiSettings::~CApplicationUsingUiSettings() 00063 { 00064 Cancel(); 00065 00066 iConnection.Close(); 00067 00068 iSocketServer.Close(); 00069 } 00070 00071 // ----------------------------------------------------------------------------- 00072 // CApplicationUsingUiSettings::StartL 00073 // ----------------------------------------------------------------------------- 00074 // 00075 void CApplicationUsingUiSettings::StartL() 00076 { 00077 User::LeaveIfError( iConnection.Open( iSocketServer ) ); 00078 00079 TBool selected = ConnectionSettingL(); 00080 00081 if ( !selected ) 00082 { 00083 PrintL( R_OUTPUT_USER_CANCELLED_THE_SELECTION ); 00084 return; 00085 } 00086 00087 switch ( iUserSelection.iResult ) 00088 { 00089 case CMManager::EDestination: 00090 { 00091 TConnSnapPref prefs; 00092 prefs.SetSnap( iUserSelection.iId ); 00093 00094 PrintL( R_OUTPUT_START_CONNECTION_WITH_PREFERENCES ); 00095 00096 PrintL( R_OUTPUT_SNAP_ID, prefs.Snap() ); 00097 00098 iConnection.Start( prefs, iStatus ); 00099 break; 00100 } 00101 case CMManager::EConnectionMethod: 00102 { 00103 TCommDbConnPref prefs; 00104 prefs.SetIapId( iUserSelection.iId ); 00105 prefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); 00106 00107 PrintL( R_OUTPUT_START_CONNECTION_WITH_PREFERENCES ); 00108 00109 PrintL( R_OUTPUT_IAP_ID, prefs.IapId() ); 00110 00111 iConnection.Start( prefs, iStatus ); 00112 break; 00113 } 00114 case CMManager::EDefaultConnection: 00115 { 00116 PrintL( R_OUTPUT_ATTEMPT_TO_USE_THE_DFT_CONNECTION ); 00117 00118 iConnection.Start( iStatus ); 00119 break; 00120 } 00121 default: // CMManager::EAlwaysAsk 00122 { 00123 TCommDbConnPref prefs; 00124 prefs.SetDialogPreference( ECommDbDialogPrefPrompt ); 00125 00126 PrintL( R_OUTPUT_PROMPT_CONNECTION_DIALOG ); 00127 00128 iConnection.Start( prefs, iStatus ); 00129 } 00130 } 00131 00132 SetActive(); 00133 } 00134 00135 // ----------------------------------------------------------------------------- 00136 // CApplicationUsingUiSettings::ConnectionSettingL 00137 // ----------------------------------------------------------------------------- 00138 // 00139 TBool CApplicationUsingUiSettings::ConnectionSettingL() 00140 { 00141 TBool selected( EFalse ); 00142 00143 CCmApplicationSettingsUi* settings = CCmApplicationSettingsUi::NewL(); 00144 CleanupStack::PushL( settings ); 00145 00146 TUint listedItems = CMManager::EShowAlwaysAsk | 00147 CMManager::EShowDefaultConnection | 00148 CMManager::EShowDestinations | 00149 CMManager::EShowConnectionMethods; 00150 00151 TBearerFilterArray filter; 00152 00153 selected = settings->RunApplicationSettingsL( iUserSelection, 00154 listedItems, 00155 filter ); 00156 00157 CleanupStack::PopAndDestroy( settings ); 00158 00159 return selected; 00160 } 00161 00162 // ----------------------------------------------------------------------------- 00163 // CApplicationUsingUiSettings::RunL 00164 // ----------------------------------------------------------------------------- 00165 // 00166 void CApplicationUsingUiSettings::RunL() 00167 { 00168 if ( iStatus.Int() == KErrNone ) 00169 { 00170 PrintL( R_OUTPUT_CONNECTION_STARTED ); 00171 } 00172 else 00173 { 00174 PrintL( R_OUTPUT_RUNL_STATUS_ERROR, iStatus.Int() ); 00175 } 00176 } 00177 00178 // ----------------------------------------------------------------------------- 00179 // CApplicationUsingUiSettings::DoCancel 00180 // ----------------------------------------------------------------------------- 00181 // 00182 void CApplicationUsingUiSettings::DoCancel() 00183 { 00184 iConnection.Close(); 00185 // iConnection.Stop() should be avoided: 00186 // other client applications' connection should not be terminated. 00187 } 00188 00189 // ----------------------------------------------------------------------------- 00190 // CApplicationUsingUiSettings::PrintL 00191 // ----------------------------------------------------------------------------- 00192 // 00193 void CApplicationUsingUiSettings::PrintL( TInt aResourceId ) 00194 { 00195 // Load a string from the resource file. 00196 HBufC* message = StringLoader::LoadL( aResourceId ); 00197 00198 iObserver.Print( *message ); 00199 00200 delete message; 00201 } 00202 00203 // ----------------------------------------------------------------------------- 00204 // CApplicationUsingUiSettings::PrintL 00205 // ----------------------------------------------------------------------------- 00206 // 00207 void CApplicationUsingUiSettings::PrintL( TInt aResourceId, TInt aInt ) 00208 { 00209 // Load a string from the resource file. 00210 HBufC* message = StringLoader::LoadL( aResourceId, aInt ); 00211 00212 iObserver.Print( *message ); 00213 00214 delete message; 00215 } 00216 00217 // End of File
|
© Nokia 2009 |