menucontentsrv/handlersrc/menuurlhandler.cpp
branchRCL_3
changeset 114 a5a39a295112
equal deleted inserted replaced
113:0efa10d348c0 114:a5a39a295112
       
     1 /*
       
     2 * Copyright (c) 2009 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 *
       
    16 */
       
    17 #include "menuurlhandler.h"
       
    18 #include "menuuninstalloperation.h"
       
    19 #include "menucompletedoperation.h"
       
    20 #include "mcsmenuitem.h"
       
    21 #include "mcsdef.h"
       
    22 
       
    23 #include <w32std.h>
       
    24 #include <apgtask.h>
       
    25 #include <apgcli.h>
       
    26 #include <AknTaskList.h>
       
    27 #include <schemehandler.h>
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =======================
       
    30 
       
    31 // ---------------------------------------------------------
       
    32 // CMenuUrlHandler::~CMenuUrlHandler
       
    33 // ---------------------------------------------------------
       
    34 //
       
    35 CMenuUrlHandler::~CMenuUrlHandler()
       
    36     {
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------
       
    40 // CMenuUrlHandler::NewL
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 CMenuUrlHandler* CMenuUrlHandler::NewL( RMenu &aMenu )
       
    44     {
       
    45     CMenuUrlHandler* handler = new (ELeave) CMenuUrlHandler( aMenu );
       
    46     CleanupStack::PushL( handler );
       
    47     handler->ConstructL();
       
    48     CleanupStack::Pop( handler );
       
    49     return handler;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // CMenuUrlHandler::CMenuUrlHandler
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 CMenuUrlHandler::CMenuUrlHandler( RMenu &aMenu )
       
    57 : CMenuHandlerPlugin( aMenu )
       
    58     {
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------
       
    62 // CMenuUrlHandler::ConstructL
       
    63 // ---------------------------------------------------------
       
    64 //
       
    65 void CMenuUrlHandler::ConstructL()
       
    66     {
       
    67     BaseConstructL();
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // CMenuUrlHandler::SupportsType
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 TBool CMenuUrlHandler::SupportsType( const TDesC& aType )
       
    75     {
       
    76     if ( !aType.Compare( KMenuTypeUrl() ) )
       
    77         {
       
    78         return ETrue;
       
    79         }
       
    80 
       
    81     return EFalse;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // CMenuUrlHandler::HandleCommandL
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 CMenuOperation* CMenuUrlHandler::HandleCommandL(
       
    89         CMenuItem& aItem,
       
    90         const TDesC8& aCommand,
       
    91         const TDesC8& /*aParams*/,
       
    92         TRequestStatus& aStatus )
       
    93     {
       
    94     // Check if item type is correct
       
    95     if( aItem.Type() != KMenuTypeUrl() )
       
    96         {
       
    97         User::Leave( KErrNotSupported );
       
    98         }
       
    99 
       
   100     if( !aCommand.Compare( KMenuCmdOpen() ) )
       
   101         {
       
   102         // Get URL attribute 'url'
       
   103         TBool attrExists = ETrue;
       
   104         TPtrC url = aItem.GetAttributeL( KMenuAttrUrl(), attrExists );
       
   105 
       
   106         if( !attrExists )
       
   107             {
       
   108             User::Leave( KErrCorrupt );
       
   109             }
       
   110 
       
   111         LaunchUrlL( url );
       
   112 
       
   113         return CMenuCompletedOperation::NewL
       
   114                     ( iMenu, CActive::EPriorityStandard, aStatus, KErrNone );
       
   115         }
       
   116 
       
   117     User::Leave( KErrNotSupported );
       
   118     return NULL;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------
       
   122 // CMenuUrlHandler::LaunchUrlL
       
   123 // ---------------------------------------------------------
       
   124 //
       
   125 
       
   126 void CMenuUrlHandler::LaunchUrlL( const TDesC& aUrl )
       
   127     {
       
   128     CSchemeHandler* urlHandler = CSchemeHandler::NewL( aUrl );
       
   129     if( urlHandler )
       
   130         {
       
   131         CleanupStack::PushL( urlHandler );
       
   132         urlHandler->HandleUrlStandaloneL();
       
   133         CleanupStack::PopAndDestroy( urlHandler );
       
   134         }
       
   135     }