-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Better file export #3572
Open
poelzi
wants to merge
36
commits into
mixxxdj:main
Choose a base branch
from
poelzi:better-export
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Better file export #3572
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
8dbb96f
Add Grantlee lib to dependencies
poelzi 5874dbe
Major track export overhaul
poelzi ad7ac51
Use the the last right click selected playlist, not the current
poelzi 167550a
Add libgrantlee5-dev to debian build env
poelzi 69f357d
Fix build problems
poelzi 4672c8b
Make Key a Q_GADGET and add string properties for formatting
poelzi b97b6cc
Use index for position index and dup for duplication counter
poelzi 0d9618e
Add support for exporting files from context menu
poelzi d129f2d
Export crate summary into file exporter context
poelzi e2d9ec9
Add render function which does not escape html characters
poelzi 19f00f6
Add grantlee plugin with mixxx specific filters
poelzi 715355c
Fix Exporter Test
poelzi fc287dc
Use CrateSummaryWrapper as QObject wrapper
poelzi 993a5e7
Add zeropad filter for adding 0 prefixes
poelzi 515d393
Move exportPlaylistItemsIntoFile to Parser
poelzi 999edbf
Add support for creating a playlist on file export
poelzi 7c86579
Add PlaylistSummary for repersenting playlists
poelzi f6fc540
Add PlaylistSummary wrapper and export to track exporter
poelzi cc9b5fa
Add round filter, move default patterns to code
poelzi 998667f
Compile fixes
poelzi 9324697
Merge branch 'main' of https://github.com/mixxxdj/mixxx into better-e…
poelzi 7c1d480
Merge branch 'main' of https://github.com/mixxxdj/mixxx into better-e…
poelzi 1d64ce4
Add function to ensure safe filename on all platforms
poelzi 3057941
Use tabwidget for export dialog
poelzi dd3d9e6
cleanup group filter
poelzi 3a79ffa
Fix missing assignment of crateWrapper
poelzi 7fad172
Properly escape problematic filenames on all platforms
poelzi 488671b
Use Dropdown Menu for pattern suggestions, not a ComboBox
poelzi 4d0ce25
Implement default lookup function for keys (not working)
poelzi 049c65d
fix clazy warnings
poelzi 2118737
clazy fixes
poelzi 87aa753
Use one button line in export
poelzi 49aa05d
Escape playlist name in menu
poelzi 1dd67eb
Prevent crashes on patterns like "{{ }}"
poelzi 82652f0
Go back to a QComboBox but with custom item handling
poelzi 28f0439
Merge branch 'main' of https://github.com/mixxxdj/mixxx into better-e…
poelzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ const auto kResultCantCreateFile = QStringLiteral("Could not create file"); | |
const auto kDefaultPattern = QStringLiteral( | ||
"{{ track.basename }}{% if dup %}-{{dup}}{% endif %}" | ||
".{{track.extension}}"); | ||
const auto kEmptyMsg = QLatin1String(""); | ||
} // namespace | ||
|
||
TrackExportWorker::TrackExportWorker(const QString& destDir, | ||
|
@@ -120,31 +121,42 @@ void TrackExportWorker::setPattern(QString* pattern) { | |
if (pattern == nullptr) { | ||
m_pattern = nullptr; | ||
if (!m_template.isNull()) { | ||
m_template_valid = false; | ||
m_template.reset(); | ||
} | ||
return; | ||
} | ||
if (!m_engine) { | ||
m_engine = Formatter::getEngine(this); | ||
m_engine->setSmartTrimEnabled(true); | ||
// smartTrimEnabled would be good, but causes crashes on invalid pattern '{{ }}' | ||
// m_engine->setSmartTrimEnabled(true); | ||
} | ||
m_pattern = pattern; | ||
updateTemplate(); | ||
} | ||
|
||
void TrackExportWorker::updateTemplate() { | ||
QString tmpl = m_destDir + QDir::separator().toLatin1() + | ||
(m_pattern ? *m_pattern : kDefaultPattern); | ||
m_template = m_engine->newTemplate(tmpl, QStringLiteral("export")); | ||
QString fullPattern; | ||
if (m_pattern) { | ||
QString trimmed = m_pattern->trimmed(); | ||
fullPattern = m_destDir + QDir::separator().toLatin1() + trimmed; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can omit .toLatin1() here and below. |
||
} else { | ||
fullPattern = m_destDir + QDir::separator().toLatin1() + kDefaultPattern; | ||
} | ||
m_template = m_engine->newTemplate(fullPattern, QStringLiteral("export")); | ||
if (m_template->error()) { | ||
m_errorMessage = m_template->errorString(); | ||
m_template_valid = false; | ||
} else { | ||
m_errorMessage = QString(); | ||
m_template_valid = true; | ||
} | ||
} | ||
|
||
void TrackExportWorker::run() { | ||
m_running = true; | ||
m_bStop = false; | ||
m_overwriteMode = OverwriteMode::ASK; | ||
int i = 0; | ||
auto skippedTracks = TrackPointerList(); | ||
QMap<QString, TrackFile> copy_list = createCopylist(m_tracks, &skippedTracks); | ||
|
@@ -154,7 +166,7 @@ void TrackExportWorker::run() { | |
jobsTotal++; | ||
} | ||
|
||
for (TrackPointer track : qAsConst(skippedTracks)) { | ||
for (const TrackPointer& track : qAsConst(skippedTracks)) { | ||
QString fileName = track->fileName(); | ||
emit progress(fileName, nullptr, 0, jobsTotal); | ||
emit result(TrackExportWorker::ExportResult::SKIPPED, kResultEmptyPattern); | ||
|
@@ -178,10 +190,10 @@ void TrackExportWorker::run() { | |
} | ||
if (!m_playlist.isEmpty()) { | ||
const auto targetDir = QDir(m_destDir); | ||
const QString plsPath = targetDir.filePath(m_playlist); | ||
const QString plsPath = targetDir.filePath(FileUtils::escapeFileName(m_playlist)); | ||
QFileInfo plsPathFileinfo(plsPath); | ||
|
||
emit progress(QStringLiteral("export playlist"), m_playlist, i, jobsTotal); | ||
emit progress(QStringLiteral("export playlist"), plsPath, i, jobsTotal); | ||
|
||
QDir plsDir = plsPathFileinfo.absoluteDir(); | ||
if (!plsDir.mkpath(plsDir.absolutePath())) { | ||
|
@@ -208,7 +220,7 @@ void TrackExportWorker::run() { | |
i++; | ||
} | ||
|
||
emit progress(QStringLiteral(""), QStringLiteral(""), i, jobsTotal); | ||
emit progress(kEmptyMsg, kEmptyMsg, i, jobsTotal); | ||
emit result(TrackExportWorker::ExportResult::EXPORT_COMPLETE, kResultOk); | ||
m_running = false; | ||
} | ||
|
@@ -223,19 +235,19 @@ QString TrackExportWorker::applyPattern( | |
TrackPointer track, | ||
int index, | ||
int duplicateCounter) { | ||
VERIFY_OR_DEBUG_ASSERT(!m_destDir.isEmpty()) { | ||
qWarning() << "empty target directory"; | ||
if (!m_template_valid) { | ||
return QString(); | ||
} | ||
VERIFY_OR_DEBUG_ASSERT(!m_template.isNull()) { | ||
qWarning() << "template missing"; | ||
VERIFY_OR_DEBUG_ASSERT(!m_destDir.isEmpty()) { | ||
qWarning() << "empty target directory"; | ||
return QString(); | ||
} | ||
VERIFY_OR_DEBUG_ASSERT(m_engine) { | ||
qWarning() << "engine missing"; | ||
return QString(); | ||
} | ||
// fill the context with the proper variables | ||
|
||
// fill the context with the proper variables. | ||
m_context->push(); | ||
m_context->insert(QStringLiteral("directory"), m_destDir); | ||
// this is safe since the context stack is popped after rendering | ||
|
@@ -249,7 +261,7 @@ QString TrackExportWorker::applyPattern( | |
m_context->pop(); | ||
|
||
// replace bad filename characters with spaces | ||
return newName; | ||
return newName.trimmed(); | ||
} | ||
|
||
void TrackExportWorker::copyFile(const QFileInfo& source_fileinfo, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can become just:
const QString kEmptyMsg;