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 <tqlayout.h> 00026 #include <kapplication.h> 00027 #include <kdepimmacros.h> 00028 00029 KPartsGenericPart::KPartsGenericPart( TQWidget* parentWidget, const char* name ) 00030 : TQWidget( parentWidget, name ), m_part( 0 ) 00031 { 00032 TQVBoxLayout* layout = new TQVBoxLayout( 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 TQString 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, TQString(), TQT_TQWIDGET(this), 0, TQT_TQOBJECT(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 TQStringList KPartsWidgetPlugin::keys() const { 00063 return TQStringList() << mykey; 00064 } 00065 00066 TQWidget * KPartsWidgetPlugin::create( const TQString & key, TQWidget * parent, const char * name ) { 00067 if ( key == mykey ) 00068 return new KPartsGenericPart( parent, name ); 00069 return 0; 00070 } 00071 00072 TQString KPartsWidgetPlugin::group( const TQString & key ) const { 00073 if ( key == mykey ) 00074 return "Display (KDE)"; 00075 return TQString(); 00076 } 00077 00078 #if 0 00079 TQIconSet KPartsWidgetPlugin::iconSet( const TQString & key ) const { 00080 return TQIconSet(); 00081 } 00082 #endif 00083 00084 TQString KPartsWidgetPlugin::includeFile( const TQString & key ) const { 00085 if ( key == mykey ) 00086 return "partplugin.h"; 00087 return TQString(); 00088 } 00089 00090 TQString KPartsWidgetPlugin::toolTip( const TQString & key ) const { 00091 if ( key == mykey ) 00092 return "Generic KParts viewer"; 00093 return TQString(); 00094 } 00095 00096 TQString KPartsWidgetPlugin::whatsThis( const TQString & key ) const { 00097 if ( key == mykey ) 00098 return "A widget to embed any KParts viewer, given a url and optionally a mimetype"; 00099 return TQString(); 00100 } 00101 00102 bool KPartsWidgetPlugin::isContainer( const TQString & /*key*/ ) const { 00103 return false; 00104 } 00105 00107 #ifndef KDE_TQ_EXPORT_PLUGIN 00108 #define KDE_TQ_EXPORT_PLUGIN(PLUGIN) \ 00109 TQ_EXTERN_C KDE_EXPORT const char* qt_ucm_query_verification_data(); \ 00110 TQ_EXTERN_C KDE_EXPORT TQUnknownInterface* ucm_instantiate(); \ 00111 TQ_EXPORT_PLUGIN(PLUGIN) 00112 #endif 00113 00114 KDE_TQ_EXPORT_PLUGIN( KPartsWidgetPlugin ) 00115 00116 #include "kpartsdesignerplugin.moc" 00117