libkdepim

embeddedurlpage.cpp

00001 /*
00002     This file is part of libkdepim.
00003 
00004     Copyright (c) 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
00005     Part of loadContents() copied from the kpartsdesignerplugin:
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 <kparts/componentfactory.h>
00026 #include <kparts/browserextension.h>
00027 #include <kparts/part.h>
00028 #include <kmimetype.h>
00029 #include <klocale.h>
00030 #include <qlayout.h>
00031 #include <qlabel.h>
00032 
00033 using namespace KPIM;
00034 
00035 EmbeddedURLPage::EmbeddedURLPage( const QString &url, const QString &mimetype,
00036                                   QWidget *parent, const char *name )
00037   : QWidget( parent, name ), mUri(url), mMimeType( mimetype ), mPart( 0 )
00038 {
00039   initGUI( url, mimetype );
00040 }
00041 
00042 void EmbeddedURLPage::initGUI( const QString &url, const QString &/*mimetype*/ )
00043 {
00044   QVBoxLayout *layout = new QVBoxLayout( this );
00045   layout->setAutoAdd( true );
00046   new QLabel( 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     QString 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, QString::null, this, 0, 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, SIGNAL( openURLRequestDelayed( const KURL &, const KParts::URLArgs & ) ),
00066 //              mPart, SLOT( openURL( const KURL & ) ) );
00067              this, SIGNAL( openURL( const KURL & ) ) );
00068   }
00069 }
00070 
00071 #include "embeddedurlpage.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys