examples/ForumNokia/S60_3rd_Edition_TextMTM_Example/modules/UiData/src/txti.cpp

00001 // TXTI.CPP
00002 //
00003 // © 2005 Nokia Corporation.  All rights reserved.
00004 //
00005 
00006 
00007 
00008 // class include
00009 #include "txti.h"
00010 
00011 // Standard includes
00012 #include <bautils.h>
00013 #include <coemain.h>    // CCoeEnv
00014 
00015 // Messaging includes
00016 #include <msvstd.hrh>
00017 #include <mtclbase.h> 
00018 #include <mtmdef.hrh>
00019 #include <msvids.h>
00020 #include <msvuids.h>
00021 #include <mtmuidef.hrh>
00022 #include <stringloader.h>        // StringLoader
00023 #include <AknsSkinInstance.h>
00024 #include <AknsUtils.h>
00025 #include <aknsconstants.h>//skinned icon ids
00026 
00027 #include <txti.rsg>
00028 #include <txti.mbg>
00029 
00030 //
00031 #include <akniconutils.h>
00032 // user includes
00033 #include "txclient.h"
00034 #include "txtipan.h"
00035 
00036 // user includes
00037 #include "txut.h"
00038 #include "txtucmds.hrh"
00039 #include "../../Client/inc/txclient.h"
00040 #include "txtipan.h"
00041 
00042 // eikcore.rsg
00043 #include <eikcore.rsg>
00044 
00045 #ifdef __WINS__
00046         #pragma message("If you use an IDE, build from the command line first to create the bitmaps file and .mbg header")
00047 #endif
00048 
00049 // Constants
00050 const TInt KTxtiMtmUdNumberOfIconSets =         3;
00051 const TInt KTxtMtmArrayGranularity  = 18;
00052 
00053 _LIT(KTxtiMtmUdResourceFile,"TXTI.RSC");
00054 _LIT(KTxtiMtmUdBitmapFile,"TXTI.MIF");
00055 #ifdef __WINS__
00056 // on wins, assume built to z:
00057 _LIT(KTxtiMtmUdPath,"\\resource\\messaging\\");
00058 #else
00059 _LIT(KTxtiMtmUdPath,"c:\\resource\\messaging\\");
00060 #endif //WINS
00061 
00062 
00063 // This constant is required so that the series 60 messaging application knows that the TextMTM
00064 // can be used to create a message
00065 #define KUidMtmQueryCanCreateNewMsgValue 0x10008b24
00066 
00067 //
00068 // CTxtiMtmUiData: UI Data MTM
00069 //
00070 
00071 //
00072 //      Construction, initialisation, and destruction
00073 //
00074 
00075 
00076 enum TIcons 
00077         {
00078         EMailRead,
00079         EMailUnread,
00080         EService
00081         };
00082 
00083 EXPORT_C CTxtiMtmUiData* CTxtiMtmUiData::NewL(CRegisteredMtmDll& aRegisteredDll)
00084         {
00085         CTxtiMtmUiData* base=new(ELeave) CTxtiMtmUiData(aRegisteredDll);
00086         CleanupStack::PushL(base);
00087         base->TxtConstructL();
00088         CleanupStack::Pop(base);
00089         return base;
00090         }
00091 
00092 void CTxtiMtmUiData::TxtConstructL()
00093     {
00094     
00095         iIconArrays = new (ELeave) CArrayPtrSeg<CBitmapArray>(KTxtMtmArrayGranularity);
00096         iMtmSpecificFunctions = new (ELeave) CArrayFixFlat<TMtmUiFunction>(KTxtMtmArrayGranularity);
00097 
00098         // Get resource file
00099         TFileName resourceFileName;
00100 
00101     TxtUtils::FindFileL(KTxtiMtmUdResourceFile, KTxtiMtmUdPath, resourceFileName);
00102     iResourceFileName = resourceFileName.AllocL();
00103 
00104         // Now try to find a resource file that matches the particular locale, if one
00105     // exists and the locale has been set
00106         BaflUtils::NearestLanguageFile(iCoeEnv->FsSession(), resourceFileName);
00107 
00108         // Add the resource file to the CCoeEnv
00109     iNewResourceFileOffset=iCoeEnv->AddResourceFileL(resourceFileName);
00110 
00111         // finally, populate the arrays
00112     PopulateArraysL();
00113     }
00114 
00115 
00116 
00117 void CTxtiMtmUiData::TxtCreateBitmapsL(const TDesC& aBitmapFile)
00118         {
00119     CFbsBitmap* bitmap;
00120     CFbsBitmap* bitmapMask;
00121 
00122     TBool found = ETrue;
00123 
00124     for( TInt i = EMbmTxtiRead; 
00125               i < EMbmTxtiLastElement; 
00126               i++ )
00127         {
00128         found = ETrue;
00129         switch( i )
00130             {
00131             // Add to iIconArrays in this order
00132             case EMbmTxtiRead:
00133                 break;
00134             case EMbmTxtiUnread:
00135                 break;
00136             case EMbmTxtiMailbox:
00137                 break;
00138             default:
00139                 found = EFalse;
00140                 break;
00141             }
00142         if( found )
00143             {
00144             CArrayPtrFlat<CFbsBitmap>* array = 
00145                 new (ELeave) CArrayPtrFlat<CFbsBitmap>(  KTxtMtmArrayGranularity  );
00146             CleanupStack::PushL( array );
00147 
00148             array->SetReserveL(  KTxtMtmArrayGranularity ); // AppendLs will not LEAVE
00149             TInt err=0;
00150             TRAP(err, AknIconUtils::CreateIconL(bitmap, bitmapMask, 
00151                                    aBitmapFile, i, i + 1 ));
00152             array->AppendL( bitmap );
00153             bitmap = 0;
00154             array->AppendL( bitmapMask );
00155             bitmapMask = 0;
00156             iIconArrays->AppendL( array );
00157             CleanupStack::Pop( array ); // array
00158             }
00159         }
00160     return;
00161         }
00162 
00163 
00164 
00165 CTxtiMtmUiData::~CTxtiMtmUiData()
00166         {
00167         // remove the resource file we added to the CCoeEnv
00168         if (iNewResourceFileOffset != 0)
00169             iCoeEnv->DeleteResourceFile(iNewResourceFileOffset);
00170     delete iResourceFileName;
00171         
00172         
00173         
00174         
00175         }
00176 
00177 
00178 
00179 // Initialise bitmaps and function information
00180 void CTxtiMtmUiData::PopulateArraysL()
00181         {
00182         // Read MTM-specific operation information
00183         ReadFunctionsFromResourceFileL(R_TEXTUD_FUNCTION_ARRAY);
00184 
00185         // Populate bitmap array
00186         TFileName bitmapFileName;
00187         TxtUtils::FindFileL(KTxtiMtmUdBitmapFile, KTxtiMtmUdPath, bitmapFileName);
00188 
00189         TxtCreateBitmapsL(bitmapFileName);
00190         }
00191 
00192 
00193 
00194 
00195 CTxtiMtmUiData::CTxtiMtmUiData(CRegisteredMtmDll& aRegisteredDll)
00196         :       CBaseMtmUiData(aRegisteredDll)
00197         {
00198     }
00199 
00200 
00201 void CTxtiMtmUiData::GetResourceFileName(TFileName& aFileName) const
00202 // Resource file loading
00203         {
00204         aFileName=*iResourceFileName;
00205         }
00206 
00207 
00208 //
00209 //      MTM-specific functionality
00210 //
00211 
00212 
00213 // Context-sensitive operation query
00214 TInt CTxtiMtmUiData::OperationSupportedL(TInt aOperationId, const TMsvEntry& aContext) const
00215         {
00216         TInt aReasonResourceId=0;       // 0 means "operation is available"
00217 
00218         if (aContext.iMtm!=KUidMsgTypeText)
00219         return R_TEXTUD_NOT_SUPPORTED;
00220 
00221         const TBool isMessage = (aContext.iType==KUidMsvMessageEntry);
00222         const TBool isService = (aContext.iType==KUidMsvServiceEntry);
00223 
00224         if (aOperationId==ETxtuCommandRefreshMBox)
00225                 {
00226                 // Only allow refresh on services
00227                 if (!isService)
00228                 aReasonResourceId=R_TEXTUD_ONLY_REFRESH_SERVICES;
00229                 }
00230         else if (aOperationId==ETxtuCommandMessage)
00231                 {
00232                 // Only allow this command on local messages
00233                 if ( (!isMessage) || (aContext.iServiceId != KMsvLocalServiceIndexEntryId) )
00234                 aReasonResourceId=R_TEXTUD_ONLY_MESSAGES;
00235                 }
00236         return aReasonResourceId;
00237         }
00238 
00239 
00240 TInt CTxtiMtmUiData::QueryCapability(TUid aCapability, TInt& aResponse) const
00241 // Query for capability
00242         {
00243         switch (aCapability.iUid)
00244                 {
00245         // Supported valued capabilities
00246         case KUidMtmQueryMaxBodySizeValue:
00247                 aResponse=KMaxTextMessageSize;
00248                 break;
00249         case KUidMtmQueryMaxTotalMsgSizeValue:
00250                 aResponse=KMaxTextMessageSize;
00251                 break;
00252 
00253         // Supported non-valued capabilities
00254 
00255         case KUidMtmQuerySupportedBodyValue:
00256         case KUidMtmQueryOffLineAllowedValue:
00257         case KUidMtmQueryCanReceiveMsgValue:
00258         case KUidMtmQueryCanSendMsgValue:       
00259         case KUidMtmQueryCanCreateNewMsgValue:
00260                 aResponse=0;
00261                 break;
00262 
00263         default:
00264                 return KErrNotSupported;
00265                 };
00266         return KErrNone;
00267         }
00268 
00269 
00270 const CBaseMtmUiData::CBitmapArray& CTxtiMtmUiData::ContextIcon(const TMsvEntry& aContext, TInt /*aStateFlags*/) const
00271         {
00272         __ASSERT_ALWAYS(aContext.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00273         __ASSERT_ALWAYS(aContext.iType!=KUidMsvAttachmentEntry, Panic(ETxtiMtmUdNoIconForAttachment));
00274 
00275         TInt retIndex=EService;
00276         // If it is a folder or a service use the same icon
00277         if (aContext.iType == KUidMsvServiceEntry ||aContext.iType == KUidMsvFolderEntry )
00278                 {
00279                 retIndex=EService;
00280                 }
00281         else 
00282                 {
00283                 // if it is a message, check whether the message is read or unread      
00284                 // and select the right icon
00285                 if (aContext.iType == KUidMsvMessageEntry)
00286                         retIndex=aContext.Unread() ?  EMailUnread : EMailRead;
00287                 }
00288                 
00289         return *(iIconArrays->At(retIndex));
00290         }
00291 
00292 //
00293 // Context-specific information
00294 //
00295 
00296 TBool CTxtiMtmUiData::CanOpenEntryL(const TMsvEntry& aContext, TInt& aReasonResourceId) const
00297         {
00298         __ASSERT_ALWAYS(aContext.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00299         __ASSERT_ALWAYS(aContext.iType!=KUidMsvAttachmentEntry, Panic(ETxtiMtmUdAttachmentsNotSupported));
00300 
00301         aReasonResourceId=R_EIK_TBUF_NOT_AVAILABLE;
00302         if ( aContext.iType != KUidMsvMessageEntry )
00303                 {
00304                 aReasonResourceId=R_TEXTUD_ONLY_MESSAGES;
00305                 return EFalse;
00306                 }
00307         else
00308                 return ETrue;
00309         }
00310 
00311 
00312 TBool CTxtiMtmUiData::CanCloseEntryL(const TMsvEntry& aContext, TInt& aReasonResourceId) const
00313         {
00314         __ASSERT_ALWAYS(aContext.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00315         __ASSERT_ALWAYS(aContext.iType!=KUidMsvAttachmentEntry, Panic(ETxtiMtmUdAttachmentsNotSupported));
00316 
00317         aReasonResourceId=R_EIK_TBUF_NOT_AVAILABLE;
00318         if ( aContext.iType != KUidMsvMessageEntry )
00319                 {
00320                 aReasonResourceId=R_TEXTUD_ONLY_MESSAGES;
00321                 return EFalse;
00322                 }
00323         else
00324                 return ETrue;
00325         }
00326 
00327 
00328 TBool CTxtiMtmUiData::CanViewEntryL(const TMsvEntry& aContext, TInt& aReasonResourceId) const
00329         {
00330         __ASSERT_ALWAYS(aContext.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00331         __ASSERT_ALWAYS(aContext.iType!=KUidMsvAttachmentEntry, Panic(ETxtiMtmUdAttachmentsNotSupported));
00332 
00333         aReasonResourceId=R_EIK_TBUF_NOT_AVAILABLE;
00334         if ( aContext.iType != KUidMsvMessageEntry )
00335                 {
00336                 aReasonResourceId=R_TEXTUD_ONLY_MESSAGES;
00337                 return EFalse;
00338                 }
00339         else
00340                 return ETrue;
00341         }
00342 
00343 
00344 TBool CTxtiMtmUiData::CanEditEntryL(const TMsvEntry& aContext, TInt& aReasonResourceId) const
00345         {
00346         __ASSERT_ALWAYS(aContext.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00347         __ASSERT_ALWAYS(aContext.iType!=KUidMsvAttachmentEntry, Panic(ETxtiMtmUdAttachmentsNotSupported));
00348 
00349         aReasonResourceId=R_EIK_TBUF_NOT_AVAILABLE;
00350         if ( aContext.iType == KUidMsvFolderEntry )
00351                 {
00352                 aReasonResourceId=R_TEXTUD_CAN_NOT_EDIT_FOLDERS;
00353                 return EFalse;
00354                 }
00355         else
00356                 return ETrue;
00357         }
00358 
00359 
00360 TBool CTxtiMtmUiData::CanDeleteFromEntryL(const TMsvEntry& aContext, TInt& aReasonResourceId) const
00361         {
00362         __ASSERT_ALWAYS(aContext.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00363         __ASSERT_ALWAYS(aContext.iType!=KUidMsvAttachmentEntry, Panic(ETxtiMtmUdAttachmentsNotSupported));
00364 
00365         aReasonResourceId=R_EIK_TBUF_NOT_AVAILABLE;    // There is no resource string for this operation
00366         return EFalse;
00367         }
00368 
00369 
00370 TBool CTxtiMtmUiData::CanCopyMoveToEntryL(const TMsvEntry& aContext, TInt& aReasonResourceId) const
00371         {
00372         __ASSERT_ALWAYS(aContext.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00373         __ASSERT_ALWAYS(aContext.iType!=KUidMsvAttachmentEntry, Panic(ETxtiMtmUdAttachmentsNotSupported));
00374 
00375         aReasonResourceId=R_EIK_TBUF_NOT_AVAILABLE;    // There is no resource string for this operation
00376         return EFalse;
00377         }
00378 
00379 
00380 TBool CTxtiMtmUiData::CanCopyMoveFromEntryL(const TMsvEntry& aContext, TInt& aReasonResourceId) const
00381         {
00382         __ASSERT_ALWAYS(aContext.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00383         __ASSERT_ALWAYS(aContext.iType!=KUidMsvAttachmentEntry, Panic(ETxtiMtmUdAttachmentsNotSupported));
00384 
00385         aReasonResourceId=R_EIK_TBUF_NOT_AVAILABLE;    // There is no resource string for this operation
00386         return EFalse;
00387         }
00388 
00389 
00390 TBool CTxtiMtmUiData::CanReplyToEntryL(const TMsvEntry& aContext, TInt& aReasonResourceId) const
00391 //
00392 // MTM UI does not support replying.
00393 //
00394     {
00395         __ASSERT_ALWAYS(aContext.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00396         __ASSERT_ALWAYS(aContext.iType!=KUidMsvAttachmentEntry, Panic(ETxtiMtmUdAttachmentsNotSupported));
00397 
00398         aReasonResourceId=R_TEXTUD_NOT_SUPPORTED;
00399         return EFalse;
00400     }
00401 
00402 
00403 TBool CTxtiMtmUiData::CanForwardEntryL(const TMsvEntry& aContext, TInt& aReasonResourceId) const
00404 //
00405 // MTM UI does not supports forwarding.
00406 //
00407     {
00408         __ASSERT_ALWAYS(aContext.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00409         __ASSERT_ALWAYS(aContext.iType!=KUidMsvAttachmentEntry, Panic(ETxtiMtmUdAttachmentsNotSupported));
00410 
00411         aReasonResourceId=R_TEXTUD_NOT_SUPPORTED;
00412         return EFalse;
00413     }
00414 
00415 
00416 TBool CTxtiMtmUiData::CanCreateEntryL(const TMsvEntry& aParent, TMsvEntry& aNewEntry,
00417                                                                           TInt& aReasonResourceId) const
00418         {
00419         __ASSERT_ALWAYS(aNewEntry.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00420         __ASSERT_ALWAYS(aNewEntry.iType!=KUidMsvAttachmentEntry, Panic(ETxtiMtmUdAttachmentsNotSupported));
00421 
00422         aReasonResourceId=R_EIK_TBUF_NOT_AVAILABLE;    // There is no resource string for this operation
00423         // --- Can create services if they are off root ---
00424         if (aNewEntry.iType == KUidMsvServiceEntry)
00425                 return (aParent.Id() == KMsvRootIndexEntryIdValue);
00426 
00427         // --- Can create messages in local folders ---
00428         if (aNewEntry.iType == KUidMsvMessageEntry)
00429                 return (aParent.iMtm.iUid == KMsvLocalServiceIndexEntryIdValue);
00430         
00431         return EFalse;
00432         }
00433 
00434 TBool CTxtiMtmUiData::CanDeleteServiceL(const TMsvEntry& aService, TInt& aReasonResourceId)const
00435         {
00436         __ASSERT_ALWAYS(aService.iMtm==KUidMsgTypeText, Panic(ETxtiMtmUdWrongMtm));
00437 
00438         aReasonResourceId=R_EIK_TBUF_NOT_AVAILABLE;    // There is no resource string for this operation
00439         return EFalse;
00440         }
00441 
00442 TBool CTxtiMtmUiData::CanCancelL(const TMsvEntry& /*aContext*/, TInt& /*aReasonResourceId*/) const
00443         {
00444         return EFalse;
00445         }
00446 
00447 HBufC* CTxtiMtmUiData::StatusTextL(const TMsvEntry& /*aContext*/) const
00448         {
00449         return StringLoader::LoadL(R_TEXTUD_STATUS_TEXT, iCoeEnv );
00450         }

Generated by  doxygen 1.6.2