qtinternetradio/irqcommon/src/irqutility.cpp
changeset 3 ee64f059b8e1
parent 0 09774dfdd46b
child 8 3b03c28289e6
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 #include <QString>
    17 #include <QString>
    18 #include <QByteArray>
    18 #include <QByteArray>
    19 #include <QPixmap>
    19 #include <QFile>
       
    20 #include <QTextStream>
       
    21 #include <QStringList>
       
    22 
       
    23 #include <xqsettingsmanager.h>
       
    24 #include <xqsettingskey.h>
       
    25 
    20 #include <e32err.h>
    26 #include <e32err.h>
    21 #include <fbs.h>
       
    22 #include <apmstd.h>
    27 #include <apmstd.h>
    23 #include <apgcli.h>
    28 #include <apgcli.h>
    24 #include <apgtask.h>
    29 #include <apgtask.h>
    25 #include <coemain.h> 
    30 #include <coemain.h> 
    26 
       
    27 #ifdef _DEBUG
       
    28 #include <QFile>
       
    29 #include <QTextStream>
       
    30 #endif
       
    31 
    31 
    32 #include "irqutility.h"
    32 #include "irqutility.h"
    33 #include "irchannelserverurl.h"
    33 #include "irchannelserverurl.h"
    34 #include "irqisdsdatastructure.h"
    34 #include "irqisdsdatastructure.h"
    35 #include "irisdspreset.h"
    35 #include "irisdspreset.h"
    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);
       
    46 static TUid getSongRecognitionAppUid();
       
    47 static bool launchAppByUid(const TUid aUid);
       
    48   
    42 //
    49 //
    43 //convert the CIRIsdsPreset to the IRQPreset. 
    50 //convert the CIRIsdsPreset to the IRQPreset. 
    44 //
    51 //
    45 EXPORT_C void IRQUtility::convertCIRIsdsPreset2IRQPrest(const CIRIsdsPreset& aCIRIsdsPreset, IRQPreset& aQIRPreset)
    52 EXPORT_C void IRQUtility::convertCIRIsdsPreset2IRQPrest(const CIRIsdsPreset& aCIRIsdsPreset, IRQPreset& aQIRPreset)
    46 {
    53 {
   196  * Description : check the validity of URL
   203  * Description : check the validity of URL
   197  * return value: true: the URL is valid, vice versa.
   204  * return value: true: the URL is valid, vice versa.
   198  */
   205  */
   199 EXPORT_C bool IRQUtility::isValidUrl(const QString& aUrl)
   206 EXPORT_C bool IRQUtility::isValidUrl(const QString& aUrl)
   200 {
   207 {
   201     if (aUrl.size() < 8)
   208     QString temp = aUrl.trimmed();
       
   209     if (temp.size() < 8)
   202     {
   210     {
   203         return false;
   211         return false;
   204     }
   212     }
   205 
   213 
   206     QString prefix7 = aUrl.left(7);
   214     if ( temp.startsWith("http://", Qt::CaseInsensitive) ||
   207     QString prefix6 = aUrl.left(6);
   215          temp.startsWith("rtsp://", Qt::CaseInsensitive) ||
   208 
   216          temp.startsWith("mms://", Qt::CaseInsensitive) ||
   209     if (0 == prefix7.compare("http://", Qt::CaseInsensitive) ||
   217 		 temp.startsWith("mmst://", Qt::CaseInsensitive) ||
   210         0 == prefix7.compare("rtsp://", Qt::CaseInsensitive) ||
   218 		 temp.startsWith("mmsu://", Qt::CaseInsensitive))
   211         0 == prefix6.compare("mms://", Qt::CaseInsensitive))
       
   212     {
   219     {
   213         return true;
   220         return true;
   214     }
   221     }
   215 
   222 
   216     return false;
   223     return false;
   226     TRAP_IGNORE(retval = openAdvLinkL(aUrl));
   233     TRAP_IGNORE(retval = openAdvLinkL(aUrl));
   227 
   234 
   228     return retval;
   235     return retval;
   229 }
   236 }
   230 
   237 
   231 EXPORT_C void IRQUtility::writeLog2File(const QString& aString, bool aDeleteOldFile)
   238 EXPORT_C bool IRQUtility::identifySongAvailable()
       
   239 {
       
   240     RApaLsSession lsSession;
       
   241     if( lsSession.Connect() != KErrNone )
       
   242     {
       
   243         return false;
       
   244     }
       
   245     
       
   246     bool ret = false;
       
   247     TUid songRecognitionAppUid = getSongRecognitionAppUid();
       
   248     TApaAppInfo appInfo;
       
   249     lsSession.GetAllApps();  
       
   250 
       
   251     while( KErrNone == lsSession.GetNextApp(appInfo) )
       
   252     {
       
   253         TBool appIsHidden = EFalse;
       
   254         TApaAppCapabilityBuf capability;
       
   255         if( KErrNone == lsSession.GetAppCapability(capability,appInfo.iUid) )
       
   256         {
       
   257             appIsHidden = capability().iAppIsHidden;
       
   258         }
       
   259         
       
   260         if(!appIsHidden)
       
   261         {
       
   262             if(songRecognitionAppUid == appInfo.iUid)
       
   263             {
       
   264                 ret = true;
       
   265                 break;
       
   266             }
       
   267         }
       
   268     }
       
   269     
       
   270     lsSession.Close();
       
   271     return ret;         
       
   272 }   
       
   273     
       
   274     
       
   275 EXPORT_C bool IRQUtility::openSongRecognition()
   232 {       
   276 {       
   233 #ifdef _DEBUG 
   277     return launchAppByUid(getSongRecognitionAppUid());
   234     QFile file("C:\\data\\QTIRLog.txt");
       
   235     
       
   236     if (file.exists() && aDeleteOldFile)
       
   237     {
       
   238         bool ret = file.remove();
       
   239         if (!ret)
       
   240         {
       
   241             return;
       
   242         }
       
   243     }
       
   244 
       
   245     bool ret = file.open(QIODevice::ReadWrite);    
       
   246     if( !ret )
       
   247     {
       
   248         return;
       
   249     }
       
   250     
       
   251     QTextStream stream(&file);
       
   252     stream << aString;
       
   253     stream << "\r\n";    
       
   254 
       
   255     stream.flush();
       
   256     file.close();
       
   257    
       
   258 #else
       
   259     Q_UNUSED(aString);
       
   260     Q_UNUSED(aDeleteOldFile);
       
   261 #endif
       
   262 
       
   263 }
   278 }
   264 
   279 
   265 void IRQUtility::appendURLL(const IRQPreset& aQIRPreset, CIRIsdsPreset& aCIRIsdsPreset)
   280 void IRQUtility::appendURLL(const IRQPreset& aQIRPreset, CIRIsdsPreset& aCIRIsdsPreset)
   266 {
   281 {
   267     int count = aQIRPreset.urlArray.count();
   282     int count = aQIRPreset.urlArray.count();
   276       aCIRIsdsPreset.iUrlArray->AppendL(tempServerUrl);
   291       aCIRIsdsPreset.iUrlArray->AppendL(tempServerUrl);
   277       CleanupStack::Pop(tempServerUrl);     
   292       CleanupStack::Pop(tempServerUrl);     
   278     } 
   293     } 
   279 }
   294 }
   280 
   295 
   281 bool IRQUtility::openAdvLinkL(const QString& aUrl)
   296 bool openAdvLinkL(const QString& aUrl)
   282 {
   297 {
   283     if (aUrl.size() == 0)
   298     if (aUrl.size() == 0)
   284     {
   299     {
   285         return false;
   300         return false;
   286     }
   301     }
   336     CleanupStack::PopAndDestroy( &wsSession );
   351     CleanupStack::PopAndDestroy( &wsSession );
   337 
   352 
   338     return ret;
   353     return ret;
   339 }
   354 }
   340 
   355 
   341 
   356 bool launchAppByUid(const TUid aUid)
       
   357 {
       
   358     RWsSession wsSession;
       
   359     if(KErrNone != wsSession.Connect())
       
   360     {
       
   361         return false;
       
   362     }
       
   363     
       
   364     bool retVal = false;
       
   365     TApaTaskList tasList(wsSession);
       
   366     TApaTask task = tasList.FindApp(aUid);
       
   367 
       
   368     if(task.Exists())
       
   369     {
       
   370         task.BringToForeground();
       
   371         retVal = true;
       
   372     }
       
   373     else
       
   374     {
       
   375         RApaLsSession session;
       
   376         if(KErrNone == session.Connect())
       
   377         {
       
   378             TThreadId threadId;
       
   379             TInt err = session.CreateDocument(KNullDesC, aUid, threadId);
       
   380             if(KErrNone == err)
       
   381             {
       
   382                 retVal = true;
       
   383             }
       
   384             session.Close();
       
   385         }      	
       
   386     }
       
   387     
       
   388     wsSession.Flush();    
       
   389     wsSession.Close();
       
   390     return retVal;
       
   391 }
       
   392 
       
   393 TUid getSongRecognitionAppUid()
       
   394 {
       
   395     // Create an XQSettingsManager object
       
   396     XQSettingsManager settingsManager;
       
   397     // Create an XQSettingsKey object for a particular central repository item.
       
   398     XQSettingsKey appUidKey(XQSettingsKey::TargetCentralRepository, 
       
   399         KCenrepUidInternetRadio, KSongRecognitionKeyId);
       
   400     
       
   401     // Read the integer value
       
   402     int uidValue = settingsManager.readItemValue(appUidKey, XQSettingsManager::TypeInt).toInt();
       
   403 
       
   404     return TUid::Uid(uidValue);
       
   405 }
       
   406 
       
   407