examples/ForumNokia/S60_3rd_Edition_TextMTM_Example/modules/Deinstall/src/txdeinstall.cpp

00001 // txdeinstall.cpp
00002 //
00003 // © 2006 Nokia Corporation.  All rights reserved.
00004 //
00005 
00006 // includes
00007 #include <e32base.h>
00008 #include <e32cons.h>
00009 #include <f32file.h>
00010 #include <msvapi.h>
00011 #include <msvids.h>     // KMsvRootIndexEntryId
00012 #include <msvuids.h>    // KUidMsvServiceEntry
00013 #include "txut.h"
00014 
00015 //LOCAL_D const TInt KUidMsgTypeTextValue = 0x10005247;
00016 //LOCAL_D const TUid KUidMsgTypeText = { KUidMsgTypeTextValue};
00017 //LOCAL_D const TUid KTxtMtmTechnologyTypeUid   = { KUidMsgTypeTextValue};
00018 
00019 LOCAL_D CConsoleBase* console;
00020 LOCAL_C void consoleUIDeinstallL();
00021 LOCAL_C void DoDeinstallL();
00022 LOCAL_C void ClearMessageEntriesL(CMsvSession& aSession);
00023 LOCAL_C void ClearEntriesFromContextL(CMsvEntry& aEntry, TMsvId aContext);
00024 
00025 // constants
00026 _LIT(KMTMDataFileName,"txtmtm.rsc");
00027 _LIT(KMTMDataLocation,"\\resource\\messaging\\Mtm\\");
00028 _LIT(KTxtTitle,"TextMTM deinstall");
00029 _LIT(KFormatFailed,"failed: leave code=%d");
00030 
00031 // Dummy observer class to absorb Message Server session events
00032 class TDummyObserver : public MMsvSessionObserver
00033         {
00034 public:
00035         void HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) {};
00036         };
00037 
00038 
00039 LOCAL_C void FindFileL(const TDesC& aFileName, const TDesC& aLocation, TFileName& aRetVal)
00040     {
00041     RFs fs;
00042     User::LeaveIfError(fs.Connect());
00043     CleanupClosePushL(fs);
00044     TFindFile finder(fs);
00045     User::LeaveIfError(finder.FindByDir(aFileName, aLocation));
00046     aRetVal = finder.File();
00047     CleanupStack::PopAndDestroy();
00048     }
00049 
00050 
00051 LOCAL_C void DoDeinstallL()
00052 // Set up Message Server session and install Text MTM group
00053         {
00054     TFileName filename;
00055     FindFileL(KMTMDataFileName, KMTMDataLocation, filename);
00056 
00057         TDummyObserver ob;
00058         CMsvSession* session = CMsvSession::OpenSyncL(ob);
00059         CleanupStack::PushL(session);
00060     ClearMessageEntriesL(*session);
00061 
00062         TInt err=session->DeInstallMtmGroup(filename);
00063         if (err!=KErrNone && err!=KErrNotFound)
00064                 User::Leave(err);
00065         
00066         CMTMTxtSettings* settings = CMTMTxtSettings::NewL();
00067         CleanupStack::PushL(settings);
00068         settings->DeleteDefaultServiceSettingL();
00069         CleanupStack::PopAndDestroy(settings);
00070 
00071         CleanupStack::PopAndDestroy(session); // session
00072 
00073         RFs fs;
00074         fs.Connect();
00075     CFileMan* fileman = CFileMan::NewL(fs);
00076         _LIT(KMTMDir,"\\data\\TextMTMService\\");
00077         fileman->RmDir(KMTMDir);
00078     delete fileman;
00079         fs.Close();
00080 
00081         }
00082 
00083 LOCAL_C void ClearMessageEntriesL(CMsvSession& aSession)
00084     {
00085     TMsvSelectionOrdering ordering;
00086     ordering.SetShowInvisibleEntries(ETrue);
00087     CMsvEntry* entry = CMsvEntry::NewL(aSession, KMsvRootIndexEntryId, ordering);
00088     CleanupStack::PushL(entry);
00089 
00090     ClearEntriesFromContextL(*entry, KMsvGlobalInBoxIndexEntryId);
00091     ClearEntriesFromContextL(*entry, KMsvGlobalOutBoxIndexEntryId);
00092     ClearEntriesFromContextL(*entry, KMsvSentEntryId);
00093     ClearEntriesFromContextL(*entry, KMsvDeletedEntryFolderEntryId);
00094     ClearEntriesFromContextL(*entry, KMsvDraftEntryId);
00095     ClearEntriesFromContextL(*entry, KMsvRootIndexEntryId);
00096 
00097     CleanupStack::PopAndDestroy(entry);
00098     }
00099 
00100 LOCAL_C void ClearEntriesFromContextL(CMsvEntry& aEntry, TMsvId aContext)
00101     {
00102     aEntry.SetEntryL(aContext);
00103 
00104     CMsvEntrySelection* sel = aEntry.ChildrenWithMtmL(KTxtMtmTechnologyTypeUid);
00105     CleanupStack::PushL(sel);
00106 
00107     const TInt count = sel->Count();
00108 
00109     for(TInt ii = 0; ii < count; ii++)
00110         aEntry.DeleteL(sel->At(ii));
00111 
00112     CleanupStack::PopAndDestroy(sel);
00113     }
00114 
00115 LOCAL_C void consoleUIDeinstallL()
00116 // Set up simple console UI
00117     {
00118         // Construct and install the active scheduler
00119         CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
00120         CleanupStack::PushL(scheduler);
00121         CActiveScheduler::Install(scheduler);
00122 
00123         console=Console::NewL(KTxtTitle,TSize(KConsFullScreen,KConsFullScreen));
00124         CleanupStack::PushL(console);
00125         TRAPD(error,DoDeinstallL()); // call install function
00126 
00127         if (error)
00128                 console->Printf(KFormatFailed, error);
00129 
00130         console->Getch();
00131 
00132         CleanupStack::PopAndDestroy(2, scheduler); // console, scheduler
00133         }
00134 
00135 GLDEF_C TInt E32Main()
00136         {
00137         __UHEAP_MARK;
00138         CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
00139         TRAPD(error,consoleUIDeinstallL());
00140         delete cleanup; // destroy clean-up stack
00141         __UHEAP_MARKEND;
00142         return 0;
00143     }

Generated by  doxygen 1.6.2