tdepartsdesignerplugin.cpp
1/*
2 Copyright (C) 2004, David Faure <faure@kde.org>
3 This file is part of the KDE project
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2, as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "tdepartsdesignerplugin.h"
21
22#include <tdeparts/componentfactory.h>
23#include <tdeparts/part.h>
24#include <kmimetype.h>
25#include <tqlayout.h>
26#include <tdeapplication.h>
27#include <tdemacros.h>
28
29KPartsGenericPart::KPartsGenericPart( TQWidget* parentWidget, const char* name )
30 : TQWidget( parentWidget, name ), m_part( 0 )
31{
32 TQVBoxLayout* layout = new TQVBoxLayout( this );
33 layout->setAutoAdd( true );
34}
35
36void KPartsGenericPart::load()
37{
38 if ( m_mimetype.isEmpty() || m_url.isEmpty() )
39 return; // not enough info yet
40 // Here it crashes in KSycoca::openDatabase when trying to load the stuff from designer itself
41 // Not sure why - but it's not really needed anyway.
42 if ( !tdeApp )
43 return;
44 TQString mimetype = m_mimetype;
45 if ( mimetype == "auto" )
46 mimetype == KMimeType::findByURL( m_url )->name();
47 if ( m_part ) {
48 delete m_part;
49 }
50 // "this" is both the parent widget and the parent object
51 m_part = KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>( mimetype, TQString(), this, 0, this, 0 );
52 if ( m_part ) {
53 m_part->openURL( m_url );
54 m_part->widget()->show();
55 }
56}
57
59
60static const char* mykey = "KPartsGenericPart";
61
62TQStringList KPartsWidgetPlugin::keys() const {
63 return TQStringList() << mykey;
64}
65
66TQWidget * KPartsWidgetPlugin::create( const TQString & key, TQWidget * parent, const char * name ) {
67 if ( key == mykey )
68 return new KPartsGenericPart( parent, name );
69 return 0;
70}
71
72TQString KPartsWidgetPlugin::group( const TQString & key ) const {
73 if ( key == mykey )
74 return "Display (KDE)";
75 return TQString();
76}
77
78#if 0
79TQIconSet KPartsWidgetPlugin::iconSet( const TQString & key ) const {
80 return TQIconSet();
81}
82#endif
83
84TQString KPartsWidgetPlugin::includeFile( const TQString & key ) const {
85 if ( key == mykey )
86 return "partplugin.h";
87 return TQString();
88}
89
90TQString KPartsWidgetPlugin::toolTip( const TQString & key ) const {
91 if ( key == mykey )
92 return "Generic KParts viewer";
93 return TQString();
94}
95
96TQString KPartsWidgetPlugin::whatsThis( const TQString & key ) const {
97 if ( key == mykey )
98 return "A widget to embed any KParts viewer, given a url and optionally a mimetype";
99 return TQString();
100}
101
102bool KPartsWidgetPlugin::isContainer( const TQString & /*key*/ ) const {
103 return false;
104}
105
107#ifndef TDE_EXPORT_PLUGIN
108#define TDE_EXPORT_PLUGIN(PLUGIN) \
109 TQ_EXTERN_C TDE_EXPORT const char* qt_ucm_query_verification_data(); \
110 TQ_EXTERN_C TDE_EXPORT TQUnknownInterface* ucm_instantiate(); \
111 TQ_EXPORT_PLUGIN(PLUGIN)
112#endif
113
114TDE_EXPORT_PLUGIN( KPartsWidgetPlugin )
115
116#include "tdepartsdesignerplugin.moc"
117
Generic part loader, able to view any kind of file for which a KParts::ReadOnlyPart is available.
TQt designer plugin for embedding a KParts using KPartsGenericPart.