/** \file CopyEngineManager.cpp \brief Define the copy engine manager \author alpha_one_x86 \licence GPL3, see the file COPYING */ #include #include "CopyEngineManager.h" #include "LanguagesManager.h" #include "cpp11addition.h" #ifdef ULTRACOPIER_PLUGIN_ALL_IN_ONE_DIRECT #include "plugins/CopyEngine/Ultracopier-Spec/CopyEngineFactory.h" #endif CopyEngineManager::CopyEngineManager(OptionDialog *optionDialog) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start"); this->optionDialog=optionDialog; //setup the ui layout PluginsManager::pluginsManager->lockPluginListEdition(); connect(this,&CopyEngineManager::previouslyPluginAdded, this,&CopyEngineManager::onePluginAdded,Qt::QueuedConnection); connect(PluginsManager::pluginsManager,&PluginsManager::onePluginAdded, this,&CopyEngineManager::onePluginAdded,Qt::QueuedConnection); #ifndef ULTRACOPIER_PLUGIN_ALL_IN_ONE connect(PluginsManager::pluginsManager,&PluginsManager::onePluginWillBeRemoved, this,&CopyEngineManager::onePluginWillBeRemoved,Qt::DirectConnection); #endif connect(PluginsManager::pluginsManager,&PluginsManager::pluginListingIsfinish, this,&CopyEngineManager::allPluginIsloaded,Qt::QueuedConnection); std::vector list=PluginsManager::pluginsManager->getPluginsByCategory(PluginType_CopyEngine); foreach(PluginsAvailable currentPlugin,list) emit previouslyPluginAdded(currentPlugin); PluginsManager::pluginsManager->unlockPluginListEdition(); //load the options isConnected=false; } void CopyEngineManager::onePluginAdded(const PluginsAvailable &plugin) { if(plugin.category!=PluginType_CopyEngine) return; //setFileName std::string pluginPath=plugin.path+PluginsManager::getResolvedPluginName("copyEngine"); #ifndef ULTRACOPIER_PLUGIN_ALL_IN_ONE /*more IO if(!QFile(pluginPath).exists()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"The plugin binary is missing: "+pluginPath); return; }*/ #endif ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start: "+pluginPath); //search into loaded session unsigned int index=0; while(index(pluginObject); if(newItem.factory!=NULL) break; index++; } if(index==objectList.size()) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"static copy engine not found"); return; } #else QObject *pluginObject = newItem.pointer->instance(); if(pluginObject==NULL) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"unable to load the plugin: "+newItem.pointer->errorString().toStdString()); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"unable to load the plugin for "+newItem.pluginPath); newItem.pointer->unload(); return; } newItem.factory = qobject_cast(pluginObject); //check if found index=0; while(indexunload(); return; } index++; } if(newItem.factory==NULL) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"unable to cast the plugin: "+newItem.pointer->errorString().toStdString()); newItem.pointer->unload(); return; } #endif #else newItem.factory=new CopyEngineFactory(); #endif #ifdef ULTRACOPIER_DEBUG connect(newItem.factory,&PluginInterface_CopyEngineFactory::debugInformation,this,&CopyEngineManager::debugInformation,Qt::QueuedConnection); #endif // ULTRACOPIER_DEBUG newItem.options=new LocalPluginOptions("CopyEngine-"+newItem.name); newItem.factory->setResources(newItem.options,plugin.writablePath,plugin.path,&FacilityEngine::facilityEngine,ULTRACOPIER_VERSION_PORTABLE_BOOL); connect(OptionEngine::optionEngine,&OptionEngine::resetOptions,newItem.factory,&PluginInterface_CopyEngineFactory::resetOptions); newItem.optionsWidget=newItem.factory->options(); newItem.supportedProtocolsForTheSource=newItem.factory->supportedProtocolsForTheSource(); newItem.supportedProtocolsForTheDestination=newItem.factory->supportedProtocolsForTheDestination(); newItem.canDoOnlyCopy=newItem.factory->canDoOnlyCopy(); newItem.type=newItem.factory->getCopyType(); newItem.transferListOperation=newItem.factory->getTransferListOperation(); optionDialog->addPluginOptionWidget(PluginType_CopyEngine,newItem.name,newItem.optionsWidget); ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"plugin: "+newItem.name+" loaded, send options"); //emit newCopyEngineOptions(plugin.path,newItem.name,newItem.optionsWidget); pluginList.push_back(newItem); connect(LanguagesManager::languagesManager,&LanguagesManager::newLanguageLoaded,newItem.factory,&PluginInterface_CopyEngineFactory::newLanguageLoaded); if(PluginsManager::pluginsManager->allPluginHaveBeenLoaded()) allPluginIsloaded(); if(isConnected) emit addCopyEngine(newItem.name,newItem.canDoOnlyCopy); } #ifndef ULTRACOPIER_PLUGIN_ALL_IN_ONE void CopyEngineManager::onePluginWillBeRemoved(const PluginsAvailable &plugin) { unsigned int index=0; while(indexunload(); return; } index++; } } #endif CopyEngineManager::returnCopyEngine CopyEngineManager::getCopyEngine(const Ultracopier::CopyMode &mode, const std::vector &protocolsUsedForTheSources,const std::string &protocolsUsedForTheDestination) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start, pluginList.size(): "+std::to_string(pluginList.size())+", mode: "+std::to_string((int)mode)+", and particular protocol"); returnCopyEngine temp; unsigned int index=0; bool isTheGoodEngine=false; while(indexgetInstance()); temp.engine=pluginList.at(index).intances.back(); temp.canDoOnlyCopy=pluginList.at(index).canDoOnlyCopy; temp.havePause=pluginList.at(index).factory->havePause(); temp.type=pluginList.at(index).type; temp.transferListOperation=pluginList.at(index).transferListOperation; return temp; } index++; } if(mode==Ultracopier::Move) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Cannot find any copy engine with move support"); QMessageBox::critical(NULL,tr("Warning"),tr("Cannot find any copy engine with move support")); } else { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Cannot find any compatible engine!"); QMessageBox::critical(NULL,tr("Warning"),tr("Cannot find any compatible engine!")); } ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"protocolsUsedForTheSources: "+stringimplode(protocolsUsedForTheSources,";")+", protocolsUsedForTheDestination: "+protocolsUsedForTheDestination); temp.engine=NULL; temp.type=Ultracopier::File; temp.canDoOnlyCopy=true; return temp; } CopyEngineManager::returnCopyEngine CopyEngineManager::getCopyEngine(const Ultracopier::CopyMode &mode,const std::string &name) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start, pluginList.size(): "+std::to_string(pluginList.size())+", with mode: "+std::to_string((int)mode)+", and name: "+name); returnCopyEngine temp; unsigned int index=0; while(indexgetInstance(); pluginList[index].intances.push_back(newIntance); temp.engine=pluginList.at(index).intances.back(); temp.canDoOnlyCopy=pluginList.at(index).canDoOnlyCopy; temp.type=pluginList.at(index).type; temp.havePause=factory->havePause(); temp.transferListOperation=pluginList.at(index).transferListOperation; return temp; } index++; } ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Cannot find any engine with this name: "+name); QMessageBox::critical(NULL,tr("Warning"),tr("Cannot find any engine with this name: %1").arg(QString::fromStdString(name))); temp.engine=NULL; temp.type=Ultracopier::File; temp.canDoOnlyCopy=true; return temp; } #ifdef ULTRACOPIER_DEBUG void CopyEngineManager::debugInformation(const Ultracopier::DebugLevel &level,const std::string& fonction,const std::string& text,const std::string& file,const int& ligne) { DebugEngine::addDebugInformationStatic(level,fonction,text,file,ligne,"Copy Engine plugin"); } #endif // ULTRACOPIER_DEBUG /// \brief To notify when new value into a group have changed void CopyEngineManager::newOptionValue(const std::string &groupName,const std::string &variableName,const std::string &value) { if(groupName=="CopyEngine" && variableName=="List") { Q_UNUSED(value) ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,"start(\""+groupName+"\",\""+variableName+"\",\""+value+"\")"); allPluginIsloaded(); } } void CopyEngineManager::setIsConnected() { /* ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start"); prevent bug, I don't know why, in one case it bug here */ isConnected=true; unsigned int index=0; while(index actualList; unsigned int index=0; while(index preferedList=stringsplit(OptionEngine::optionEngine->getOptionValue("CopyEngine","List"),';'); vectorRemoveDuplicatesForSmallList(preferedList); vectorRemoveDuplicatesForSmallList(actualList); index=0; while(indexsetOptionValue("CopyEngine","List",stringimplode(preferedList,';')); std::vector newPluginList; index=0; while(index &protocolsUsedForTheSources,const std::string &protocolsUsedForTheDestination) { unsigned int index=0; while(index