diff --git a/private/packages.cpp b/private/packages.cpp index d73879276..1b6311a25 100644 --- a/private/packages.cpp +++ b/private/packages.cpp @@ -37,7 +37,8 @@ namespace Plasma { PlasmoidPackage::PlasmoidPackage(QObject *parent) - : Plasma::PackageStructure(parent, QString("Plasmoid")) + : Plasma::PackageStructure(parent, QString("Plasmoid")), + m_knsEngine(0) { addDirectoryDefinition("images", "images/", i18n("Images")); QStringList mimetypes; @@ -66,6 +67,11 @@ PlasmoidPackage::PlasmoidPackage(QObject *parent) setRequired("mainscript", true); } +PlasmoidPackage::~PlasmoidPackage() +{ + delete m_knsEngine; +} + void PlasmoidPackage::pathChanged() { KDesktopFile config(path() + "/metadata.desktop"); @@ -79,10 +85,20 @@ void PlasmoidPackage::pathChanged() void PlasmoidPackage::createNewWidgetBrowser(QWidget *parent) { - KNS::Engine *engine = new KNS::Engine(parent); - if (engine->init("plasmoids.knsrc")) { - engine->downloadDialog(this, SLOT(widgetBrowserFinished())); - } +//FIXME: memory leak below: it creates a new KNS::Engine every time it's called +// however, due to issues in the KNS2 library, reusing the same engine causes crashes :( +// if (!m_knsEngine) { + m_knsEngine = new KNS::Engine(parent); + kDebug() << "creating new kns engine" << m_knsEngine; + if (!m_knsEngine->init("plasmoids.knsrc")) { + delete m_knsEngine; + m_knsEngine = 0; + return; + } +// } + + kDebug() << "successful kns engine" << m_knsEngine; + m_knsEngine->downloadDialog(this, SLOT(widgetBrowserFinished())); } void PlasmoidPackage::widgetBrowserFinished() diff --git a/private/packages_p.h b/private/packages_p.h index 7e00f91bb..a1f8280b3 100644 --- a/private/packages_p.h +++ b/private/packages_p.h @@ -24,6 +24,11 @@ #include "plasma/wallpaper.h" #include "plasma/plasma.h" +namespace KNS +{ + class Engine; +} // namespace KNS + namespace Plasma { @@ -34,6 +39,7 @@ class PlasmoidPackage : public PackageStructure Q_OBJECT public: explicit PlasmoidPackage(QObject *parent = 0); + ~PlasmoidPackage(); void createNewWidgetBrowser(QWidget *parent = 0); protected: @@ -41,6 +47,10 @@ protected: protected Q_SLOTS: void widgetBrowserFinished(); + void deleteNewStuffEngine(); + +private: + KNS::Engine *m_knsEngine; }; class ThemePackage : public PackageStructure