phonebookui/pbkcommonui/src/cntdetailorderinghelper.cpp
changeset 61 d30183af6ca6
parent 46 efe85016a067
--- a/phonebookui/pbkcommonui/src/cntdetailorderinghelper.cpp	Wed Aug 11 09:06:35 2010 +0300
+++ b/phonebookui/pbkcommonui/src/cntdetailorderinghelper.cpp	Mon Aug 23 16:06:28 2010 +0300
@@ -267,4 +267,55 @@
     return orderedSupportedList;
 }
 
+/**
+* Return ordered list of address details
+*
+* @param QContact&, contact
+* @return QList<QContactAddress>, ordered list of address details
+*/   
+QList<QContactAddress> CntDetailOrderingHelper::getOrderedAddresses( const QContact& contact )
+{
+    QMap<QString, int> orderMap;
+    
+    orderMap.insert("" , EAddress);
+    orderMap.insert(QContactAddress::ContextHome , EAddressHome);
+    orderMap.insert(QContactAddress::ContextWork , EAddressWork);
+    
+    QList<QContactAddress> completeList = contact.details<QContactAddress>();
+    QList<QContactAddress> orderedSupportedList;
+    
+    foreach ( QContactAddress address, completeList )
+    {
+        QString context = address.contexts().isEmpty() ? QString() : address.contexts().first();
+        
+        if ( orderMap.keys().contains(context) )
+        {
+            int position = orderMap.value(context);
+            bool added = false;
+            
+            for (int i = 0; i < orderedSupportedList.count(); i++)
+            {
+                QString currentContext = orderedSupportedList.at(i).contexts().isEmpty() ? 
+                        QString() : orderedSupportedList.at(i).contexts().first();
+                
+                int currentPosition = orderMap.value(currentContext);
+                
+                if (currentPosition > position)
+                {
+                    orderedSupportedList.insert(i, address);
+                    added = true;
+                    break;
+                }
+            }
+            
+            if (!added)
+            {
+                orderedSupportedList.append(address);
+            }
+        }
+    }
+    
+    return orderedSupportedList;
+}
+
 // EOF