00001
00002
00003
00004
00005
00006
00007 #include <e32base.h>
00008 #include <e32cons.h>
00009 #include <f32file.h>
00010 #include <msvapi.h>
00011 #include <msvids.h>
00012 #include <msvuids.h>
00013 #include "txut.h"
00014
00015
00016
00017
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
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
00032 class TDummyObserver : public MMsvSessionObserver
00033 {
00034 public:
00035 void HandleSessionEventL(TMsvSessionEvent , TAny* , TAny* , TAny* ) {};
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
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);
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
00117 {
00118
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());
00126
00127 if (error)
00128 console->Printf(KFormatFailed, error);
00129
00130 console->Getch();
00131
00132 CleanupStack::PopAndDestroy(2, scheduler);
00133 }
00134
00135 GLDEF_C TInt E32Main()
00136 {
00137 __UHEAP_MARK;
00138 CTrapCleanup* cleanup=CTrapCleanup::New();
00139 TRAPD(error,consoleUIDeinstallL());
00140 delete cleanup;
00141 __UHEAP_MARKEND;
00142 return 0;
00143 }