examples/Messaging/TextMTM/txtc/TXCLIENT.CPP

00001 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 #if !defined(__E32STD_H__)
00017 #include <e32std.h>
00018 #endif
00019 #if !defined(__TXTRICH_H__)
00020 #include <txtrich.h>
00021 #endif
00022 
00023 #if !defined(__MSVREG_H__)
00024 #include <msvreg.h>     
00025 #endif
00026 #if !defined(__MSVSTORE_H__)
00027 #include <msvstore.h>
00028 #endif  // CMsvStore
00029 #if !defined(__MSVIDS_H__)
00030 #include <msvids.h>     
00031 #endif  // KMsvLocalServiceIndexEntryId
00032 #if !defined(__MTMDEF_H__)
00033 #include <mtmdef.h>     
00034 #endif  // KMsvMessagePartBody
00035 #if !defined(__MSVUIDS_H__)
00036 #include <msvuids.h>
00037 #endif  // KUidMsvMessageEntry
00038 
00039 #if !defined(__TXUT_H__)
00040 #include "TXUT.H"
00041 #endif
00042 #if !defined(_TXTCMDS_H_)
00043 #include "TXTCMDS.H"    // Commands that can be passed on to the server side.
00044 #endif
00045 
00046 #if !defined(__TXTCPAN_H__)
00047 #include "TXTCPAN.H"
00048 #endif  // Panics
00049 #if !defined(__TXCLIENT_H__)
00050 #include "TXCLIENT.H"
00051 #endif
00052 
00053 #include <mtmuidsdef.hrh>
00054 
00055 EXPORT_C CTextMtmClient* CTextMtmClient::NewL(CRegisteredMtmDll& aRegisteredMtmDll, CMsvSession& aMsvSession)
00056 // Factory function
00057         {
00058         CTextMtmClient* self = new (ELeave) CTextMtmClient(aRegisteredMtmDll,aMsvSession);
00059         CleanupStack::PushL(self);
00060         self->ConstructL();
00061         CleanupStack::Pop();
00062         return self;
00063         }
00064 
00065 CTextMtmClient::CTextMtmClient(CRegisteredMtmDll& aRegisteredMtmDll, CMsvSession& aMsvSession)
00066 : CBaseMtm(aRegisteredMtmDll,aMsvSession)
00067         {
00068         __ASSERT_DEBUG(Type()==KUidMsgTypeText,gPanic(ETxtcBadMtmTypeUid));
00069         }
00070 
00071 void CTextMtmClient::ConstructL()
00072         {
00073         iSettings = CMTMTxtSettings::NewL();
00074         SwitchCurrentEntryL(KMsvRootIndexEntryId);
00075         }
00076 
00077 CTextMtmClient::~CTextMtmClient()
00078         {
00079         delete iSettings;
00080         }
00081 
00082 void CTextMtmClient::SaveMessageL()
00083 // Store entry data 
00084 // If it is a service entry, store the current settings. Otherwise it has to be
00085 // a message. 
00086 //
00087         {
00088         __ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ETxtcNoCMsvEntrySet));
00089         // get an editable message store
00090         CMsvStore* store = iMsvEntry->EditStoreL();
00091         CleanupStack::PushL(store);
00092 
00093         switch (iMsvEntry->Entry().iType.iUid)
00094                 {
00095                 case KUidMsvServiceEntryValue:
00096                         iSettings->SaveSettingsL(iMsvEntry->Entry().Id(), iTxtSettings);
00097                         break;
00098                 case KUidMsvMessageEntryValue:
00099                         StoreBodyL(*store);     
00100                         break;
00101                 default:
00102                         __ASSERT_DEBUG(EFalse, gPanic(ETxtcEntryTypeNotSupported));
00103                         break;
00104                 }
00105 
00106         store->CommitL();
00107         CleanupStack::PopAndDestroy(); // store
00108         }
00109 
00110 void CTextMtmClient::LoadMessageL()
00111 // Restore entry data 
00112 // Operation inverse to StoreL
00113 //
00114         {
00115         __ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ETxtcNoCMsvEntrySet));
00116         // get read-only message store
00117         CMsvStore* store = iMsvEntry->ReadStoreL();
00118         CleanupStack::PushL(store);
00119 
00120         switch (iMsvEntry->Entry().iType.iUid)
00121                 {
00122                 case KUidMsvServiceEntryValue:
00123                         iSettings->LoadSettingsL(iMsvEntry->Entry().Id(), iTxtSettings);
00124                         break;
00125                 case KUidMsvMessageEntryValue:
00126                         RestoreBodyL(*store);   
00127                         break;
00128                 default:
00129                         __ASSERT_DEBUG(EFalse, gPanic(ETxtcEntryTypeNotSupported));
00130                         break;
00131                 }
00132 
00133         CleanupStack::PopAndDestroy(); // store
00134         }
00135 
00136 
00137 CMsvOperation* CTextMtmClient::ReplyL (TMsvId /*aReplyEntryId*/, TMsvPartList /*aPartlist*/, 
00138                                                                            TRequestStatus& /*aCompletionStatus*/)
00139 // Create reply message 
00140 // Reply is not defined
00141 //
00142         {
00143         User::Leave(KErrNotSupported);
00144         return NULL;
00145         }
00146 
00147 
00148 CMsvOperation* CTextMtmClient::ForwardL(TMsvId aForwardEntryId, TMsvPartList aPartList, 
00149                                                                                 TRequestStatus& aCompletionStatus)
00150 // Create forwarded message 
00151 // Destination folder is aForwardEntryL
00152 //
00153         {
00154         __ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ETxtcNoCMsvEntrySet));
00155         __ASSERT_DEBUG(iMsvEntry->Entry().iType.iUid == KUidMsvMessageEntryValue, gPanic(ETxtcEntryTypeNotSupported));
00156         __ASSERT_DEBUG(iMsvEntry->Entry().iServiceId == KMsvLocalServiceIndexEntryId, gPanic(ETxtcInvalidServiceId));
00157         
00158         // Create the forwarded index entry
00159         TMsvEntry forwardEntry;
00160         forwardEntry.iMtm = KUidMsgTypeText;
00161         forwardEntry.iServiceId = Entry().Entry().iServiceId;
00162         forwardEntry.iType = KUidMsvMessageEntry;
00163         forwardEntry.iDetails.Set(iMsvEntry->Entry().iDetails);                         
00164         forwardEntry.iSize = iMsvEntry->Entry().iSize;  
00165         if(aPartList&KMsvMessagePartDate)
00166                 forwardEntry.iDate.HomeTime();
00167         if(aPartList&KMsvMessagePartDescription)
00168                 forwardEntry.iDescription.Set(iMsvEntry->Entry().iDescription);         
00169 
00170         // Get CMsvEntry for destination (parent)
00171         CMsvEntry* cEntry = CMsvEntry::NewL(Session(), aForwardEntryId, TMsvSelectionOrdering());
00172         CleanupStack::PushL(cEntry);
00173         // Synchronously create new child
00174         CMsvOperationActiveSchedulerWait* wait = CMsvOperationActiveSchedulerWait::NewLC();
00175         CMsvOperation* opert = cEntry->CreateL(forwardEntry, wait->iStatus);
00176         CleanupStack::PushL(opert);
00177         wait->Start();
00178         User::LeaveIfError(opert->iStatus.Int());
00179         // Check result
00180         TPckgBuf<TMsvLocalOperationProgress> progressPack;
00181     progressPack.Copy(opert->ProgressL());
00182         TMsvLocalOperationProgress progress = progressPack();
00183         User::LeaveIfError(progress.iError);
00184         CleanupStack::PopAndDestroy(2); // opert, wait
00185 
00186         // Get CMsvEntry for new entry
00187         TMsvId forwardId=progress.iId;
00188         cEntry->SetEntryL(forwardId);
00189         
00190         // Populate new forwarded message with Body text
00191         if(aPartList&KMsvMessagePartBody)
00192                 {
00193                 CMsvStore* store=cEntry->EditStoreL();
00194                 CleanupStack::PushL(store);
00195                 StoreBodyL(*store);                             // Current context is original message
00196                 store->CommitL();
00197                 CleanupStack::PopAndDestroy();  // store
00198                 }
00199 
00200         CleanupStack::PopAndDestroy(); // cEntry
00201                 
00202         // Request was performed synchronously, so return a completed operation object
00203         return CMsvCompletedOperation::NewL(Session(), KUidMsgTypeText, progressPack, 
00204                 KMsvNullIndexEntryId, aCompletionStatus);
00205         }
00206 
00207 
00208 TMsvPartList CTextMtmClient::ValidateMessage(TUint aPartList)
00209 // Message validation
00210 //
00211 // The only thing about the message that can be invalid
00212 // is the iDescription, which should be an acceptable file name. So, length isn't 
00213 // allowed to be zero, and backslashes are not allowed in iDescription.
00214 //
00215         {
00216         __ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ETxtcNoCMsvEntrySet));
00217         TInt retVal=0;
00218         if (aPartList & KMsvMessagePartDescription)
00219                 {
00220                 if (iMsvEntry->Entry().iDescription.Length() == 0)
00221                         {
00222                         retVal |= KMsvMessagePartDescription;
00223                         }
00224                 else if (iMsvEntry->Entry().iDescription.Locate( TChar('\\')) >= 0)
00225                         {
00226                         retVal |= KMsvMessagePartDescription;
00227                         }
00228                 }
00229         return retVal;
00230         }
00231 
00232 
00233 TMsvPartList CTextMtmClient::Find(const TDesC& aTextToFind, TMsvPartList aPartList)
00234 // Find text in entry 
00235         {
00236         __ASSERT_DEBUG(iMsvEntry!=NULL, gPanic(ETxtcNoCMsvEntrySet));
00237         TBool found=EFalse;
00238         if (aPartList & KMsvMessagePartBody)
00239                 {
00240                 CRichText *body = &Body();
00241                 if (body != NULL)
00242                         {
00243                         TInt textSize = body->DocumentLength();
00244                         // Get searchable text
00245 
00246                         if (textSize>0)  // Symbian platform doesn't handle allocing zero byte arrays too
00247                                 {               
00248                                 TText *bodyText = new TText[textSize];
00249                                 if (bodyText != NULL)
00250                                         {
00251                                         // search the rich text
00252                                         TPtr p(bodyText,textSize,textSize);
00253                                         body->Extract(p);
00254                                         if (p.FindF( aTextToFind ) >= 0)
00255                                                 {
00256                                                 found = ETrue;
00257                                                 }
00258                                         }
00259                                 delete bodyText;
00260                                 }
00261                         }
00262                 }
00263 
00264         if (aPartList & KMsvMessagePartOriginator)
00265                 {
00266                 if (iMsvEntry->Entry().iDetails.FindF( aTextToFind ) >= 0)
00267                         {
00268                         found=ETrue;
00269                         }
00270                 }
00271         
00272         if (aPartList & KMsvMessagePartDescription)
00273                 {
00274                 if (iMsvEntry->Entry().iDescription.FindF( aTextToFind ) >= 0)
00275                         {
00276                         found=ETrue;
00277                         }
00278                 }
00279         
00280         // Never searched - KMsvMessagePartAttachments, KMsvMessagePartRecipient 
00281         // and KMsvMessagePartDate
00282         return found;
00283         }
00284 
00285 TInt CTextMtmClient::QueryCapability(TUid aCapability, TInt& aResponse)
00286 // Query for capability 
00287         {
00288         TInt error = KErrNone;
00289         switch (aCapability.iUid)
00290                 {
00291                 case KUidMtmQueryMaxBodySizeValue:
00292                 case KUidMtmQueryMaxTotalMsgSizeValue:
00293                         aResponse = KMaxTextMessageSize;
00294                         break;
00295                 case KUidMtmQuerySupportedBodyValue:
00296                         aResponse = KMtm8BitBody + KMtm7BitBody;
00297                         break;
00298                 case KUidMtmQueryOffLineAllowedValue:
00299                 case KUidMtmQueryCanSendMsgValue:
00300                 case KUidMtmQueryCanReceiveMsgValue:
00301                         aResponse = ETrue;
00302                         break;
00303                 case KUidMtmQuerySupportAttachmentsValue:
00304                 default:
00305                         return KErrNotSupported;
00306                 }
00307         return error;
00308         }
00309 
00310 void CTextMtmClient::InvokeSyncFunctionL(TInt aFunctionId,const CMsvEntrySelection& aSelection, 
00311                                                                                  TDes8& aParameter)
00312 // Call MTM-specific operation synchronously
00313         {
00314         TInt error = KErrNone;
00315         CMsvOperationActiveSchedulerWait* wait=CMsvOperationActiveSchedulerWait::NewLC();
00316         CMsvOperation* operation = InvokeAsyncFunctionL(aFunctionId,aSelection, aParameter, wait->iStatus);
00317         if (operation != NULL)
00318                 {
00319                 wait->Start();
00320                 error = wait->iStatus.Int();
00321                 delete operation;
00322                 }
00323         else
00324                 {
00325                 error=KErrNotSupported;
00326                 }
00327         CleanupStack::PopAndDestroy(); // wait
00328         User::LeaveIfError(error);
00329         }
00330 
00331 
00332 CMsvOperation* CTextMtmClient::InvokeAsyncFunctionL(TInt aFunctionId,
00333                                                                                                         const CMsvEntrySelection& aSelection, 
00334                                                                                                         TDes8& aParameter, 
00335                                                                                                         TRequestStatus& aCompletionStatus)
00336 // Call MTM-specific operation asynchronously
00337         {
00338         CMsvOperation* operation = NULL;
00339         switch (aFunctionId)
00340                 {
00341                 case KTXTMTMRefresh:
00342             {
00343             operation = (Entry().Session().TransferCommandL(aSelection, aFunctionId, aParameter, aCompletionStatus));
00344             }
00345                         break;
00346                 default:
00347                         __ASSERT_DEBUG(EFalse,gPanic(ETxtcCommandNotSupported));
00348                         break;
00349                 }
00350         return operation;
00351         }
00352 
00353 
00354 void CTextMtmClient::ContextEntrySwitched() 
00355 // Context change notification 
00356 //
00357 // No need to know entry changes
00358 //
00359         {
00360         }
00361 
00362 // attachments are not supported for this MTM
00363 void CTextMtmClient::CreateAttachmentL(const TDesC& , const TDesC8& , TRequestStatus& )
00364         {
00365         User::Leave(KErrNotSupported);
00366         }
00367         
00368 void CTextMtmClient::CreateAttachmentL(RFile& , const TDesC8& , TRequestStatus& )
00369         {
00370         User::Leave(KErrNotSupported);
00371         }
00372 
00373 void CTextMtmClient::CreateLinkedAttachmentL(const TDesC& , const TDesC8& , TRequestStatus& )
00374         {
00375         User::Leave(KErrNotSupported);
00376         }
00377 
00378 void CTextMtmClient::CreateMessageAttachmentL(TMsvId , TRequestStatus& )
00379         {
00380         User::Leave(KErrNotSupported);
00381         }
00382 
00383 // delegate default service storage to CMTMTxtSettings
00384 TMsvId CTextMtmClient::DefaultServiceL() const
00385         {
00386         return iSettings->DefaultServiceL();
00387         }
00388         
00389 void CTextMtmClient::RemoveDefaultServiceL()
00390         {
00391         iSettings->DeleteDefaultServiceSettingL();
00392         }
00393         
00394 void CTextMtmClient::ChangeDefaultServiceL(const TMsvId& aService)
00395         {
00396         iSettings->SetDefaultServiceL(aService);        
00397         }
00398 

Generated on Thu Jan 21 10:32:59 2010 for TB10.1 Example Applications by  doxygen 1.5.3