r23051 by craig - Reimplement URL Launcher with better singleton approach

scribus-commit scribus-commit at lists.scribus.net
Tue Jun 25 22:14:09 UTC 2019


Author: craig
Date: Tue Jun 25 22:14:09 2019
New Revision: 23051

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23051
Log:
Reimplement URL Launcher with better singleton approach

Modified:
    trunk/Scribus/scribus/actionmanager.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/ui/sctextbrowser.cpp
    trunk/Scribus/scribus/urllauncher.cpp
    trunk/Scribus/scribus/urllauncher.h

Modified: trunk/Scribus/scribus/actionmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23051&path=/trunk/Scribus/scribus/actionmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/actionmanager.cpp	(original)
+++ trunk/Scribus/scribus/actionmanager.cpp	Tue Jun 25 22:14:09 2019
@@ -1017,12 +1017,12 @@
 	connect( (*scrActions)["helpTooltips"], SIGNAL(triggered()), mainWindow, SLOT(ToggleTips()) );
 	connect( (*scrActions)["helpManual"], SIGNAL(triggered()), mainWindow, SLOT(slotOnlineHelp()) );
 	connect( (*scrActions)["helpCheckUpdates"], SIGNAL(triggered()), mainWindow, SLOT(slotHelpCheckUpdates()) );
-	UrlLauncher* ul=UrlLauncher::instance();
-	connect( (*scrActions)["helpOnlineWWW"], SIGNAL(triggeredData(QString)), ul, SLOT(launchUrlExt(QString)) );
-	connect( (*scrActions)["helpOnlineDocs"], SIGNAL(triggeredData(QString)), ul, SLOT(launchUrlExt(QString)) );
-	connect( (*scrActions)["helpOnlineWiki"], SIGNAL(triggeredData(QString)), ul, SLOT(launchUrlExt(QString)) );
-	connect( (*scrActions)["helpOnlineTutorial1"], SIGNAL(triggeredData(QString)), ul, SLOT(launchUrlExt(QString)) );
-	connect( (*scrActions)["helpChat"], SIGNAL(triggeredData(QString)), ul, SLOT(launchUrlExt(QString)) );
+	UrlLauncher& ul=UrlLauncher::instance();
+	connect( (*scrActions)["helpOnlineWWW"], SIGNAL(triggeredData(QString)), &ul, SLOT(launchUrlExt(QString)) );
+	connect( (*scrActions)["helpOnlineDocs"], SIGNAL(triggeredData(QString)), &ul, SLOT(launchUrlExt(QString)) );
+	connect( (*scrActions)["helpOnlineWiki"], SIGNAL(triggeredData(QString)), &ul, SLOT(launchUrlExt(QString)) );
+	connect( (*scrActions)["helpOnlineTutorial1"], SIGNAL(triggeredData(QString)), &ul, SLOT(launchUrlExt(QString)) );
+	connect( (*scrActions)["helpChat"], SIGNAL(triggeredData(QString)), &ul, SLOT(launchUrlExt(QString)) );
 }
 
 void ActionManager::initUnicodeActions(QMap<QString, QPointer<ScrAction> > *actionMap, QWidget *actionParent, QStringList *actionNamesList)

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23051&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Tue Jun 25 22:14:09 2019
@@ -302,7 +302,6 @@
 	m_prefsManager=nullptr;
 	m_formatsManager=nullptr;
 	resourceManager=nullptr;
-	UrlLauncher::instance();
 	m_mainWindowStatusLabel=nullptr;
 	m_ScriptRunning = 0;
 #ifdef Q_OS_MAC
@@ -2015,7 +2014,6 @@
 		m_prefsManager->SavePrefs();
 	UndoManager::deleteInstance();
 	FormatsManager::deleteInstance();
-	UrlLauncher::deleteInstance();
 //	qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
 	ce->accept();
 }

