kontact Library API Documentation

core.cpp

00001 /*
00002    This file is part of KDE Kontact.
00003 
00004    Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@kde.org>
00005    Copyright (c) 2002-2003 Daniel Molkentin <molkentin@kde.org>
00006    Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00007 
00008    This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public
00010    License as published by the Free Software Foundation; either
00011    version 2 of the License, or (at your option) any later version.
00012 
00013    This library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public License
00019    along with this library; see the file COPYING.LIB.  If not, write to
00020    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021    Boston, MA 02111-1307, USA.
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() << "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() << "Creating new KPart" << endl;
00055 
00056   KParts::ReadOnlyPart *part =
00057       KParts::ComponentFactory::
00058           createPartInstanceFromLibrary<KParts::ReadOnlyPart>
00059               ( libname, this, 0, this, "kontact" );
00060 
00061   if ( part ) {
00062     mParts.insert( libname, part );
00063     QObject::connect( part, SIGNAL( destroyed( QObject * ) ),
00064         SLOT( slotPartDestroyed( QObject * ) ) );
00065   }
00066 
00067   return part;
00068 }
00069 
00070 void Core::slotPartDestroyed( QObject * obj )
00071 {
00072   // the part was deleted, we need to remove it from the part map to not return
00073   // a dangling pointer in createPart
00074   QMap<QCString, KParts::ReadOnlyPart*>::Iterator end = mParts.end();
00075   QMap<QCString, KParts::ReadOnlyPart*>::Iterator it = mParts.begin();
00076   for ( ; it != end; ++it ) {
00077     if ( it.data() == obj ) {
00078       mParts.remove( it );
00079       return;
00080     }
00081   }
00082 }
00083 
00084 void Core::checkNewDay()
00085 {
00086   if ( mLastDate != QDate::currentDate() )
00087     emit dayChanged( QDate::currentDate() );
00088 
00089   mLastDate = QDate::currentDate();
00090 }
00091 
00092 #include "core.moc"
00093 // vim: sw=2 sts=2 et tw=80
KDE Logo
This file is part of the documentation for kontact Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:39:00 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003