summaryrefslogtreecommitdiff
path: root/Core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Core.cpp')
-rwxr-xr-x[-rw-r--r--]Core.cpp330
1 files changed, 257 insertions, 73 deletions
diff --git a/Core.cpp b/Core.cpp
index f27181b..a12ba32 100644..100755
--- a/Core.cpp
+++ b/Core.cpp
@@ -20,13 +20,27 @@ Core::Core(CopyEngineManager *copyEngineList)
//connect(&copyEngineList, SIGNAL(newCanDoOnlyCopy(bool)), this, SIGNAL(newCanDoOnlyCopy(bool)));
connect(themes, SIGNAL(theThemeNeedBeUnloaded()), this, SLOT(unloadInterface()));
connect(themes, SIGNAL(theThemeIsReloaded()), this, SLOT(loadInterface()));
- connect(&forUpateInformation, SIGNAL(timeout()), this, SLOT(periodiqueSync()));
+ connect(&forUpateInformation, SIGNAL(timeout()), this, SLOT(periodicSynchronization()));
+
+ qRegisterMetaType<QList<returnActionOnCopyList> >("QList<returnActionOnCopyList>");
+ qRegisterMetaType<QList<ProgressionItem> >("QList<ProgressionItem>");
+ qRegisterMetaType<QList<int> >("QList<int>");
+ qRegisterMetaType<QList<QUrl> >("QList<QUrl>");
+ qRegisterMetaType<EngineActionInProgress>("EngineActionInProgress");
+ qRegisterMetaType<CopyMode >("CopyMode");
+ qRegisterMetaType<QList<returnActionOnCopyList> >("QList<returnActionOnCopyList>");
+ qRegisterMetaType<QList<ProgressionItem> >("QList<ProgressionItem>");
}
void Core::newCopy(const quint32 &orderId,const QStringList &protocolsUsedForTheSources,const QStringList &sources)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
- openNewCopy(Copy,false,protocolsUsedForTheSources);
+ if(openNewCopyEngineInstance(Copy,false,protocolsUsedForTheSources)==-1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to get a copy engine instance");
+ QMessageBox::critical(NULL,tr("Error"),tr("Unable to get a copy engine instance"));
+ return;
+ }
copyList.last().orderId<<orderId;
copyList.last().engine->newCopy(sources);
copyList.last().interface->haveExternalOrder();
@@ -74,7 +88,12 @@ void Core::newCopy(const quint32 &orderId,const QStringList &protocolsUsedForThe
}
}
//else open new windows
- openNewCopy(Copy,false,protocolsUsedForTheSources,protocolsUsedForTheDestination);
+ if(openNewCopyEngineInstance(Copy,false,protocolsUsedForTheSources,protocolsUsedForTheDestination)==-1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to get a copy engine instance");
+ QMessageBox::critical(NULL,tr("Error"),tr("Unable to get a copy engine instance"));
+ return;
+ }
copyList.last().orderId<<orderId;
copyList.last().engine->newCopy(sources,destination);
copyList.last().interface->haveExternalOrder();
@@ -82,7 +101,12 @@ void Core::newCopy(const quint32 &orderId,const QStringList &protocolsUsedForThe
void Core::newMove(const quint32 &orderId,const QStringList &protocolsUsedForTheSources,const QStringList &sources)
{
- openNewCopy(Move,false,protocolsUsedForTheSources);
+ if(openNewCopyEngineInstance(Move,false,protocolsUsedForTheSources)==-1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to get a copy engine instance");
+ QMessageBox::critical(NULL,tr("Error"),tr("Unable to get a copy engine instance"));
+ return;
+ }
copyList.last().orderId<<orderId;
copyList.last().engine->newMove(sources);
copyList.last().interface->haveExternalOrder();
@@ -90,7 +114,7 @@ void Core::newMove(const quint32 &orderId,const QStringList &protocolsUsedForThe
void Core::newMove(const quint32 &orderId,const QStringList &protocolsUsedForTheSources,const QStringList &sources,const QString &protocolsUsedForTheDestination,const QString &destination)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start: "+sources.join(";")+", dest: "+destination);
//search to group the window
int GroupWindowWhen=options->getOptionValue("Ultracopier","GroupWindowWhen").toInt();
bool haveSameSource=false,haveSameDestination=false;
@@ -130,17 +154,27 @@ void Core::newMove(const quint32 &orderId,const QStringList &protocolsUsedForThe
}
}
//else open new windows
- openNewCopy(Move,false,protocolsUsedForTheSources,protocolsUsedForTheDestination);
+ if(openNewCopyEngineInstance(Move,false,protocolsUsedForTheSources,protocolsUsedForTheDestination)==-1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to get a copy engine instance");
+ QMessageBox::critical(NULL,tr("Error"),tr("Unable to get a copy engine instance"));
+ return;
+ }
copyList.last().orderId<<orderId;
copyList.last().engine->newMove(sources,destination);
copyList.last().interface->haveExternalOrder();
}
-/// \todo name to open the right copy engine
+/// \brief name to open the right copy engine
void Core::addWindowCopyMove(const CopyMode &mode,const QString &name)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start: "+name);
- openNewCopy(mode,false,name);
+ if(openNewCopyEngineInstance(mode,false,name)==-1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to get a copy engine instance");
+ QMessageBox::critical(NULL,tr("Error"),tr("Unable to get a copy engine instance"));
+ return;
+ }
ActionOnManualOpen ActionOnManualOpen_value=(ActionOnManualOpen)options->getOptionValue("Ultracopier","ActionOnManualOpen").toInt();
if(ActionOnManualOpen_value!=ActionOnManualOpen_Nothing)
{
@@ -151,11 +185,56 @@ void Core::addWindowCopyMove(const CopyMode &mode,const QString &name)
}
}
-/// \todo name to open the right copy engine
+/// \brief name to open the right copy engine
void Core::addWindowTransfer(const QString &name)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start"+name);
- openNewCopy(Copy,true,name);
+ if(openNewCopyEngineInstance(Copy,true,name)==-1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to get a copy engine instance");
+ QMessageBox::critical(NULL,tr("Error"),tr("Unable to get a copy engine instance"));
+ return;
+ }
+}
+
+/** new transfer list pased by the CLI */
+void Core::newTransferList(QString engine,QString mode,QString file)
+{
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("engine: %1, mode: %2, file: %3").arg(engine).arg(mode).arg(file));
+ if(mode=="Transfer")
+ {
+ if(openNewCopyEngineInstance(Copy,true,engine)==-1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to get a copy engine instance");
+ QMessageBox::critical(NULL,tr("Error"),tr("Unable to get a copy engine instance"));
+ return;
+ }
+ }
+ else if(mode=="Copy")
+ {
+ if(openNewCopyEngineInstance(Copy,false,engine)==-1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to get a copy engine instance");
+ QMessageBox::critical(NULL,tr("Error"),tr("Unable to get a copy engine instance"));
+ return;
+ }
+ }
+ else if(mode=="Move")
+ {
+ if(openNewCopyEngineInstance(Move,false,engine)==-1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to get a copy engine instance");
+ QMessageBox::critical(NULL,tr("Error"),tr("Unable to get a copy engine instance"));
+ return;
+ }
+ }
+ else
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"The argument for the mode is not understand");
+ QMessageBox::critical(NULL,tr("Error"),tr("The argument for the mode is not understand"));
+ return;
+ }
+ copyList.last().engine->newTransferList(file);
}
void Core::loadInterface()
@@ -222,20 +301,37 @@ int Core::incrementId()
return nextId;
}
-int Core::openNewCopy(const CopyMode &mode,const bool &ignoreMode,const QStringList &protocolsUsedForTheSources,const QString &protocolsUsedForTheDestination)
+/** open with specific source/destination
+\param move Copy or move
+\param ignoreMode if need ignore the mode
+\param protocolsUsedForTheSources protocols used for sources
+\param protocolsUsedForTheDestination protocols used for destination
+*/
+int Core::openNewCopyEngineInstance(const CopyMode &mode,const bool &ignoreMode,const QStringList &protocolsUsedForTheSources,const QString &protocolsUsedForTheDestination)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
CopyEngineManager::returnCopyEngine returnInformations=copyEngineList->getCopyEngine(mode,protocolsUsedForTheSources,protocolsUsedForTheDestination);
+ if(returnInformations.engine==NULL)
+ return -1;
return connectCopyEngine(mode,ignoreMode,returnInformations);
}
-int Core::openNewCopy(const CopyMode &mode,const bool &ignoreMode,const QString &name)
+/** open with specific copy engine
+\param move Copy or move
+\param ignoreMode if need ignore the mode
+\param protocolsUsedForTheSources protocols used for sources
+\param protocolsUsedForTheDestination protocols used for destination
+*/
+int Core::openNewCopyEngineInstance(const CopyMode &mode,const bool &ignoreMode,const QString &name)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start, mode: "+QString::number(mode)+", name: "+name);
CopyEngineManager::returnCopyEngine returnInformations=copyEngineList->getCopyEngine(mode,name);
+ if(returnInformations.engine==NULL)
+ return -1;
return connectCopyEngine(mode,ignoreMode,returnInformations);
}
+/** Connect the copy engine instance provided previously to the management */
int Core::connectCopyEngine(const CopyMode &mode,bool ignoreMode,const CopyEngineManager::returnCopyEngine &returnInformations)
{
if(returnInformations.canDoOnlyCopy)
@@ -260,7 +356,8 @@ int Core::connectCopyEngine(const CopyMode &mode,bool ignoreMode,const CopyEngin
newItem.baseTime=0;
newItem.numberOfFile=0;
newItem.numberOfTransferedFile=0;
- newItem.sizeToCopy=0;
+ newItem.currentProgression=0;
+ newItem.totalProgression=0;
newItem.action=Idle;
newItem.lastProgression=0;//store the real byte transfered, used in time remaining calculation
newItem.isPaused=false;
@@ -273,7 +370,10 @@ int Core::connectCopyEngine(const CopyMode &mode,bool ignoreMode,const CopyEngin
newItem.copyEngineIsSync=true;
if(!ignoreMode)
+ {
newItem.interface->forceCopyMode(mode);
+ newItem.engine->forceMode(mode);
+ }
if(copyList.size()==0)
forUpateInformation.start();
copyList << newItem;
@@ -281,8 +381,8 @@ int Core::connectCopyEngine(const CopyMode &mode,bool ignoreMode,const CopyEngin
connectInterfaceAndSync(copyList.count()-1);
return newItem.id;
}
- delete newItem.engine;
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Unable to load the interface, copy aborted");
+ delete newItem.engine;
QMessageBox::critical(NULL,tr("Error"),tr("Unable to load the interface, copy aborted"));
}
else
@@ -345,7 +445,7 @@ void Core::actionInProgess(const EngineActionInProgress &action)
}
}
//do sync
- periodiqueSync(index);
+ periodicSynchronization(index);
copyList[index].action=action;
if(copyList.at(index).interface!=NULL)
copyList.at(index).interface->actionInProgess(action);
@@ -408,6 +508,7 @@ void Core::isInPause(const bool &isPaused)
}
}
+/// \brief get the right copy instance (copy engine + interface), by signal emited from copy engine
int Core::indexCopySenderCopyEngine()
{
QObject * senderObject=sender();
@@ -430,6 +531,7 @@ int Core::indexCopySenderCopyEngine()
return -1;
}
+/// \brief get the right copy instance (copy engine + interface), by signal emited from interface
int Core::indexCopySenderInterface()
{
QObject * senderObject=sender();
@@ -473,16 +575,28 @@ void Core::connectEngine(const int &index)
disconnectEngine(index);
CopyInstance& currentCopyInstance=copyList[index];
- connect(currentCopyInstance.engine,SIGNAL(newFolderListing(QString)), this,SLOT(newFolderListing(QString)),Qt::QueuedConnection);//to check to change
- connect(currentCopyInstance.engine,SIGNAL(newCollisionAction(QString)), this,SLOT(newCollisionAction(QString)),Qt::QueuedConnection);
- connect(currentCopyInstance.engine,SIGNAL(newErrorAction(QString)), this,SLOT(newErrorAction(QString)),Qt::QueuedConnection);
- connect(currentCopyInstance.engine,SIGNAL(actionInProgess(EngineActionInProgress)), this,SLOT(actionInProgess(EngineActionInProgress)),Qt::QueuedConnection);
- connect(currentCopyInstance.engine,SIGNAL(isInPause(bool)), this,SLOT(isInPause(bool)),Qt::QueuedConnection);//to check to change
- connect(currentCopyInstance.engine,SIGNAL(cancelAll()), this,SLOT(copyInstanceCanceledByEngine()),Qt::QueuedConnection);
- connect(currentCopyInstance.engine,SIGNAL(error(QString,quint64,QDateTime,QString)), this,SLOT(error(QString,quint64,QDateTime,QString)),Qt::QueuedConnection);
- connect(currentCopyInstance.engine,SIGNAL(rmPath(QString)), this,SLOT(rmPath(QString)),Qt::QueuedConnection);
- connect(currentCopyInstance.engine,SIGNAL(mkPath(QString)), this,SLOT(mkPath(QString)),Qt::QueuedConnection);
- connect(currentCopyInstance.engine,SIGNAL(syncReady()), this,SLOT(syncReady()),Qt::QueuedConnection);
+ if(!connect(currentCopyInstance.engine,SIGNAL(newFolderListing(QString)), this,SLOT(newFolderListing(QString)),Qt::QueuedConnection))//to check to change
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the engine can not work correctly: %1: %2 for newFolderListing()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(newCollisionAction(QString)), this,SLOT(newCollisionAction(QString)),Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the engine can not work correctly: %1: %2 for newCollisionAction()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(newErrorAction(QString)), this,SLOT(newErrorAction(QString)),Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the engine can not work correctly: %1: %2 for newErrorAction()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(actionInProgess(EngineActionInProgress)), this,SLOT(actionInProgess(EngineActionInProgress)),Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the engine can not work correctly: %1: %2 for actionInProgess()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(isInPause(bool)), this,SLOT(isInPause(bool)),Qt::QueuedConnection))//to check to change
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the engine can not work correctly: %1: %2 for isInPause()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(cancelAll()), this,SLOT(copyInstanceCanceledByEngine()),Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the engine can not work correctly: %1: %2 for cancelAll()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(error(QString,quint64,QDateTime,QString)), this,SLOT(error(QString,quint64,QDateTime,QString)),Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the engine can not work correctly: %1: %2 for error()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(rmPath(QString)), this,SLOT(rmPath(QString)),Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the engine can not work correctly: %1: %2 for rmPath()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(mkPath(QString)), this,SLOT(mkPath(QString)),Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the engine can not work correctly: %1: %2 for mkPath()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(syncReady()), this,SLOT(syncReady()),Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the engine can not work correctly: %1: %2 for syncReady()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(canBeDeleted()), this,SLOT(deleteCopyEngine()),Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the engine can not work correctly: %1: %2 for syncReady()").arg(index).arg((quint64)sender()));
}
void Core::connectInterfaceAndSync(const int &index)
@@ -491,31 +605,55 @@ void Core::connectInterfaceAndSync(const int &index)
disconnectInterface(index);
CopyInstance& currentCopyInstance=copyList[index];
- connect(currentCopyInstance.interface,SIGNAL(pause()), currentCopyInstance.engine,SLOT(pause()));
- connect(currentCopyInstance.interface,SIGNAL(resume()), currentCopyInstance.engine,SLOT(resume()));
- connect(currentCopyInstance.interface,SIGNAL(skip(quint64)), currentCopyInstance.engine,SLOT(skip(quint64)));
- connect(currentCopyInstance.interface,SIGNAL(sendErrorAction(QString)), currentCopyInstance.engine,SLOT(setErrorAction(QString)));
- connect(currentCopyInstance.interface,SIGNAL(newSpeedLimitation(qint64)), currentCopyInstance.engine,SLOT(setSpeedLimitation(qint64)));
- connect(currentCopyInstance.interface,SIGNAL(sendCollisionAction(QString)), currentCopyInstance.engine,SLOT(setCollisionAction(QString)));
- connect(currentCopyInstance.interface,SIGNAL(userAddFolder(CopyMode)), currentCopyInstance.engine,SLOT(userAddFolder(CopyMode)));
- connect(currentCopyInstance.interface,SIGNAL(userAddFile(CopyMode)), currentCopyInstance.engine,SLOT(userAddFile(CopyMode)));
-
- connect(currentCopyInstance.interface,SIGNAL(removeItems(QList<int>)), currentCopyInstance.engine,SLOT(removeItems(QList<int>)));
- connect(currentCopyInstance.interface,SIGNAL(moveItemsOnTop(QList<int>)), currentCopyInstance.engine,SLOT(moveItemsOnTop(QList<int>)));
- connect(currentCopyInstance.interface,SIGNAL(moveItemsUp(QList<int>)), currentCopyInstance.engine,SLOT(moveItemsUp(QList<int>)));
- connect(currentCopyInstance.interface,SIGNAL(moveItemsDown(QList<int>)), currentCopyInstance.engine,SLOT(moveItemsDown(QList<int>)));
- connect(currentCopyInstance.interface,SIGNAL(moveItemsOnBottom(QList<int>)), currentCopyInstance.engine,SLOT(moveItemsOnBottom(QList<int>)));
- connect(currentCopyInstance.interface,SIGNAL(exportTransferList()), currentCopyInstance.engine,SLOT(exportTransferList()));
- connect(currentCopyInstance.interface,SIGNAL(importTransferList()), currentCopyInstance.engine,SLOT(importTransferList()));
-
- connect(currentCopyInstance.interface,SIGNAL(newSpeedLimitation(qint64)), this,SLOT(resetSpeedDetectedInterface()));
- connect(currentCopyInstance.interface,SIGNAL(resume()), this,SLOT(resetSpeedDetectedInterface()));
- connect(currentCopyInstance.interface,SIGNAL(cancel()), this,SLOT(copyInstanceCanceledByInterface()),Qt::QueuedConnection);
- connect(currentCopyInstance.interface,SIGNAL(urlDropped(QList<QUrl>)), this,SLOT(urlDropped(QList<QUrl>)),Qt::QueuedConnection);
- connect(currentCopyInstance.engine,SIGNAL(newActionOnList(QList<returnActionOnCopyList>)),this,SLOT(getActionOnList(QList<returnActionOnCopyList>)), Qt::QueuedConnection);
-
- connect(currentCopyInstance.engine,SIGNAL(pushFileProgression(QList<ProgressionItem>)), currentCopyInstance.interface,SLOT(setFileProgression(QList<ProgressionItem>)), Qt::QueuedConnection);
- connect(currentCopyInstance.engine,SIGNAL(pushGeneralProgression(quint64,quint64)), currentCopyInstance.interface,SLOT(setGeneralProgression(quint64,quint64)), Qt::QueuedConnection);
+ if(!connect(currentCopyInstance.interface,SIGNAL(pause()), currentCopyInstance.engine,SLOT(pause())))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for pause()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(resume()), currentCopyInstance.engine,SLOT(resume())))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for resume()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(skip(quint64)), currentCopyInstance.engine,SLOT(skip(quint64))))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for skip()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(sendErrorAction(QString)), currentCopyInstance.engine,SLOT(setErrorAction(QString))))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for sendErrorAction()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(newSpeedLimitation(qint64)), currentCopyInstance.engine,SLOT(setSpeedLimitation(qint64))))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for newSpeedLimitation()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(sendCollisionAction(QString)), currentCopyInstance.engine,SLOT(setCollisionAction(QString))))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for sendCollisionAction()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(userAddFolder(CopyMode)), currentCopyInstance.engine,SLOT(userAddFolder(CopyMode))))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for userAddFolder()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(userAddFile(CopyMode)), currentCopyInstance.engine,SLOT(userAddFile(CopyMode))))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for userAddFile()").arg(index).arg((quint64)sender()));
+
+ if(!connect(currentCopyInstance.interface,SIGNAL(removeItems(QList<int>)), currentCopyInstance.engine,SLOT(removeItems(QList<int>))))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for removeItems()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(moveItemsOnTop(QList<int>)), currentCopyInstance.engine,SLOT(moveItemsOnTop(QList<int>))))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for moveItemsOnTop()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(moveItemsUp(QList<int>)), currentCopyInstance.engine,SLOT(moveItemsUp(QList<int>))))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for moveItemsUp()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(moveItemsDown(QList<int>)), currentCopyInstance.engine,SLOT(moveItemsDown(QList<int>))))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for moveItemsDown()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(moveItemsOnBottom(QList<int>)), currentCopyInstance.engine,SLOT(moveItemsOnBottom(QList<int>))))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for moveItemsOnBottom()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(exportTransferList()), currentCopyInstance.engine,SLOT(exportTransferList())))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for exportTransferList()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(importTransferList()), currentCopyInstance.engine,SLOT(importTransferList())))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for importTransferList()").arg(index).arg((quint64)sender()));
+
+ if(!connect(currentCopyInstance.interface,SIGNAL(newSpeedLimitation(qint64)), this,SLOT(resetSpeedDetectedInterface())))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for newSpeedLimitation()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(resume()), this,SLOT(resetSpeedDetectedInterface())))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for resume()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(cancel()), this,SLOT(copyInstanceCanceledByInterface()),Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for cancel()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.interface,SIGNAL(urlDropped(QList<QUrl>)), this,SLOT(urlDropped(QList<QUrl>)),Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for urlDropped()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(newActionOnList(QList<returnActionOnCopyList>)),this,SLOT(getActionOnList(QList<returnActionOnCopyList>)), Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for newActionOnList()").arg(index).arg((quint64)sender()));
+
+ if(!connect(currentCopyInstance.engine,SIGNAL(pushFileProgression(QList<ProgressionItem>)), currentCopyInstance.interface,SLOT(setFileProgression(QList<ProgressionItem>)), Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for pushFileProgression()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(pushGeneralProgression(quint64,quint64)), currentCopyInstance.interface,SLOT(setGeneralProgression(quint64,quint64)), Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for pushGeneralProgression()").arg(index).arg((quint64)sender()));
+ if(!connect(currentCopyInstance.engine,SIGNAL(pushGeneralProgression(quint64,quint64)), this,SLOT(pushGeneralProgression(quint64,quint64)), Qt::QueuedConnection))
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("error at connect, the interface can not work correctly: %1: %2 for pushGeneralProgression() for this").arg(index).arg((quint64)sender()));
currentCopyInstance.interface->setSpeedLimitation(currentCopyInstance.engine->getSpeedLimitation());
currentCopyInstance.interface->setErrorAction(currentCopyInstance.engine->getErrorAction());
@@ -529,19 +667,21 @@ void Core::connectInterfaceAndSync(const int &index)
QWidget *tempWidget=currentCopyInstance.interface->getOptionsEngineWidget();
if(tempWidget!=NULL)
currentCopyInstance.interface->getOptionsEngineEnabled(currentCopyInstance.engine->getOptionsEngine(tempWidget));
+ //important, to have the modal dialog
+ currentCopyInstance.engine->setInterfacePointer(currentCopyInstance.interface);
//put entry into the interface
currentCopyInstance.engine->syncTransferList();
//force the updating, without wait the timer
- periodiqueSync(index);
+ periodicSynchronization(index);
}
void Core::disconnectEngine(const int &index)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("start with index: %1").arg(index));
- CopyInstance& currentCopyInstance=copyList[index];
- disconnect(currentCopyInstance.engine,SIGNAL(newFolderListing(QString)), this,SLOT(newFolderListing(QString)));//to check to change
+// CopyInstance& currentCopyInstance=copyList[index];
+/* disconnect(currentCopyInstance.engine,SIGNAL(newFolderListing(QString)), this,SLOT(newFolderListing(QString)));//to check to change
disconnect(currentCopyInstance.engine,SIGNAL(newCollisionAction(QString)), this,SLOT(newCollisionAction(QString)));
disconnect(currentCopyInstance.engine,SIGNAL(newErrorAction(QString)), this,SLOT(newErrorAction(QString)));
disconnect(currentCopyInstance.engine,SIGNAL(actionInProgess(EngineActionInProgress)), this,SLOT(actionInProgess(EngineActionInProgress)));
@@ -549,14 +689,15 @@ void Core::disconnectEngine(const int &index)
disconnect(currentCopyInstance.engine,SIGNAL(cancelAll()), this,SLOT(copyInstanceCanceledByEngine()));
disconnect(currentCopyInstance.engine,SIGNAL(error(QString,quint64,QDateTime,QString)), this,SLOT(error(QString,quint64,QDateTime,QString)));
disconnect(currentCopyInstance.engine,SIGNAL(rmPath(QString)), this,SLOT(rmPath(QString)));
- disconnect(currentCopyInstance.engine,SIGNAL(mkPath(QString)), this,SLOT(mkPath(QString)));
+ disconnect(currentCopyInstance.engine,SIGNAL(mkPath(QString)), this,SLOT(mkPath(QString)));*/
}
void Core::disconnectInterface(const int &index)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("start with index: %1").arg(index));
- CopyInstance& currentCopyInstance=copyList[index];
+ Q_UNUSED(index);
+/* CopyInstance& currentCopyInstance=copyList[index];
disconnect(currentCopyInstance.interface,SIGNAL(pause()), currentCopyInstance.engine,SLOT(pause()));
disconnect(currentCopyInstance.interface,SIGNAL(resume()), currentCopyInstance.engine,SLOT(resume()));
disconnect(currentCopyInstance.interface,SIGNAL(skip(quint64)), currentCopyInstance.engine,SLOT(skip(quint64)));
@@ -579,22 +720,22 @@ void Core::disconnectInterface(const int &index)
disconnect(currentCopyInstance.engine,SIGNAL(newActionOnList(QList<returnActionOnCopyList>)), currentCopyInstance.interface,SLOT(getActionOnList(QList<returnActionOnCopyList>)));
disconnect(currentCopyInstance.engine,SIGNAL(pushFileProgression(QList<ProgressionItem>)), currentCopyInstance.interface,SLOT(setFileProgression(QList<ProgressionItem>)));
- disconnect(currentCopyInstance.engine,SIGNAL(pushGeneralProgression(quint64,quint64)), currentCopyInstance.interface,SLOT(setGeneralProgression(quint64,quint64)));
+ disconnect(currentCopyInstance.engine,SIGNAL(pushGeneralProgression(quint64,quint64)), currentCopyInstance.interface,SLOT(setGeneralProgression(quint64,quint64)));*/
}
-void Core::periodiqueSync()
+void Core::periodicSynchronization()
{
index_sub_loop=0;
loop_size=copyList.size();
while(index_sub_loop<loop_size)
{
if(copyList.at(index_sub_loop).action==Copying || copyList.at(index_sub_loop).action==CopyingAndListing)
- periodiqueSync(index_sub_loop);
+ periodicSynchronization(index_sub_loop);
index_sub_loop++;
}
}
-void Core::periodiqueSync(const int &index)
+void Core::periodicSynchronization(const int &index)
{
CopyInstance& currentCopyInstance=copyList[index];
if(currentCopyInstance.engine==NULL || currentCopyInstance.interface==NULL)
@@ -607,24 +748,27 @@ void Core::periodiqueSync(const int &index)
if(!currentCopyInstance.isPaused)
{
//calcul the last difference of the transfere
- quint64 realByteTransfered=currentCopyInstance.engine->realByteTransfered();
- quint64 diffCopiedSize=0;
+ realByteTransfered=currentCopyInstance.engine->realByteTransfered();
+ diffCopiedSize=0;
if(realByteTransfered>=currentCopyInstance.lastProgression)
diffCopiedSize=realByteTransfered-currentCopyInstance.lastProgression;
currentCopyInstance.lastProgression=realByteTransfered;
- //do the remaining time calculation
- //byte per ms: lastProgression/(baseTime+currentCopyInstance.runningTime.elapsed()
- //currentCopyInstance.lastProgression
- if(currentCopyInstance.lastProgression==0)
+
+ // algo 1:
+ // ((double)currentProgression)/totalProgression -> example: done 80% -> 0.8
+ // baseTime+runningTime -> example: done into 80s, remaining time: 80/0.8-80=80*(1/0.8-1)=20s
+ // algo 2 (not used):
+ // remaining byte/current speed
+
+ transferAddedTime=currentCopyInstance.baseTime+currentCopyInstance.runningTime.elapsed();
+
+ //remaining time: (total byte - lastProgression)/byte per ms since the start
+ if(currentCopyInstance.totalProgression==0 || currentCopyInstance.currentProgression==0)
currentCopyInstance.interface->remainingTime(-1);
else
- currentCopyInstance.interface->remainingTime(
- (
- (double)(realByteTransfered)
- *(currentCopyInstance.baseTime+currentCopyInstance.runningTime.elapsed())
- /(currentCopyInstance.lastProgression)
- )/1000
- );
+ currentCopyInstance.interface->remainingTime(transferAddedTime*((double)currentCopyInstance.totalProgression/(double)currentCopyInstance.currentProgression-1)/1000);
+
+ //do the speed calculation
if(lastProgressionTime.isNull())
lastProgressionTime.start();
else
@@ -656,6 +800,7 @@ void Core::periodiqueSync(const int &index)
}
}
+/// \brief the copy engine have canceled the transfer
void Core::copyInstanceCanceledByEngine()
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
@@ -666,6 +811,7 @@ void Core::copyInstanceCanceledByEngine()
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"unable to locate the copy engine sender");
}
+/// \brief the interface have canceled the transfer
void Core::copyInstanceCanceledByInterface()
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
@@ -676,6 +822,7 @@ void Core::copyInstanceCanceledByInterface()
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"unable to locate the copy engine sender");
}
+/// \brief the transfer have been canceled
void Core::copyInstanceCanceledByIndex(const int &index)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start, remove with the index: "+QString::number(index));
@@ -684,7 +831,7 @@ void Core::copyInstanceCanceledByIndex(const int &index)
CopyInstance& currentCopyInstance=copyList[index];
currentCopyInstance.engine->cancel();
delete currentCopyInstance.nextConditionalSync;
- delete currentCopyInstance.engine;
+ currentCopyInstance.engine->cancel();
delete currentCopyInstance.interface;
index_sub_loop=0;
loop_size=currentCopyInstance.orderId.size();
@@ -700,6 +847,28 @@ void Core::copyInstanceCanceledByIndex(const int &index)
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"copyList.size(): "+QString::number(copyList.size()));
}
+/// \brief only when the copy engine say it's ready to delete them self, it call this
+void Core::deleteCopyEngine()
+{
+ QObject * senderObject=sender();
+ if(senderObject==NULL)
+ {
+ //QMessageBox::critical(NULL,tr("Internal error"),tr("A communication error occured between the interface and the copy plugin. Please report this bug."));
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Qt sender() NULL");
+ return;
+ }
+ PluginInterface_CopyEngine * copyEngine = static_cast<PluginInterface_CopyEngine *>(senderObject);
+ if(copyEngine==NULL)
+ {
+ //QMessageBox::critical(NULL,tr("Internal error"),tr("A communication error occured between the interface and the copy plugin. Please report this bug."));
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"Qt sender() NULL");
+ return;
+ }
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start, delete the copy engine");
+ delete copyEngine;
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"stop, delete the copy engine");
+}
+
//error occurred
void Core::error(const QString &path,const quint64 &size,const QDateTime &mtime,const QString &error)
{
@@ -725,6 +894,7 @@ void Core::mkPath(const QString &path)
log.mkPath(path);
}
+/// \brief to rsync after a new interface connection
void Core::syncReady()
{
int index=indexCopySenderCopyEngine();
@@ -736,6 +906,7 @@ void Core::syncReady()
void Core::getActionOnList(const QList<returnActionOnCopyList> & actionList)
{
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
int index=indexCopySenderCopyEngine();
if(index!=-1)
{
@@ -746,6 +917,19 @@ void Core::getActionOnList(const QList<returnActionOnCopyList> & actionList)
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"unable to locate the copy engine sender");
}
+void Core::pushGeneralProgression(const quint64 &current,const quint64 &total)
+{
+ int index=indexCopySenderCopyEngine();
+ if(index!=-1)
+ {
+ copyList[index].currentProgression=current;
+ copyList[index].totalProgression=total;
+ }
+ else
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"unable to locate the copy engine sender");
+}
+
+/// \brief used to drag and drop files
void Core::urlDropped(const QList<QUrl> &urls)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");