static bool handleOtherSchemes(const QUrl &url) { QString encUrl(QString::fromUtf8(url.toEncoded())); TPtrC urlPtr(qt_QString2TPtrC(encUrl)); TRAPD( err, handleOtherSchemesL(urlPtr)); return err ? false : true; }
// The biggest advantage of schemehandler is that it can handle // wide range of schemes and is extensible by plugins static bool handleUrl(const QUrl &url) { if (!url.isValid()) return false; QString urlString(url.toString()); TPtrC urlPtr(qt_QString2TPtrC(urlString)); TRAPD( err, handleUrlL(urlPtr)); return err ? false : true; }
// ----------------------------------------------------------------------------- // CBrCtlSampleAppLinkResolver::GetFileNameL // Translate the file name from a URL to a valid file name in the system. // ----------------------------------------------------------------------------- // TBool CBrCtlSampleAppLinkResolver::GetFileNameL(const TDesC& aFileName) { // This function accepts URLs in the following format: // file://filename.xxx // file:///filename.xxx // file://c:/filename.xxx // file:///c:/filename.xxx // _LIT(KFileScheme, "file://"); _LIT(KDefaultDrivePath, "C:\\"); _LIT(KPathChar, "\\"); TInt count; TInt index = 0; TBool drvLetter = EFalse; TUint16 c; // Verify the file scheme TPtrC urlPtr(aFileName); if (urlPtr.FindF(KFileScheme) != 0) { return EFalse; } urlPtr.Set(urlPtr.Mid(KFileScheme().Length())); // make sure there are enough characters in the filename before // trying to check them count = urlPtr.Length(); if(count == 0) { return EFalse; // no filename, so can't look at urlPtr[0] } // Skip the first '/' if there is one if (urlPtr[0] == '/') { urlPtr.Set(urlPtr.Mid(1)); } count = urlPtr.Length(); // Is there a drive letter? if(count > 1) { // can check for drive letter if (urlPtr[1 + index] == ':') { drvLetter = ETrue; } } if(drvLetter == EFalse) { // 3 additional characters for the string "c:\" count = urlPtr.Length() + 3; } iFileName = HBufC::NewL(count); if (!drvLetter) { iFileName->Des().Append(KDefaultDrivePath); } TBool fragment(EFalse); // Convert relative path containing /./ and /../ to absolute path for (; index < urlPtr.Length() && !fragment; index ++) { switch(urlPtr[index]) { case '#': //Check if there is a fragment '#' { fragment = ETrue; continue; // Just stop there } case '/': { iFileName->Des().Append(KPathChar); break; } case '.': { if (index > 1 && urlPtr[index - 1] == '/') { if (index < count - 1 && urlPtr[index + 1] == '/') { index ++; // skip ./ break; } if (index > 2 && index < count - 3 && urlPtr[index + 1] == '.' && urlPtr[index + 2] == '/') { TInt i = index - 2; for (; i > 0 && urlPtr[i] != '/'; i--) {} // skip /../ iFileName->Des().SetLength(iFileName->Des().Length() - (index - i)); index += 2; break; } } } // no break //lint -fallthrough default: { c = urlPtr[index]; iFileName->Des().Append(&c, 1); break; } } // end of switch } return ETrue; }
// ----------------------------------------------------------------------------- // CWidgetUiObserver::TranslateURLToFilenameL // Translate the file name from a URL to a valid file name in the system. // ----------------------------------------------------------------------------- // TBool CWidgetUiObserver::TranslateURLToFilenameL( const TDesC& aFileName, const TDesC& aLanguageDir ) { // This function accepts URLs in the following format: // file://filename.xxx // file:///filename.xxx // file://c:/filename.xxx // file:///c:/filename.xxx // c:/dir/file.txt (the browser engine can send these too!) TInt count( 0 ); TInt index( 0 ); TBool drvLetter = EFalse; TUint16 c; HBufC* decodedUrl = EscapeUtils::EscapeDecodeL(aFileName); CleanupStack::PushL( decodedUrl ); // Throw away the intial file:// part, if present TPtrC urlPtr( aFileName ); if (urlPtr.FindF( KFileScheme) == 0 ) { urlPtr.Set( decodedUrl->Mid( KFileScheme().Length() ) ); } // Make sure there are enough characters in the filename before // trying to check them count = urlPtr.Length() + aLanguageDir.Length() + KLprojExt().Length() + KPathChar().Length(); if ( urlPtr.Length() > 0 ) //do nothing for trivial input { // Skip the first '/' if there is one if ( urlPtr[0] == '/' ) { urlPtr.Set( urlPtr.Mid( 1 ) ); } // Is there a drive letter? if ( urlPtr.Length() > 1 ) { // Can check for drive letter if ( urlPtr[1 + index] == ':' ) { drvLetter = ETrue; } } if ( drvLetter == EFalse ) { // Plan for a c:\ type drive prefix to what we already tallied above count += KDefaultDrivePath().Length(); } delete iFileName; iFileName = NULL; iFileName = HBufC::NewL( count ); if ( !drvLetter ) { iFileName->Des().Append( KDefaultDrivePath ); } TBool fragment( EFalse ); // Convert relative path containing /./ and /../ to absolute path for ( ; index < urlPtr.Length() && !fragment; index ++ ) { switch ( urlPtr[index] ) { case '#': // Check if there is a fragment '#' { fragment = ETrue; continue; // Just stop there } case '/': { iFileName->Des().Append( KPathChar ); break; } case '.': { if ( index > 1 && urlPtr[index - 1] == '/' ) { if ( index < count - 1 && urlPtr[ index + 1 ] == '/' ) { index ++; // Skip ./ break; } if ( index > 2 && index < count - 3 && urlPtr[ index + 1 ] == '.' && urlPtr[ index + 2 ] == '/' ) { TInt i = index - 2; for ( ; i > 0 && urlPtr[i] != '/'; i-- ) {} // Skip /../ iFileName->Des().SetLength( iFileName->Des().Length() - (index - i) ); index += 2; break; } } } // No break //lint -fallthrough default: { c = urlPtr[ index ]; iFileName->Des().Append( &c, 1 ); break; } } // end of switch } if ( aLanguageDir.Length() ) { TChar backSlash = '\\'; TInt pos = iFileName->Des().LocateReverse( backSlash ); if ( pos != KErrNotFound ) { TPtr p = iFileName->Des(); p.Insert(pos, KLprojExt ); p.Insert(pos, aLanguageDir ); p.Insert(pos, KPathChar ); } } } //Do nothing for any trivial input CleanupStack::PopAndDestroy(1, decodedUrl); // decodedUrl return ETrue; }