playlist export: add missing file extension#4531
Conversation
66a1695 to
a18d321
Compare
|
@uklotzde Refactored to use regexp in util/string.h |
eb06a87 to
62d59c5
Compare
|
for anyone testing this without reading the code:
so for example |
62d59c5 to
aa72e10
Compare
|
ping, this is ready. |
aa72e10 to
22d2a47
Compare
|
@ronso0, I took the liberty and pushed my changes directly to your branch so my changes don't get detached from the PR. |
7a6241b to
f07b964
Compare
|
Perfecto, thanks! |
| const ConfigKey kConfigKeyLastImportExportCrateDirectoryKey( | ||
| "[Library]", "last_import_export_crate_directory"); | ||
|
|
There was a problem hiding this comment.
@uklotzde I'd like to hear your opinion on this. Instead of defining kConfigKeyLastImportExportCrateDirectoryKey in a bunch of cpp files all at once, put it in a header file under the mixxx namespace and then #include it where its needed. Does that make sense, what do you need to specify for it to work? something like inline const ConfigKey ...?
nevermind, its not defined in more than one translation unit. Don't know how I got that idea.
Swiftb0y
left a comment
There was a problem hiding this comment.
LGTM, though I'm not sure if I'm allowed to merge since this PR does contain commits I made.
cc15cce to
371c925
Compare
|
sqashed, rebased, tested if all commits build. |
I think it doesn't make a difference if your review proposals are implemented or if you implment them yourself. |
371c925 to
4ead4ac
Compare
|
pushed again because I squashing wiped your co-authorship @Swiftb0y |
| QFileInfo fileInfo(playlist_files.first()); | ||
| m_pConfig->set(kConfigKeyLastImportExportPlaylistDirectory, | ||
| ConfigValue(fileInfo.dir().absolutePath())); |
There was a problem hiding this comment.
| QFileInfo fileInfo(playlist_files.first()); | |
| m_pConfig->set(kConfigKeyLastImportExportPlaylistDirectory, | |
| ConfigValue(fileInfo.dir().absolutePath())); | |
| m_pConfig->set(kConfigKeyLastImportExportPlaylistDirectory, | |
| ConfigValue(QFileInfo(playlist_files.first()).dir().absolutePath())); |
There was a problem hiding this comment.
The explanation for this change got lost somehow:
The point of this change is that I don't really see a reason to reuse the fileInfo variable inside the loop. So inlining it here and instead declaring a const version in the loop seems like better style to me.
There was a problem hiding this comment.
playlist_files.first() is a QString, so this won't work.
There was a problem hiding this comment.
Sorry yes, noticed after the fact too. We can just construct a temporary QFileInfo (I updated the code suggestion accordingly). This pattern of getting the absolutePath of the folder containing some file has also been used multiple times. We might want to consider factoring that out into an utility function. Especially since I don't think this entire chain of QString -> QFileInfo -> QDir -> QString is particularly efficient.
There was a problem hiding this comment.
I'm aware this chain is the opposite of 'simple', though I think refactoring should happen in main where there are more places where this is needed (effect chain import/export comes to mind).
I'll add a ToDo.
I suppose to extract the dir string we just need to chop everything after the last QDir::separator.
There was a problem hiding this comment.
str.truncate(str.lastIndexOf(QDir::separator));There was a problem hiding this comment.
if we are sure that the path's we get are absolute, yes that should be sufficient.
| QString fileFilter = tr("M3U Playlist (*.m3u)"); | ||
| QString fileLocationInput = QFileDialog::getSaveFileName( | ||
| nullptr, | ||
| tr("Export Playlist"), | ||
| lastPlaylistDirectory.append("/").append(playlistName), | ||
| tr("M3U Playlist (*.m3u);;M3U8 Playlist (*.m3u8);;" | ||
| "PLS Playlist (*.pls);;Text CSV (*.csv);;Readable Text (*.txt)"), | ||
| &filefilter); | ||
| &fileFilter); | ||
| QString fileLocation = filePathWithSelectedExtension(fileLocationInput, fileFilter); |
There was a problem hiding this comment.
add const to each, if ur already touching them
| QFileInfo fileInfo(playlist_files.first()); | ||
| m_pConfig->set(kConfigKeyLastImportExportCrateDirectoryKey, | ||
| ConfigValue(fileInfo.dir().absolutePath())); | ||
|
|
There was a problem hiding this comment.
apply suggestions from baseplaylistfeature here too
| namespace { | ||
|
|
||
| const ConfigKey kConfigKeyLastImportExportPlaylistDirectory( | ||
| "[Library]", "last_import_export_playlist_directory"); |
There was a problem hiding this comment.
This changes the key. Was this intentionally?
This breaks the feature for users after upgrade.
There was a problem hiding this comment.
The same applies to the Crate version
There was a problem hiding this comment.
I thought if I touch it I might as well apply snake_case.
"This breaks the feature" is a bit of an exxageration, users just need to select it again. But if that's not okay for a bugfix release I'll revert it, of course.
There was a problem hiding this comment.
this is a good question. In general, our control object and configkey names are a gigantic mess and totally inconsistent. In general, we have preferred to stick to existing names, even if the names were poorly chosen, to preserve compatibility. Unless there's a compelling reason to change the name, I think it's better to stick with the old one.
|
The last two commits contain the experimental workaround for the QFileDialog suffix bug (with the Qt dialog). |
| return fileLocation; | ||
| } | ||
|
|
||
| QString checkedFilePathWithSelectedExtension(const QString& caption, |
There was a problem hiding this comment.
The function name sounds as if it will just do the check. It also pops up a dialog.
This should be expressed by the name.
Something like:
SaveFileDialogWithVerifiedExtension() or such
There was a problem hiding this comment.
yes, thank you. consider this WIP and the name will be adjusted.
What I care about here is whether this approach works for everyone, or not.
if this get's sufficient 👍 I'll implement it in other places, too, and change the name.
There was a problem hiding this comment.
considering the return value I'd name it filePathWithVerifiedExtensionFromFileDialog
There was a problem hiding this comment.
Try to name functions starting with an imperative verb if possible. Like good commit messages ;)
There was a problem hiding this comment.
getFilePathWithVerifiedExtensionFromFileDialog ;)
|
I have tested this and it works quite good. Since the roundtrip happens only in an exceptional case, it is a good solution. I have noticed if you, misspell the extension, the correctly spelled extension is appended. I think we can merge it after the function name has been adjusted. |
|
@uklotzde Are all your review findings solved. |
|
I'll address @Swiftb0y's recent comments after implementing the new dialog. |
uklotzde
left a comment
There was a problem hiding this comment.
The naming could be improved, but I don't have concerns regarding the code. Merge when ready.
| return fileLocation; | ||
| } | ||
|
|
||
| QString checkedFilePathWithSelectedExtension(const QString& caption, |
There was a problem hiding this comment.
Try to name functions starting with an imperative verb if possible. Like good commit messages ;)
|
Okay then, thanks for reviewing! |
c14ccfd to
02705f6
Compare
|
Done. Every commit builds and works as intended. |
daschuer
left a comment
There was a problem hiding this comment.
LGTM, Thank you for all these bug fixes of this type. That makes really a difference.
| m_pConfig->set(ConfigKey("[Library]", "LastImportExportPlaylistDirectory"), | ||
| ConfigValue(fileName.dir().absolutePath())); | ||
| QString fileDirectory(playlistFile); | ||
| fileDirectory.truncate(playlistFile.lastIndexOf(QDir::separator())); |
There was a problem hiding this comment.
I suspect this always truncates at position 0, see https://bugs.launchpad.net/bugs/1964508
Native separator is \ on Windows and maybe Qt has already converted the path to use /? In that case lastIndexOf("\") would return -1 which is equivalent to passing 0 to truncate
https://doc.qt.io/qt-5/qstring.html#truncate
It is not recommended to use QDir::separator() for constructing paths, but appearantly it also creates issues when computing paths
https://doc.qt.io/qt-5/qdir.html#separator
original bug https://bugs.launchpad.net/mixxx/+bug/1197302
follow-up https://bugs.launchpad.net/mixxx/+bug/1889352
the fix from #430 got lost somehow.
related pending bug:
"extension is not autocompleted in dialog"
https://bugs.launchpad.net/mixxx/+bug/1455749