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