examples/Messaging/TextMTM/txtu/TXTU.CPP

00001 // Copyright (c) 2000-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 
00017 // Standard includes
00018 #include <txtrich.h>//CRichText
00019 #include <eikrted.h> // CEikRichTextEditor
00020 #include <apffndr.h>//CApaScanningAppFinder
00021 #include <eikenv.h>//CEikonEnv
00022 #include <eikfsel.h> //CEikFolderNameSelector
00023 #include <eikon.hrh>  //EEikBidCancel, EEikBidTab
00024 #include <eikon.rsg>
00025 
00026 // Messaging includes
00027 #include <msvuids.h>
00028 #include <msvids.h>
00029 
00030 // Specific includes
00031 #include "TXTCMDS.H" //commands accepted by the server side mtms
00032 #include "TXCLIENT.H"
00033 
00034 #include "TXTU.HRH"
00035 #include "TXTU.H"
00036 #include "TXTUCMDS.H"
00037 #include "Txtupan.h"
00038 #include <txtu.rsg>
00039 #include "TXTU.HRH"
00040 
00041 // resource file locations
00042 #ifdef __WINS__
00043 // on wins, assume built to z:
00044 _LIT(KTxtuMtmUiResourceFile,"z:\\resource\\messaging\\txtu.rsc");
00045 #else
00046 _LIT(KTxtuMtmUiResourceFile,"Z:\\resource\\messaging\\txtu.rsc");
00047 #endif
00048 
00049 //
00050 // CTextMtmUi: User Interface MTM
00051 //
00052 
00053 //
00054 //      Construction and destruction 
00055 //
00056 
00057 CTextMtmUi* CTextMtmUi::NewL(CBaseMtm& aBaseMtm, CRegisteredMtmDll& aRegisteredMtmDll)
00058         {
00059         CTextMtmUi* self=new(ELeave) CTextMtmUi(aBaseMtm, aRegisteredMtmDll);
00060         CleanupStack::PushL(self);
00061         self->ConstructL();
00062         CleanupStack::Pop();
00063         return self;
00064         }
00065 
00066 CTextMtmUi::CTextMtmUi(CBaseMtm& aBaseMtm, CRegisteredMtmDll& aRegisteredMtmDll)
00067         :       CBaseMtmUi(aBaseMtm, aRegisteredMtmDll)
00068         {
00069         }
00070 
00071 CTextMtmUi::~CTextMtmUi()
00072         {
00073         }
00074 
00075 void CTextMtmUi::ConstructL()
00076         {
00077         CBaseMtmUi::ConstructL();
00078         }
00079 
00080 CMsvOperation* CTextMtmUi::CancelL(TRequestStatus& /*aStatus*/, const CMsvEntrySelection& /*aSelection*/)
00081         {
00082         User::Leave(KErrNotSupported); // no cancelling
00083         return NULL;
00084         }
00085 
00086 void CTextMtmUi::GetResourceFileName(TFileName& aFileName) const
00087 // Resource file loading 
00088         { 
00089         aFileName=KTxtuMtmUiResourceFile; 
00090         }
00091 
00092 //
00093 //      Entry manipulation 
00094 //
00095 
00096 CMsvOperation* CTextMtmUi::OpenL(TRequestStatus& aStatus)
00097 // Open 
00098         {
00099         __ASSERT_DEBUG(iBaseMtm.Entry().Entry().iType==KUidMsvMessageEntry, 
00100                 Panic(ETextMtmUiOnlyWorksWithMessageEntries));
00101         return EditL(aStatus);
00102         }
00103 
00104 CMsvOperation* CTextMtmUi::OpenL(TRequestStatus& aStatus, const CMsvEntrySelection& aSelection)
00105 // Open selection
00106         {
00107         __ASSERT_DEBUG(aSelection.Count(), Panic(ETextMtmUiEmptySelection));
00108         iBaseMtm.SwitchCurrentEntryL(aSelection.At(0));
00109         return OpenL(aStatus);
00110         }
00111 
00112 CMsvOperation* CTextMtmUi::CloseL(TRequestStatus& aStatus)
00113         {
00114 // Close 
00115         __ASSERT_DEBUG(iBaseMtm.Entry().Entry().iType==KUidMsvMessageEntry, 
00116                 Panic(ETextMtmUiOnlyWorksWithMessageEntries));
00117 
00118         // Nothing to do for this MTM
00119         TPckgBuf<TMsvLocalOperationProgress> progress;
00120         SetProgressSuccess(progress,iBaseMtm.Entry().Entry().Id());
00121 
00122         CMsvCompletedOperation* op=CMsvCompletedOperation::NewL(Session(), Type(), 
00123                 progress, KMsvLocalServiceIndexEntryId,aStatus);
00124         return op;
00125         }
00126 
00127 CMsvOperation* CTextMtmUi::CloseL(TRequestStatus& aStatus, const CMsvEntrySelection& aSelection)
00128         {
00129 // Close selection
00130         __ASSERT_DEBUG(aSelection.Count(), Panic(ETextMtmUiEmptySelection));
00131         iBaseMtm.SwitchCurrentEntryL(aSelection.At(0));
00132         return CloseL(aStatus);
00133         }
00134 
00135 CMsvOperation* CTextMtmUi::CreateL(const TMsvEntry& aEntry, CMsvEntry& aParent, 
00136                                                                    TRequestStatus& aStatus)
00137 // Create new entry 
00138         {
00139         TMsvId oldId=0;
00140         if (iBaseMtm.HasContext())
00141                 oldId = iBaseMtm.Entry().Entry().Id();  
00142         else
00143                 iBaseMtm.SwitchCurrentEntryL(KMsvRootIndexEntryId);
00144         
00145         // Create the new entry synchronously
00146         TMsvEntry newEntry=aEntry;
00147         if (newEntry.iType.iUid == KUidMsvMessageEntryValue)
00148                 {
00149                 // Some extra info for new messages
00150                 _LIT(KNewText,"New Text");
00151                 newEntry.iServiceId=KMsvLocalServiceIndexEntryId;
00152                 newEntry.iDescription.Set(KNewText);
00153                 }
00154         CMsvOperationActiveSchedulerWait* wait=CMsvOperationActiveSchedulerWait::NewLC();
00155         CMsvOperation* op=CBaseMtmUi::CreateL(newEntry, aParent, wait->iStatus);
00156         CleanupStack::PushL(op);
00157         wait->Start();
00158 
00159         TPckgBuf<TMsvLocalOperationProgress> progressPack;
00160     progressPack.Copy(op->ProgressL());
00161         TMsvLocalOperationProgress progress = progressPack();
00162         User::LeaveIfError(progress.iError);
00163 
00164         CleanupStack::PopAndDestroy(2);// op, wait
00165 
00166         // Now edit the entry
00167         iBaseMtm.SwitchCurrentEntryL(progress.iId);
00168         TRAPD(ret, op=EditL(aStatus));
00169         if (ret!=KErrNone)
00170                 {// An error has occurred before ownership of entry passed over to editor, 
00171                 //      so try and delete the new entry, and return context to its previous state
00172                 wait = CMsvOperationActiveSchedulerWait::NewLC();
00173                 CMsvEntry* entry=Session().GetEntryL(iBaseMtm.Entry().Entry().Parent());
00174                 CleanupStack::PushL(entry);
00175                 wait->Start();
00176                 entry->DeleteL(progress.iId);
00177                 CleanupStack::PopAndDestroy(2);// wait, entry
00178                 if (oldId)
00179                         iBaseMtm.SwitchCurrentEntryL(oldId);
00180                 User::Leave(ret);
00181                 }
00182         return op;
00183         }
00184 
00185 
00186 CMsvOperation* CTextMtmUi::EditL(TRequestStatus& aStatus)
00187 // Edit 
00188         {
00189         TUid type = iBaseMtm.Entry().Entry().iType;
00190         iServiceId = iBaseMtm.Entry().Entry().iServiceId;
00191 
00192         __ASSERT_DEBUG(type==KUidMsvMessageEntry || type==KUidMsvServiceEntry, 
00193                 Panic(ETextMtmUiWrongEntryType));
00194 
00195         if ( type == KUidMsvMessageEntry )
00196                 return MessageEditL(aStatus);
00197         else
00198                 return ServiceEditL(aStatus);
00199         }
00200 
00201 CMsvOperation* CTextMtmUi::MessageEditL(TRequestStatus& aStatus)
00202 // Message editing
00203         {
00204         CMsvOperation* op=NULL;
00205 
00206         // If the message is already stored locally, edit it.
00207         if ( iServiceId == KMsvLocalServiceIndexEntryId )
00208                 {
00209                 return LaunchEditorApplicationL(aStatus, iBaseMtm.Entry().Entry().Id(), EFalse);
00210                 }
00211 
00212         // Otherwise ask user if she wants to copy it to local
00213         CEikDialog* dialog=new(ELeave) CEikDialog;
00214         if (dialog->ExecuteLD(R_DIALOG_REFUSE_EDIT_REMOTE_MESSAGE))
00215                 {
00216                 TMsvEntry tEntry = iBaseMtm.Entry().Entry();
00217                 CEditRemoteOperation* edop = new (ELeave)CEditRemoteOperation(*this, Session(), 0, aStatus);
00218                 edop->StartL(tEntry);
00219                 op = edop;
00220                 }
00221         else
00222                 {
00223                 TPckgBuf<TMsvLocalOperationProgress> progress;
00224                 SetProgressSuccess(progress,iBaseMtm.Entry().Entry().Id());
00225 
00226                 op=CMsvCompletedOperation::NewL(Session(), Type(), progress, iServiceId, aStatus);
00227                 }
00228                 
00229         __ASSERT_DEBUG(op != NULL, Panic(ETextMtmUiInvalidNullPointer));
00230         return op;
00231         }
00232 
00233 
00234 CMsvOperation* CTextMtmUi::ServiceEditL(TRequestStatus& aStatus)
00235 // Service edit dialog
00236         {
00237         TMTMTxtSettings settings;
00238 
00239         // load any existing settings
00240         CTextMtmClient& mtm = static_cast<CTextMtmClient&>(BaseMtm());
00241         // leaves if none found, which is acceptable, so ignore leave 
00242         TRAP_IGNORE(mtm.Settings().LoadSettingsL(iBaseMtm.Entry().Entry().Id(), settings));     
00243 
00244         // run the edit service settings dialog
00245         CEikDialog* dialog=new(ELeave) CTextMtmEditServiceDialog(settings);
00246         TPckgBuf<TMsvLocalOperationProgress> progress;
00247         if (dialog->ExecuteLD(R_DIALOG_SERVICE_SETTINGS))
00248                 {
00249                 mtm.Settings().SaveSettingsL(iBaseMtm.Entry().Entry().Id(), settings);          
00250                 // Update index entry description
00251                 TMsvEntry entry = iBaseMtm.Entry().Entry();
00252                 entry.iDetails.Set(settings.RootFolder());
00253                 iBaseMtm.Entry().ChangeL(entry);
00254                 // Send a refresh service command
00255                 CMsvEntrySelection* selection=new (ELeave) CMsvEntrySelection;
00256                 CleanupStack::PushL(selection);
00257                 selection->AppendL(iBaseMtm.Entry().Entry().Id());
00258                 CleanupStack::Pop(); //selection
00259                 TBuf8<1> scrap;
00260                 InvokeSyncFunctionL(ETxtuCommandRefreshMBox, *selection, scrap);
00261                 delete selection;
00262                 SetProgressSuccess(progress,iBaseMtm.Entry().Entry().Id());
00263                 }
00264         else
00265                 {
00266                 progress().iTotalNumberOfEntries=1;
00267                 progress().iNumberCompleted=0;
00268                 }
00269 
00270         return CMsvCompletedOperation::NewL(Session(), Type(), progress, iServiceId, aStatus);
00271         }
00272         
00273 CMsvOperation* CTextMtmUi::EditL(TRequestStatus& aStatus, const CMsvEntrySelection& aSelection)
00274 // Edit selection
00275         {
00276         __ASSERT_DEBUG(aSelection.Count(), Panic(ETextMtmUiEmptySelection));
00277         iBaseMtm.SwitchCurrentEntryL(aSelection.At(0));
00278         return EditL(aStatus);
00279         }
00280 
00281 CMsvOperation* CTextMtmUi::ViewL(TRequestStatus& aStatus)
00282 // View
00283         {
00284         __ASSERT_DEBUG(iBaseMtm.Entry().Entry().iType==KUidMsvMessageEntry, 
00285                 Panic(ETextMtmUiOnlyWorksWithMessageEntries));
00286         return LaunchEditorApplicationL(aStatus, iBaseMtm.Entry().Entry().Id(), ETrue);
00287         }
00288 
00289 CMsvOperation* CTextMtmUi::ViewL(TRequestStatus& aStatus, const CMsvEntrySelection& aSelection)
00290 // View selection
00291         {
00292         __ASSERT_DEBUG(aSelection.Count(), Panic(ETextMtmUiEmptySelection));
00293         iBaseMtm.SwitchCurrentEntryL(aSelection.At(0));
00294         return ViewL(aStatus);
00295         }
00296 
00297 //
00298 //      Copy/move/delete functionality
00299 //
00300 
00301 
00302 CMsvOperation* CTextMtmUi::DeleteFromL(const CMsvEntrySelection& aSelection,
00303                                                                            TRequestStatus& aStatus)
00304         {
00305         __ASSERT_DEBUG(aSelection.Count(), Panic(ETextMtmUiEmptySelection));
00306 
00307         CheckValidCopyMoveDelSelectionL(BaseMtm().Entry(),aSelection);
00308         return BaseMtm().Entry().DeleteL(aSelection, aStatus);
00309         }
00310 
00311 CMsvOperation* CTextMtmUi::DeleteServiceL(const TMsvEntry& aService, TRequestStatus& aStatus)
00312         {
00313         // remove settings from cenrep
00314         CTextMtmClient& mtm = static_cast<CTextMtmClient&>(BaseMtm());
00315         mtm.Settings().DeleteSettingsL(aService.Id());
00316         return CBaseMtmUi::DeleteServiceL(aService, aStatus);
00317         }
00318 
00319 CMsvOperation* CTextMtmUi::CopyToL(const CMsvEntrySelection& aSelection, 
00320                                                                                         TRequestStatus& aStatus)
00321 // Copies entries in selection to the current context
00322         {
00323         return DoCopyMoveToL(aSelection, aStatus, ETrue);
00324         }
00325 
00326 
00327 CMsvOperation* CTextMtmUi::MoveToL(const CMsvEntrySelection& aSelection, 
00328                                                                                         TRequestStatus& aStatus)
00329 // Moves entries in selection to the current context
00330         {
00331         return DoCopyMoveToL(aSelection, aStatus, EFalse);
00332         }
00333 
00334 
00335 CMsvOperation* CTextMtmUi::CopyFromL(const CMsvEntrySelection& aSelection, 
00336                                                                          TMsvId aTargetId, TRequestStatus& aStatus)
00337 // Copies entries in selection from current context to aTargetId id     
00338         {
00339         return DoCopyMoveFromL(aSelection, aTargetId, aStatus, ETrue);
00340         }
00341 
00342 
00343 CMsvOperation* CTextMtmUi::MoveFromL(const CMsvEntrySelection& aSelection, 
00344                                                                          TMsvId aTargetId, TRequestStatus& aStatus)
00345 // Moves entries in selection from current context to aTargetId id      
00346         {
00347         return DoCopyMoveFromL(aSelection, aTargetId, aStatus, EFalse);
00348         }
00349 
00350 
00351 CMsvOperation* CTextMtmUi::DoCopyMoveFromL(const CMsvEntrySelection& aSelection, 
00352                                                                          TMsvId aTargetId, TRequestStatus& aStatus, TBool aAction)
00353 // Does copy/move of entries in selection from current context to aTargetId id
00354         {
00355         __ASSERT_DEBUG(aSelection.Count(), Panic(ETextMtmUiEmptySelection));
00356 
00357         const TMsvEntry& context=BaseMtm().Entry().Entry();
00358         __ASSERT_ALWAYS(context.iType.iUid==KUidMsvServiceEntryValue || 
00359                 context.iType.iUid==KUidMsvFolderEntryValue, Panic(ETextMtmUiWrongEntryType));
00360 
00361         CheckValidCopyMoveDelSelectionL(BaseMtm().Entry(),aSelection);
00362 
00363         // Call the CMsvEntry copy/move functions: this will in turn call the Message Server
00364         CMsvOperation* op=NULL;
00365         if (aAction)
00366                 op=BaseMtm().Entry().CopyL(aSelection, aTargetId, aStatus);
00367         else
00368                 op=BaseMtm().Entry().MoveL(aSelection, aTargetId, aStatus);
00369 
00370         return op;
00371         }
00372 
00373 
00374 CMsvOperation* CTextMtmUi::DoCopyMoveToL(const CMsvEntrySelection& aSelection, 
00375                                                                                         TRequestStatus& aStatus, TBool aAction)
00376 // Perform a copy/move (depending on value of aAction)
00377         {
00378         __ASSERT_DEBUG(aSelection.Count(), Panic(ETextMtmUiEmptySelection));
00379 
00380         const TMsvEntry& context=BaseMtm().Entry().Entry();
00381         __ASSERT_ALWAYS(context.iType.iUid==KUidMsvServiceEntryValue || 
00382                 context.iType.iUid==KUidMsvFolderEntryValue, Panic(ETextMtmUiWrongEntryType));
00383 
00384         // Find selection parent
00385         CMsvEntry* sourceEntry=Session().GetEntryL(aSelection.At(0));
00386         CleanupStack::PushL(sourceEntry);
00387 
00388         TMsvId parent=sourceEntry->Entry().Parent();
00389         sourceEntry->SetEntryL(parent);
00390 
00391         CheckValidCopyMoveDelSelectionL(*sourceEntry,aSelection);
00392 
00393         // Call the CMsvEntry copy/move function: this will in turn call the Message Server
00394         CMsvOperation* op=NULL;
00395         if (aAction)
00396                 op=sourceEntry->CopyL(aSelection, context.Id(), aStatus);
00397         else
00398                 op=sourceEntry->MoveL(aSelection, context.Id(), aStatus);
00399 
00400         CleanupStack::PopAndDestroy();// sourceEntry
00401 
00402         return op;
00403         }
00404 
00405 void CTextMtmUi::CheckValidCopyMoveDelSelectionL(const CMsvEntry& aParent,
00406                                                                                                  const CMsvEntrySelection& aSelection)
00407 // Check selection and confirm it contains only messages
00408 // As Server-side doesn't handle folders
00409         {
00410         // We have a ready-made way of getting a list of the message children to check against
00411         CMsvEntrySelection* msgChildren=aParent.ChildrenWithTypeL(KUidMsvMessageEntry);
00412         CleanupStack::PushL(msgChildren);
00413         
00414         // Check each aSelection entry is a child message
00415         TInt nChildren=aSelection.Count();
00416         for (TInt i=0; i<nChildren; i++)
00417                 if ( msgChildren->Find(aSelection[i] ) == KErrNotFound )
00418                         User::Leave(KErrNotSupported);
00419         CleanupStack::PopAndDestroy();// msgChildren
00420         }
00421 
00422 
00423 //
00424 //      MTM-specific functionality
00425 //
00426 
00427 void CTextMtmUi::InvokeSyncFunctionL(TInt aFunctionId, const CMsvEntrySelection& aSelection, 
00428                                                                          TDes8& aParameter)
00429 // Call MTM-specific function synchronously
00430         {
00431         if (aFunctionId==ETxtuCommandExportText)
00432                 {
00433                 __ASSERT_DEBUG(aSelection.Count()==1, Panic(ETextMtmUiSelectionIsNotOneMessage));
00434                 DoExportTextFromMessageL(aSelection.At(0));// take the first message in selection
00435                 }
00436         else if (aFunctionId==ETxtuCommandRefreshMBox)
00437                 {
00438                 CBaseMtmUi::InvokeSyncFunctionL(KTXTMTMRefresh, aSelection, aParameter);
00439                 }
00440         else
00441                 {
00442                 CBaseMtmUi::InvokeSyncFunctionL(aFunctionId, aSelection, aParameter);
00443                 }
00444         }
00445 
00446 CMsvOperation* CTextMtmUi::InvokeAsyncFunctionL(TInt aFunctionId, const CMsvEntrySelection& aSelection, 
00447                                                                                                 TRequestStatus& aCompletionStatus, TDes8& aParameter)
00448 // Call MTM-specific function asynchronously
00449         {
00450         return CBaseMtmUi::InvokeAsyncFunctionL(aFunctionId, aSelection, aCompletionStatus, aParameter);
00451         }
00452 
00453 //
00454 //      Message responding
00455 //
00456 
00457 CMsvOperation* CTextMtmUi::ReplyL(TMsvId /*aDestination*/, TMsvPartList /*aPartlist*/, TRequestStatus& /*aCompletionStatus*/)
00458 // Reply to message - no UI support
00459         {
00460         User::Leave(KErrNotSupported);
00461         return NULL;
00462         }
00463 
00464 CMsvOperation* CTextMtmUi::ForwardL(TMsvId /*aDestination*/, TMsvPartList /*aPartlist*/, TRequestStatus& /*aCompletionStatus*/)
00465 // Forwarded message - no UI support
00466         {
00467         User::Leave(KErrNotSupported);
00468         return NULL;
00469         }
00470 
00471 //
00472 //      Progress information
00473 //
00474 
00475 TInt CTextMtmUi::GetProgress(const TDesC8& aProgress, TBuf<EProgressStringMaxLen>& aReturnString, 
00476                 TInt& aTotalEntryCount, TInt& aEntriesDone,TInt& aCurrentEntrySize, TInt& aCurrentBytesTrans) const
00477 // Get progress information 
00478         {
00479         TTxtProgressBuf paramPack;
00480         if (aProgress.Length()!=paramPack.Length())
00481                 return KErrNone;
00482 
00483         // Only the server-side copy/move/del fill in the progress
00484         // A good idea would be to add a flag to the progress info to show which was happening
00485         paramPack.Copy(aProgress);      
00486         TTxtProgress progress=paramPack();
00487         aReturnString.Zero();
00488         _LIT(KWorking,"Working");
00489         _LIT(KError,"Error: ");
00490 
00491         // Progress information contains any error returned from the server-side
00492         // It's handling here is very simple
00493         if (progress.iErrorCode==KErrNone)
00494                 aReturnString.Append(KWorking);
00495         else
00496                 {
00497                 aReturnString.Append(KError);
00498                 aReturnString.AppendNum(progress.iErrorCode);
00499                 }
00500 
00501         // Copy info from progress
00502         aTotalEntryCount=progress.iTotalMsgs;
00503         aEntriesDone=progress.iMsgsProcessed;
00504 
00505         // TTxtProgress doesn't hold anything about these
00506         aCurrentEntrySize=0;
00507         aCurrentBytesTrans=0;
00508 
00509         return KErrNone;
00510         }
00511 
00512 //
00513 // Specific to CTextMtmUi
00514 //
00515 
00516 void CTextMtmUi::DoExportTextFromMessageL(TMsvId anId)
00517 // Export message text to file
00518         {
00519         TFileName filename(_S("\\"));
00520         HBufC* title=iCoeEnv->AllocReadResourceLC(R_TEXT_MTMUI_EXPORT_DIALOG_TITLE);
00521         CEikDialog* dialog=new(ELeave) CTextMtmExportToFileDialog(&filename, title);
00522         if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_SAVEAS))
00523                 {
00524                 // Get the entry to export the text from
00525                 CMsvEntry* messageEntry=GetMessageEntryLC(anId);
00526                 
00527                 // Get the store for the message
00528                 CMsvStore* store=messageEntry->ReadStoreL();
00529                 CleanupStack::PushL(store);
00530 
00531                 // Now get the rich text from that message
00532                 CRichText* text=GetTextFromMessageStoreL(store);
00533 
00534                 // No longer need entry or store, so discard them
00535                 CleanupStack::PopAndDestroy(2);// messageEntry, store
00536                 
00537                 // Now export the text to the given file
00538                 CleanupStack::PushL(text);
00539                 text->ExportAsTextL(filename, CPlainText::EOrganiseByParagraph, 80);
00540                 CleanupStack::PopAndDestroy();// text
00541                 }
00542         CleanupStack::PopAndDestroy();// title
00543         }
00544 
00545 CMsvEntry* CTextMtmUi::GetMessageEntryLC(TMsvId anId) const
00546         {
00547         CMsvEntry* messageEntry=Session().GetEntryL(anId);
00548         CleanupStack::PushL(messageEntry);
00549         return messageEntry;
00550         }
00551 
00552 CRichText* CTextMtmUi::GetTextFromMessageStoreL(CMsvStore* aStore) const
00553         {
00554         CRichText* text=CRichText::NewL(iEikonEnv->SystemParaFormatLayerL(), 
00555                 iEikonEnv->SystemCharFormatLayerL());
00556         CleanupStack::PushL(text);
00557         aStore->RestoreBodyTextL(*text);
00558         CleanupStack::Pop();// text
00559         return text;
00560         }
00561 
00562 CMsvOperation* CTextMtmUi::LaunchEditorApplicationL(TRequestStatus& aStatus, TMsvId aId, 
00563                                                                                                         TBool aReadOnly)
00564         {
00565 // In a real MTM, would launch the appropriate editor/viewer, and return a controlling CMsvOperation
00566 // Here we just pretend...
00567         if (aReadOnly)
00568                 iEikonEnv->InfoMsg(R_TEXT_MTMUI_VIEWER_MESSAGE);
00569         else
00570                 {
00571                 // For editing, append a bit of text to the message
00572                 iEikonEnv->InfoMsg(R_TEXT_MTMUI_EDIT_MESSAGE);
00573 
00574                 _LIT(KEdited,"Edited document\n");
00575                 iBaseMtm.SwitchCurrentEntryL(aId);
00576                 CreateBodyIfNoneL();
00577                 iBaseMtm.LoadMessageL();
00578                 TInt docEnd=iBaseMtm.Body().DocumentLength();
00579                 iBaseMtm.Body().InsertL(docEnd,KEdited);
00580                 iBaseMtm.SaveMessageL();
00581                 }
00582 
00583         TPckgBuf<TMsvLocalOperationProgress> progress;
00584         SetProgressSuccess(progress,aId);
00585 
00586         return CMsvCompletedOperation::NewL(Session(), Type(), progress, iServiceId, aStatus);
00587         }
00588 
00589 void CTextMtmUi::SetProgressSuccess(TPckgBuf<TMsvLocalOperationProgress>& aProgress,TMsvId aId)
00590 // Little utility function to set progress info
00591         {
00592         aProgress().iTotalNumberOfEntries=1;
00593         aProgress().iNumberCompleted=1;
00594         aProgress().iId=aId;
00595         }
00596 
00597 void CTextMtmUi::CreateBodyIfNoneL()
00598 // Creates body text stream for context if doesn't have one already (i.e. is newly created)
00599         {
00600         __ASSERT_DEBUG(iBaseMtm.Entry().Entry().iType.iUid == KUidMsvMessageEntryValue, 
00601                 Panic(ETextMtmUiOnlyWorksWithMessageEntries));
00602 
00603         CMsvStore* store=iBaseMtm.Entry().EditStoreL();
00604         CleanupStack::PushL(store);
00605         
00606         if (!store->HasBodyTextL())
00607                 {
00608                 // Create CRichText object
00609                 CRichText* body = CRichText::NewL(iEikonEnv->SystemParaFormatLayerL(), 
00610                         iEikonEnv->SystemCharFormatLayerL());
00611                 CleanupStack::PushL(body);
00612 
00613                 // Store CRichText in body
00614                 store->StoreBodyTextL(*body);
00615                 store->CommitL();
00616 
00617                 CleanupStack::PopAndDestroy(); // body
00618                 }
00619         CleanupStack::PopAndDestroy(); // store
00620         }
00621 
00622 //
00623 //      CEditRemoteOperation: remote edit operation
00624 //
00625 
00626 CEditRemoteOperation::CEditRemoteOperation(CTextMtmUi& aMtmUi, CMsvSession& aMsvSession, 
00627                                                                                    TInt aPriority, TRequestStatus& aObserverRequestStatus)
00628         : CMsvOperation(aMsvSession, aPriority, aObserverRequestStatus), iMtmUi(aMtmUi)
00629         {
00630         CActiveScheduler::Add(this);
00631         }
00632 
00633 CEditRemoteOperation::~CEditRemoteOperation()
00634         {
00635         Cancel();
00636         delete iCopyOperation;
00637         delete iEditOperation;
00638         }
00639 
00640 const TDesC8& CEditRemoteOperation::ProgressL() 
00641         {
00642         return progress;
00643         }
00644 
00645 void CEditRemoteOperation::DoCancel()
00646         {
00647         switch (iState)
00648                 {
00649                 case EStateCopying:
00650                         iCopyOperation->Cancel();
00651                         break;
00652                 case EStateEditing:
00653                         iEditOperation->Cancel();
00654                         break;
00655                 default:
00656                         break;
00657                 }
00658         }
00659 
00660 void CEditRemoteOperation::StartL(TMsvEntry& aSourceEntry)
00661         {
00662         CMsvEntry* cEntry=iMsvSession.GetEntryL(aSourceEntry.Parent());
00663         CleanupStack::PushL(cEntry);
00664         iObserverRequestStatus = KRequestPending;
00665         SetActive();
00666         iCopyOperation=cEntry->CopyL(aSourceEntry.Id(), KMsvGlobalInBoxIndexEntryId, iStatus);
00667         CleanupStack::PopAndDestroy();// cEntry
00668         iState = EStateCopying;
00669         }
00670 
00671 void CEditRemoteOperation::RunL()
00672         {
00673         switch (iState)
00674                 {
00675                 case EStateCopying:
00676                         {
00677                         TTxtProgressBuf package;
00678                         package.Copy(iCopyOperation->ProgressL());
00679                         TMsvId newid = package().iNewId;
00680 
00681                         iStatus = KRequestPending;
00682                         SetActive();
00683                         iEditOperation = iMtmUi.LaunchEditorApplicationL(iStatus, newid, EFalse);
00684                         iState = EStateEditing;
00685                         }
00686                         break;
00687                 case EStateEditing:
00688                         {
00689                         iState = EStateFinished;
00690                         TRequestStatus *sP = &iObserverRequestStatus;
00691                         User::RequestComplete(sP,iStatus.Int());
00692                         }
00693                         break;
00694                 default:
00695                         break;
00696                 }
00697         }
00698 
00699 //
00700 //      CTextMtmExportToFileDialog: export to file dialog
00701 //
00702 
00703 CTextMtmExportToFileDialog::CTextMtmExportToFileDialog(TDes* aFileName, const TDesC* aTitle)
00704         :       CEikFileSaveAsDialog(aFileName, aTitle, NULL, EFalse),
00705                 iTitleBuf(*aTitle) // iTitle is private in CEikFileSaveAsDialog
00706         {
00707         }
00708 
00709 void CTextMtmExportToFileDialog::PreLayoutDynInitL()
00710         {
00711         CEikFileSaveAsDialog::PreLayoutDynInitL();
00712         SetTitleL(iTitleBuf);
00713         }
00714 
00715 //
00716 //      CTextMtmEditServiceDialog: service setup dialog
00717 //
00718 
00719 CTextMtmEditServiceDialog::CTextMtmEditServiceDialog(TMTMTxtSettings& aTxtSettings)
00720         : iTxtSettings(aTxtSettings)
00721         {
00722         }
00723 
00724 void CTextMtmEditServiceDialog::PreLayoutDynInitL()
00725         {
00726         TParse parse;
00727         _LIT(KCRoot,"\\");
00728         
00729         TDriveUnit sysDrive (RFs::GetSystemDrive());
00730         TDriveName sysDriveName (sysDrive.Name());      
00731         TFileName defaultName(sysDriveName);
00732         defaultName.Append(KCRoot);
00733                 
00734         parse.Set(iTxtSettings.RootFolder(),&defaultName,&defaultName);
00735         CEikFolderNameSelector* fsel = (CEikFolderNameSelector*)Control(ETxtEditServiceFolder);
00736         TFileName fullName = parse.FullName();
00737         fsel->SetFullNameL(fullName);   
00738         }
00739 
00740 TBool CTextMtmEditServiceDialog::OkToExitL(TInt /*aButtonId*/)
00741         {
00742         CEikFolderNameSelector* fsel = (CEikFolderNameSelector*)Control(ETxtEditServiceFolder);
00743         iTxtSettings.SetRootFolder(fsel->FullName());
00744         return ETrue;
00745         }
00746 

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