qtcontactsmobility/plugins/contacts/symbian/src/cntdisplaylabel.cpp
changeset 37 fd64c38c277d
parent 27 de1630741fbe
child 40 b46a585f6909
equal deleted inserted replaced
31:2a11b5b00470 37:fd64c38c277d
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include "cntdisplaylabel.h"
    42 #include "cntdisplaylabel.h"
    43 #include <qtcontacts.h>
    43 #include <qtcontacts.h>
       
    44 #include <centralrepository.h>
       
    45 #include <cntcenrepkeys.h>
       
    46 
       
    47 const TUint32 KOrderLastFirst = 0x00000000;
       
    48 const TUint32 KOrderLastCommaFirst = 0x00000001;
       
    49 const TUint32 KOrderFirstLast = 0x00000002;
    44 
    50 
    45 /*! 
    51 /*! 
    46  * Constructor
    52  * Constructor
    47  */
    53  */
    48 
    54 
    49 CntDisplayLabel::CntDisplayLabel()
    55 CntDisplayLabel::CntDisplayLabel() :
    50 {
    56     m_nameOrder(KOrderFirstLast)
       
    57 {
       
    58 #ifdef SYMBIAN_BACKEND_USE_SQLITE
       
    59     CRepository* cenrep;
       
    60     TRAPD(err, cenrep = CRepository::NewL(KCRUiContacts));
       
    61     if (err == KErrNone) {
       
    62         TInt value(-1);
       
    63         if (cenrep->Get(KNameOrdering, value) == KErrNone) {
       
    64             m_nameOrder = static_cast<int>(value);
       
    65         }
       
    66     }
       
    67 #endif
    51     setDisplayLabelDetails();
    68     setDisplayLabelDetails();
    52 }
    69 }
    53 
    70 
    54 /*! 
    71 /*! 
    55  * Destructor
    72  * Destructor
    72 
    89 
    73     //Display label details
    90     //Display label details
    74     //Contact
    91     //Contact
    75     //Preferred details
    92     //Preferred details
    76     QList<QPair<QLatin1String, QLatin1String> > contactPrefferedDisplayLabelDetails;
    93     QList<QPair<QLatin1String, QLatin1String> > contactPrefferedDisplayLabelDetails;
    77     contactPrefferedDisplayLabelDetails.append(qMakePair(QLatin1String(QContactName::DefinitionName), QLatin1String(QContactName::FieldFirstName)));
    94     QLatin1String firstLatin(QContactName::FieldFirstName);
    78     contactPrefferedDisplayLabelDetails.append(qMakePair(QLatin1String(QContactName::DefinitionName), QLatin1String(QContactName::FieldLastName)));
    95     QLatin1String secondLatin(QContactName::FieldLastName);
       
    96     
       
    97     if (m_nameOrder == KOrderLastFirst || m_nameOrder == KOrderLastCommaFirst) {
       
    98         firstLatin = QLatin1String(QContactName::FieldLastName);
       
    99         secondLatin = QLatin1String(QContactName::FieldFirstName);
       
   100     }
       
   101 
       
   102     contactPrefferedDisplayLabelDetails.append(qMakePair(QLatin1String(QContactName::DefinitionName), firstLatin));
       
   103     contactPrefferedDisplayLabelDetails.append(qMakePair(QLatin1String(QContactName::DefinitionName), secondLatin));
    79     m_contactDisplayLabelDetails.append(contactPrefferedDisplayLabelDetails);
   104     m_contactDisplayLabelDetails.append(contactPrefferedDisplayLabelDetails);
    80 
   105 
    81     //if preferred details doesn't exist use these
   106     //if preferred details doesn't exist use these
    82     QList<QPair<QLatin1String, QLatin1String> > contactSecondaryDisplayLabelDetails;
   107     QList<QPair<QLatin1String, QLatin1String> > contactSecondaryDisplayLabelDetails;
    83     contactSecondaryDisplayLabelDetails.append(qMakePair(QLatin1String(QContactOrganization::DefinitionName), QLatin1String(QContactOrganization::FieldName)));
   108     contactSecondaryDisplayLabelDetails.append(qMakePair(QLatin1String(QContactOrganization::DefinitionName), QLatin1String(QContactOrganization::FieldName)));
   144             else{ //read the value and append it to the display label
   169             else{ //read the value and append it to the display label
   145                 QString label = contactDetail.value(detailPairList.at(j).second);
   170                 QString label = contactDetail.value(detailPairList.at(j).second);
   146                 
   171                 
   147                 if(!label.isEmpty())
   172                 if(!label.isEmpty())
   148                 {
   173                 {
   149                     displayLabel.append(delimiter());
   174                     // Inlcude a comma if needed in the display label
       
   175                     if (m_nameOrder == KOrderLastCommaFirst)
       
   176                         displayLabel.append(comma());
       
   177                     displayLabel.append(delimiter());                        
   150                     displayLabel.append(label);
   178                     displayLabel.append(label);
   151                 }  
   179                 }
   152             }
   180             }
   153         }
   181         }
   154     }
   182     }
   155 
   183 
   156     //no display label, set default value
   184     //no display label, set default value
   194  */
   222  */
   195 QList<QPair<QLatin1String, QLatin1String> > CntDisplayLabel::groupFilterDetails() const
   223 QList<QPair<QLatin1String, QLatin1String> > CntDisplayLabel::groupFilterDetails() const
   196 {
   224 {
   197     return m_groupDisplayLabelDetails.at(0);
   225     return m_groupDisplayLabelDetails.at(0);
   198 }
   226 }
       
   227 
       
   228 /*! 
       
   229  * Comma to be used in display label
       
   230  * \return comma
       
   231  */
       
   232 QString CntDisplayLabel::comma() const
       
   233 {
       
   234     return ",";
       
   235 }