Fix inability to Drag+Drop screenshot due to subfolder in filename
ClosedPublic

Authored by brainpower on Apr 9 2020, 2:06 PM.

Details

Summary

Fixes the mentioned bug by creating all necessary subdirectories.

BUG: 417722

Test Plan
  1. Set save Filename in Spectacle to one including one or more /, thus including subdirectories. Example: %Y/%M/screen-%2d
  2. Take a screenshot
  3. Start dragging the preview

Diff Detail

Repository
R166 Spectacle
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
brainpower created this revision.Apr 9 2020, 2:06 PM
Restricted Application added a subscriber: Spectacle. · View Herald TranscriptApr 9 2020, 2:06 PM
brainpower requested review of this revision.Apr 9 2020, 2:06 PM
davidre added a subscriber: davidre.Apr 9 2020, 2:17 PM

I wonder why we care about subdirs at all? If we do tempSave for drag and drop would it be sufficient to create the file in the tmp dir and strip the rest of autosaveFilename? This would save the need to create the subdirectories but I don't think it will make a big difference either way, but it's one thing less that could fail?

ngraham added a subscriber: ngraham.
ngraham added inline comments.
src/ExportManager.cpp
403

Use QLatin1Char("/") instead of QDir::separator() (Qt automatically transforms a slash into the correct platform-specific separator character)

406

Use consistent indentation: 4 chars of whitespace, not 2

ngraham retitled this revision from Fix Bug 417722: Cannot Drag/Drop Screenshot Due To Subfolder in Filename to Fix inability to Drag+Drop screenshot due to subfolder in filename .Apr 9 2020, 2:19 PM
ngraham edited the summary of this revision. (Show Details)

@davidre:

Stripping the filename of subdirs would be fine with me.
I did try to be consistent, just in case something may not work otherwise.

Is autosaveFilename.section(QDir::separator(), -1); fine or would you like to have QUrl::fileName() used for stripping?

src/ExportManager.cpp
403

I did use QDir::separator() because it was used before for this and is used for constructing mTempDir at the beginning of the function (Line 395).
Should it be changed to QLatinChar("/") for mTempDir, too?

406

ok, will fix.

@davidre:

Stripping the filename of subdirs would be fine with me.
I did try to be consistent, just in case something may not work otherwise.

Is autosaveFilename.section(QDir::separator(), -1); fine or would you like to have QUrl::fileName() used for stripping?

I will trust your judgment what you think works best while writing the code :)

ngraham added inline comments.Apr 9 2020, 3:35 PM
src/ExportManager.cpp
403

Probably. That's unrelated to this patch though, and should be fixed in another one.

brainpower updated this revision to Diff 79720.Apr 9 2020, 4:39 PM

I decided to go with the suggested "just strip the subdirs".

The change is smaller and it should not matter for temporary saving.

The only other places tempSave() is used is for export via purpose and export via KIPI.
I tested some exports of both and they seemed to work fine either way.

brainpower marked 3 inline comments as done.Apr 9 2020, 4:39 PM
ngraham accepted this revision.Apr 9 2020, 5:17 PM

This makes sense to me.

@davidre?

This revision is now accepted and ready to land.Apr 9 2020, 5:17 PM
davidre accepted this revision.Apr 9 2020, 5:22 PM

Nice patch.

Can you provide your name and email address so we can land it with correct git authorship information?

brainpower added a comment.EditedApr 10 2020, 11:32 AM

I've updated my information on https://identity.kde.org/index.php?r=people/view&uid=brainpower , but this seems to have not propagated to the phabricator profile? (yet?)

The two aren't linked, and I don't have the ability to see that page.

You can either tell me that information in a comment here, or else put in your .gitconfig file and submit patchs using arc; Phabricator ignores the git authorship information if you don't use arc, which is stupid, but since we're migrating to GitLab soon enough, we won't have to live with it for long. :)

Well, the name is Franz Baumgärtner , mail is: f.baumg at mailbox dot org . (If the name has to be ascii, please use ae as replacement for the ä.)

Closed by commit R166:464dde9677f4: Fix inability to Drag+Drop screenshot due to subfolder in filename (authored by Franz Baumgärtner <f.baumg@mailbox.org>, committed by ngraham). · Explain WhyApr 13 2020, 1:33 AM
This revision was automatically updated to reflect the committed changes.

Thanks! Very nice patch. May it be the first of many. :)