libtdepim

embeddedurlpage.cpp

00001 /*
00002     This file is part of libtdepim.
00003 
00004     Copyright (c) 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
00005     Part of loadContents() copied from the tdepartsdesignerplugin:
00006     Copyright (C) 2005, David Faure <faure@kde.org>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include "embeddedurlpage.h"
00025 #include <tdeparts/componentfactory.h>
00026 #include <tdeparts/browserextension.h>
00027 #include <tdeparts/part.h>
00028 #include <kmimetype.h>
00029 #include <tdelocale.h>
00030 #include <tqlayout.h>
00031 #include <tqlabel.h>
00032 
00033 using namespace KPIM;
00034 
00035 EmbeddedURLPage::EmbeddedURLPage( const TQString &url, const TQString &mimetype,
00036                                   TQWidget *parent, const char *name )
00037   : TQWidget( parent, name ), mUri(url), mMimeType( mimetype ), mPart( 0 )
00038 {
00039   initGUI( url, mimetype );
00040 }
00041 
00042 void EmbeddedURLPage::initGUI( const TQString &url, const TQString &/*mimetype*/ )
00043 {
00044   TQVBoxLayout *layout = new TQVBoxLayout( this );
00045   layout->setAutoAdd( true );
00046   new TQLabel( i18n("Showing URL %1").arg( url ), this );
00047 }
00048 
00049 void EmbeddedURLPage::loadContents()
00050 {
00051   if ( !mPart ) {
00052     if ( mMimeType.isEmpty() || mUri.isEmpty() )
00053         return;
00054     TQString mimetype = mMimeType;
00055     if ( mimetype == "auto" )
00056         mimetype == KMimeType::findByURL( mUri )->name();
00057     // "this" is both the parent widget and the parent object
00058     mPart = KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>( mimetype, TQString(), TQT_TQWIDGET(this), 0, TQT_TQOBJECT(this), 0 );
00059     if ( mPart ) {
00060         mPart->openURL( mUri );
00061         mPart->widget()->show();
00062     }
00063 //void KParts::BrowserExtension::openURLRequestDelayed( const KURL &url, const KParts::URLArgs &args = KParts::URLArgs() )
00064     KParts::BrowserExtension* be = KParts::BrowserExtension::childObject( mPart );
00065     connect( be, TQT_SIGNAL( openURLRequestDelayed( const KURL &, const KParts::URLArgs & ) ),
00066 //              mPart, TQT_SLOT( openURL( const KURL & ) ) );
00067              this, TQT_SIGNAL( openURL( const KURL & ) ) );
00068   }
00069 }
00070 
00071 #include "embeddedurlpage.moc"