locationdataharvester/maptileservice/src/maptileservice.cpp
changeset 30 96df3ab41000
parent 26 f3533f6eae3f
child 31 8db05346071b
equal deleted inserted replaced
26:f3533f6eae3f 30:96df3ab41000
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 
    19 
    20 #include <centralrepository.h> 
    20 #include <centralrepository.h> 
       
    21 #include <locationservicedefines.h>
       
    22 #include <qvaluespacepublisher.h>
       
    23 #include <qvaluespacesubscriber.h>
       
    24 #include "mylocationlogger.h"
    21 
    25 
    22 #include "maptileservice.h"
    26 #include "maptileservice.h"
    23 #include "maptiledblookuptable.h"
    27 #include "maptiledblookuptable.h"
    24 
    28 #include <QVariant>
    25 // CONSTANTS
    29 // CONSTANTS
    26 // Maptile interface uid
    30 // Maptile interface uid
    27 const TUid KUidMapTileInterface = { 0x2002E6E8 };
    31 const TUid KUidMapTileInterface = { 0x2002E6E8 };
       
    32 
    28 // Central Repository Key IDs
    33 // Central Repository Key IDs
    29 const TInt KEnableLocationFeature  = 0x1;
    34 const TInt KEnableLocationFeature  = 0x1;
    30 
    35 
    31 
    36 const char *MAPTILE_STATUS_RECEIVER = "/maptilestatuspublisher/name";
       
    37 const char *MAPTILE_STATUS_PUBLISHER = "/maptilepublisher";
       
    38 const char *MAPTILE_STATUS_CALENDAR_PUBLISHER = "/maptilecalpublisher";
       
    39 
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // MapTileService::MapTileService()
       
    43 // Default constructor
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 MapTileService::MapTileService():mCalPublisher(0)
       
    47 {
       
    48    /* Constructs a QValueSpacePublisher that publishes values under path /mypublisher*/
       
    49     mPublisher = NULL;    
       
    50     mSubscriber = new QValueSpaceSubscriber( MAPTILE_STATUS_RECEIVER );
       
    51     //Connect for maptile status change key
       
    52     QObject::connect(mSubscriber, SIGNAL(contentsChanged()), this, SLOT(setMaptileStatus()));
       
    53     
       
    54 }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // MapTileService::~MapTileService()
       
    58 // Destructor
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 MapTileService::~MapTileService()
       
    62 {
       
    63     if( mSubscriber )
       
    64     {
       
    65         delete mSubscriber;
       
    66         mSubscriber = NULL;
       
    67     }
       
    68     
       
    69     if( mPublisher )
       
    70     {
       
    71         delete mPublisher;
       
    72         mPublisher = NULL;
       
    73     }
       
    74 	if( mCalPublisher )
       
    75 	{
       
    76 	    delete mCalPublisher;
       
    77 		mCalPublisher = NULL;
       
    78 	}
       
    79 }
    32 // -----------------------------------------------------------------------------
    80 // -----------------------------------------------------------------------------
    33 // MapTileService::isLocationFeatureEnabled()
    81 // MapTileService::isLocationFeatureEnabled()
    34 // Checks whether location feature is enabled or disabled
    82 // Checks whether location feature is enabled or disabled
    35 // -----------------------------------------------------------------------------
    83 // -----------------------------------------------------------------------------
    36 //
    84 //
    37 bool MapTileService::isLocationFeatureEnabled(AppType appType)
    85 bool MapTileService::isLocationFeatureEnabled(AppType appType)
    38 { 
    86 {    
    39    
       
    40     //Create the centrep with uid 0x2002C3A8
    87     //Create the centrep with uid 0x2002C3A8
    41     bool iLocationFeatureEnabled = false;
    88     bool iLocationFeatureEnabled = false;
    42     
    89     
    43     CRepository* centralRepository = NULL;  
    90     CRepository* centralRepository = NULL;  
    44      
    91      
    74 // -----------------------------------------------------------------------------
   121 // -----------------------------------------------------------------------------
    75 // MapTileService::getMapTileImage()
   122 // MapTileService::getMapTileImage()
    76 // Gets the maptile image path associated with a contact.
   123 // Gets the maptile image path associated with a contact.
    77 // -----------------------------------------------------------------------------
   124 // -----------------------------------------------------------------------------
    78 //
   125 //
    79 QString MapTileService::getMapTileImage( int id, AddressType sourceType )    
   126 int MapTileService::getMapTileImage( int id, AddressType sourceType, QString& imagePath )    
    80 {
   127 {
       
   128     __TRACE_CALLSTACK;
       
   129     
       
   130     TLookupItem lookupItem;
       
   131     
       
   132     int addressCount = 0;  
       
   133     int maptileStatus = MapTileFetchingUnknownError;
       
   134 
       
   135     int error = readEntryFromMaptileDataBase( id, sourceType, lookupItem, addressCount );
       
   136         
       
   137     //if entry available returns the file path otherwise NULL. 
       
   138     if ( KErrNone == error  )
       
   139     {
       
   140      
       
   141         //Get the image path
       
   142         QString imageFile((QChar*)lookupItem.iFilePath.Ptr(),
       
   143                     lookupItem.iFilePath.Length());
       
   144         imagePath = imageFile;
       
   145             
       
   146         maptileStatus = lookupItem.iFetchingStatus;
       
   147         MYLOCLOGSTRING1("getMapTileImage maptileStatus  - %d ", maptileStatus );
       
   148 
       
   149         if( maptileStatus == MapTileFetchingNetworkError ||
       
   150                     maptileStatus == MapTileFetchingInProgress )
       
   151         {
       
   152             switch(sourceType)
       
   153             {           
       
   154                 case AddressHome:            
       
   155                 case AddressPreference:           
       
   156                 case AddressWork:
       
   157                 {
       
   158                     publishValue( id, sourceType, addressCount );
       
   159                     break;
       
   160                 }
       
   161                 
       
   162                 case AddressPlain:
       
   163                 {
       
   164                     publishCalEntry( id );
       
   165                     break;
       
   166                 }
       
   167                 default:
       
   168                     break;
       
   169             };
       
   170            		  
       
   171         }
       
   172                     
       
   173 
       
   174     }
       
   175     else if ( KErrNotFound == error )
       
   176     {
       
   177         MYLOCLOGSTRING("getMapTileImage entry not found, return MapTileFetchingInProgress" );
       
   178         //If entry is not found , it will be a newly added entry.       
       
   179         switch (sourceType) {
       
   180             case AddressHome:
       
   181             case AddressPreference:
       
   182             case AddressWork:
       
   183             {
       
   184                 publishValue(id, sourceType, addressCount);
       
   185                 break;
       
   186             }
       
   187     
       
   188             case AddressPlain:
       
   189             {
       
   190                 publishCalEntry(id);
       
   191                 break;
       
   192             }
       
   193             default:
       
   194                 break;
       
   195         };
       
   196         maptileStatus = MapTileFetchingInProgress;
       
   197     }
       
   198  
       
   199     //Return the maptile status
       
   200     MYLOCLOGSTRING("getMapTileImage  returns MapTileFetchingUnknownError" );
       
   201     return maptileStatus;
       
   202 
       
   203 }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // MapTileService::setMaptileStatus()
       
   207 // Gets call back from location engine , after maptile fetching done ,
       
   208 // to set status and emit signal . 
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void MapTileService::setMaptileStatus()
       
   212 {
       
   213     __TRACE_CALLSTACK;
       
   214     QString imagePath;
       
   215     AddressType addressType = AddressUnknown;   
       
   216     QStringList subPath = mSubscriber->subPaths();
       
   217     QVariant value = mSubscriber->value(subPath.at(0));
       
   218       
       
   219     //Subscriber Protocol : [appid-addresstype-maptilestatus]
       
   220     QStringList text = value.toString().split("-");
       
   221     
       
   222     int id = text.at(0).toInt();
       
   223     int status = text.at(2).toInt();
       
   224     
       
   225     switch( text.at(1).toInt() )
       
   226     {
       
   227         case ESourceContactsPref:
       
   228             addressType = AddressPreference;
       
   229             break;
       
   230         case ESourceContactsWork:
       
   231             addressType = AddressWork;
       
   232             break;        
       
   233         case ESourceContactsHome:
       
   234             addressType = AddressHome;
       
   235             break;
       
   236         case ESourceCalendar:           
       
   237             addressType = AddressPlain;
       
   238             break;
       
   239         default:
       
   240             break;
       
   241     }
       
   242             
       
   243     //Emit the maptile status signal 
       
   244     int type = addressType;
       
   245     MYLOCLOGSTRING1("setMaptileStatus() status  - %d ", addressType );
       
   246     if( mLastViewedEntryId == id )
       
   247     {
       
   248         emit maptileFetchingStatusUpdate( mLastViewedEntryId, type , status );
       
   249 	}
       
   250   
       
   251 }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // MapTileService::publishValue()
       
   255 // publish the contact entry 
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void MapTileService::publishValue( int id, AddressType sourceType, int addressCount )
       
   259 {
       
   260     __TRACE_CALLSTACK;
       
   261     mLastViewedEntryId = id;
       
   262     
       
   263 	int addressType = ESourceInvalid;    
       
   264     switch( sourceType )
       
   265     {
       
   266         case AddressPreference:
       
   267             addressType = ESourceContactsPref;
       
   268             break;
       
   269         case AddressWork:
       
   270             addressType = ESourceContactsWork;
       
   271             break;
       
   272         case AddressHome:
       
   273             addressType = ESourceContactsHome;
       
   274             break;
       
   275     }
       
   276     
       
   277     if ( !mPublisher )
       
   278     {
       
   279         /* Constructs a QValueSpacePublisher that publishes values under path /mypublisher*/
       
   280         mPublisher = new QValueSpacePublisher( MAPTILE_STATUS_PUBLISHER, this);
       
   281     }
    81    
   282    
    82     //Image file to return;
   283     
    83    
   284     /* Publisher protocol [appid-addresstype-count] */
       
   285     QString addressId;
       
   286     addressId.append( QVariant(id).toString());
       
   287     addressId.append( QChar('-') );
       
   288     addressId.append( QVariant(addressType).toString());
       
   289     addressId.append( QChar('-') );
       
   290     addressId.append( QVariant(addressCount).toString() );
       
   291     mPublisher->setValue("name", addressId.toAscii() );
       
   292     mPublisher->sync();
       
   293     
       
   294 }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // MapTileService::publishValue()
       
   298 // publish the calendar entry 
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 void MapTileService::publishCalEntry( int id)
       
   302 {
       
   303     __TRACE_CALLSTACK;
       
   304     mLastViewedEntryId = id;       
       
   305     if ( NULL ==mCalPublisher )
       
   306     {
       
   307         /* Constructs a QValueSpacePublisher that publishes values under path /mypublisher*/
       
   308         mCalPublisher = new QValueSpacePublisher( MAPTILE_STATUS_CALENDAR_PUBLISHER, this);
       
   309     }    
       
   310     mCalPublisher->setValue("name", id);
       
   311     mCalPublisher->sync();
       
   312 }
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // MapTileService::readEntryFromMaptileDataBase()
       
   316 // Read all entries from database
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 int MapTileService::readEntryFromMaptileDataBase( 
       
   320             int id, AddressType sourceType, TLookupItem& aLookupItem, int& aNoOfAddress )
       
   321 {
       
   322     
    84     //Maptile database  instance
   323     //Maptile database  instance
    85     CLookupMapTileDatabase* mapTileDatabase = NULL;
   324     CLookupMapTileDatabase* mapTileDatabase = NULL;
    86    
   325    
    87     TRAPD( err, mapTileDatabase = CLookupMapTileDatabase::NewL(
   326     TRAPD( err, mapTileDatabase = CLookupMapTileDatabase::NewL(
    88             KMapTileLookupDatabaseName ) );
   327             KMapTileLookupDatabaseName ) );
       
   328     
    89     if ( KErrNone == err )
   329     if ( KErrNone == err )
    90     {
   330     {     
    91         TLookupItem lookupItem;
   331         TRAP( err,aNoOfAddress = mapTileDatabase->FindNumberOfAddressL(id) );
    92         lookupItem.iUid = id;
   332         MYLOCLOGSTRING1("no of address  FindNumberOfAddressL returns - %d ", err );     
    93         switch( sourceType )
   333        if ( KErrNone == err )
    94         {
   334        {
    95             case AddressPlain:
   335             aLookupItem.iUid = id;
    96                 lookupItem.iSource = ESourceCalendar;
   336             switch (sourceType)
    97                 break;
   337             {
    98            case AddressPreference:
   338                 case AddressPlain:
    99                lookupItem.iSource = ESourceContactsPref;
   339                     aLookupItem.iSource = ESourceCalendar;
   100                break;
   340                     break;
   101            case AddressWork:
   341                 case AddressPreference:
   102                lookupItem.iSource = ESourceContactsWork;
   342                     aLookupItem.iSource = ESourceContactsPref;
   103                break;
   343                     break;
   104            case AddressHome:
   344                 case AddressWork:
   105                lookupItem.iSource = ESourceContactsHome;
   345                     aLookupItem.iSource = ESourceContactsWork;
   106                break;
   346                     break;
   107            default: 
   347                 case AddressHome:
   108                break;
   348                     aLookupItem.iSource = ESourceContactsHome;
   109         }
   349                     break;
   110        
   350                 default:
   111         TRAP( err , mapTileDatabase->FindEntryL( lookupItem ) );
   351                     break;
   112        
   352             }
       
   353 
       
   354             TRAP( err , mapTileDatabase->FindEntryL( aLookupItem ) );
       
   355 
       
   356             MYLOCLOGSTRING1("getMapTileImage FindEntryL returns - %d ", err );
       
   357         }
   113         //delet the database instance
   358         //delet the database instance
   114         delete mapTileDatabase;
   359         delete mapTileDatabase;
   115        
   360            
   116         //if entry available returns the file path otherwise NULL. 
   361     }
   117         if ( KErrNone == err  )
   362     
   118         {
   363     return err;
   119            //Get the image path
   364 }
   120             QString imageFile((QChar*)lookupItem.iFilePath.Ptr(),
       
   121                     lookupItem.iFilePath.Length());
       
   122             return imageFile;
       
   123         }
       
   124     }
       
   125     
       
   126     return QString();
       
   127 }
       
   128 
       
   129 // End of file
   365 // End of file
   130