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.
 
 
 

191 lines
4.7 KiB

// KMail startup and initialize code
// Author: Stefan Taferner <taferner@alpin.or.at>
#include <qstring.h>
#include <qdir.h>
#include "kmglobal.h"
#include "kmmainwin.h"
#include "kmacctmgr.h"
#include "kmfoldermgr.h"
#include "kmfilteraction.h"
#include "kmfolder.h"
#include "kmsender.h"
#include "kbusyptr.h"
#include "kmfiltermgr.h"
#include "kmversion.h"
#include "kmmessage.h"
#include <kapp.h>
#include <stdio.h>
#include <stdlib.h>
#include <kmsgbox.h>
#include <klocale.h>
#include <kstdaccel.h>
#include <kmidentity.h>
#include <dirent.h>
#include <sys/stat.h>
KBusyPtr* kbp = NULL;
KApplication* app = NULL;
KMAcctMgr* acctMgr = NULL;
KMFolderMgr* folderMgr = NULL;
KMFilterMgr* filterMgr = NULL;
KMSender* msgSender = NULL;
KLocale* nls = NULL;
KMFolder* inboxFolder = NULL;
KMFolder* outboxFolder = NULL;
KMFolder* queuedFolder = NULL;
KMFolder* sentFolder = NULL;
KMFolder* trashFolder = NULL;
KStdAccel* keys = NULL;
KMIdentity* identity = NULL;
KMFilterActionDict* filterActionDict = NULL;
bool shuttingDown = FALSE;
const char* aboutText =
"KMail [" KMAIL_VERSION "] by\n\n"
"Stefan Taferner <taferner@kde.org>,\n"
"Markus Wübben <markus.wuebben@kde.org>\n\n"
"based on the work of:\n"
"Lynx <lynx@topaz.hknet.com>,\n"
"Stephan Meyer <Stephan.Meyer@pobox.com>,\n"
"and the above authors.\n\n"
"This program is covered by the GPL.";
static msg_handler oldMsgHandler = NULL;
//-----------------------------------------------------------------------------
// Message handler
static void kmailMsgHandler(QtMsgType aType, const char* aMsg)
{
QString appName = app->appName();
switch (aType)
{
case QtDebugMsg:
fprintf(stderr, "%s: %s\n", (const char*)app->appName(), aMsg);
break;
case QtWarningMsg:
fprintf(stderr, "%s: %s\n", (const char*)app->appName(), aMsg);
KMsgBox::message(NULL, appName+" "+nls->translate("warning"), aMsg,
KMsgBox::EXCLAMATION);
break;
case QtFatalMsg:
fprintf(stderr, appName+" "+nls->translate("fatal error")+": %s\n", aMsg);
KMsgBox::message(NULL, appName+" "+nls->translate("fatal error"),
aMsg, KMsgBox::STOP);
abort();
}
}
//-----------------------------------------------------------------------------
void testDir( const char *_name )
{
DIR *dp;
QString c = getenv( "HOME" );
c += _name;
dp = opendir( c.data() );
if ( dp == NULL )
::mkdir( c.data(), S_IRWXU );
else
closedir( dp );
}
//-----------------------------------------------------------------------------
static void init(int argc, char *argv[])
{
QString acctPath, foldersPath;
KConfig* cfg;
app = new KApplication(argc, argv, "kmail");
nls = app->getLocale();
kbp = new KBusyPtr;
cfg = app->getConfig();
keys = new KStdAccel(cfg);
oldMsgHandler = qInstallMsgHandler(kmailMsgHandler);
testDir("/.kde");
testDir("/.kde/share");
testDir("/.kde/share/config");
testDir("/.kde/share/apps");
testDir("/.kde/share/apps/kmail");
identity = new KMIdentity;
cfg->setGroup("General");
foldersPath = cfg->readEntry("folders",
QDir::homeDirPath() + QString("/KMail"));
acctPath = cfg->readEntry("accounts", foldersPath + "/.kmail-accounts");
folderMgr = new KMFolderMgr(foldersPath);
acctMgr = new KMAcctMgr(acctPath);
filterMgr = new KMFilterMgr;
filterActionDict = new KMFilterActionDict;
inboxFolder = (KMFolder*)folderMgr->findOrCreate(
cfg->readEntry("inboxFolder", "inbox"));
//inboxFolder->open();
outboxFolder = folderMgr->findOrCreate(cfg->readEntry("outboxFolder", "outbox"));
outboxFolder->setType("out");
outboxFolder->open();
sentFolder = folderMgr->findOrCreate(cfg->readEntry("sentFolder", "sent_mail"));
sentFolder->setType("st");
sentFolder->open();
trashFolder = folderMgr->findOrCreate(cfg->readEntry("trashFolder", "trash"));
trashFolder->setType("tr");
trashFolder->open();
acctMgr->readConfig();
filterMgr->readConfig();
KMMessage::readConfig();
msgSender = new KMSender;
}
//-----------------------------------------------------------------------------
static void cleanup(void)
{
shuttingDown = TRUE;
if (inboxFolder) inboxFolder->close(TRUE);
if (outboxFolder) outboxFolder->close(TRUE);
if (sentFolder) sentFolder->close(TRUE);
if (trashFolder) trashFolder->close(TRUE);
if (msgSender) delete msgSender;
if (filterMgr) delete filterMgr;
if (acctMgr) delete acctMgr;
if (folderMgr) delete folderMgr;
if (kbp) delete kbp;
qInstallMsgHandler(oldMsgHandler);
app->getConfig()->sync();
}
//-----------------------------------------------------------------------------
main(int argc, char *argv[])
{
KMMainWin* mainWin;
init(argc, argv);
mainWin = new KMMainWin;
mainWin->show();
app->exec();
cleanup();
}