• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.3 API Reference
  • KDE Home
  • Contact Us
 

Kontact Plugin Interface Library

core.cpp
00001 /*
00002   This file is part of the KDE Kontact Plugin Interface Library.
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., 51 Franklin Street, Fifth Floor,
00021   Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include "core.h"
00025 
00026 #include <kdebug.h>
00027 #include <kparts/part.h>
00028 #include <kparts/componentfactory.h>
00029 
00030 #include <QDateTime>
00031 #include <QTimer>
00032 
00033 using namespace KontactInterface;
00034 
00035 //@cond PRIVATE
00036 class KontactInterface::Core::Private
00037 {
00038   Core *const q;
00039 
00040   public:
00041     explicit Private( Core *qq );
00042 
00043     void slotPartDestroyed( QObject * );
00044     void checkNewDay();
00045 
00046     QString lastErrorMessage;
00047     QDate mLastDate;
00048     QMap<QByteArray,KParts::ReadOnlyPart *> mParts;
00049 };
00050 
00051 Core::Private::Private( Core *qq )
00052   : q( qq ), mLastDate( QDate::currentDate() )
00053 {
00054 }
00055 //@endcond
00056 
00057 Core::Core( QWidget *parent, Qt::WindowFlags f )
00058   : KParts::MainWindow( parent, f ), d( new Private( this ) )
00059 {
00060   QTimer *timer = new QTimer( this );
00061   connect( timer, SIGNAL(timeout()), SLOT(checkNewDay()) );
00062   timer->start( 1000 * 60 );
00063 }
00064 
00065 Core::~Core()
00066 {
00067   delete d;
00068 }
00069 
00070 KParts::ReadOnlyPart *Core::createPart( const char *libname )
00071 {
00072   kDebug() << libname;
00073 
00074   QMap<QByteArray,KParts::ReadOnlyPart *>::ConstIterator it;
00075   it = d->mParts.constFind( libname );
00076   if ( it != d->mParts.constEnd() ) {
00077     return it.value();
00078   }
00079 
00080   kDebug() << "Creating new KPart";
00081 
00082   KPluginLoader loader( libname );
00083   kDebug() << loader.fileName();
00084   KPluginFactory *factory = loader.factory();
00085   KParts::ReadOnlyPart *part = 0;
00086   if ( factory ) {
00087     part = factory->create<KParts::ReadOnlyPart>( this );
00088   }
00089 
00090   if (part) {
00091     d->mParts.insert( libname, part );
00092     QObject::connect( part, SIGNAL(destroyed(QObject*)),
00093                       SLOT(slotPartDestroyed(QObject*)) );
00094   } else {
00095     d->lastErrorMessage = loader.errorString();
00096     kWarning() << d->lastErrorMessage;
00097   }
00098 
00099   return part;
00100 }
00101 
00102 //@cond PRIVATE
00103 void Core::Private::slotPartDestroyed( QObject *obj )
00104 {
00105   // the part was deleted, we need to remove it from the part map to not return
00106   // a dangling pointer in createPart
00107   QMap<QByteArray, KParts::ReadOnlyPart*>::Iterator end = mParts.end();
00108   QMap<QByteArray, KParts::ReadOnlyPart*>::Iterator it = mParts.begin();
00109   for ( ; it != end; ++it ) {
00110     if ( it.value() == obj ) {
00111       mParts.erase( it );
00112       return;
00113     }
00114   }
00115 }
00116 
00117 void Core::Private::checkNewDay()
00118 {
00119   if ( mLastDate != QDate::currentDate() ) {
00120     emit q->dayChanged( QDate::currentDate() );
00121   }
00122 
00123   mLastDate = QDate::currentDate();
00124 }
00125 //@endcond
00126 
00127 QString Core::lastErrorMessage() const
00128 {
00129   return d->lastErrorMessage;
00130 }
00131 
00132 #include "core.moc"
00133 // vim: sw=2 sts=2 et tw=80
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:51:33 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kontact Plugin Interface Library

Skip menu "Kontact Plugin Interface Library"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal