diff --git a/importer/importer.cpp b/importer/importer.cpp --- a/importer/importer.cpp +++ b/importer/importer.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -130,7 +131,18 @@ } dst.setPath(dst.path() + fileName); - FileUtils::RenameResult result = FileUtils::rename(src, dst, mAuthWindow); + FileUtils::RenameResult result; + // Create additional subfolders if needed (e.g. when extra slashes in FileNameFormater) + QUrl subFolder = dst.adjusted(QUrl::RemoveFilename); + KIO::Job* job = KIO::mkpath(subFolder, QUrl(), KIO::HideProgressInfo); + KJobWidgets::setWindow(job,mAuthWindow); + if (!job->exec()) { // if subfolder creation fails + qWarning() << "Could not create subfolder:" << subFolder; + result = FileUtils::RenameFailed; + } else { // if subfolder creation succeeds + result = FileUtils::rename(src, dst, mAuthWindow); + } + switch (result) { case FileUtils::RenamedOK: mImportedUrlList << mCurrentUrl; diff --git a/tests/auto/importertest.cpp b/tests/auto/importertest.cpp --- a/tests/auto/importertest.cpp +++ b/tests/auto/importertest.cpp @@ -202,15 +202,21 @@ NEW_ROW("iLikeCurlies", "2009-10-24T22:50:49", "{{{name}}", "{iLikeCurlies}"); NEW_ROW("UnknownKeyword", "2009-10-24T22:50:49", "foo{unknown}bar", "foobar"); NEW_ROW("MissingClosingCurly", "2009-10-24T22:50:49", "foo{date", "foo"); + NEW_ROW("PICT0001.JPG", "2009-10-24T22:50:49", "{date}/{name}.{ext}", "2009-10-24/PICT0001.JPG"); } void ImporterTest::testAutoRenameFormat() { QStringList dates = QStringList() << "1979-02-23_10-20-00" << "2006-04-01_11-30-15" << "2009-10-01_21-15-27"; + QStringList dates2 = QStringList() + << "1979-02-23/10-20-00" + << "2006-04-01/11-30-15" + << "2009-10-01/21-15-27"; QCOMPARE(dates.count(), mDocumentList.count()); + QCOMPARE(dates2.count(), mDocumentList.count()); QUrl destUrl = QUrl::fromLocalFile(mTempDir->path() + "/foo"); @@ -232,6 +238,21 @@ dst.setPath(dst.path() + '/' + dates[pos] + ".jpg"); QVERIFY(FileUtils::contentsAreIdentical(src, dst)); } + + // Test again with slashes in AutoRenameFormat + importer.setAutoRenameFormat("{date}/{time}.{ext}"); + importer.start(list, destUrl); + loop.exec(); + + QCOMPARE(importer.importedUrlList().count(), list.count()); + QCOMPARE(importer.importedUrlList(), list); + + for (int pos = 0; pos < dates2.count(); ++pos) { + QUrl src = list[pos]; + QUrl dst = destUrl; + dst.setPath(dst.path() + '/' + dates2[pos] + ".jpg"); + QVERIFY(FileUtils::contentsAreIdentical(src, dst)); + } } void ImporterTest::testReadOnlyDestination()