diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 4aed2c8219774f5d797760606b8489a92ddc5163 (patch) | |
tree | 3f8c130f7d269626bf6a9447407ef6c35954426a /konqueror/konq_factory.cc | |
download | tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'konqueror/konq_factory.cc')
-rw-r--r-- | konqueror/konq_factory.cc | 263 |
1 files changed, 263 insertions, 0 deletions
diff --git a/konqueror/konq_factory.cc b/konqueror/konq_factory.cc new file mode 100644 index 000000000..c873fcee9 --- /dev/null +++ b/konqueror/konq_factory.cc @@ -0,0 +1,263 @@ +/* This file is part of the KDE project + Copyright (C) 1999 Simon Hausmann <[email protected]> + Copyright (C) 1999 David Faure <[email protected]> + Copyright (C) 1999 Torben Weis <[email protected]> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#include <kparts/factory.h> +#include "konq_factory.h" +#include "version.h" + +#include <konq_settings.h> +#include <konq_mainwindow.h> +#include <kdebug.h> +#include <kaboutdata.h> +#include <klocale.h> +#include <kmessagebox.h> + +#include <qwidget.h> +#include <qfile.h> + +#include <assert.h> + +KAboutData *KonqFactory::s_aboutData = 0; + +KonqViewFactory::KonqViewFactory( KLibFactory *factory, const QStringList &args, + bool createBrowser ) + : m_factory( factory ), m_args( args ), m_createBrowser( createBrowser ) +{ + if ( m_createBrowser ) + m_args << QString::fromLatin1( "Browser/View" ); +} + +KParts::ReadOnlyPart *KonqViewFactory::create( QWidget *parentWidget, const char *widgetName, + QObject * parent, const char *name ) +{ + if ( !m_factory ) + return 0L; + + QObject *obj = 0L; + + if ( m_factory->inherits( "KParts::Factory" ) ) + { + if ( m_createBrowser ) + obj = static_cast<KParts::Factory *>(m_factory)->createPart( parentWidget, widgetName, parent, name, "Browser/View", m_args ); + + if ( !obj ) + obj = static_cast<KParts::Factory *>(m_factory)->createPart( parentWidget, widgetName, parent, name, "KParts::ReadOnlyPart", m_args ); + } + else + { + if ( m_createBrowser ) + obj = m_factory->create( parentWidget, name, "Browser/View", m_args ); + + if ( !obj ) + obj = m_factory->create( parentWidget, name, "KParts::ReadOnlyPart", m_args ); + } + + if ( !obj->inherits( "KParts::ReadOnlyPart" ) ) + kdError(1202) << "Part " << obj << " (" << obj->className() << ") doesn't inherit KParts::ReadOnlyPart !" << endl; + + KParts::ReadOnlyPart* part = static_cast<KParts::ReadOnlyPart *>( obj ); + QFrame* frame = ::qt_cast<QFrame*>( part->widget() ); + if (frame) + { + frame->setFrameStyle( QFrame::NoFrame ); + } + + return part; +} + +KonqViewFactory KonqFactory::createView( const QString &serviceType, + const QString &serviceName, + KService::Ptr *serviceImpl, + KTrader::OfferList *partServiceOffers, + KTrader::OfferList *appServiceOffers, + bool forceAutoEmbed ) +{ + kdDebug(1202) << "Trying to create view for \"" << serviceType << "\"" << endl; + + // We need to get those in any case + KTrader::OfferList offers, appOffers; + + // Query the trader + getOffers( serviceType, &offers, &appOffers ); + + if ( partServiceOffers ) + (*partServiceOffers) = offers; + if ( appServiceOffers ) + (*appServiceOffers) = appOffers; + + // We ask ourselves whether to do it or not only if no service was specified. + // If it was (from the View menu or from RMB + Embedding service), just do it. + forceAutoEmbed = forceAutoEmbed || !serviceName.isEmpty(); + // Or if we have no associated app anyway, then embed. + forceAutoEmbed = forceAutoEmbed || ( appOffers.isEmpty() && !offers.isEmpty() ); + // Or if the associated app is konqueror itself, then embed. + if ( !appOffers.isEmpty() ) + forceAutoEmbed = forceAutoEmbed || KonqMainWindow::isMimeTypeAssociatedWithSelf( serviceType, appOffers.first() ); + + if ( ! forceAutoEmbed ) + { + if ( ! KonqFMSettings::settings()->shouldEmbed( serviceType ) ) + { + kdDebug(1202) << "KonqFMSettings says: don't embed this servicetype" << endl; + return KonqViewFactory(); + } + } + + KService::Ptr service = 0L; + + // Look for this service + if ( !serviceName.isEmpty() ) + { + KTrader::OfferList::Iterator it = offers.begin(); + for ( ; it != offers.end() && !service ; ++it ) + { + if ( (*it)->desktopEntryName() == serviceName ) + { + kdDebug(1202) << "Found requested service " << serviceName << endl; + service = *it; + } + } + } + + KLibFactory *factory = 0L; + + if ( service ) + { + kdDebug(1202) << "Trying to open lib for requested service " << service->desktopEntryName() << endl; + factory = KLibLoader::self()->factory( QFile::encodeName(service->library()) ); + if ( !factory ) + KMessageBox::error(0, + i18n("There was an error loading the module %1.\nThe diagnostics is:\n%2") + .arg(service->name()).arg(KLibLoader::self()->lastErrorMessage())); + } + + KTrader::OfferList::Iterator it = offers.begin(); + for ( ; !factory && it != offers.end() ; ++it ) + { + service = (*it); + // Allowed as default ? + QVariant prop = service->property( "X-KDE-BrowserView-AllowAsDefault" ); + kdDebug(1202) << service->desktopEntryName() << " : X-KDE-BrowserView-AllowAsDefault is valid : " << prop.isValid() << endl; + if ( !prop.isValid() || prop.toBool() ) // defaults to true + { + //kdDebug(1202) << "Trying to open lib for service " << service->name() << endl; + // Try loading factory + factory = KLibLoader::self()->factory( QFile::encodeName(service->library()) ); + if ( !factory ) + KMessageBox::error(0, + i18n("There was an error loading the module %1.\nThe diagnostics is:\n%2") + .arg(service->name()).arg(KLibLoader::self()->lastErrorMessage())); + // If this works, we exit the loop. + } else + kdDebug(1202) << "Not allowed as default " << service->desktopEntryName() << endl; + } + + if ( serviceImpl ) + (*serviceImpl) = service; + + if ( !factory ) + { + kdWarning(1202) << "KonqFactory::createView : no factory" << endl; + return KonqViewFactory(); + } + + QStringList args; + + QVariant prop = service->property( "X-KDE-BrowserView-Args" ); + + if ( prop.isValid() ) + { + QString argStr = prop.toString(); + args = QStringList::split( " ", argStr ); + } + + return KonqViewFactory( factory, args, service->serviceTypes().contains( "Browser/View" ) ); +} + +void KonqFactory::getOffers( const QString & serviceType, + KTrader::OfferList *partServiceOffers, + KTrader::OfferList *appServiceOffers ) +{ + if ( appServiceOffers ) + { + *appServiceOffers = KTrader::self()->query( serviceType, "Application", +"DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'", + QString::null ); + } + + if ( partServiceOffers ) + { + *partServiceOffers = KTrader::self()->query( serviceType, "KParts/ReadOnlyPart", + QString::null, QString::null ); + } +} + + +const KAboutData *KonqFactory::aboutData() +{ + if (!s_aboutData) + { + s_aboutData = new KAboutData( "konqueror", I18N_NOOP("Konqueror"), + KONQUEROR_VERSION, + I18N_NOOP("Web browser, file manager, ..."), + KAboutData::License_GPL, + I18N_NOOP("(c) 1999-2005, The Konqueror developers"), + 0, + I18N_NOOP("http://konqueror.kde.org") ); + s_aboutData->addAuthor( "David Faure", I18N_NOOP("developer (framework, parts, JavaScript, I/O lib) and maintainer"), "[email protected]" ); + s_aboutData->addAuthor( "Simon Hausmann", I18N_NOOP("developer (framework, parts)"), "[email protected]" ); + s_aboutData->addAuthor( "Michael Reiher", I18N_NOOP("developer (framework)"), "[email protected]" ); + s_aboutData->addAuthor( "Matthias Welk", I18N_NOOP("developer"), "[email protected]" ); + s_aboutData->addAuthor( "Alexander Neundorf", I18N_NOOP("developer (List views)"), "[email protected]" ); + s_aboutData->addAuthor( "Michael Brade", I18N_NOOP("developer (List views, I/O lib)"), "[email protected]" ); + s_aboutData->addAuthor( "Lars Knoll", I18N_NOOP("developer (HTML rendering engine)"), "[email protected]" ); + s_aboutData->addAuthor( "Dirk Mueller", I18N_NOOP("developer (HTML rendering engine)"), "[email protected]" ); + s_aboutData->addAuthor( "Peter Kelly", I18N_NOOP("developer (HTML rendering engine)"), "[email protected]" ); + s_aboutData->addAuthor( "Waldo Bastian", I18N_NOOP("developer (HTML rendering engine, I/O lib)"), "[email protected]" ); + s_aboutData->addAuthor( "Germain Garand", I18N_NOOP("developer (HTML rendering engine)"), "[email protected]" ); + s_aboutData->addAuthor( "Leo Savernik", I18N_NOOP("developer (HTML rendering engine)"), "[email protected]" ); + s_aboutData->addAuthor( "Stephan Kulow", I18N_NOOP("developer (HTML rendering engine, I/O lib, regression test framework)"), "[email protected]" ); + s_aboutData->addAuthor( "Antti Koivisto", I18N_NOOP("developer (HTML rendering engine)"), "[email protected]" ); + s_aboutData->addAuthor( "Zack Rusin", I18N_NOOP("developer (HTML rendering engine)"), "[email protected]" ); + s_aboutData->addAuthor( "Tobias Anton", I18N_NOOP( "developer (HTML rendering engine)" ), "[email protected]" ); + s_aboutData->addAuthor( "Lubos Lunak", I18N_NOOP( "developer (HTML rendering engine)" ), "[email protected]" ); + s_aboutData->addAuthor( "Allan Sandfeld Jensen", I18N_NOOP( "developer (HTML rendering engine)" ), "[email protected]" ); + s_aboutData->addAuthor( "Apple Safari Developers", I18N_NOOP("developer (HTML rendering engine, JavaScript)"), "" ); + s_aboutData->addAuthor( "Harri Porten", I18N_NOOP("developer (JavaScript)"), "[email protected]" ); + s_aboutData->addAuthor( "Koos Vriezen", I18N_NOOP("developer (Java applets and other embedded objects)"), "[email protected]" ); + s_aboutData->addAuthor( "Matt Koss", I18N_NOOP("developer (I/O lib)"), "[email protected]" ); + s_aboutData->addAuthor( "Alex Zepeda", I18N_NOOP("developer (I/O lib)"), "[email protected]" ); + s_aboutData->addAuthor( "Richard Moore", I18N_NOOP("developer (Java applet support)"), "[email protected]" ); + s_aboutData->addAuthor( "Dima Rogozin", I18N_NOOP("developer (Java applet support)"), "[email protected]" ); + s_aboutData->addAuthor( "Wynn Wilkes", I18N_NOOP("developer (Java 2 security manager support,\n and other major improvements to applet support)"), "[email protected]" ); + s_aboutData->addAuthor( "Stefan Schimanski", I18N_NOOP("developer (Netscape plugin support)"), "[email protected]" ); + s_aboutData->addAuthor( "George Staikos", I18N_NOOP("developer (SSL, Netscape plugins)"), "[email protected]" ); + s_aboutData->addAuthor( "Dawit Alemayehu",I18N_NOOP("developer (I/O lib, Authentication support)"), "[email protected]" ); + s_aboutData->addAuthor( "Carsten Pfeiffer",I18N_NOOP("developer (framework)"), "[email protected]" ); + s_aboutData->addAuthor( "Torsten Rahn", I18N_NOOP("graphics/icons"), "[email protected]" ); + s_aboutData->addAuthor( "Torben Weis", I18N_NOOP("kfm author"), "[email protected]" ); + s_aboutData->addAuthor( "Joseph Wenninger", I18N_NOOP("developer (navigation panel framework)"),"[email protected]"); + s_aboutData->addAuthor( "Stephan Binner", I18N_NOOP("developer (misc stuff)"),"[email protected]"); + s_aboutData->addAuthor( "Ivor Hewitt", I18N_NOOP("developer (AdBlock filter)"),"[email protected]"); + } + return s_aboutData; +} + |