libkdepim
kpartsdesignerplugin.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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;
00040
00041
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
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 & ) 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
|