Hello Asif,
in fact there's a lack of docs on it, but after all it's not part of standard api ;-)
I've written this for 3rd Ed MR, i couldn't test it on other versions, but i hope it helps.
"con" and "cal" are the syncml server sources (values provided by Funambol syncml server, "con" and "caltask" on Mobical syncml server)
Code:
void CSyncProfileManager::CreateProfileL(const TDesC& aProfileName, const TDesC8& aUsername, const TDesC8& aPassword, const TDesC8& aServerURI, const TDesC& aIapName)
{
RSyncMLSession syncMLSession;
RSyncMLDataSyncProfile syncProfile;
TInt err=KErrNone;
// open SyncML session
TRAP(err,syncMLSession.OpenL());
User::LeaveIfError(err);
// create a profile
TRAP(err,syncProfile.CreateL(syncMLSession));
User::LeaveIfError(err);
TSmlCreatorId creatorId = _UID3;
syncProfile.SetCreatorId(creatorId);
TRAP(err, {
syncProfile.SetDisplayNameL(aProfileName);
syncProfile.SetUserNameL(aUsername);
syncProfile.SetPasswordL(aPassword);
// protocol version, values are:
// ESmlVersion1_1_2 = 1.1.2
// ESmlVersion1_2 = 1.2
syncProfile.SetProtocolVersionL(ESmlVersion1_1_2);
// This is for accepting all sync requests
syncProfile.SetSanUserInteractionL(ESmlEnableSync);
//syncProfile.DeleteAllowed();
// save profile
syncProfile.UpdateL();
});
User::LeaveIfError(err);
// create and enable tasks (applications)
// retrieve needed data provider ids
TSmlDataProviderId contactsProvider = -1;
TSmlDataProviderId calendarProvider = -1;
RArray<TSmlDataProviderId> dataProvidersArr;
TRAP(err,syncMLSession.ListDataProvidersL(dataProvidersArr));
User::LeaveIfError(err);
TInt count = dataProvidersArr.Count();
for(int i=0;i<count;i++)
{
RSyncMLDataProvider dataProvider;
TRAP(err,dataProvider.OpenL(syncMLSession,dataProvidersArr[i]));
User::LeaveIfError(err);
if(dataProvider.DisplayName().Compare(_L("Calendar"))==0)
{
calendarProvider = dataProvider.Identifier();
}
else if(dataProvider.DisplayName().Compare(_L("Contacts"))==0)
{
contactsProvider = dataProvider.Identifier();
}
dataProvider.Close();
}
if(contactsProvider == -1)
User::Leave(KErrNoContactsProvider);
// contacts
RSyncMLTask contactsTask;
TRAP(err,contactsTask.CreateL(syncProfile,contactsProvider,_L("con"),_L("C:Contacts.cdb")));
User::LeaveIfError(err);
contactsTask.SetCreatorId(creatorId);
TRAP(err,
{contactsTask.SetEnabledL(ETrue);
contactsTask.SetDisplayNameL(_L("Contacts"));
contactsTask.SetDefaultSyncTypeL(ESmlTwoWay);
contactsTask.SetFilterMatchTypeL(ESyncMLMatchDisabled);
contactsTask.UpdateL();
});
User::LeaveIfError(err);
contactsTask.Close();
if(calendarProvider == -1)
User::Leave(KErrNoCalendarProvider);
// calendar
RSyncMLTask calendarTask;
TRAP(err,calendarTask.CreateL(syncProfile,calendarProvider,_L("caltask"),_L("C:Calendar")));
User::LeaveIfError(err);
calendarTask.SetCreatorId(creatorId);
TRAP(err,
{calendarTask.SetEnabledL(ETrue);
calendarTask.SetDisplayNameL(_L("Calendar"));
calendarTask.SetDefaultSyncTypeL(ESmlTwoWay);
calendarTask.SetFilterMatchTypeL(ESyncMLMatchDisabled);
calendarTask.UpdateL();
});
User::LeaveIfError(err);
calendarTask.Close();
// SAVE PROFILE AGAIN to save tasks!!!!
TRAP(err,syncProfile.UpdateL());
User::LeaveIfError(err);
// set server URI and IapId
// if NSmlIapId = -1, user is asked for IAP
// otherwise it is set to the specified IapId
// useful property names: NSmlIapId,NSmlIapId2,NSmlIapId3,NSmlIapId4,NSmlUseRoaming,NSmlHTTPAuth,NSmlHTTPUsername,NSmlHTTPPassword
RArray<TSmlConnectionId> connArr;
TRAP(err,syncProfile.ListConnectionsByConnectionIdL(connArr));
User::LeaveIfError(err);
TInt count2 = connArr.Count();
//TBuf<20> connNumber;
//connNumber.AppendNum(count2);
//CEikonEnv::InfoWinL(_L("ConnectionNumber:"),connNumber);
for(int i=0;i<count2;i++)
{
RSyncMLConnection syncConnection;
TRAP(err,syncConnection.OpenByConnectionIdL(syncProfile,connArr[i]));
User::LeaveIfError(err);
SetIapIdForConnProperties(aIapName);
syncConnection.SetPriority(0);
syncConnection.SetRetryCount(0);
TRAP(err, {
syncConnection.SetServerURIL(aServerURI);
syncConnection.SetPropertyL(_L8("NSmlIapId"),iIapId);
syncConnection.UpdateL();
});
User::LeaveIfError(err);
syncConnection.Close();
}
TRAP(err,syncProfile.UpdateL());
User::LeaveIfError(err);
// close profile
syncProfile.Close();
// close SyncML session
syncMLSession.Close();
}
regards,
pg