libkdepim

kpartsdesignerplugin.cpp

00001 /*
00002     Copyright (C) 2004, David Faure <faure@kde.org>
00003     This file is part of the KDE project
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License version 2, as published by the Free Software Foundation.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kpartsdesignerplugin.h"
00021 
00022 #include <kparts/componentfactory.h>
00023 #include <kparts/part.h>
00024 #include <kmimetype.h>
00025 #include <qlayout.h>
00026 #include <kapplication.h>
00027 #include <kdepimmacros.h>
00028 
00029 KPartsGenericPart::KPartsGenericPart( QWidget* parentWidget, const char* name )
00030     : QWidget( parentWidget, name ), m_part( 0 )
00031 {
00032     QVBoxLayout* layout = new QVBoxLayout( this );
00033     layout->setAutoAdd( true );
00034 }
00035 
00036 void KPartsGenericPart::load()
00037 {
00038     if ( m_mimetype.isEmpty() || m_url.isEmpty() )
00039         return; // not enough info yet
00040     // Here it crashes in KSycoca::openDatabase when trying to load the stuff from designer itself
00041     // Not sure why - but it's not really needed anyway.
00042     if ( !kapp )
00043         return;
00044     QString mimetype = m_mimetype;
00045     if ( mimetype == "auto" )
00046         mimetype == KMimeType::findByURL( m_url )->name();
00047     if ( m_part ) {
00048         delete m_part;
00049     }
00050     // "this" is both the parent widget and the parent object
00051     m_part = KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>( mimetype, QString::null, this, 0, this, 0 );
00052     if ( m_part ) {
00053         m_part->openURL( m_url );
00054         m_part->widget()->show();
00055     }
00056 }
00057 
00059 
00060 static const char* mykey = "KPartsGenericPart";
00061 
00062 QStringList KPartsWidgetPlugin::keys() const {
00063     return QStringList() << mykey;
00064 }
00065 
00066 QWidget * KPartsWidgetPlugin::create( const QString & key, QWidget * parent, const char * name ) {
00067     if ( key == mykey )
00068         return new KPartsGenericPart( parent, name );
00069     return 0;
00070 }
00071 
00072 QString KPartsWidgetPlugin::group( const QString & key ) const {
00073     if ( key == mykey )
00074         return "Display (KDE)";
00075     return QString::null;
00076 }
00077 
00078 #if 0
00079 QIconSet KPartsWidgetPlugin::iconSet( const QString & key ) const {
00080   return QIconSet();
00081 }
00082 #endif
00083 
00084 QString KPartsWidgetPlugin::includeFile( const QString & key ) const {
00085     if ( key == mykey )
00086         return "partplugin.h";
00087     return QString::null;
00088 }
00089 
00090 QString KPartsWidgetPlugin::toolTip( const QString & key ) const {
00091     if ( key == mykey )
00092         return "Generic KParts viewer";
00093     return QString::null;
00094 }
00095 
00096 QString KPartsWidgetPlugin::whatsThis( const QString & key ) const {
00097     if ( key == mykey )
00098         return "A widget to embed any KParts viewer, given a url and optionally a mimetype";
00099     return QString::null;
00100 }
00101 
00102 bool KPartsWidgetPlugin::isContainer( const QString & /*key*/ ) const {
00103     return false;
00104 }
00105 
00107 #ifndef KDE_Q_EXPORT_PLUGIN
00108 #define KDE_Q_EXPORT_PLUGIN(PLUGIN) \
00109   Q_EXTERN_C KDE_EXPORT const char* qt_ucm_query_verification_data(); \
00110   Q_EXTERN_C KDE_EXPORT QUnknownInterface* ucm_instantiate(); \
00111   Q_EXPORT_PLUGIN(PLUGIN)
00112 #endif
00113 
00114 KDE_Q_EXPORT_PLUGIN( KPartsWidgetPlugin )
00115 
00116 #include "kpartsdesignerplugin.moc"
00117 
KDE Home | KDE Accessibility Home | Description of Access Keys