diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/txclient_8cpp_source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/txclient_8cpp_source.html Tue Mar 30 16:16:55 2010 +0100 @@ -0,0 +1,364 @@ + + + + +TB9.2 Example Applications: examples/ForumNokia/S60_3rd_Edition_TextMTM_Example/modules/Client/src/txclient.cpp Source File + + + + + +

examples/ForumNokia/S60_3rd_Edition_TextMTM_Example/modules/Client/src/txclient.cpp

00001 // TXCLIENT.CPP
+00002 //
+00003 // © 2004 Nokia Corporation.  All rights reserved.
+00004 //
+00005 
+00006 // class include
+00007 #include "txclient.h"
+00008 
+00009 // system includes
+00010 #include <e32std.h>
+00011 #include <txtrich.h>
+00012 #include <msvids.h>             // KMsvLocalServiceIndexEntryId
+00013 #include <msvreg.h>     
+00014 #include <msvstore.h>       // CMsvStore
+00015 #include <msvuids.h>        // KUidMsvMessageEntry
+00016 #include <mtmdef.h>             // KMsvMessagePartBody
+00017 
+00018 // user includes
+00019 #include "txtcmds.hrh"  // Commands that can be passed on to the server side.
+00020 #include "txtcpan.h"
+00021 #include "txtfwdop.h"   // CTxtMtmForwardOperation
+00022 
+00023 _LIT(KTxtGeneratedFilename, "C:\\data\\TextMTMService\\sentmsgbody.txt"); // generated filename base
+00024 
+00025 EXPORT_C CTextMtmClient* CTextMtmClient::NewL(CRegisteredMtmDll& aRegisteredMtmDll, CMsvSession& aMsvSession)
+00026 // Factory function
+00027         {
+00028         CTextMtmClient* self = new (ELeave) CTextMtmClient(aRegisteredMtmDll,aMsvSession);
+00029         CleanupStack::PushL(self);
+00030         self->ConstructL();
+00031         CleanupStack::Pop();
+00032         return self;
+00033         }
+00034 
+00035 
+00036 CTextMtmClient::CTextMtmClient(CRegisteredMtmDll& aRegisteredMtmDll, CMsvSession& aMsvSession)
+00037 : CBaseMtm(aRegisteredMtmDll,aMsvSession)
+00038         {
+00039         __ASSERT_DEBUG(Type()==KUidMsgTypeText,gPanic(ETxtcBadMtmTypeUid));
+00040         }
+00041 
+00042 void CTextMtmClient::ConstructL()
+00043         {
+00044         iSettings = CMTMTxtSettings::NewL();
+00045         SwitchCurrentEntryL(KMsvRootIndexEntryId);
+00046         }
+00047 
+00048 CTextMtmClient::~CTextMtmClient()
+00049         {
+00050         delete iSettings;
+00051         }
+00052 
+00053 
+00054 void CTextMtmClient::SaveMessageL()
+00055 // Store entry data 
+00056 // If it is a service entry, store the current settings. Otherwise it has to be
+00057 // a message. 
+00058 //
+00059         {
+00060 
+00061         __ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ETxtcNoCMsvEntrySet));
+00062         TMsvEntry entry=iMsvEntry->Entry();
+00063 
+00064         switch (iMsvEntry->Entry().iType.iUid)
+00065                 {
+00066                 case KUidMsvServiceEntryValue:
+00067                 
+00068                         // Save settings to Central Repository
+00069                         iSettings->SaveSettingsL(iMsvEntry->Entry().Id(), iTxtSettings);
+00070                         break;
+00071                 case KUidMsvMessageEntryValue:
+00072                         // get an editable message store
+00073                         CMsvStore* store = iMsvEntry->EditStoreL();
+00074                         CleanupStack::PushL(store);
+00075                         StoreBodyL(*store);
+00076                         store->CommitL();
+00077                         CleanupStack::PopAndDestroy(store);
+00078                 
+00079                         // Make sure that we are visible and no longer in preparation
+00080                         entry.SetVisible(ETrue);
+00081                         entry.SetInPreparation(EFalse);
+00082                         entry.iServiceId=  KMsvLocalServiceIndexEntryId;
+00083                         _LIT(KNewFile,"message.txt");
+00084                         entry.iDescription.Set(KNewFile);
+00085                         iMsvEntry->ChangeL(entry);
+00086                         break;
+00087                         
+00088                         
+00089                         
+00090                 default:
+00091                         __ASSERT_DEBUG(EFalse, gPanic(ETxtcEntryTypeNotSupported));
+00092                         break;
+00093                 }
+00094 
+00095         }
+00096 
+00097 void CTextMtmClient::LoadMessageL()
+00098 // Restore entry data 
+00099 // Operation inverse to StoreL
+00100 //
+00101         {
+00102         __ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ETxtcNoCMsvEntrySet));
+00103 
+00104 
+00105 
+00106         switch (iMsvEntry->Entry().iType.iUid)
+00107                 {
+00108                 case KUidMsvServiceEntryValue:
+00109                         // Read settings from Central Repository
+00110                         iSettings->LoadSettingsL(iMsvEntry->Entry().Id(), iTxtSettings);
+00111                         break;
+00112                 case KUidMsvMessageEntryValue:
+00113                         // Get read-only message store.
+00114                 // ReadStoreL leaves if the entry doesn't have a message store.
+00115                 CMsvStore* store = iMsvEntry->HasStoreL() ? iMsvEntry->ReadStoreL() : NULL;
+00116                         if (store==NULL) return;
+00117                         CleanupStack::PushL(store);
+00118                         RestoreBodyL(*store);
+00119                         CleanupStack::PopAndDestroy(); // store 
+00120                         break;
+00121                 default:
+00122                         __ASSERT_DEBUG(EFalse, gPanic(ETxtcEntryTypeNotSupported));
+00123                         break;
+00124                 }
+00125 
+00126         }
+00127 
+00128 
+00129 CMsvOperation* CTextMtmClient::ReplyL (TMsvId /*aDestination*/, TMsvPartList /*aPartlist*/, 
+00130                                                                            TRequestStatus& /*aCompletionStatus*/)
+00131 // Create reply message 
+00132 // Reply is not defined
+00133 //
+00134         {
+00135         User::Leave(KErrNotSupported);
+00136         return NULL;
+00137         }
+00138 
+00139 
+00140 CMsvOperation* CTextMtmClient::ForwardL(TMsvId aDestination, TMsvPartList /*aPartList*/, TRequestStatus& aCompletionStatus)
+00141 // Create forwarded message 
+00142 // Destination folder is aForwardEntryL
+00143 //
+00144         {
+00145         __ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ETxtcNoCMsvEntrySet));
+00146         __ASSERT_DEBUG(iMsvEntry->Entry().iType.iUid == KUidMsvMessageEntryValue, gPanic(ETxtcEntryTypeNotSupported));
+00147         __ASSERT_DEBUG(iMsvEntry->Entry().iServiceId == KMsvLocalServiceIndexEntryId, gPanic(ETxtcInvalidServiceId));
+00148         
+00149     return CTxtMtmForwardOperation::NewL(Entry().EntryId(), aDestination, Session(), aCompletionStatus);
+00150         }
+00151 
+00152 
+00153 TMsvPartList CTextMtmClient::ValidateMessage(TUint aPartList)
+00154 // Message validation
+00155 //
+00156 // The only thing about the message that can be invalid
+00157 // is the iDescription, which should be an acceptable file name. So, length isn't 
+00158 // allowed to be zero, and backslashes are not allowed in iDescription.
+00159 //
+00160         {
+00161         __ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ETxtcNoCMsvEntrySet));
+00162         TInt retVal=0;
+00163         if (aPartList & KMsvMessagePartDescription)
+00164                 {
+00165                 if (iMsvEntry->Entry().iDescription.Length() == 0)
+00166                         {
+00167                         retVal |= KMsvMessagePartDescription;
+00168                         }
+00169                 else if (iMsvEntry->Entry().iDescription.Locate( TChar('\\')) >= 0)
+00170                         {
+00171                         retVal |= KMsvMessagePartDescription;
+00172                         }
+00173                 }
+00174         return retVal;
+00175         }
+00176 
+00177 
+00178 TMsvPartList CTextMtmClient::Find(const TDesC& aTextToFind, TMsvPartList aPartList)
+00179 // Find text in entry 
+00180         {
+00181         __ASSERT_DEBUG(iMsvEntry!=NULL, gPanic(ETxtcNoCMsvEntrySet));
+00182     TMsvPartList retVal = KMsvMessagePartNone;
+00183         if (aPartList & KMsvMessagePartBody)
+00184                 {
+00185                 CRichText& body = Body();
+00186 
+00187                 if (body.DocumentLength() > 0)
+00188                         {
+00189                         // Get searchable text
+00190             TPtrC theText = body.Read(0);
+00191             if(theText.FindF(aTextToFind) != KErrNone)
+00192                 retVal |= KMsvMessagePartBody;
+00193                         }
+00194                 }
+00195 
+00196         if (aPartList & KMsvMessagePartOriginator)
+00197                 {
+00198                 if (iMsvEntry->Entry().iDetails.FindF( aTextToFind ) >= 0)
+00199                         {
+00200                         retVal |= KMsvMessagePartOriginator;
+00201                         }
+00202                 }
+00203         
+00204         if (aPartList & KMsvMessagePartDescription)
+00205                 {
+00206                 if (iMsvEntry->Entry().iDescription.FindF( aTextToFind ) >= 0)
+00207                         {
+00208                         retVal |= KMsvMessagePartDescription;
+00209                         }
+00210                 }
+00211         
+00212         // Never searched - KMsvMessagePartAttachments, KMsvMessagePartRecipient 
+00213         // and KMsvMessagePartDate
+00214         return retVal;
+00215         }
+00216 
+00217 TInt CTextMtmClient::QueryCapability(TUid aCapability, TInt& aResponse)
+00218 // Query for capability 
+00219         {
+00220         TInt error = KErrNone;
+00221         switch (aCapability.iUid)
+00222                 {
+00223                 case KUidMtmQueryMaxBodySizeValue:
+00224                 case KUidMtmQueryMaxTotalMsgSizeValue:
+00225                         aResponse = KMaxTextMessageSize;
+00226                         break;
+00227                 case KUidMtmQuerySupportedBodyValue:
+00228                         aResponse = KMtm8BitBody + KMtm7BitBody;
+00229                         break;
+00230                 case KUidMtmQueryOffLineAllowedValue:
+00231                 case KUidMtmQueryCanReceiveMsgValue:
+00232                         aResponse = 0;
+00233                         break;
+00234         
+00235                 default:
+00236                         return KErrNotSupported;
+00237                 }
+00238         return error;
+00239         }
+00240 
+00241 void CTextMtmClient::InvokeSyncFunctionL(TInt aFunctionId, const CMsvEntrySelection& aSelection, TDes8& aParameter)
+00242 // Call MTM-specific operation synchronously
+00243         {
+00244         TInt error = KErrNone;
+00245         CMsvOperationActiveSchedulerWait* wait=CMsvOperationActiveSchedulerWait::NewLC();
+00246         CMsvOperation* operation = InvokeAsyncFunctionL(aFunctionId,aSelection, aParameter, wait->iStatus);
+00247         if (operation != NULL)
+00248                 {
+00249                 wait->Start();
+00250                 error = wait->iStatus.Int();
+00251                 delete operation;
+00252                 }
+00253         else
+00254                 {
+00255                 error=KErrNotSupported;
+00256                 }
+00257         CleanupStack::PopAndDestroy(); // wait
+00258         
+00259         }
+00260 
+00261 CMsvOperation* CTextMtmClient::InvokeAsyncFunctionL(TInt aFunctionId,
+00262                                                                                                         const CMsvEntrySelection& aSelection, 
+00263                                                                                                         TDes8& aParameter, 
+00264                                                                                                         TRequestStatus& aCompletionStatus)
+00265 // Call MTM-specific operation asynchronously
+00266         {
+00267         CMsvOperation* operation = NULL;
+00268         switch (aFunctionId)
+00269                 {
+00270                 case KTXTMTMRefresh:
+00271             {
+00272             operation = (Entry().Session().TransferCommandL(aSelection, aFunctionId, aParameter, aCompletionStatus));
+00273             }
+00274                         break;
+00275                 case KTXTMTMMessageCommand:
+00276                         {
+00277                         __ASSERT_DEBUG(EFalse,gPanic(ETxtcCommandNotSupported));
+00278                         break;          
+00279                         }
+00280                 default:
+00281                         __ASSERT_DEBUG(EFalse,gPanic(ETxtcCommandNotSupported));
+00282                         break;
+00283                 }
+00284         return operation;
+00285         }
+00286 
+00287 
+00288 void CTextMtmClient::ContextEntrySwitched() 
+00289 // Context change notification 
+00290 //
+00291 // No need to know entry changes
+00292 //
+00293         {
+00294         }
+00295 
+00296 // attachments are not supported for this MTM
+00297 void CTextMtmClient::CreateAttachmentL(const TDesC& , const TDesC8& , TRequestStatus& )
+00298         {
+00299         User::Leave(KErrNotSupported);
+00300         }
+00301         
+00302 void CTextMtmClient::CreateAttachmentL(RFile& , const TDesC8& , TRequestStatus& )
+00303         {
+00304         User::Leave(KErrNotSupported);
+00305         }
+00306 
+00307 void CTextMtmClient::CreateLinkedAttachmentL(const TDesC& , const TDesC8& , TRequestStatus& )
+00308         {
+00309         User::Leave(KErrNotSupported);
+00310         }
+00311 
+00312 void CTextMtmClient::CreateMessageAttachmentL(TMsvId , TRequestStatus& )
+00313         {
+00314         User::Leave(KErrNotSupported);
+00315         }
+00316 
+00317 // delegate default service storage to CMTMTxtSettings
+00318 TMsvId CTextMtmClient::DefaultServiceL() const
+00319         {
+00320         return iSettings->DefaultServiceL();
+00321         }
+00322         
+00323 void CTextMtmClient::RemoveDefaultServiceL()
+00324         {
+00325         iSettings->DeleteDefaultServiceSettingL();
+00326         }
+00327         
+00328 void CTextMtmClient::ChangeDefaultServiceL(const TMsvId& aService)
+00329         {
+00330         iSettings->SetDefaultServiceL(aService);        
+00331         }
+00332 
+00333 // Empty implementation for SetSubjectL and SubjectL fixed
+00334 // 'Feature Not Supported' on E-series devices. For details, see
+00335 // see http://www.forum.nokia.com/document/Forum_Nokia_Technical_Library/contents/FNTL/Send_via_E-mail_fails_in_Nokia_Eseries_devices_with_a_3rd_party_MTM.htm
+00336 //
+00337 // Empty implementations also fixed viewer => viewer now can render
+00338 // message directly from Text MTM mailbox - no need to
+00339 // to move messages to global inbox for viewing
+00340 void CTextMtmClient::SetSubjectL(const TDesC& //aSubject
+00341         )
+00342     {
+00343     }
+00344 
+00345 const TPtrC CTextMtmClient::SubjectL() const
+00346     {
+00347     return TPtrC(KNullDesC);
+00348     }
+
+
Generated by  + +doxygen 1.6.2
+ +