idlefw/plugins/shortcutplugin/src/caiscuttargethttp.cpp
branchRCL_3
changeset 8 d0529222e3f0
parent 4 1a2a00e78665
child 11 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 8:d0529222e3f0
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Class for http shortcut target
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <coemain.h>            // For CCoeEnv
       
    20 #include <w32std.h>             // For RWsSession
       
    21 #include <apgtask.h>            // For TApaTaskList
       
    22 #include <gulicon.h>            // For CGulIcon
       
    23 #include <AknsUtils.h>          // For AknsUtils
       
    24 #include <data_caging_path_literals.hrh>
       
    25 
       
    26 #include "caiscuttargethttp.h"
       
    27 #include "caiscutengine.h"
       
    28 #include <aiscutplugin.mbg>
       
    29 
       
    30 #include "debug.h"
       
    31 
       
    32 // ======== MEMBER FUNCTIONS ========
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CAiScutTargetHttp::CAiScutTargetHttp(CAiScutEngine& aEngine, TShortcutType aType)
       
    39     : CAiScutTarget(aEngine, aType)
       
    40 {
       
    41 }
       
    42 
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void CAiScutTargetHttp::ConstructL(const TAiScutParser& aParser)
       
    49 {
       
    50     iDefinition = aParser.Get( EScutDefComplete ).AllocL();
       
    51     iChecksum = TUid::Uid( aParser.ChecksumForString( *iDefinition) );
       
    52     
       
    53     // Get the possible custom title string from the parser
       
    54     iCaption = HBufC::NewL( iDefinition->Length() ); 
       
    55     TPtr captionPtr = iCaption->Des();
       
    56     TInt err = aParser.CustomTitle( captionPtr );    
       
    57     
       
    58     if ( err != KErrNone || iCaption->Length() <= 0 )
       
    59         {
       
    60         delete iCaption;
       
    61         iCaption = NULL;
       
    62         }
       
    63     TPtr defPtr = iDefinition->Des();    
       
    64     // we need to strip the possible icon definitions away from 
       
    65     // the URL as they are not part of it.
       
    66     aParser.RemoveExtraDefinitionsL( defPtr );
       
    67 }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CAiScutTargetHttp* CAiScutTargetHttp::NewL(
       
    75     CAiScutEngine& aEngine, TShortcutType aType, const TAiScutParser& aParser)
       
    76 {
       
    77     CAiScutTargetHttp* self = new (ELeave) CAiScutTargetHttp(aEngine, aType);
       
    78 
       
    79     CleanupStack::PushL(self);
       
    80     self->ConstructL(aParser);
       
    81     CleanupStack::Pop(self);
       
    82 
       
    83     return self;
       
    84 }
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 CAiScutTargetHttp::~CAiScutTargetHttp()
       
    92 {
       
    93     delete iDefinition;
       
    94     delete iCaption;
       
    95 }
       
    96 
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Returns the shortcut definition string.
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 TPtrC CAiScutTargetHttp::Definition() const
       
   103 {
       
   104     return iDefinition ? TPtrC(*iDefinition) : TPtrC();
       
   105 }
       
   106 
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // Returns the shortcut target caption.
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 TInt CAiScutTargetHttp::GetCaption(TPtrC& aDes, TAiScutAppTitleType /*aTitleType*/) const
       
   113 {
       
   114     // Custom title is fetched when constructing. If no custom
       
   115     // title then use part of the URL as title
       
   116     if ( !iCaption )
       
   117     {        
       
   118         TUriParser parser;
       
   119         TInt err = parser.Parse(*iDefinition);
       
   120 
       
   121         if (err == KErrNone)
       
   122             {
       
   123             // Remove scheme from the url.
       
   124             iCaption = parser.Extract(EUriHost).Alloc();
       
   125             }
       
   126         else
       
   127             {
       
   128             iCaption = iDefinition->Alloc();
       
   129             }
       
   130     }
       
   131 
       
   132     aDes.Set(*iCaption);
       
   133 
       
   134     return 0;
       
   135 }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // Returns the shortcut target icon.
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 TInt CAiScutTargetHttp::GetIcon(CGulIcon*& aIcon) const
       
   143 {
       
   144 
       
   145     if ( CAiScutTarget::GetIcon(aIcon) != KErrNone )
       
   146         {
       
   147         CGulIcon* tempIcon = NULL;
       
   148 
       
   149         TFileName pluginIconFile(KDC_APP_BITMAP_DIR);
       
   150         pluginIconFile.Append(KBitmapFile);
       
   151 
       
   152         TRAP_IGNORE(
       
   153             tempIcon = AknsUtils::CreateGulIconL(
       
   154                 AknsUtils::SkinInstance(),
       
   155                 KAknsIIDQgnPropAiShortcut,
       
   156                 pluginIconFile,
       
   157                 EMbmAiscutpluginQgn_menu_url,
       
   158                 EMbmAiscutpluginQgn_menu_url_mask
       
   159                 )
       
   160             );
       
   161 
       
   162         aIcon = tempIcon;
       
   163         }
       
   164     return 0;
       
   165 }
       
   166 
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // Checks if the shortcut target is accessible.
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 TBool CAiScutTargetHttp::IsAccessibleL(TInt /*aCheckType*/)
       
   173 {
       
   174     return (iDefinition->Length() > 0);
       
   175 }
       
   176 
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // Launches the browser
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CAiScutTargetHttp::LaunchL()
       
   183 {
       
   184     // Store the http address directly in the browser parameter format.
       
   185     // For example "4 http://www.nokia.com". 4 = open an url.
       
   186     HBufC* param = HBufC::NewLC(iDefinition->Length() + KOpenUrlParam().Length());
       
   187     param->Des().Copy(KOpenUrlParam());
       
   188     param->Des().Append(*iDefinition);
       
   189 
       
   190     __PRINT( __DBG_FORMAT("XAI: CAiScutTargetHttp::LaunchL '%S' "), param);
       
   191 
       
   192     TApaTaskList taskList(iEngine.Env()->WsSession());
       
   193     TApaTask task = taskList.FindApp(KScutBrowserUid);
       
   194 
       
   195     if (task.Exists())
       
   196     {
       
   197         HBufC8* param8 = HBufC8::NewLC(param->Length());
       
   198         param8->Des().Copy(*param);
       
   199         task.SendMessage(KNullUid, *param8); // Uid is not used.
       
   200         CleanupStack::PopAndDestroy(param8);
       
   201     }
       
   202     else
       
   203     {
       
   204         TThreadId id;
       
   205         User::LeaveIfError(iEngine.ApaSession().StartDocument(
       
   206             *param, KScutBrowserUid, id));
       
   207     }
       
   208 
       
   209     CleanupStack::PopAndDestroy(param);
       
   210 }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // Return application uid this target launches.
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 TUid CAiScutTargetHttp::AppUid() const
       
   217 {
       
   218     return KScutBrowserUid;
       
   219 }
       
   220 
       
   221 TUid CAiScutTargetHttp::AdditionalUid() const
       
   222 {
       
   223     return iChecksum;
       
   224 }
       
   225 
       
   226 // End of File.