phonebookui/cntcommonui/common/cntsimengine.cpp
changeset 72 6abfb1094884
child 81 640d30f4fb64
equal deleted inserted replaced
67:59984e68247d 72:6abfb1094884
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QString.h>
       
    19 
       
    20 #include "cntglobal.h"
       
    21 #include "CntSimEngine.h"
       
    22 #include "cntimportviewcallback.h"
       
    23 #include "cntdebug.h"
       
    24 
       
    25 #include <hbview.h>
       
    26 #include <QCoreApplication>
       
    27 #include <QStandardItemModel>
       
    28 #include <hbextendedlocale.h>
       
    29 #include <hbstringutil.h>
       
    30 #include <hbparameterlengthlimiter.h>
       
    31 #include <hbdialog.h>
       
    32 #include <hbnotificationdialog.h>
       
    33 #include <hbdevicenotificationdialog.h>
       
    34 
       
    35 const int KTimerValue = 1; // used as 1 msec timer for saving ADN contacts from SIM   
       
    36 
       
    37 CntSimEngine::CntSimEngine(CntImportViewCallback& aImportViewCallback, HbView& aView)
       
    38 : mImportViewCallback(aImportViewCallback),
       
    39     mView(aView),
       
    40     mAdnSimUtility(0),
       
    41     mSdnSimUtility(0),
       
    42     mContactSimManagerADN(0),
       
    43     mContactSimManagerSDN(0),    
       
    44     mFetchRequestADN(0),
       
    45     mFetchRequestSDN(0),
       
    46     mTimer(0),
       
    47     mAbsEngine(0),
       
    48     mTimerId(0),
       
    49     mSaveCount(0),
       
    50     mAdnStoreEntries(0),
       
    51     mSdnStoreEntries(0),
       
    52     mAdnEntriesPresent(false),
       
    53     mFetchIsDone(false),
       
    54     mAdnStorePresent(false),
       
    55     mSdnStorePresent(false),
       
    56     mSimPresent(false),
       
    57     mSimError(false),
       
    58     mWaitingForAdnCache(false),
       
    59     mImportInProgress(false)
       
    60 {
       
    61 
       
    62 }
       
    63 
       
    64 CntSimEngine::~CntSimEngine()
       
    65 {
       
    66     CNT_ENTRY
       
    67     delete mFetchRequestADN;
       
    68     delete mFetchRequestSDN;
       
    69     delete mAdnSimUtility;
       
    70     delete mSdnSimUtility;
       
    71     CNT_EXIT
       
    72 }
       
    73 
       
    74 void CntSimEngine::init(CntAbstractEngine& aAbsEngine)
       
    75 {
       
    76     CNT_ENTRY
       
    77     mAbsEngine = &aAbsEngine;
       
    78     mContactSymbianManager = &mAbsEngine->contactManager(SYMBIAN_BACKEND);
       
    79      
       
    80     // Sim Utility info fetch
       
    81      int getSimInfoError(0);
       
    82      int storesError(0);
       
    83      int getSdnSimInfoError(0);
       
    84      
       
    85      
       
    86      //ADN store
       
    87      int error = -1;
       
    88      mAdnSimUtility = new CntSimUtility(CntSimUtility::AdnStore, error);
       
    89      
       
    90      if (error != 0) 
       
    91      {
       
    92          delete mAdnSimUtility; 
       
    93          mAdnSimUtility = 0;
       
    94          mSimError = true;
       
    95          //mSimError = true;
       
    96      }
       
    97      else
       
    98      {
       
    99          // check what stores are there
       
   100          CntSimUtility::AvailableStores stores = mAdnSimUtility->getAvailableStores(storesError);
       
   101          if(!storesError)
       
   102          {
       
   103              mSimPresent = stores.SimPresent;
       
   104              mAdnStorePresent = stores.AdnStorePresent; 
       
   105              mSdnStorePresent = stores.SdnStorePresent;
       
   106          }
       
   107          
       
   108          //check there are ADN contacts 
       
   109          if (mAdnStorePresent)
       
   110          {
       
   111              CntSimUtility::SimInfo simInfo = mAdnSimUtility->getSimInfo(getSimInfoError);
       
   112              if (getSimInfoError == KErrNone)
       
   113              {
       
   114                  // sim entries are present
       
   115                  mAdnStoreEntries = simInfo.usedEntries;
       
   116                  if (mAdnStoreEntries > 0) 
       
   117                  {
       
   118                       mAdnEntriesPresent = true;
       
   119                  }
       
   120              }
       
   121              else
       
   122              {
       
   123                  if (getSimInfoError == KErrNotReady)
       
   124                  {
       
   125                      //ADN store is not accessible, e.g. because of active FDN
       
   126                      //Or ADN cache is not ready yet, so wait for this  
       
   127                      
       
   128                      mAdnStorePresent = true;
       
   129                      mAdnEntriesPresent = true;
       
   130                      mWaitingForAdnCache = true;
       
   131                      connect(mAdnSimUtility, SIGNAL(getSimInfoAndUpdateUI(CntSimUtility::CacheStatus&, int)), this, SLOT(getSimInfoAndUpdateUI(CntSimUtility::CacheStatus&, int)));
       
   132                      if (!mAdnSimUtility->notifyAdnCacheStatus()) {
       
   133                          mAdnStorePresent = false;
       
   134                          mAdnEntriesPresent = false;
       
   135                          mWaitingForAdnCache = false;
       
   136                      }
       
   137                  }
       
   138                  else
       
   139                  {
       
   140                      simInfoErrorMessage(getSimInfoError);
       
   141                  }
       
   142              }
       
   143          }
       
   144      }
       
   145      
       
   146      //SDN store
       
   147       if (mSdnStorePresent && !mWaitingForAdnCache)
       
   148       {
       
   149          int sdnError = -1;
       
   150          mSdnStorePresent = false;
       
   151          if (!mSdnSimUtility) 
       
   152          {
       
   153              mSdnSimUtility = new CntSimUtility(CntSimUtility::SdnStore, sdnError);
       
   154              if (sdnError != 0) 
       
   155              {
       
   156                  delete mSdnSimUtility; 
       
   157                  mSdnSimUtility = 0;
       
   158              }
       
   159          }
       
   160          if (mSdnSimUtility)
       
   161          {
       
   162              //get number of SDN contacts 
       
   163              CntSimUtility::SimInfo sdnSimInfo = mSdnSimUtility->getSimInfo(getSdnSimInfoError);
       
   164              if (!getSdnSimInfoError)
       
   165              {
       
   166                  // sim entries are present
       
   167                  mSdnStoreEntries = sdnSimInfo.usedEntries;
       
   168                  if (mSdnStoreEntries > 0)
       
   169                  {
       
   170                      mSdnStorePresent = true;    
       
   171                  }
       
   172              }
       
   173          }
       
   174       }
       
   175       CNT_EXIT
       
   176      // end SDN store
       
   177 }
       
   178 
       
   179 void CntSimEngine::checkEntries(QStringList& simList, QStandardItem& importSimItem)
       
   180 {
       
   181     CNT_ENTRY
       
   182     QString simImport(hbTrId("txt_phob_dblist_import_from_sim"));
       
   183     QString simNoContacts(hbTrId("txt_phob_dblist_import_from_1_val_no_sim_contacts"));
       
   184     QString simNoCard(hbTrId("txt_phob_dblist_import_from_ovi_val_no_sim_card"));
       
   185 
       
   186     // check if SIM card is NOT there 
       
   187     if (mSimError)
       
   188     {
       
   189         simList << simImport;
       
   190         importSimItem.setEnabled(false);
       
   191     }
       
   192     else if (!(mAdnStorePresent || mSdnStorePresent))
       
   193     {
       
   194         // Both stores are not present
       
   195         // disable the QStandardItem
       
   196         if (!mSimPresent) 
       
   197         {
       
   198             simList << simImport << simNoCard;
       
   199         }
       
   200         else
       
   201         {
       
   202             simList << simImport << simNoContacts;
       
   203         }
       
   204         importSimItem.setEnabled(false);
       
   205     }
       
   206     else if (!(mAdnEntriesPresent || mSdnStorePresent))
       
   207     {
       
   208         // Sim card is present
       
   209         // No ADN entries are there
       
   210         // no SDN entries are there
       
   211         simList << simImport << simNoContacts;
       
   212         importSimItem.setEnabled(false);
       
   213     }
       
   214     else
       
   215     {   
       
   216         // SIM card is present
       
   217         //ADN entries or SDN entries are there
       
   218         simList << simImport;
       
   219         int error = 0;
       
   220         QDateTime date = mAdnSimUtility->getLastImportTime(error);
       
   221         if (error == 0) {
       
   222             HbExtendedLocale locale = HbExtendedLocale::system();
       
   223             QString dateStr = locale.format(date.date(), r_qtn_date_usual);
       
   224             QString dateStrLocaleDigits = HbStringUtil::convertDigits(dateStr); 
       
   225             QString dateStrFull = 
       
   226                 HbParameterLengthLimiter(hbTrId("txt_phob_dblist_import_from_1_val_updated_1")).arg(dateStrLocaleDigits);
       
   227             simList << dateStrFull;
       
   228         }
       
   229     }
       
   230     CNT_EXIT
       
   231 }
       
   232 
       
   233 bool CntSimEngine::startSimImport()
       
   234 {
       
   235     CNT_ENTRY
       
   236     bool started = false;
       
   237     mImportInProgress = true;
       
   238     mSaveCount = 0;
       
   239 
       
   240     delete mFetchRequestADN;
       
   241     mContactSimManagerADN = &mAbsEngine->contactManager(SIM_BACKEND_ADN);
       
   242     mFetchRequestADN = new QContactFetchRequest;
       
   243     mFetchRequestADN->setManager(mContactSimManagerADN);   
       
   244     
       
   245     delete mFetchRequestSDN;
       
   246     mContactSimManagerSDN = &mAbsEngine->contactManager(SIM_BACKEND_SDN);
       
   247     mFetchRequestSDN = new QContactFetchRequest;
       
   248     mFetchRequestSDN->setManager(mContactSimManagerSDN);        
       
   249         
       
   250     if (mWaitingForAdnCache)
       
   251     {
       
   252         //show progress dialog and wait when ADN cache is ready
       
   253         started = true;
       
   254     }
       
   255     else
       
   256     {
       
   257         if(mAdnStorePresent)
       
   258         {
       
   259             connect(mFetchRequestADN, SIGNAL(resultsAvailable()), this, SLOT(importADNFetchResults()));
       
   260         }
       
   261       
       
   262         if(mSdnStorePresent)
       
   263         {
       
   264             connect(mFetchRequestSDN, SIGNAL(resultsAvailable()), this, SLOT(importSDNFetchResults()));
       
   265         }
       
   266         
       
   267         if(mAdnEntriesPresent > 0 && mContactSimManagerADN->error() == QContactManager::NoError) 
       
   268         {
       
   269             // ADN contacts are there, start fetch
       
   270             mFetchRequestADN->start();
       
   271             started = true;
       
   272         }
       
   273         else if (mSdnStorePresent && mContactSimManagerSDN->error() == QContactManager::NoError)        
       
   274         {
       
   275             //start fetch of SDN contacts since ADN contacts are not there
       
   276             mFetchRequestSDN->start();
       
   277             started = true;
       
   278         }
       
   279     }
       
   280     CNT_EXIT
       
   281     return started;
       
   282 }  
       
   283 
       
   284 
       
   285 void CntSimEngine::stopSimImport()
       
   286 {
       
   287     CNT_ENTRY    
       
   288     if(mImportInProgress)
       
   289     {
       
   290         emit closePopup();            
       
   291         mImportInProgress = false;
       
   292         if (mFetchIsDone)
       
   293         {
       
   294             // indicates that timer has been started
       
   295             killTimer(mTimerId);
       
   296         }
       
   297         mSaveSimContactsList.clear(); 
       
   298         mSaveSimContactsListSDN.clear(); 
       
   299         
       
   300         showSimImportResults();
       
   301         
       
   302         if (mFetchRequestADN != NULL)
       
   303         {
       
   304             mFetchRequestADN->cancel();
       
   305         }
       
   306         if (mFetchRequestSDN != NULL)
       
   307         {
       
   308             mFetchRequestSDN->cancel();
       
   309         }
       
   310         
       
   311         // save import time
       
   312         int error = 0;
       
   313         mAdnSimUtility->setLastImportTime(error);
       
   314         
       
   315         //update sim import row with last import time
       
   316         if (error == 0)
       
   317         {
       
   318             QDateTime date = mAdnSimUtility->getLastImportTime(error);
       
   319             if (error == 0)
       
   320             {
       
   321                 QString simImport(hbTrId("txt_phob_dblist_import_from_sim"));
       
   322                 
       
   323                 HbExtendedLocale locale = HbExtendedLocale::system();
       
   324                 QString dateStr = locale.format(date.date(), r_qtn_date_usual);
       
   325                 QString dateStrLocaleDigits = HbStringUtil::convertDigits(dateStr);
       
   326                 QString dateStrFull = 
       
   327                     HbParameterLengthLimiter(hbTrId("txt_phob_dblist_import_from_1_val_updated_1")).arg(dateStrLocaleDigits);
       
   328                 //simList << dateStrFull;
       
   329                 
       
   330                 mImportViewCallback.setListBoxItemText(simImport, dateStrFull);
       
   331             }
       
   332         }
       
   333     }
       
   334     
       
   335     CNT_EXIT
       
   336 }
       
   337 
       
   338 void CntSimEngine::timerEvent(QTimerEvent *event)
       
   339 {
       
   340     CNT_ENTRY
       
   341     Q_UNUSED(event);
       
   342     if (!(mSaveCount >= mSaveSimContactsList.count())) // while mSaveCount is less than or equal to mSaveSimContactsList.count()
       
   343     {
       
   344         QContact unSavedContact = mSaveSimContactsList.at(mSaveCount);
       
   345         mContactSymbianManager->saveContact(&unSavedContact);
       
   346         mSaveCount++;
       
   347         //use another counter to check number of actual saved if saveContact() fails
       
   348     }
       
   349     else
       
   350     {
       
   351         // saving complete
       
   352         killTimer(mTimerId);
       
   353         mSaveSimContactsList.clear();
       
   354         
       
   355         // ADN contacts fetching and saving is done
       
   356         // Now start SDN fetching and save
       
   357         fetchSDNContacts();
       
   358     }
       
   359     CNT_EXIT
       
   360 }
       
   361 
       
   362 
       
   363 void CntSimEngine::importADNFetchResults()
       
   364 {
       
   365     CNT_ENTRY
       
   366     //save import time
       
   367     int error = 0;
       
   368     mAdnSimUtility->setLastImportTime(error);
       
   369 
       
   370     QList<QContact> simContactsList = mFetchRequestADN->contacts();
       
   371     if (simContactsList.isEmpty())
       
   372     {
       
   373         // No sim contacts, jump to fetching SDN contacts
       
   374         fetchSDNContacts();
       
   375     }
       
   376     else
       
   377     {
       
   378         // save ADN contacts
       
   379     
       
   380         int count = simContactsList.count();
       
   381         foreach(QContact contact, simContactsList) 
       
   382         {
       
   383             if (contact.localId() > 0) 
       
   384             {
       
   385             //delete local id before saving to different storage
       
   386                QScopedPointer<QContactId> contactId(new QContactId());
       
   387                contactId->setLocalId(0);
       
   388                contactId->setManagerUri(QString());
       
   389                contact.setId(*contactId);
       
   390     
       
   391                // custom label contains name information, save it to the first name 
       
   392                QList<QContactDetail> names = contact.details(QContactName::DefinitionName);
       
   393                if (names.count() > 0) 
       
   394                {
       
   395                    QContactName name = static_cast<QContactName>(names.at(0));
       
   396                    name.setFirstName(name.customLabel());
       
   397                    name.setCustomLabel(QString());
       
   398                    contact.saveDetail(&name);
       
   399                }
       
   400                  
       
   401                //update phone numbers to contain default subtype
       
   402                QList<QContactDetail> numbers = contact.details(QContactPhoneNumber::DefinitionName);
       
   403                for (int i = 0; i < numbers.count(); i++) 
       
   404                {
       
   405                    QContactPhoneNumber number = static_cast<QContactPhoneNumber>(numbers.at(i));
       
   406                    number.setSubTypes(QContactPhoneNumber::SubTypeMobile);
       
   407                    contact.saveDetail(&number);
       
   408                }
       
   409                
       
   410                //remove sync target details, it's read-only. 
       
   411                 QList<QContactDetail> syncTargets = contact.details(QContactSyncTarget::DefinitionName);
       
   412                 for (int j = 0; j < syncTargets.count(); j++) 
       
   413                 {
       
   414                     QContactSyncTarget syncTarget = static_cast<QContactSyncTarget>(syncTargets.at(j));
       
   415                     contact.removeDetail(&syncTarget);
       
   416                 }
       
   417                
       
   418                contact.setType(QContactType::TypeContact);
       
   419                setPreferredDetails(contact);
       
   420                mSaveSimContactsList.append(contact);
       
   421                 
       
   422             }
       
   423         }
       
   424         // save the list synchronously because async cancelling of save request is  
       
   425         // not supported in symbian backend at the time of this implementation
       
   426         
       
   427         if (!(mSaveSimContactsList.isEmpty()))
       
   428         {
       
   429             // indicates that there is one or more sim contact that has been fetched
       
   430             // create a timer and start saving synchronously one by one
       
   431             // when cancel is pressed, kill the timer
       
   432             
       
   433             mTimerId = startTimer(KTimerValue); // starting a 1 msec timer
       
   434             mFetchIsDone = true;
       
   435             mSaveCount = 0;    
       
   436         }
       
   437     }
       
   438     CNT_EXIT
       
   439 }
       
   440 
       
   441 void CntSimEngine::importSDNFetchResults()
       
   442 {
       
   443     CNT_ENTRY
       
   444     //save import time
       
   445     int error = 0;
       
   446     mAdnSimUtility->setLastImportTime(error);
       
   447 
       
   448     QList<QContact> simContactsListSDN = mFetchRequestSDN->contacts();
       
   449     if (simContactsListSDN.isEmpty())
       
   450     {
       
   451         //No sdn contacts present
       
   452         showSimImportResults();
       
   453         mSaveSimContactsListSDN.clear(); 
       
   454         emit closePopup();
       
   455         mImportInProgress = false;
       
   456         // Importing finished, go back to NamesView
       
   457         emit showNamesView();
       
   458         //showPreviousView();
       
   459     }
       
   460     else
       
   461     {
       
   462     // SAVE SDN CONTACTS
       
   463         int count = simContactsListSDN.count();
       
   464         foreach(QContact contact, simContactsListSDN) 
       
   465         {
       
   466             if (contact.localId() > 0) 
       
   467             {
       
   468             //delete local id before saving to different storage
       
   469                QScopedPointer<QContactId> contactId(new QContactId());
       
   470                contactId->setLocalId(0);
       
   471                contactId->setManagerUri(QString());
       
   472                contact.setId(*contactId);
       
   473     
       
   474                //custom label contains name information, save it to the first name 
       
   475               QList<QContactDetail> names = contact.details(QContactName::DefinitionName);
       
   476               if (names.count() > 0) 
       
   477               {
       
   478                   QContactName name = static_cast<QContactName>(names.at(0));
       
   479                   name.setFirstName(name.customLabel());
       
   480                   name.setCustomLabel(QString());
       
   481                   contact.saveDetail(&name);
       
   482               }
       
   483                 
       
   484               //update phone numbers to contain default subtype
       
   485               QList<QContactDetail> numbers = contact.details(QContactPhoneNumber::DefinitionName);
       
   486               for (int i = 0; i < numbers.count(); i++) 
       
   487               {
       
   488                   QContactPhoneNumber number = static_cast<QContactPhoneNumber>(numbers.at(i));
       
   489                   number.setSubTypes(QContactPhoneNumber::SubTypeMobile);
       
   490                   contact.saveDetail(&number);
       
   491               }
       
   492               
       
   493               //remove sync target details, it's read-only. 
       
   494               QList<QContactDetail> syncTargets = contact.details(QContactSyncTarget::DefinitionName);
       
   495               for (int j = 0; j < syncTargets.count(); j++) 
       
   496               {
       
   497                   QContactSyncTarget syncTarget = static_cast<QContactSyncTarget>(syncTargets.at(j));
       
   498                   contact.removeDetail(&syncTarget);
       
   499               }
       
   500               
       
   501                contact.setType(QContactType::TypeContact);
       
   502                setPreferredDetails(contact);
       
   503                mSaveSimContactsListSDN.append(contact);
       
   504                 
       
   505             }
       
   506         }
       
   507         // save the list synchronously because async cancelling of save request is  
       
   508         // not supported in symbian backend at the time of this implementation
       
   509         
       
   510         if (!(mSaveSimContactsListSDN.isEmpty()))
       
   511         {
       
   512             // indicates that there is one or more SDN sim contact that has been fetched
       
   513             QMap<int, QContactManager::Error> errorMap;
       
   514             mContactSymbianManager->saveContacts(&mSaveSimContactsListSDN,&errorMap);
       
   515             // check number of contacts really saved
       
   516             mSaveCount = mSaveCount + mSaveSimContactsListSDN.count();
       
   517         }
       
   518         
       
   519         // no more SDN contacts to fetch
       
   520         showSimImportResults();
       
   521         mSaveSimContactsListSDN.clear(); 
       
   522         emit closePopup();
       
   523         mImportInProgress = false;
       
   524         // Importing finished, go back to NamesView
       
   525         emit showNamesView();
       
   526         //showPreviousView();
       
   527     }   
       
   528     CNT_EXIT
       
   529 }
       
   530 
       
   531 void CntSimEngine::setPreferredDetails(QContact& aContact )
       
   532 {
       
   533     CNT_ENTRY
       
   534     QList<QContactPhoneNumber> numberList( aContact.details<QContactPhoneNumber>() );
       
   535     //set preferred number for call if there is only one phone number
       
   536     if ( aContact.preferredDetail("call").isEmpty() && numberList.count() == 1 )
       
   537     {
       
   538         aContact.setPreferredDetail( "call", numberList.first() );
       
   539     }
       
   540     //set preferred number for message if there is only one mobile phone number
       
   541     if ( aContact.preferredDetail("message").isEmpty() && numberList.count() == 1 )
       
   542     {      
       
   543         aContact.setPreferredDetail( "message", numberList.first() );
       
   544     }
       
   545     //set preferred number for message if there is only one email address
       
   546     QList<QContactEmailAddress> emailList( aContact.details<QContactEmailAddress>() );
       
   547     if ( aContact.preferredDetail("email").isEmpty() && emailList.count() == 1 )
       
   548     {      
       
   549         aContact.setPreferredDetail( "email", emailList.first() );
       
   550     }
       
   551     CNT_EXIT
       
   552 }
       
   553 
       
   554 void CntSimEngine::showSimImportResults() const
       
   555 {   
       
   556     CNT_ENTRY
       
   557     QString results = hbTrId("txt_phob_dpophead_ln_contacts_imported").arg(mSaveCount).arg(mAdnStoreEntries + mSdnStoreEntries);
       
   558     HbNotificationDialog::launchDialog(results);
       
   559     CNT_EXIT
       
   560 }
       
   561 
       
   562 void CntSimEngine::fetchSDNContacts()
       
   563 {
       
   564     CNT_ENTRY
       
   565    if (mSdnStorePresent && mContactSimManagerSDN->error() == QContactManager::NoError)
       
   566     {
       
   567         mFetchRequestSDN->start();
       
   568     }
       
   569     else
       
   570     {
       
   571         // no SDN contacts to fetch
       
   572         showSimImportResults();
       
   573         emit closePopup();
       
   574         mImportInProgress = false;
       
   575         // Importing finished, go back to NamesView
       
   576         
       
   577         //showPreviousView();
       
   578         emit showNamesView();
       
   579     }
       
   580     CNT_EXIT
       
   581 }
       
   582 
       
   583 
       
   584 void CntSimEngine::getSimInfoAndUpdateUI(CntSimUtility::CacheStatus& cacheStatus, int error)
       
   585 {
       
   586     CNT_ENTRY
       
   587     mWaitingForAdnCache = false;
       
   588     //update ADN store info...
       
   589     if (error != KErrNone || cacheStatus == CntSimUtility::ECacheFailed)
       
   590     {
       
   591         mAdnStorePresent = false;
       
   592         mAdnEntriesPresent = false;
       
   593         mSdnStorePresent = false;
       
   594     }
       
   595     else
       
   596     {
       
   597         //check if there are ADN contacts
       
   598         mAdnStorePresent = true;
       
   599         mAdnEntriesPresent = false;
       
   600         int getSimInfoError = -1;
       
   601         CntSimUtility::SimInfo simInfo = mAdnSimUtility->getSimInfo(getSimInfoError);
       
   602         if (!getSimInfoError)
       
   603         {
       
   604             // sim entries are present
       
   605             mAdnStoreEntries = simInfo.usedEntries;
       
   606             if (mAdnStoreEntries > 0) 
       
   607             { 
       
   608                 mAdnEntriesPresent = true;
       
   609             }
       
   610         }
       
   611         
       
   612         //get number of SDN contacts
       
   613         int sdnError = -1;
       
   614         mSdnStorePresent = false;
       
   615         if (!mSdnSimUtility)
       
   616         {
       
   617             mSdnSimUtility = new CntSimUtility(CntSimUtility::SdnStore, sdnError);
       
   618             if (sdnError != 0) 
       
   619             {
       
   620                 delete mSdnSimUtility; 
       
   621                 mSdnSimUtility = 0;
       
   622             }
       
   623         }
       
   624         if (mSdnSimUtility)
       
   625         {
       
   626             int getSdnSimInfoError = 0;
       
   627             CntSimUtility::SimInfo sdnSimInfo = mSdnSimUtility->getSimInfo(getSdnSimInfoError);
       
   628             if (!getSdnSimInfoError)
       
   629             {
       
   630                 mSdnStoreEntries = sdnSimInfo.usedEntries;
       
   631                 if (mSdnStoreEntries > 0)
       
   632                 {
       
   633                     mSdnStorePresent = true;    
       
   634                 }
       
   635             }
       
   636         }
       
   637     }
       
   638     
       
   639     //dismiss progress dialog, if there are no SIM contacts 
       
   640     if(!mAdnEntriesPresent && !mSdnStorePresent)
       
   641     {
       
   642         emit closePopup();
       
   643         showSimImportResults();
       
   644     }
       
   645     
       
   646     //disable sim import item, if there are no SIM contacts 
       
   647     if(!mAdnEntriesPresent && !mSdnStorePresent)
       
   648     {
       
   649         QString simImport(hbTrId("txt_phob_dblist_import_from_sim"));
       
   650         QString simNoContacts(hbTrId("txt_phob_dblist_import_from_1_val_no_sim_contacts"));
       
   651         
       
   652         mImportViewCallback.setListBoxItemText(simImport, simNoContacts);
       
   653         mImportViewCallback.setListBoxItemEnabled(false);     
       
   654     }
       
   655     
       
   656     //start SIM contacts import, if user tapped "SIM import"
       
   657 //    if(mImportSimPopup != NULL && mImportSimPopup->isActive())
       
   658 //    {
       
   659         if (!startSimImport())
       
   660         {
       
   661             //dismiss wait note
       
   662             emit closePopup();
       
   663             mImportInProgress = false;
       
   664             //and show error note
       
   665             simInfoErrorMessage(KErrAccessDenied);
       
   666         }
       
   667  //   }
       
   668         CNT_EXIT
       
   669 }
       
   670 
       
   671 void CntSimEngine::simInfoErrorMessage(int infoError)
       
   672 {
       
   673     CNT_ENTRY
       
   674     Q_UNUSED(infoError);
       
   675     QString errorMessage;
       
   676     errorMessage.append(hbTrId("txt_phob_info_sim_card_error"));
       
   677     HbNotificationDialog::launchDialog(errorMessage);
       
   678     mSimError = true;
       
   679     CNT_EXIT
       
   680 }
       
   681 
       
   682 bool CntSimEngine::userCancelsImport(QString& aResults)
       
   683 {   
       
   684     CNT_ENTRY
       
   685     aResults = "";
       
   686     
       
   687     bool boolResult = mImportInProgress && !mSimError;
       
   688     
       
   689     if(boolResult)
       
   690     {
       
   691         aResults = hbTrId("txt_phob_dpophead_ln_contacts_imported").arg(mSaveCount).arg(mAdnStoreEntries + mSdnStoreEntries);
       
   692     }
       
   693     mImportInProgress = false;
       
   694     CNT_EXIT
       
   695     return boolResult;
       
   696 }
       
   697 
       
   698 
       
   699 
       
   700