TDE base libraries and programs
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_extensionmanager.cc 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset:4 -*-
  2. konq_extensionmanager.cc - Extension Manager for Konqueror
  3. Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
  4. Copyright (c) 2004 by Arend van Beelen jr. <arend@auton.nl>
  5. *************************************************************************
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; either version 2 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. *************************************************************************
  13. */
  14. #include <tqlayout.h>
  15. #include <tqtimer.h>
  16. #include <tdeconfig.h>
  17. #include <kdebug.h>
  18. #include <tdelocale.h>
  19. #include <tdeparts/componentfactory.h>
  20. #include <tdeparts/plugin.h>
  21. #include <kplugininfo.h>
  22. #include <kpluginselector.h>
  23. #include <ksettings/dispatcher.h>
  24. #include <dcopref.h>
  25. #include "konq_extensionmanager.h"
  26. #include "konq_mainwindow.h"
  27. class KonqExtensionManagerPrivate
  28. {
  29. public:
  30. KPluginSelector *pluginSelector;
  31. KonqMainWindow *mainWindow;
  32. KParts::ReadOnlyPart* activePart;
  33. bool isChanged;
  34. };
  35. KonqExtensionManager::KonqExtensionManager(TQWidget *parent, KonqMainWindow *mainWindow, KParts::ReadOnlyPart* activePart) :
  36. KDialogBase(Plain, i18n("Configure"), Default | Cancel | Apply | Ok | User1,
  37. Ok, parent, "extensionmanager", false, true, KGuiItem(i18n("&Reset"), "edit-undo"))
  38. {
  39. d = new KonqExtensionManagerPrivate;
  40. showButton(User1, false);
  41. setChanged(false);
  42. setInitialSize(TQSize(640, 480));
  43. (new TQVBoxLayout(plainPage(), 0, 0))->setAutoAdd(true);
  44. d->pluginSelector = new KPluginSelector(plainPage());
  45. setMainWidget(d->pluginSelector);
  46. connect(d->pluginSelector, TQT_SIGNAL(changed(bool)), this, TQT_SLOT(setChanged(bool)));
  47. connect(d->pluginSelector, TQT_SIGNAL(configCommitted(const TQCString &)),
  48. KSettings::Dispatcher::self(), TQT_SLOT(reparseConfiguration(const TQCString &)));
  49. d->mainWindow = mainWindow;
  50. d->activePart = activePart;
  51. // There's a limitation of KPluginSelector here... It assumes that all plugins in a given widget (as created by addPlugins)
  52. // have their config in the same TDEConfig[Group]. So we can't show konqueror extensions and tdehtml extensions in the same tab.
  53. d->pluginSelector->addPlugins("konqueror", i18n("Extensions"), "Extensions", TDEGlobal::config());
  54. if ( activePart ) {
  55. TDEInstance* instance = activePart->instance();
  56. d->pluginSelector->addPlugins(instance->instanceName(), i18n("Tools"), "Tools", instance->config());
  57. d->pluginSelector->addPlugins(instance->instanceName(), i18n("Statusbar"), "Statusbar", instance->config());
  58. }
  59. }
  60. KonqExtensionManager::~KonqExtensionManager()
  61. {
  62. delete d;
  63. }
  64. void KonqExtensionManager::setChanged(bool c)
  65. {
  66. d->isChanged = c;
  67. enableButton(Apply, c);
  68. }
  69. void KonqExtensionManager::slotDefault()
  70. {
  71. d->pluginSelector->defaults();
  72. setChanged(false);
  73. }
  74. void KonqExtensionManager::slotUser1()
  75. {
  76. d->pluginSelector->load();
  77. setChanged(false);
  78. }
  79. void KonqExtensionManager::apply()
  80. {
  81. if(d->isChanged)
  82. {
  83. d->pluginSelector->save();
  84. setChanged(false);
  85. if( d->mainWindow )
  86. {
  87. KParts::Plugin::loadPlugins(TQT_TQOBJECT(d->mainWindow), d->mainWindow, TDEGlobal::instance());
  88. TQPtrList<KParts::Plugin> plugins = KParts::Plugin::pluginObjects(TQT_TQOBJECT(d->mainWindow));
  89. TQPtrListIterator<KParts::Plugin> it(plugins);
  90. KParts::Plugin *plugin;
  91. while((plugin = it.current()) != 0)
  92. {
  93. ++it;
  94. d->mainWindow->factory()->addClient(plugin);
  95. }
  96. }
  97. if ( d->activePart )
  98. {
  99. KParts::Plugin::loadPlugins( d->activePart, d->activePart, d->activePart->instance() );
  100. TQPtrList<KParts::Plugin> plugins = KParts::Plugin::pluginObjects( d->activePart );
  101. TQPtrListIterator<KParts::Plugin> it(plugins);
  102. KParts::Plugin *plugin;
  103. while((plugin = it.current()) != 0)
  104. {
  105. ++it;
  106. d->activePart->factory()->addClient(plugin);
  107. }
  108. }
  109. }
  110. }
  111. void KonqExtensionManager::slotApply()
  112. {
  113. apply();
  114. }
  115. void KonqExtensionManager::slotOk()
  116. {
  117. emit okClicked();
  118. apply();
  119. accept();
  120. }
  121. void KonqExtensionManager::show()
  122. {
  123. d->pluginSelector->load();
  124. KDialogBase::show();
  125. }
  126. #include "konq_extensionmanager.moc"