locationsystemui/locationsysui/privacyverifiernotifierui/locnotificationengine/src/qlocnotificationengine.cpp
changeset 32 b12ea03c50a3
child 37 e175e2ba2fb0
equal deleted inserted replaced
25:73f6c2762ffe 32:b12ea03c50a3
       
     1 /*
       
     2 * Copyright (c) 2010 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:  Implementation of positioning settings engine class. 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "qlocnotificationengine.h"
       
    19 
       
    20 #include <QDebug>
       
    21 #include <QLocale>
       
    22 
       
    23 #include <qcontactrequests.h>
       
    24 #include <qcontactfilters.h>
       
    25 #include <qcontact.h>
       
    26 #include <qcontactname.h>
       
    27 #include <qcontactemailaddress.h>
       
    28 #include <qcontactphonenumber.h>
       
    29 #include <qcontacturl.h>
       
    30 #include <qcontactmanager.h>
       
    31 #include <qcontactdisplaylabel.h>
       
    32 
       
    33 #include <hbnumbergrouping.h>
       
    34 
       
    35 
       
    36 
       
    37 //---------------------------------------------------------------------
       
    38 // QLocNotificationEngine::QLocNotificationEngine()
       
    39 // (other items were commented in a header).
       
    40 //---------------------------------------------------------------------
       
    41 QLocNotificationEngine::QLocNotificationEngine()
       
    42     {
       
    43     //"symbian" is the string used to load the contact manager corresponding to the phonebook database
       
    44     mContactManager = new QtMobility::QContactManager("symbian");
       
    45     }
       
    46 
       
    47 //------QLocNotificationEngine-----------------------------------------
       
    48 // QLocNotificationEngine::~QLocNotificationEngine()
       
    49 // (other items were commented in a header).
       
    50 //---------------------------------------------------------------------
       
    51 QLocNotificationEngine::~QLocNotificationEngine()
       
    52     {
       
    53     delete mContactManager;
       
    54     }
       
    55 
       
    56 //------QLocNotificationEngine-----------------------------------------
       
    57 // QLocNotificationEngine::processRequestors
       
    58 // Used to resolve requestors
       
    59 // (other items were commented in a header).
       
    60 //---------------------------------------------------------------------
       
    61 void QLocNotificationEngine::processRequestors(QPosRequestorData& posRequestorData)
       
    62     {        
       
    63   
       
    64     QtMobility::QContactDetailFilter filter;
       
    65 
       
    66     QString idString;
       
    67     QPosRequestorData::IdFormat idFormat =  QPosRequestorData::EIdFormatUnknown;
       
    68     posRequestorData.getPosRequestorData(idFormat,idString);
       
    69     
       
    70     switch(idFormat) // set definition name based on the idformat to be searched for
       
    71         {
       
    72         case QPosRequestorData::EIdFormatPhoneNumber:      
       
    73             {
       
    74             filter.setDetailDefinitionName(QtMobility::QContactPhoneNumber::DefinitionName, QtMobility::QContactPhoneNumber::FieldNumber);            
       
    75             }
       
    76             break;
       
    77         
       
    78         case QPosRequestorData::EIdFormatEmail:
       
    79             {
       
    80             filter.setDetailDefinitionName(QtMobility::QContactEmailAddress::DefinitionName, QtMobility::QContactEmailAddress::FieldEmailAddress);
       
    81             }
       
    82             break;
       
    83         case QPosRequestorData::EIdFormatUrl:
       
    84             {
       
    85             filter.setDetailDefinitionName(QtMobility::QContactUrl::DefinitionName,QtMobility::QContactUrl::ContextHome);
       
    86             }
       
    87             break;
       
    88         
       
    89         //other cases are not supported by the phonebook
       
    90         default: //this case wont arise as other values will already have been filtered out 
       
    91             
       
    92             break;
       
    93         }
       
    94     filter.setMatchFlags(QtMobility::QContactFilter::MatchExactly);
       
    95     filter.setValue(idString);
       
    96     
       
    97     QList<QtMobility::QContactLocalId> matchingContacts = mContactManager->contactIds(filter);
       
    98     
       
    99     if (matchingContacts.size() > 0) //if any contacts were found
       
   100         {
       
   101                
       
   102         QtMobility::QContact match = mContactManager->contact(matchingContacts.at(0)); //return the first contact among the ones found
       
   103 
       
   104        // QtMobility::QContactDisplayLabel cdl = match.detail(QtMobility::QContactDisplayLabel::DefinitionName);
       
   105         QString labelDetail = match.displayLabel();
       
   106         posRequestorData.setPosRequestorData(idFormat,labelDetail); //set back result
       
   107         }
       
   108     else
       
   109     	{
       
   110     	// if no contacts were found
       
   111     	
       
   112     	if( QPosRequestorData::EIdFormatPhoneNumber == idFormat )
       
   113     		{
       
   114     		// Group the phone number according to current system locale
       
   115     		/*
       
   116     	    QString isStringPh = HbNumberGrouping::formatPhoneNumber(idString,QLocale::system().country());
       
   117             posRequestorData.setPosRequestorData(idFormat,isStringPh); //set back result
       
   118     		*/
       
   119             posRequestorData.setPosRequestorData(idFormat,idString); //set back result
       
   120     		}
       
   121     	} 
       
   122     
       
   123     }
       
   124 
       
   125 //---------------------------------------------------------------------
       
   126 // QPosRequestorData::QPosRequestorData()
       
   127 // Constructor for QPosRequestorData
       
   128 // (other items were commented in a header).
       
   129 //---------------------------------------------------------------------
       
   130 QPosRequestorData::QPosRequestorData()
       
   131     {
       
   132     
       
   133     }
       
   134    
       
   135 //---------------------------------------------------------------------
       
   136 // QPosRequestorData::~QPosRequestorData()
       
   137 // Destructor for QPosRequestorData
       
   138 // (other items were commented in a header).
       
   139 //---------------------------------------------------------------------
       
   140 QPosRequestorData::~QPosRequestorData()
       
   141     {
       
   142     
       
   143     }
       
   144 
       
   145 //---------------------------------------------------------------------
       
   146 // QPosRequestorData::setPosRequestorData()
       
   147 // Settermethod for QPosRequestorData
       
   148 // (other items were commented in a header).
       
   149 //---------------------------------------------------------------------
       
   150 void QPosRequestorData::setPosRequestorData(const QPosRequestorData::IdFormat& idFormat, const QString& idString)
       
   151     {
       
   152     mIdFormat = idFormat;
       
   153     mIdString = idString;
       
   154     }
       
   155     
       
   156 //---------------------------------------------------------------------
       
   157 // QPosRequestorData::getPosRequestorData()
       
   158 // Gettermethod for QPosRequestorData
       
   159 // (other items were commented in a header).
       
   160 //---------------------------------------------------------------------
       
   161 void QPosRequestorData::getPosRequestorData(QPosRequestorData::IdFormat& idFormat, QString& idString) const
       
   162     {
       
   163     idFormat = mIdFormat;
       
   164     idString = mIdString;
       
   165     }
       
   166     
       
   167 // End of file.