tdebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

konq_factory.cc 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17. #include <tdeparts/factory.h>
  18. #include "konq_factory.h"
  19. #include "version.h"
  20. #include <konq_settings.h>
  21. #include <konq_mainwindow.h>
  22. #include <kdebug.h>
  23. #include <tdeaboutdata.h>
  24. #include <tdelocale.h>
  25. #include <tdemessagebox.h>
  26. #include <tqwidget.h>
  27. #include <tqfile.h>
  28. #include <assert.h>
  29. TDEAboutData *KonqFactory::s_aboutData = 0;
  30. KonqViewFactory::KonqViewFactory( KLibFactory *factory, const TQStringList &args,
  31. bool createBrowser )
  32. : m_factory( factory ), m_args( args ), m_createBrowser( createBrowser )
  33. {
  34. if ( m_createBrowser )
  35. m_args << TQString::fromLatin1( "Browser/View" );
  36. }
  37. KParts::ReadOnlyPart *KonqViewFactory::create( TQWidget *parentWidget, const char *widgetName,
  38. TQObject * parent, const char *name )
  39. {
  40. if ( !m_factory )
  41. return 0L;
  42. TQObject *obj = 0L;
  43. if ( m_factory->inherits( "KParts::Factory" ) )
  44. {
  45. if ( m_createBrowser )
  46. obj = static_cast<KParts::Factory *>(m_factory)->createPart( parentWidget, widgetName, parent, name, "Browser/View", m_args );
  47. if ( !obj )
  48. obj = static_cast<KParts::Factory *>(m_factory)->createPart( parentWidget, widgetName, parent, name, "KParts::ReadOnlyPart", m_args );
  49. }
  50. else
  51. {
  52. if ( m_createBrowser )
  53. obj = m_factory->create( TQT_TQOBJECT(parentWidget), name, "Browser/View", m_args );
  54. if ( !obj )
  55. obj = m_factory->create( TQT_TQOBJECT(parentWidget), name, "KParts::ReadOnlyPart", m_args );
  56. }
  57. if ( !obj->inherits( "KParts::ReadOnlyPart" ) )
  58. kdError(1202) << "Part " << obj << " (" << obj->className() << ") doesn't inherit KParts::ReadOnlyPart !" << endl;
  59. KParts::ReadOnlyPart* part = static_cast<KParts::ReadOnlyPart *>( obj );
  60. TQFrame* frame = ::tqqt_cast<TQFrame*>( part->widget() );
  61. if (frame)
  62. {
  63. frame->setFrameStyle( TQFrame::NoFrame );
  64. }
  65. return part;
  66. }
  67. KonqViewFactory KonqFactory::createView( const TQString &serviceType,
  68. const TQString &serviceName,
  69. KService::Ptr *serviceImpl,
  70. TDETrader::OfferList *partServiceOffers,
  71. TDETrader::OfferList *appServiceOffers,
  72. bool forceAutoEmbed )
  73. {
  74. kdDebug(1202) << "Trying to create view for \"" << serviceType << "\"" << endl;
  75. // We need to get those in any case
  76. TDETrader::OfferList offers, appOffers;
  77. // Query the trader
  78. getOffers( serviceType, &offers, &appOffers );
  79. if ( partServiceOffers )
  80. (*partServiceOffers) = offers;
  81. if ( appServiceOffers )
  82. (*appServiceOffers) = appOffers;
  83. // We ask ourselves whether to do it or not only if no service was specified.
  84. // If it was (from the View menu or from RMB + Embedding service), just do it.
  85. forceAutoEmbed = forceAutoEmbed || !serviceName.isEmpty();
  86. // Or if we have no associated app anyway, then embed.
  87. forceAutoEmbed = forceAutoEmbed || ( appOffers.isEmpty() && !offers.isEmpty() );
  88. // Or if the associated app is konqueror itself, then embed.
  89. if ( !appOffers.isEmpty() )
  90. forceAutoEmbed = forceAutoEmbed || KonqMainWindow::isMimeTypeAssociatedWithSelf( serviceType, appOffers.first() );
  91. if ( ! forceAutoEmbed )
  92. {
  93. if ( ! KonqFMSettings::settings()->shouldEmbed( serviceType ) )
  94. {
  95. kdDebug(1202) << "KonqFMSettings says: don't embed this servicetype" << endl;
  96. return KonqViewFactory();
  97. }
  98. }
  99. KService::Ptr service = 0L;
  100. // Look for this service
  101. if ( !serviceName.isEmpty() )
  102. {
  103. TDETrader::OfferList::Iterator it = offers.begin();
  104. for ( ; it != offers.end() && !service ; ++it )
  105. {
  106. if ( (*it)->desktopEntryName() == serviceName )
  107. {
  108. kdDebug(1202) << "Found requested service " << serviceName << endl;
  109. service = *it;
  110. }
  111. }
  112. }
  113. KLibFactory *factory = 0L;
  114. if ( service )
  115. {
  116. kdDebug(1202) << "Trying to open lib for requested service " << service->desktopEntryName() << endl;
  117. factory = KLibLoader::self()->factory( TQFile::encodeName(service->library()) );
  118. if ( !factory )
  119. KMessageBox::error(0,
  120. i18n("There was an error loading the module %1.\nThe diagnostics is:\n%2")
  121. .arg(service->name()).arg(KLibLoader::self()->lastErrorMessage()));
  122. }
  123. TDETrader::OfferList::Iterator it = offers.begin();
  124. for ( ; !factory && it != offers.end() ; ++it )
  125. {
  126. service = (*it);
  127. // Allowed as default ?
  128. TQVariant prop = service->property( "X-TDE-BrowserView-AllowAsDefault" );
  129. kdDebug(1202) << service->desktopEntryName() << " : X-TDE-BrowserView-AllowAsDefault is valid : " << prop.isValid() << endl;
  130. if ( !prop.isValid() || prop.toBool() ) // defaults to true
  131. {
  132. //kdDebug(1202) << "Trying to open lib for service " << service->name() << endl;
  133. // Try loading factory
  134. factory = KLibLoader::self()->factory( TQFile::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. // If this works, we exit the loop.
  140. } else
  141. kdDebug(1202) << "Not allowed as default " << service->desktopEntryName() << endl;
  142. }
  143. if ( serviceImpl )
  144. (*serviceImpl) = service;
  145. if ( !factory )
  146. {
  147. kdWarning(1202) << "KonqFactory::createView : no factory" << endl;
  148. return KonqViewFactory();
  149. }
  150. TQStringList args;
  151. TQVariant prop = service->property( "X-TDE-BrowserView-Args" );
  152. if ( prop.isValid() )
  153. {
  154. TQString argStr = prop.toString();
  155. args = TQStringList::split( " ", argStr );
  156. }
  157. return KonqViewFactory( factory, args, service->serviceTypes().contains( "Browser/View" ) );
  158. }
  159. void KonqFactory::getOffers( const TQString & serviceType,
  160. TDETrader::OfferList *partServiceOffers,
  161. TDETrader::OfferList *appServiceOffers )
  162. {
  163. if ( appServiceOffers )
  164. {
  165. *appServiceOffers = TDETrader::self()->query( serviceType, "Application",
  166. "DesktopEntryName != 'kfmclient' and DesktopEntryName != 'kfmclient_dir' and DesktopEntryName != 'kfmclient_html'",
  167. TQString::null );
  168. }
  169. if ( partServiceOffers )
  170. {
  171. *partServiceOffers = TDETrader::self()->query( serviceType, "KParts/ReadOnlyPart",
  172. TQString::null, TQString::null );
  173. }
  174. }
  175. const TDEAboutData *KonqFactory::aboutData()
  176. {
  177. if (!s_aboutData)
  178. {
  179. s_aboutData = new TDEAboutData( "konqueror", I18N_NOOP("Konqueror"),
  180. KONQUEROR_VERSION,
  181. I18N_NOOP("Web browser, file manager, ..."),
  182. TDEAboutData::License_GPL,
  183. I18N_NOOP("(c) 2011-2014, The Trinity Desktop project\n(c) 1999-2010, The Konqueror developers"),
  184. 0,
  185. I18N_NOOP("https://www.trinitydesktop.org") );
  186. s_aboutData->addAuthor( "Timothy Pearson", I18N_NOOP("Maintainer, Trinity bugfixes"), "kb9vqf@pearsoncomputing.net" );
  187. s_aboutData->addAuthor( "David Faure", I18N_NOOP("developer (framework, parts, JavaScript, I/O lib) and maintainer"), "faure@kde.org" );
  188. s_aboutData->addAuthor( "Simon Hausmann", I18N_NOOP("developer (framework, parts)"), "hausmann@kde.org" );
  189. s_aboutData->addAuthor( "Michael Reiher", I18N_NOOP("developer (framework)"), "michael.reiher@gmx.de" );
  190. s_aboutData->addAuthor( "Matthias Welk", I18N_NOOP("developer"), "welk@fokus.gmd.de" );
  191. s_aboutData->addAuthor( "Alexander Neundorf", I18N_NOOP("developer (List views)"), "neundorf@kde.org" );
  192. s_aboutData->addAuthor( "Michael Brade", I18N_NOOP("developer (List views, I/O lib)"), "brade@kde.org" );
  193. s_aboutData->addAuthor( "Lars Knoll", I18N_NOOP("developer (HTML rendering engine)"), "knoll@kde.org" );
  194. s_aboutData->addAuthor( "Dirk Mueller", I18N_NOOP("developer (HTML rendering engine)"), "mueller@kde.org" );
  195. s_aboutData->addAuthor( "Peter Kelly", I18N_NOOP("developer (HTML rendering engine)"), "pmk@post.com" );
  196. s_aboutData->addAuthor( "Waldo Bastian", I18N_NOOP("developer (HTML rendering engine, I/O lib)"), "bastian@kde.org" );
  197. s_aboutData->addAuthor( "Germain Garand", I18N_NOOP("developer (HTML rendering engine)"), "germain@ebooksfrance.org" );
  198. s_aboutData->addAuthor( "Leo Savernik", I18N_NOOP("developer (HTML rendering engine)"), "l.savernik@aon.at" );
  199. s_aboutData->addAuthor( "Stephan Kulow", I18N_NOOP("developer (HTML rendering engine, I/O lib, regression test framework)"), "coolo@kde.org" );
  200. s_aboutData->addAuthor( "Antti Koivisto", I18N_NOOP("developer (HTML rendering engine)"), "koivisto@kde.org" );
  201. s_aboutData->addAuthor( "Zack Rusin", I18N_NOOP("developer (HTML rendering engine)"), "zack@kde.org" );
  202. s_aboutData->addAuthor( "Tobias Anton", I18N_NOOP( "developer (HTML rendering engine)" ), "anton@stud.fbi.fh-darmstadt.de" );
  203. s_aboutData->addAuthor( "Lubos Lunak", I18N_NOOP( "developer (HTML rendering engine)" ), "l.lunak@kde.org" );
  204. s_aboutData->addAuthor( "Allan Sandfeld Jensen", I18N_NOOP( "developer (HTML rendering engine)" ), "kde@carewolf.com" );
  205. s_aboutData->addAuthor( "Apple Safari Developers", I18N_NOOP("developer (HTML rendering engine, JavaScript)"), "" );
  206. s_aboutData->addAuthor( "Harri Porten", I18N_NOOP("developer (JavaScript)"), "porten@kde.org" );
  207. s_aboutData->addAuthor( "Koos Vriezen", I18N_NOOP("developer (Java applets and other embedded objects)"), "koos.vriezen@xs4all.nl" );
  208. s_aboutData->addAuthor( "Matt Koss", I18N_NOOP("developer (I/O lib)"), "koss@miesto.sk" );
  209. s_aboutData->addAuthor( "Alex Zepeda", I18N_NOOP("developer (I/O lib)"), "zipzippy@sonic.net" );
  210. s_aboutData->addAuthor( "Richard Moore", I18N_NOOP("developer (Java applet support)"), "rich@kde.org" );
  211. s_aboutData->addAuthor( "Dima Rogozin", I18N_NOOP("developer (Java applet support)"), "dima@mercury.co.il" );
  212. s_aboutData->addAuthor( "Wynn Wilkes", I18N_NOOP("developer (Java 2 security manager support,\n and other major improvements to applet support)"), "wynnw@calderasystems.com" );
  213. s_aboutData->addAuthor( "Stefan Schimanski", I18N_NOOP("developer (Netscape plugin support)"), "schimmi@kde.org" );
  214. s_aboutData->addAuthor( "George Staikos", I18N_NOOP("developer (SSL, Netscape plugins)"), "staikos@kde.org" );
  215. s_aboutData->addAuthor( "Dawit Alemayehu",I18N_NOOP("developer (I/O lib, Authentication support)"), "adawit@kde.org" );
  216. s_aboutData->addAuthor( "Carsten Pfeiffer",I18N_NOOP("developer (framework)"), "pfeiffer@kde.org" );
  217. s_aboutData->addAuthor( "Torsten Rahn", I18N_NOOP("graphics/icons"), "torsten@kde.org" );
  218. s_aboutData->addAuthor( "Torben Weis", I18N_NOOP("kfm author"), "weis@kde.org" );
  219. s_aboutData->addAuthor( "Joseph Wenninger", I18N_NOOP("developer (navigation panel framework)"),"jowenn@kde.org");
  220. s_aboutData->addAuthor( "Stephan Binner", I18N_NOOP("developer (misc stuff)"),"binner@kde.org");
  221. s_aboutData->addAuthor( "Ivor Hewitt", I18N_NOOP("developer (AdBlock filter)"),"ivor@ivor.org");
  222. }
  223. return s_aboutData;
  224. }