r19986 by craig - Fix PictureBrowser crash when closing Scribus without closing PictureBrowser. Adds cleanupPlugin to ScActionPlugin to achieve this

scribus-commit scribus-commit at lists.scribus.net
Fri Apr 10 19:54:29 UTC 2015


Author: craig
Date: Fri Apr 10 19:54:28 2015
New Revision: 19986

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19986
Log:
Fix PictureBrowser crash when closing Scribus without closing PictureBrowser. Adds cleanupPlugin to ScActionPlugin to achieve this

Modified:
    trunk/Scribus/scribus/pluginmanager.cpp
    trunk/Scribus/scribus/pluginmanager.h
    trunk/Scribus/scribus/plugins/picbrowser/picturebrowserplugin.cpp
    trunk/Scribus/scribus/plugins/picbrowser/picturebrowserplugin.h
    trunk/Scribus/scribus/scplugin.h

Modified: trunk/Scribus/scribus/pluginmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19986&path=/trunk/Scribus/scribus/pluginmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/pluginmanager.cpp (original)
+++ trunk/Scribus/scribus/pluginmanager.cpp Fri Apr 10 19:54:28 2015
@@ -550,29 +550,29 @@
 void PluginManager::cleanupPlugins()
 {
 	for (PluginMap::Iterator it = pluginMap.begin(); it != pluginMap.end(); ++it)
-		if (it.value().enabled == true)
+		if (it.value().enabled)
 			finalizePlug(it.value());
 }
 
-void PluginManager::finalizePlug(PluginData & pda)
+void PluginManager::finalizePlug(PluginData & pluginData)
 {
 	typedef void (*freePluginPtr)(ScPlugin* plugin);
-	if (pda.plugin)
-	{
-		if (pda.enabled)
-			disablePlugin(pda);
-		Q_ASSERT(!pda.enabled);
+	if (pluginData.plugin)
+	{
+		if (pluginData.enabled)
+			disablePlugin(pluginData);
+		Q_ASSERT(!pluginData.enabled);
 		freePluginPtr freePlugin =
-			(freePluginPtr) resolveSym(pda.pluginDLL, QString(pda.pluginName + "_freePlugin").toLocal8Bit().data());
+			(freePluginPtr) resolveSym(pluginData.pluginDLL, QString(pluginData.pluginName + "_freePlugin").toLocal8Bit().data());
 		if ( freePlugin )
-			(*freePlugin)( pda.plugin );
-		pda.plugin = 0;
-	}
-	Q_ASSERT(!pda.enabled);
-	if (pda.pluginDLL)
-	{
-		unloadDLL(pda.pluginDLL);
-		pda.pluginDLL = 0;
+			(*freePlugin)( pluginData.plugin );
+		pluginData.plugin = 0;
+	}
+	Q_ASSERT(!pluginData.enabled);
+	if (pluginData.pluginDLL)
+	{
+		unloadDLL(pluginData.pluginDLL);
+		pluginData.pluginDLL = 0;
 	}
 }
 
@@ -584,6 +584,7 @@
 	{
 		ScActionPlugin* plugin = dynamic_cast<ScActionPlugin*>(pda.plugin);
 		assert(plugin);
+		plugin->cleanupPlugin();
 		// FIXME: Correct way to delete action?
 		delete ScCore->primaryMainWindow()->scrActions[plugin->actionInfo().name];
 	}
@@ -702,8 +703,7 @@
 	return pluginMap[pluginName].enabled;
 }
 
