6 #include "kmfolderdir.h"
7 #include "kmfoldersearch.h"
8 #include "kmfoldercachedimap.h"
13 #include <tdelocale.h>
14 #include <tdemessagebox.h>
16 #include <kstandarddirs.h>
21 KMFolderRootDir::KMFolderRootDir(KMFolderMgr* manager,
const TQString& path,
22 KMFolderDirType dirType)
30 KMFolderRootDir::~KMFolderRootDir()
39 void KMFolderRootDir::setPath(
const TQString& aPath)
46 TQString KMFolderRootDir::path()
const
53 TQString KMFolderRootDir::prettyURL()
const
55 if ( !mBaseURL.isEmpty() )
56 return i18n( mBaseURL.data() );
63 void KMFolderRootDir::setBaseURL(
const TQCString &baseURL )
70 KMFolderMgr* KMFolderRootDir::manager()
const
79 const TQString& name, KMFolderDirType dirType )
80 : KMFolderNode( parent, name ), KMFolderNodeList(),
81 mOwner( owner ), mDirType( dirType )
83 setAutoDelete(
true );
88 KMFolderDir::~KMFolderDir()
99 assert(!aFolderName.isEmpty());
101 if (mDirType == KMImapDir)
102 fld =
new KMFolder(
this, aFolderName, KMFolderTypeImap );
104 fld =
new KMFolder(
this, aFolderName, aFolderType );
107 fld->setSystemFolder(aSysFldr);
111 for (fNode=first(); fNode; fNode=next()) {
112 if (fNode->name().lower() > fld->name().lower()) {
113 insert( index, fld );
134 p = parent()->path();
148 return mOwner->
label();
159 parentUrl = parent()->prettyURL();
160 if ( !parentUrl.isEmpty() )
161 return parentUrl +
'/' +
label();
172 parentFolder->
setChild( folderDir );
177 KMFolderType dirTypeToFolderType( KMFolderDirType dirType )
183 case KMStandardDir:
return KMFolderTypeMaildir;
185 case KMImapDir:
return KMFolderTypeImap;
186 case KMDImapDir:
return KMFolderTypeCachedImap;
187 case KMSearchDir:
return KMFolderTypeSearch;
188 default: Q_ASSERT(
false );
return KMFolderTypeMaildir;
197 TQFileInfo* fileInfo;
199 TQPtrList<KMFolder> folderList;
203 const TQString fldPath =
path();
204 dir.setFilter(TQDir::Files | TQDir::Dirs | TQDir::Hidden);
205 dir.setNameFilter(
"*");
207 if (!dir.cd(fldPath, TRUE))
209 TQString msg = i18n(
"<qt>Cannot enter folder <b>%1</b>.</qt>").arg(fldPath);
210 KMessageBox::information(0, msg);
214 TQFileInfoList* fiList=(TQFileInfoList*)dir.entryInfoList();
217 TQString msg = i18n(
"<qt>Folder <b>%1</b> is unreadable.</qt>").arg(fldPath);
218 KMessageBox::information(0, msg);
222 for (fileInfo=fiList->first(); fileInfo; fileInfo=fiList->next())
224 const TQString fname = fileInfo->fileName();
225 if( ( fname[0] ==
'.' ) && !fname.endsWith(
".directory" ) ) {
229 if( fname ==
".directory" ) {
234 if ( fileInfo->isDir() &&
235 fname.startsWith(
"." ) && fname.endsWith(
".directory" ) ) {
236 diList.append(fname);
240 if ( mDirType == KMImapDir
241 &&
path().startsWith( KMFolderImap::cacheLocation() ) )
244 if ( KMFolderImap::encodeFileName(
245 KMFolderImap::decodeFileName( fname ) ) == fname )
247 folder =
new KMFolder(
this, KMFolderImap::decodeFileName( fname ),
250 folderList.append(folder);
253 else if ( mDirType == KMDImapDir
254 &&
path().startsWith( KMFolderCachedImap::cacheLocation() ) )
256 if (fileInfo->isDir())
260 TQString maildir(fname +
"/new");
261 TQString imapcachefile = TQString::fromLatin1(
".%1.uidcache").arg(fname);
262 if ( dir.exists( imapcachefile) || dir.exists( maildir ) )
264 folder =
new KMFolder(
this, fname, KMFolderTypeCachedImap );
266 folderList.append(folder);
270 else if ( mDirType == KMSearchDir)
272 folder =
new KMFolder(
this, fname, KMFolderTypeSearch );
274 folderList.append(folder);
276 else if ( mDirType == KMStandardDir )
280 if (fileInfo->isDir())
283 if( dir.exists( fname +
"/new" ) )
285 folder =
new KMFolder(
this, fname, KMFolderTypeMaildir );
287 folderList.append(folder);
293 folder =
new KMFolder(
this, fname, KMFolderTypeMbox );
295 folderList.append(folder);
300 TQStringList dirsWithoutFolder = diList;
301 for (folder=folderList.first(); folder; folder=folderList.next())
303 for(TQStringList::Iterator it = diList.begin();
306 if (*it ==
"." + folder->
fileName() +
".directory")
308 dirsWithoutFolder.remove( *it );
317 if ( type() == KMDImapDir ) {
318 for ( TQStringList::Iterator it = dirsWithoutFolder.begin();
319 it != dirsWithoutFolder.end(); ++it ) {
322 TQString folderName = *it;
323 int right = folderName.find(
".directory" );
324 int left = folderName.find(
"." );
325 Q_ASSERT( left != -1 && right != -1 );
326 folderName = folderName.mid( left + 1, right - 1 );
328 kdDebug(5006) <<
"Found dir without associated folder: " << ( *it ) <<
", recreating the folder " << folderName <<
"." << endl;
331 KMFolder *folder =
new KMFolder(
this, folderName, KMFolderTypeCachedImap );
333 folderList.append( folder );
346 for (fNode=first(); fNode; fNode=next()) {
347 if (fNode->name() == aName)
357 return parent()->manager();
361 #include "kmfolderdir.moc"
KMail list that manages the contents of one directory that may contain folders and/or other directori...
virtual KMFolder * createFolder(const TQString &folderName, bool sysFldr=false, KMFolderType folderType=KMFolderTypeMbox)
Create a mail folder in this directory with given name.
virtual TQString path() const
Return full pathname of this directory.
void addDirToParent(const TQString &dirName, KMFolder *parentFolder)
Adds the given subdirectory of this directory to the associated folder.
virtual bool reload()
Read contents of directory.
virtual TQString prettyURL() const
URL of the node for visualization purposes.
virtual KMFolderNode * hasNamedFolder(const TQString &name)
Returns folder with given name or zero if it does not exist.
TQString label() const
Returns the label of the folder for visualization.
virtual KMFolderMgr * manager() const
Returns the folder manager that manages this folder.
void correctUnreadMsgsCount()
A cludge to help make sure the count of unread messges is kept in sync.
virtual TQString label() const
Returns the label of the folder for visualization.
TQString fileName() const
Returns the filename of the folder (reimplemented in KMFolderImap)
void setChild(KMFolderDir *aChild)
Set the folder directory associated with this node.