Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix & improve Sampler export #4539

Merged
merged 2 commits into from
Dec 31, 2021
Merged

fix & improve Sampler export #4539

merged 2 commits into from
Dec 31, 2021

Conversation

ronso0
Copy link
Member

@ronso0 ronso0 commented Nov 23, 2021

  • before .xml was added to any specified export file even if it ended with .xml
  • remember the import/export directory

@ronso0 ronso0 changed the base branch from main to 2.3 November 23, 2021 01:48
@ronso0 ronso0 added this to the 2.3.2 milestone Nov 23, 2021
src/mixer/samplerbank.cpp Outdated Show resolved Hide resolved
@ronso0 ronso0 marked this pull request as ready for review November 24, 2021 12:26
src/mixer/samplerbank.cpp Outdated Show resolved Hide resolved
@ronso0 ronso0 added the changelog This PR should be included in the changelog label Dec 12, 2021
Copy link
Member

@Holzhaus Holzhaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the file "foo.xml" already exists and I type "foo.xml" into the filename field of save file dialog (or if I just select the existing file), I'm asked if I really want to overwrite the existing file. If I just type "foo", the ".xml" suffix is appended and the file is overwritten without warning.

src/mixer/samplerbank.cpp Outdated Show resolved Hide resolved
src/mixer/samplerbank.cpp Show resolved Hide resolved
@ronso0
Copy link
Member Author

ronso0 commented Dec 13, 2021

If the file "foo.xml" already exists and I type "foo.xml" into the filename field of save file dialog (or if I just select the existing file), I'm asked if I really want to overwrite the existing file. If I just type "foo", the ".xml" suffix is appended and the file is overwritten without warning.

I'm really annoyed by havin to work around this Qt bug (missing file extension, which was fixed for Windows btw but not for Linux).
So we could either
A put that dialog into a loop (while file exists) and feed it back as starting point so Qt's own "Overwrite?" mechanism can kick in or
B we show out own oerwrite dialog, like we do for controller mappings?

@ronso0
Copy link
Member Author

ronso0 commented Dec 13, 2021

Actually I'm in favor of A (IINM we'd just need to feed back the fileFilter and the file location) even though that would create small UX hickup: when clicking Save that would open the dialog again with the file and the extension being preselected. Then Save and you'd get asked if to overwrite or not.

@daschuer
Copy link
Member

daschuer commented Dec 13, 2021

We already have the override Dialog in main? I think this is a good solution, because the is use case for overriding when the user has lets say 4 favorit sets and wants to adjust one of it.

@daschuer
Copy link
Member

Oh, I now understand. We bypass the current solution by the added extension.
A works for me as well.

@ronso0
Copy link
Member Author

ronso0 commented Dec 13, 2021

B we show out own oerwrite dialog, like we do for controller mappings?

Downside of this is that it's needed only for Linux environments which don't supply a native file dialog -- all other OS and distros would request overwrite confirmation twice :\

All in all this feels like re-inventing the wheel. We could as well use an own QFileDialog with the root issue fixed.

@ronso0
Copy link
Member Author

ronso0 commented Dec 14, 2021

I implemented A in #4531. It's the last two commits and for now only implemented for exporting playlists from the Playlist feature.
Please check if this works for you.

@ronso0
Copy link
Member Author

ronso0 commented Dec 17, 2021

This is now based on #4531 so only the changes in /src/mixer are relevant.
I'll rebase as soon as that is merged.

@@ -33,28 +44,40 @@ SamplerBank::SamplerBank(PlayerManager* pPlayerManager)
SamplerBank::~SamplerBank() {
}

const QString SamplerBank::samplerFiletype() {
return tr("Mixxx Sampler Banks (*.xml)");
}
Copy link
Member Author

@ronso0 ronso0 Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't feel this is the smartest way to define a tr string which is used multple times.
Are there any other ways to do that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QT_TR_NOOP seems to be the weapon of choice, put in the anonymous namespace.
const QString kSamplerFileType = QT_TR_NOOP("Mixxx Sampler Banks (*.xml)");

Let me know what you think.

Copy link
Member

@Swiftb0y Swiftb0y Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't const QString kSamplerFileType = QObject::tr("Mixxx Sampler Banks (*.xml)"); work just as well? According to Qt docs, QT_TR_NOOP marks a string for "delayed translation", but I don't know what that means, maybe lazy loading of the translated string on first use?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to test the translation for both to be sure. Never did that before though..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means the current code translates the string on every call. The proposed solution of @Swiftb0y only translates one time. However I am not sure if the translation is initialized before the string is initialized.

Copy link
Member Author

@ronso0 ronso0 Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I'm not familiar with the translation workflow, so I appreciate any advice how to proceed here.
Edit just noticed you reply below, I'll take a look.

@daschuer
Copy link
Member

#4531 is now merged. Can you rebase this again?


const ConfigKey kConfigkeyLastImportExportDirectory(
"[Samplers]", "last_import_export_directory");
const QString kSamplerFileType = QT_TR_NOOP("Mixxx Sampler Banks (*.xml)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const QString kSamplerFileType = QT_TR_NOOP("Mixxx Sampler Banks (*.xml)");
const char kSamplerFileType[] = QT_TR_NOOP("Mixxx Sampler Banks (*.xml)");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can explain why a char[] is preferred here? QT_TR_NOOP is used nowhere else in mixxx so explaining why its used here definitively deserves explanation in the code IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping
Shall we add a comment, then merge?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe, this was meant for @daschuer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QT_TR_NOOP should always used with char[] or char*, because the result will be used as key for fetching the translated string in tr()

https://doc.qt.io/qt-5/qobject.html#tr

Using QString will convert from char[] and back to char*

src/mixer/samplerbank.cpp Outdated Show resolved Hide resolved
@ronso0
Copy link
Member Author

ronso0 commented Dec 17, 2021

Thank you!

I rebased onto 2.3, added recent tr suggestions and made the dialog preselect samplers.xml.
Please check, and if it's okay I'll squash the commits.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
There is still room for improving redundant translations lookups, but let's move on to more important tasks

Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
@ronso0
Copy link
Member Author

ronso0 commented Dec 17, 2021

Alright, done here.

@ronso0 ronso0 marked this pull request as ready for review December 17, 2021 18:58
Copy link
Member

@Holzhaus Holzhaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@ronso0
Copy link
Member Author

ronso0 commented Dec 30, 2021

Okay, great. Ready!

@daschuer
Copy link
Member

daschuer commented Dec 30, 2021

Oh sorry, I guess that is my dog food. I will prepare a fixed branch you can reset too, or we can merge this and fix it upstream.
https://github.com/daschuer/mixxx/tree/sampler-export

@ronso0
Copy link
Member Author

ronso0 commented Dec 30, 2021

I don't spot the difference? I commited your comment suggestion, what else is missing?

ah, okay: pre-commit, trailing whitespaces
I'll fix and foce-push.

Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
@ronso0
Copy link
Member Author

ronso0 commented Dec 31, 2021

Done and CI all green.

@daschuer
Copy link
Member

Thank you!

@daschuer daschuer merged commit 32106f9 into mixxxdj:2.3 Dec 31, 2021
@ronso0 ronso0 deleted the sampler-export branch December 31, 2021 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog This PR should be included in the changelog library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants