~ubuntu-branches/ubuntu/warty/kdebase/warty

« back to all changes in this revision

Viewing changes to konqueror/konq_factory.cc

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-09-16 04:51:45 UTC
  • Revision ID: james.westby@ubuntu.com-20040916045145-9vr63kith3k1cpza
Tags: upstream-3.2.2
ImportĀ upstreamĀ versionĀ 3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 
 
20
*/
 
21
 
 
22
#include <kparts/factory.h>
 
23
#include "konq_factory.h"
 
24
#include "version.h"
 
25
 
 
26
#include <konq_settings.h>
 
27
#include <kdebug.h>
 
28
#include <kaboutdata.h>
 
29
#include <klocale.h>
 
30
#include <kmessagebox.h>
 
31
 
 
32
#include <qwidget.h>
 
33
#include <qfile.h>
 
34
 
 
35
#include <assert.h>
 
36
 
 
37
KAboutData *KonqFactory::s_aboutData = 0;
 
38
 
 
39
KonqViewFactory::KonqViewFactory( KLibFactory *factory, const QStringList &args,
 
40
                                  bool createBrowser )
 
41
    : m_factory( factory ), m_args( args ), m_createBrowser( createBrowser ) 
 
42
{
 
43
    if ( m_createBrowser )
 
44
        m_args << QString::fromLatin1( "Browser/View" );
 
45
}
 
46
 
 
47
KParts::ReadOnlyPart *KonqViewFactory::create( QWidget *parentWidget, const char *widgetName,
 
48
                                               QObject * parent, const char *name )
 
49
{
 
50
  if ( !m_factory )
 
51
    return 0L;
 
52
 
 
53
  QObject *obj = 0L;
 
54
 
 
55
  if ( m_factory->inherits( "KParts::Factory" ) )
 
56
  {
 
57
    if ( m_createBrowser )
 
58
      obj = static_cast<KParts::Factory *>(m_factory)->createPart( parentWidget, widgetName, parent, name, "Browser/View", m_args );
 
59
 
 
60
    if ( !obj )
 
61
      obj = static_cast<KParts::Factory *>(m_factory)->createPart( parentWidget, widgetName, parent, name, "KParts::ReadOnlyPart", m_args );
 
62
  }
 
63
  else
 
64
  {
 
65
    if ( m_createBrowser )
 
66
      obj = m_factory->create( parentWidget, name, "Browser/View", m_args );
 
67
 
 
68
    if ( !obj )
 
69
      obj = m_factory->create( parentWidget, name, "KParts::ReadOnlyPart", m_args );
 
70
  }
 
71
 
 
72
  if ( !obj->inherits( "KParts::ReadOnlyPart" ) )
 
73
      kdError(1202) << "Part " << obj << " (" << obj->className() << ") doesn't inherit KParts::ReadOnlyPart !" << endl;
 
74
 
 
75
  return static_cast<KParts::ReadOnlyPart *>(obj);
 
76
}
 
77
 
 
78
KonqViewFactory KonqFactory::createView( const QString &serviceType,
 
79
                                         const QString &serviceName,
 
80
                                         KService::Ptr *serviceImpl,
 
81
                                         KTrader::OfferList *partServiceOffers,
 
82
                                         KTrader::OfferList *appServiceOffers,
 
83
                                         bool forceAutoEmbed )
 
