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(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       // ### how to pass it to kontact for displaying together with the "Cannot load Part" box?
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   // the part was deleted, we need to remove it from the part map to not return
00081   // a dangling pointer in createPart
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 // vim: sw=2 sts=2 et tw=80
KDE Logo
This file is part of the documentation for kontact Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 4 14:43:45 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003