932 TInt iDataProvElementCount = iProfiles[iProfiles.Count()-1]->iDataProvElement.Count()-1; |
937 TInt iDataProvElementCount = iProfiles[iProfiles.Count()-1]->iDataProvElement.Count()-1; |
933 // Leave if aType cannot be assigned |
938 // Leave if aType cannot be assigned |
934 if( ( aType.Length() > 0 ) && |
939 if( ( aType.Length() > 0 ) && |
935 ( iProfiles[iProfiles.Count()-1]->iDataProvElement[iDataProvElementCount]->iRemoteDBUri ) ) |
940 ( iProfiles[iProfiles.Count()-1]->iDataProvElement[iDataProvElementCount]->iRemoteDBUri ) ) |
936 { |
941 { |
|
942 TBool dataProvIdFoundInZ = FALSE; |
|
943 TSmlDataProviderId firstDataProvIdFound = 0; |
|
944 TSmlDataProviderId uidFound = 0; |
|
945 |
|
946 TBool doSearch = ETrue; |
|
947 if ( aType.FindF( KXVcardMimeType ) != KErrNotFound ) |
|
948 { |
|
949 if ( IsOperatorProfile( *iProfiles[iProfiles.Count()-1] ) ) |
|
950 { |
|
951 const CNSmlDsProfileElement& profile = *iProfiles[iProfiles.Count()-1]; |
|
952 StoreOperatorUrlL( *profile.iHostAddress ); |
|
953 |
|
954 // Do not make a search through adapter implementations |
|
955 doSearch = EFalse; |
|
956 uidFound = OperatorAdapterUid(); |
|
957 if ( !uidFound ) |
|
958 { |
|
959 // If OperatorAdapterUid returns 0, do a search |
|
960 doSearch = ETrue; |
|
961 } |
|
962 } |
|
963 } |
937 // look through every implementation adapter until one found |
964 // look through every implementation adapter until one found |
938 // which supports MIME type in question |
965 // which supports MIME type in question |
939 |
966 |
940 // The first one located in ROM is chosen. If none found in ROM then |
967 // The first one located in ROM is chosen. If none found in ROM then |
941 // the first adapter found is chosen. |
968 // the first adapter found is chosen. |
942 |
969 |
943 HBufC8 *type = HBufC8::NewLC(aType.Size()); |
970 HBufC8 *type = HBufC8::NewLC(aType.Size()); |
944 TPtr8 typePtr = type->Des(); |
971 TPtr8 typePtr = type->Des(); |
945 CnvUtfConverter::ConvertFromUnicodeToUtf8( typePtr, aType); |
972 CnvUtfConverter::ConvertFromUnicodeToUtf8( typePtr, aType); |
946 |
|
947 TBool dataProvIdFoundInZ = FALSE; |
|
948 TSmlDataProviderId firstDataProvIdFound = 0; |
|
949 TSmlDataProviderId uidFound = 0; |
|
950 |
973 |
951 // get list of dataproviderIds |
974 // get list of dataproviderIds |
952 RImplInfoPtrArray implArray; |
975 RImplInfoPtrArray implArray; |
953 CleanupStack::PushL( PtrArrCleanupItemRArr( CImplementationInformation, &implArray ) ); |
976 CleanupStack::PushL( PtrArrCleanupItemRArr( CImplementationInformation, &implArray ) ); |
954 TUid ifUid = { KNSmlDSInterfaceUid }; |
977 TUid ifUid = { KNSmlDSInterfaceUid }; |
955 REComSession::ListImplementationsL( ifUid, implArray ); |
978 REComSession::ListImplementationsL( ifUid, implArray ); |
956 |
979 |
957 TInt countProviders = implArray.Count(); |
980 if ( doSearch ) |
958 for( TInt i = 0; i < countProviders; i++ ) |
981 { |
959 { |
982 TInt countProviders = implArray.Count(); |
960 CImplementationInformation* implInfo = implArray[i]; |
983 for( TInt i = 0; i < countProviders; i++ ) |
|
984 { |
|
985 CImplementationInformation* implInfo = implArray[i]; |
|
986 |
|
987 RSyncMLDataProvider dataProvider; |
|
988 dataProvider.OpenL( iSession, implInfo->ImplementationUid().iUid ); |
|
989 CleanupClosePushL( dataProvider ); |
|
990 |
|
991 TInt mimeTypeCount = dataProvider.MimeTypeCount(); |
|
992 for( TInt j = 0; j < mimeTypeCount; j++ ) |
|
993 { |
|
994 HBufC* mimeType = dataProvider.MimeType( j ).AllocLC(); |
|
995 TPtrC8 convMimeType = ConvertTo8LC( *mimeType ); |
|
996 if( typePtr.Find( convMimeType ) == 0) |
|
997 { |
|
998 // MIME type in question was found |
|
999 uidFound = implInfo->ImplementationUid().iUid; |
|
1000 |
|
1001 if( firstDataProvIdFound == 0 ) |
|
1002 { |
|
1003 // save the first in case of none found from ROM |
|
1004 firstDataProvIdFound = uidFound; |
|
1005 } |
|
1006 |
|
1007 // check whether the provider is located in ROM (drive Z) |
|
1008 if( implInfo->Drive() == EDriveZ ) |
|
1009 { |
|
1010 dataProvIdFoundInZ = TRUE; |
|
1011 } |
|
1012 } |
|
1013 |
|
1014 CleanupStack::PopAndDestroy(2); // mimetype, ConvertTo8LC |
|
1015 |
|
1016 if( uidFound ) |
|
1017 { |
|
1018 break; |
|
1019 } |
|
1020 } |
|
1021 |
|
1022 CleanupStack::PopAndDestroy(); // dataProvider |
961 |
1023 |
962 RSyncMLDataProvider dataProvider; |
1024 if ( dataProvIdFoundInZ ) |
963 dataProvider.OpenL( iSession, implInfo->ImplementationUid().iUid ); |
1025 { |
964 CleanupClosePushL( dataProvider ); |
1026 break; |
965 |
1027 } |
966 TInt mimeTypeCount = dataProvider.MimeTypeCount(); |
1028 else |
967 for( TInt j = 0; j < mimeTypeCount; j++ ) |
1029 { |
968 { |
1030 uidFound = firstDataProvIdFound; |
969 HBufC* mimeType = dataProvider.MimeType( j ).AllocLC(); |
1031 } |
970 TPtrC8 convMimeType = ConvertTo8LC( *mimeType ); |
1032 } |
971 if( typePtr.Find( convMimeType ) == 0) |
1033 } |
972 { |
1034 |
973 // MIME type in question was found |
|
974 uidFound = implInfo->ImplementationUid().iUid; |
|
975 |
|
976 if( firstDataProvIdFound == 0 ) |
|
977 { |
|
978 // save the first in case of none found from ROM |
|
979 firstDataProvIdFound = uidFound; |
|
980 } |
|
981 |
|
982 // check whether the provider is located in ROM (drive Z) |
|
983 if( implInfo->Drive() == EDriveZ ) |
|
984 { |
|
985 dataProvIdFoundInZ = TRUE; |
|
986 } |
|
987 } |
|
988 |
|
989 CleanupStack::PopAndDestroy(2); // mimetype, ConvertTo8LC |
|
990 |
|
991 if( uidFound ) |
|
992 { |
|
993 break; |
|
994 } |
|
995 } |
|
996 |
|
997 CleanupStack::PopAndDestroy(); // dataProvider |
|
998 |
|
999 if ( dataProvIdFoundInZ ) |
|
1000 { |
|
1001 break; |
|
1002 } |
|
1003 else |
|
1004 { |
|
1005 uidFound = firstDataProvIdFound; |
|
1006 } |
|
1007 } |
|
1008 |
|
1009 REComSession::FinalClose(); |
1035 REComSession::FinalClose(); |
1010 CleanupStack::PopAndDestroy( 2 ); // type, implArray |
1036 CleanupStack::PopAndDestroy( 2 ); // type, implArray |
1011 |
1037 |
1012 if( uidFound ) |
1038 if( uidFound ) |
1013 { |
1039 { |
1072 CnvUtfConverter::ConvertFromUnicodeToUtf8( bufPtr, aSource ); |
1098 CnvUtfConverter::ConvertFromUnicodeToUtf8( bufPtr, aSource ); |
1073 |
1099 |
1074 return *buf; |
1100 return *buf; |
1075 } |
1101 } |
1076 |
1102 |
|
1103 //----------------------------------------------------------------------------- |
|
1104 // CNSmlDsProvisioningAdapter::IsOperatorProfile |
|
1105 // |
|
1106 //----------------------------------------------------------------------------- |
|
1107 // |
|
1108 TBool CNSmlDsProvisioningAdapter::IsOperatorProfile( const CNSmlDsProfileElement& aProfile ) |
|
1109 { |
|
1110 TBuf8<KMaxValueLength> value; |
|
1111 CRepository* rep = NULL; |
|
1112 TRAPD ( err, rep = CRepository::NewL( KCRUidOperatorDatasyncInternalKeys ) ); |
|
1113 if ( err == KErrNone ) |
|
1114 { |
|
1115 rep->Get( KNsmlOpDsOperatorSyncServerId, value ); |
|
1116 delete rep; |
|
1117 } |
|
1118 |
|
1119 if ( aProfile.iServerId ) |
|
1120 { |
|
1121 if ( value.Compare( *aProfile.iServerId ) == 0 ) |
|
1122 { |
|
1123 return ETrue; |
|
1124 } |
|
1125 } |
|
1126 return EFalse; |
|
1127 } |
|
1128 |
|
1129 //----------------------------------------------------------------------------- |
|
1130 // CNSmlDsProvisioningAdapter::OperatorAdapterUid |
|
1131 // |
|
1132 //----------------------------------------------------------------------------- |
|
1133 // |
|
1134 TInt CNSmlDsProvisioningAdapter::OperatorAdapterUid() |
|
1135 { |
|
1136 TInt value = 0; |
|
1137 CRepository* rep = NULL; |
|
1138 TRAPD ( err, rep = CRepository::NewL( KCRUidOperatorDatasyncInternalKeys ) ); |
|
1139 if ( err == KErrNone ) |
|
1140 { |
|
1141 rep->Get( KNsmlOpDsOperatorAdapterUid, value ); |
|
1142 delete rep; |
|
1143 } |
|
1144 return value; |
|
1145 } |
|
1146 |
|
1147 //----------------------------------------------------------------------------- |
|
1148 // CNSmlDsProvisioningAdapter::StoreOperatorUrlL |
|
1149 // |
|
1150 //----------------------------------------------------------------------------- |
|
1151 // |
|
1152 void CNSmlDsProvisioningAdapter::StoreOperatorUrlL( const TDesC& aUrl ) |
|
1153 { |
|
1154 CRepository* rep = NULL; |
|
1155 TRAPD ( err, rep = CRepository::NewL( KCRUidOperatorDatasyncInternalKeys ) ); |
|
1156 if ( err == KErrNone ) |
|
1157 { |
|
1158 CleanupStack::PushL( rep ); |
|
1159 User::LeaveIfError( rep->Set( KNsmlOpDsOperatorSyncServerURL, aUrl )); |
|
1160 CleanupStack::PopAndDestroy( rep ); |
|
1161 } |
|
1162 } |
1077 |
1163 |
1078 // End of File |
1164 // End of File |