mobilemessaging/smilui/playersrc/SmilPlayerLinkParser.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2003-2005 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:  
       
    15 *       Parses wanted string:
       
    16 *           Phone numbers
       
    17 *           E-mail addresses
       
    18 *           URL addresses
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 // INCLUDE FILES
       
    25 #include "SmilPlayerLinkParser.h"
       
    26 
       
    27 // Url Address' beginnings
       
    28 _LIT( KHttpUrlAddress, "http://");
       
    29 _LIT( KRtspUrlAddress, "rtsp://");
       
    30 _LIT( KHttpsUrlAddress, "https://");
       
    31 _LIT( KWwwUrlAddress, "www.");
       
    32 _LIT( KWapUrlAddress, "wap.");
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // ----------------------------------------------------------------------------
       
    37 // CSmilPlayerLinkParser::LinkType
       
    38 // Returns given link type.
       
    39 // ----------------------------------------------------------------------------
       
    40 //
       
    41 SmilPlayerLinkParser::TSmilPlayerLinkType
       
    42        SmilPlayerLinkParser::LinkType( const TDesC& aText )
       
    43     {
       
    44     TSmilPlayerLinkType result( ESmilPlayerNotSupported );
       
    45     if ( SearchMailAddress( aText ) )
       
    46         {
       
    47         result = ESmilPlayerMailAddress;
       
    48         }
       
    49 
       
    50     if ( SearchUrl( aText ) )
       
    51         {
       
    52         result = ESmilPlayerUrlAddress;
       
    53         }
       
    54 
       
    55     if ( SearchPhoneNumber( aText ) )
       
    56         {
       
    57         result = ESmilPlayerPhoneNumber; 
       
    58         }
       
    59     return result;
       
    60     }
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // CSmilPlayerLinkParser::ParseUrl
       
    64 // Parses URL from given text string.
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 TBool SmilPlayerLinkParser::ParseUrl( const TDesC& aType,
       
    68                                              const TDesC& aText )
       
    69     {
       
    70     if( aText.Length() >= aType.Length() ) 
       
    71         {
       
    72         if( aText.Left( aType.Length() ).MatchF( aType ) != KErrNotFound )
       
    73             {
       
    74             return ETrue;
       
    75             }
       
    76         }
       
    77     return EFalse;
       
    78     }
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // SmilPlayerLinkParser::SearchMailAddress
       
    82 // Returns whether given string contains mail address.
       
    83 // ----------------------------------------------------------------------------
       
    84 //
       
    85 TBool SmilPlayerLinkParser::SearchMailAddress( const TDesC& aText )
       
    86     {
       
    87     if( aText.Length() >= KMailToString().Length() ) 
       
    88         {
       
    89         if( aText.Left( KMailToString().Length() ).MatchF(
       
    90                         KMailToString ) != KErrNotFound )
       
    91             {
       
    92             return ETrue;
       
    93             }
       
    94         }
       
    95 
       
    96     return EFalse;
       
    97     }
       
    98 
       
    99 // ----------------------------------------------------------------------------
       
   100 // SmilPlayerLinkParser::SearchPhoneNumber
       
   101 // Returns whether given string contains phone number.
       
   102 // ----------------------------------------------------------------------------
       
   103 //
       
   104 TBool SmilPlayerLinkParser::SearchPhoneNumber( const TDesC& aText )
       
   105     {
       
   106     if( aText.Length() >= KPhoneToString().Length() ) 
       
   107         {
       
   108         if( aText.Left( KPhoneToString().Length() ).MatchF( 
       
   109                         KPhoneToString ) != KErrNotFound )
       
   110             {
       
   111             return ETrue;
       
   112             }
       
   113         }
       
   114 
       
   115     return EFalse;
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // SmilPlayerLinkParser::SearchUrl
       
   120 // Returns whether given string contains URL address.
       
   121 // ----------------------------------------------------------------------------
       
   122 //
       
   123 TBool SmilPlayerLinkParser::SearchUrl( const TDesC& aText )
       
   124     {
       
   125     TBool wasValidUrl = EFalse;
       
   126 
       
   127     // Search for http://
       
   128     wasValidUrl = ParseUrl( KHttpUrlAddress, aText );
       
   129 
       
   130     if ( !wasValidUrl )
       
   131         { // Search for https://
       
   132         wasValidUrl = ParseUrl( KHttpsUrlAddress, aText );
       
   133         }
       
   134 
       
   135     if ( !wasValidUrl )
       
   136         { // Search for rtsp://
       
   137         wasValidUrl = ParseUrl( KRtspUrlAddress, aText );
       
   138         }
       
   139 
       
   140     if ( !wasValidUrl )
       
   141         { // Search for www.
       
   142         wasValidUrl = ParseUrl( KWwwUrlAddress, aText );
       
   143         }
       
   144 
       
   145     if ( !wasValidUrl )
       
   146         { // Search for wap.
       
   147         wasValidUrl = ParseUrl( KWapUrlAddress, aText );
       
   148         }
       
   149 
       
   150     return wasValidUrl;
       
   151     }
       
   152 
       
   153 // End of File