delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / konqueror / src / konqfactory.cpp
bloba15090ef6a85b086a8f12be0b3cff4589f6f1eb2
1 /* This file is part of the KDE project
2 Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
3 Copyright (C) 1999 David Faure <faure@kde.org>
4 Copyright (C) 1999 Torben Weis <weis@kde.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 // Own
23 #include "konqfactory.h"
25 // std
26 #include <assert.h>
28 // Qt
29 #include <QtGui/QWidget>
30 #include <QtCore/QFile>
31 #include <QtCore/QCoreApplication>
33 // KDE
34 #include <kaboutdata.h>
35 #include <kdebug.h>
36 #include <klocale.h>
37 #include <kmessagebox.h>
38 #include <kmimetypetrader.h>
39 #include <kparts/factory.h>
40 #include <kparts/part.h>
41 #include <kservicetypetrader.h>
42 #include <kdeversion.h>
44 // Local
45 #include "konqsettings.h"
46 #include "konqmainwindow.h"
49 static KAboutData *s_aboutData = 0;
50 static void cleanupKAboutData()
52 delete s_aboutData;
55 KonqViewFactory::KonqViewFactory(const QString& libName, KLibFactory *factory)
56 : m_libName(libName), m_factory(factory),
57 m_args()
61 void KonqViewFactory::setArgs(const QVariantList &args)
63 m_args = args;
66 KParts::ReadOnlyPart *KonqViewFactory::create( QWidget *parentWidget, QObject * parent )
68 if ( !m_factory )
69 return 0;
71 KParts::ReadOnlyPart* part = m_factory->create<KParts::ReadOnlyPart>( parentWidget, parent, QString(), m_args );
73 if ( !part ) {
74 kError(1202) << "No KParts::ReadOnlyPart created from" << m_libName;
75 } else {
76 QFrame* frame = qobject_cast<QFrame*>( part->widget() );
77 if ( frame ) {
78 frame->setFrameStyle( QFrame::NoFrame );
81 return part;
84 static KonqViewFactory tryLoadingService(KService::Ptr service)
86 KPluginLoader pluginLoader(*service);
87 KPluginFactory* factory = pluginLoader.factory();
88 if (!factory) {
89 KMessageBox::error(0,
90 i18n("There was an error loading the module %1.\nThe diagnostics is:\n%2",
91 service->name(), pluginLoader.errorString()));
92 return KonqViewFactory();
94 else {
95 return KonqViewFactory(service->library(), factory);
99 KonqViewFactory KonqFactory::createView( const QString &serviceType,
100 const QString &serviceName,
101 KService::Ptr *serviceImpl,
102 KService::List *partServiceOffers,
103 KService::List *appServiceOffers,
104 bool forceAutoEmbed )
106 kDebug(1202) << "Trying to create view for" << serviceType << serviceName;
108 // We need to get those in any case
109 KService::List offers, appOffers;
111 // Query the trader
112 getOffers( serviceType, &offers, &appOffers );
114 if ( partServiceOffers )
115 (*partServiceOffers) = offers;
116 if ( appServiceOffers )
117 (*appServiceOffers) = appOffers;
119 // We ask ourselves whether to do it or not only if no service was specified.
120 // If it was (from the View menu or from RMB + Embedding service), just do it.
121 forceAutoEmbed = forceAutoEmbed || !serviceName.isEmpty();
122 // Or if we have no associated app anyway, then embed.
123 forceAutoEmbed = forceAutoEmbed || ( appOffers.isEmpty() && !offers.isEmpty() );
124 // Or if the associated app is konqueror itself, then embed.
125 if ( !appOffers.isEmpty() )
126 forceAutoEmbed = forceAutoEmbed || KonqMainWindow::isMimeTypeAssociatedWithSelf( serviceType, appOffers.first() );
128 if ( ! forceAutoEmbed )
130 if ( ! KonqFMSettings::settings()->shouldEmbed( serviceType ) )
132 kDebug(1202) << "KonqFMSettings says: don't embed this servicetype";
133 return KonqViewFactory();
137 KService::Ptr service;
139 // Look for this service
140 if (!serviceName.isEmpty()) {
141 KService::List::const_iterator it = offers.constBegin();
142 for ( ; it != offers.constEnd() && !service ; ++it ) {
143 if ( (*it)->desktopEntryName() == serviceName ) {
144 kDebug(1202) << "Found requested service" << serviceName;
145 service = *it;
150 KonqViewFactory viewFactory;
151 if (service) {
152 kDebug(1202) << "Trying to open lib for requested service " << service->desktopEntryName();
153 viewFactory = tryLoadingService(service);
154 // If this fails, then return an error.
155 // When looking for konq_sidebartng or konq_aboutpage, we don't want to end up
156 // with khtml or another Browser/View part in case of an error...
157 } else {
158 KService::List::Iterator it = offers.begin();
159 for ( ; viewFactory.isNull() /* exit as soon as we get one */ && it != offers.end() ; ++it ) {
160 service = (*it);
161 // Allowed as default ?
162 QVariant prop = service->property( "X-KDE-BrowserView-AllowAsDefault" );
163 kDebug(1202) << service->desktopEntryName() << " : X-KDE-BrowserView-AllowAsDefault is valid : " << prop.isValid();
164 if ( !prop.isValid() || prop.toBool() ) { // defaults to true
165 //kDebug(1202) << "Trying to open lib for service " << service->name();
166 viewFactory = tryLoadingService(service);
167 // If this works, we exit the loop.
168 } else {
169 kDebug(1202) << "Not allowed as default " << service->desktopEntryName();
174 if (serviceImpl)
175 (*serviceImpl) = service;
177 if (viewFactory.isNull()) {
178 if (offers.isEmpty())
179 kWarning(1202) << "no part was associated with" << serviceType;
180 else
181 kWarning(1202) << "no part could be loaded"; // full error was shown to user already
182 return viewFactory;
185 QVariantList args;
186 const QVariant prop = service->property( "X-KDE-BrowserView-Args" );
187 if (prop.isValid()) {
188 Q_FOREACH(const QString& str, prop.toString().split(' '))
189 args << QVariant(str);
192 if (service->serviceTypes().contains("Browser/View"))
193 args << QLatin1String("Browser/View");
195 viewFactory.setArgs(args);
196 return viewFactory;
199 void KonqFactory::getOffers( const QString & serviceType,
200 KService::List *partServiceOffers,
201 KService::List *appServiceOffers )
203 #ifdef __GNUC__
204 #warning Temporary hack -- must separate mimetypes and servicetypes better
205 #endif
206 if ( partServiceOffers && serviceType.length() > 0 && serviceType[0].isUpper() ) {
207 *partServiceOffers = KServiceTypeTrader::self()->query( serviceType,
208 "DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'");
209 return;
212 if ( appServiceOffers )
214 *appServiceOffers = KMimeTypeTrader::self()->query( serviceType, "Application",
215 "DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'");
218 if ( partServiceOffers )
220 *partServiceOffers = KMimeTypeTrader::self()->query( serviceType, "KParts/ReadOnlyPart" );
225 const KAboutData *KonqFactory::aboutData()
227 if (!s_aboutData)
229 s_aboutData = new KAboutData( "konqueror", 0, ki18n("Konqueror"),
230 KDE_VERSION_STRING,
231 ki18n("Web browser, file manager and document viewer."),
232 KAboutData::License_GPL,
233 ki18n("(C) 1999-2008, The Konqueror developers"),
234 KLocalizedString(),
235 I18N_NOOP("http://konqueror.kde.org") );
236 s_aboutData->addAuthor( ki18n("David Faure"), ki18n("Developer (framework, parts, JavaScript, I/O library) and maintainer"), "faure@kde.org" );
237 s_aboutData->addAuthor( ki18n("Simon Hausmann"), ki18n("Developer (framework, parts)"), "hausmann@kde.org" );
238 s_aboutData->addAuthor( ki18n("Michael Reiher"), ki18n("Developer (framework)"), "michael.reiher@gmx.de" );
239 s_aboutData->addAuthor( ki18n("Matthias Welk"), ki18n("Developer"), "welk@fokus.gmd.de" );
240 s_aboutData->addAuthor( ki18n("Alexander Neundorf"), ki18n("Developer (List views)"), "neundorf@kde.org" );
241 s_aboutData->addAuthor( ki18n("Michael Brade"), ki18n("Developer (List views, I/O library)"), "brade@kde.org" );
242 s_aboutData->addAuthor( ki18n("Lars Knoll"), ki18n("Developer (HTML rendering engine)"), "knoll@kde.org" );
243 s_aboutData->addAuthor( ki18n("Dirk Mueller"), ki18n("Developer (HTML rendering engine)"), "mueller@kde.org" );
244 s_aboutData->addAuthor( ki18n("Peter Kelly"), ki18n("Developer (HTML rendering engine)"), "pmk@post.com" );
245 s_aboutData->addAuthor( ki18n("Waldo Bastian"), ki18n("Developer (HTML rendering engine, I/O library)"), "bastian@kde.org" );
246 s_aboutData->addAuthor( ki18n("Germain Garand"), ki18n("Developer (HTML rendering engine)"), "germain@ebooksfrance.org" );
247 s_aboutData->addAuthor( ki18n("Leo Savernik"), ki18n("Developer (HTML rendering engine)"), "l.savernik@aon.at" );
248 s_aboutData->addAuthor( ki18n("Stephan Kulow"), ki18n("Developer (HTML rendering engine, I/O library, regression test framework)"), "coolo@kde.org" );
249 s_aboutData->addAuthor( ki18n("Antti Koivisto"), ki18n("Developer (HTML rendering engine)"), "koivisto@kde.org" );
250 s_aboutData->addAuthor( ki18n("Zack Rusin"), ki18n("Developer (HTML rendering engine)"), "zack@kde.org" );
251 s_aboutData->addAuthor( ki18n("Tobias Anton"), ki18n( "Developer (HTML rendering engine)" ), "anton@stud.fbi.fh-darmstadt.de" );
252 s_aboutData->addAuthor( ki18n("Lubos Lunak"), ki18n( "Developer (HTML rendering engine)" ), "l.lunak@kde.org" );
253 s_aboutData->addAuthor( ki18n("Allan Sandfeld Jensen"), ki18n( "Developer (HTML rendering engine)" ), "kde@carewolf.com" );
254 s_aboutData->addAuthor( ki18n("Apple Safari Developers"), ki18n("Developer (HTML rendering engine, JavaScript)"));
255 s_aboutData->addAuthor( ki18n("Harri Porten"), ki18n("Developer (JavaScript)"), "porten@kde.org" );
256 s_aboutData->addAuthor( ki18n("Koos Vriezen"), ki18n("Developer (Java applets and other embedded objects)"), "koos.vriezen@xs4all.nl" );
257 s_aboutData->addAuthor( ki18n("Matt Koss"), ki18n("Developer (I/O library)"), "koss@miesto.sk" );
258 s_aboutData->addAuthor( ki18n("Alex Zepeda"), ki18n("Developer (I/O library)"), "zipzippy@sonic.net" );
259 s_aboutData->addAuthor( ki18n("Richard Moore"), ki18n("Developer (Java applet support)"), "rich@kde.org" );
260 s_aboutData->addAuthor( ki18n("Dima Rogozin"), ki18n("Developer (Java applet support)"), "dima@mercury.co.il" );
261 s_aboutData->addAuthor( ki18n("Wynn Wilkes"), ki18n("Developer (Java 2 security manager support,\n and other major improvements to applet support)"), "wynnw@calderasystems.com" );
262 s_aboutData->addAuthor( ki18n("Stefan Schimanski"), ki18n("Developer (Netscape plugin support)"), "schimmi@kde.org" );
263 s_aboutData->addAuthor( ki18n("George Staikos"), ki18n("Developer (SSL, Netscape plugins)"), "staikos@kde.org" );
264 s_aboutData->addAuthor( ki18n("Dawit Alemayehu"),ki18n("Developer (I/O library, Authentication support)"), "adawit@kde.org" );
265 s_aboutData->addAuthor( ki18n("Carsten Pfeiffer"),ki18n("Developer (framework)"), "pfeiffer@kde.org" );
266 s_aboutData->addAuthor( ki18n("Torsten Rahn"), ki18n("Graphics/icons"), "torsten@kde.org" );
267 s_aboutData->addAuthor( ki18n("Torben Weis"), ki18n("KFM author"), "weis@kde.org" );
268 s_aboutData->addAuthor( ki18n("Joseph Wenninger"), ki18n("Developer (navigation panel framework)"),"jowenn@kde.org");
269 s_aboutData->addAuthor( ki18n("Stephan Binner"), ki18n("Developer (misc stuff)"),"binner@kde.org");
270 s_aboutData->addAuthor( ki18n("Ivor Hewitt"), ki18n("Developer (AdBlock filter)"),"ivor@ivor.org");
271 s_aboutData->addAuthor( ki18n("Eduardo Robles Elvira"), ki18n("Developer (framework)"),"edulix@gmail.com");
272 qAddPostRoutine(cleanupKAboutData);
274 return s_aboutData;