720
724
if (curEntry->currItem == curEntry->reversedOrder.count())
722
726
const QFileInfo & mainItem = curEntry->reversedOrder.at(curEntry->currItem -1);
723
if (m_curAction->type == ActionRemove || m_curAction->type == ActionMove ||
724
m_curAction->type == ActionHardMoveRemove)
726
emit removed(mainItem);
728
if (m_curAction->type == ActionCopy || m_curAction->type == ActionMove ||
729
m_curAction->type == ActionHardMoveCopy)
732
QString addedItem = targetFom(mainItem.absoluteFilePath(), m_curAction);
733
if (curEntry->alreadyExists && curEntry->newName == 0)
735
//if an item already exists there are two possibilities:
736
// 1. emit removed(), then emit added()
737
// 2. emit removedThenAdded() which should be attached to a kind of change slot
738
if (m_curAction->type == ActionHardMoveCopy)
740
emit removed(addedItem);
743
{ //ActionCopy ActionMove
744
emit removedThenAdded(QFileInfo(addedItem));
750
emit added(addedItem);
753
727
m_curAction->currEntryIndex++;
754
//check if is doing a hard move and the copy part has finished
755
//if so switch the action to remove
756
if (m_curAction->type == ActionHardMoveCopy &&
757
m_curAction->currEntryIndex == m_curAction->entries.count() )
728
switch(m_curAction->type)
759
m_curAction->type = ActionHardMoveRemove;
760
m_curAction->currEntryIndex = 0;
761
int entryCounter = m_curAction->entries.count();
763
while (entryCounter--)
765
entry = m_curAction->entries.at(entryCounter);
731
emit removed(mainItem);
733
case ActionHardMoveRemove: // nothing to do
735
case ActionHardMoveCopy:
736
//check if is doing a hard move and the copy part has finished
737
//if so switch the action to remove
738
if (m_curAction->currEntryIndex == m_curAction->entries.count())
740
m_curAction->type = ActionHardMoveRemove;
741
m_curAction->currEntryIndex = 0;
742
int entryCounter = m_curAction->entries.count();
744
while (entryCounter--)
746
entry = m_curAction->entries.at(entryCounter);
751
case ActionCopy: // ActionHardMoveCopy is also checked here
754
QString addedItem = targetFom(mainItem.absoluteFilePath(), m_curAction);
755
if (!curEntry->added && !curEntry->alreadyExists)
757
emit added(addedItem);
758
curEntry->added = true;
762
emit changed(QFileInfo(addedItem));
768
}//end if (curEntry->currItem == curEntry->reversedOrder.count())
771
770
if (curEntry->currStep == STEP_FILES)
773
772
curEntry->currStep = 0;
908
907
QString path(target);
909
908
// do this here to allow progress send right item number, copySingleFile will emit progress()
910
909
m_curAction->currItem++;
912
911
if (fi.isFile() || fi.isSymLink())
914
913
QFileInfo t(target);
916
//check if the main item in the entry is a directory
917
//if so it needs to appear on any attached view
918
if ( m_curAction->currItem == 1
919
&& entry->reversedOrder.last().isDir()
920
&& !entry->reversedOrder.last().isSymLink()
923
QString entryDir = targetFom(entry->reversedOrder.last().absoluteFilePath(), m_curAction);
924
QDir entryDirObj(entryDir);
925
if (!entryDirObj.exists() && entryDirObj.mkpath(entryDir))
927
emit added(entryDir);
918
932
if (!d.exists() && !d.mkpath(path))
964
qint64 needsSize = 0;
950
965
m_curAction->copyFile.clear();
951
966
m_curAction->copyFile.source = new QFile(orig);
952
if (!m_curAction->copyFile.source->open(QFile::ReadOnly))
954
m_cancelCurrentAction = true;
967
m_cancelCurrentAction = !m_curAction->copyFile.source->open(QFile::ReadOnly);
968
if (m_cancelCurrentAction)
955
970
m_errorTitle = QObject::tr("Could not open file");
956
971
m_errorMsg = orig;
958
m_curAction->copyFile.target = new QTemporaryFile();
959
if (! m_curAction->copyFile.target->open())
961
m_cancelCurrentAction = true;
962
m_errorTitle = QObject::tr("Could not create temporary file");
963
m_errorMsg = m_curAction->copyFile.target->fileName();
965
m_curAction->copyFile.targetName = target;
966
scheduleAnySlot = processCopySingleFile();
975
needsSize = m_curAction->copyFile.source->size();
977
m_curAction->copyFile.target = new QFile(target);
978
m_curAction->copyFile.targetName = target;
979
//first open it read-only to get its size if exists
980
if (m_curAction->copyFile.target->open(QFile::ReadOnly))
982
needsSize -= m_curAction->copyFile.target->size();
983
m_curAction->copyFile.target->close();
985
//check if there is disk space to copy source to target
986
if (needsSize > 0 && !isThereDiskSpace( needsSize ))
988
m_cancelCurrentAction = true;
989
m_errorTitle = QObject::tr("There is no space on disk to copy");
990
m_errorMsg = m_curAction->copyFile.target->fileName();
993
if (!m_cancelCurrentAction)
995
m_cancelCurrentAction =
996
!m_curAction->copyFile.target->open(QFile::WriteOnly | QFile::Truncate);
997
if (m_cancelCurrentAction)
999
m_errorTitle = QObject::tr("Could not create file");
1000
m_errorMsg = m_curAction->copyFile.target->fileName();
1003
if (!m_cancelCurrentAction)
1005
m_curAction->copyFile.isEntryItem = entry->currItem == (entry->reversedOrder.count() -1);
1006
scheduleAnySlot = processCopySingleFile();
1007
//main item from the entry. notify views new item inserted,
1008
//depending on the file size it may take longer, the view needs to be informed
1009
if (m_curAction->copyFile.isEntryItem && !m_cancelCurrentAction)
1011
if (!entry->alreadyExists)
1014
entry->added = true;
1018
emit changed(QFileInfo(target));
970
1025
//no copy going on
1206
1264
unsigned long originFsId = 0xfffe;
1207
1265
#if defined(Q_OS_UNIX)
1208
1266
struct statvfs vfs;
1209
if ( ::statvfs(m_path.toLatin1().constData(), &vfs) == 0 )
1267
if ( ::statvfs( QFile::encodeName(m_path).constData(), &vfs) == 0 )
1211
1269
targetFsId = vfs.f_fsid;
1213
if ( ::statvfs(itemToMovePathname.toLatin1().constData(), &vfs) == 0)
1271
if ( ::statvfs(QFile::encodeName(itemToMovePathname).constData(), &vfs) == 0)
1215
1273
originFsId = vfs.f_fsid;
1328
1390
&& m_curAction->copyFile.source->isOpen()
1331
m_curAction->copyFile.source->close();
1332
m_curAction->copyFile.target->close();
1333
m_curAction->copyFile.target->setAutoRemove(false);
1334
m_cancelCurrentAction = !m_curAction->copyFile.target->setPermissions(
1335
m_curAction->copyFile.source->permissions());
1336
if (m_cancelCurrentAction)
1338
m_errorTitle = QObject::tr("Set permissions error in ")
1339
+ m_curAction->copyFile.targetName,
1340
m_errorMsg = ::strerror(errno);
1344
QFile testExistTarget(m_curAction->copyFile.targetName);
1345
if (testExistTarget.exists())
1347
if ((m_cancelCurrentAction = ! testExistTarget.remove()))
1349
m_errorTitle = QObject::tr("Could not remove original file ")
1350
+ m_curAction->copyFile.targetName,
1351
m_errorMsg = ::strerror(errno);
1354
if (!m_cancelCurrentAction)
1356
m_cancelCurrentAction = ! m_curAction->copyFile.target->
1357
rename(m_curAction->copyFile.targetName);
1358
if (m_cancelCurrentAction)
1360
m_errorTitle = QObject::tr("Rename error: renaming to ")
1361
+ m_curAction->copyFile.targetName,
1362
m_errorMsg = ::strerror(errno);
1366
copySingleFileDone = true;
1393
copySingleFileDone = endCopySingleFile();
1372
1396
if (m_cancelCurrentAction)
1374
1398
if (m_curAction->copyFile.target)
1376
m_curAction->copyFile.target->setAutoRemove(true);
1400
if (m_curAction->copyFile.target->isOpen())
1402
m_curAction->copyFile.target->close();
1404
if (m_curAction->copyFile.target->remove())
1406
emit removed(m_curAction->copyFile.targetName);
1378
1409
m_curAction->copyFile.clear();
1379
1410
endActionEntry();
1652
1688
emit clipboardChanged();
1693
//==================================================================
1694
bool FileSystemAction::endCopySingleFile()
1697
m_curAction->copyFile.source->close();
1698
m_curAction->copyFile.target->close();
1699
m_cancelCurrentAction = !m_curAction->copyFile.target->setPermissions(
1700
m_curAction->copyFile.source->permissions());
1701
if (m_cancelCurrentAction)
1703
m_errorTitle = QObject::tr("Set permissions error in ")
1704
+ m_curAction->copyFile.targetName,
1705
m_errorMsg = ::strerror(errno);
1711
//==================================================================
1712
bool FileSystemAction::isThereDiskSpace(qint64 requiredSize)
1715
#if defined(Q_OS_UNIX)
1717
if ( ::statvfs( QFile::encodeName(m_path).constData(), &vfs) == 0 )
1719
qint64 free = vfs.f_bsize * vfs.f_bfree;
1720
ret = free > requiredSize;