From c3f94863f271f1e6f8ee80e5053ccef547c2d0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 21 May 2022 14:31:56 +0200 Subject: [PATCH 1/5] Extract a common check to isColumnExported() --- src/library/parsercsv.cpp | 36 ++++++++++++++++------------------- src/library/parsercsv.h | 40 ++++++++++++++------------------------- 2 files changed, 30 insertions(+), 46 deletions(-) diff --git a/src/library/parsercsv.cpp b/src/library/parsercsv.cpp index 41f411d6f14..38b7ebbaa15 100644 --- a/src/library/parsercsv.cpp +++ b/src/library/parsercsv.cpp @@ -1,17 +1,3 @@ -// -// C++ Implementation: parsercsv -// -// Description: module to parse Comma-Separated Values (CSV) formatted playlists (rfc4180) -// -// -// Author: Ingo Kossyk , (C) 2004 -// Author: Tobias Rafreider trafreider@mixxx.org, (C) 2011 -// Author: Daniel Schürmann daschuer@gmx.de, (C) 2011 -// -// Copyright: See COPYING file that comes with this distribution -// -// - #include "library/parsercsv.h" #include @@ -21,10 +7,22 @@ #include "moc_parsercsv.cpp" -ParserCsv::ParserCsv() : Parser() { +namespace { + +bool isColumnExported(BaseSqlTableModel* pPlaylistTableModel, int column) { + if (pPlaylistTableModel->isColumnInternal(column)) { + return false; + } + if (pPlaylistTableModel->fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW) == column) { + return false; + } + return true; } -ParserCsv::~ParserCsv() { +} // namespace + +ParserCsv::ParserCsv() + : Parser() { } QList ParserCsv::parse(const QString& sFilename) { @@ -148,8 +146,7 @@ bool ParserCsv::writeCSVFile(const QString &file_str, BaseSqlTableModel* pPlayli bool first = true; int columns = pPlaylistTableModel->columnCount(); for (int i = 0; i < columns; ++i) { - if (pPlaylistTableModel->isColumnInternal(i) || - (pPlaylistTableModel->fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW) == i)) { + if (!isColumnExported(pPlaylistTableModel, i)) { continue; } if (!first) { @@ -170,8 +167,7 @@ bool ParserCsv::writeCSVFile(const QString &file_str, BaseSqlTableModel* pPlayli // writing fields section first = true; for (int i = 0; i < columns; ++i) { - if (pPlaylistTableModel->isColumnInternal(i) || - (pPlaylistTableModel->fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW) == i)) { + if (!isColumnExported(pPlaylistTableModel, i)) { continue; } if (!first) { diff --git a/src/library/parsercsv.h b/src/library/parsercsv.h index ecf1e1167ed..919c7bc31b6 100644 --- a/src/library/parsercsv.h +++ b/src/library/parsercsv.h @@ -1,16 +1,3 @@ -// -// C++ Interface: parserm3u -// -// Description: Interface header parse Comma-Separated Values (CSV) formatted playlists (rfc4180) -// -// -// Author: Ingo Kossyk , (C) 2004 -// Author: Tobias Rafreider trafreider@mixxx.org, (C) 2011 -// Author: Daniel Schürmann daschuer@gmx.de, (C) 2011 -// -// Copyright: See COPYING file that comes with this distribution -// -// #pragma once #include @@ -20,21 +7,22 @@ #include "library/parser.h" #include "library/basesqltablemodel.h" -class ParserCsv : public Parser -{ +class ParserCsv : public Parser { Q_OBJECT -public: + public: ParserCsv(); - virtual ~ParserCsv(); - /**Overwriting function parse in class Parser**/ - QList parse(const QString&); - // Playlist Export - static bool writeCSVFile(const QString &file, BaseSqlTableModel* pPlaylistTableModel, bool useRelativePath); - // Readable Text export - static bool writeReadableTextFile(const QString &file, BaseSqlTableModel* pPlaylistTableModel, bool writeTimestamp); -private: - /**Reads a line from the file and returns filepath if a valid file**/ - QList > tokenize(const QByteArray& str, char delimiter); + QList parse(const QString&); + static bool writeCSVFile( + const QString& file, + BaseSqlTableModel* pPlaylistTableModel, + bool useRelativePath); + static bool writeReadableTextFile( + const QString& file, + BaseSqlTableModel* pPlaylistTableModel, + bool writeTimestamp); + private: + /// Reads a line from the file and returns filepath if a valid file + QList> tokenize(const QByteArray& str, char delimiter); }; From 1be3c157df0ca0aac3b014db0219fcad15c7f360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 21 May 2022 14:36:03 +0200 Subject: [PATCH 2/5] Don't export likely too wide cover-art column --- src/library/parsercsv.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/library/parsercsv.cpp b/src/library/parsercsv.cpp index 38b7ebbaa15..1a622e1cc6d 100644 --- a/src/library/parsercsv.cpp +++ b/src/library/parsercsv.cpp @@ -16,6 +16,10 @@ bool isColumnExported(BaseSqlTableModel* pPlaylistTableModel, int column) { if (pPlaylistTableModel->fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW) == column) { return false; } + if (pPlaylistTableModel->fieldIndex(ColumnCache::COLUMN_LIBRARYTABLE_COVERART) == column) { + // This is the bas64 encoded image which may hit the maximum line length of spreadsheet applications + return false; + } return true; } From cf3e9939939c43c8cd00705961b1515e499721cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 21 May 2022 15:28:28 +0200 Subject: [PATCH 3/5] Export star rating and remove parenthesis from exported play count --- src/library/basetracktablemodel.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/library/basetracktablemodel.cpp b/src/library/basetracktablemodel.cpp index b44dc821f60..0da1a322130 100644 --- a/src/library/basetracktablemodel.cpp +++ b/src/library/basetracktablemodel.cpp @@ -553,6 +553,9 @@ QVariant BaseTrackTableModel::roleValue( return composeCoverArtToolTipHtml(index); case ColumnCache::COLUMN_LIBRARYTABLE_PREVIEW: return QVariant(); + case ColumnCache::COLUMN_LIBRARYTABLE_RATING: + case ColumnCache::COLUMN_LIBRARYTABLE_TIMESPLAYED: + return std::move(rawValue); default: // Same value as for Qt::DisplayRole (see below) break; From dffee098d93123c902b4d30882fbd7bdd15dbd9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 24 May 2022 01:38:07 +0200 Subject: [PATCH 4/5] Export and display year column as it is. This allows to export/display all sort of valid TDRC formats --- src/library/basetracktablemodel.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/library/basetracktablemodel.cpp b/src/library/basetracktablemodel.cpp index 0da1a322130..6f2996dbc65 100644 --- a/src/library/basetracktablemodel.cpp +++ b/src/library/basetracktablemodel.cpp @@ -649,20 +649,6 @@ QVariant BaseTrackTableModel::roleValue( return QChar('-'); } } - case ColumnCache::COLUMN_LIBRARYTABLE_YEAR: { - if (rawValue.isNull()) { - return QVariant(); - } - VERIFY_OR_DEBUG_ASSERT(rawValue.canConvert()) { - return QVariant(); - } - bool ok; - const auto year = mixxx::TrackMetadata::formatCalendarYear(rawValue.toString(), &ok); - if (!ok) { - return QVariant(); - } - return year; - } case ColumnCache::COLUMN_LIBRARYTABLE_BITRATE: { if (rawValue.isNull()) { return QVariant(); From 92b856ff01764cd2de7aaf9f1d37c968b3ee4c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 26 May 2022 18:25:48 +0200 Subject: [PATCH 5/5] Remove redundant constructor and an override destructor --- src/library/parsercsv.cpp | 4 ---- src/library/parsercsv.h | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/library/parsercsv.cpp b/src/library/parsercsv.cpp index 1a622e1cc6d..3a3f4fde4e9 100644 --- a/src/library/parsercsv.cpp +++ b/src/library/parsercsv.cpp @@ -25,10 +25,6 @@ bool isColumnExported(BaseSqlTableModel* pPlaylistTableModel, int column) { } // namespace -ParserCsv::ParserCsv() - : Parser() { -} - QList ParserCsv::parse(const QString& sFilename) { QFile file(sFilename); QString basepath = sFilename.section('/', 0, -2); diff --git a/src/library/parsercsv.h b/src/library/parsercsv.h index 919c7bc31b6..4b7b168d444 100644 --- a/src/library/parsercsv.h +++ b/src/library/parsercsv.h @@ -10,9 +10,9 @@ class ParserCsv : public Parser { Q_OBJECT public: - ParserCsv(); + ~ParserCsv() override = default; - QList parse(const QString&); + QList parse(const QString&) override; static bool writeCSVFile( const QString& file, BaseSqlTableModel* pPlaylistTableModel,