idlefw/plugins/shortcutplugin/src/caiscuttargetmessagingview.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 messaging view shortcut target
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <msvuids.h>            // For KMsvRootIndexEntryIdValue
       
    20 #include <gulicon.h>            // For CGulIcon
       
    21 #include <SenduiMtmUids.h>
       
    22 #include <viewcli.h>            // For CVwsSessionWrapper
       
    23 #include <AknsUtils.h>          // For AknsUtils
       
    24 #include <data_caging_path_literals.hrh>
       
    25 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    26 #include <viewclipartner.h>
       
    27 #endif
       
    28 
       
    29 #include "caiscuttargetmessagingview.h"
       
    30 #include "caiscutengine.h"
       
    31 #include <aiscutplugin.mbg>
       
    32 
       
    33 #include "debug.h"
       
    34 
       
    35 // ======== MEMBER FUNCTIONS ========
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CAiScutTargetMessagingView::CAiScutTargetMessagingView(CAiScutEngine& aEngine, TShortcutType aType)
       
    42     : CAiScutTarget(aEngine, aType)
       
    43 {
       
    44 }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 void CAiScutTargetMessagingView::ConstructL(const TAiScutParser& aParser)
       
    52 {
       
    53     iDefinition = aParser.Get(EScutDefComplete).AllocL();
       
    54     // Updates the view name also
       
    55     FindViewIdL();
       
    56 }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CAiScutTargetMessagingView* CAiScutTargetMessagingView::NewL(
       
    64     CAiScutEngine& aEngine, TShortcutType aType, const TAiScutParser& aParser)
       
    65 {
       
    66     CAiScutTargetMessagingView* self = new (ELeave) CAiScutTargetMessagingView(aEngine, aType);
       
    67 
       
    68     CleanupStack::PushL(self);
       
    69     self->ConstructL(aParser);
       
    70     CleanupStack::Pop(self);
       
    71 
       
    72     return self;
       
    73 }
       
    74 
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CAiScutTargetMessagingView::~CAiScutTargetMessagingView()
       
    81 {
       
    82     delete iDefinition;
       
    83     delete iViewName;
       
    84 }
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Returns the shortcut definition string.
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 TPtrC CAiScutTargetMessagingView::Definition() const
       
    92 {
       
    93     return TPtrC(*iDefinition);
       
    94 }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // Returns the shortcut target caption.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 TInt CAiScutTargetMessagingView::GetCaption(TPtrC& aDes, TAiScutAppTitleType /*aTitleType*/) const
       
   102 {
       
   103     aDes.Set(*iViewName);
       
   104     return 0;
       
   105 }
       
   106 
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // Returns the shortcut target icon.
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 TInt CAiScutTargetMessagingView::GetIcon(CGulIcon*& aIcon) const
       
   113 {
       
   114     if ( CAiScutTarget::GetIcon(aIcon) != KErrNone )
       
   115         {
       
   116         TRAP_IGNORE(GetIconL(aIcon));    
       
   117         }
       
   118 
       
   119     return 0;
       
   120 }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // Returns the shortcut target icon.
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CAiScutTargetMessagingView::GetIconL(CGulIcon*& aIcon) const
       
   127 {
       
   128     CGulIcon* tempIcon = NULL;
       
   129 
       
   130     CFbsBitmap* bitmap = NULL;
       
   131     CFbsBitmap* mask   = NULL;
       
   132 
       
   133     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   134     AknsUtils::CreateAppIconLC(skin, KScutMessagingUid, EAknsAppIconTypeList, bitmap, mask);
       
   135 
       
   136     tempIcon = CGulIcon::NewL(bitmap, mask);
       
   137 
       
   138     CleanupStack::Pop(2); // Bitmap and mask. They have to be popped out by number
       
   139                           // because the order in which they are pushed in is undefined.
       
   140 
       
   141     //Do not need to sets the bitmap and mask to be owned externally
       
   142     
       
   143     aIcon = tempIcon;
       
   144 }
       
   145 
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // Checks if the shortcut target is accessible.
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 TBool CAiScutTargetMessagingView::IsAccessibleL(TInt /*aCheckType*/)
       
   152 {
       
   153 	return FindViewIdL() != KErrNotFound;
       
   154 }
       
   155 
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // Launches a remote mailbox.
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CAiScutTargetMessagingView::LaunchL()
       
   162 {
       
   163     TMsvId id(FindViewIdL());
       
   164     if (id != KErrNotFound)
       
   165     {
       
   166         const TVwsViewId viewId(KScutMessagingUid, KScutRemoteMailboxViewId);
       
   167         iEngine.VwsSession()->CreateActivateViewEvent(viewId, TUid::Uid(id), KNullDesC8());
       
   168     }
       
   169 }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // Return application uid this target launches.
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 TUid CAiScutTargetMessagingView::AppUid() const
       
   176 {
       
   177     return KScutMessagingUid;
       
   178 }
       
   179 
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // Tries to find a view id.
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 TMsvId CAiScutTargetMessagingView::FindViewIdL()
       
   186     {
       
   187     TMsvId id(KErrNotFound);
       
   188 
       
   189     TInt mailboxId = KErrNone;
       
   190     TAiScutParser parser;
       
   191     parser.Parse(*iDefinition);          		
       
   192     TLex lex(parser.Get(EScutDefParamValue));
       
   193     lex.Val(mailboxId);
       
   194 
       
   195     if (iEngine.MsvSession())
       
   196     {
       
   197         // KErrNotReady is the only allowed leave code. Engine will trap it and start a timer
       
   198         // to check access later. Other possible leaves emitted by the message server are
       
   199         // substituted with KErrNotReady.
       
   200         CMsvEntry* rootEntry = NULL;
       
   201         TRAPD(err, rootEntry = iEngine.MsvSession()->GetEntryL(KMsvRootIndexEntryIdValue));
       
   202         if (err != KErrNone)
       
   203         {
       
   204             User::Leave(KErrNotReady);
       
   205         }
       
   206 
       
   207 		if(rootEntry)
       
   208 		{
       
   209 	        // No leaving code here since rootEntry is not in cleanup stack.
       
   210     	    for (TInt i = rootEntry->Count(); --i >= 0;)
       
   211         	{
       
   212             	const TMsvEntry& tentry = (*rootEntry)[i];
       
   213 	
       
   214 				__PRINT( __DBG_FORMAT("XAI: CAiScutTargetMessagingView::FindViewIdL id = 0x%x '%S'"),
       
   215 					 tentry.Id(), &tentry.iDetails);
       
   216             	if ((tentry.iMtm == KSenduiMtmImap4Uid || tentry.iMtm == KSenduiMtmPop3Uid) &&
       
   217                 	tentry.Id() == mailboxId)
       
   218 	            {
       
   219     	            id = tentry.Id();
       
   220     	            delete iViewName;
       
   221     	            iViewName = NULL;
       
   222     	            iViewName = tentry.iDetails.AllocL();
       
   223         	        break;
       
   224             	}
       
   225 	        }
       
   226 	
       
   227     	    delete rootEntry;
       
   228         	rootEntry = NULL;
       
   229 			
       
   230 		}
       
   231     }
       
   232 
       
   233     return id;
       
   234 }
       
   235 
       
   236 // End of File.