-QStringList PluginManager::pluginNames(
-		bool includeDisabled, const char* inherits) const
+QStringList PluginManager::pluginNames( bool includeDisabled, const char* inherits) const
 {
 	// Scan the plugin map for plugins...
 	QStringList names;

Modified: trunk/Scribus/scribus/pluginmanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19986&path=/trunk/Scribus/scribus/pluginmanager.h
==============================================================================
--- trunk/Scribus/scribus/pluginmanager.h (original)
+++ trunk/Scribus/scribus/pluginmanager.h Fri Apr 10 19:54:28 2015
@@ -208,7 +208,7 @@
 	 *         The plug-in is marked unloaded in the map.
 	 *  \param pda plugin data
 	 */
-	void finalizePlug(PluginData & pda);
+	void finalizePlug(PluginData & pluginData);
 
 	/** \brief Configuration structure */
 	PrefsContext* prefs;

Modified: trunk/Scribus/scribus/plugins/picbrowser/picturebrowserplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19986&path=/trunk/Scribus/scribus/plugins/picbrowser/picturebrowserplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/picbrowser/picturebrowserplugin.cpp (original)
+++ trunk/Scribus/scribus/plugins/picbrowser/picturebrowserplugin.cpp Fri Apr 10 19:54:28 2015
@@ -5,7 +5,6 @@
 for which a new license (GPL+exception) is in place.
 */
 #include "picturebrowserplugin.h"
-//#include "picturebrowser.h"
 
 // See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods
 // do. That documentatation is not duplicated here.
@@ -22,6 +21,12 @@
 
 PictureBrowserPlugin::~PictureBrowserPlugin()
 {
+}
+
+bool PictureBrowserPlugin::cleanupPlugin()
+{
+	closePictureBrowser();
+	return true;
 }
 
 void PictureBrowserPlugin::languageChange()
@@ -66,7 +71,7 @@
 	//picturebrowser isn't running yet, so create it
 	if ( !pictureBrowser )
 	{
-		pictureBrowser = new PictureBrowser ( doc, doc->scMW() );
+		pictureBrowser = new PictureBrowser ( doc, 0 );
 
 		if ( !pictureBrowser )
 		{
@@ -110,13 +115,21 @@
 //		pictureBrowser->changedDocument ( doc );
 }
 
+void PictureBrowserPlugin::closePictureBrowser()
+{
+	if (pictureBrowser)
+	{
+		if (pictureBrowser->isVisible())
+			pictureBrowser->close();
+		delete pictureBrowser;
+		pictureBrowser = NULL;
+	}
+}
+
 void PictureBrowserPlugin::pictureBrowserClosed()
 {
-	if(pictureBrowser)
-		pictureBrowser->close();
-	pictureBrowser = 0;
+	pictureBrowser = NULL;
 }
-
 
 // Low level plugin API
 int picturebrowser_getPluginAPIVersion()

Modified: trunk/Scribus/scribus/plugins/picbrowser/picturebrowserplugin.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19986&path=/trunk/Scribus/scribus/plugins/picbrowser/picturebrowserplugin.h
==============================================================================
--- trunk/Scribus/scribus/plugins/picbrowser/picturebrowserplugin.h (original)
+++ trunk/Scribus/scribus/plugins/picbrowser/picturebrowserplugin.h Fri Apr 10 19:54:28 2015
@@ -23,6 +23,7 @@
 		//! \brief Standard plugin implementation
 		PictureBrowserPlugin();
 		virtual ~PictureBrowserPlugin();
+		virtual bool cleanupPlugin();
 		//! \brief main method to run the plug
 		virtual bool run ( ScribusDoc* doc, QString target = QString::null );
 		virtual const QString fullTrName() const;
@@ -34,10 +35,14 @@
 		virtual void unsetDoc();
 		virtual void changedDoc ( ScribusDoc* doc );
 
+	public slots:
+		void closePictureBrowser();
+
 	private:
 		PictureBrowser *pictureBrowser;
 
 	private slots:
+		//only called on auto delete on close, resets ptr
 		void pictureBrowserClosed();
 };
 

Modified: trunk/Scribus/scribus/scplugin.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19986&path=/trunk/Scribus/scribus/scplugin.h
==============================================================================
--- trunk/Scribus/scribus/scplugin.h (original)
+++ trunk/Scribus/scribus/scplugin.h Fri Apr 10 19:54:28 2015
@@ -305,6 +305,19 @@
 
 	public slots:
 		/**
+		 * @brief Deactivates the plugin for unloading / program quit
+		 *
+		 * This method will be called when the plug-in is about to be unloaded,
+		 * or if the plug-in manager has been asked to disable the plug-in.
+		 * This method will never be called unless initPlugin has been called
+		 * first, but there is no guarantee the plugin will actually be
+		 * unloaded after this is called, or before initPlugin is called again.
+		 *
+		 * @returns bool True for success.
+		 */
+		virtual bool cleanupPlugin() { return false; }
+
+		/**
 		 * @brief Run the plug-in's main action.
 		 *
 		 * Run the plug-in's default action synchronously, blocking the rest of
@@ -503,7 +516,7 @@
 //
 // The API version is currently simply incremented with each incompatible
 // change. Future versions may introduce a minor/major scheme if necessary.
-#define PLUGIN_API_VERSION 0x00000105
+#define PLUGIN_API_VERSION 0x00000106
 
 
 #endif




More information about the scribus-commit mailing list