idlefw/plugins/shortcutplugin/src/caiscuttargetnewmsg.cpp
branchRCL_3
changeset 9 d0529222e3f0
parent 4 1a2a00e78665
child 10 5ef93ea513cb
child 18 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 9:d0529222e3f0
     1 /*
       
     2 * Copyright (c) 2005-2008 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 new message shortcut target
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <sendui.h>         // For CSendUi
       
    20 #include <Sendnorm.rsg>     // For settings not ok - error dialog
       
    21 #include <gulicon.h>        // For CGulIcon
       
    22 #include <SenduiMtmUids.h>
       
    23 #include <cemailaccounts.h> // For finding out available email account counts
       
    24 #include <AknsUtils.h>      // For AknsUtils
       
    25 
       
    26 #include <avkon.rsg>
       
    27 
       
    28 #include <data_caging_path_literals.hrh>
       
    29 #include <AknGlobalNote.h>  // For error note
       
    30 #include <MuiuMsvUiServiceUtilities.h>
       
    31 #include <StringLoader.h>
       
    32 
       
    33 #include "aiscutcontentmodel.h"
       
    34 #include "caiscuttargetnewmsg.h"
       
    35 #include "caiscutengine.h"
       
    36 #include <aiscutplugin.mbg>
       
    37 #include <e32property.h>
       
    38 #include <connect/sbdefs.h>
       
    39 #include <filemanagerbkupchecker.rsg>
       
    40 #include <aiscuttexts.rsg>
       
    41 
       
    42 #include "debug.h"
       
    43 
       
    44 using namespace conn;
       
    45 const TInt KMaxBufSize = 256;
       
    46 
       
    47 // Status keys adopted from FileManager to be used when checking file backup status
       
    48 const TUid KPSUidFileManagerStatus = { 0x101F84EB }; // File Manager SID
       
    49 const TUint32 KFileManagerBkupStatus = 0x00000001;
       
    50 
       
    51 enum TFileManagerBkupStatusType
       
    52     {
       
    53     EFileManagerBkupStatusUnset   = 0x00000000,
       
    54     EFileManagerBkupStatusBackup  = 0x00000001,
       
    55     EFileManagerBkupStatusRestore = 0x00000002
       
    56     };
       
    57 
       
    58 TBool PhoneIsInBackupOrRestoreMode()
       
    59     {
       
    60     TBool backupOrRestore = EFalse;
       
    61     
       
    62     TInt status( EFileManagerBkupStatusUnset );
       
    63     TInt err( RProperty::Get( KPSUidFileManagerStatus, KFileManagerBkupStatus, status ) );
       
    64     if ( status == EFileManagerBkupStatusBackup )
       
    65     {
       
    66     	backupOrRestore = ETrue;
       
    67     	return backupOrRestore;
       
    68     }
       
    69 
       
    70     // Get the back-up restore key, return EFalse if we can't get the key
       
    71     TInt keyVal = 0;
       
    72     const TInt error = RProperty::Get( KUidSystemCategory, conn::KUidBackupRestoreKey, keyVal );
       
    73     if( error )
       
    74         {
       
    75         return backupOrRestore;
       
    76         }
       
    77 
       
    78     const conn::TBURPartType partType = static_cast< conn::TBURPartType >( keyVal & conn::KBURPartTypeMask );
       
    79     if  (keyVal != 0)
       
    80         {
       
    81         switch(partType)
       
    82             {
       
    83         case EBURUnset:
       
    84         case EBURNormal:
       
    85             break;
       
    86         case EBURBackupFull:
       
    87         case EBURBackupPartial:
       
    88         case EBURRestoreFull:
       
    89         case EBURRestorePartial:
       
    90             backupOrRestore = ETrue;
       
    91             break;
       
    92             }
       
    93         }
       
    94     //
       
    95 
       
    96     return backupOrRestore;
       
    97     }
       
    98 
       
    99 // ======== MEMBER FUNCTIONS ========
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 CAiScutTargetNewMsg::CAiScutTargetNewMsg(CAiScutEngine& aEngine, TShortcutType aType)
       
   106     : CAiScutTarget(aEngine, aType)
       
   107 {
       
   108 }
       
   109 
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CAiScutTargetNewMsg::ConstructL(const TAiScutParser& aParser)
       
   116 {
       
   117     iDefinition = aParser.Get(EScutDefComplete).AllocL();
       
   118 
       
   119     iAppUid       = KNullUid;
       
   120     iViewUid.iUid = -1;
       
   121 
       
   122     switch (aParser.Type())
       
   123     {
       
   124     case EScutNewMessage:
       
   125         iMtm          = KSenduiMtmUniMessageUid;
       
   126         iAppUid.iUid  = KScutUnifiedEditorUidValue;
       
   127         break;
       
   128 
       
   129     case EScutNewEmail:
       
   130         iMtm          = KSenduiMtmSmtpUid;
       
   131         iAppUid.iUid  = KScutEmailEditorUidValue;
       
   132         break;
       
   133 
       
   134 #ifdef __SYNCML_DS_EMAIL
       
   135     case EScutNewSyncMLMail:
       
   136         iMtm          = KSenduiMtmSyncMLEmailUid;
       
   137         iAppUid.iUid  = KScutEmailEditorUidValue; // check that these uids are in sync with aiscuttexts.rss
       
   138         iViewUid.iUid = KScutSyncMlEmailUidValue;
       
   139         break;
       
   140 #endif
       
   141 
       
   142     case EScutNewPostcard:
       
   143         iMtm          = KSenduiMtmPostcardUid;
       
   144         iAppUid.iUid  = KScutPostcardEditorUidValue;
       
   145         break;
       
   146 
       
   147     case EScutNewAudioMsg:
       
   148         iMtm          = KSenduiMtmAudioMessageUid;
       
   149         iAppUid.iUid  = KScutAmsEditorUidValue;
       
   150         break;
       
   151 
       
   152     case EScutNewMsgType:
       
   153         iAppUid.iUid  = KScutMessagingCenterUidValue; // check that these uids are in sync with aiscuttexts.rss
       
   154         iViewUid.iUid = KScutMessagingCenterUidValue;
       
   155         // fallthrough
       
   156     default:
       
   157         iMtm = KNullUid;
       
   158         break;
       
   159     }
       
   160 }
       
   161 
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 CAiScutTargetNewMsg* CAiScutTargetNewMsg::NewL(
       
   168     CAiScutEngine& aEngine, TShortcutType aType, const TAiScutParser& aParser)
       
   169 {
       
   170     CAiScutTargetNewMsg* self = new (ELeave) CAiScutTargetNewMsg(aEngine, aType);
       
   171 
       
   172     CleanupStack::PushL(self);
       
   173     self->ConstructL(aParser);
       
   174     CleanupStack::Pop(self);
       
   175 
       
   176     return self;
       
   177 }
       
   178 
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 CAiScutTargetNewMsg::~CAiScutTargetNewMsg()
       
   185 {
       
   186     delete iCaption;
       
   187     delete iShortCaption;
       
   188     delete iDefinition;
       
   189 
       
   190 }
       
   191 
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // Returns the shortcut definition string.
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 TPtrC CAiScutTargetNewMsg::Definition() const
       
   198 {
       
   199     return TPtrC(*iDefinition);
       
   200 }
       
   201 
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // Returns the shortcut target caption.
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 TInt CAiScutTargetNewMsg::GetCaption(TPtrC& aDes, TAiScutAppTitleType aTitleType) const
       
   208 {
       
   209     TRAP_IGNORE(GetCaptionL(aTitleType));
       
   210 
       
   211     if (aTitleType == EAiScutSkeyTitle)
       
   212     {
       
   213         aDes.Set(iShortCaption ? *iShortCaption : KNullDesC());
       
   214     }
       
   215     else
       
   216     {
       
   217         aDes.Set(iCaption ? *iCaption : KNullDesC());
       
   218     }
       
   219 
       
   220     return 0;
       
   221 }
       
   222 
       
   223 // ---------------------------------------------------------------------------
       
   224 // Returns the shortcut target caption.
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CAiScutTargetNewMsg::GetCaptionL(TAiScutAppTitleType aTitleType) const
       
   228 {
       
   229     HBufC* titlePtr = HBufC::NewLC(KMaxBufSize);
       
   230     TPtr titlePtrP = titlePtr->Des();
       
   231 
       
   232 
       
   233     // Use lazy evaluation, create the caption only when it is first needed.
       
   234     if (aTitleType == EAiScutSkeyTitle)
       
   235     {
       
   236         if (!iShortCaption)
       
   237         {
       
   238             if (iEngine.GetAppTitle(iAppUid, iViewUid, titlePtrP, aTitleType))
       
   239             {
       
   240                 iShortCaption = titlePtrP.AllocL();
       
   241             }
       
   242         }
       
   243     }
       
   244     else
       
   245     {
       
   246         if (!iCaption)
       
   247         {
       
   248             if (iEngine.GetAppTitle(iAppUid, iViewUid, titlePtrP, aTitleType))
       
   249             {
       
   250                 iCaption = titlePtrP.AllocL();
       
   251             }
       
   252         }
       
   253     }
       
   254 
       
   255     CleanupStack::PopAndDestroy(titlePtr);
       
   256 }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // Returns the shortcut target icon.
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 TInt CAiScutTargetNewMsg::GetIcon(CGulIcon*& aIcon) const
       
   263 {
       
   264     if ( CAiScutTarget::GetIcon(aIcon) != KErrNone )
       
   265         {
       
   266         TRAP_IGNORE(GetIconL(aIcon));
       
   267         }
       
   268 
       
   269 
       
   270     return 0;
       
   271 }
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // Returns the shortcut target icon.
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 void CAiScutTargetNewMsg::GetIconL(CGulIcon*& aIcon) const
       
   278 {
       
   279 
       
   280     CGulIcon* tempIcon = NULL;
       
   281     TBool useAppIcon = ETrue;
       
   282     TInt iconId = 0;
       
   283     TInt maskId = 0;
       
   284 
       
   285     if (iMtm == KNullUid)
       
   286     {
       
   287         useAppIcon = EFalse;
       
   288         iconId = EMbmAiscutpluginQgn_menu_mce_sel_mes;
       
   289         maskId = EMbmAiscutpluginQgn_menu_mce_sel_mes_mask;
       
   290     }
       
   291 #ifdef __SYNCML_DS_EMAIL
       
   292     else if (iMtm.iUid == KSenduiMtmSyncMLEmailUidValue)
       
   293     {
       
   294         useAppIcon = EFalse;
       
   295         iconId = EMbmAiscutpluginQgn_menu_mce_syncmail;
       
   296         maskId = EMbmAiscutpluginQgn_menu_mce_syncmail_mask;
       
   297     }
       
   298 #endif
       
   299 
       
   300     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   301 
       
   302     if (useAppIcon)
       
   303     {
       
   304         CFbsBitmap* bitmap = NULL;
       
   305         CFbsBitmap* mask   = NULL;
       
   306 
       
   307         AknsUtils::CreateAppIconLC(skin, iAppUid, EAknsAppIconTypeList, bitmap, mask);
       
   308         tempIcon = CGulIcon::NewL(bitmap, mask);
       
   309         CleanupStack::Pop(2); // Bitmap and mask. They have to be popped out by number
       
   310                               // because the order in which they are pushed in is undefined.
       
   311     }
       
   312     else
       
   313     {
       
   314         TFileName pluginIconFile(KDC_APP_BITMAP_DIR);
       
   315         pluginIconFile.Append(KBitmapFile);
       
   316 
       
   317         tempIcon = AknsUtils::CreateGulIconL(
       
   318             skin,
       
   319             KAknsIIDQgnPropAiShortcut,
       
   320             pluginIconFile,
       
   321             iconId,
       
   322             maskId
       
   323             );
       
   324     }
       
   325 
       
   326     //Do not need to sets the bitmap and mask to be owned externally
       
   327 
       
   328 
       
   329     aIcon = tempIcon;
       
   330 }
       
   331 
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // Checks if the shortcut target is accessible.
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 TBool CAiScutTargetNewMsg::IsAccessibleL(TInt /*aCheckType*/)
       
   338 {
       
   339     return ETrue;
       
   340 }
       
   341 
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // Launches the message editor to send an Sms, Mms or Email message.
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 void CAiScutTargetNewMsg::LaunchL()
       
   348     {
       
   349     if( PhoneIsInBackupOrRestoreMode() )
       
   350         {
       
   351         CAknGlobalNote* note = CAknGlobalNote::NewLC();
       
   352 
       
   353         HBufC* prompt = StringLoader::LoadLC( R_QTN_AI_SCUT_OPERATION_DISABLED );
       
   354 
       
   355         note->SetSoftkeys( R_AVKON_SOFTKEYS_OK_EMPTY );
       
   356         note->ShowNoteL( EAknGlobalInformationNote, *prompt );
       
   357 
       
   358         CleanupStack::PopAndDestroy( prompt );
       
   359         CleanupStack::PopAndDestroy( note );
       
   360         return;
       
   361         }
       
   362 
       
   363   CSendUi* sendUi = CSendUi::NewLC();
       
   364 
       
   365     if (iMtm == KNullUid)
       
   366         {
       
   367         TSendingCapabilities capabs(0, 0, TSendingCapabilities::ESupportsEditor);
       
   368 
       
   369         TUid uid = sendUi->ShowTypedQueryL(CSendUi::EWriteMenu, NULL, capabs, NULL, KNullDesC);
       
   370         if (uid != KNullUid)
       
   371             {
       
   372             sendUi->ServiceCapabilitiesL(uid, capabs);
       
   373             sendUi->CreateAndSendMessageL(uid, NULL, KNullUid, EFalse); // launch standalone
       
   374             }
       
   375         }
       
   376     else
       
   377         {
       
   378         if( iMtm == KSenduiMtmSmtpUid ) // pop, imap, smtp
       
   379             {
       
   380             RArray<TPopAccount> popAccounts;
       
   381             RArray<TImapAccount> imapAccounts;
       
   382             RArray<TSmtpAccount> smtpAccounts;
       
   383             CEmailAccounts* emailAccounts = CEmailAccounts::NewLC();
       
   384             // check that mailbox exists or else display error message
       
   385             emailAccounts->GetPopAccountsL(popAccounts);
       
   386             emailAccounts->GetImapAccountsL(imapAccounts);
       
   387             emailAccounts->GetSmtpAccountsL(smtpAccounts);
       
   388             CleanupStack::PopAndDestroy(emailAccounts);
       
   389 
       
   390             if( iMtm == KSenduiMtmSmtpUid &&
       
   391                 (popAccounts.Count() + imapAccounts.Count() + smtpAccounts.Count() ) > 0 )
       
   392                 {
       
   393                 sendUi->CreateAndSendMessageL(iMtm, NULL, KNullUid, EFalse); // launch standalone
       
   394                 }
       
   395             else
       
   396                 {
       
   397                 ShowErrorNote();
       
   398                 }
       
   399             popAccounts.Reset();
       
   400             imapAccounts.Reset();
       
   401             smtpAccounts.Reset();
       
   402             }
       
   403         else if ( iMtm == KSenduiMtmSyncMLEmailUid ) // syncml
       
   404             {
       
   405             CMsvEntrySelection* sel =
       
   406                 MsvUiServiceUtilities::GetListOfAccountsWithMTML( *(iEngine.MsvSession()), iMtm );
       
   407             TInt accounts = sel->Count();
       
   408             delete sel;
       
   409             if ( accounts > 0 )
       
   410                 {
       
   411                 sendUi->CreateAndSendMessageL(iMtm, NULL, KNullUid, EFalse); // launch standalone
       
   412                 }
       
   413             else
       
   414                 {
       
   415                 ShowErrorNote();
       
   416                 }
       
   417             }
       
   418         else
       
   419             {
       
   420             sendUi->CreateAndSendMessageL(iMtm, NULL, KNullUid, EFalse); // launch standalone
       
   421             }
       
   422 
       
   423     }
       
   424     CleanupStack::PopAndDestroy(sendUi);
       
   425 }
       
   426 
       
   427 void CAiScutTargetNewMsg::ShowErrorNote()
       
   428     {
       
   429      TRAP_IGNORE(
       
   430         // Display global error note.
       
   431         CAknGlobalNote* note = CAknGlobalNote::NewLC();
       
   432         HBufC* prompt = StringLoader::LoadLC( R_SENDUI_SETTINGS_NOT_OK );
       
   433         note->ShowNoteL( EAknGlobalErrorNote, *prompt );
       
   434         CleanupStack::PopAndDestroy( prompt );
       
   435         CleanupStack::PopAndDestroy( note );
       
   436     ); // end TRAP_IGNORE
       
   437     }
       
   438 
       
   439 // ---------------------------------------------------------------------------
       
   440 // Return application uid this target launches.
       
   441 // ---------------------------------------------------------------------------
       
   442 //
       
   443 TUid CAiScutTargetNewMsg::AppUid() const
       
   444 {
       
   445     return iAppUid;
       
   446 }
       
   447 
       
   448 // End of File.