84
{
 
85
  kdDebug(1202) << "Trying to create view for \"" << serviceType << "\"" << endl;
 
86
 
 
87
  // We need to get those in any case
 
88
  KTrader::OfferList offers, appOffers;
 
89
 
 
90
  // Query the trader
 
91
  getOffers( serviceType, &offers, &appOffers );
 
92
 
 
93
  if ( partServiceOffers )
 
94
     (*partServiceOffers) = offers;
 
95
  if ( appServiceOffers )
 
96
     (*appServiceOffers) = appOffers;
 
97
 
 
98
  // We ask ourselves whether to do it or not only if no service was specified.
 
99
  // If it was (from the View menu or from RMB + Embedding service), just do it.
 
100
  forceAutoEmbed |= !serviceName.isEmpty();
 
101
  // Or if we have no associated app anyway, then embed.
 
102
  forceAutoEmbed |= appOffers.isEmpty() && !offers.isEmpty();
 
103
 
 
104
  if ( ! forceAutoEmbed )
 
105
  {
 
106
    if ( ! KonqFMSettings::settings()->shouldEmbed( serviceType ) )
 
107
    {
 
108
      kdDebug(1202) << "KonqFMSettings says: don't embed this servicetype" << endl;
 
109
      return KonqViewFactory();
 
110
    }
 
111
  }
 
112
 
 
113
  KService::Ptr service = 0L;
 
114
 
 
115
  // Look for this service
 
116
  if ( !serviceName.isEmpty() )
 
117
  {
 
118
      KTrader::OfferList::Iterator it = offers.begin();
 
119
      for ( ; it != offers.end() && !service ; ++it )
 
120
      {
 
121
          if ( (*it)->desktopEntryName() == serviceName )
 
122
          {
 
123
              kdDebug(1202) << "Found requested service " << serviceName << endl;
 
124
              service = *it;
 
125
          }
 
126
      }
 
127
  }
 
128
 
 
129
  KLibFactory *factory = 0L;
 
130
 
 
131
  if ( service )
 
132
  {
 
133
    kdDebug(1202) << "Trying to open lib for requested service " << service->desktopEntryName() << endl;
 
134
    factory = KLibLoader::self()->factory( QFile::encodeName(service->library()) );
 
135
    if ( !factory )
 
136
        KMessageBox::error(0,
 
137
                           i18n("There was an error loading the module %1.\nThe diagnostics is:\n%2")
 
138
                           .arg(service->name()).arg(KLibLoader::self()->lastErrorMessage()));
 
139
  }
 
140
 
 
141
  KTrader::OfferList::Iterator it = offers.begin();
 
142
  for ( ; !factory && it != offers.end() ; ++it )
 
143
  {
 
144
    service = (*it);
 
145
    // Allowed as default ?
 
146
    QVariant prop = service->property( "X-KDE-BrowserView-AllowAsDefault" );
 
147
    kdDebug(1202) << service->desktopEntryName() << " : X-KDE-BrowserView-AllowAsDefault is valid : " << prop.isValid() << endl;
 
148
    if ( !prop.isValid() || prop.toBool() ) // defaults to true
 
149
    {
 
150
      //kdDebug(1202) << "Trying to open lib for service " << service->name() << endl;
 
151
      // Try loading factory
 
152
      factory = KLibLoader::self()->factory( QFile::encodeName(service->library()) );
 
153
      if ( !factory )
 
154
        KMessageBox::error(0,
 
155
                           i18n("There was an error loading the module %1.\nThe diagnostics is:\n%2")
 
156
                           .arg(service->name()).arg(KLibLoader::self()->lastErrorMessage()));
 
157
      // If this works, we exit the loop.
 
158
    } else
 
159
      kdDebug(1202) << "Not allowed as default " << service->desktopEntryName() << endl;
 
160
  }
 
161
 
 
162
  if ( serviceImpl )
 
163
    (*serviceImpl) = service;
 
164
 
 
165
  if ( !factory )
 
166
  {
 
167
    kdWarning(1202) << "KonqFactory::createView : no factory" << endl;
 
168
    return KonqViewFactory();
 
169
  }
 
170
 
 
171
  QStringList args;
 
172
 
 
173
  QVariant prop = service->property( "X-KDE-BrowserView-Args" );
 
174
 
 
175
  if ( prop.isValid() )
 
176
  {
 
177
    QString argStr = prop.toString();
 
178
    args = QStringList::split( " ", argStr );
 
179
  }
 
180
 
 
181
  return KonqViewFactory( factory, args, service->serviceTypes().contains( "Browser/View" ) );
 
182
}
 
183
 
 
184
void KonqFactory::getOffers( const QString & serviceType,
 
185
                             KTrader::OfferList *partServiceOffers,
 
186
                             KTrader::OfferList *appServiceOffers )
 
187
{
 
188
    if ( appServiceOffers )
 
189
    {
 
190
        *appServiceOffers = KTrader::self()->query( serviceType, "Application",
 
191
"DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'",
 
192
                                                    QString::null );
 
193
    }
 
194
 
 
195
    if ( partServiceOffers )
 
196
    {
 
197
        *partServiceOffers = KTrader::self()->query( serviceType, "KParts/ReadOnlyPart",
 
198
                                                     QString::null, QString::null );
 
199
    }
 
200
}
 
201
 
 
202
 
 
203
const KAboutData *KonqFactory::aboutData()
 
