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 csv rating export #4762

Merged
merged 5 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -646,20 +649,6 @@ QVariant BaseTrackTableModel::roleValue(
return QChar('-');
}
}
case ColumnCache::COLUMN_LIBRARYTABLE_YEAR: {
if (rawValue.isNull()) {
return QVariant();
}
VERIFY_OR_DEBUG_ASSERT(rawValue.canConvert<QString>()) {
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();
Expand Down
38 changes: 17 additions & 21 deletions src/library/parsercsv.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
//
// C++ Implementation: parsercsv
//
// Description: module to parse Comma-Separated Values (CSV) formatted playlists (rfc4180)
//
//
// Author: Ingo Kossyk <[email protected]>, (C) 2004
// Author: Tobias Rafreider [email protected], (C) 2011
// Author: Daniel Schürmann [email protected], (C) 2011
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include "library/parsercsv.h"

#include <QDir>
Expand All @@ -21,12 +7,24 @@

#include "moc_parsercsv.cpp"

ParserCsv::ParserCsv() : Parser() {
}
namespace {

ParserCsv::~ParserCsv() {
bool isColumnExported(BaseSqlTableModel* pPlaylistTableModel, int column) {
if (pPlaylistTableModel->isColumnInternal(column)) {
return false;
}
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;
}

} // namespace

QList<QString> ParserCsv::parse(const QString& sFilename) {
QFile file(sFilename);
QString basepath = sFilename.section('/', 0, -2);
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
42 changes: 15 additions & 27 deletions src/library/parsercsv.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
//
// C++ Interface: parserm3u
//
// Description: Interface header parse Comma-Separated Values (CSV) formatted playlists (rfc4180)
//
//
// Author: Ingo Kossyk <[email protected]>, (C) 2004
// Author: Tobias Rafreider [email protected], (C) 2011
// Author: Daniel Schürmann [email protected], (C) 2011
//
// Copyright: See COPYING file that comes with this distribution
//
//
#pragma once

#include <QList>
Expand All @@ -20,21 +7,22 @@
#include "library/parser.h"
#include "library/basesqltablemodel.h"

class ParserCsv : public Parser
{
class ParserCsv : public Parser {
Q_OBJECT
public:
ParserCsv();
virtual ~ParserCsv();
/**Overwriting function parse in class Parser**/
QList<QString> 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<QList<QString> > tokenize(const QByteArray& str, char delimiter);
public:
~ParserCsv() override = default;

QList<QString> parse(const QString&) override;
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<QList<QString>> tokenize(const QByteArray& str, char delimiter);
};