phonebookui/phonebookservices/src/cntservices.cpp
changeset 81 640d30f4fb64
parent 72 6abfb1094884
equal deleted inserted replaced
77:c18f9fa7f42e 81:640d30f4fb64
    34 
    34 
    35 #include <QApplication>
    35 #include <QApplication>
    36 #include <QPixmap>
    36 #include <QPixmap>
    37 #include <QFile>
    37 #include <QFile>
    38 #include <QUrl>
    38 #include <QUrl>
    39 #include <QTextCodec>
       
    40 
       
    41 const int Latin1CharSetMIB = 4;
       
    42 
    39 
    43 CntServices::CntServices() :
    40 CntServices::CntServices() :
    44 mViewManager(NULL),
    41 mViewManager(NULL),
    45 mCurrentProvider(NULL)
    42 mCurrentProvider(NULL)
    46 {
    43 {
   181     mCurrentProvider = &aServiceProvider;
   178     mCurrentProvider = &aServiceProvider;
   182 
   179 
   183     CntImageUtility imageUtility;
   180     CntImageUtility imageUtility;
   184     QContact contact;
   181     QContact contact;
   185     QVersitReader reader;
   182     QVersitReader reader;
   186     QFile inputFile(fileName);
       
   187     if (!inputFile.open(QIODevice::ReadOnly))
       
   188         return;
       
   189     
       
   190     // Versit parser default codec is UTF-8
       
   191     // Check if decoding text to unicode is possible, else use Latin-1 text codec
       
   192     QByteArray ba = inputFile.readAll();
       
   193     if(!ba.isEmpty())
       
   194         {
       
   195         QTextCodec *c = QTextCodec::codecForUtfText(ba);
       
   196         // Text codec returned is Latin-1, set default to Latin-1
       
   197         if(c->mibEnum()==Latin1CharSetMIB)
       
   198             reader.setDefaultCodec(QTextCodec::codecForName("ISO 8859-1"));
       
   199         }
       
   200     inputFile.close();
       
   201     
       
   202     QFile vCardFile(fileName);
   183     QFile vCardFile(fileName);
   203     if (!vCardFile.open(QIODevice::ReadOnly))
   184     if (!vCardFile.open(QIODevice::ReadOnly))
   204         return;
   185         return;
   205     reader.setDevice(&vCardFile);
   186     reader.setDevice(&vCardFile);
   206     reader.startReading();
   187     reader.startReading();
   214         QList<QContact> contacts = importer.contacts();
   195         QList<QContact> contacts = importer.contacts();
   215         if(contacts.count() > 0)
   196         if(contacts.count() > 0)
   216             contact = contacts.first();
   197             contact = contacts.first();
   217         }
   198         }
   218     vCardFile.close();
   199     vCardFile.close();
   219     
       
   220     // check if the contact is in db already.
       
   221     updateLocalId( contact );
       
   222     
   200     
   223     // Save thumbnail images
   201     // Save thumbnail images
   224     QList<QContactThumbnail> details = contact.details<QContactThumbnail>();
   202     QList<QContactThumbnail> details = contact.details<QContactThumbnail>();
   225     for (int i = 0;i < details.count();i++)
   203     for (int i = 0;i < details.count();i++)
   226         {
   204         {
   497     CNT_EXIT
   475     CNT_EXIT
   498 }
   476 }
   499 
   477 
   500 void CntServices::fillOnlineAccount( QContactOnlineAccount& account, const QString& value,
   478 void CntServices::fillOnlineAccount( QContactOnlineAccount& account, const QString& value,
   501     const QString& subType, bool defaultForOnlineAccountIsImpp )
   479     const QString& subType, bool defaultForOnlineAccountIsImpp )
   502     {
   480 {
   503         // The value should normally consist of two parts:
   481     // The value should normally consist of two parts:
   504         //    <service provider>:<user ID>
   482     //    <service provider>:<user ID>
   505         // for eg. "serviceprovider:jack@serviceprovider.com"
   483     // for eg. "serviceprovider:jack@serviceprovider.com"
   506         QStringList accountDetails = value.split(":");
   484     QStringList accountDetails = value.split(":");
   507         if (accountDetails.count() == 1)
   485     if (accountDetails.count() == 1)
   508         {
   486     {
   509             // For some reason it only had one part, so we're assuming it's the user ID.
   487         // For some reason it only had one part, so we're assuming it's the user ID.
   510             account.setAccountUri(accountDetails.at(0));
   488         account.setAccountUri(accountDetails.at(0));
   511         }
   489     }
   512         else if (accountDetails.count() >= 2)
   490     else if (accountDetails.count() >= 2)
   513         {
   491     {
   514             account.setServiceProvider(accountDetails.at(0));        
   492         account.setServiceProvider(accountDetails.at(0));        
   515             account.setAccountUri(accountDetails.at(1)); // the user ID
   493         account.setAccountUri(accountDetails.at(1)); // the user ID
   516         }
   494     }
   517 
   495 
   518         if (!subType.isEmpty())
   496     if (!subType.isEmpty())
   519         {        
   497     {        
   520             account.setSubTypes(subType);
   498         account.setSubTypes(subType);
       
   499     }
       
   500     else
       
   501     {
       
   502         if (defaultForOnlineAccountIsImpp)
       
   503         {
       
   504             account.setSubTypes( QContactOnlineAccount::SubTypeImpp );
   521         }
   505         }
   522         else
   506         else
   523         {
   507         {
   524             if (defaultForOnlineAccountIsImpp)
   508             account.setSubTypes( QContactOnlineAccount::SubTypeSipVoip );
   525             {
   509         }
   526                 account.setSubTypes( QContactOnlineAccount::SubTypeImpp );
   510     }
   527             }
   511 }
   528             else
   512 
   529             {
       
   530                 account.setSubTypes( QContactOnlineAccount::SubTypeSipVoip );
       
   531             }
       
   532         }
       
   533     }
       
   534 
       
   535 void CntServices::updateLocalId( QContact& aContact )
       
   536 {
       
   537     CNT_ENTRY
       
   538     if ( aContact.localId() == 0 )
       
   539         {
       
   540         QContactGuid guid = aContact.detail<QContactGuid>();
       
   541         QString guidString = guid.guid();
       
   542             
       
   543         QContactDetailFilter filter;
       
   544         filter.setDetailDefinitionName( QContactGuid::DefinitionName, QContactGuid::FieldGuid );
       
   545         filter.setValue( guid.guid() );
       
   546             
       
   547         QContactManager& cm = mEngine->contactManager( SYMBIAN_BACKEND );
       
   548         QList<QContactLocalId> idList = cm.contactIds( filter, QList<QContactSortOrder>() );
       
   549         int count = idList.count();
       
   550         
       
   551         if ( !idList.isEmpty() )
       
   552             {
       
   553             QContactId id;
       
   554             id.setLocalId( idList.first() );
       
   555             id.setManagerUri( cm.managerUri() );
       
   556             
       
   557             aContact.setId( id );
       
   558             }
       
   559         }
       
   560     CNT_EXIT
       
   561 }
       
   562 // This method is inherited from CntAbstractServiceProvider
   513 // This method is inherited from CntAbstractServiceProvider
   563 void CntServices::CompleteServiceAndCloseApp(const QVariant& retValue)
   514 void CntServices::CompleteServiceAndCloseApp(const QVariant& retValue)
   564 {
   515 {
   565     CNT_ENTRY
   516     CNT_ENTRY
   566     if (  mCurrentProvider )
   517     if (  mCurrentProvider )