plugins/contacts/symbiansim/src/cntsimstoreprivate.cpp
changeset 5 603d3f8b6302
parent 0 876b1a06bc25
equal deleted inserted replaced
3:e4ebb16b39ea 5:603d3f8b6302
    83     m_storeInfo.m_secondNameSupported       = false;
    83     m_storeInfo.m_secondNameSupported       = false;
    84     m_storeInfo.m_additionalNumberSupported = false;
    84     m_storeInfo.m_additionalNumberSupported = false;
    85     m_storeInfo.m_emailSupported            = false;
    85     m_storeInfo.m_emailSupported            = false;
    86     
    86     
    87     // SDN store is allways read only
    87     // SDN store is allways read only
    88     if (m_storeInfo.m_storeName == KParameterValueSimStoreNameSdn)
    88     if (m_storeInfo.m_storeName == KParameterValueSimStoreNameSdn ||
       
    89         m_storeInfo.m_storeName == KParameterValueSimStoreNameOn)
    89         m_storeInfo.m_readOnlyAccess = true;
    90         m_storeInfo.m_readOnlyAccess = true;
    90 }
    91 }
    91 
    92 
    92 void CntSimStorePrivate::ConstructL()
    93 void CntSimStorePrivate::ConstructL()
    93 {
    94 {
   102     RTelServer::TPhoneInfo info;
   103     RTelServer::TPhoneInfo info;
   103     User::LeaveIfError(m_etelServer.GetPhoneInfo(0, info));
   104     User::LeaveIfError(m_etelServer.GetPhoneInfo(0, info));
   104     User::LeaveIfError(m_etelPhone.Open(m_etelServer, info.iName));
   105     User::LeaveIfError(m_etelPhone.Open(m_etelServer, info.iName));
   105     
   106     
   106     // Open Etel store
   107     // Open Etel store
   107     User::LeaveIfError(m_etelStore.Open(m_etelPhone, storeName));
   108     if (m_storeInfo.m_storeName == KParameterValueSimStoreNameOn) {
       
   109         User::LeaveIfError(m_etelOnStore.Open(m_etelPhone));
       
   110     }
       
   111     else {
       
   112         User::LeaveIfError(m_etelStore.Open(m_etelPhone, storeName));        
       
   113     }
   108 
   114 
   109     // Update store info
   115     // Update store info
   110     updateStoreInfoL();
   116     updateStoreInfoL();
   111     
   117     
   112     // Start listening for events
   118     // Start listening for events
   113     m_listener = new (ELeave) CntSimStoreEventListener(m_engine, m_etelStore);
   119     if (m_storeInfo.m_storeName == KParameterValueSimStoreNameOn) {
       
   120         m_listener = new (ELeave) CntSimStoreEventListener(m_engine, m_etelOnStore);
       
   121     }
       
   122     else {
       
   123         m_listener = new (ELeave) CntSimStoreEventListener(m_engine, m_etelStore);
       
   124     }
   114     m_listener->start();
   125     m_listener->start();
   115 }
   126 }
   116 
   127 
   117 CntSimStorePrivate::~CntSimStorePrivate()
   128 CntSimStorePrivate::~CntSimStorePrivate()
   118 {
   129 {
   119     Cancel();
   130     Cancel();
   120     delete m_listener;
   131     delete m_listener;
   121     m_etelStore.Close();
   132     m_etelStore.Close();
       
   133     m_etelOnStore.Close();
   122     m_etelPhone.Close();
   134     m_etelPhone.Close();
   123     m_etelServer.Close();
   135     m_etelServer.Close();
   124 }
   136 }
   125 
   137 
   126 void CntSimStorePrivate::convertStoreNameL(TDes &storeName)
   138 void CntSimStorePrivate::convertStoreNameL(TDes &storeName)
   137         storeName.Copy(KETelIccFdnPhoneBook);
   149         storeName.Copy(KETelIccFdnPhoneBook);
   138     } else if (m_storeInfo.m_storeName == KParameterValueSimStoreNameAdn) {
   150     } else if (m_storeInfo.m_storeName == KParameterValueSimStoreNameAdn) {
   139         storeName.Copy(KETelIccAdnPhoneBook);
   151         storeName.Copy(KETelIccAdnPhoneBook);
   140     } else if (m_storeInfo.m_storeName == KParameterValueSimStoreNameSdn) {
   152     } else if (m_storeInfo.m_storeName == KParameterValueSimStoreNameSdn) {
   141         storeName.Copy(KETelIccSdnPhoneBook);
   153         storeName.Copy(KETelIccSdnPhoneBook);
       
   154     } else if (m_storeInfo.m_storeName == KParameterValueSimStoreNameOn) {
       
   155         storeName.Copy(KETelOwnNumberStore);
   142     }
   156     }
   143 
   157 
   144     // Check that we got a valid store name
   158     // Check that we got a valid store name
   145     if(storeName.Length() == 0) {
   159     if(storeName.Length() == 0) {
   146         User::Leave(KErrArgument);
   160         User::Leave(KErrArgument);
   151 {
   165 {
   152     if (IsActive()) {
   166     if (IsActive()) {
   153         *error = QContactManager::LockedError;
   167         *error = QContactManager::LockedError;
   154         return false;
   168         return false;
   155     }
   169     }
       
   170     
       
   171     // ON store requires different read approach.
       
   172     // fetch ON contacts synchronously since there are usually only couple of them  
       
   173     if (m_storeInfo.m_storeName == KParameterValueSimStoreNameOn) {
       
   174 
       
   175         TRequestStatus status;
       
   176         QList<QContact> fetchedContacts; 
       
   177         for (int i = index; i <= numSlots; i++) {
       
   178             RMobileONStore::TMobileONEntryV1 onEntry;
       
   179             onEntry.iIndex = i;         
       
   180             RMobileONStore::TMobileONEntryV1Pckg onEntryPkg(onEntry);
       
   181             m_etelOnStore.Read(status, onEntryPkg);
       
   182             User::WaitForRequest(status);
       
   183             if (status.Int() == KErrNone) {
       
   184                 QContact c;
       
   185                 c.setType(QContactType::TypeContact);
       
   186                 QContactName name;
       
   187                 name.setCustomLabel(QString::fromUtf16(onEntry.iText.Ptr(),
       
   188                         onEntry.iText.Length()));
       
   189                 c.saveDetail(&name);
       
   190                 
       
   191                 QContactPhoneNumber number;
       
   192                 number.setNumber(QString::fromUtf16(onEntry.iNumber.iTelNumber.Ptr(),
       
   193                         onEntry.iNumber.iTelNumber.Length()));
       
   194                 c.saveDetail(&number);
       
   195                 
       
   196                 QScopedPointer<QContactId> contactId(new QContactId());
       
   197                 contactId->setLocalId(i);
       
   198                 contactId->setManagerUri(m_managerUri);
       
   199                 c.setId(*contactId);
       
   200                 fetchedContacts.append(c);
       
   201             }
       
   202         }
       
   203         emit m_simStore.readComplete(fetchedContacts, QContactManager::NoError);
       
   204         *error = QContactManager::NoError;
       
   205         return true;
       
   206     }        
   156     
   207     
   157     // start reading
   208     // start reading
   158     m_buffer.Zero();
   209     m_buffer.Zero();
   159     m_buffer.ReAlloc(KOneSimContactBufferSize*numSlots);
   210     m_buffer.ReAlloc(KOneSimContactBufferSize*numSlots);
   160     m_etelStore.Read(iStatus, index, numSlots, m_buffer);
   211     m_etelStore.Read(iStatus, index, numSlots, m_buffer);
       
   212     
   161     SetActive();
   213     SetActive();
   162     m_state = ReadState;
   214     m_state = ReadState;
   163     
   215     
   164     *error = QContactManager::NoError;
   216     *error = QContactManager::NoError;
   165     return true;
   217     return true;
   168 bool CntSimStorePrivate::write(const QContact &contact, QContactManager::Error *error)
   220 bool CntSimStorePrivate::write(const QContact &contact, QContactManager::Error *error)
   169 {
   221 {
   170     if (IsActive()) {
   222     if (IsActive()) {
   171         *error = QContactManager::LockedError;
   223         *error = QContactManager::LockedError;
   172         return false;
   224         return false;
       
   225     }
       
   226     
       
   227     if (m_storeInfo.m_readOnlyAccess) {
       
   228         *error = QContactManager::NotSupportedError;
       
   229         return false;    
   173     }
   230     }
   174     
   231     
   175     // get index
   232     // get index
   176     m_writeIndex = KErrNotFound;
   233     m_writeIndex = KErrNotFound;
   177     if (contact.id().managerUri() == m_managerUri &&
   234     if (contact.id().managerUri() == m_managerUri &&
   206     if (IsActive()) {
   263     if (IsActive()) {
   207         *error = QContactManager::LockedError;
   264         *error = QContactManager::LockedError;
   208         return false;
   265         return false;
   209     }
   266     }
   210     
   267     
       
   268     if (m_storeInfo.m_readOnlyAccess) {
       
   269         *error = QContactManager::NotSupportedError;
       
   270         return false;    
       
   271     }
       
   272     
   211     // NOTE:
   273     // NOTE:
   212     // If index points to an empty slot and running in hardware the 
   274     // If index points to an empty slot and running in hardware the 
   213     // delete operation will not return any error.
   275     // delete operation will not return any error.
   214     
   276     
   215     m_etelStore.Delete(iStatus, index);
   277     m_etelStore.Delete(iStatus, index);
   223 bool CntSimStorePrivate::getReservedSlots(QContactManager::Error *error)
   285 bool CntSimStorePrivate::getReservedSlots(QContactManager::Error *error)
   224 {
   286 {
   225     if (IsActive()) {
   287     if (IsActive()) {
   226         *error = QContactManager::LockedError;
   288         *error = QContactManager::LockedError;
   227         return false;
   289         return false;
       
   290     }
       
   291     
       
   292     // reserved slots are checked for sim contacts removing, 
       
   293     // this operation is not supported for read only stores
       
   294     if (m_storeInfo.m_readOnlyAccess) {
       
   295         *error = QContactManager::NotSupportedError;
       
   296         return false;    
   228     }
   297     }
   229     
   298     
   230     // start reading
   299     // start reading
   231     m_buffer.Zero();
   300     m_buffer.Zero();
   232     m_buffer.ReAlloc(KOneSimContactBufferSize*m_storeInfo.m_totalEntries);
   301     m_buffer.ReAlloc(KOneSimContactBufferSize*m_storeInfo.m_totalEntries);
   662 void CntSimStorePrivate::writeL(QContact *contact)
   731 void CntSimStorePrivate::writeL(QContact *contact)
   663 {
   732 {
   664     if (IsActive())
   733     if (IsActive())
   665         User::Leave(KErrLocked);
   734         User::Leave(KErrLocked);
   666     
   735     
       
   736     if (m_storeInfo.m_readOnlyAccess) {
       
   737         User::Leave(KErrNotSupported);
       
   738     }
       
   739     
   667     // get index
   740     // get index
   668     int index = KErrNotFound;
   741     int index = KErrNotFound;
   669     if (contact->id().managerUri() == m_managerUri &&
   742     if (contact->id().managerUri() == m_managerUri &&
   670         contact->localId() > 0) {
   743         contact->localId() > 0) {
   671         index = contact->localId();
   744         index = contact->localId();
   692 void CntSimStorePrivate::removeL(int index)
   765 void CntSimStorePrivate::removeL(int index)
   693 {
   766 {
   694     if (IsActive())
   767     if (IsActive())
   695         User::Leave(KErrLocked);
   768         User::Leave(KErrLocked);
   696     
   769     
       
   770     if (m_storeInfo.m_readOnlyAccess) {
       
   771         User::Leave(KErrNotSupported);
       
   772     }
       
   773     
   697     // NOTE:
   774     // NOTE:
   698     // If index points to an empty slot and running in hardware the 
   775     // If index points to an empty slot and running in hardware the 
   699     // delete operation will not return any error.
   776     // delete operation will not return any error.
   700     
   777     
   701     TRequestStatus status;
   778     TRequestStatus status;
   705 }
   782 }
   706 
   783 
   707 void CntSimStorePrivate::updateStoreInfoL()
   784 void CntSimStorePrivate::updateStoreInfoL()
   708 {
   785 {
   709 #ifdef SYMBIANSIM_BACKEND_PHONEBOOKINFOV1
   786 #ifdef SYMBIANSIM_BACKEND_PHONEBOOKINFOV1
       
   787     TRequestStatus status;
   710     RMobilePhoneBookStore::TMobilePhoneBookInfoV1 info;
   788     RMobilePhoneBookStore::TMobilePhoneBookInfoV1 info;
   711     RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg infoPckg(info);
   789     RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg infoPckg(info);
   712 #else
       
   713     RMobilePhoneBookStore::TMobilePhoneBookInfoV5 info;
       
   714     RMobilePhoneBookStore::TMobilePhoneBookInfoV5Pckg infoPckg(info);
       
   715 #endif
       
   716 
       
   717     // Get info
       
   718     TRequestStatus status;
       
   719     m_etelStore.GetInfo(status, infoPckg);
   790     m_etelStore.GetInfo(status, infoPckg);
   720     User::WaitForRequest(status);
   791     User::WaitForRequest(status);
   721     User::LeaveIfError(status.Int());
   792     User::LeaveIfError(status.Int());
   722 
       
   723     // Update entry counts
       
   724     m_storeInfo.m_totalEntries = info.iTotalEntries;
   793     m_storeInfo.m_totalEntries = info.iTotalEntries;
   725     m_storeInfo.m_usedEntries  = info.iUsedEntries;
   794     m_storeInfo.m_usedEntries  = info.iUsedEntries;
   726     
   795 #else
       
   796     // Get info
       
   797     TRequestStatus status;
       
   798     if (m_storeInfo.m_storeName == KParameterValueSimStoreNameOn) {
       
   799         RMobileONStore::TMobileONStoreInfoV1 onInfo;
       
   800         RMobileONStore::TMobileONStoreInfoV1Pckg onInfoPckg(onInfo);
       
   801         m_etelOnStore.GetInfo(status, onInfoPckg);
       
   802         User::WaitForRequest(status);
       
   803         User::LeaveIfError(status.Int());
       
   804 
       
   805         // Update entry counts
       
   806         m_storeInfo.m_totalEntries = onInfo.iTotalEntries;
       
   807         m_storeInfo.m_usedEntries  = onInfo.iUsedEntries;
       
   808     }
       
   809     else {
       
   810         RMobilePhoneBookStore::TMobilePhoneBookInfoV5 info;
       
   811         RMobilePhoneBookStore::TMobilePhoneBookInfoV5Pckg infoPckg(info);
       
   812         m_etelStore.GetInfo(status, infoPckg);
       
   813         User::WaitForRequest(status);
       
   814         User::LeaveIfError(status.Int());
       
   815 
       
   816         // Update entry counts
       
   817         m_storeInfo.m_totalEntries = info.iTotalEntries;
       
   818         m_storeInfo.m_usedEntries  = info.iUsedEntries;
       
   819     }
       
   820 #endif
       
   821 
   727 #ifdef SYMBIANSIM_BACKEND_TEST_EXTRADETAILS
   822 #ifdef SYMBIANSIM_BACKEND_TEST_EXTRADETAILS
   728     // Check if store supports the extra details
   823     // Check if store supports the extra details
   729     //
   824     //
   730     // NOTE: 
   825     // NOTE: 
   731     // We cannot rely on TMobilePhoneBookInfoV5 to check if we support
   826     // We cannot rely on TMobilePhoneBookInfoV5 to check if we support
   732     // these details. For example iMaxSecondNames is allways -1 even if the sim
   827     // these details. For example iMaxSecondNames is allways -1 even if the sim
   733     // card supports a second name.
   828     // card supports a second name.
   734     //
   829     //
   735     // There is an API for checking these but it's Nokia internal so we must
   830     // There is an API for checking these but it's Nokia internal so we must
   736     // do it this way - by checking if saving these details is possible.
   831     // do it this way - by checking if saving these details is possible.
   737     
   832 
   738     // Have we checked these already?
   833     // Have we checked these already?
   739     if (m_extraDetailsChecked == false)
   834     if (m_extraDetailsChecked == false)
   740     {
   835     {
   741         // Cannot test extra details if sim card is full 
   836         // Cannot test extra details if sim card is full 
   742         if (m_storeInfo.m_usedEntries == m_storeInfo.m_totalEntries)
   837         if (m_storeInfo.m_usedEntries == m_storeInfo.m_totalEntries)