204
{
 
205
  if (!s_aboutData)
 
206
  {
 
207
    s_aboutData = new KAboutData( "konqueror", I18N_NOOP("Konqueror"),
 
208
                        KONQUEROR_VERSION,
 
209
                        I18N_NOOP("Web browser, file manager, ..."),
 
210
                        KAboutData::License_GPL,
 
211
                        I18N_NOOP("(c) 1999-2003, The Konqueror developers"),
 
212
                        0,
 
213
                        I18N_NOOP("http://konqueror.kde.org") );
 
214
    s_aboutData->addAuthor( "David Faure", I18N_NOOP("developer (parts, I/O lib) and maintainer"), "faure@kde.org" );
 
215
    s_aboutData->addAuthor( "Simon Hausmann", I18N_NOOP("developer (framework, parts)"), "hausmann@kde.org" );
 
216
    s_aboutData->addAuthor( "Michael Reiher", I18N_NOOP("developer (framework)"), "michael.reiher@gmx.de" );
 
217
    s_aboutData->addAuthor( "Matthias Welk", I18N_NOOP("developer"), "welk@fokus.gmd.de" );
 
218
    s_aboutData->addAuthor( "Alexander Neundorf", I18N_NOOP("developer (List views)"), "neundorf@kde.org" );
 
219
    s_aboutData->addAuthor( "Michael Brade", I18N_NOOP("developer (List views, I/O lib)"), "brade@kde.org" );
 
220
    s_aboutData->addAuthor( "Lars Knoll", I18N_NOOP("developer (HTML rendering engine)"), "knoll@kde.org" );
 
221
    s_aboutData->addAuthor( "Antti Koivisto", I18N_NOOP("developer (HTML rendering engine)"), "koivisto@kde.org" );
 
222
    s_aboutData->addAuthor( "Dirk Mueller", I18N_NOOP("developer (HTML rendering engine)"), "mueller@kde.org" );
 
223
    s_aboutData->addAuthor( "Peter Kelly", I18N_NOOP("developer (HTML rendering engine)"), "pmk@post.com" );
 
224
    s_aboutData->addAuthor( "Waldo Bastian", I18N_NOOP("developer (HTML rendering engine, I/O lib)"), "bastian@kde.org" );
 
225
    s_aboutData->addAuthor( "Matt Koss", I18N_NOOP("developer (I/O lib)"), "koss@miesto.sk" );
 
226
    s_aboutData->addAuthor( "Alex Zepeda", I18N_NOOP("developer (I/O lib)"), "zipzippy@sonic.net" );
 
227
    s_aboutData->addAuthor( "Stephan Kulow", I18N_NOOP("developer (I/O lib)"), "coolo@kde.org" );
 
228
    s_aboutData->addAuthor( "Richard Moore", I18N_NOOP("developer (Java applet support)"), "rich@kde.org" );
 
229
    s_aboutData->addAuthor( "Dima Rogozin", I18N_NOOP("developer (Java applet support)"), "dima@mercury.co.il" );
 
230
    s_aboutData->addAuthor( "Wynn Wilkes", I18N_NOOP("developer (Java 2 security manager support,\n and other major improvements to applet support)"), "wynnw@calderasystems.com" );
 
231
    s_aboutData->addAuthor( "Harri Porten", I18N_NOOP("developer (JavaScript)"), "porten@kde.org" );
 
232
    s_aboutData->addAuthor( "Stefan Schimanski", I18N_NOOP("developer (Netscape plugin support)"), "schimmi@kde.org" );
 
233
    s_aboutData->addAuthor( "George Staikos", I18N_NOOP("developer (SSL, Netscape plugins)"), "staikos@kde.org" );
 
234
    s_aboutData->addAuthor( "Dawit Alemayehu",I18N_NOOP("developer (I/O lib, Authentication support)"), "adawit@kde.org" );
 
235
    s_aboutData->addAuthor( "Carsten Pfeiffer",I18N_NOOP("developer (framework)"), "pfeiffer@kde.org" );
 
236
    s_aboutData->addAuthor( "Torsten Rahn", I18N_NOOP("graphics/icons"), "torsten@kde.org" );
 
237
    s_aboutData->addAuthor( "Torben Weis", I18N_NOOP("kfm author"), "weis@kde.org" );
 
238
    s_aboutData->addAuthor( "Joseph Wenninger", I18N_NOOP("developer (navigation panel framework)"),"jowenn@kde.org");
 
239
  }
 
240
  return s_aboutData;
 
241
}
 
242