← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3267: rework plugin settings loading/saving

 

------------------------------------------------------------
revno: 3267
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2013-04-21 19:35:50 +0200
message:
  rework plugin settings loading/saving
modified:
  dcpp/PluginManager.cpp
  dcpp/PluginManager.h


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/PluginManager.cpp'
--- dcpp/PluginManager.cpp	2013-01-29 18:08:36 +0000
+++ dcpp/PluginManager.cpp	2013-04-21 17:35:50 +0000
@@ -63,19 +63,18 @@
 }
 
 PluginManager::PluginManager() : dcCore(), shutdown(false), secNum(Util::rand()) {
-	SettingsManager::getInstance()->addListener(this);
 }
 
 PluginManager::~PluginManager() {
-	SettingsManager::getInstance()->removeListener(this);
 }
 
 void PluginManager::loadPlugins(function<void (const string&)> f) {
 	TimerManager::getInstance()->addListener(this);
 	ClientManager::getInstance()->addListener(this);
 	QueueManager::getInstance()->addListener(this);
+	SettingsManager::getInstance()->addListener(this);
 
-	loadSettings(); // workaround for SettingsManager loading memory of this when loading fails
+	loadSettings();
 
 	StringTokenizer<string> st(getPluginSetting("CoreSetup", "Plugins"), ";");
 	auto err = [](const string& str) { LogManager::getInstance()->message(str); };
@@ -148,6 +147,11 @@
 }
 
 void PluginManager::unloadPlugins() {
+	TimerManager::getInstance()->removeListener(this);
+	ClientManager::getInstance()->removeListener(this);
+	QueueManager::getInstance()->removeListener(this);
+	SettingsManager::getInstance()->removeListener(this);
+
 	Lock l(cs);
 	shutdown = true;
 
@@ -169,9 +173,7 @@
 	// Destroy hooks that may have not been correctly freed
 	hooks.clear();
 
-	TimerManager::getInstance()->removeListener(this);
-	ClientManager::getInstance()->removeListener(this);
-	QueueManager::getInstance()->removeListener(this);
+	saveSettings();
 }
 
 void PluginManager::unloadPlugin(size_t index) {
@@ -462,8 +464,8 @@
 				const string& pluginGuid = xml.getChildAttrib("Guid");
 				xml.stepIn();
 				auto settings = xml.getCurrentChildren();
-				for(auto j = settings.cbegin(); j != settings.cend(); ++j) {
-					setPluginSetting(pluginGuid, j->first, j->second);
+				for(auto& i: settings) {
+					setPluginSetting(pluginGuid, i.first, i.second);
 				}
 				xml.stepOut();
 			}
@@ -474,25 +476,21 @@
 	}
 }
 
-void PluginManager::on(SettingsManagerListener::Load, SimpleXML& /*xml*/) noexcept {
-	loadSettings();
-}
-
-void PluginManager::on(SettingsManagerListener::Save, SimpleXML& /*xml*/) noexcept {
+void PluginManager::saveSettings() noexcept {
 	Lock l(cs);
 
 	try {
 		SimpleXML xml;
 		xml.addTag("Plugins");
 		xml.stepIn();
-		for(auto i = settings.cbegin(); i != settings.cend(); ++i) {
+		for(auto& i: settings) {
 			xml.addTag("Plugin");
 			xml.stepIn();
-			for(auto j = i->second.cbegin(); j != i->second.cend(); ++j) {
-				xml.addTag(j->first, j->second);			
+			for(auto& j: i.second) {
+				xml.addTag(j.first, j.second);			
 			}
 			xml.stepOut();
-			xml.addChildAttrib("Guid", i->first);
+			xml.addChildAttrib("Guid", i.first);
 		}
 		xml.stepOut();
 
@@ -508,4 +506,12 @@
 	}
 }
 
+void PluginManager::on(SettingsManagerListener::Load, SimpleXML& /*xml*/) noexcept {
+	loadSettings();
+}
+
+void PluginManager::on(SettingsManagerListener::Save, SimpleXML& /*xml*/) noexcept {
+	saveSettings();
+}
+
 } // namespace dcpp

=== modified file 'dcpp/PluginManager.h'
--- dcpp/PluginManager.h	2013-01-29 18:08:36 +0000
+++ dcpp/PluginManager.h	2013-04-21 17:35:50 +0000
@@ -160,8 +160,8 @@
 	void removePluginSetting(const string& pluginName, const string& setting);
 
 private:
-	// So the constructor can easily call it.
 	void loadSettings() noexcept;
+	void saveSettings() noexcept;
 
 	// Check if plugin can be loaded
 	bool checkPlugin(const MetaData& info, function<void (const string&)> err);