qtinternetradio/irqcommon/src/irqutility.cpp
changeset 14 896e9dbc5f19
parent 11 f683e24efca3
child 16 5723da102db1
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
    37 
    37 
    38 _LIT8( KIRHtmlMimeType, "text/html" );
    38 _LIT8( KIRHtmlMimeType, "text/html" );
    39 /** Browser prefix: See browser API specification */
    39 /** Browser prefix: See browser API specification */
    40 _LIT( KBrowserPrefix, "4 " );
    40 _LIT( KBrowserPrefix, "4 " );
    41 
    41 
    42 const long int KCenrepUidInternetRadio = { 0x2000B499 };
       
    43 const unsigned long int KSongRecognitionKeyId = { 0x00000035 };
       
    44 
       
    45 static bool openAdvLinkL(const QString& aUrl);
    42 static bool openAdvLinkL(const QString& aUrl);
    46 static TUid getSongRecognitionAppUid();
       
    47 static bool launchAppByUid(const TUid aUid);
       
    48   
    43   
    49 //
    44 //
    50 //convert the CIRIsdsPreset to the IRQPreset. 
    45 //convert the CIRIsdsPreset to the IRQPreset. 
    51 //
    46 //
    52 EXPORT_C void IRQUtility::convertCIRIsdsPreset2IRQPrest(const CIRIsdsPreset& aCIRIsdsPreset, IRQPreset& aQIRPreset)
    47 void IRQUtility::convertCIRIsdsPreset2IRQPrest(const CIRIsdsPreset& aCIRIsdsPreset, IRQPreset& aQIRPreset)
    53 {
    48 {
    54   aQIRPreset.type = aCIRIsdsPreset.GetChannelType();
    49   aQIRPreset.type = aCIRIsdsPreset.GetChannelType();
    55   
    50   
    56   aQIRPreset.presetId = aCIRIsdsPreset.GetId();
    51   aQIRPreset.presetId = aCIRIsdsPreset.GetId();
    57   aQIRPreset.iChannelUrlCount  = aCIRIsdsPreset.GetUrlCount();
    52   aQIRPreset.iChannelUrlCount  = aCIRIsdsPreset.GetUrlCount();
    73   aQIRPreset.advertisementUrl  = QString::fromUtf16(aCIRIsdsPreset.GetAdvertisementUrl().Ptr(), aCIRIsdsPreset.GetAdvertisementUrl().Length());
    68   aQIRPreset.advertisementUrl  = QString::fromUtf16(aCIRIsdsPreset.GetAdvertisementUrl().Ptr(), aCIRIsdsPreset.GetAdvertisementUrl().Length());
    74   aQIRPreset.advertisementInUse  = QString::fromUtf16(aCIRIsdsPreset.GetAdvertisementInUse().Ptr(),aCIRIsdsPreset.GetAdvertisementInUse().Length());
    69   aQIRPreset.advertisementInUse  = QString::fromUtf16(aCIRIsdsPreset.GetAdvertisementInUse().Ptr(),aCIRIsdsPreset.GetAdvertisementInUse().Length());
    75   
    70   
    76   aQIRPreset.imgUrl  = QString::fromUtf16(aCIRIsdsPreset.GetImgUrl().Ptr(), aCIRIsdsPreset.GetImgUrl().Length());   
    71   aQIRPreset.imgUrl  = QString::fromUtf16(aCIRIsdsPreset.GetImgUrl().Ptr(), aCIRIsdsPreset.GetImgUrl().Length());   
    77   aQIRPreset.logoData.Close();
    72   aQIRPreset.logoData.Close();
    78   aQIRPreset.logoData.Create(aCIRIsdsPreset.GetLogoData());
    73   TRAP_IGNORE(aQIRPreset.logoData.CreateL(aCIRIsdsPreset.GetLogoData()));
    79   
    74   
    80   aQIRPreset.musicStoreStatus  = QString::fromUtf16(aCIRIsdsPreset.GetMusicStoreStatus().Ptr(), aCIRIsdsPreset.GetMusicStoreStatus().Length());
    75   aQIRPreset.musicStoreStatus  = QString::fromUtf16(aCIRIsdsPreset.GetMusicStoreStatus().Ptr(), aCIRIsdsPreset.GetMusicStoreStatus().Length());
    81   aQIRPreset.clearChannelServerList();
    76   aQIRPreset.clearChannelServerList();
    82   
    77   
    83   IRQChannelServerURL url;
    78   IRQChannelServerURL url;
    95   aQIRPreset.sortURLArray();   
    90   aQIRPreset.sortURLArray();   
    96 }
    91 }
    97 
    92 
    98 //convert the IRQPreset to the CIRIsdsPreset 
    93 //convert the IRQPreset to the CIRIsdsPreset 
    99 //
    94 //
   100 EXPORT_C void IRQUtility::convertIRQPreset2CIRIsdsPreset(const IRQPreset& aQIRPreset, CIRIsdsPreset& aCIRIsdsPreset)
    95 void IRQUtility::convertIRQPreset2CIRIsdsPreset(const IRQPreset& aQIRPreset, CIRIsdsPreset& aCIRIsdsPreset)
   101 {
    96 {
   102   aCIRIsdsPreset.SetId(aQIRPreset.presetId);
    97   aCIRIsdsPreset.SetId(aQIRPreset.presetId);
   103   aCIRIsdsPreset.SetUrlCount(aQIRPreset.iChannelUrlCount);
    98   aCIRIsdsPreset.SetUrlCount(aQIRPreset.iChannelUrlCount);
   104   aCIRIsdsPreset.SetChannelType(aQIRPreset.type);  
    99   aCIRIsdsPreset.SetChannelType(aQIRPreset.type);  
   105   
   100   
   106   TPtrC16 namePtr(reinterpret_cast<const TUint16*>(aQIRPreset.name.utf16()));
   101   TPtrC16 namePtr(reinterpret_cast<const TUint16*>(aQIRPreset.name.utf16()));
   107   aCIRIsdsPreset.SetName(namePtr);
   102   TRAP_IGNORE(aCIRIsdsPreset.SetNameL(namePtr));
   108   
   103   
   109   TPtrC16 languageCodePtr(reinterpret_cast<const TUint16*>(aQIRPreset.languageCode.utf16()));
   104   TPtrC16 languageCodePtr(reinterpret_cast<const TUint16*>(aQIRPreset.languageCode.utf16()));
   110   aCIRIsdsPreset.SetLangCode(languageCodePtr);
   105   TRAP_IGNORE(aCIRIsdsPreset.SetLangCodeL(languageCodePtr));
   111   
   106   
   112   TPtrC16 languageNamePtr(reinterpret_cast<const TUint16*>(aQIRPreset.languageName.utf16()));
   107   TPtrC16 languageNamePtr(reinterpret_cast<const TUint16*>(aQIRPreset.languageName.utf16()));
   113   aCIRIsdsPreset.SetLang(languageNamePtr);
   108   TRAP_IGNORE(aCIRIsdsPreset.SetLangL(languageNamePtr));
   114   
   109   
   115   TPtrC16 countryCode(reinterpret_cast<const TUint16*>(aQIRPreset.countryCode.utf16()));
   110   TPtrC16 countryCode(reinterpret_cast<const TUint16*>(aQIRPreset.countryCode.utf16()));
   116   aCIRIsdsPreset.SetCountryCode(countryCode);
   111   TRAP_IGNORE(aCIRIsdsPreset.SetCountryCodeL(countryCode));
   117   
   112   
   118   TPtrC16 countryName(reinterpret_cast<const TUint16*>(aQIRPreset.countryName.utf16()));
   113   TPtrC16 countryName(reinterpret_cast<const TUint16*>(aQIRPreset.countryName.utf16()));
   119   aCIRIsdsPreset.SetCountryName(countryName);
   114   TRAP_IGNORE(aCIRIsdsPreset.SetCountryNameL(countryName));
   120   
   115   
   121   TPtrC16 lastModified(reinterpret_cast<const TUint16*>(aQIRPreset.lastModified.utf16()));
   116   TPtrC16 lastModified(reinterpret_cast<const TUint16*>(aQIRPreset.lastModified.utf16()));
   122   aCIRIsdsPreset.SetLastModifiedTime(lastModified);
   117   TRAP_IGNORE(aCIRIsdsPreset.SetLastModifiedTimeL(lastModified));
   123   
   118   
   124   TPtrC16 description(reinterpret_cast<const TUint16*>(aQIRPreset.description.utf16()));
   119   TPtrC16 description(reinterpret_cast<const TUint16*>(aQIRPreset.description.utf16()));
   125   aCIRIsdsPreset.SetDescription(description);
   120   TRAP_IGNORE(aCIRIsdsPreset.SetDescriptionL(description));
   126   
   121   
   127   TPtrC16 shortDescription(reinterpret_cast<const TUint16*>(aQIRPreset.shortDesc.utf16()));
   122   TPtrC16 shortDescription(reinterpret_cast<const TUint16*>(aQIRPreset.shortDesc.utf16()));
   128   aCIRIsdsPreset.SetShortDesc(shortDescription);
   123   TRAP_IGNORE(aCIRIsdsPreset.SetShortDescL(shortDescription));
   129   
   124   
   130   TPtrC16 genreId(reinterpret_cast<const TUint16*>(aQIRPreset.genreId.utf16()));
   125   TPtrC16 genreId(reinterpret_cast<const TUint16*>(aQIRPreset.genreId.utf16()));
   131   aCIRIsdsPreset.SetGenreId(genreId);
   126   TRAP_IGNORE(aCIRIsdsPreset.SetGenreIdL(genreId));
   132   
   127   
   133   TPtrC16 genreName(reinterpret_cast<const TUint16*>(aQIRPreset.genreName.utf16()));
   128   TPtrC16 genreName(reinterpret_cast<const TUint16*>(aQIRPreset.genreName.utf16()));
   134   aCIRIsdsPreset.SetGenreName(genreName);
   129   TRAP_IGNORE(aCIRIsdsPreset.SetGenreNameL(genreName));
   135   
   130   
   136   TPtrC16 advertisementUrl(reinterpret_cast<const TUint16*>(aQIRPreset.advertisementUrl.utf16()));
   131   TPtrC16 advertisementUrl(reinterpret_cast<const TUint16*>(aQIRPreset.advertisementUrl.utf16()));
   137   aCIRIsdsPreset.SetAdvertisementUrl(advertisementUrl);
   132   TRAP_IGNORE(aCIRIsdsPreset.SetAdvertisementUrlL(advertisementUrl));
   138   
   133   
   139   TPtrC16 advertisementINUse(reinterpret_cast<const TUint16*>(aQIRPreset.advertisementInUse.utf16()));
   134   TPtrC16 advertisementINUse(reinterpret_cast<const TUint16*>(aQIRPreset.advertisementInUse.utf16()));
   140   aCIRIsdsPreset.SetAdvertisementInUse(advertisementINUse);
   135   TRAP_IGNORE(aCIRIsdsPreset.SetAdvertisementInUseL(advertisementINUse));
   141   
   136   
   142   TPtrC16 imgUrl(reinterpret_cast<const TUint16*>(aQIRPreset.imgUrl.utf16()));
   137   TPtrC16 imgUrl(reinterpret_cast<const TUint16*>(aQIRPreset.imgUrl.utf16()));
   143   aCIRIsdsPreset.SetImgUrl(imgUrl);
   138   TRAP_IGNORE(aCIRIsdsPreset.SetImgUrlL(imgUrl));
   144   
   139   
   145   TPtrC16 musicStoreStatus(reinterpret_cast<const TUint16*>(aQIRPreset.musicStoreStatus.utf16()));
   140   TPtrC16 musicStoreStatus(reinterpret_cast<const TUint16*>(aQIRPreset.musicStoreStatus.utf16()));
   146   aCIRIsdsPreset.SetMusicStoreStatus(musicStoreStatus);   
   141   TRAP_IGNORE(aCIRIsdsPreset.SetMusicStoreStatusL(musicStoreStatus));   
   147   aCIRIsdsPreset.SetLogoData(aQIRPreset.logoData);
   142   TRAP_IGNORE(aCIRIsdsPreset.SetLogoDataL(aQIRPreset.logoData));
   148 
   143 
   149   TRAP_IGNORE(appendURLL(aQIRPreset, aCIRIsdsPreset));    
   144   TRAP_IGNORE(appendURLL(aQIRPreset, aCIRIsdsPreset));    
   150 }
   145 }
   151 
   146 
   152 //convert CIRPreset to the IRQPreset 
   147 //convert CIRPreset to the IRQPreset 
   153 //
   148 //
   154 EXPORT_C void IRQUtility::convertCIRPreset2IRQPreset(const CIRPreset& aCIRPreset, IRQPreset& aIRQPreset)
   149 void IRQUtility::convertCIRPreset2IRQPreset(const CIRPreset& aCIRPreset, IRQPreset& aIRQPreset)
   155 {
   150 {
   156     aIRQPreset.uniqID = aCIRPreset.Id(); 
   151     aIRQPreset.uniqID = aCIRPreset.Id(); 
   157     aIRQPreset.type = aCIRPreset.GetChannelType();
   152     aIRQPreset.type = aCIRPreset.GetChannelType();
   158     
   153     
   159     aIRQPreset.presetId = aCIRPreset.GetId();
   154     aIRQPreset.presetId = aCIRPreset.GetId();
   195     aIRQPreset.sortURLArray();   
   190     aIRQPreset.sortURLArray();   
   196 }
   191 }
   197 
   192 
   198 //switch from the symbian error code to the IRQ error code 
   193 //switch from the symbian error code to the IRQ error code 
   199 //
   194 //
   200 EXPORT_C void IRQUtility::convertSError2QError(const int aSError, int& aQError)
   195 void IRQUtility::convertSError2QError(const int aSError, int& aQError)
   201 {
   196 {
   202   if( aSError > 0 )
   197   if( aSError > 0 )
   203   {
   198   {
   204     aQError = aSError;
   199     aQError = aSError;
   205     return;
   200     return;
   229 
   224 
   230 /*
   225 /*
   231  * Description : check the validity of URL
   226  * Description : check the validity of URL
   232  * return value: true: the URL is valid, vice versa.
   227  * return value: true: the URL is valid, vice versa.
   233  */
   228  */
   234 EXPORT_C bool IRQUtility::isValidUrl(const QString& aUrl)
   229 bool IRQUtility::isValidUrl(const QString& aUrl)
   235 {
   230 {
   236     QString temp = aUrl.trimmed();
   231     QString temp = aUrl.trimmed();
   237     if (temp.size() < 8)
   232     if (temp.size() < 8)
   238     {
   233     {
   239         return false;
   234         return false;
   253 
   248 
   254 /*
   249 /*
   255  * Description : check the validity of URL
   250  * Description : check the validity of URL
   256  * return value: true: the URL is valid, vice versa.
   251  * return value: true: the URL is valid, vice versa.
   257  */
   252  */
   258 EXPORT_C bool IRQUtility::openAdvLink(const QString& aUrl)
   253 bool IRQUtility::openAdvLink(const QString& aUrl)
   259 {
   254 {
   260     bool retval = false;
   255     bool retval = false;
   261     TRAP_IGNORE(retval = openAdvLinkL(aUrl));
   256     TRAP_IGNORE(retval = openAdvLinkL(aUrl));
   262 
   257 
   263     return retval;
   258     return retval;
   264 }
   259 }
   265 
   260 
   266 EXPORT_C bool IRQUtility::identifySongAvailable()
   261 bool IRQUtility::findAppByUid(const int aUid)
   267 {
   262 {
       
   263     if (0 == aUid)
       
   264     {
       
   265         return false;
       
   266     }
       
   267 
   268     RApaLsSession lsSession;
   268     RApaLsSession lsSession;
   269     if( lsSession.Connect() != KErrNone )
   269     if( lsSession.Connect() != KErrNone )
   270     {
   270     {
   271         return false;
   271         return false;
   272     }
   272     }
   273     
   273     
   274     bool ret = false;
   274     bool ret = false;
   275     TUid songRecognitionAppUid = getSongRecognitionAppUid();
   275     TUid appUid = TUid::Uid(aUid);
   276     TApaAppInfo *appInfo = new TApaAppInfo;
   276     TApaAppInfo *appInfo = new TApaAppInfo;
   277     lsSession.GetAllApps();  
   277     lsSession.GetAllApps();  
   278 
   278 
   279     while( KErrNone == lsSession.GetNextApp(*appInfo) )
   279     while( KErrNone == lsSession.GetNextApp(*appInfo) )
   280     {
   280     {
   285             appIsHidden = capability().iAppIsHidden;
   285             appIsHidden = capability().iAppIsHidden;
   286         }
   286         }
   287         
   287         
   288         if(!appIsHidden)
   288         if(!appIsHidden)
   289         {
   289         {
   290             if(songRecognitionAppUid == appInfo->iUid)
   290             if(appUid == appInfo->iUid)
   291             {
   291             {
   292                 ret = true;
   292                 ret = true;
   293                 break;
   293                 break;
   294             }
   294             }
   295         }
   295         }
   297     delete appInfo;
   297     delete appInfo;
   298     lsSession.Close();
   298     lsSession.Close();
   299     return ret;         
   299     return ret;         
   300 }   
   300 }   
   301     
   301     
   302     
       
   303 EXPORT_C bool IRQUtility::openSongRecognition()
       
   304 {       
       
   305     return launchAppByUid(getSongRecognitionAppUid());
       
   306 }
       
   307 
       
   308 void IRQUtility::appendURLL(const IRQPreset& aQIRPreset, CIRIsdsPreset& aCIRIsdsPreset)
   302 void IRQUtility::appendURLL(const IRQPreset& aQIRPreset, CIRIsdsPreset& aCIRIsdsPreset)
   309 {
   303 {
   310     int count = aQIRPreset.urlArray.count();
   304     int count = aQIRPreset.urlArray.count();
   311     for( int i=0; i<count; i++)
   305     for( int i=0; i<count; i++)
   312     {
   306     {
   317       tempServerUrl->SetServerUrl(url);
   311       tempServerUrl->SetServerUrl(url);
   318       tempServerUrl->SetBitRate(aQIRPreset.urlArray[i].bitrate);
   312       tempServerUrl->SetBitRate(aQIRPreset.urlArray[i].bitrate);
   319       aCIRIsdsPreset.iUrlArray->AppendL(tempServerUrl);
   313       aCIRIsdsPreset.iUrlArray->AppendL(tempServerUrl);
   320       CleanupStack::Pop(tempServerUrl);     
   314       CleanupStack::Pop(tempServerUrl);     
   321     } 
   315     } 
       
   316 }
       
   317 
       
   318 
       
   319 bool IRQUtility::launchAppByUid(const int aUid)
       
   320 {
       
   321     if (0 == aUid)
       
   322     {
       
   323         return false;
       
   324     }
       
   325     TUid appUid = TUid::Uid(aUid);
       
   326     
       
   327     RWsSession wsSession;
       
   328     if(KErrNone != wsSession.Connect())
       
   329     {
       
   330         return false;
       
   331     }
       
   332     
       
   333     bool retVal = false;
       
   334     TApaTaskList tasList(wsSession);
       
   335     TApaTask task = tasList.FindApp(appUid);
       
   336 
       
   337     if(task.Exists())
       
   338     {
       
   339         task.BringToForeground();
       
   340         retVal = true;
       
   341     }
       
   342     else
       
   343     {
       
   344         RApaLsSession session;
       
   345         if(KErrNone == session.Connect())
       
   346         {
       
   347             TThreadId threadId;
       
   348             TInt err = session.CreateDocument(KNullDesC, appUid, threadId);
       
   349             if(KErrNone == err)
       
   350             {
       
   351                 retVal = true;
       
   352             }
       
   353             session.Close();
       
   354         }       
       
   355     }
       
   356     
       
   357     wsSession.Flush();    
       
   358     wsSession.Close();
       
   359     return retVal;
   322 }
   360 }
   323 
   361 
   324 bool openAdvLinkL(const QString& aUrl)
   362 bool openAdvLinkL(const QString& aUrl)
   325 {
   363 {
   326     if (aUrl.size() == 0)
   364     if (aUrl.size() == 0)
   379     CleanupStack::PopAndDestroy( &wsSession );
   417     CleanupStack::PopAndDestroy( &wsSession );
   380 
   418 
   381     return ret;
   419     return ret;
   382 }
   420 }
   383 
   421 
   384 bool launchAppByUid(const TUid aUid)
       
   385 {
       
   386     RWsSession wsSession;
       
   387     if(KErrNone != wsSession.Connect())
       
   388     {
       
   389         return false;
       
   390     }
       
   391     
       
   392     bool retVal = false;
       
   393     TApaTaskList tasList(wsSession);
       
   394     TApaTask task = tasList.FindApp(aUid);
       
   395 
       
   396     if(task.Exists())
       
   397     {
       
   398         task.BringToForeground();
       
   399         retVal = true;
       
   400     }
       
   401     else
       
   402     {
       
   403         RApaLsSession session;
       
   404         if(KErrNone == session.Connect())
       
   405         {
       
   406             TThreadId threadId;
       
   407             TInt err = session.CreateDocument(KNullDesC, aUid, threadId);
       
   408             if(KErrNone == err)
       
   409             {
       
   410                 retVal = true;
       
   411             }
       
   412             session.Close();
       
   413         }      	
       
   414     }
       
   415     
       
   416     wsSession.Flush();    
       
   417     wsSession.Close();
       
   418     return retVal;
       
   419 }
       
   420 
       
   421 TUid getSongRecognitionAppUid()
       
   422 {
       
   423     // Create an XQSettingsManager object
       
   424     XQSettingsManager settingsManager;
       
   425     // Create an XQSettingsKey object for a particular central repository item.
       
   426     XQSettingsKey appUidKey(XQSettingsKey::TargetCentralRepository, 
       
   427         KCenrepUidInternetRadio, KSongRecognitionKeyId);
       
   428     
       
   429     // Read the integer value
       
   430     int uidValue = settingsManager.readItemValue(appUidKey, XQSettingsManager::TypeInt).toInt();
       
   431 
       
   432     return TUid::Uid(uidValue);
       
   433 }
       
   434 
       
   435