Modified: trunk/Scribus/scribus/ui/sctextbrowser.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23051&path=/trunk/Scribus/scribus/ui/sctextbrowser.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/sctextbrowser.cpp	(original)
+++ trunk/Scribus/scribus/ui/sctextbrowser.cpp	Tue Jun 25 22:14:09 2019
@@ -49,6 +49,6 @@
 void ScTextBrowser::externalLinkClick(const QUrl& url)
 {
 	if (url.scheme()=="http")
-		UrlLauncher::instance()->launchUrlExt(url, parentWidget());
+		UrlLauncher::instance().launchUrlExt(url, parentWidget());
 }
 

Modified: trunk/Scribus/scribus/urllauncher.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23051&path=/trunk/Scribus/scribus/urllauncher.cpp
==============================================================================
--- trunk/Scribus/scribus/urllauncher.cpp	(original)
+++ trunk/Scribus/scribus/urllauncher.cpp	Tue Jun 25 22:14:09 2019
@@ -18,28 +18,10 @@
 #include "scribuscore.h"
 #include "util.h"
 
-UrlLauncher* UrlLauncher::_instance = nullptr;
-
-UrlLauncher::UrlLauncher()
+UrlLauncher& UrlLauncher::instance()
 {
-}
-
-UrlLauncher::~UrlLauncher()
-{
-}
-
-UrlLauncher* UrlLauncher::instance()
-{
-	if (_instance == nullptr)
-		_instance = new UrlLauncher();
-
+	static UrlLauncher _instance;
 	return _instance;
-}
-
-void UrlLauncher::deleteInstance()
-{
-	delete _instance;
-	_instance = nullptr;
 }
 
 void UrlLauncher::launchUrlExt(const QString& link, QWidget *parent)
@@ -61,7 +43,7 @@
 			{
 				extBrowser = QFileDialog::getOpenFileName(p, tr("Locate your web browser"), QString(), QString());
 				if (!QFileInfo::exists(extBrowser))
-					extBrowser="";
+					extBrowser.clear();
 				PrefsManager::instance()->setExtBrowserExecutable(extBrowser);
 			}
 		}

Modified: trunk/Scribus/scribus/urllauncher.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23051&path=/trunk/Scribus/scribus/urllauncher.h
==============================================================================
--- trunk/Scribus/scribus/urllauncher.h	(original)
+++ trunk/Scribus/scribus/urllauncher.h	Tue Jun 25 22:14:09 2019
@@ -20,34 +20,24 @@
 class SCRIBUS_API UrlLauncher : public QObject
 {
 	Q_OBJECT;
-	
+
 	public:
-		UrlLauncher();
-		~UrlLauncher();
+		UrlLauncher(UrlLauncher const&) = delete;
+		void operator=(UrlLauncher const&) = delete;
 
 		/**
-		 * @brief Returns a pointer to the UrlLauncher instance
-		 * @return A pointer to the UrlLauncher instance
+		 * @brief Returns a reference to the UrlLauncher instance
+		 * @return A reference to the UrlLauncher instance
 		 */
-		static UrlLauncher* instance();
-		/**
-		 * @brief Deletes the UrlLauncher Instance
-		 * Must be called when UrlLauncher is no longer needed.
-		 */
-		static void deleteInstance();
-		
+		static UrlLauncher& instance();
+
 	public slots:
-		void launchUrlExt(const QString& link, QWidget *parent=0);
-		void launchUrlExt(const QUrl& link, QWidget *parent=0);
+		void launchUrlExt(const QString& link, QWidget *parent = nullptr);
+		void launchUrlExt(const QUrl& link, QWidget *parent = nullptr);
 
 	private:
-		/**
-		* @brief The only instance of UrlLauncher available.
-		*
-		* UrlLauncher is singleton and the instance can be queried with the method
-		* instance().
-		*/
-	static UrlLauncher* _instance;
+		UrlLauncher() = default;
+		~UrlLauncher() = default;
 };
 
 #endif




More information about the scribus-commit mailing list