summaryrefslogtreecommitdiff
path: root/CopyListener.cpp
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2017-11-24 23:24:09 +0000
committerThomas Preud'homme <robotux@celest.fr>2017-11-24 23:24:09 +0000
commitb3c8bdcc0d1e4b2ab298847a7902b6d60410a5bc (patch)
tree8fce8a51adfb245db8ab2a76831661780c0c713e /CopyListener.cpp
parente297dbd8052ef4e66f069e2dd1865ae7fa8af28e (diff)
New upstream version 1.2.3.6
Diffstat (limited to 'CopyListener.cpp')
-rw-r--r--[-rwxr-xr-x]CopyListener.cpp657
1 files changed, 365 insertions, 292 deletions
diff --git a/CopyListener.cpp b/CopyListener.cpp
index c648b97..897a4c4 100755..100644
--- a/CopyListener.cpp
+++ b/CopyListener.cpp
@@ -1,392 +1,465 @@
/** \file CopyListener.h
\brief Define the copy listener
\author alpha_one_x86
-\version 0.3
-\date 2010
\licence GPL3, see the file COPYING */
#include "CopyListener.h"
+#include "LanguagesManager.h"
+
+#ifdef ULTRACOPIER_PLUGIN_ALL_IN_ONE_DIRECT
+#include "plugins/Listener/catchcopy-v0002/listener.h"
+#endif
+
+#include <QRegularExpression>
+#include <QMessageBox>
CopyListener::CopyListener(OptionDialog *optionDialog)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- this->optionDialog=optionDialog;
- pluginLoader=new PluginLoader(optionDialog);
- //load the options
- tryListen=false;
- QList<QPair<QString, QVariant> > KeysList;
- KeysList.append(qMakePair(QString("CatchCopyAsDefault"),QVariant(true)));
- options->addOptionGroup("CopyListener",KeysList);
- plugins->lockPluginListEdition();
- QList<PluginsAvailable> list=plugins->getPluginsByCategory(PluginType_Listener);
- qRegisterMetaType<PluginsAvailable>("PluginsAvailable");
- qRegisterMetaType<ListeningState>("ListeningState");
- connect(this,SIGNAL(previouslyPluginAdded(PluginsAvailable)), this,SLOT(onePluginAdded(PluginsAvailable)),Qt::QueuedConnection);
- connect(plugins,SIGNAL(onePluginAdded(PluginsAvailable)), this,SLOT(onePluginAdded(PluginsAvailable)),Qt::QueuedConnection);
- connect(plugins,SIGNAL(onePluginWillBeRemoved(PluginsAvailable)), this,SLOT(onePluginWillBeRemoved(PluginsAvailable)),Qt::DirectConnection);
- connect(plugins,SIGNAL(pluginListingIsfinish()), this,SLOT(allPluginIsloaded()),Qt::QueuedConnection);
- connect(pluginLoader,SIGNAL(pluginLoaderReady(CatchState,bool,bool)), this,SIGNAL(pluginLoaderReady(CatchState,bool,bool)));
- foreach(PluginsAvailable currentPlugin,list)
- emit previouslyPluginAdded(currentPlugin);
- plugins->unlockPluginListEdition();
- last_state=NotListening;
- last_have_plugin=false;
- last_inWaitOfReply=false;
+ stopIt=false;
+ this->optionDialog=optionDialog;
+ pluginLoader=new PluginLoader(optionDialog);
+ //load the options
+ tryListen=false;
+ PluginsManager::pluginsManager->lockPluginListEdition();
+ QList<PluginsAvailable> list=PluginsManager::pluginsManager->getPluginsByCategory(PluginType_Listener);
+ connect(this,&CopyListener::previouslyPluginAdded, this,&CopyListener::onePluginAdded,Qt::QueuedConnection);
+ connect(PluginsManager::pluginsManager,&PluginsManager::onePluginAdded, this,&CopyListener::onePluginAdded,Qt::QueuedConnection);
+ #ifndef ULTRACOPIER_PLUGIN_ALL_IN_ONE
+ connect(PluginsManager::pluginsManager,&PluginsManager::onePluginWillBeRemoved, this,&CopyListener::onePluginWillBeRemoved,Qt::DirectConnection);
+ #endif
+ connect(PluginsManager::pluginsManager,&PluginsManager::pluginListingIsfinish, this,&CopyListener::allPluginIsloaded,Qt::QueuedConnection);
+ connect(pluginLoader,&PluginLoader::pluginLoaderReady, this,&CopyListener::pluginLoaderReady);
+ foreach(PluginsAvailable currentPlugin,list)
+ emit previouslyPluginAdded(currentPlugin);
+ PluginsManager::pluginsManager->unlockPluginListEdition();
+ last_state=Ultracopier::NotListening;
+ last_have_plugin=false;
+ last_inWaitOfReply=false;
+ stripSeparatorRegex=QRegularExpression(QStringLiteral("[\\\\/]+$"));
}
CopyListener::~CopyListener()
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- QList<PluginsAvailable> list=plugins->getPluginsByCategory(PluginType_Listener);
- foreach(PluginsAvailable currentPlugin,list)
- onePluginWillBeRemoved(currentPlugin);
- delete pluginLoader;
+ stopIt=true;
+ if(pluginLoader!=NULL)
+ {
+ delete pluginLoader;
+ pluginLoader=NULL;
+ }
}
void CopyListener::resendState()
{
- if(plugins->allPluginHaveBeenLoaded())
- {
- sendState(true);
- pluginLoader->resendState();
- }
+ if(PluginsManager::pluginsManager->allPluginHaveBeenLoaded())
+ {
+ sendState(true);
+ if(pluginLoader!=NULL)
+ pluginLoader->resendState();
+ }
}
void CopyListener::onePluginAdded(const PluginsAvailable &plugin)
{
- if(plugin.category!=PluginType_Listener)
- return;
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"try load: "+plugin.path+PluginsManager::getResolvedPluginName("listener"));
- //setFileName
- QPluginLoader *pluginOfPluginLoader=new QPluginLoader(plugin.path+PluginsManager::getResolvedPluginName("listener"));
- QObject *pluginInstance = pluginOfPluginLoader->instance();
- if(pluginInstance)
- {
- PluginInterface_Listener *listen = qobject_cast<PluginInterface_Listener *>(pluginInstance);
- //check if found
- int index=0;
- while(index<pluginList.size())
- {
- if(pluginList.at(index).listenInterface==listen)
- {
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("Plugin already found %1 for %2").arg(pluginList.at(index).path).arg(plugin.path));
- pluginOfPluginLoader->unload();
- return;
- }
- index++;
- }
- if(listen)
- {
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"Plugin correctly loaded");
- #ifdef ULTRACOPIER_DEBUG
- connect(listen,SIGNAL(debugInformation(DebugLevel,QString,QString,QString,int)),this,SLOT(debugInformation(DebugLevel,QString,QString,QString,int)));
- #endif // ULTRACOPIER_DEBUG
- connect(listen,SIGNAL(newCopy(quint32,QStringList)), this,SLOT(newPluginCopy(quint32,QStringList)));
- connect(listen,SIGNAL(newCopy(quint32,QStringList,QString)), this,SLOT(newPluginCopy(quint32,QStringList,QString)));
- connect(listen,SIGNAL(newMove(quint32,QStringList)), this,SLOT(newPluginMove(quint32,QStringList)));
- connect(listen,SIGNAL(newMove(quint32,QStringList,QString)), this,SLOT(newPluginMove(quint32,QStringList,QString)));
- PluginListener newPluginListener;
- newPluginListener.listenInterface = listen;
- newPluginListener.pluginLoader = pluginOfPluginLoader;
- newPluginListener.path = plugin.path+PluginsManager::getResolvedPluginName("listener");
- newPluginListener.state = NotListening;
- newPluginListener.inWaitOfReply = false;
- newPluginListener.options=new LocalPluginOptions("Listener-"+plugin.name);
- newPluginListener.listenInterface->setResources(newPluginListener.options,plugin.writablePath,plugin.path,ULTRACOPIER_VERSION_PORTABLE_BOOL);
- optionDialog->addPluginOptionWidget(PluginType_Listener,plugin.name,newPluginListener.listenInterface->options());
- connect(languages,SIGNAL(newLanguageLoaded(QString)),newPluginListener.listenInterface,SLOT(newLanguageLoaded()));
- pluginList << newPluginListener;
- connect(pluginList.last().listenInterface,SIGNAL(newState(ListeningState)),this,SLOT(newState(ListeningState)));
- if(tryListen)
- {
- pluginList.last().inWaitOfReply=true;
- listen->listen();
- }
- }
- else
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"unable to cast the plugin: "+pluginOfPluginLoader->errorString());
- }
- else
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"unable to load the plugin: "+pluginOfPluginLoader->errorString());
+ if(plugin.category!=PluginType_Listener)
+ return;
+ PluginListener newPluginListener;
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("try load: ")+plugin.path+PluginsManager::getResolvedPluginName("listener"));
+ //setFileName
+ #ifdef ULTRACOPIER_PLUGIN_ALL_IN_ONE
+ PluginInterface_Listener *listen;
+ #ifndef ULTRACOPIER_PLUGIN_ALL_IN_ONE_DIRECT
+ QObjectList objectList=QPluginLoader::staticInstances();
+ int index=0;
+ QObject *pluginObject;
+ while(index<objectList.size())
+ {
+ pluginObject=objectList.at(index);
+ listen = qobject_cast<PluginInterface_Listener *>(pluginObject);
+ if(listen!=NULL)
+ break;
+ index++;
+ }
+ if(index==objectList.size())
+ {
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("static listener not found"));
+ return;
+ }
+ #else
+ listen=new Listener();
+ #endif
+ #ifndef ULTRACOPIER_PLUGIN_ALL_IN_ONE_DIRECT
+ newPluginListener.pluginLoader=NULL;
+ #endif
+ #else
+ QPluginLoader *pluginOfPluginLoader=new QPluginLoader(plugin.path+PluginsManager::getResolvedPluginName(QStringLiteral("listener")));
+ QObject *pluginInstance = pluginOfPluginLoader->instance();
+ if(!pluginInstance)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("unable to load the plugin: ")+pluginOfPluginLoader->errorString());
+ return;
+ }
+ PluginInterface_Listener *listen = qobject_cast<PluginInterface_Listener *>(pluginInstance);
+ if(!listen)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("unable to load the plugin: ")+pluginOfPluginLoader->errorString());
+ return;
+ }
+ //check if found
+ int index=0;
+ while(index<pluginList.size())
+ {
+ if(pluginList.at(index).listenInterface==listen)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("Plugin already found %1 for %2").arg(pluginList.at(index).path).arg(plugin.path));
+ pluginOfPluginLoader->unload();
+ return;
+ }
+ index++;
+ }
+ newPluginListener.pluginLoader = pluginOfPluginLoader;
+ #endif
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("Plugin correctly loaded"));
+ #ifdef ULTRACOPIER_DEBUG
+ connect(listen,&PluginInterface_Listener::debugInformation,this,&CopyListener::debugInformation,Qt::DirectConnection);
+ #endif // ULTRACOPIER_DEBUG
+ connect(listen,&PluginInterface_Listener::error, this,&CopyListener::error,Qt::DirectConnection);
+ connect(listen,&PluginInterface_Listener::newCopyWithoutDestination, this,&CopyListener::newPluginCopyWithoutDestination,Qt::DirectConnection);
+ connect(listen,&PluginInterface_Listener::newCopy, this,&CopyListener::newPluginCopy,Qt::DirectConnection);
+ connect(listen,&PluginInterface_Listener::newMoveWithoutDestination, this,&CopyListener::newPluginMoveWithoutDestination,Qt::DirectConnection);
+ connect(listen,&PluginInterface_Listener::newMove, this,&CopyListener::newPluginMove,Qt::DirectConnection);
+ connect(listen,&PluginInterface_Listener::newClientList, this,&CopyListener::reloadClientList,Qt::DirectConnection);
+ newPluginListener.listenInterface = listen;
+
+ newPluginListener.path = plugin.path+PluginsManager::getResolvedPluginName(QStringLiteral("listener"));
+ newPluginListener.state = Ultracopier::NotListening;
+ newPluginListener.inWaitOfReply = false;
+ newPluginListener.options=new LocalPluginOptions(QStringLiteral("Listener-")+plugin.name);
+ newPluginListener.listenInterface->setResources(newPluginListener.options,plugin.writablePath,plugin.path,ULTRACOPIER_VERSION_PORTABLE_BOOL);
+ optionDialog->addPluginOptionWidget(PluginType_Listener,plugin.name,newPluginListener.listenInterface->options());
+ connect(LanguagesManager::languagesManager,&LanguagesManager::newLanguageLoaded,newPluginListener.listenInterface,&PluginInterface_Listener::newLanguageLoaded,Qt::DirectConnection);
+ pluginList << newPluginListener;
+ connect(pluginList.last().listenInterface,&PluginInterface_Listener::newState,this,&CopyListener::newState,Qt::DirectConnection);
+ if(tryListen)
+ {
+ pluginList.last().inWaitOfReply=true;
+ listen->listen();
+ }
}
#ifdef ULTRACOPIER_DEBUG
-void CopyListener::debugInformation(DebugLevel level,const QString& fonction,const QString& text,const QString& file,const int& ligne)
+void CopyListener::debugInformation(const Ultracopier::DebugLevel &level, const QString& fonction, const QString& text, const QString& file, const int& ligne)
{
- DebugEngine::addDebugInformationStatic(level,fonction,text,file,ligne,"Listener plugin");
+ DebugEngine::addDebugInformationStatic(level,fonction,text,file,ligne,QStringLiteral("Listener plugin"));
}
#endif // ULTRACOPIER_DEBUG
+void CopyListener::error(const QString &error)
+{
+ QMessageBox::critical(NULL,tr("Error"),tr("Error during the reception of the copy/move list\n%1").arg(error));
+}
+
bool CopyListener::oneListenerIsLoaded()
{
- return (pluginList.size()>0);
+ return (pluginList.size()>0);
}
+#ifndef ULTRACOPIER_PLUGIN_ALL_IN_ONE
void CopyListener::onePluginWillBeRemoved(const PluginsAvailable &plugin)
{
- if(plugin.category!=PluginType_Listener)
- return;
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"unload the current plugin");
- int indexPlugin=0;
- while(indexPlugin<pluginList.size())
- {
- if((plugin.path+PluginsManager::getResolvedPluginName("listener"))==pluginList.at(indexPlugin).path)
- {
- int index=0;
- while(index<copyRunningList.size())
- {
- if(copyRunningList.at(index).listenInterface==pluginList.at(indexPlugin).listenInterface)
- copyRunningList[index].listenInterface=NULL;
- index++;
- }
- pluginList.at(indexPlugin).listenInterface->close();
- disconnect(pluginList.at(indexPlugin).listenInterface);
- pluginList.at(indexPlugin).pluginLoader->unload();
- delete pluginList.at(indexPlugin).options;
- pluginList.removeAt(indexPlugin);
- sendState();
- return;
- }
- indexPlugin++;
- }
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"not found");
+ if(plugin.category!=PluginType_Listener)
+ return;
+ int indexPlugin=0;
+ while(indexPlugin<pluginList.size())
+ {
+ if((plugin.path+PluginsManager::getResolvedPluginName(QStringLiteral("listener")))==pluginList.at(indexPlugin).path)
+ {
+ int index=0;
+ while(index<copyRunningList.size())
+ {
+ if(copyRunningList.at(index).listenInterface==pluginList.at(indexPlugin).listenInterface)
+ copyRunningList[index].listenInterface=NULL;
+ index++;
+ }
+ if(pluginList.at(indexPlugin).listenInterface!=NULL)
+ {
+ pluginList.at(indexPlugin).listenInterface->close();
+ delete pluginList.at(indexPlugin).listenInterface;
+ }
+ if(pluginList.at(indexPlugin).pluginLoader!=NULL)
+ {
+ pluginList.at(indexPlugin).pluginLoader->unload();
+ delete pluginList.at(indexPlugin).options;
+ }
+ pluginList.removeAt(indexPlugin);
+ sendState();
+ return;
+ }
+ indexPlugin++;
+ }
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"not found");
}
+#endif
-void CopyListener::newState(const ListeningState &state)
+void CopyListener::newState(const Ultracopier::ListeningState &state)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- PluginInterface_Listener *temp=qobject_cast<PluginInterface_Listener *>(QObject::sender());
- if(temp==NULL)
- {
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("listener not located!"));
- return;
- }
- int index=0;
- while(index<pluginList.size())
- {
- if(temp==pluginList.at(index).listenInterface)
- {
- pluginList[index].state=state;
- pluginList[index].inWaitOfReply=false;
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("new state for the plugin %1: %2").arg(index).arg(state));
- sendState(true);
- return;
- }
- index++;
- }
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("listener not found!"));
+ if(stopIt)
+ return;
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start"));
+ PluginInterface_Listener *temp=qobject_cast<PluginInterface_Listener *>(QObject::sender());
+ if(temp==NULL)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,QStringLiteral("listener not located!"));
+ return;
+ }
+ int index=0;
+ while(index<pluginList.size())
+ {
+ if(temp==pluginList.at(index).listenInterface)
+ {
+ pluginList[index].state=state;
+ pluginList[index].inWaitOfReply=false;
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("new state for the plugin %1: %2").arg(index).arg(state));
+ sendState(true);
+ return;
+ }
+ index++;
+ }
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,QStringLiteral("listener not found!"));
}
void CopyListener::listen()
{
- tryListen=true;
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- int index=0;
- while(index<pluginList.size())
- {
- pluginList[index].inWaitOfReply=true;
- pluginList.at(index).listenInterface->listen();
- index++;
- }
- pluginLoader->load();
+ tryListen=true;
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start"));
+ int index=0;
+ while(index<pluginList.size())
+ {
+ pluginList[index].inWaitOfReply=true;
+ pluginList.at(index).listenInterface->listen();
+ index++;
+ }
+ if(pluginLoader!=NULL)
+ pluginLoader->load();
}
void CopyListener::close()
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- tryListen=false;
- pluginLoader->unload();
- int index=0;
- while(index<pluginList.size())
- {
- pluginList[index].inWaitOfReply=true;
- pluginList.at(index).listenInterface->close();
- index++;
- }
- copyRunningList.clear();
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start"));
+ tryListen=false;
+ if(pluginLoader!=NULL)
+ pluginLoader->unload();
+ int index=0;
+ while(index<pluginList.size())
+ {
+ pluginList[index].inWaitOfReply=true;
+ pluginList.at(index).listenInterface->close();
+ index++;
+ }
+ copyRunningList.clear();
}
QStringList CopyListener::stripSeparator(QStringList sources)
{
- int index=0;
- while(index<sources.size())
- {
- sources[index].remove(QRegExp("[\\\\/]+$"));
- index++;
- }
- return sources;
+ int index=0;
+ while(index<sources.size())
+ {
+ sources[index].remove(stripSeparatorRegex);
+ index++;
+ }
+ return sources;
}
/** new copy without destination have been pased by the CLI */
-void CopyListener::newCopy(QStringList sources)
+void CopyListener::copyWithoutDestination(QStringList sources)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- emit newCopy(incrementOrderId(),QStringList() << "file",stripSeparator(sources));
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start"));
+ emit newCopyWithoutDestination(incrementOrderId(),QStringList() << QStringLiteral("file"),stripSeparator(sources));
}
/** new copy with destination have been pased by the CLI */
-void CopyListener::newCopy(QStringList sources,QString destination)
+void CopyListener::copy(QStringList sources,QString destination)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- emit newCopy(incrementOrderId(),QStringList() << "file",stripSeparator(sources),"file",destination);
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start"));
+ emit newCopy(incrementOrderId(),QStringList() << QStringLiteral("file"),stripSeparator(sources),QStringLiteral("file"),destination);
}
/** new move without destination have been pased by the CLI */
-void CopyListener::newMove(QStringList sources)
+void CopyListener::moveWithoutDestination(QStringList sources)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- emit newMove(incrementOrderId(),QStringList() << "file",stripSeparator(sources));
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start"));
+ emit newMoveWithoutDestination(incrementOrderId(),QStringList() << QStringLiteral("file"),stripSeparator(sources));
}
/** new move with destination have been pased by the CLI */
-void CopyListener::newMove(QStringList sources,QString destination)
+void CopyListener::move(QStringList sources,QString destination)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- emit newMove(incrementOrderId(),QStringList() << "file",stripSeparator(sources),"file",destination);
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start"));
+ emit newMove(incrementOrderId(),QStringList() << QStringLiteral("file"),stripSeparator(sources),QStringLiteral("file"),destination);
}
void CopyListener::copyFinished(const quint32 & orderId,const bool &withError)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- int index=0;
- while(index<copyRunningList.size())
- {
- if(orderId==copyRunningList.at(index).orderId)
- {
- orderList.removeAll(orderId);
- if(copyRunningList.at(index).listenInterface!=NULL)
- copyRunningList.at(index).listenInterface->transferFinished(copyRunningList.at(index).pluginOrderId,withError);
- copyRunningList.removeAt(index);
- return;
- }
- index++;
- }
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start"));
+ int index=0;
+ while(index<copyRunningList.size())
+ {
+ if(orderId==copyRunningList.at(index).orderId)
+ {
+ orderList.removeAll(orderId);
+ if(copyRunningList.at(index).listenInterface!=NULL)
+ copyRunningList.at(index).listenInterface->transferFinished(copyRunningList.at(index).pluginOrderId,withError);
+ copyRunningList.removeAt(index);
+ return;
+ }
+ index++;
+ }
}
void CopyListener::copyCanceled(const quint32 & orderId)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- int index=0;
- while(index<copyRunningList.size())
- {
- if(orderId==copyRunningList.at(index).orderId)
- {
- orderList.removeAll(orderId);
- if(copyRunningList.at(index).listenInterface!=NULL)
- copyRunningList.at(index).listenInterface->transferCanceled(copyRunningList.at(index).pluginOrderId);
- copyRunningList.removeAt(index);
- return;
- }
- index++;
- }
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start"));
+ int index=0;
+ while(index<copyRunningList.size())
+ {
+ if(orderId==copyRunningList.at(index).orderId)
+ {
+ orderList.removeAll(orderId);
+ if(copyRunningList.at(index).listenInterface!=NULL)
+ copyRunningList.at(index).listenInterface->transferCanceled(copyRunningList.at(index).pluginOrderId);
+ copyRunningList.removeAt(index);
+ return;
+ }
+ index++;
+ }
}
-void CopyListener::newPluginCopy(const quint32 &orderId,const QStringList &sources)
+void CopyListener::newPluginCopyWithoutDestination(const quint32 &orderId,const QStringList &sources)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"sources: "+sources.join(";"));
- PluginInterface_Listener *plugin = qobject_cast<PluginInterface_Listener *>(sender());
- CopyRunning newCopyInformation;
- newCopyInformation.listenInterface = plugin;
- newCopyInformation.pluginOrderId = orderId;
- newCopyInformation.orderId = incrementOrderId();
- copyRunningList << newCopyInformation;
- emit newCopy(orderId,QStringList() << "file",stripSeparator(sources));
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("sources: ")+sources.join(QStringLiteral(";")));
+ PluginInterface_Listener *plugin = qobject_cast<PluginInterface_Listener *>(sender());
+ CopyRunning newCopyInformation;
+ newCopyInformation.listenInterface = plugin;
+ newCopyInformation.pluginOrderId = orderId;
+ newCopyInformation.orderId = incrementOrderId();
+ copyRunningList << newCopyInformation;
+ emit newCopyWithoutDestination(orderId,QStringList() << QStringLiteral("file"),stripSeparator(sources));
}
void CopyListener::newPluginCopy(const quint32 &orderId,const QStringList &sources,const QString &destination)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"sources: "+sources.join(";")+", destination: "+destination);
- PluginInterface_Listener *plugin = qobject_cast<PluginInterface_Listener *>(sender());
- CopyRunning newCopyInformation;
- newCopyInformation.listenInterface = plugin;
- newCopyInformation.pluginOrderId = orderId;
- newCopyInformation.orderId = incrementOrderId();
- copyRunningList << newCopyInformation;
- emit newCopy(orderId,QStringList() << "file",stripSeparator(sources),"file",destination);
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("sources: ")+sources.join(QStringLiteral(";"))+QStringLiteral(", destination: ")+destination);
+ PluginInterface_Listener *plugin = qobject_cast<PluginInterface_Listener *>(sender());
+ CopyRunning newCopyInformation;
+ newCopyInformation.listenInterface = plugin;
+ newCopyInformation.pluginOrderId = orderId;
+ newCopyInformation.orderId = incrementOrderId();
+ copyRunningList << newCopyInformation;
+ emit newCopy(orderId,QStringList() << QStringLiteral("file"),stripSeparator(sources),QStringLiteral("file"),destination);
}
-void CopyListener::newPluginMove(const quint32 &orderId,const QStringList &sources)
+void CopyListener::newPluginMoveWithoutDestination(const quint32 &orderId,const QStringList &sources)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"sources: "+sources.join(";"));
- PluginInterface_Listener *plugin = qobject_cast<PluginInterface_Listener *>(sender());
- CopyRunning newCopyInformation;
- newCopyInformation.listenInterface = plugin;
- newCopyInformation.pluginOrderId = orderId;
- newCopyInformation.orderId = incrementOrderId();
- copyRunningList << newCopyInformation;
- emit newMove(orderId,QStringList() << "file",stripSeparator(sources));
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("sources: ")+sources.join(QStringLiteral(";")));
+ PluginInterface_Listener *plugin = qobject_cast<PluginInterface_Listener *>(sender());
+ CopyRunning newCopyInformation;
+ newCopyInformation.listenInterface = plugin;
+ newCopyInformation.pluginOrderId = orderId;
+ newCopyInformation.orderId = incrementOrderId();
+ copyRunningList << newCopyInformation;
+ emit newMoveWithoutDestination(orderId,QStringList() << QStringLiteral("file"),stripSeparator(sources));
}
void CopyListener::newPluginMove(const quint32 &orderId,const QStringList &sources,const QString &destination)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"sources: "+sources.join(";")+", destination: "+destination);
- PluginInterface_Listener *plugin = qobject_cast<PluginInterface_Listener *>(sender());
- CopyRunning newCopyInformation;
- newCopyInformation.listenInterface = plugin;
- newCopyInformation.pluginOrderId = orderId;
- newCopyInformation.orderId = incrementOrderId();
- copyRunningList << newCopyInformation;
- emit newMove(orderId,QStringList() << "file",stripSeparator(sources),"file",destination);
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("sources: ")+sources.join(";")+QStringLiteral(", destination: ")+destination);
+ PluginInterface_Listener *plugin = qobject_cast<PluginInterface_Listener *>(sender());
+ CopyRunning newCopyInformation;
+ newCopyInformation.listenInterface = plugin;
+ newCopyInformation.pluginOrderId = orderId;
+ newCopyInformation.orderId = incrementOrderId();
+ copyRunningList << newCopyInformation;
+ emit newMove(orderId,QStringList() << QStringLiteral("file"),stripSeparator(sources),QStringLiteral("file"),destination);
}
quint32 CopyListener::incrementOrderId()
{
- do
- {
- nextOrderId++;
- if(nextOrderId>2000000)
- nextOrderId=0;
- } while(orderList.contains(nextOrderId));
- return nextOrderId;
+ do
+ {
+ nextOrderId++;
+ if(nextOrderId>2000000)
+ nextOrderId=0;
+ } while(orderList.contains(nextOrderId));
+ return nextOrderId;
}
void CopyListener::allPluginIsloaded()
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"with value: "+QString::number(pluginList.size()>0));
- sendState(true);
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("with value: ")+QString::number(pluginList.size()>0));
+ sendState(true);
+ reloadClientList();
+}
+
+void CopyListener::reloadClientList()
+{
+ if(!PluginsManager::pluginsManager->allPluginHaveBeenLoaded())
+ return;
+ QStringList clients;
+ int indexPlugin=0;
+ while(indexPlugin<pluginList.size())
+ {
+ if(pluginList.at(indexPlugin).listenInterface!=NULL)
+ {
+ clients << pluginList.at(indexPlugin).listenInterface->clientsList();
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("ask client to: ")+pluginList.at(indexPlugin).path);
+ }
+ indexPlugin++;
+ }
+ emit newClientList(clients);
}
void CopyListener::sendState(bool force)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("start, pluginList.size(): %1, force: %2").arg(pluginList.size()).arg(force));
- ListeningState current_state=NotListening;
- bool found_not_listen=false,found_listen=false,found_inWaitOfReply=false;
- int index=0;
- while(index<pluginList.size())
- {
- if(current_state==NotListening)
- {
- if(pluginList.at(index).state==SemiListening)
- current_state=SemiListening;
- else if(pluginList.at(index).state==NotListening)
- found_not_listen=true;
- else if(pluginList.at(index).state==FullListening)
- found_listen=true;
- }
- if(pluginList.at(index).inWaitOfReply)
- found_inWaitOfReply=true;
- index++;
- }
- if(current_state==NotListening)
- {
- if(found_not_listen && found_listen)
- current_state=SemiListening;
- else if(found_not_listen)
- current_state=NotListening;
- else if(FullListening)
- current_state=FullListening;
- else
- current_state=SemiListening;
- }
- bool have_plugin=pluginList.size()>0;
- if(force || current_state!=last_state || have_plugin!=last_have_plugin || found_inWaitOfReply!=last_inWaitOfReply)
- {
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("send listenerReady(%1,%2,%3)").arg(current_state).arg(have_plugin).arg(found_inWaitOfReply));
- emit listenerReady(current_state,have_plugin,found_inWaitOfReply);
- }
- else
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("Skip the signal sending"));
- last_state=current_state;
- last_have_plugin=have_plugin;
- last_inWaitOfReply=found_inWaitOfReply;
+ if(stopIt)
+ return;
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("start, pluginList.size(): %1, force: %2").arg(pluginList.size()).arg(force));
+ Ultracopier::ListeningState current_state=Ultracopier::NotListening;
+ bool found_not_listen=false,found_listen=false,found_inWaitOfReply=false;
+ int index=0;
+ while(index<pluginList.size())
+ {
+ if(current_state==Ultracopier::NotListening)
+ {
+ if(pluginList.at(index).state==Ultracopier::SemiListening)
+ current_state=Ultracopier::SemiListening;
+ else if(pluginList.at(index).state==Ultracopier::NotListening)
+ found_not_listen=true;
+ else if(pluginList.at(index).state==Ultracopier::FullListening)
+ found_listen=true;
+ }
+ if(pluginList.at(index).inWaitOfReply)
+ found_inWaitOfReply=true;
+ index++;
+ }
+ if(current_state==Ultracopier::NotListening)
+ {
+ if(found_not_listen && found_listen)
+ current_state=Ultracopier::SemiListening;
+ else if(found_not_listen)
+ current_state=Ultracopier::NotListening;
+ else if(!found_not_listen && found_listen)
+ current_state=Ultracopier::FullListening;
+ else
+ current_state=Ultracopier::SemiListening;
+ }
+ bool have_plugin=pluginList.size()>0;
+ if(force || current_state!=last_state || have_plugin!=last_have_plugin || found_inWaitOfReply!=last_inWaitOfReply)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("send listenerReady(%1,%2,%3)").arg(current_state).arg(have_plugin).arg(found_inWaitOfReply));
+ emit listenerReady(current_state,have_plugin,found_inWaitOfReply);
+ }
+ else
+ ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("Skip the signal sending"));
+ last_state=current_state;
+ last_have_plugin=have_plugin;
+ last_inWaitOfReply=found_inWaitOfReply;
}