Add BatchRenameJob to KIO
ClosedPublic

Authored by chinmoyr on Dec 2 2017, 11:06 AM.

Details

Summary

This job will be used to rename multiple files. It basically reuses the code from Dolphin::RenameDialog.

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
chinmoyr created this revision.Dec 2 2017, 11:06 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptDec 2 2017, 11:06 AM
chinmoyr requested review of this revision.Dec 2 2017, 11:06 AM
apol added a subscriber: apol.Dec 2 2017, 11:20 AM

Wouldn't it be easier to have this job in Dolphin? Or it needs to be in kio to access private API?

In D9103#174381, @apol wrote:

Wouldn't it be easier to have this job in Dolphin? Or it needs to be in kio to access private API?

Adding undo support is easier if it's in KIO.

chinmoyr updated this revision to Diff 23272.Dec 2 2017, 1:37 PM

Emit both old and new url in fileRenamed. It will be useful when undoing.

dfaure requested changes to this revision.Dec 2 2017, 2:19 PM

I'm OK with this being in KIO. One day we might want the same from the file dialog, or krusader, etc.

autotests/batchrenamejobtest.cpp
21

this is all of QtTest + all of QtCore, please use <QTest> instead

52

srcList.reserve(fileList.count());

src/core/batchrenamejob.cpp
49

Well soon this won't be dolphin's logic anymore, right? Anyone reading this in 2 years won't find such logic in dolphin but only here? Then don't point to Dolphin ;)

52

"At least" is two words.

56

Why special case "not a sequence", rather than just replacing the first (last?) sequence?

65

cheap to create, but still, move outside foreach

76

this code iterates over newName's 3 times... I wonder why this isn't just indexOf + a small loop until (current char != placeholder). Simpler, faster, and easier to specify (as mentioned above)

110

nice docu, wrong location :-)

154

Faster: indexString.prepend(QString(minIndexLength - indexString.length(), QLatin1Char('0'));
Well, please test that it's correct, but you see the point, QString(int, char) creates the string with the repeated char in one go.

159

what if that's -1 because not found? can this happen?

197

what happens if we get "file already exists"? It seems the error is ignored?

src/core/batchrenamejob.h
47

add a one-line docu

53

/// @internal

66

Can you add an example here, to make it clearer?

Also mention that newName *must* contain the indexPlaceHolder character (right?) (what happens if it doesn't?)

Also I find the name "indexPlaceHolder" misleading, it reads like "index of the placeholder". Why not just call it placeHolder? (or replacementCharacter?)

72

QChar is basically a quint16, pass it by value, not by const ref.

This revision now requires changes to proceed.Dec 2 2017, 2:19 PM
chinmoyr updated this revision to Diff 23281.Dec 2 2017, 2:54 PM
chinmoyr marked 10 inline comments as done.

Made the required changes

dfaure requested changes to this revision.Dec 2 2017, 3:21 PM
dfaure added inline comments.
src/core/batchrenamejob.cpp
56

Not done, the comment here still talks about the "invalid because not connected sequence" case. Instead, point 3 could be simplified to "no placeholder", i.e. no longer "invalid" that needs to be explained with "(This means...)".

But of course the code also needs to do this: stop at the first sequence of placeholders, use that.

57

At least is two words in this sentence too ;)

76

not done. You added an if(), but you didn't implement my suggestion.

In a hurry? ;)

87

coding style: join with previous line

197

?

src/core/batchrenamejob.h
47

not done

53

not done

66

not done

This revision now requires changes to proceed.Dec 2 2017, 3:21 PM
chinmoyr updated this revision to Diff 23286.Dec 2 2017, 4:29 PM
chinmoyr marked 13 inline comments as done.

Hopefully I haven't missed any more of your comments.

src/core/batchrenamejob.cpp
56

Because there might not be a first or last sequence present. In case 3 we don't need a replacement and in case 4 we just append the integer irrespective of placeholder's location.

56

Here if there is exactly one sequence of placeholders then it is valid otherwise invalid.

76

Here it is searching for exactly one sequence. If more than one sequence are present like $$file$$name$$ then it is considered invalid.

76

Not really in a hurry :P I missed two comments and I also hoped arc would submit my comments but it didn't.

110

I just copied whatever there was in Dolphin. Where should I move it to?

159

This cannot happen. m_useIndex and m_appendIndex are there for that purpose only.

197

In dolphin the overwrite dialog pops up. Otherwise the fileRenamed is still emitted and the job continues. Maybe I should make that its emission conditional?

src/core/batchrenamejob.h
53

I hope it is for BatchRenameJob.

66

It is not necessary for newName to contain the placeholder. If its not there index will be appended to newName.

dfaure added inline comments.Dec 2 2017, 5:09 PM
src/core/batchrenamejob.cpp
76

But why? Why doesn't this lead to 12file$$name$$?

It's a weird input in the first place, I don't mind if the output is weird, because the benefit of doing it that way is:

  • easier documentation (no need to talk about the case of multiple disconnected sequences)
  • faster implementation (look for first placeholder, look if repeated, done)

OK I see that you solved the latter point in this commit though, it's at least fast now. Then I don't mind as much. You can leave it as is, I just wanted to finish explaining my point ;)

77

The trailing ';' looks like a mistake, even if it's not.

{} solves this, or moving ++first to the body of the while (more readable IMHO).

BTW if it moves forward it shouldn't be called first, it makes the indexOf below very confusing. Maybe just call it pos.

110

The public header, where people will see it ;)

I see you did that now, thanks.

197

Ah right KIO::moveAs itself pops up the overwrite dialog, but then can it end with KIO::ERR_FILE_ALREADY_EXIST ? At that point the user should overwrite or skip or cancel. Are you really sure this error code can happen in this slot?

src/core/batchrenamejob.h
73

... and then this should mention the case where no placeholder is present, and 12 gets appended (before the extension, IIUC).

chinmoyr updated this revision to Diff 23299.Dec 2 2017, 5:54 PM

changed 'first' to 'pos'.
added one more example to the doc.

chinmoyr added inline comments.Dec 2 2017, 6:04 PM
src/core/batchrenamejob.cpp
197

If the job isn't interactive (like in unit test) then it ends with ERR_FILE_ALREADY_EXIST error. In case of unit test ignoring the error seems quite harmless.

dfaure added inline comments.Dec 2 2017, 6:26 PM
src/core/batchrenamejob.cpp
197

Ah, yes, makes sense when non-interactive.

But this still reads like "risky" code to me. Why not remove the special check? For unittests it means any "existing dest" situation will lead to an error that aborts the whole job, but that's good, no?

chinmoyr updated this revision to Diff 23306.Dec 2 2017, 6:43 PM

removed exception for ERR_FILE_ALREADY_EXISTS.

dfaure accepted this revision.Dec 2 2017, 7:01 PM

Thanks!

This revision is now accepted and ready to land.Dec 2 2017, 7:01 PM
This revision was automatically updated to reflect the committed changes.