kontact
core.cpp00001
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 #include <klocale.h>
00031
00032 using namespace Kontact;
00033
00034 class Core::Private
00035 {
00036 public:
00037 QString lastErrorMessage;
00038 };
00039
00040 Core::Core( QWidget *parent, const char *name )
00041 : KParts::MainWindow( parent, name )
00042 {
00043 d = new Private;
00044 QTimer* timer = new QTimer( this );
00045 mLastDate = QDate::currentDate();
00046 connect(timer, SIGNAL( timeout() ), SLOT( checkNewDay() ) );
00047 timer->start( 1000*60 );
00048 }
00049
00050 Core::~Core()
00051 {
00052 delete d;
00053 }
00054
00055 KParts::ReadOnlyPart *Core::createPart( const char *libname )
00056 {
00057 kdDebug(5601) << "Core::createPart(): " << libname << endl;
00058
00059 QMap<QCString,KParts::ReadOnlyPart *>::ConstIterator it;
00060 it = mParts.find( libname );
00061 if ( it != mParts.end() ) return it.data();
00062
00063 kdDebug(5601) << "Creating new KPart" << endl;
00064
00065 int error = 0;
00066 KParts::ReadOnlyPart *part =
00067 KParts::ComponentFactory::
00068 createPartInstanceFromLibrary<KParts::ReadOnlyPart>
00069 ( libname, this, 0, this, "kontact", QStringList(), &error );
00070
00071 KParts::ReadOnlyPart *pimPart = dynamic_cast<KParts::ReadOnlyPart*>( part );
00072 if ( pimPart ) {
00073 mParts.insert( libname, pimPart );
00074 QObject::connect( pimPart, SIGNAL( destroyed( QObject * ) ),
00075 SLOT( slotPartDestroyed( QObject * ) ) );
00076 } else {
00077
00078 switch( error ) {
00079 case KParts::ComponentFactory::ErrNoServiceFound:
00080 d->lastErrorMessage = i18n( "No service found" );
00081 break;
00082 case KParts::ComponentFactory::ErrServiceProvidesNoLibrary:
00083 d->lastErrorMessage = i18n( "Program error: the .desktop file for the service does not have a Library key." );
00084 break;
00085 case KParts::ComponentFactory::ErrNoLibrary:
00086 d->lastErrorMessage = KLibLoader::self()->lastErrorMessage();
00087 break;
00088 case KParts::ComponentFactory::ErrNoFactory:
00089 d->lastErrorMessage = i18n( "Program error: the library %1 does not provide a factory." ).arg( libname );
00090 break;
00091 case KParts::ComponentFactory::ErrNoComponent:
00092 d->lastErrorMessage = i18n( "Program error: the library %1 does not support creating components of the specified type" ).arg( libname );
00093 break;
00094 }
00095 kdWarning(5601) << d->lastErrorMessage << endl;
00096 }
00097
00098 return pimPart;
00099 }
00100
00101 void Core::slotPartDestroyed( QObject * obj )
00102 {
00103
00104
00105 QMap<QCString, KParts::ReadOnlyPart*>::Iterator end = mParts.end();
00106 QMap<QCString, KParts::ReadOnlyPart*>::Iterator it = mParts.begin();
00107 for ( ; it != end; ++it ) {
00108 if ( it.data() == obj ) {
00109 mParts.remove( it );
00110 return;
00111 }
00112 }
00113 }
00114
00115 void Core::checkNewDay()
00116 {
00117 if ( mLastDate != QDate::currentDate() )
00118 emit dayChanged( QDate::currentDate() );
00119
00120 mLastDate = QDate::currentDate();
00121 }
00122
00123 QString Core::lastErrorMessage() const
00124 {
00125 return d->lastErrorMessage;
00126 }
00127
00128 #include "core.moc"
00129
|