locationmanager/geotagger/inc/cinternalgeotagger.h
changeset 36 aa5a574040a4
child 40 910a23996aa0
child 45 a93990e5815e
child 54 a3cc46f37772
equal deleted inserted replaced
35:f727727520eb 36:aa5a574040a4
       
     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:  A class responsible for geotagging of media files in background.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef C_CINTERNALGEOTAGGER_H
       
    19 #define C_CINTERNALGEOTAGGER_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <e32property.h>
       
    23 #include <lbs.h>
       
    24 #include <locationdatatype.h>
       
    25 #include <geotagger.h>
       
    26 
       
    27 #include "reversegeocode.h"
       
    28 #include "mdccommon.h"
       
    29 #include "mdesession.h"
       
    30 #include "mdenamespacedef.h"
       
    31 #include "mdeobjectdef.h"
       
    32 #include "mdepropertydef.h"
       
    33 #include "mderelation.h"
       
    34 #include "mdequery.h"
       
    35 #include "ctagcreator.h"
       
    36 
       
    37 #ifdef LOC_GEOTAGGING_CELLID
       
    38 #include "cgeoconverter.h"
       
    39 #endif
       
    40 
       
    41 class CReverseGeoCoderPlugin;
       
    42 
       
    43 /**
       
    44  *  GeoTagger converts a given cell ID(CGI Info) to geo-coordinates.
       
    45  *  Does reverse geocoding to get country and city name.
       
    46  *  Creates country and city tag for image/video files.  
       
    47  *  @since S60 9.2
       
    48  */
       
    49  
       
    50 class CInternalGeoTagger : public CGeoTagger,
       
    51                    public MMdESessionObserver,
       
    52                    public MMdEQueryObserver,
       
    53                    public MReverseGeocodeObserver
       
    54 #ifdef LOC_GEOTAGGING_CELLID	
       
    55                    ,public MGeoConverterObserver
       
    56 #endif				   
       
    57     {
       
    58 public:  
       
    59     
       
    60     /**
       
    61      * 2-phased constructor.
       
    62      * @param aMdeSession An instance of the CMdESession
       
    63      * @param aObserver   The observer that is to be notified when geotagging is over
       
    64      */
       
    65     IMPORT_C static CInternalGeoTagger* NewL( CMdESession* aMdeSession,
       
    66         MGeoTaggerObserver* aObserver );
       
    67 
       
    68     /**
       
    69       * C++ destructor.
       
    70       */    
       
    71     IMPORT_C virtual ~CInternalGeoTagger();
       
    72 
       
    73     
       
    74 public:    //exported API
       
    75     // CGeoTagger
       
    76      /**
       
    77        * Harvests location tags.
       
    78        * @param aObserver, observer for geotagging.
       
    79        * @return None.
       
    80        */    
       
    81     virtual void CreateGeoTagsL( const TConnectionOption = EInteractive  );
       
    82 
       
    83      /**
       
    84        * Checks if there is any untagged photos with location info and tags them.
       
    85        * @param aTagInProgress, boolean value to indicate if geotagging is in progress.
       
    86        * @return None.
       
    87        */
       
    88     virtual void PendingGeoTagsL( TBool aTagInProgress );
       
    89     
       
    90 public:   //observer methods
       
    91 
       
    92     // From MMdEQueryObserver
       
    93 
       
    94     /**
       
    95       * @param aQuery the query type
       
    96       * @param aFirstNewItemIndex The new item index
       
    97       * @param aNewItemCount   The new item count
       
    98       */
       
    99       void HandleQueryNewResults(CMdEQuery& aQuery, TInt aFirstNewItemIndex, 
       
   100               TInt aNewItemCount);
       
   101 
       
   102     /**
       
   103       * This method is called on completion of a query
       
   104       * @param aQuery the query type
       
   105       * @param aError  Error if any
       
   106       */    
       
   107       void HandleQueryCompleted(CMdEQuery& aQuery, TInt aError);
       
   108     
       
   109     //MReverseGeocodeObserver
       
   110 
       
   111     /**
       
   112       * This method is called when reverse geocoding is completed
       
   113       *@param  aErrorcode  Error if any
       
   114       *@param aAddressInfo   the reverse geocoded address     
       
   115       */
       
   116     void ReverseGeocodeComplete( TInt& aErrorcode, MAddressInfo& aAddressInfo );
       
   117 
       
   118     /*
       
   119     * Get registrer network country code
       
   120     *
       
   121     * @return current register n/w info
       
   122     */
       
   123     RMobilePhone::TMobilePhoneNetworkInfoV2& GetCurrentRegisterNw();
       
   124 	
       
   125     /*
       
   126     * UE is registered to home network?
       
   127     *
       
   128     * @return ETrue if UE is registered at home network else EFalse
       
   129     */
       
   130     TBool IsRegisteredAtHomeNetwork();
       
   131 
       
   132 
       
   133     /*
       
   134     * Get home network country code
       
   135     * @param aHomeNwInfoAvailableFlag ETrue if home n/w info available else EFalse
       
   136     * @return user home n/w info
       
   137     */
       
   138     const RMobilePhone::TMobilePhoneNetworkInfoV1& 
       
   139         GetHomeNetworkInfo(TBool& aHomeNwInfoAvailableFlag);
       
   140     
       
   141     
       
   142     // From MMdESessionObserver
       
   143 
       
   144     /** 
       
   145       * Handles session opening
       
   146       *@param  aSession  A reference of the CMdESession
       
   147       *@param aError     error if any
       
   148       */    
       
   149     void HandleSessionOpened(CMdESession& aSession, TInt aError);
       
   150 
       
   151     /**
       
   152       * Handles any error in session opening
       
   153       *@param  aSession  A reference of the CMdESession
       
   154       *@param aError     error if any
       
   155       */    
       
   156     void HandleSessionError(CMdESession& aSession, TInt aError);
       
   157 
       
   158 #ifdef LOC_GEOTAGGING_CELLID	
       
   159 public:     // MGeoConverterObserver
       
   160         /**
       
   161          * This method is used for notifying completion of geotagging
       
   162          * @param aError error code
       
   163          * @param aPosition position (lat/lon) for the correcponding n/w info
       
   164          */
       
   165      void ConversionCompletedL( const TInt aError, TLocality& aPosition );
       
   166 
       
   167 
       
   168 		/**
       
   169 		* This method is used to handle the conversion error
       
   170 		* @param aError the error code
       
   171 		*/
       
   172 	 void HandleConversionError(TInt aError);
       
   173 
       
   174 #endif    
       
   175 private:    
       
   176     
       
   177     /**
       
   178      * C++ constructor.
       
   179      * @param aMdeSession An instance of the CMdESession
       
   180      * @param aObserver   The observer that is to be notified when geotagging is over     
       
   181      */  
       
   182     CInternalGeoTagger( CMdESession* aMdeSession, MGeoTaggerObserver* aObserver );
       
   183     
       
   184     /**
       
   185       * 2nd phase constructor.
       
   186      */
       
   187     void ConstructL();
       
   188  
       
   189     /**
       
   190       * Get all relation objects associated with this location
       
   191      * @param aLocID The locationId whose relation is to be fetched
       
   192      */
       
   193     void GetRelationObjectsL(TItemId aLocID);
       
   194 
       
   195     /**
       
   196       * get tags for this image
       
   197      * @param aImageID The imageIs whose tag is to be fetched
       
   198      */ 
       
   199     void GetTagsL( TItemId aImageID );
       
   200 
       
   201     /**
       
   202        * Get location objects, where lat, long not populated.
       
   203       */    
       
   204     void GetAllLocationsL( );
       
   205 
       
   206     /**
       
   207        * Get location objects, where lat, long not populated.
       
   208       * @param  aCountryTagId The country tagId
       
   209       * @param aCityTagId  The city tagId
       
   210       */        
       
   211     void AddressInfoL( const TItemId aCountryTagId, const TItemId aCityTagId );
       
   212 
       
   213     /**
       
   214        * checks if the session is ready
       
   215       * @return ETrue If the session is ready
       
   216       */        
       
   217     TBool IsSessionReady();
       
   218 
       
   219     /**
       
   220        * Fetches the location information
       
   221       */        
       
   222     void GetLocationInfoL();
       
   223 
       
   224     /**
       
   225        * starts geotagging of objects
       
   226       */        
       
   227     void StartGeoTaggingL();
       
   228 
       
   229     /**
       
   230        * Checks if Location atg exists for an object
       
   231       * @return ETrue if location tag is found
       
   232       */        
       
   233     TBool LocationTagExists();
       
   234 
       
   235     /**
       
   236        * Moves to the next location for reverse geocoding
       
   237       */        
       
   238     void IterateNextLocation();
       
   239     
       
   240     /**
       
   241        * @return ETrue if item had valid lat/lon else EFalse
       
   242       */        
       
   243     TBool GPSInfoExists();
       
   244 private:
       
   245     /**
       
   246      * A session to Metadata Engine for creating and manipulating location objects.
       
   247      */
       
   248     CMdESession* iMdeSession;
       
   249 
       
   250     /**
       
   251      * This query object is used to find existing locations
       
   252      */
       
   253     CMdEObjectQuery* iLocationQuery;
       
   254     /** @var iRelationQuery. */
       
   255     CMdERelationQuery* iRelationQuery;
       
   256     CMdERelationQuery* iTagQuery;
       
   257     
       
   258     TInt iIndex;
       
   259         
       
   260     TBool iSessionReady;  
       
   261     
       
   262     MGeoTaggerObserver* iObserver;
       
   263     
       
   264     TLocationData iLocationData;
       
   265     
       
   266     TItemId iLocationId;
       
   267     
       
   268     TConnectionOption iConnectionOption;
       
   269     
       
   270     CTagCreator* iTagCreator;
       
   271     
       
   272     /**
       
   273      * An active scheduler wait loop for waiting a session to MdE to open.
       
   274      */
       
   275     CActiveSchedulerWait* iASW;
       
   276     TBool iMdeSessionOwnFlag;
       
   277     TBool iTagPendingHandlerFlag;
       
   278     CReverseGeoCoderPlugin* iRevGeocoderPlugin;
       
   279     TUid iDtorKey;
       
   280 #ifdef LOC_GEOTAGGING_CELLID	
       
   281     /*
       
   282        * Geo converter
       
   283        */
       
   284 	CGeoConverter* iGeoConverter;
       
   285 #endif
       
   286     };
       
   287 
       
   288 #endif // C_CGEOTAGGER_H 
       
   289 
       
   290 // End of file.