phonebookui/pbkcommonui/src/cntdetailorderinghelper.cpp
changeset 46 efe85016a067
child 61 d30183af6ca6
equal deleted inserted replaced
40:b46a585f6909 46:efe85016a067
       
     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 "cntdetailorderinghelper.h"
       
    19 
       
    20 /**
       
    21 * Return ordered list of supported (by UI implementation) phone numbers
       
    22 *
       
    23 * @param QContact&, contact
       
    24 * @return QList<QContactPhoneNumber>, ordered list of supported phone numbers
       
    25 */    
       
    26 QList<QContactPhoneNumber> CntDetailOrderingHelper::getOrderedSupportedPhoneNumbers( const QContact& contact )
       
    27 {
       
    28     QMap<QPair<QString, QString>, int> orderMap;
       
    29     
       
    30     QPair<QString, QString> pair = qMakePair(QContactPhoneNumber::SubTypeMobile.operator QString(), QString(""));
       
    31     orderMap.insert(pair , EMobile);
       
    32     pair = qMakePair(QContactPhoneNumber::SubTypeMobile.operator QString(), QContactPhoneNumber::ContextHome.operator QString());
       
    33     orderMap.insert(pair , EMobileHome);
       
    34     pair = qMakePair(QContactPhoneNumber::SubTypeMobile.operator QString(), QContactPhoneNumber::ContextWork.operator QString());
       
    35     orderMap.insert(pair , EMobileWork);
       
    36     
       
    37     pair = qMakePair(QContactPhoneNumber::SubTypeLandline.operator QString(), QString(""));
       
    38     orderMap.insert(pair , EPhone);
       
    39     pair = qMakePair(QContactPhoneNumber::SubTypeLandline.operator QString(), QContactPhoneNumber::ContextHome.operator QString());
       
    40     orderMap.insert(pair , EPhoneHome);
       
    41     pair = qMakePair(QContactPhoneNumber::SubTypeLandline.operator QString(), QContactPhoneNumber::ContextWork.operator QString());
       
    42     orderMap.insert(pair , EPhoneWork);
       
    43     
       
    44     pair = qMakePair(QContactPhoneNumber::SubTypeFax.operator QString(), QString(""));
       
    45     orderMap.insert(pair , EFax);
       
    46     pair = qMakePair(QContactPhoneNumber::SubTypeFax.operator QString(), QContactPhoneNumber::ContextHome.operator QString());
       
    47     orderMap.insert(pair , EFaxHome);
       
    48     pair = qMakePair(QContactPhoneNumber::SubTypeFax.operator QString(), QContactPhoneNumber::ContextWork.operator QString());
       
    49     orderMap.insert(pair , EFaxWork);
       
    50     
       
    51     pair = qMakePair(QContactPhoneNumber::SubTypePager.operator QString(), QString(""));
       
    52     orderMap.insert(pair , EPager);
       
    53     pair = qMakePair(QContactPhoneNumber::SubTypeAssistant.operator QString(), QString(""));
       
    54     orderMap.insert(pair , EAssistant);
       
    55     pair = qMakePair(QContactPhoneNumber::SubTypeCar.operator QString(), QString(""));
       
    56     orderMap.insert(pair , ECar);
       
    57     
       
    58     QList<QContactPhoneNumber> completeList = contact.details<QContactPhoneNumber>();
       
    59     QList<QContactPhoneNumber> orderedSupportedList;
       
    60     
       
    61     foreach ( QContactPhoneNumber number, completeList )
       
    62     {
       
    63         QString context = number.contexts().isEmpty() ? QString() : number.contexts().first();
       
    64         QString subtype = number.subTypes().isEmpty() ? number.definitionName() : number.subTypes().first();
       
    65         
       
    66         QPair<QString, QString> pair = qMakePair(subtype, context);
       
    67         
       
    68         if ( orderMap.keys().contains(pair) )
       
    69         {
       
    70             int position = orderMap.value(pair);
       
    71             bool added = false;
       
    72             
       
    73             for (int i = 0; i < orderedSupportedList.count(); i++)
       
    74             {
       
    75                 QString currentContext = orderedSupportedList.at(i).contexts().isEmpty() ? 
       
    76                         QString() : orderedSupportedList.at(i).contexts().first();
       
    77                 
       
    78                 // this is safe because no details without a subtype can be in the list
       
    79                 QString currentSubtype = orderedSupportedList.at(i).subTypes().first();
       
    80                 
       
    81                 QPair<QString, QString> currentPair = qMakePair(currentSubtype, currentContext);
       
    82                 
       
    83                 int currentPosition = orderMap.value(currentPair);
       
    84                 
       
    85                 if (currentPosition > position)
       
    86                 {
       
    87                     orderedSupportedList.insert(i, number);
       
    88                     added = true;
       
    89                     break;
       
    90                 }
       
    91             }
       
    92             
       
    93             if (!added)
       
    94             {
       
    95                 orderedSupportedList.append(number);
       
    96             }
       
    97         }
       
    98     }
       
    99     
       
   100     return orderedSupportedList;
       
   101 }
       
   102 
       
   103 /**
       
   104 * Return ordered list of supported (by UI implementation) online accounts
       
   105 *
       
   106 * @param QContact&, contact
       
   107 * @return QList<QContactOnlineAccount>, ordered list of supported online accounts
       
   108 */    
       
   109 QList<QContactOnlineAccount> CntDetailOrderingHelper::getOrderedSupportedOnlineAccounts( const QContact &contact )
       
   110 {
       
   111     QMap<QPair<QString, QString>, int> orderMap;
       
   112     
       
   113     QPair<QString, QString> pair = qMakePair(QContactOnlineAccount::SubTypeSipVoip.operator QString(), QString(""));
       
   114     orderMap.insert(pair , EInternetTelephone);
       
   115     pair = qMakePair(QContactOnlineAccount::SubTypeSipVoip.operator QString(), QContactOnlineAccount::ContextHome.operator QString());
       
   116     orderMap.insert(pair , EInternetTelephoneHome);
       
   117     pair = qMakePair(QContactOnlineAccount::SubTypeSipVoip.operator QString(), QContactOnlineAccount::ContextWork.operator QString());
       
   118     orderMap.insert(pair , EInternetTelephoneWork);
       
   119     
       
   120     pair = qMakePair(QContactOnlineAccount::SubTypeSip.operator QString(), QString(""));
       
   121     orderMap.insert(pair , ESip);
       
   122     
       
   123     QList<QContactOnlineAccount> completeList = contact.details<QContactOnlineAccount>();
       
   124     QList<QContactOnlineAccount> orderedSupportedList;
       
   125     
       
   126     foreach ( QContactOnlineAccount account, completeList )
       
   127     {
       
   128         QString context = account.contexts().isEmpty() ? QString() : account.contexts().first();
       
   129         QString subtype = account.subTypes().isEmpty() ? account.definitionName() : account.subTypes().first();
       
   130         
       
   131         QPair<QString, QString> pair = qMakePair(subtype, context);
       
   132         
       
   133         if ( orderMap.keys().contains(pair) )
       
   134         {
       
   135             int position = orderMap.value(pair);
       
   136             bool added = false;
       
   137             
       
   138             for (int i = 0; i < orderedSupportedList.count(); i++)
       
   139             {
       
   140                 QString currentContext = orderedSupportedList.at(i).contexts().isEmpty() ? 
       
   141                         QString() : orderedSupportedList.at(i).contexts().first();
       
   142                 
       
   143                 // this is safe because no details without a subtype can be in the list
       
   144                 QString currentSubtype = orderedSupportedList.at(i).subTypes().first();
       
   145                 
       
   146                 QPair<QString, QString> currentPair = qMakePair(currentSubtype, currentContext);
       
   147                 
       
   148                 int currentPosition = orderMap.value(currentPair);
       
   149                 
       
   150                 if (currentPosition > position)
       
   151                 {
       
   152                     orderedSupportedList.insert(i, account);
       
   153                     added = true;
       
   154                     break;
       
   155                 }
       
   156             }
       
   157             
       
   158             if (!added)
       
   159             {
       
   160                 orderedSupportedList.append(account);
       
   161             }
       
   162         }
       
   163     }
       
   164     
       
   165     return orderedSupportedList;
       
   166 }
       
   167 
       
   168 /**
       
   169 * Return ordered list of email accounts
       
   170 *
       
   171 * @param QContact&, contact
       
   172 * @return QList<QContactEmailAddress>, ordered list of email accounts
       
   173 */    
       
   174 QList<QContactEmailAddress> CntDetailOrderingHelper::getOrderedEmailAccounts( const QContact &contact )
       
   175 {
       
   176     QMap<QString, int> orderMap;
       
   177     
       
   178     orderMap.insert("" , EEmail);
       
   179     orderMap.insert(QContactEmailAddress::ContextHome , EEmailHome);
       
   180     orderMap.insert(QContactEmailAddress::ContextWork , EEmailWork);
       
   181     
       
   182     QList<QContactEmailAddress> completeList = contact.details<QContactEmailAddress>();
       
   183     QList<QContactEmailAddress> orderedSupportedList;
       
   184     
       
   185     foreach ( QContactEmailAddress email, completeList )
       
   186     {
       
   187         QString context = email.contexts().isEmpty() ? QString() : email.contexts().first();
       
   188         
       
   189         if ( orderMap.keys().contains(context) )
       
   190         {
       
   191             int position = orderMap.value(context);
       
   192             bool added = false;
       
   193             
       
   194             for (int i = 0; i < orderedSupportedList.count(); i++)
       
   195             {
       
   196                 QString currentContext = orderedSupportedList.at(i).contexts().isEmpty() ? 
       
   197                         QString() : orderedSupportedList.at(i).contexts().first();
       
   198                 
       
   199                 int currentPosition = orderMap.value(currentContext);
       
   200                 
       
   201                 if (currentPosition > position)
       
   202                 {
       
   203                     orderedSupportedList.insert(i, email);
       
   204                     added = true;
       
   205                     break;
       
   206                 }
       
   207             }
       
   208             
       
   209             if (!added)
       
   210             {
       
   211                 orderedSupportedList.append(email);
       
   212             }
       
   213         }
       
   214     }
       
   215     
       
   216     return orderedSupportedList;
       
   217 }
       
   218 
       
   219 /**
       
   220 * Return ordered list of url details
       
   221 *
       
   222 * @param QContact&, contact
       
   223 * @return QList<QContactUrl>, ordered list of url details
       
   224 */   
       
   225 QList<QContactUrl> CntDetailOrderingHelper::getOrderedUrls( const QContact &contact )
       
   226 {
       
   227     QMap<QString, int> orderMap;
       
   228     
       
   229     orderMap.insert("" , EUrl);
       
   230     orderMap.insert(QContactUrl::ContextHome , EUrlHome);
       
   231     orderMap.insert(QContactUrl::ContextWork , EUrlWork);
       
   232     
       
   233     QList<QContactUrl> completeList = contact.details<QContactUrl>();
       
   234     QList<QContactUrl> orderedSupportedList;
       
   235     
       
   236     foreach ( QContactUrl url, completeList )
       
   237     {
       
   238         QString context = url.contexts().isEmpty() ? QString() : url.contexts().first();
       
   239         
       
   240         if ( orderMap.keys().contains(context) )
       
   241         {
       
   242             int position = orderMap.value(context);
       
   243             bool added = false;
       
   244             
       
   245             for (int i = 0; i < orderedSupportedList.count(); i++)
       
   246             {
       
   247                 QString currentContext = orderedSupportedList.at(i).contexts().isEmpty() ? 
       
   248                         QString() : orderedSupportedList.at(i).contexts().first();
       
   249                 
       
   250                 int currentPosition = orderMap.value(currentContext);
       
   251                 
       
   252                 if (currentPosition > position)
       
   253                 {
       
   254                     orderedSupportedList.insert(i, url);
       
   255                     added = true;
       
   256                     break;
       
   257                 }
       
   258             }
       
   259             
       
   260             if (!added)
       
   261             {
       
   262                 orderedSupportedList.append(url);
       
   263             }
       
   264         }
       
   265     }
       
   266     
       
   267     return orderedSupportedList;
       
   268 }
       
   269 
       
   270 // EOF