You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

82 lines
1.6 KiB

// kmfoldermgr.cpp
#include <qdir.h>
#include <assert.h>
#include "kmfoldermgr.h"
#include "kmfolder.h"
//-----------------------------------------------------------------------------
KMFolderMgr::KMFolderMgr(const char* aBasePath)
{
assert(aBasePath != NULL);
setBasePath(aBasePath);
}
//-----------------------------------------------------------------------------
KMFolderMgr::~KMFolderMgr()
{
mBasePath = NULL;
}
//-----------------------------------------------------------------------------
void KMFolderMgr::setBasePath(const char* aBasePath)
{
QDir dir;
assert(aBasePath != NULL);
if (aBasePath[0] == '~')
{
mBasePath = QDir::homeDirPath();
mBasePath.append("/");
mBasePath.append(aBasePath+1);
}
else
{
mBasePath = "";
mBasePath.append(aBasePath);
}
mBasePath.detach();
dir.setPath(mBasePath);
if (!dir.exists())
{
KMFolder fld(&mDir);
warning("Directory\n"+mBasePath+"\ndoes not exist.\n\n"
"KMail will create it now.");
dir.mkdir(mBasePath, TRUE);
fld.setName("inbox");
fld.create();
fld.close();
fld.setName("outbox");
fld.create();
fld.close();
fld.setName("trash");
fld.create();
fld.close();
}
mDir.setPath(mBasePath);
mDir.reload();
}
//-----------------------------------------------------------------------------
KMFolder* KMFolderMgr::find(const char* folderName, bool foldersOnly)
{
KMFolderNode* node;
for (node=mDir.first(); node; node=mDir.next())
{
if (node->isDir() && foldersOnly) continue;
if (node->name()==folderName) return (KMFolder*)node;
}
return NULL;
}