Commit 4bc95c36 authored by Maik Qualmann's avatar Maik Qualmann

delete the right target file

parent a4f6db45
...@@ -85,18 +85,18 @@ void FCTask::run() ...@@ -85,18 +85,18 @@ void FCTask::run()
QLatin1Char('/') + QLatin1Char('/') +
d->srcUrl.fileName()); d->srcUrl.fileName());
if (d->settings.overwrite && QFile::exists(dest.toLocalFile()))
{
QFile::remove(dest.toLocalFile());
}
bool ok = false; bool ok = false;
if (d->settings.behavior == FCContainer::CopyFile) if (d->settings.behavior == FCContainer::CopyFile)
{ {
QFileInfo srcInfo(d->srcUrl.toLocalFile());
QString suffix = srcInfo.suffix().toUpper();
QString mimeName = QMimeDatabase().mimeTypeForFile(d->srcUrl.toLocalFile()).name(); QString mimeName = QMimeDatabase().mimeTypeForFile(d->srcUrl.toLocalFile()).name();
if (d->settings.changeImageProperties && mimeName.startsWith(QLatin1String("image/"))) if (d->settings.changeImageProperties &&
((suffix == QLatin1String("PGF")) ||
(suffix == QLatin1String("KRA")) ||
mimeName.startsWith(QLatin1String("image/"))))
{ {
QString errString; QString errString;
ok = imageResize(d->srcUrl.toLocalFile(), dest.toLocalFile(), errString); ok = imageResize(d->srcUrl.toLocalFile(), dest.toLocalFile(), errString);
...@@ -108,6 +108,7 @@ void FCTask::run() ...@@ -108,6 +108,7 @@ void FCTask::run()
} }
else else
{ {
deleteTargetFile(dest.toLocalFile());
ok = QFile::copy(d->srcUrl.toLocalFile(), ok = QFile::copy(d->srcUrl.toLocalFile(),
dest.toLocalFile()); dest.toLocalFile());
} }
...@@ -121,6 +122,7 @@ void FCTask::run() ...@@ -121,6 +122,7 @@ void FCTask::run()
if (d->settings.behavior == FCContainer::FullSymLink) if (d->settings.behavior == FCContainer::FullSymLink)
{ {
deleteTargetFile(dest.toLocalFile());
ok = QFile::link(d->srcUrl.toLocalFile(), ok = QFile::link(d->srcUrl.toLocalFile(),
dest.toLocalFile()); dest.toLocalFile());
} }
...@@ -129,6 +131,8 @@ void FCTask::run() ...@@ -129,6 +131,8 @@ void FCTask::run()
QDir dir(d->settings.destUrl.toLocalFile()); QDir dir(d->settings.destUrl.toLocalFile());
QString path = dir.relativeFilePath(d->srcUrl.toLocalFile()); QString path = dir.relativeFilePath(d->srcUrl.toLocalFile());
QUrl srcUrl = QUrl::fromLocalFile(path); QUrl srcUrl = QUrl::fromLocalFile(path);
deleteTargetFile(dest.toLocalFile());
ok = QFile::link(srcUrl.toLocalFile(), ok = QFile::link(srcUrl.toLocalFile(),
dest.toLocalFile()); dest.toLocalFile());
} }
...@@ -230,6 +234,7 @@ bool FCTask::imageResize(const QString& orgUrl, const QString& destName, QString ...@@ -230,6 +234,7 @@ bool FCTask::imageResize(const QString& orgUrl, const QString& destName, QString
if (d->settings.imageFormat == FCContainer::JPEG) if (d->settings.imageFormat == FCContainer::JPEG)
{ {
destFile.append(QLatin1String(".jpeg")); destFile.append(QLatin1String(".jpeg"));
deleteTargetFile(destFile);
img.setAttribute(QLatin1String("quality"), d->settings.imageCompression); img.setAttribute(QLatin1String("quality"), d->settings.imageCompression);
...@@ -242,6 +247,7 @@ bool FCTask::imageResize(const QString& orgUrl, const QString& destName, QString ...@@ -242,6 +247,7 @@ bool FCTask::imageResize(const QString& orgUrl, const QString& destName, QString
else if (d->settings.imageFormat == FCContainer::PNG) else if (d->settings.imageFormat == FCContainer::PNG)
{ {
destFile.append(QLatin1String(".png")); destFile.append(QLatin1String(".png"));
deleteTargetFile(destFile);
if (!img.save(destFile, QLatin1String("PNG"))) if (!img.save(destFile, QLatin1String("PNG")))
{ {
...@@ -281,4 +287,12 @@ bool FCTask::imageResize(const QString& orgUrl, const QString& destName, QString ...@@ -281,4 +287,12 @@ bool FCTask::imageResize(const QString& orgUrl, const QString& destName, QString
return false; return false;
} }
void FCTask::deleteTargetFile(const QString& filePath)
{
if (d->settings.overwrite && QFile::exists(filePath))
{
QFile::remove(filePath);
}
}
} // namespace DigikamGenericFileCopyPlugin } // namespace DigikamGenericFileCopyPlugin
...@@ -60,6 +60,7 @@ protected: ...@@ -60,6 +60,7 @@ protected:
private: private:
bool imageResize(const QString& orgUrl, const QString& destName, QString& err); bool imageResize(const QString& orgUrl, const QString& destName, QString& err);
void deleteTargetFile(const QString& filePath);
class Private; class Private;
Private* const d; Private* const d;
......
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