00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #if !defined(__TXTSPAN_H__)
00017 #include "TXTSPAN.H"
00018 #endif
00019
00020 #if !defined(__MSVUIDS_H__)
00021 #include <msvuids.h>
00022 #endif
00023
00024 #if !defined(__MSVIDS_H__)
00025 #include <msvids.h>
00026 #endif
00027
00028 #include "TXTMBOX.H"
00029
00030
00031
00032
00033
00034 CTxtRefreshMBox* CTxtRefreshMBox::NewL(RFs& aFs, TFileName& aRelativePath, TMsvId aCurrentRootEntryId,
00035 CMsvServerEntry *aEntry, TMsvId aServiceEntryId,
00036 const TMTMTxtSettings& aTxtSettings)
00037
00038
00039
00040 {
00041 CTxtRefreshMBox* self = new (ELeave)CTxtRefreshMBox(aFs, aRelativePath,
00042 aCurrentRootEntryId, aEntry, aServiceEntryId, aTxtSettings);
00043 CleanupStack::PushL(self);
00044 self->ConstructL();
00045 CleanupStack::Pop();
00046 return self;
00047 }
00048
00049 void CTxtRefreshMBox::ConstructL()
00050 {
00051
00052 TFileName fullPath = iTxtSettings.RootFolder();
00053 fullPath.Append(iRelativePath);
00054
00055
00056 User::LeaveIfError(iFs.GetDir(fullPath, KEntryAttDir | KEntryAttNormal,ESortByName
00057 | EDirsAnyOrder | EAscending, iFilelist));
00058
00059
00060 iExistingEntries = new (ELeave) CMsvEntrySelection;
00061 TMsvSelectionOrdering order(KMsvNoGrouping, EMsvSortByDescription);
00062 User::LeaveIfError(iEntry->SetEntry(iCurrentRootEntryId));
00063 iEntry->SetSort( order );
00064 iEntry->GetChildren(*iExistingEntries);
00065
00066 iCurrentFile = 0;
00067 iCurrentEntry = 0;
00068 }
00069
00070 CTxtRefreshMBox::~CTxtRefreshMBox()
00071 {
00072 delete iExistingEntries;
00073 delete iFilelist;
00074 }
00075
00076 void CTxtRefreshMBox::DeleteEntryL()
00077
00078 {
00079 __ASSERT_DEBUG(iCurrentEntry < iExistingEntries->Count(), gPanic(ETxtsInvalidEntryIndex));
00080
00081 User::LeaveIfError(iEntry->SetEntry(iCurrentRootEntryId));
00082 iEntry->DeleteEntry((*iExistingEntries)[iCurrentEntry]);
00083 }
00084
00085 TInt CTxtRefreshMBox::CreateChild(const TDesC& aDescription, const TDesC& aDetails, TUid aMessageType,
00086 const TTime& aDate, const TInt aSize)
00087
00088
00089
00090 {
00091 TMsvEntry newChildEntry;
00092 newChildEntry.iType= aMessageType;
00093 newChildEntry.iMtm = KUidMsgTypeText;
00094 newChildEntry.iDescription.Set(aDescription);
00095 newChildEntry.iDetails.Set(aDetails);
00096 newChildEntry.iServiceId = iServiceEntryId;
00097 newChildEntry.iSize = aSize;
00098 newChildEntry.iDate=aDate;
00099 iEntry->CreateEntry(newChildEntry);
00100 return newChildEntry.Id();
00101 }
00102
00103 TMsvId CTxtRefreshMBox::InsertFileL()
00104
00105
00106
00107
00108 {
00109 __ASSERT_DEBUG(iCurrentFile < iFilelist->Count(), gPanic(ETxtsInvalidEntryIndex));
00110 User::LeaveIfError(iEntry->SetEntry( iCurrentRootEntryId ));
00111 TEntry fileEntry = (*iFilelist)[iCurrentFile];
00112 TTime date;
00113 TInt size;
00114 if (fileEntry.IsDir())
00115 {
00116 date.HomeTime();
00117 size=0;
00118 return CreateChild(fileEntry.iName, fileEntry.iName, KUidMsvFolderEntry, date, size);
00119 }
00120 else
00121 {
00122 TFileName filename = iTxtSettings.RootFolder();
00123 filename.Append(iRelativePath);
00124 filename.Append(fileEntry.iName);
00125 RFile file;
00126 User::LeaveIfError(file.Open(iFs,filename,EFileRead));
00127
00128 file.Modified(date);
00129 file.Size(size);
00130 file.Close();
00131 CreateChild(fileEntry.iName, iRelativePath, KUidMsvMessageEntry, date, size);
00132
00133 return KMsvNullIndexEntryId;
00134 }
00135 }
00136
00137 TBool CTxtRefreshMBox::DoStepL()
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 {
00152
00153 TInt nrFiles = iFilelist->Count();
00154 TInt existingEntries = iExistingEntries->Count();
00155 if (iCurrentFile == nrFiles && iCurrentEntry == existingEntries)
00156 return ETrue;
00157
00158 TMsvId folderId = KMsvNullIndexEntryId;
00159
00160
00161 if (iCurrentFile == nrFiles)
00162 {
00163
00164 DeleteEntryL();
00165
00166 iCurrentEntry++;
00167 }
00168
00169 else if (iCurrentEntry == existingEntries)
00170 {
00171
00172
00173 folderId = InsertFileL();
00174
00175 iCurrentFile++;
00176 }
00177 else
00178 {
00179
00180 User::LeaveIfError(iEntry->SetEntry( (*iExistingEntries)[iCurrentEntry] ));
00181
00182 TInt compare = (*iFilelist)[iCurrentFile].iName.CompareF(iEntry->Entry().iDescription);
00183
00184
00185
00186 if ( compare < 0 )
00187 {
00188
00189
00190 folderId = InsertFileL();
00191
00192 iCurrentFile++;
00193 }
00194
00195 else if (compare == 0)
00196 {
00197
00198 if (iEntry->Entry().iType == KUidMsvFolderEntry)
00199 folderId = (*iExistingEntries)[iCurrentEntry];
00200
00201 iCurrentFile++;
00202 iCurrentEntry++;
00203 }
00204
00205
00206 else
00207 {
00208
00209 DeleteEntryL();
00210
00211 iCurrentEntry++;
00212 }
00213 }
00214
00215
00216 if (folderId != KMsvNullIndexEntryId)
00217 {
00218 User::LeaveIfError(iEntry->SetEntry(folderId));
00219
00220
00221 TFileName subDir = iRelativePath;
00222 subDir.Append(iEntry->Entry().iDescription);
00223 subDir.Append(KPathDelimiter);
00224
00225 CTxtRefreshMBox *folderSynchroniser = CTxtRefreshMBox::NewL(iFs, subDir, folderId, iEntry, iServiceEntryId, iTxtSettings);
00226 CleanupStack::PushL(folderSynchroniser);
00227 while (!folderSynchroniser->DoStepL()) ;
00228 CleanupStack::PopAndDestroy();
00229 }
00230
00231 return EFalse;
00232 }
00233