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

Kontact Plugin Interface Library

  • kontactinterface
core.cpp
1/*
2 This file is part of the KDE Kontact Plugin Interface Library.
3
4 Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@kde.org>
5 Copyright (c) 2002-2003 Daniel Molkentin <molkentin@kde.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22*/
23
24#include "core.h"
25
26#include <kdebug.h>
27#include <kparts/part.h>
28#include <kparts/componentfactory.h>
29
30#include <QDateTime>
31#include <QTimer>
32
33using namespace KontactInterface;
34
35//@cond PRIVATE
36class KontactInterface::Core::Private
37{
38 Core *const q;
39
40 public:
41 explicit Private( Core *qq );
42
43 void slotPartDestroyed( QObject * );
44 void checkNewDay();
45
46 QString lastErrorMessage;
47 QDate mLastDate;
48 QMap<QByteArray,KParts::ReadOnlyPart *> mParts;
49};
50
51Core::Private::Private( Core *qq )
52 : q( qq ), mLastDate( QDate::currentDate() )
53{
54}
55//@endcond
56
57Core::Core( QWidget *parent, Qt::WindowFlags f )
58 : KParts::MainWindow( parent, f ), d( new Private( this ) )
59{
60 QTimer *timer = new QTimer( this );
61 connect( timer, SIGNAL(timeout()), SLOT(checkNewDay()) );
62 timer->start( 1000 * 60 );
63}
64
65Core::~Core()
66{
67 delete d;
68}
69
70KParts::ReadOnlyPart *Core::createPart( const char *libname )
71{
72 kDebug() << libname;
73
74 QMap<QByteArray,KParts::ReadOnlyPart *>::ConstIterator it;
75 it = d->mParts.constFind( libname );
76 if ( it != d->mParts.constEnd() ) {
77 return it.value();
78 }
79
80 kDebug() << "Creating new KPart";
81
82 KPluginLoader loader( QString::fromLatin1(libname) );
83 kDebug() << loader.fileName();
84 KPluginFactory *factory = loader.factory();
85 KParts::ReadOnlyPart *part = 0;
86 if ( factory ) {
87 part = factory->create<KParts::ReadOnlyPart>( this );
88 }
89
90 if ( part ) {
91 d->mParts.insert( libname, part );
92 QObject::connect( part, SIGNAL(destroyed(QObject*)),
93 SLOT(slotPartDestroyed(QObject*)) );
94 } else {
95 d->lastErrorMessage = loader.errorString();
96 kWarning() << d->lastErrorMessage;
97 }
98
99 return part;
100}
101
102//@cond PRIVATE
103void Core::Private::slotPartDestroyed( QObject *obj )
104{
105 // the part was deleted, we need to remove it from the part map to not return
106 // a dangling pointer in createPart
107 QMap<QByteArray, KParts::ReadOnlyPart*>::Iterator end = mParts.end();
108 QMap<QByteArray, KParts::ReadOnlyPart*>::Iterator it = mParts.begin();
109 for ( ; it != end; ++it ) {
110 if ( it.value() == obj ) {
111 mParts.erase( it );
112 return;
113 }
114 }
115}
116
117void Core::Private::checkNewDay()
118{
119 if ( mLastDate != QDate::currentDate() ) {
120 emit q->dayChanged( QDate::currentDate() );
121 }
122
123 mLastDate = QDate::currentDate();
124}
125//@endcond
126
127QString Core::lastErrorMessage() const
128{
129 return d->lastErrorMessage;
130}
131
132#include "moc_core.cpp"
133// vim: sw=2 sts=2 et tw=80
KontactInterface::Core
The abstract interface that represents the Kontact core.
Definition: core.h:40
KontactInterface::Core::~Core
virtual ~Core()
Destroys the core object.
Definition: core.cpp:65
KontactInterface::Core::Core
Core(QWidget *parent=0, Qt::WindowFlags flags=KDE_DEFAULT_WINDOWFLAGS)
Creates a new core object.
Definition: core.cpp:57
KontactInterface::Core::createPart
KParts::ReadOnlyPart * createPart(const char *library)
Definition: core.cpp:70
KontactInterface::Core::lastErrorMessage
QString lastErrorMessage() const
Returns the last error message for problems during KParts loading.
Definition: core.cpp:127
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.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.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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