summaryrefslogtreecommitdiff
path: root/plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2013-03-21 11:01:59 +0100
committerThomas Preud'homme <robotux@celest.fr>2013-03-21 11:01:59 +0100
commite297dbd8052ef4e66f069e2dd1865ae7fa8af28e (patch)
tree342fea0a2f6f33b8b62dad2d1729f8209da1a1ba /plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp
parent8f9f382e1c97cab2e72e97495650c73ac4b97314 (diff)
Imported Upstream version 0.3.1.0
Diffstat (limited to 'plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp')
-rwxr-xr-x[-rw-r--r--]plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp490
1 files changed, 350 insertions, 140 deletions
diff --git a/plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp b/plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp
index 7f022d8..9856c3c 100644..100755
--- a/plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp
+++ b/plugins/CopyEngine/Ultracopier-0.3/ListThread.cpp
@@ -1,22 +1,13 @@
#include "ListThread.h"
-/// \todo do pushed or instant mount point (setDrive, ...)
-/// \todo semaphore to prevent dual mkpath
-/// \todo repair the mkpath, to use mkpath class before file transfer to have the folder
-/// \todo do QThread( parent )
-/** \todo when overwrite with large inode operation, it not start specificly the first in the list
- When that's is finish, send start file at real transfer start, not inode operation start **/
-/** \todo group setCollisionAction(FileExistsAction alwaysDoThisActionForFileExists) and setAlwaysFileExistsAction(FileExistsAction alwaysDoThisActionForFileExists)
- and check if I can choose case by case if I wish overwrite, skip, ... */
-/// \todo move directly the folder when it's needed
-/// \todo connect folder error of mkpath and rmpath class
-
ListThread::ListThread(FacilityInterface * facilityInterface)
{
qRegisterMetaType<DebugLevel>("DebugLevel");
qRegisterMetaType<ItemOfCopyList>("ItemOfCopyList");
qRegisterMetaType<QFileInfo>("QFileInfo");
qRegisterMetaType<CopyMode>("CopyMode");
+ qRegisterMetaType<QList<Filters_rules> >("QList<Filters_rules>");
+ qRegisterMetaType<TransferStat>("TransferStat");
moveToThread(this);
start(HighPriority);
@@ -39,7 +30,14 @@ ListThread::ListThread(FacilityInterface * facilityInterface)
doRightTransfer = false;
keepDate = false;
blockSize = 1024;
+ osBufferLimit = 512;
alwaysDoThisActionForFileExists = FileExists_NotSet;
+ doChecksum = false;
+ checksumIgnoreIfImpossible = true;
+ checksumOnlyOnError = true;
+ osBuffer = false;
+ osBufferLimited = false;
+ forcedMode = false;
#if ! defined (Q_CC_GNU)
ui->keepDate->setEnabled(false);
@@ -49,8 +47,6 @@ ListThread::ListThread(FacilityInterface * facilityInterface)
connect(&timerUpdateDebugDialog,SIGNAL(timeout()),this,SLOT(timedUpdateDebugDialog()));
timerUpdateDebugDialog.start(ULTRACOPIER_PLUGIN_DEBUG_WINDOW_TIMER);
#endif
- connect(&timerActionDone,SIGNAL(timeout()), this,SLOT(sendActionDone()));
- connect(&timerProgression,SIGNAL(timeout()), this,SLOT(sendProgression()));
connect(this, SIGNAL(tryCancel()), this,SLOT(cancel()), Qt::QueuedConnection);
connect(this, SIGNAL(askNewTransferThread()), this,SLOT(createTransferThread()), Qt::QueuedConnection);
connect(&mkPathQueue, SIGNAL(firstFolderFinish()), this,SLOT(mkPathFirstFolderFinish()), Qt::QueuedConnection);
@@ -65,16 +61,13 @@ ListThread::ListThread(FacilityInterface * facilityInterface)
emit askNewTransferThread();
mkpathTransfer.release();
- timerActionDone.setSingleShot(true);
- timerActionDone.setInterval(ULTRACOPIER_PLUGIN_TIME_UPDATE_TRASNFER_LIST);
- timerProgression.setSingleShot(true);
- timerProgression.setInterval(ULTRACOPIER_PLUGIN_TIME_UPDATE_PROGRESSION);
}
ListThread::~ListThread()
{
emit tryCancel();
waitCancel.acquire();
+ quit();
wait();
}
@@ -92,7 +85,7 @@ void ListThread::transferInodeIsClosed()
#ifdef ULTRACOPIER_PLUGIN_DEBUG
int countLocalParse=0;
#endif
- if(temp_transfer_thread->getStat()!=TransferThread::Idle)
+ if(temp_transfer_thread->getStat()!=TransferStat_Idle)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("transfer thread not idle!"));
return;
@@ -113,8 +106,7 @@ void ListThread::transferInodeIsClosed()
actionToDoListTransfer.removeAt(int_for_internal_loop);
if(actionToDoListTransfer.size()==0 && actionToDoListInode.size()==0 && actionToDoListInode_afterTheTransfer.size()==0)
updateTheStatus();
- /// \todo add the oversize to all size here
- bytesTransfered+=temp_transfer_thread->transferSize;
+
temp_transfer_thread->transferId=0;
temp_transfer_thread->transferSize=0;
#ifdef ULTRACOPIER_PLUGIN_DEBUG
@@ -157,6 +149,17 @@ void ListThread::transferIsFinished()
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("transfer thread not located!"));
return;
}
+
+ //add the current size of file, to general size because it's finish
+ copiedSize=temp_transfer_thread->copiedSize();
+ if(copiedSize>(qint64)temp_transfer_thread->transferSize)
+ {
+ oversize=copiedSize-temp_transfer_thread->transferSize;
+ bytesToTransfer+=oversize;
+ bytesTransfered+=oversize;
+ }
+ bytesTransfered+=temp_transfer_thread->transferSize;
+
// emit newTransferStop(temp_transfer_thread->transferId);
numberOfTranferRuning--;
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start transferIsFinished(), numberOfTranferRuning: "+QString::number(numberOfTranferRuning));
@@ -178,47 +181,37 @@ void ListThread::transferPutAtBottom()
#ifdef ULTRACOPIER_PLUGIN_DEBUG
int countLocalParse=0;
#endif
- int index=0;
- loop_sub_size_transfer_thread_search=transferThreadList.size();
- while(index<loop_sub_size_transfer_thread_search)
+ int indexAction=0;
+ while(indexAction<actionToDoListTransfer.size())
{
- if(transferThreadList.at(index)==transfer)
+ if(actionToDoListTransfer.at(indexAction).id==transfer->transferId)
{
- int indexAction=0;
- while(indexAction<actionToDoListTransfer.size())
- {
- if(actionToDoListTransfer.at(indexAction).id==transferThreadList.at(index)->transferId)
- {
- //push for interface at the end
- returnActionOnCopyList newAction;
- newAction.type=MoveItem;
- newAction.addAction.id=transferThreadList.at(index)->transferId;
- newAction.userAction.position=actionToDoListTransfer.size()-1;
- actionDone << newAction;
- //do the wait stat
- actionToDoListTransfer[index].isRunning=false;
- //move at the end
- actionToDoListTransfer.move(indexAction,actionToDoListTransfer.size()-1);
- //reset the thread list stat
- transferThreadList[index]->transferId=0;
- transferThreadList[index]->transferSize=0;
- #ifdef ULTRACOPIER_PLUGIN_DEBUG
- countLocalParse++;
- #endif
- isFound=true;
- break;
- }
- indexAction++;
- }
- if(!isFound)
- {
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("unable to found item into the todo list, id: %1, index: %2").arg(transferThreadList.at(index)->transferId).arg(index));
- transferThreadList[index]->transferId=0;
- transferThreadList[index]->transferSize=0;
- }
+ //push for interface at the end
+ returnActionOnCopyList newAction;
+ newAction.type=MoveItem;
+ newAction.addAction.id=transfer->transferId;
+ newAction.userAction.position=actionToDoListTransfer.size()-1;
+ actionDone << newAction;
+ //do the wait stat
+ actionToDoListTransfer[indexAction].isRunning=false;
+ //move at the end
+ actionToDoListTransfer.move(indexAction,actionToDoListTransfer.size()-1);
+ //reset the thread list stat
+ transfer->transferId=0;
+ transfer->transferSize=0;
+ #ifdef ULTRACOPIER_PLUGIN_DEBUG
+ countLocalParse++;
+ #endif
+ isFound=true;
break;
}
- index++;
+ indexAction++;
+ }
+ if(!isFound)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("unable to found item into the todo list, id: %1, index: %2").arg(transfer->transferId));
+ transfer->transferId=0;
+ transfer->transferSize=0;
}
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("countLocalParse: %1").arg(countLocalParse));
#ifdef ULTRACOPIER_PLUGIN_DEBUG
@@ -338,9 +331,12 @@ scanFileOrFolder * ListThread::newScanThread(CopyMode mode)
connect(scanFileOrFolderThreadsPool.last(),SIGNAL(errorOnFolder(QFileInfo,QString)), this,SLOT(errorOnFolder(QFileInfo,QString)), Qt::QueuedConnection);
connect(scanFileOrFolderThreadsPool.last(),SIGNAL(folderAlreadyExists(QFileInfo,QFileInfo,bool)), this,SLOT(folderAlreadyExists(QFileInfo,QFileInfo,bool)), Qt::QueuedConnection);
+
+ scanFileOrFolderThreadsPool.last()->setFilters(include,exclude);
scanFileOrFolderThreadsPool.last()->setCheckDestinationFolderExists(checkDestinationFolderExists && alwaysDoThisActionForFolderExists!=FolderExists_Merge);
if(scanFileOrFolderThreadsPool.size()==1)
updateTheStatus();
+ scanFileOrFolderThreadsPool.last()->setRenamingRules(firstRenamingRule,otherRenamingRule);
return scanFileOrFolderThreadsPool.last();
}
@@ -349,31 +345,16 @@ void ListThread::scanThreadHaveFinish(bool skipFirstRemove)
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"listing thread have finish, skipFirstRemove: "+QString::number(skipFirstRemove));
if(!skipFirstRemove)
{
- QObject * senderThread = sender();
+ scanFileOrFolder * senderThread = qobject_cast<scanFileOrFolder *>(QObject::sender());
if(senderThread==NULL)
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"sender pointer null (plugin copy engine)");
else
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start the next thread, scanFileOrFolderThreadsPool.size(): "+QString::number(scanFileOrFolderThreadsPool.size()));
- bool isFound=false;
- int index=0;
- while(index<scanFileOrFolderThreadsPool.size())
- {
- if(senderThread==scanFileOrFolderThreadsPool.at(index))
- {
- if(index!=0)
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"scanFileOrFolderThread is not the first (plugin copy engine)");
- delete scanFileOrFolderThreadsPool.at(index);
- scanFileOrFolderThreadsPool.removeAt(index);
- if(scanFileOrFolderThreadsPool.size()==0)
- updateTheStatus();
- isFound=true;
- break;
- }
- index++;
- }
- if(!isFound)
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"sender pointer not found (plugin copy engine)");
+ delete senderThread;
+ scanFileOrFolderThreadsPool.removeOne(senderThread);
+ if(scanFileOrFolderThreadsPool.size()==0)
+ updateTheStatus();
}
}
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start the next thread, scanFileOrFolderThreadsPool.size(): "+QString::number(scanFileOrFolderThreadsPool.size()));
@@ -407,7 +388,6 @@ void ListThread::scanThreadHaveFinish(bool skipFirstRemove)
void ListThread::startGeneralTransfer()
{
doNewActions_inode_manipulation();
- timerProgression.start();
}
// -> add thread safe, by Qt::BlockingQueuedConnection
@@ -512,6 +492,79 @@ ItemOfCopyList ListThread::getReturnItemOfCopyListToCopyEngine()
return returnItemOfCopyListToCopyEngine;
}
+void ListThread::set_doChecksum(bool doChecksum)
+{
+ this->doChecksum=doChecksum;
+ int index=0;
+ loop_sub_size_transfer_thread_search=transferThreadList.size();
+ while(index<loop_sub_size_transfer_thread_search)
+ {
+ transferThreadList.at(index)->set_doChecksum(doChecksum);
+ index++;
+ }
+}
+
+void ListThread::set_checksumIgnoreIfImpossible(bool checksumIgnoreIfImpossible)
+{
+ this->checksumIgnoreIfImpossible=checksumIgnoreIfImpossible;
+ int index=0;
+ loop_sub_size_transfer_thread_search=transferThreadList.size();
+ while(index<loop_sub_size_transfer_thread_search)
+ {
+ transferThreadList.at(index)->set_checksumIgnoreIfImpossible(checksumIgnoreIfImpossible);
+ index++;
+ }
+}
+
+void ListThread::set_checksumOnlyOnError(bool checksumOnlyOnError)
+{
+ this->checksumOnlyOnError=checksumOnlyOnError;
+ int index=0;
+ loop_sub_size_transfer_thread_search=transferThreadList.size();
+ while(index<loop_sub_size_transfer_thread_search)
+ {
+ transferThreadList.at(index)->set_checksumOnlyOnError(checksumOnlyOnError);
+ index++;
+ }
+}
+
+void ListThread::set_osBuffer(bool osBuffer)
+{
+ this->osBuffer=osBuffer;
+ int index=0;
+ loop_sub_size_transfer_thread_search=transferThreadList.size();
+ while(index<loop_sub_size_transfer_thread_search)
+ {
+ transferThreadList.at(index)->set_osBuffer(osBuffer);
+ index++;
+ }
+}
+
+void ListThread::set_osBufferLimited(bool osBufferLimited)
+{
+ this->osBufferLimited=osBufferLimited;
+ int index=0;
+ loop_sub_size_transfer_thread_search=transferThreadList.size();
+ while(index<loop_sub_size_transfer_thread_search)
+ {
+ transferThreadList.at(index)->set_osBufferLimited(osBufferLimited);
+ index++;
+ }
+}
+
+void ListThread::realByteTransfered()
+{
+ quint64 totalRealByteTransfered=0;
+ int index=0;
+ loop_sub_size_transfer_thread_search=transferThreadList.size();
+ while(index<loop_sub_size_transfer_thread_search)
+ {
+ totalRealByteTransfered+=transferThreadList.at(index)->realByteTransfered();
+ index++;
+ }
+ emit send_realBytesTransfered(totalRealByteTransfered);
+}
+
void ListThread::pause()
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
@@ -603,7 +656,6 @@ void ListThread::cancel()
return;
}
stopIt=true;
- disconnect(this);
int index=0;
loop_size=transferThreadList.size();
while(index<loop_size)
@@ -624,6 +676,7 @@ void ListThread::cancel()
}
quit();
waitCancel.release();
+ emit canBeDeleted();
}
//speed limitation
@@ -634,7 +687,7 @@ qint64 ListThread::getSpeedLimitation()
bool ListThread::setSpeedLimitation(const qint64 &speedLimitation)
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"maxSpeed: "+QString::number(maxSpeed));
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"maxSpeed: "+QString::number(speedLimitation));
maxSpeed=speedLimitation;
int_for_loop=0;
loop_size=transferThreadList.size();
@@ -713,11 +766,10 @@ void ListThread::sendActionDone()
{
if(actionDone.size()>0)
{
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
emit newActionOnList(actionDone);
actionDone.clear();
}
- if(actionToDoListTransfer.size()>0)
- timerActionDone.start();
}
//send progression
@@ -725,38 +777,48 @@ void ListThread::sendProgression()
{
if(actionToDoListTransfer.size()==0)
return;
- qint64 copiedSize,totalSize,localOverSize;
- QList<ProgressionItem> progressionList;
- TransferThread *thread;
oversize=0;
currentProgression=0;
int_for_loop=0;
loop_size=transferThreadList.size();
while(int_for_loop<loop_size)
{
- thread=transferThreadList.at(int_for_loop);
- if(thread->getStat()==TransferThread::Transfer)
+ temp_transfer_thread=transferThreadList.at(int_for_loop);
+ if(temp_transfer_thread->getStat()==TransferStat_Transfer || temp_transfer_thread->getStat()==TransferStat_Checksum)
{
- copiedSize=thread->copiedSize();
+ copiedSize=temp_transfer_thread->copiedSize();
+
+ //for the general progression
currentProgression+=copiedSize;
- if(copiedSize>(qint64)thread->transferSize)
- localOverSize=copiedSize-thread->transferSize;
- totalSize=thread->transferSize+localOverSize;
- ProgressionItem tempItem;
- tempItem.current=copiedSize;
- tempItem.id=thread->transferId;
+
+ //the oversize (when the file is bigger after/during the copy then what was during the listing)
+ if(copiedSize>(qint64)temp_transfer_thread->transferSize)
+ localOverSize=copiedSize-temp_transfer_thread->transferSize;
+ else
+ localOverSize=0;
+
+ //the current size copied
+ totalSize=temp_transfer_thread->transferSize+localOverSize;
+ if(temp_transfer_thread->getStat()==TransferStat_Checksum)
+ tempItem.current=temp_transfer_thread->realByteTransfered();
+ else
+ tempItem.current=copiedSize;
+ tempItem.id=temp_transfer_thread->transferId;
tempItem.total=totalSize;
progressionList << tempItem;
+
+ //add the oversize to the general progression
oversize+=localOverSize;
}
int_for_loop++;
}
emit pushFileProgression(progressionList);
+ progressionList.clear();
emit pushGeneralProgression(bytesTransfered+currentProgression,bytesToTransfer+oversize);
- timerProgression.start();
+ realByteTransfered();
}
-//send the progression
+//send the progression, after full reset of the interface (then all is empty)
void ListThread::syncTransferList_internal()
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
@@ -770,7 +832,7 @@ void ListThread::syncTransferList_internal()
for(int_for_loop=0; int_for_loop<loop_size; ++int_for_loop) {
const actionToDoTransfer &item=actionToDoListTransfer.at(int_for_loop);
returnActionOnCopyList newAction;
- newAction.type = AddingItem;
+ newAction.type = PreOperation;
newAction.addAction.id = item.id;
newAction.addAction.sourceFullPath = item.source.absoluteFilePath();
newAction.addAction.sourceFileName = item.source.fileName();
@@ -779,6 +841,7 @@ void ListThread::syncTransferList_internal()
newAction.addAction.size = item.size;
newAction.addAction.mode = item.mode;
actionDone << newAction;
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("id: %1, size: %2, name: %3, size2: %4").arg(item.id).arg(item.size).arg(item.source.absoluteFilePath()).arg(newAction.addAction.size));
if(item.isRunning)
{
for(int_for_internal_loop=0; int_for_internal_loop<loop_sub_size; ++int_for_internal_loop) {
@@ -793,15 +856,15 @@ void ListThread::syncTransferList_internal()
newAction.addAction.size = item.size;
newAction.addAction.mode = item.mode;
actionDone << newAction;
- if(transferThread->getStat()!=TransferThread::PreOperation)
+ if(transferThread->getStat()!=TransferStat_PreOperation)
{
returnActionOnCopyList newAction;
switch(transferThread->getStat())
{
- case TransferThread::Transfer:
+ case TransferStat_Transfer:
newAction.type=Transfer;
break;
- case TransferThread::PostTransfer:
+ case TransferStat_PostTransfer:
newAction.type=PostOperation;
break;
default:
@@ -818,9 +881,6 @@ void ListThread::syncTransferList_internal()
//add file transfer to do
quint64 ListThread::addToTransfer(const QFileInfo& source,const QFileInfo& destination,const CopyMode& mode)
{
- //ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"source: "+source.absoluteFilePath()+", destination: "+destination.absoluteFilePath());
- if(actionToDoListTransfer.size()==0)
- timerActionDone.start();
//add to transfer list
numberOfTransferIntoToDoList++;
bytesToTransfer+= source.size();
@@ -843,7 +903,7 @@ quint64 ListThread::addToTransfer(const QFileInfo& source,const QFileInfo& desti
newAction.addAction.size = temp.size;
newAction.addAction.mode = mode;
actionDone << newAction;
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"source: "+source.absoluteFilePath()+",destination: "+destination.absoluteFilePath()+", add entry: "+QString::number(temp.id));
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("source: %1, destination: %2, add entry: %3, size: %4, size2: %5").arg(source.absoluteFilePath()).arg(destination.absoluteFilePath()).arg(temp.id).arg(temp.size).arg(newAction.addAction.size));
return temp.id;
}
@@ -867,6 +927,11 @@ void ListThread::removeItems(const QList<int> &ids)
//put on top
void ListThread::moveItemsOnTop(QList<int> ids)
{
+ if(actionToDoListTransfer.size()<=1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"list size is empty");
+ return;
+ }
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
//do list operation
int indexToMove=0;
@@ -897,6 +962,11 @@ void ListThread::moveItemsOnTop(QList<int> ids)
//move up
void ListThread::moveItemsUp(QList<int> ids)
{
+ if(actionToDoListTransfer.size()<=1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"list size is empty");
+ return;
+ }
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
//do list operation
int lastGoodPositionExtern=0;
@@ -943,6 +1013,11 @@ void ListThread::moveItemsUp(QList<int> ids)
//move down
void ListThread::moveItemsDown(QList<int> ids)
{
+ if(actionToDoListTransfer.size()<=1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"list size is empty");
+ return;
+ }
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
//do list operation
int lastGoodPositionExtern=numberOfTransferIntoToDoList;
@@ -990,6 +1065,11 @@ void ListThread::moveItemsDown(QList<int> ids)
//put on bottom
void ListThread::moveItemsOnBottom(QList<int> ids)
{
+ if(actionToDoListTransfer.size()<=1)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"list size is empty");
+ return;
+ }
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
//do list operation
int lastGoodPositionExtern=numberOfTransferIntoToDoList;
@@ -1020,19 +1100,66 @@ void ListThread::moveItemsOnBottom(QList<int> ids)
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"stop");
}
+/** \brief give the forced mode, to export/import transfer list */
+void ListThread::forceMode(const CopyMode &mode)
+{
+ if(mode==Copy)
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("Force mode to copy"));
+ else
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("Force mode to move"));
+ this->mode=mode;
+ forcedMode=true;
+}
+
void ListThread::exportTransferList(const QString &fileName)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
QFile transferFile(fileName);
if(transferFile.open(QIODevice::WriteOnly|QIODevice::Truncate))
{
- transferFile.write(QString("Ultracopier-0.3;CopyEngine-0.3\n").toUtf8());
+ transferFile.write(QString("Ultracopier-0.3;Transfer-list;").toUtf8());
+ if(!forcedMode)
+ transferFile.write(QString("Transfer;").toUtf8());
+ else
+ {
+ if(mode==Copy)
+ transferFile.write(QString("Copy;").toUtf8());
+ else
+ transferFile.write(QString("Move;").toUtf8());
+ }
+ transferFile.write(QString("Ultracopier-0.3\n").toUtf8());
+ bool haveError=false;
int size=actionToDoListTransfer.size();
for (int index=0;index<size;++index) {
if(actionToDoListTransfer.at(index).mode==Copy)
- transferFile.write(QString("Copy;%1;%2\n").arg(actionToDoListTransfer.at(index).source.absoluteFilePath()).arg(actionToDoListTransfer.at(index).destination.absoluteFilePath()).toUtf8());
- else
- transferFile.write(QString("Move;%1;%2\n").arg(actionToDoListTransfer.at(index).source.absoluteFilePath()).arg(actionToDoListTransfer.at(index).destination.absoluteFilePath()).toUtf8());
+ {
+ if(!forcedMode || mode==Copy)
+ {
+ if(forcedMode)
+ transferFile.write(QString("%1;%2\n").arg(actionToDoListTransfer.at(index).source.absoluteFilePath()).arg(actionToDoListTransfer.at(index).destination.absoluteFilePath()).toUtf8());
+ else
+ transferFile.write(QString("Copy;%1;%2\n").arg(actionToDoListTransfer.at(index).source.absoluteFilePath()).arg(actionToDoListTransfer.at(index).destination.absoluteFilePath()).toUtf8());
+ }
+ else
+ haveError=true;
+ }
+ else if(actionToDoListTransfer.at(index).mode==Move)
+ {
+ if(!forcedMode || mode==Move)
+ {
+ if(forcedMode)
+ transferFile.write(QString("Move;%1;%2\n").arg(actionToDoListTransfer.at(index).source.absoluteFilePath()).arg(actionToDoListTransfer.at(index).destination.absoluteFilePath()).toUtf8());
+ else
+ transferFile.write(QString("%1;%2\n").arg(actionToDoListTransfer.at(index).source.absoluteFilePath()).arg(actionToDoListTransfer.at(index).destination.absoluteFilePath()).toUtf8());
+ }
+ else
+ haveError=true;
+ }
+ }
+ if(haveError)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("Unable do to move or copy item into wrong forced mode: %1").arg(transferFile.errorString()));
+ emit errorTransferList(tr("Unable do to move or copy item into wrong forced mode: %1").arg(transferFile.errorString()));
}
transferFile.close();
}
@@ -1051,7 +1178,7 @@ void ListThread::importTransferList(const QString &fileName)
if(transferFile.open(QIODevice::ReadOnly))
{
QString content;
- QByteArray data=transferFile.readLine();
+ QByteArray data=transferFile.readLine(64);
if(data.size()<=0)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("Problem at the reading, or file size is null"));
@@ -1059,19 +1186,47 @@ void ListThread::importTransferList(const QString &fileName)
return;
}
content=QString::fromUtf8(data);
- if(content!="Ultracopier-0.3;CopyEngine-0.3\n")
+ if(content!="Ultracopier-0.3;Transfer-list;Transfer;Ultracopier-0.3\n" && content!="Ultracopier-0.3;Transfer-list;Copy;Ultracopier-0.3\n" && content!="Ultracopier-0.3;Transfer-list;Move;Ultracopier-0.3\n")
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("Wrong header: \"%1\"").arg(content));
emit errorTransferList(tr("Wrong header: \"%1\"").arg(content));
return;
}
- bool errorFound=false,ignored_by_wrong_type=false;
- QRegExp correctLine("^(Copy|Move);[^;]+;[^;]+\n$");
+ bool transferListMixedMode=false;
+ if(content=="Ultracopier-0.3;Transfer-list;Transfer;Ultracopier-0.3\n")
+ {
+ if(forcedMode)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("The transfer list is in mixed mode, but this instance is not in this mode"));
+ emit errorTransferList(tr("The transfer list is in mixed mode, but this instance is not in this mode"));
+ return;
+ }
+ else
+ transferListMixedMode=true;
+ }
+ if(content=="Ultracopier-0.3;Transfer-list;Copy;Ultracopier-0.3\n" && (forcedMode && mode==Move))
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("The transfer list is in copy mode, but this instance is not in this mode: forcedMode: %1, mode: %2").arg(forcedMode).arg(mode));
+ emit errorTransferList(tr("The transfer list is in copy mode, but this instance is not in this mode"));
+ return;
+ }
+ if(content=="Ultracopier-0.3;Transfer-list;Move;Ultracopier-0.3\n" && (forcedMode && mode==Copy))
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,QString("The transfer list is in move mode, but this instance is not in this mode: forcedMode: %1, mode: %2").arg(forcedMode).arg(mode));
+ emit errorTransferList(tr("The transfer list is in move mode, but this instance is not in this mode"));
+ return;
+ }
+ bool errorFound=false;
+ QRegExp correctLine;
+ if(transferListMixedMode)
+ correctLine=QRegExp("^(Copy|Move);[^;]+;[^;]+\n$");
+ else
+ correctLine=QRegExp("^[^;]+;[^;]+\n$");
QStringList args;
- CopyMode mode;
+ CopyMode tempMode;
do
{
- data=transferFile.readLine();
+ data=transferFile.readLine(65535*2);
if(data.size()>0)
{
content=QString::fromUtf8(data);
@@ -1080,12 +1235,20 @@ void ListThread::importTransferList(const QString &fileName)
{
content.remove("\n");
args=content.split(";");
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("New data to import: %1,%2,%3").arg(args.at(0)).arg(args.at(1)).arg(args.at(2)));
- if(args.at(0)=="Copy")
- mode=Copy;
+ if(forcedMode)
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("New data to import in forced mode: %2,%3").arg(args.at(0)).arg(args.at(1)));
+ addToTransfer(QFileInfo(args.at(0)),QFileInfo(args.at(1)),mode);
+ }
else
- mode=Move;
- addToTransfer(QFileInfo(args.at(1)),QFileInfo(args.at(2)),mode);
+ {
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("New data to import: %1,%2,%3").arg(args.at(0)).arg(args.at(1)).arg(args.at(2)));
+ if(args.at(0)=="Copy")
+ tempMode=Copy;
+ else
+ tempMode=Move;
+ addToTransfer(QFileInfo(args.at(1)),QFileInfo(args.at(2)),tempMode);
+ }
}
else
{
@@ -1098,8 +1261,6 @@ void ListThread::importTransferList(const QString &fileName)
transferFile.close();
if(errorFound)
emit warningTransferList(tr("Some error have been found during the line parsing"));
- else if(ignored_by_wrong_type)
- emit warningTransferList(tr("Some list is ignored because it not corresponds to the window transfer type"));
// emit newActionOnList();
}
else
@@ -1113,7 +1274,7 @@ void ListThread::importTransferList(const QString &fileName)
//do new actions
void ListThread::doNewActions_start_transfer()
{
- ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("actionToDoListTransfer.size(): %1, numberOfTranferRuning: ").arg(actionToDoListTransfer.size()).arg(numberOfTranferRuning));
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("actionToDoListTransfer.size(): %1, numberOfTranferRuning: %2").arg(actionToDoListTransfer.size()).arg(numberOfTranferRuning));
if(stopIt || putInPause)
return;
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start");
@@ -1122,7 +1283,7 @@ void ListThread::doNewActions_start_transfer()
loop_size=transferThreadList.size();
while(int_for_loop<loop_size && numberOfTranferRuning<ULTRACOPIER_PLUGIN_MAXPARALLELTRANFER)
{
- if(transferThreadList.at(int_for_loop)->getStat()==TransferThread::WaitForTheTransfer)
+ if(transferThreadList.at(int_for_loop)->getStat()==TransferStat_WaitForTheTransfer)
{
transferThreadList.at(int_for_loop)->startTheTransfer();
numberOfTranferRuning++;
@@ -1132,7 +1293,7 @@ void ListThread::doNewActions_start_transfer()
int_for_loop=0;
while(int_for_loop<loop_size && numberOfTranferRuning<ULTRACOPIER_PLUGIN_MAXPARALLELTRANFER)
{
- if(transferThreadList.at(int_for_loop)->getStat()==TransferThread::PreOperation)
+ if(transferThreadList.at(int_for_loop)->getStat()==TransferStat_PreOperation)
{
transferThreadList.at(int_for_loop)->startTheTransfer();
numberOfTranferRuning++;
@@ -1195,7 +1356,7 @@ void ListThread::doNewActions_inode_manipulation()
I this case it lose all data
*/
currentTransferThread=transferThreadList[int_for_transfer_thread_search];
- if(currentTransferThread->getStat()==TransferThread::Idle && currentTransferThread->transferId==0) // /!\ important!
+ if(currentTransferThread->getStat()==TransferStat_Idle && currentTransferThread->transferId==0) // /!\ important!
{
currentTransferThread->transferId=currentActionToDoTransfer.id;
currentTransferThread->transferSize=currentActionToDoTransfer.size;
@@ -1265,7 +1426,7 @@ void ListThread::restartTransferIfItCan()
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,QString("transfer thread not located!"));
return;
}
- if(numberOfTranferRuning<ULTRACOPIER_PLUGIN_MAXPARALLELTRANFER && transfer->getStat()==TransferThread::WaitForTheTransfer)
+ if(numberOfTranferRuning<ULTRACOPIER_PLUGIN_MAXPARALLELTRANFER && transfer->getStat()==TransferStat_WaitForTheTransfer)
{
transfer->startTheTransfer();
numberOfTranferRuning++;
@@ -1274,36 +1435,70 @@ void ListThread::restartTransferIfItCan()
}
/// \brief update the transfer stat
-void ListThread::newTransferStat(TransferThread::TransferStat stat,quint64 id)
+void ListThread::newTransferStat(TransferStat stat,quint64 id)
{
returnActionOnCopyList newAction;
switch(stat)
{
- case TransferThread::Idle:
+ case TransferStat_Idle:
return;
break;
- case TransferThread::PreOperation:
+ case TransferStat_PreOperation:
return;
break;
- case TransferThread::WaitForTheTransfer:
+ case TransferStat_WaitForTheTransfer:
return;
break;
- case TransferThread::Transfer:
+ case TransferStat_Transfer:
newAction.type=Transfer;
break;
- case TransferThread::PostTransfer:
+ case TransferStat_PostTransfer:
+ case TransferStat_PostOperation:
newAction.type=PostOperation;
break;
- case TransferThread::PostOperation:
- return;
+ case TransferStat_Checksum:
+ newAction.type=CustomOperation;
break;
default:
+ return;
break;
}
newAction.addAction.id = id;
actionDone << newAction;
}
+void ListThread::set_osBufferLimit(unsigned int osBufferLimit)
+{
+ this->osBufferLimit=osBufferLimit;
+ int index=0;
+ loop_sub_size_transfer_thread_search=transferThreadList.size();
+ while(index<loop_sub_size_transfer_thread_search)
+ {
+ transferThreadList.at(index)->set_osBufferLimit(osBufferLimit);
+ index++;
+ }
+}
+
+void ListThread::set_setFilters(QList<Filters_rules> include,QList<Filters_rules> exclude)
+{
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,QString("include.size(): %1, exclude.size(): %2").arg(include.size()).arg(exclude.size()));
+ this->include=include;
+ this->exclude=exclude;
+ int index=0;
+ while(index<scanFileOrFolderThreadsPool.size())
+ {
+ scanFileOrFolderThreadsPool.at(index)->setFilters(include,exclude);
+ index++;
+ }
+}
+
+void ListThread::set_sendNewRenamingRules(QString firstRenamingRule,QString otherRenamingRule)
+{
+ this->firstRenamingRule=firstRenamingRule;
+ this->otherRenamingRule=otherRenamingRule;
+ emit send_sendNewRenamingRules(firstRenamingRule,otherRenamingRule);
+}
+
void ListThread::mkPathFirstFolderFinish()
{
int_for_loop=0;
@@ -1358,24 +1553,27 @@ void ListThread::timedUpdateDebugDialog()
QString stat;
switch(transferThreadList.at(index)->getStat())
{
- case TransferThread::Idle:
+ case TransferStat_Idle:
stat="Idle";
break;
- case TransferThread::PreOperation:
+ case TransferStat_PreOperation:
stat="PreOperation";
break;
- case TransferThread::WaitForTheTransfer:
+ case TransferStat_WaitForTheTransfer:
stat="WaitForTheTransfer";
break;
- case TransferThread::Transfer:
+ case TransferStat_Transfer:
stat="Transfer";
break;
- case TransferThread::PostOperation:
+ case TransferStat_PostOperation:
stat="PostOperation";
break;
- case TransferThread::PostTransfer:
+ case TransferStat_PostTransfer:
stat="PostTransfer";
break;
+ case TransferStat_Checksum:
+ stat="Checksum";
+ break;
default:
stat=QString("??? (%1)").arg(transferThreadList.at(index)->getStat());
break;
@@ -1454,6 +1652,13 @@ void ListThread::createTransferThread()
last->setDrive(drives);
last->setAlwaysFileExistsAction(alwaysDoThisActionForFileExists);
last->setMaxSpeed(maxSpeed/ULTRACOPIER_PLUGIN_MAXPARALLELTRANFER);
+ last->set_doChecksum(doChecksum);
+ last->set_checksumIgnoreIfImpossible(checksumIgnoreIfImpossible);
+ last->set_checksumOnlyOnError(checksumOnlyOnError);
+ last->set_osBuffer(osBuffer);
+ last->set_osBufferLimited(osBufferLimited);
+ last->set_osBufferLimit(osBufferLimit);
+
#ifdef ULTRACOPIER_PLUGIN_DEBUG
connect(last,SIGNAL(debugInformation(DebugLevel,QString,QString,QString,int)),this,SIGNAL(debugInformation(DebugLevel,QString,QString,QString,int)), Qt::QueuedConnection);
#endif // ULTRACOPIER_PLUGIN_DEBUG
@@ -1464,9 +1669,14 @@ void ListThread::createTransferThread()
connect(last,SIGNAL(preOperationStopped()), this,SLOT(doNewActions_start_transfer()), Qt::QueuedConnection);
connect(last,SIGNAL(postOperationStopped()), this,SLOT(transferInodeIsClosed()), Qt::QueuedConnection);
connect(last,SIGNAL(checkIfItCanBeResumed()), this,SLOT(restartTransferIfItCan()), Qt::QueuedConnection);
+ connect(last,SIGNAL(pushStat(TransferStat,quint64)), this,SLOT(newTransferStat(TransferStat,quint64)), Qt::QueuedConnection);
+
+ connect(this,SIGNAL(send_sendNewRenamingRules(QString,QString)), last,SLOT(setRenamingRules(QString,QString)), Qt::QueuedConnection);
+
last->start();
last->setObjectName(QString("transfer %1").arg(transferThreadList.size()-1));
last->setMkpathTransfer(&mkpathTransfer);
+ last->setRenamingRules(firstRenamingRule,otherRenamingRule);
#ifdef ULTRACOPIER_PLUGIN_DEBUG
last->setId(transferThreadList.size()-1);
#endif