Commit e0a32fb8 authored by Yew Ming Chen's avatar Yew Ming Chen
Browse files

fix overwrite query to support skip all and better overwrite all support

svn path=/trunk/KDE/kdeutils/ark/; revision=906844
parent 6748becb
......@@ -108,6 +108,11 @@ namespace Kerfuffle
return m_data.value("response").toInt() == KIO::R_SKIP;
}
bool OverwriteQuery::responseAutoSkip()
{
return m_data.value("response").toInt() == KIO::R_AUTO_SKIP;
}
QString OverwriteQuery::newFilename()
{
return m_data.value("newFilename").toString();
......@@ -145,11 +150,12 @@ namespace Kerfuffle
if( !dlg.exec() )
{
setResponse(false);
return;
}
m_data["password"] = dlg.password();
setResponse(true);
else
{
m_data["password"] = dlg.password();
setResponse(true);
}
QApplication::restoreOverrideCursor();
}
......
......@@ -81,6 +81,7 @@ namespace Kerfuffle
bool responseOverwrite();
bool responseRename();
bool responseSkip();
bool responseAutoSkip();
QString newFilename();
void setNoRenameMode(bool enableNoRenameMode);
......
......@@ -263,46 +263,73 @@ bool p7zipInterface::copyFiles( const QList<QVariant> & files, const QString & d
QStringList overwriteList;
const QList<QVariant>* filesList = (files.count() == 0)? &m_archiveContents : &files;
bool overwriteAll = false;
QStringList overwriteAllDirectories;
QStringList autoSkipDirectories;
QStringList skipList;
for (int i = 0; i < filesList->count(); i++)
{
if (overwriteAll)
QString filepath(destinationDirectory + '/' + filesList->at(i).toString());
QFileInfo currentFileInfo(filepath);
if ( overwriteAllDirectories.contains(currentFileInfo.canonicalPath()) ||
overwriteAllDirectories.contains(currentFileInfo.canonicalFilePath()))
{
overwriteList << filesList->at(i).toString();
}
else
else if (autoSkipDirectories.contains(currentFileInfo.canonicalPath())
|| autoSkipDirectories.contains(currentFileInfo.canonicalFilePath()))
{
skipList << currentFileInfo.canonicalFilePath();
}
else if (currentFileInfo.exists())
{
QString filepath(destinationDirectory + '/' + filesList->at(i).toString());
if (QFile::exists(filepath))
Kerfuffle::OverwriteQuery query(filepath);
query.setNoRenameMode(true);
emit userQuery(&query);
query.waitForResponse();
if (query.responseOverwrite())
{
Kerfuffle::OverwriteQuery query(filepath);
query.setNoRenameMode(true);
emit userQuery(&query);
query.waitForResponse();
if (query.responseOverwrite())
{
overwriteList << filesList->at(i).toString();
}
else if (query.responseSkip())
{
// do not add to overwriteList
}
else if (query.responseOverwriteAll())
overwriteList << filesList->at(i).toString();
}
else if (query.responseSkip())
{
skipList << currentFileInfo.canonicalFilePath();
}
else if (query.responseAutoSkip())
{
if (currentFileInfo.isDir())
{
overwriteAll = true;
overwriteList << filesList->at(i).toString();
autoSkipDirectories << currentFileInfo.canonicalFilePath();
}
else if (query.responseCancelled())
else
{
return true;
autoSkipDirectories << currentFileInfo.canonicalPath();
}
kDebug( 1601 ) << "adding auto skip" << autoSkipDirectories.at(autoSkipDirectories.size()-1);
skipList << currentFileInfo.canonicalFilePath();
}
else
else if (query.responseOverwriteAll())
{
kDebug( 1601 ) << "adding overwrite all" << currentFileInfo.canonicalPath();
overwriteAllDirectories << currentFileInfo.canonicalPath();
overwriteList << filesList->at(i).toString();
}
else if (query.responseCancelled())
{
return true;
}
}
else
{
overwriteList << filesList->at(i).toString();
}
}
kDebug( 1601 ) << overwriteList;
if (overwriteList.isEmpty() && !skipList.isEmpty())
{
// all files skipped
return true;
}
if (!create7zipProcess())
......
......@@ -220,46 +220,73 @@ bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & des
QStringList overwriteList;
const QList<QVariant>* filesList = (files.count() == 0)? &m_archiveContents : &files;
bool overwriteAll = false;
QStringList overwriteAllDirectories;
QStringList autoSkipDirectories;
QStringList skipList;
for (int i = 0; i < filesList->count(); i++)
{
if (overwriteAll)
QString filepath(destinationDirectory + '/' + filesList->at(i).toString());
QFileInfo currentFileInfo(filepath);
if ( overwriteAllDirectories.contains(currentFileInfo.canonicalPath()) ||
overwriteAllDirectories.contains(currentFileInfo.canonicalFilePath()))
{
overwriteList << filesList->at(i).toString();
}
else
else if (autoSkipDirectories.contains(currentFileInfo.canonicalPath())
|| autoSkipDirectories.contains(currentFileInfo.canonicalFilePath()))
{
skipList << currentFileInfo.canonicalFilePath();
}
else if (currentFileInfo.exists())
{
QString filepath(destinationDirectory + '/' + filesList->at(i).toString());
if (QFile::exists(filepath))
Kerfuffle::OverwriteQuery query(filepath);
query.setNoRenameMode(true);
emit userQuery(&query);
query.waitForResponse();
if (query.responseOverwrite())
{
Kerfuffle::OverwriteQuery query(filepath);
query.setNoRenameMode(true);
emit userQuery(&query);
query.waitForResponse();
if (query.responseOverwrite())
{
overwriteList << filesList->at(i).toString();
}
else if (query.responseSkip())
{
// do not add to overwriteList
}
else if (query.responseOverwriteAll())
overwriteList << filesList->at(i).toString();
}
else if (query.responseSkip())
{
skipList << currentFileInfo.canonicalFilePath();
}
else if (query.responseAutoSkip())
{
if (currentFileInfo.isDir())
{
overwriteAll = true;
overwriteList << filesList->at(i).toString();
autoSkipDirectories << currentFileInfo.canonicalFilePath();
}
else if (query.responseCancelled())
else
{
return true;
autoSkipDirectories << currentFileInfo.canonicalPath();
}
kDebug( 1601 ) << "adding auto skip" << autoSkipDirectories.at(autoSkipDirectories.size()-1);
skipList << currentFileInfo.canonicalFilePath();
}
else
else if (query.responseOverwriteAll())
{
kDebug( 1601 ) << "adding overwrite all" << currentFileInfo.canonicalPath();
overwriteAllDirectories << currentFileInfo.canonicalPath();
overwriteList << filesList->at(i).toString();
}
else if (query.responseCancelled())
{
return true;
}
}
else
{
overwriteList << filesList->at(i).toString();
}
}
kDebug( 1601 ) << overwriteList;
if (overwriteList.isEmpty() && !skipList.isEmpty())
{
// all files skipped
return true;
}
if (!createRarProcess())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment