00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
#include "core.h"
00025
00026
#include <kparts/part.h>
00027
#include <kparts/componentfactory.h>
00028
#include <kdebug.h>
00029
#include <qtimer.h>
00030
00031
using namespace Kontact;
00032
00033 Core::Core(
QWidget *parent,
const char *name )
00034 : KParts::MainWindow( parent, name )
00035 {
00036
QTimer* timer =
new QTimer(
this );
00037 mLastDate = QDate::currentDate();
00038 connect(timer, SIGNAL( timeout() ), SLOT( checkNewDay() ) );
00039 timer->start( 1000*60 );
00040 }
00041
00042 Core::~Core()
00043 {
00044 }
00045
00046 KParts::ReadOnlyPart *Core::createPart(
const char *libname )
00047 {
00048 kdDebug(5601) <<
"Core::createPart(): " << libname << endl;
00049
00050
QMap<QCString,KParts::ReadOnlyPart *>::ConstIterator it;
00051 it = mParts.find( libname );
00052
if ( it != mParts.end() )
return it.data();
00053
00054 kdDebug(5601) <<
"Creating new KPart" << endl;
00055
00056
int error = 0;
00057 KParts::ReadOnlyPart *part =
00058 KParts::ComponentFactory::
00059 createPartInstanceFromLibrary<KParts::ReadOnlyPart>
00060 ( libname,
this, 0,
this,
"kontact",
QStringList(), &error );
00061
00062
if ( part ) {
00063 mParts.insert( libname, part );
00064 QObject::connect( part, SIGNAL( destroyed(
QObject * ) ),
00065 SLOT( slotPartDestroyed(
QObject * ) ) );
00066 }
else {
00067
if ( error == KParts::ComponentFactory::ErrNoLibrary ) {
00068
00069 kdWarning(5601) << KLibLoader::self()->lastErrorMessage() << endl;
00070 }
else {
00071 kdWarning(5601) <<
"KParts::ComponentFactory::createInstanceFromFactory returned error code " << error <<
" for " << libname << endl;
00072 }
00073 }
00074
00075
return part;
00076 }
00077
00078
void Core::slotPartDestroyed(
QObject * obj )
00079 {
00080
00081
00082
QMap<QCString, KParts::ReadOnlyPart*>::Iterator end = mParts.end();
00083
QMap<QCString, KParts::ReadOnlyPart*>::Iterator it = mParts.begin();
00084
for ( ; it != end; ++it ) {
00085
if ( it.data() == obj ) {
00086 mParts.remove( it );
00087
return;
00088 }
00089 }
00090 }
00091
00092
void Core::checkNewDay()
00093 {
00094
if ( mLastDate != QDate::currentDate() )
00095 emit
dayChanged( QDate::currentDate() );
00096
00097 mLastDate = QDate::currentDate();
00098 }
00099
00100
#include "core.moc"
00101