| 
									
										
										
										
											2017-04-27 20:24:53 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2015-10-09 19:18:45 -03:00
										 |  |  | #include "pluginmanager.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QApplication>
 | 
					
						
							|  |  |  | #include <QDir>
 | 
					
						
							|  |  |  | #include <QPluginLoader>
 | 
					
						
							| 
									
										
										
										
											2015-10-29 21:47:08 -02:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2015-10-09 19:18:45 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | static QList<ISocialNetworkIntegration*> _socialNetworks; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-22 12:29:46 -07:00
										 |  |  | // no point in including dive.h for this
 | 
					
						
							|  |  |  | extern int verbose; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 21:47:08 -02:00
										 |  |  | PluginManager& PluginManager::instance() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-09 19:18:45 -03:00
										 |  |  | 	static PluginManager self; | 
					
						
							|  |  |  | 	return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 21:47:08 -02:00
										 |  |  | PluginManager::PluginManager() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-09 19:26:05 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 21:47:08 -02:00
										 |  |  | void PluginManager::loadPlugins() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-09 19:18:45 -03:00
										 |  |  | 	QDir pluginsDir(qApp->applicationDirPath()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined(Q_OS_WIN)
 | 
					
						
							|  |  |  | 	if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release") | 
					
						
							|  |  |  | 		pluginsDir.cdUp(); | 
					
						
							|  |  |  | #elif defined(Q_OS_MAC)
 | 
					
						
							|  |  |  | 	if (pluginsDir.dirName() == "MacOS") { | 
					
						
							|  |  |  | 		pluginsDir.cdUp(); | 
					
						
							|  |  |  | 		pluginsDir.cdUp(); | 
					
						
							|  |  |  | 		pluginsDir.cdUp(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	pluginsDir.cd("plugins"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-22 12:29:46 -07:00
										 |  |  | 	if (verbose) | 
					
						
							|  |  |  | 		qDebug() << "Plugins Directory: " << pluginsDir; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-09 19:18:45 -03:00
										 |  |  | 	foreach (const QString& fileName, pluginsDir.entryList(QDir::Files)) { | 
					
						
							|  |  |  | 		QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); | 
					
						
							|  |  |  | 		QObject *plugin = loader.instance(); | 
					
						
							| 
									
										
										
										
											2015-10-29 21:47:08 -02:00
										 |  |  | 		if(!plugin) | 
					
						
							| 
									
										
										
										
											2015-10-09 19:18:45 -03:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-08 10:51:50 -02:00
										 |  |  | 		if (ISocialNetworkIntegration *social = qobject_cast<ISocialNetworkIntegration*>(plugin)) { | 
					
						
							|  |  |  | 			qDebug() << "Adding the plugin: " << social->socialNetworkName(); | 
					
						
							| 
									
										
										
										
											2015-10-09 19:18:45 -03:00
										 |  |  | 			_socialNetworks.push_back(social); | 
					
						
							| 
									
										
										
										
											2015-11-08 10:51:50 -02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-10-29 21:47:08 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-10-09 19:18:45 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 21:47:08 -02:00
										 |  |  | QList<ISocialNetworkIntegration*> PluginManager::socialNetworkIntegrationPlugins() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-09 19:18:45 -03:00
										 |  |  | 	return _socialNetworks; | 
					
						
							| 
									
										
										
										
											2015-10-29 21:47:08 -02:00
										 |  |  | } |