/** \file CopyEngineManager.cpp \brief Define the copy engine manager \author alpha_one_x86 \version 0.3 \date 2010 \licence GPL3, see the file COPYING */ #include #include #include "CopyEngineManager.h" CopyEngineManager::CopyEngineManager(OptionDialog *optionDialog) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start"); this->optionDialog=optionDialog; //setup the ui layout plugins->lockPluginListEdition(); QList list=plugins->getPluginsByCategory(PluginType_CopyEngine); foreach(PluginsAvailable currentPlugin,list) onePluginAdded(currentPlugin); connect(plugins,SIGNAL(onePluginAdded(PluginsAvailable)), this,SLOT(onePluginAdded(PluginsAvailable))); connect(plugins,SIGNAL(onePluginWillBeRemoved(PluginsAvailable)), this,SLOT(onePluginWillBeRemoved(PluginsAvailable)),Qt::DirectConnection); connect(plugins,SIGNAL(pluginListingIsfinish()), this,SLOT(allPluginIsloaded())); plugins->unlockPluginListEdition(); //load the options isConnected=false; connect(languages, SIGNAL(newLanguageLoaded(QString)), &facilityEngine,SLOT(retranslate())); } void CopyEngineManager::onePluginAdded(const PluginsAvailable &plugin) { if(plugin.category!=PluginType_CopyEngine) return; //setFileName QString pluginPath=plugin.path+PluginsManager::getResolvedPluginName("copyEngine"); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start: "+pluginPath); //search into loaded session int index=0; while(indexinstance(); if(pluginObject==NULL) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("unable to load the plugin: %1").arg(newItem.pointer->errorString())); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("unable to load the plugin for %1").arg(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(DebugLevel_Warning,QString("unable to cast the plugin: %1").arg(newItem.pointer->errorString())); newItem.pointer->unload(); return; } #ifdef ULTRACOPIER_DEBUG qRegisterMetaType("DebugLevel"); connect(newItem.factory,SIGNAL(debugInformation(DebugLevel,QString,QString,QString,int)),this,SLOT(debugInformation(DebugLevel,QString,QString,QString,int)),Qt::QueuedConnection); #endif // ULTRACOPIER_DEBUG newItem.options=new LocalPluginOptions("CopyEngine-"+newItem.name); newItem.factory->setResources(newItem.options,plugin.writablePath,plugin.path,&facilityEngine,ULTRACOPIER_VERSION_PORTABLE_BOOL); 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->addCopyEngineWidget(newItem.name,newItem.optionsWidget); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"plugin: "+newItem.name+" loaded, send options"); //emit newCopyEngineOptions(plugin.path,newItem.name,newItem.optionsWidget); pluginList << newItem; connect(languages,SIGNAL(newLanguageLoaded(QString)),newItem.factory,SLOT(newLanguageLoaded())); if(plugins->allPluginHaveBeenLoaded()) allPluginIsloaded(); if(isConnected) emit addCopyEngine(newItem.name,newItem.canDoOnlyCopy); } void CopyEngineManager::onePluginWillBeRemoved(const PluginsAvailable &plugin) { int index=0; while(indexremoveCopyEngineWidget(pluginList.at(index).name); delete pluginList.at(index).options; delete pluginList.at(index).factory; pluginList.at(index).pointer->unload(); return; } index++; } } CopyEngineManager::returnCopyEngine CopyEngineManager::getCopyEngine(const CopyMode &mode,const QStringList &protocolsUsedForTheSources,const QString &protocolsUsedForTheDestination) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("start, pluginList.size(): %1, mode: %2, and particular protocol").arg(pluginList.size()).arg((int)mode)); returnCopyEngine temp; int index=0; bool isTheGoodEngine=false; while(indexgetInstance(); temp.engine=pluginList[index].intances.last(); temp.canDoOnlyCopy=pluginList.at(index).canDoOnlyCopy; temp.type=pluginList.at(index).type; temp.transferListOperation=pluginList.at(index).transferListOperation; return temp; } index++; } if(mode==Move) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Cannot find any copy engine with motions support"); QMessageBox::critical(NULL,tr("Warning"),tr("Cannot find any copy engine with motions support")); } else { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Cannot find any compatible engine!"); QMessageBox::critical(NULL,tr("Warning"),tr("Cannot find any compatible engine!")); } temp.engine=NULL; temp.type=File; temp.canDoOnlyCopy=true; return temp; } CopyEngineManager::returnCopyEngine CopyEngineManager::getCopyEngine(const CopyMode &mode,const QString &name) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("start, pluginList.size(): %1, with mode: %2, and name: %3").arg(pluginList.size()).arg((int)mode).arg(name)); returnCopyEngine temp; int index=0; while(indexgetInstance(); temp.engine=pluginList[index].intances.last(); temp.canDoOnlyCopy=pluginList.at(index).canDoOnlyCopy; temp.type=pluginList.at(index).type; temp.transferListOperation=pluginList.at(index).transferListOperation; return temp; } index++; } ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Cannot find any engine with this name"); QMessageBox::critical(NULL,tr("Warning"),tr("Cannot find any engine with this name")); temp.engine=NULL; temp.type=File; temp.canDoOnlyCopy=true; return temp; } #ifdef ULTRACOPIER_DEBUG void CopyEngineManager::debugInformation(DebugLevel level,const QString& fonction,const QString& text,const QString& 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 QString &groupName,const QString &variableName,const QVariant &value) { if(groupName=="CopyEngine" && variableName=="List") { Q_UNUSED(value) ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Information,"start(\""+groupName+"\",\""+variableName+"\",\""+value.toString()+"\")"); allPluginIsloaded(); } } void CopyEngineManager::setIsConnected() { /* ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start"); prevent bug, I don't know why, in one case it bug here */ isConnected=true; int index=0; while(indexgetOptionValue("CopyEngine","List").toStringList(); preferedList.removeDuplicates(); actualList.removeDuplicates(); index=0; while(indexsetOptionValue("CopyEngine","List",preferedList); QList newPluginList; index=0; while(index